mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Merge branch 'master' into image-improvement
This commit is contained in:
commit
5e1b4504e8
2
.github/workflows/build.yaml
vendored
2
.github/workflows/build.yaml
vendored
@ -44,7 +44,7 @@ jobs:
|
||||
run: |
|
||||
cat platformio_override.ini
|
||||
- name: Run PlatformIO
|
||||
run: pio run -e d1-mini-esp32_ili9341 -e esp32-touchdown -e freetouchdeck -e huzzah32-featherwing-24 -e huzzah32-featherwing-35 -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits
|
||||
run: pio run -e makerfabs-tft35-cap -e yeacreate-nscreen32 -e d1-mini-esp32_ili9341 -e esp32-touchdown -e freetouchdeck -e huzzah32-featherwing-24 -e huzzah32-featherwing-35 -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits
|
||||
- name: Upload output file
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -48,7 +48,7 @@ jobs:
|
||||
run: |
|
||||
cat platformio_override.ini
|
||||
- name: Run PlatformIO
|
||||
run: pio run -e d1-mini-esp32_ili9341 -e esp32-touchdown -e freetouchdeck -e huzzah32-featherwing-24 -e huzzah32-featherwing-35 -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits
|
||||
run: pio run -e makerfabs-tft35-cap -e yeacreate-nscreen32 -e d1-mini-esp32_ili9341 -e esp32-touchdown -e freetouchdeck -e huzzah32-featherwing-24 -e huzzah32-featherwing-35 -e lanbon_l8 -e m5stack-core2 -e wt32-sc01 -e d1-mini-esp8266_ili9341 -e linux_sdl_64bits
|
||||
- name: Upload output file
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -18,6 +18,9 @@ build_output/firmware/*.bin
|
||||
build_output/firmware/*.exe
|
||||
src/custom/*
|
||||
!src/custom/README.md
|
||||
!src/custom/bootlogo_template.h
|
||||
!src/custom/my_custom_template.h
|
||||
!src/custom/my_custom_template.cpp
|
||||
|
||||
## Test result files
|
||||
*.xml
|
||||
@ -33,3 +36,4 @@ src/custom/*
|
||||
*.bak
|
||||
|
||||
test/config.yaml
|
||||
tools/mklittlefs*
|
@ -1,6 +1,6 @@
|
||||
tasks:
|
||||
- init: cp platformio_override-template.ini platformio_override.ini
|
||||
- before: platformio upgrade
|
||||
- before: platformio upgrade; npm install -g lv_font_conv
|
||||
- command: echo "Please open 'platformio_override.ini', uncomment the platform, override and environment you wish to build for, save and then run command 'platformio run'."
|
||||
|
||||
image:
|
||||
|
14
README.md
14
README.md
@ -24,19 +24,19 @@ openHASP also adds ESP32 and STM32F4 support to take advantage of the additional
|
||||
|
||||
## Features
|
||||
|
||||
| Feature | ESP8266 | ESP32 | STM32F4
|
||||
| Feature (v0.6.0) | ESP8266 | ESP32 | STM32F4
|
||||
|-------------------------|---------|---------|----------
|
||||
| SPI display | :white_check_mark: yes | :white_check_mark: yes | :white_check_mark: yes
|
||||
| Parallel display | :x: no | :white_check_mark: yes | :white_check_mark: yes
|
||||
| PWM Screen dimming | :white_check_mark: yes | :white_check_mark: yes | :white_check_mark: yes
|
||||
| Maximum Page Count | 4 | 12 | 12
|
||||
| Object Types / Widgets | 14 | 15 | 15
|
||||
| [Object Types / Widgets][7]| 20 | 20 | 20
|
||||
| Dynamic Objects | :white_check_mark: yes | :white_check_mark: yes | :white_check_mark: yes
|
||||
| [Lvgl Theme Support][3] | basic only | all themes | tbd
|
||||
| Theme Support | yes | yes | yes
|
||||
| [Custom .zi V5 font][4] | :white_check_mark: yes (latin1) | :white_check_mark: yes (latin1) | no
|
||||
| [FontAwesome Icons][5] | :white_check_mark: 1300+ | :white_check_mark: 1300+ | no
|
||||
| PNG images | :x: no | :grey_question: tbd | :grey_question: tbd
|
||||
| Network | :white_check_mark: Wifi | :white_check_mark: Wifi | :white_check_mark: Ethernet
|
||||
| MDI Icons | :white_check_mark: yes | :white_check_mark: yes | no
|
||||
| [PNG images][8] | :x: no | :white_check_mark: yes | :white_check_mark: yes
|
||||
| Network | :white_check_mark: Wi-Fi | :white_check_mark: Wi-Fi | :white_check_mark: Ethernet
|
||||
|
||||
|
||||
## Getting Started
|
||||
@ -57,3 +57,5 @@ For support using openHASP, please join the [#openHASP channel][6] on Discord.
|
||||
[4]: https://github.com/fvanroie/HMI-Font-Pack/releases
|
||||
[5]: https://fontawesome.com/cheatsheet/
|
||||
[6]: https://discord.gg/VCWyuhF
|
||||
[7]: https://haswitchplate.github.io/openHASP-docs/0.6/design/objects#cheatsheet
|
||||
[8]: https://haswitchplate.github.io/openHASP-docs/0.6/design/objects#image
|
||||
|
File diff suppressed because one or more lines are too long
BIN
data/edit.htm.gz
BIN
data/edit.htm.gz
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
/* This file is used during the build of the paho library */
|
||||
|
||||
#ifndef VERSIONINFO_H
|
||||
|
@ -1,3 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef WIFISPI_H
|
||||
#define WIFISPI_H
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_CONF_H
|
||||
#define HASP_CONF_H
|
||||
|
||||
@ -36,7 +39,7 @@
|
||||
(ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0)
|
||||
|
||||
#ifndef HASP_USE_OTA
|
||||
#define HASP_USE_OTA (HASP_HAS_NETWORK)
|
||||
#define HASP_USE_OTA 0 //(HASP_HAS_NETWORK)
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_MQTT
|
||||
@ -51,10 +54,22 @@
|
||||
#define MQTT_NODENAME "plate"
|
||||
#endif
|
||||
|
||||
#ifndef HASP_START_CONSOLE
|
||||
#define HASP_START_CONSOLE 1
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_HTTP
|
||||
#define HASP_USE_HTTP (HASP_HAS_NETWORK)
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_HTTP_ASYNC
|
||||
#define HASP_USE_HTTP_ASYNC 0 //(HASP_HAS_NETWORK)
|
||||
#endif
|
||||
|
||||
#ifndef HASP_START_HTTP
|
||||
#define HASP_START_HTTP 1
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_MDNS
|
||||
#define HASP_USE_MDNS (HASP_HAS_NETWORK)
|
||||
#endif
|
||||
@ -67,6 +82,10 @@
|
||||
#define HASP_USE_TELNET 0
|
||||
#endif
|
||||
|
||||
#ifndef HASP_START_TELNET
|
||||
#define HASP_START_TELNET 1
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_CONSOLE
|
||||
#define HASP_USE_CONSOLE 1
|
||||
#endif
|
||||
@ -122,6 +141,10 @@
|
||||
#define HASP_NUM_GPIO_CONFIG 8
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_CUSTOM
|
||||
#define HASP_USE_CUSTOM 0
|
||||
#endif
|
||||
|
||||
// #ifndef HASP_NUM_OUTPUTS
|
||||
// #define HASP_NUM_OUTPUTS 3
|
||||
// #endif
|
||||
@ -233,6 +256,10 @@ static WiFiSpiClass WiFi;
|
||||
#include "sys/svc/hasp_http.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_HTTP_ASYNC > 0
|
||||
#include "sys/svc/hasp_http.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_CONSOLE > 0
|
||||
#include "sys/svc/hasp_console.h"
|
||||
#endif
|
||||
@ -247,13 +274,6 @@ static WiFiSpiClass WiFi;
|
||||
|
||||
#if HASP_USE_OTA > 0
|
||||
#include "sys/svc/hasp_ota.h"
|
||||
#ifndef HASP_OTA_PORT
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#define HASP_OTA_PORT 3232
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
#define HASP_OTA_PORT 8266
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TASMOTA_CLIENT > 0
|
||||
|
@ -1,3 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_MACRO_H
|
||||
#define HASP_MACRO_H
|
||||
|
||||
|
@ -221,7 +221,12 @@ typedef void* lv_fs_drv_user_data_t;
|
||||
* With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
|
||||
* However the opened images might consume additional RAM.
|
||||
* LV_IMG_CACHE_DEF_SIZE must be >= 1 */
|
||||
#ifndef LV_IMG_CACHE_DEF_SIZE
|
||||
#define LV_IMG_CACHE_DEF_SIZE 1
|
||||
#endif
|
||||
#ifndef LV_IMG_CACHE_DEF_SIZE_PSRAM
|
||||
#define LV_IMG_CACHE_DEF_SIZE_PSRAM 20 // special openHASP setting when PSRAM is used
|
||||
#endif
|
||||
|
||||
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
|
||||
typedef void* lv_img_decoder_user_data_t;
|
||||
@ -349,36 +354,6 @@ typedef void* lv_indev_drv_user_data_t; /*Type of user data in the in
|
||||
|
||||
#if TFT_WIDTH>=320 || TFT_WIDTH>=480
|
||||
|
||||
#ifdef WT32SC01
|
||||
|
||||
#ifndef HASP_FONT_1
|
||||
#define HASP_FONT_1 robotocondensed_regular_16_ascii /* 5% Width */
|
||||
#endif
|
||||
#ifndef HASP_FONT_2
|
||||
#define HASP_FONT_2 robotocondensed_regular_24_ascii /* 5% Width */
|
||||
#endif
|
||||
#ifndef HASP_FONT_3
|
||||
#define HASP_FONT_3 robotocondensed_regular_32_ascii /* 10% Width */
|
||||
#endif
|
||||
#ifndef HASP_FONT_4
|
||||
#define HASP_FONT_4 robotocondensed_regular_48_ascii /* 10% Height */
|
||||
#endif
|
||||
|
||||
#ifndef ROBOTOCONDENSED_REGULAR_16_ASCII
|
||||
#define ROBOTOCONDENSED_REGULAR_16_ASCII 1
|
||||
#endif
|
||||
#ifndef ROBOTOCONDENSED_REGULAR_24_ASCII
|
||||
#define ROBOTOCONDENSED_REGULAR_24_ASCII 1
|
||||
#endif
|
||||
#ifndef ROBOTOCONDENSED_REGULAR_32_ASCII
|
||||
#define ROBOTOCONDENSED_REGULAR_32_ASCII 1
|
||||
#endif
|
||||
#ifndef ROBOTOCONDENSED_REGULAR_48_ASCII
|
||||
#define ROBOTOCONDENSED_REGULAR_48_ASCII 1
|
||||
#endif
|
||||
|
||||
#else // not WT32SC01
|
||||
|
||||
#ifndef HASP_FONT_1
|
||||
#define HASP_FONT_1 robotocondensed_regular_16_latin1 /* 5% Width */
|
||||
#endif
|
||||
@ -405,8 +380,6 @@ typedef void* lv_indev_drv_user_data_t; /*Type of user data in the in
|
||||
#define ROBOTOCONDENSED_REGULAR_48_LATIN1 1
|
||||
#endif
|
||||
|
||||
#endif // WT32SC01
|
||||
|
||||
#ifndef HASP_FONT_SIZE_1
|
||||
#define HASP_FONT_SIZE_1 16
|
||||
#endif
|
||||
@ -655,8 +628,8 @@ typedef void* lv_font_user_data_t;
|
||||
#endif
|
||||
|
||||
/*Change the built in (v)snprintf functions*/
|
||||
#define LV_SPRINTF_CUSTOM 0
|
||||
#if LV_SPRINTF_CUSTOM
|
||||
#define LV_SPRINTF_CUSTOM 1 // saves 1.4 KiB
|
||||
#if LV_SPRINTF_CUSTOM
|
||||
# define LV_SPRINTF_INCLUDE <stdio.h>
|
||||
# define lv_snprintf snprintf
|
||||
# define lv_vsnprintf vsnprintf
|
||||
@ -738,6 +711,19 @@ typedef struct {
|
||||
# define LV_DROPDOWN_DEF_ANIM_TIME 200
|
||||
#endif
|
||||
|
||||
/*Linemeter (dependencies: -*/
|
||||
#define LV_USE_LINEMETER 1
|
||||
#if LV_USE_LINEMETER
|
||||
|
||||
/* Set how precisely should the lines of the line meter be calculated.
|
||||
* Higher precision means slower rendering.
|
||||
* 0: normal
|
||||
* 1: extra precision in the inner ring
|
||||
* 2. extra precision on the outer ring too
|
||||
*/
|
||||
# define LV_LINEMETER_PRECISE 2
|
||||
#endif
|
||||
|
||||
/*Gauge (dependencies:lv_bar, lv_linemeter)*/
|
||||
#define LV_USE_GAUGE 1
|
||||
|
||||
|
@ -556,7 +556,7 @@ typedef void * lv_font_user_data_t;
|
||||
#define LV_USE_ARABIC_PERSIAN_CHARS 0
|
||||
|
||||
/*Change the built in (v)snprintf functions*/
|
||||
#define LV_SPRINTF_CUSTOM 0
|
||||
#define LV_SPRINTF_CUSTOM 1 // saves 1.4 KiB
|
||||
#if LV_SPRINTF_CUSTOM
|
||||
# define LV_SPRINTF_INCLUDE <stdio.h>
|
||||
# define lv_snprintf snprintf
|
||||
@ -692,7 +692,7 @@ typedef struct {
|
||||
* 1: extra precision in the inner ring
|
||||
* 2. extra precision on the outer ring too
|
||||
*/
|
||||
# define LV_LINEMETER_PRECISE 1
|
||||
# define LV_LINEMETER_PRECISE 2
|
||||
#endif
|
||||
/*Mask (dependencies: -)*/
|
||||
#define LV_USE_OBJMASK 1
|
||||
|
@ -1,3 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef LV_SYMBOL_MDI_DEF_H
|
||||
#define LV_SYMBOL_MDI_DEF_H
|
||||
/* clang-format off */
|
||||
|
@ -1,3 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
/* Include the normal default core configuration */
|
||||
#include "stm32f4xx_hal_conf_default.h"
|
||||
|
||||
|
@ -124,5 +124,8 @@
|
||||
* Other Settings
|
||||
**************************************************/
|
||||
//#define HASP_USE_HA // Enable Home Assistant auto-discovery
|
||||
//#define HASP_START_CONSOLE 0 // Disable starting of serial console at boot
|
||||
//#define HASP_START_TELNET 0 // Disable starting of telnet service at boot
|
||||
//#define HASP_START_HTTP 0 // Disable starting of web interface at boot
|
||||
|
||||
#endif
|
@ -343,7 +343,7 @@ class Logging {
|
||||
#ifndef DISABLE_LOGGING
|
||||
int _level[3];
|
||||
bool _showLevel[3];
|
||||
Print* _logOutput[3];
|
||||
Print* _logOutput[3] = {NULL,NULL,NULL};
|
||||
|
||||
printfunction _prefix = NULL;
|
||||
printfunction _suffix = NULL;
|
||||
|
@ -54,7 +54,7 @@ TFT_Class tft(io, controller, TFT_WIDTH, TFT_HEIGHT);
|
||||
#include <GxCTRL/GxCTRL_ILI9341/GxCTRL_ILI9341.h> // 240x320
|
||||
#include "GxReadRegisters.h"
|
||||
|
||||
#include "bootscreen.h" // Sketch tab header for xbm images
|
||||
#include "custom/bootlogo_template.h" // Sketch tab header for xbm images
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
|
@ -302,6 +302,8 @@ static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p)
|
||||
|
||||
fflush(*fp); /*If not syncronized fclose can write the truncated part*/
|
||||
uint32_t p = ftell(*fp);
|
||||
(void)p; // unused
|
||||
|
||||
// ftruncate(fileno(*fp), p);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
@ -1,7 +1,5 @@
|
||||
/**
|
||||
* @file lv_zifont.h
|
||||
*
|
||||
*/
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef LV_ZIFONT_H
|
||||
#define LV_ZIFONT_H
|
||||
|
@ -1,4 +1,4 @@
|
||||
; MIT License - Copyright (c) 2020 Francis Van Roie
|
||||
; MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
; For full license information read the LICENSE file in the project folder
|
||||
;
|
||||
; PlatformIO Project Configuration File
|
||||
@ -66,15 +66,15 @@ build_flags =
|
||||
; -- Shared library dependencies in all environments
|
||||
; Warning : don't put comments after github links => causes infinite download loop
|
||||
lib_deps =
|
||||
bxparks/AceButton@^1.8.3 ; GPIO button library
|
||||
bblanchon/ArduinoJson@^6.18.0 ; Json(l) parser
|
||||
bxparks/AceButton@^1.9.0 ; GPIO button library
|
||||
bblanchon/ArduinoJson@^6.18.3 ; Json(l) parser
|
||||
bblanchon/StreamUtils@1.6.1 ; for EEPromStream
|
||||
knolleary/PubSubClient@^2.8.0 ; MQTT client
|
||||
git+https://github.com/fvanroie/ConsoleInput.git
|
||||
;git+https://github.com/andrethomas/TasmotaSlave.git
|
||||
;git+https://github.com/lvgl/lvgl.git
|
||||
;Needed for touch rotation:
|
||||
git+https://github.com/lvgl/lvgl.git#release/v7
|
||||
;git+https://github.com/lvgl/lvgl.git#797212a3f346e9fdf71aef6f193889357eeae3f0
|
||||
;lvgl/lvgl@^7.11.0 ; from PIO library
|
||||
bodmer/TFT_eSPI@^2.3.70
|
||||
;git+https://github.com/Bodmer/TFT_eSPI.git
|
||||
@ -91,7 +91,7 @@ src_filter = +<*> -<.git/> -<examples/> -<test/> -<tests/> -<stm32f4/> -<lv_font
|
||||
; -- Platform specific build flags
|
||||
[esp32]
|
||||
framework = arduino
|
||||
platform = espressif32@^3.2.0
|
||||
platform = espressif32@^3.3.1
|
||||
|
||||
board_upload.flash_size=4MB
|
||||
board_upload.maximum_size = 4194304
|
||||
@ -115,6 +115,7 @@ build_flags =
|
||||
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
|
||||
-D HASP_CONSOLE_BUFFER=256 ; maximum length of a console/telnet command
|
||||
-D NO_GLOBAL_HTTPUPDATE ; dont instantiate httpUpdate
|
||||
;-D CONFIG_NEWLIB_NANO_FORMAT
|
||||
; -- lvgl build options -----------------------------
|
||||
-D LV_MEM_SIZE=49152U ; 48 kB lvgl memory
|
||||
-D LV_ATTRIBUTE_FAST_MEM=IRAM_ATTR
|
||||
@ -152,6 +153,7 @@ lib_ignore =
|
||||
AXP192
|
||||
|
||||
lib_deps =
|
||||
ESP Async WebServer
|
||||
LittleFS_esp32
|
||||
git+https://github.com/lvgl/lv_lib_png.git#release/v7
|
||||
#git+https://github.com/lvgl/lv_lib_bmp.git#release/v7
|
||||
|
@ -86,12 +86,12 @@ build_flags =
|
||||
${esp32.build_flags}
|
||||
;region -- TFT_eSPI build options -----------------------------------
|
||||
${lcd.lolin24}
|
||||
${esp32.vspi}
|
||||
${esp32.vspi} ; Use VSPI hardware SPI bus
|
||||
-D TFT_DC=5
|
||||
-D TFT_CS=26
|
||||
-D TFT_RST=-1 ; RST
|
||||
-D TFT_BCKL=22 ; None, configurable via web UI (e.g. 21)
|
||||
-D TOUCH_CS=17 ; (can also be 22 or 16)
|
||||
-D TFT_RST=-1 ; RST
|
||||
-D TFT_BCKL=22 ; None, configurable via web UI (e.g. 21)
|
||||
-D TOUCH_CS=17 ; (can also be 22 or 16)
|
||||
; -- Options ----------------------------------------
|
||||
-D HASP_USE_TELNET=1
|
||||
;endregion
|
||||
|
@ -5,25 +5,25 @@
|
||||
// as as a const unsigned char array in PROGMEM (FLASH program memory).
|
||||
|
||||
// The xbm format adds padding to pixel rows so they are a whole number of bytes
|
||||
// In this example 50 pixel width means 56 bits = 7 bytes
|
||||
// the 50 height then means array uses 50 x 7 = 350 bytes of FLASH
|
||||
// In this example 93 pixel width means 96 bits = 12 bytes
|
||||
// the 16 height then means array uses 12 x 16 = 192 bytes of FLASH
|
||||
// The library ignores the padding bits when drawing the image on the display.
|
||||
|
||||
// The openHASP logo uses the MaterialDesign icons font, released under the OFL license
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include <pgmspace.h> // PROGMEM support header
|
||||
#endif
|
||||
// Usage:
|
||||
// - Copy this file to src/custom/bootlogo.h
|
||||
// - Add #define HASP_CUSTOMIZE_BOOTLOGO to include/user_config_override.h
|
||||
|
||||
#ifndef PROGMEM
|
||||
#define PROGMEM
|
||||
#endif
|
||||
// RGB array
|
||||
#define logoBgColor {0,128,128}
|
||||
#define logoFgColor {255,255,255}
|
||||
|
||||
// Image is stored in th array below, adjust the width and height accordingly
|
||||
#define logoWidth 93
|
||||
#define logoHeight 16
|
||||
|
||||
PROGMEM const unsigned char bootscreen[] = {
|
||||
// Image is stored in the array below, also update the width and height accordingly
|
||||
PROGMEM const unsigned char logoImage[] = {
|
||||
0x7C, 0xF0, 0x07, 0xFF, 0x71, 0x1C, 0xC7, 0xC1, 0x07, 0xFC, 0xF1, 0x07, 0xFE, 0xF0, 0x0F, 0xFF, 0xF1, 0x1C,
|
||||
0xC7, 0xE1, 0x0F, 0xFE, 0xF1, 0x0F, 0xFF, 0xF1, 0x1F, 0xFF, 0xF1, 0x1C, 0xC7, 0xF1, 0x1F, 0xFF, 0xF1, 0x1F,
|
||||
0xC7, 0x71, 0x1C, 0x07, 0xF0, 0x1C, 0xC7, 0x71, 0x1C, 0x07, 0x70, 0x1C, 0xC7, 0x71, 0x1C, 0x07, 0xF0, 0x1D,
|
49
src/custom/my_custom_template.cpp
Normal file
49
src/custom/my_custom_template.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#include "hasplib.h"
|
||||
|
||||
#if HASP_USE_CUSTOM > 0 && false // <-- set this to true in your code
|
||||
|
||||
#include "custom/my_custom.h"
|
||||
|
||||
void custom_setup()
|
||||
{
|
||||
// Initialization code here
|
||||
randomSeed(millis());
|
||||
}
|
||||
|
||||
void custom_loop()
|
||||
{
|
||||
// Non-blocking code here, this should execute very fast!
|
||||
}
|
||||
|
||||
void custom_every_second()
|
||||
{
|
||||
Serial.print("#");
|
||||
}
|
||||
|
||||
void custom_every_5seconds()
|
||||
{
|
||||
Log.verbose(TAG_CUSTOM, "5 seconds have passsed...");
|
||||
dispatch_state_subtopic("my_sensor","{\"test\":123}");
|
||||
}
|
||||
|
||||
bool custom_pin_in_use(uint pin)
|
||||
{
|
||||
if(pin == 1024) return true; // fictuous used pin
|
||||
|
||||
// otherwise the pin is not used
|
||||
return false;
|
||||
}
|
||||
|
||||
void custom_get_sensors(JsonDocument& doc)
|
||||
{
|
||||
/* Sensor Name */
|
||||
JsonObject sensor = doc.createNestedObject(F("Custom"));
|
||||
|
||||
/* Key-Value pair of the sensor value */
|
||||
sensor[F("Random")] = random(256);
|
||||
}
|
||||
|
||||
#endif // HASP_USE_CUSTOM
|
30
src/custom/my_custom_template.h
Normal file
30
src/custom/my_custom_template.h
Normal file
@ -0,0 +1,30 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_CUSTOM_H
|
||||
#define HASP_CUSTOM_H
|
||||
|
||||
#include "hasplib.h"
|
||||
#if HASP_USE_CUSTOM > 0
|
||||
|
||||
/* This function is called at boot */
|
||||
void custom_setup();
|
||||
|
||||
/* This function is called every itteration of the main loop */
|
||||
void custom_loop();
|
||||
|
||||
/* This function is called every second */
|
||||
void custom_every_second();
|
||||
|
||||
/* This function is called every 5 seconds */
|
||||
void custom_every_5seconds();
|
||||
|
||||
/* return true if the pin used by the custom code */
|
||||
bool custom_pin_in_use(uint pin);
|
||||
|
||||
/* Add a key which defines a JsonObject to add to the sensor JSON document */
|
||||
void custom_get_sensors(JsonDocument& doc);
|
||||
|
||||
#endif // HASP_USE_CUSTOM
|
||||
|
||||
#endif // HASP_CUSTOM_H
|
@ -107,6 +107,8 @@ class BaseDevice {
|
||||
}
|
||||
virtual void get_info(JsonDocument& doc)
|
||||
{}
|
||||
virtual void get_sensors(JsonDocument& doc)
|
||||
{}
|
||||
virtual bool is_system_pin(uint8_t pin)
|
||||
{
|
||||
return false;
|
||||
|
@ -16,8 +16,12 @@
|
||||
#include "esp32.h"
|
||||
#include "hasp_debug.h"
|
||||
|
||||
#include "../../drv/tft/tft_driver.h" // for haspTft
|
||||
|
||||
#define BACKLIGHT_CHANNEL 0
|
||||
|
||||
uint8_t temprature_sens_read();
|
||||
|
||||
namespace dev {
|
||||
|
||||
static String esp32ResetReason(uint8_t cpuid)
|
||||
@ -210,23 +214,45 @@ void Esp32Device::update_backlight()
|
||||
if(_backlight_invert) duty = 4095 - duty;
|
||||
ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value
|
||||
}
|
||||
|
||||
// haspTft.tft.writecommand(0x53); // Write CTRL Display
|
||||
// if(_backlight_power)
|
||||
// haspTft.tft.writedata(0x24); // BL on, show image
|
||||
// else
|
||||
// haspTft.tft.writedata(0x20); // BL off, white screen
|
||||
|
||||
// // if(_backlight_power)
|
||||
// // haspTft.tft.writecommand(0x29); // BL on, show image
|
||||
// // else
|
||||
// // haspTft.tft.writecommand(0x28); // BL off, white screen
|
||||
|
||||
// // haspTft.tft.writecommand(0x55); // Write Content Adaptive Brightness Control and Color Enhancement
|
||||
// // haspTft.tft.writedata(0x0); // Off
|
||||
|
||||
// haspTft.tft.writecommand(0x5E); // minimum brightness
|
||||
// haspTft.tft.writedata(_backlight_level); // 0-255
|
||||
|
||||
// haspTft.tft.writecommand(0x51); // Write Display Brightness
|
||||
// haspTft.tft.writedata(_backlight_level); // 0-255
|
||||
}
|
||||
|
||||
size_t Esp32Device::get_free_max_block()
|
||||
{
|
||||
return ESP.getMaxAllocHeap();
|
||||
// return ESP.getMaxAllocHeap();
|
||||
return heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
}
|
||||
|
||||
size_t Esp32Device::get_free_heap()
|
||||
{
|
||||
return ESP.getFreeHeap();
|
||||
// return ESP.getFreeHeap();
|
||||
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
}
|
||||
|
||||
uint8_t Esp32Device::get_heap_fragmentation()
|
||||
{
|
||||
uint32_t free = ESP.getFreeHeap();
|
||||
uint32_t free = get_free_heap();
|
||||
if(free) {
|
||||
return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)free);
|
||||
return (int8_t)(100.00f - (float)get_free_max_block() * 100.00f / (float)free);
|
||||
} else {
|
||||
return 100; // no free memory
|
||||
}
|
||||
@ -276,6 +302,18 @@ void Esp32Device::get_info(JsonDocument& doc)
|
||||
info[F(D_INFO_SKETCH_FREE)] = size_buf;
|
||||
}
|
||||
|
||||
void Esp32Device::get_sensors(JsonDocument& doc)
|
||||
{
|
||||
JsonObject sensor = doc.createNestedObject(F("ESP32"));
|
||||
uint32_t temp = (temprature_sens_read() - 32) * 100 / 1.8;
|
||||
sensor[F("Temperature")] = serialized(String(1.0f * temp / 100, 2));
|
||||
}
|
||||
|
||||
long Esp32Device::get_uptime()
|
||||
{
|
||||
return esp_timer_get_time() / 1000000U;
|
||||
}
|
||||
|
||||
} // namespace dev
|
||||
|
||||
#if defined(LANBONL8)
|
||||
|
@ -9,6 +9,16 @@
|
||||
|
||||
#if defined(ESP32)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint8_t temprature_sens_read();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace dev {
|
||||
|
||||
class Esp32Device : public BaseDevice {
|
||||
@ -34,6 +44,8 @@ class Esp32Device : public BaseDevice {
|
||||
uint8_t get_heap_fragmentation() override;
|
||||
uint16_t get_cpu_frequency() override;
|
||||
void get_info(JsonDocument& doc) override;
|
||||
void get_sensors(JsonDocument& doc) override;
|
||||
long get_uptime();
|
||||
|
||||
bool is_system_pin(uint8_t pin) override;
|
||||
|
||||
|
@ -39,6 +39,8 @@ hw_timer_t* timer = NULL; // Instancia do timer
|
||||
esp_adc_cal_characteristics_t* adc_chars =
|
||||
new esp_adc_cal_characteristics_t; // adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
|
||||
|
||||
int16_t watt_10 = 0;
|
||||
|
||||
namespace dev {
|
||||
|
||||
static void check_efuse(void)
|
||||
@ -130,10 +132,24 @@ void LanbonL8::loop_5s()
|
||||
uint32_t newPulses = OverflowCounter * 10000 + PulseCounter;
|
||||
uint32_t delta = newPulses - totalPulses;
|
||||
totalPulses = newPulses;
|
||||
int16_t watt_10 = DEC / 5 * delta * MEASURED_WATTS / MEASURED_PULSES_PER_SECOND;
|
||||
watt_10 = DEC / 5 * delta * MEASURED_WATTS / MEASURED_PULSES_PER_SECOND;
|
||||
int16_t kwh_10 = DEC * totalPulses * MEASURED_WATTS / MEASURED_PULSES_PER_SECOND / 3600 / 1000;
|
||||
LOG_VERBOSE(TAG_DEV, F("Pulse Counter %d.%d W / %d / %d.%d kWh"), watt_10 / DEC, watt_10 % DEC, totalPulses,
|
||||
kwh_10 / DEC, kwh_10 % DEC);
|
||||
// LOG_VERBOSE(TAG_DEV, F("Pulse Counter %d.%d W / %d / %d.%d kWh"), watt_10 / DEC, watt_10 % DEC, totalPulses,
|
||||
// kwh_10 / DEC, kwh_10 % DEC);
|
||||
// uint32_t temp = (temprature_sens_read() - 32) * 100 / 1.8;
|
||||
// LOG_VERBOSE(TAG_DEV, F("Temperature %d C"), temp);
|
||||
}
|
||||
|
||||
void LanbonL8::get_sensors(JsonDocument& doc)
|
||||
{
|
||||
Esp32Device::get_sensors(doc);
|
||||
|
||||
JsonObject sensor = doc.createNestedObject(F("Energy"));
|
||||
|
||||
// int16_t kwh_10 = DEC * totalPulses * MEASURED_WATTS / MEASURED_PULSES_PER_SECOND / 3600 / 1000;
|
||||
|
||||
/* Pulse counter Stats */
|
||||
sensor[F("Power")] = serialized(String(1.0f * watt_10 / DEC, 2));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
@ -16,6 +16,7 @@ class LanbonL8 : public Esp32Device {
|
||||
public:
|
||||
void init();
|
||||
void loop_5s();
|
||||
void get_sensors(JsonDocument& doc);
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
@ -8,17 +8,19 @@
|
||||
#include "AXP192.h" // Power Mgmt
|
||||
#include "dev/esp32/esp32.h"
|
||||
|
||||
AXP192 Axp;
|
||||
|
||||
// AXP192 Axp;
|
||||
namespace dev {
|
||||
|
||||
void M5StackCore2::init(void)
|
||||
{
|
||||
AXP192 Axp;
|
||||
Wire.begin(TOUCH_SDA, TOUCH_SCL);
|
||||
Axp.begin();
|
||||
|
||||
Axp.SetCHGCurrent(AXP192::kCHG_100mA);
|
||||
Axp.SetLcdVoltage(2800);
|
||||
_backlight_power = true;
|
||||
|
||||
Axp.SetBusPowerMode(0);
|
||||
Axp.SetCHGCurrent(AXP192::kCHG_190mA);
|
||||
@ -43,6 +45,52 @@ void M5StackCore2::init(void)
|
||||
Axp.SetLed(1);
|
||||
}
|
||||
|
||||
void M5StackCore2::set_backlight_level(uint8_t level)
|
||||
{
|
||||
_backlight_level = level;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
uint8_t M5StackCore2::get_backlight_level()
|
||||
{
|
||||
return _backlight_level;
|
||||
}
|
||||
|
||||
void M5StackCore2::set_backlight_power(bool power)
|
||||
{
|
||||
_backlight_power = power;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
bool M5StackCore2::get_backlight_power()
|
||||
{
|
||||
return _backlight_power;
|
||||
}
|
||||
|
||||
void M5StackCore2::update_backlight()
|
||||
{
|
||||
if(_backlight_power) {
|
||||
uint16_t voltage = map(_backlight_level, 0, 255, 2500, 3300);
|
||||
Axp.SetLcdVoltage(voltage);
|
||||
} else {
|
||||
Axp.SetDCVoltage(2, 2200);
|
||||
}
|
||||
// Axp.SetDCDC3(_backlight_power); // LCD backlight
|
||||
}
|
||||
|
||||
void M5StackCore2::get_sensors(JsonDocument& doc)
|
||||
{
|
||||
Esp32Device::get_sensors(doc);
|
||||
|
||||
JsonObject sensor = doc.createNestedObject(F("AXP192"));
|
||||
sensor[F("BattVoltage")] = Axp.GetBatVoltage();
|
||||
sensor[F("BattPower")] = Axp.GetBatPower();
|
||||
// sensor[F("Batt%")] = Axp.getBattPercentage();
|
||||
sensor[F("BattChargeCurrent")] = Axp.GetBatChargeCurrent();
|
||||
sensor[F("Temperature")] = Axp.GetTempInAXP192();
|
||||
sensor[F("Charging")] = Axp.isCharging();
|
||||
}
|
||||
|
||||
} // namespace dev
|
||||
|
||||
dev::M5StackCore2 haspDevice;
|
||||
|
@ -13,6 +13,17 @@ namespace dev {
|
||||
class M5StackCore2 : public Esp32Device {
|
||||
public:
|
||||
void init() override;
|
||||
void get_sensors(JsonDocument& doc);
|
||||
|
||||
void set_backlight_level(uint8_t level);
|
||||
uint8_t get_backlight_level();
|
||||
void set_backlight_power(bool power);
|
||||
bool get_backlight_power();
|
||||
void update_backlight();
|
||||
|
||||
private:
|
||||
uint8_t _backlight_level;
|
||||
uint8_t _backlight_power;
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
@ -140,6 +140,11 @@ bool Esp8266Device::is_system_pin(uint8_t pin)
|
||||
return false;
|
||||
}
|
||||
|
||||
long Esp8266Device::get_uptime()
|
||||
{
|
||||
return millis() / 1000U;
|
||||
}
|
||||
|
||||
} // namespace dev
|
||||
|
||||
dev::Esp8266Device haspDevice;
|
||||
|
@ -35,6 +35,7 @@ class Esp8266Device : public BaseDevice {
|
||||
size_t get_free_heap() override;
|
||||
uint8_t get_heap_fragmentation() override;
|
||||
uint16_t get_cpu_frequency() override;
|
||||
long get_uptime();
|
||||
|
||||
bool is_system_pin(uint8_t pin) override;
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#if defined(POSIX)
|
||||
|
||||
#include <cstdint>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/sysinfo.h> // uptime
|
||||
|
||||
#include "hasp_posix.h"
|
||||
|
||||
@ -135,12 +139,16 @@ void PosixDevice::update_backlight()
|
||||
|
||||
size_t PosixDevice::get_free_max_block()
|
||||
{
|
||||
return 0;
|
||||
struct sysinfo s_info;
|
||||
if(sysinfo(&s_info) < 0) return 0;
|
||||
return s_info.freeram;
|
||||
}
|
||||
|
||||
size_t PosixDevice::get_free_heap(void)
|
||||
{
|
||||
return 0;
|
||||
struct sysinfo s_info;
|
||||
if(sysinfo(&s_info) < 0) return 0;
|
||||
return s_info.freeram;
|
||||
}
|
||||
|
||||
uint8_t PosixDevice::get_heap_fragmentation()
|
||||
@ -158,6 +166,13 @@ bool PosixDevice::is_system_pin(uint8_t pin)
|
||||
return false;
|
||||
}
|
||||
|
||||
long PosixDevice::get_uptime()
|
||||
{
|
||||
struct sysinfo s_info;
|
||||
if(sysinfo(&s_info) < 0) return 0;
|
||||
return s_info.uptime;
|
||||
}
|
||||
|
||||
} // namespace dev
|
||||
|
||||
dev::PosixDevice haspDevice;
|
||||
|
@ -50,6 +50,7 @@ class PosixDevice : public BaseDevice {
|
||||
size_t get_free_heap();
|
||||
uint8_t get_heap_fragmentation();
|
||||
uint16_t get_cpu_frequency();
|
||||
long get_uptime();
|
||||
|
||||
bool is_system_pin(uint8_t pin) override;
|
||||
|
||||
|
@ -132,6 +132,11 @@ bool Win32Device::is_system_pin(uint8_t pin)
|
||||
return false;
|
||||
}
|
||||
|
||||
long Win32Device::get_uptime()
|
||||
{
|
||||
return GetTickCount64() / 1000;
|
||||
}
|
||||
|
||||
} // namespace dev
|
||||
|
||||
dev::Win32Device haspDevice;
|
||||
|
@ -71,6 +71,7 @@ class Win32Device : public BaseDevice {
|
||||
size_t get_free_heap();
|
||||
uint8_t get_heap_fragmentation();
|
||||
uint16_t get_cpu_frequency();
|
||||
long get_uptime();
|
||||
|
||||
bool is_system_pin(uint8_t pin) override;
|
||||
|
||||
|
@ -58,6 +58,8 @@ static void scan(TwoWire& i2c)
|
||||
|
||||
void FT6336U_init()
|
||||
{
|
||||
scan(Wire1);
|
||||
|
||||
LOG_INFO(TAG_DRVR, F("Touch SDA : %d"), TOUCH_SDA);
|
||||
LOG_INFO(TAG_DRVR, F("Touch SCL : %d"), TOUCH_SCL);
|
||||
LOG_INFO(TAG_DRVR, F("Touch freq. : %d"), TOUCH_FREQUENCY);
|
||||
@ -78,8 +80,6 @@ void FT6336U_init()
|
||||
Wire1.write(0x00); // data
|
||||
Wire1.endTransmission();
|
||||
|
||||
scan(Wire1);
|
||||
|
||||
if(touchpanel->read_chip_id() != 0) {
|
||||
LOG_INFO(TAG_DRVR, F("FT6336U touch driver started chipid: %d"), touchpanel->read_chip_id());
|
||||
} else {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#if TOUCH_DRIVER == 911
|
||||
/*
|
||||
#if TOUCH_DRIVER == 91100
|
||||
|
||||
#include <Wire.h>
|
||||
#include "Goodix.h"
|
||||
@ -105,4 +106,5 @@ void GT911_loop()
|
||||
{
|
||||
touch.loop();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
*/
|
@ -1,10 +1,11 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
/*
|
||||
#ifndef HASP_DRV_911_H
|
||||
#define HASP_DRV_911_H
|
||||
|
||||
#if TOUCH_DRIVER == 911
|
||||
#if TOUCH_DRIVER == 91100
|
||||
|
||||
#include "hasp_debug.h" // for TAG_DRVR
|
||||
|
||||
@ -13,4 +14,5 @@ void GT911_init();
|
||||
void GT911_loop();
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
*/
|
@ -63,7 +63,7 @@ void drv_touch_init(uint8_t rotation)
|
||||
#endif
|
||||
|
||||
#elif TOUCH_DRIVER == 911
|
||||
GT911_init();
|
||||
// GT911_init();
|
||||
|
||||
#elif TOUCH_DRIVER == 0xADC // Analog Digital Touch Conroller
|
||||
// Touch_init();
|
||||
@ -96,7 +96,7 @@ static inline bool drv_touchpad_getXY(int16_t* touchX, int16_t* touchY)
|
||||
touched = XPT2046_getXY(&normal_x, &normal_y, true);
|
||||
|
||||
#elif TOUCH_DRIVER == 911
|
||||
touched = GT911_getXY(&normal_x, &normal_y, true);
|
||||
// touched = GT911_getXY(&normal_x, &normal_y, true);
|
||||
|
||||
#elif TOUCH_DRIVER == 0xADC // Analog Digital Touch Conroller
|
||||
touched = Touch_getXY(&normal_x, &normal_y, false);
|
||||
@ -221,6 +221,6 @@ IRAM_ATTR bool drv_touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* dat
|
||||
IRAM_ATTR void drv_touch_loop()
|
||||
{
|
||||
#if TOUCH_DRIVER == 911
|
||||
GT911_loop();
|
||||
// GT911_loop();
|
||||
#endif
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
|
||||
#if defined(WINDOWS) || defined(POSIX)
|
||||
|
||||
#include "hasplib.h"
|
||||
#include "lvgl.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
@ -15,6 +16,12 @@
|
||||
#include "dev/device.h"
|
||||
#include "hasp_debug.h"
|
||||
|
||||
#ifdef HASP_CUSTOMIZE_BOOTLOGO
|
||||
#include "custom/bootlogo.h" // Sketch tab header for xbm images
|
||||
#else
|
||||
#include "custom/bootlogo_template.h" // Sketch tab header for xbm images
|
||||
#endif
|
||||
|
||||
namespace dev {
|
||||
|
||||
/**
|
||||
@ -59,6 +66,8 @@ void TftSdl::init(int w, int h)
|
||||
}
|
||||
void TftSdl::show_info()
|
||||
{
|
||||
splashscreen();
|
||||
|
||||
SDL_version linked;
|
||||
SDL_GetVersion(&linked);
|
||||
LOG_VERBOSE(TAG_TFT, F("Driver : SDL2"));
|
||||
@ -67,10 +76,11 @@ void TftSdl::show_info()
|
||||
|
||||
void TftSdl::splashscreen()
|
||||
{
|
||||
// tft.fillScreen(TFT_DARKCYAN);
|
||||
// int x = (tft.width() - logoWidth) / 2;
|
||||
// int y = (tft.height() - logoHeight) / 2;
|
||||
// tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE);
|
||||
uint8_t fg[] = logoFgColor;
|
||||
uint8_t bg[] = logoBgColor;
|
||||
lv_color_t fgColor = lv_color_make(fg[0], fg[1], fg[2]);
|
||||
lv_color_t bgColor = lv_color_make(bg[0], bg[1], bg[2]);
|
||||
monitor_splashscreen(logoImage, logoWidth, logoHeight, lv_color_to32(fgColor), lv_color_to32(bgColor));
|
||||
}
|
||||
void TftSdl::set_rotation(uint8_t rotation)
|
||||
{}
|
||||
|
@ -102,10 +102,15 @@ void TftEspi::show_info()
|
||||
|
||||
void TftEspi::splashscreen()
|
||||
{
|
||||
tft.fillScreen(TFT_DARKCYAN);
|
||||
uint8_t fg[] = logoFgColor;
|
||||
uint8_t bg[] = logoBgColor;
|
||||
lv_color_t fgColor = lv_color_make(fg[0], fg[1], fg[2]);
|
||||
lv_color_t bgColor = lv_color_make(bg[0], bg[1], bg[2]);
|
||||
|
||||
tft.fillScreen(bgColor.full);
|
||||
int x = (tft.width() - logoWidth) / 2;
|
||||
int y = (tft.height() - logoHeight) / 2;
|
||||
tft.drawXBitmap(x, y, bootscreen, logoWidth, logoHeight, TFT_WHITE);
|
||||
tft.drawXBitmap(x, y, logoImage, logoWidth, logoHeight, fgColor.full);
|
||||
}
|
||||
|
||||
void TftEspi::set_rotation(uint8_t rotation)
|
||||
@ -128,18 +133,15 @@ void IRAM_ATTR TftEspi::flush_pixels(lv_disp_drv_t* disp, const lv_area_t* area,
|
||||
{
|
||||
uint32_t w = (area->x2 - area->x1 + 1);
|
||||
uint32_t h = (area->y2 - area->y1 + 1);
|
||||
// size_t len = lv_area_get_size(area);
|
||||
uint32_t len = w * h;
|
||||
|
||||
#ifdef USE_DMA_TO_TFT
|
||||
tft.startWrite(); /* Start new TFT transaction */
|
||||
// tft.setWindow(area->x1, area->y1, area->x2, area->y2);
|
||||
tft.setAddrWindow(area->x1, area->y1, w, h); /* set the working window */
|
||||
tft.pushPixelsDMA((uint16_t*)color_p, len); /* Write words at once */
|
||||
tft.endWrite(); /* terminate TFT transaction */
|
||||
#else
|
||||
tft.startWrite(); /* Start new TFT transaction */
|
||||
// tft.setWindow(area->x1, area->y1, area->x2, area->y2);
|
||||
tft.setAddrWindow(area->x1, area->y1, w, h); /* set the working window */
|
||||
tft.pushPixels((uint16_t*)color_p, len); /* Write words at once */
|
||||
tft.endWrite(); /* terminate TFT transaction */
|
||||
|
@ -15,7 +15,11 @@
|
||||
#include "dev/device.h"
|
||||
#include "hasp_debug.h"
|
||||
|
||||
#include "bootscreen.h" // Sketch tab header for xbm images
|
||||
#ifdef HASP_CUSTOMIZE_BOOTLOGO
|
||||
#include "custom/bootlogo.h" // Sketch tab header for xbm images
|
||||
#else
|
||||
#include "custom/bootlogo_template.h" // Sketch tab header for xbm images
|
||||
#endif
|
||||
|
||||
namespace dev {
|
||||
|
||||
|
@ -17,8 +17,8 @@ class BaseTouch {
|
||||
public:
|
||||
void init(int w, int h)
|
||||
{}
|
||||
void loop()
|
||||
{}
|
||||
// void loop()
|
||||
// {}
|
||||
void show_info()
|
||||
{}
|
||||
void set_rotation(uint8_t rotation)
|
||||
@ -51,15 +51,18 @@ class BaseTouch {
|
||||
#warning Building for XPT2046
|
||||
//#include "touch_driver_xpt2046.h"
|
||||
#include "touch_driver_tftespi.h"
|
||||
#elif TOUCH_DRIVER == 5206
|
||||
#warning Building for FT5206
|
||||
#include "touch_driver_ft5206.h"
|
||||
#elif TOUCH_DRIVER == 6336
|
||||
#warning Building for FT6336
|
||||
#include "touch_driver_ft6336u.h"
|
||||
#elif TOUCH_DRIVER == 610
|
||||
#warning Building for STMPE610
|
||||
#include "touch_driver_stmpe610.h"
|
||||
#elif TOUCH_DRIVER == 5206
|
||||
#warning Building for FT5206
|
||||
#include "touch_driver_ft5206.h"
|
||||
#elif TOUCH_DRIVER == 911
|
||||
#warning Building for GT911
|
||||
#include "touch_driver_gt911.h"
|
||||
#else
|
||||
#warning Building for Generic Touch
|
||||
using dev::BaseTouch;
|
||||
|
110
src/drv/touch/touch_driver_gt911.h
Normal file
110
src/drv/touch/touch_driver_gt911.h
Normal file
@ -0,0 +1,110 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_GT911_TOUCH_DRIVER_H
|
||||
#define HASP_GT911_TOUCH_DRIVER_H
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include "hasp_conf.h"
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Wire.h>
|
||||
#include "Goodix.h"
|
||||
#include "ArduinoLog.h"
|
||||
|
||||
#include "touch_driver.h" // base class
|
||||
|
||||
#include "../../hasp/hasp.h" // for hasp_sleep_state
|
||||
extern uint8_t hasp_sleep_state;
|
||||
|
||||
#define INT_PIN (TOUCH_IRQ)
|
||||
#define RST_PIN (TOUCH_RST) // -1 if pin is connected to VCC else set pin number
|
||||
|
||||
static Goodix touch = Goodix();
|
||||
// static int8_t GT911_num_touches;
|
||||
// static GTPoint* GT911_points;
|
||||
|
||||
// Store touch points into global variable
|
||||
IRAM_ATTR void GT911_setXY(int8_t contacts, GTPoint* points)
|
||||
{
|
||||
// GT911_num_touches = contacts;
|
||||
// GT911_points = points;
|
||||
|
||||
// LOG_VERBOSE(TAG_GUI, F("Contacts: %d"), contacts);
|
||||
// for(int i = 0; i < contacts; i++) {
|
||||
// LOG_VERBOSE(TAG_GUI, F("C%d: #%d %d,%d s:%d"), i, points[i].trackId, points[i].x, points[i].y,
|
||||
// points[i].area); yield();
|
||||
// }
|
||||
}
|
||||
|
||||
IRAM_ATTR bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
// LOG_VERBOSE(TAG_GUI, F("Contacts: %d"), GT911_num_touches);
|
||||
static GTPoint points[5];
|
||||
|
||||
if(touch.readInput((uint8_t*)&points)>0) {
|
||||
|
||||
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
|
||||
|
||||
data->point.x = points[0].x;
|
||||
data->point.y = points[0].y;
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
touch.loop(); // reset IRQ
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace dev {
|
||||
|
||||
class TouchGt911 : public BaseTouch {
|
||||
|
||||
public:
|
||||
IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
return touch_read(indev_driver, data);
|
||||
}
|
||||
|
||||
void init(int w, int h)
|
||||
{
|
||||
Wire.begin(TOUCH_SDA, TOUCH_SCL, I2C_TOUCH_FREQUENCY);
|
||||
delay(300);
|
||||
|
||||
touch.setHandler(GT911_setXY);
|
||||
|
||||
if(touch.begin(INT_PIN, RST_PIN)) {
|
||||
LOG_VERBOSE(TAG_DRVR, F("Goodix GT911 reset OK"));
|
||||
} else {
|
||||
LOG_WARNING(TAG_DRVR, F("Goodix GT911 reset failed"));
|
||||
}
|
||||
|
||||
Serial.print("Check ACK on addr request on 0x");
|
||||
// Serial.print(touch.i2cAddr, HEX);
|
||||
|
||||
// Wire.beginTransmission(touch.i2cAddr);
|
||||
int error;
|
||||
// = Wire.endTransmission();
|
||||
if(error == 0) {
|
||||
// Serial.println(": SUCCESS");
|
||||
} else {
|
||||
// Serial.print(": ERROR #");
|
||||
// Serial.println(error);
|
||||
}
|
||||
|
||||
LOG_INFO(TAG_DRVR, F("Goodix GT911 touch driver started"));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
||||
using dev::TouchGt911;
|
||||
extern dev::TouchGt911 haspTouch;
|
||||
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // HASP_GT911_TOUCH_DRIVER_H
|
20
src/font/MaterialDesign-Webfont/LICENSE
Normal file
20
src/font/MaterialDesign-Webfont/LICENSE
Normal file
@ -0,0 +1,20 @@
|
||||
Pictogrammers Free License
|
||||
--------------------------
|
||||
|
||||
This icon collection is released as free, open source, and GPL friendly by
|
||||
the [Pictogrammers](http://pictogrammers.com/) icon group. You may use it
|
||||
for commercial projects, open source projects, or anything really.
|
||||
|
||||
# Icons: Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
|
||||
Some of the icons are redistributed under the Apache 2.0 license. All other
|
||||
icons are either redistributed under their respective licenses or are
|
||||
distributed under the Apache 2.0 license.
|
||||
|
||||
# Fonts: Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
|
||||
All web and desktop fonts are distributed under the Apache 2.0 license. Web
|
||||
and desktop fonts contain some icons that are redistributed under the Apache
|
||||
2.0 license. All other icons are either redistributed under their respective
|
||||
licenses or are distributed under the Apache 2.0 license.
|
||||
|
||||
# Code: MIT (https://opensource.org/licenses/MIT)
|
||||
The MIT license applies to all non-font and non-icon files.
|
BIN
src/font/MaterialDesign-Webfont/materialdesignicons-webfont.ttf
Normal file
BIN
src/font/MaterialDesign-Webfont/materialdesignicons-webfont.ttf
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
317
src/font/encodings.json
Normal file
317
src/font/encodings.json
Normal file
@ -0,0 +1,317 @@
|
||||
{
|
||||
"ascii": {
|
||||
"cpp": "src/font/ascii/robotocondensed_regular_{}_ascii.cpp",
|
||||
"size": [
|
||||
12,
|
||||
14,
|
||||
16,
|
||||
20,
|
||||
22,
|
||||
24,
|
||||
26,
|
||||
28,
|
||||
32,
|
||||
36,
|
||||
38,
|
||||
40,
|
||||
44,
|
||||
48
|
||||
],
|
||||
"textfont": "src/font/roboto/RobotoCondensed-Regular.ttf",
|
||||
"iconfont": "src/font/materialdesignicons-webfont.ttf",
|
||||
"chars": {
|
||||
"ASCII range": "0x20-0x7E",
|
||||
"Non-breaking space": "0xA0",
|
||||
"Pound sign": "0xA3",
|
||||
"Degree symbol": "0xB0",
|
||||
"Plus-minus sign": "0xB1",
|
||||
"Superscript two": "0xB2",
|
||||
"Superscript three": "0xB3",
|
||||
"Micro sign": "0xB5",
|
||||
"Multiplication sign": "0xD7",
|
||||
"Division sign": "0xF7",
|
||||
"Bullet Symbol": "0x2022",
|
||||
"Euro Symbol": "0x20AC"
|
||||
}
|
||||
},
|
||||
"latin1": {
|
||||
"cpp": "src/font/latin1/robotocondensed_regular_{}_latin1.cpp",
|
||||
"size": [
|
||||
12,
|
||||
14,
|
||||
16,
|
||||
20,
|
||||
22,
|
||||
24,
|
||||
26,
|
||||
28,
|
||||
32,
|
||||
36,
|
||||
38,
|
||||
40,
|
||||
44,
|
||||
48
|
||||
],
|
||||
"textfont": "src/font/roboto/RobotoCondensed-Regular.ttf",
|
||||
"iconfont": "src/font/materialdesignicons-webfont.ttf",
|
||||
"chars": {
|
||||
"ASCII range": "0x20-0x7E",
|
||||
"Non-breaking space": "0xA0",
|
||||
"Inverted exclamation mark": "0xA1",
|
||||
"Pound sign": "0xA3",
|
||||
"Degree symbol": "0xB0",
|
||||
"Plus-minus sign": "0xB1",
|
||||
"Superscript two": "0xB2",
|
||||
"Superscript three": "0xB3",
|
||||
"Micro sign": "0xB5",
|
||||
"Inverted question mark": "0xBF",
|
||||
"Capital A with grave": "0xC0",
|
||||
"Capital A with acute": "0xC1",
|
||||
"Capital A with circumflex": "0xC2",
|
||||
"Capital A with tilde": "0xC3",
|
||||
"Capital A with diaeresis": "0xC4",
|
||||
"Capital A with ring above": "0xC5",
|
||||
"Capital AE": "0xC6",
|
||||
"Capital C with cedilla": "0xC7",
|
||||
"Capital E with grave": "0xC8",
|
||||
"Capital E with acute": "0xC9",
|
||||
"Capital E with circumflex": "0xCA",
|
||||
"Capital E with diaeresis": "0xCB",
|
||||
"Capital I with grave": "0xCC",
|
||||
"Capital I with acute": "0xCD",
|
||||
"Capital I with circumflex": "0xCE",
|
||||
"Capital I with diaeresis": "0xCF",
|
||||
"Capital Eth": "0xD0",
|
||||
"Capital N with tilde": "0xD1",
|
||||
"Capital O with grave": "0xD2",
|
||||
"Capital O with acute": "0xD3",
|
||||
"Capital O with circumflex": "0xD4",
|
||||
"Capital O with tilde": "0xD5",
|
||||
"Capital O with diaeresis": "0xD6",
|
||||
"Multiplication sign": "0xD7",
|
||||
"Capital O with stroke": "0xD8",
|
||||
"Capital U with grave": "0xD9",
|
||||
"Capital U with acute": "0xDA",
|
||||
"Capital U with circumflex": "0xDB",
|
||||
"Capital U with diaeresis": "0xDC",
|
||||
"Capital Y with acute": "0xDD",
|
||||
"Capital Thorn": "0xDE",
|
||||
"Small sharp S": "0xDF",
|
||||
"Small A with grave": "0xE0",
|
||||
"Small A with acute": "0xE1",
|
||||
"Small A with circumflex": "0xE2",
|
||||
"Small A with tilde": "0xE3",
|
||||
"Small A with diaeresis": "0xE4",
|
||||
"Small A with ring above": "0xE5",
|
||||
"Small AE": "0xE6",
|
||||
"Small C with cedilla": "0xE7",
|
||||
"Small E with grave": "0xE8",
|
||||
"Small E with acute": "0xE9",
|
||||
"Small E with circumflex": "0xEA",
|
||||
"Small E with diaeresis": "0xEB",
|
||||
"Small I with grave": "0xEC",
|
||||
"Small I with acute": "0xED",
|
||||
"Small I with circumflex": "0xEE",
|
||||
"Small I with diaeresis": "0xEF",
|
||||
"Small Eth": "0xF0",
|
||||
"Small N with tilde": "0xF1",
|
||||
"Small O with grave": "0xF2",
|
||||
"Small O with acute": "0xF3",
|
||||
"Small O with circumflex": "0xF4",
|
||||
"Small O with tilde": "0xF5",
|
||||
"Small O with diaeresis": "0xF6",
|
||||
"Division sign": "0xF7",
|
||||
"Small O with stroke": "0xF8",
|
||||
"Small U with grave": "0xF9",
|
||||
"Small U with acute": "0xFA",
|
||||
"Small U with circumflex": "0xFB",
|
||||
"Small U with diaeresis": "0xFC",
|
||||
"Small Y with acute": "0xFD",
|
||||
"Small Thorn": "0xFE",
|
||||
"Small Y with diaeresis": "0xFF",
|
||||
"G with breve": "0x011E-0x011F",
|
||||
"Capital I with dot above": "0x0130",
|
||||
"Small dotless I": "0x0131",
|
||||
"Ligature OE": "0x0152-0x0153",
|
||||
"S with cedilla": "0x015E-0x015F",
|
||||
"S with caron": "0x0160-0x0161",
|
||||
"Z with caron": "0x017D-0x017E",
|
||||
"Capital Letter Sharp S": "0x1E9E",
|
||||
"Bullet Symbol": "0x2022",
|
||||
"Euro Symbol": "0x20AC"
|
||||
}
|
||||
},
|
||||
"latin2": {
|
||||
"cpp": "src/font/latin2/robotocondensed_regular_{}_latin2.cpp",
|
||||
"size": [
|
||||
12,
|
||||
14,
|
||||
16,
|
||||
20,
|
||||
22,
|
||||
24,
|
||||
26,
|
||||
28,
|
||||
32,
|
||||
36,
|
||||
38,
|
||||
40,
|
||||
44,
|
||||
48
|
||||
],
|
||||
"textfont": "src/font/roboto/RobotoCondensed-Regular.ttf",
|
||||
"iconfont": "src/font/materialdesignicons-webfont.ttf",
|
||||
"chars": {
|
||||
"ASCII range": "0x20-0x7E",
|
||||
"Non-breaking space": "0xA0",
|
||||
"Pound sign": "0xA3",
|
||||
"Degree symbol": "0xB0",
|
||||
"Plus-minus sign": "0xB1",
|
||||
"Superscript two": "0xB2",
|
||||
"Superscript three": "0xB3",
|
||||
"Micro sign": "0xB5",
|
||||
"Capital A with acute": "0xC1",
|
||||
"Capital A with circumflex": "0xC2",
|
||||
"Capital A with diaeresis": "0x00C4",
|
||||
"Capital E with acute": "0xC9",
|
||||
"Capital E with diaeresis": "0x00CB",
|
||||
"Capital I with acute": "0xCD",
|
||||
"Capital I with circumflex": "0xCE",
|
||||
"Capital O with acute": "0xD3",
|
||||
"Capital O with circumflex": "0x00D4",
|
||||
"Capital O with diaeresis": "0xD6",
|
||||
"Multiplication sign": "0xD7",
|
||||
"Capital U with acute": "0xDA",
|
||||
"Capital U with diaeresis": "0xDC",
|
||||
"Capital Y with acute": "0xDD",
|
||||
"Small A with acute": "0xE1",
|
||||
"Small A with circumflex": "0xE2",
|
||||
"Small A with diaeresis": "0x00E4",
|
||||
"Small E with acute": "0xE9",
|
||||
"Small I with acute": "0xED",
|
||||
"Small I with circumflex": "0xEE",
|
||||
"Small O with acute": "0xF3",
|
||||
"Small O with circumflex": "0x00F4",
|
||||
"Small O with diaeresis": "0xF6",
|
||||
"Division sign": "0xF7",
|
||||
"Small U with acute": "0xFA",
|
||||
"Small U with diaeresis": "0xFC",
|
||||
"Small Y with acute": "0x00FD",
|
||||
"A with breve": "0x0102-0x0103",
|
||||
"A with ogonek": "0x0104-0x0105",
|
||||
"C with acute": "0x0106-0x0107",
|
||||
"C with caron": "0x010C-0x010D",
|
||||
"D with caron": "0x010E-0x010F",
|
||||
"D with stroke": "0x0110-0x0111",
|
||||
"E with breve": "0x0114-0x0115",
|
||||
"E with ogonek": "0x0118-0x0119",
|
||||
"E with caron": "0x011A-0x011B",
|
||||
"L with acute": "0x0139-0x013A",
|
||||
"L with caron": "0x013D-0x013E",
|
||||
"L with stroke": "0x0141-0x0142",
|
||||
"N with acute": "0x0143-0x0144",
|
||||
"N with caron": "0x0147-0x0148",
|
||||
"O with double acute": "0x0150-0x0151",
|
||||
"Capital R with acute": "0x0154-0x0155",
|
||||
"R with caron": "0x0158-0x0159",
|
||||
"S with acute": "0x015A-0x015B",
|
||||
"S with cedilla": "0x015E-0x015F",
|
||||
"S with caron": "0x0160-0x0161",
|
||||
"T with cedilla": "0x0162-0x0163",
|
||||
"T with caron": "0x0164-0X0165",
|
||||
"U with ring above": "0x016E-0x016F",
|
||||
"U with double acute": "0x0170-0x0171",
|
||||
"Z with acute": "0x0179-0x017A",
|
||||
"Z with dot above": "0x017B-0x017C",
|
||||
"Z with caron": "0x017D-0x017E",
|
||||
// "Serbo-Croatian Digraphs": "0x01C4-0x01CC", // Usually written as separate letters
|
||||
"A with Caron": "0x01CD-0x01CE",
|
||||
"HR-SL-RO letters": "0x0200-0x021B",
|
||||
"Bullet Symbol": "0x2022",
|
||||
"Euro Symbol": "0x20AC"
|
||||
}
|
||||
},
|
||||
"cyrillic": {
|
||||
"cpp": "src/font/cyrillic/robotocondensed_regular_{}_cyrillic.cpp",
|
||||
"size": [
|
||||
12,
|
||||
14,
|
||||
16,
|
||||
20,
|
||||
22,
|
||||
24,
|
||||
26,
|
||||
28,
|
||||
32,
|
||||
36,
|
||||
38,
|
||||
40,
|
||||
44,
|
||||
48
|
||||
],
|
||||
"textfont": "src/font/roboto/RobotoCondensed-Regular.ttf",
|
||||
"iconfont": "src/font/materialdesignicons-webfont.ttf",
|
||||
"chars": {
|
||||
"ASCII range": "0x20-0x7E",
|
||||
"Non-breaking space": "0xA0",
|
||||
"Pound sign": "0xA3",
|
||||
"0xA7": "0xA7",
|
||||
"0xAD": "0xAD",
|
||||
"Degree symbol": "0xB0",
|
||||
"Plus-minus sign": "0xB1",
|
||||
"Superscript two": "0xB2",
|
||||
"Superscript three": "0xB3",
|
||||
"Micro sign": "0xB5",
|
||||
"Multiplication sign": "0xD7",
|
||||
"Division sign": "0xF7",
|
||||
"Cyrillic extensions 1": "0x0400-0x040F",
|
||||
"Basic Cyrillic alphabet": "0x0410-0x044F",
|
||||
"Cyrillic extensions 2": "0x0450-0x045F",
|
||||
"Bullet Symbol": "0x2022",
|
||||
"Euro Symbol": "0x20AC"
|
||||
}
|
||||
},
|
||||
"greek": {
|
||||
"cpp": "src/font/greek/robotocondensed_regular_{}_greek.cpp",
|
||||
"size": [
|
||||
12,
|
||||
14,
|
||||
16,
|
||||
20,
|
||||
22,
|
||||
24,
|
||||
26,
|
||||
28,
|
||||
32,
|
||||
36,
|
||||
38,
|
||||
40,
|
||||
44,
|
||||
48
|
||||
],
|
||||
"textfont": "src/font/roboto/RobotoCondensed-Regular.ttf",
|
||||
"iconfont": "src/font/materialdesignicons-webfont.ttf",
|
||||
"chars": {
|
||||
"ASCII range": "0x20-0x7E",
|
||||
"Non-breaking space": "0xA0",
|
||||
"Pound sign": "0xA3",
|
||||
"0xA7": "0xA7",
|
||||
"0xAD": "0xAD",
|
||||
"Degree symbol": "0xB0",
|
||||
"Plus-minus sign": "0xB1",
|
||||
"Superscript two": "0xB2",
|
||||
"Superscript three": "0xB3",
|
||||
"Micro sign": "0xB5",
|
||||
"Multiplication sign": "0xD7",
|
||||
"Division sign": "0xF7",
|
||||
"Greek Capital Letter Alpha with Tonos": "0x0386",
|
||||
"Greek capital letters": "0x388-0x3A9",
|
||||
"Greek small letters": "0x3AC-0x3CE",
|
||||
// "Greek Theta Symbol": "0x03D1",
|
||||
// "Greek Upsilon with Hook Symbol": "0x03D2",
|
||||
// "Greek Pi Symbol": "0x03D6",
|
||||
"Bullet Symbol": "0x2022",
|
||||
"Euro Symbol": "0x20AC"
|
||||
}
|
||||
}
|
||||
}
|
2071
src/font/greek/robotocondensed_regular_12_greek.cpp
Normal file
2071
src/font/greek/robotocondensed_regular_12_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2323
src/font/greek/robotocondensed_regular_14_greek.cpp
Normal file
2323
src/font/greek/robotocondensed_regular_14_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2519
src/font/greek/robotocondensed_regular_16_greek.cpp
Normal file
2519
src/font/greek/robotocondensed_regular_16_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
3031
src/font/greek/robotocondensed_regular_20_greek.cpp
Normal file
3031
src/font/greek/robotocondensed_regular_20_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
3312
src/font/greek/robotocondensed_regular_22_greek.cpp
Normal file
3312
src/font/greek/robotocondensed_regular_22_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
3455
src/font/greek/robotocondensed_regular_24_greek.cpp
Normal file
3455
src/font/greek/robotocondensed_regular_24_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
3867
src/font/greek/robotocondensed_regular_26_greek.cpp
Normal file
3867
src/font/greek/robotocondensed_regular_26_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
4199
src/font/greek/robotocondensed_regular_28_greek.cpp
Normal file
4199
src/font/greek/robotocondensed_regular_28_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
4802
src/font/greek/robotocondensed_regular_32_greek.cpp
Normal file
4802
src/font/greek/robotocondensed_regular_32_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
5549
src/font/greek/robotocondensed_regular_36_greek.cpp
Normal file
5549
src/font/greek/robotocondensed_regular_36_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
5881
src/font/greek/robotocondensed_regular_38_greek.cpp
Normal file
5881
src/font/greek/robotocondensed_regular_38_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
6216
src/font/greek/robotocondensed_regular_40_greek.cpp
Normal file
6216
src/font/greek/robotocondensed_regular_40_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
6880
src/font/greek/robotocondensed_regular_44_greek.cpp
Normal file
6880
src/font/greek/robotocondensed_regular_44_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
7344
src/font/greek/robotocondensed_regular_48_greek.cpp
Normal file
7344
src/font/greek/robotocondensed_regular_48_greek.cpp
Normal file
File diff suppressed because it is too large
Load Diff
681
src/font/hasp_font_loader.cpp
Normal file
681
src/font/hasp_font_loader.cpp
Normal file
@ -0,0 +1,681 @@
|
||||
/**
|
||||
* @file hasp_font_loader.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "lv_misc/lv_fs.h"
|
||||
#include "hasp_font_loader.h"
|
||||
|
||||
#include "hasplib.h"
|
||||
|
||||
#if LV_USE_FILESYSTEM
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef struct
|
||||
{
|
||||
lv_fs_file_t* fp;
|
||||
int8_t bit_pos;
|
||||
uint8_t byte_value;
|
||||
} bit_iterator_t;
|
||||
|
||||
typedef struct font_header_bin
|
||||
{
|
||||
uint32_t version;
|
||||
uint16_t tables_count;
|
||||
uint16_t font_size;
|
||||
uint16_t ascent;
|
||||
int16_t descent;
|
||||
uint16_t typo_ascent;
|
||||
int16_t typo_descent;
|
||||
uint16_t typo_line_gap;
|
||||
int16_t min_y;
|
||||
int16_t max_y;
|
||||
uint16_t default_advance_width;
|
||||
uint16_t kerning_scale;
|
||||
uint8_t index_to_loc_format;
|
||||
uint8_t glyph_id_format;
|
||||
uint8_t advance_width_format;
|
||||
uint8_t bits_per_pixel;
|
||||
uint8_t xy_bits;
|
||||
uint8_t wh_bits;
|
||||
uint8_t advance_width_bits;
|
||||
uint8_t compression_id;
|
||||
uint8_t subpixels_mode;
|
||||
uint8_t padding;
|
||||
int16_t underline_position;
|
||||
uint16_t underline_thickness;
|
||||
} font_header_bin_t;
|
||||
|
||||
typedef struct cmap_table_bin
|
||||
{
|
||||
uint32_t data_offset;
|
||||
uint32_t range_start;
|
||||
uint16_t range_length;
|
||||
uint16_t glyph_id_start;
|
||||
uint16_t data_entries_count;
|
||||
uint8_t format_type;
|
||||
uint8_t padding;
|
||||
} cmap_table_bin_t;
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bit_iterator_t init_bit_iterator(lv_fs_file_t* fp);
|
||||
static bool lvgl_load_font(lv_fs_file_t* fp, lv_font_t* font);
|
||||
int32_t load_kern(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc, uint8_t format, uint32_t start);
|
||||
|
||||
static int read_bits_signed(bit_iterator_t* it, int n_bits, lv_fs_res_t* res);
|
||||
static unsigned int read_bits(bit_iterator_t* it, int n_bits, lv_fs_res_t* res);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Loads a `lv_font_t` object from a binary font file
|
||||
* @param font_name filename where the font file is located
|
||||
* @return a pointer to the font or NULL in case of error
|
||||
*/
|
||||
lv_font_t* hasp_font_load(const char* font_name)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
lv_font_t* font = (lv_font_t*)malloc(sizeof(lv_font_t));
|
||||
memset(font, 0, sizeof(lv_font_t));
|
||||
|
||||
lv_fs_file_t file;
|
||||
lv_fs_res_t res = lv_fs_open(&file, font_name, LV_FS_MODE_RD);
|
||||
|
||||
if(res == LV_FS_RES_OK) {
|
||||
success = lvgl_load_font(&file, font);
|
||||
|
||||
if(!success) {
|
||||
LOG_WARNING(TAG_FONT, "Error loading font file: %s\n", font_name);
|
||||
/*
|
||||
* When `lvgl_load_font` fails it can leak some pointers.
|
||||
* All non-null pointers can be assumed as allocated and
|
||||
* `lv_font_free` should free them correctly.
|
||||
*/
|
||||
hasp_font_free(font);
|
||||
font = NULL;
|
||||
}
|
||||
|
||||
lv_fs_close(&file);
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the memory allocated by the `lv_font_load()` function
|
||||
* @param font lv_font_t object created by the lv_font_load function
|
||||
*/
|
||||
void hasp_font_free(lv_font_t* font)
|
||||
{
|
||||
if(NULL != font) {
|
||||
lv_font_fmt_txt_dsc_t* dsc = (lv_font_fmt_txt_dsc_t*)font->dsc;
|
||||
|
||||
if(NULL != dsc) {
|
||||
|
||||
if(dsc->kern_classes == 0) {
|
||||
lv_font_fmt_txt_kern_pair_t* kern_dsc = (lv_font_fmt_txt_kern_pair_t*)dsc->kern_dsc;
|
||||
|
||||
if(NULL != kern_dsc) {
|
||||
if(kern_dsc->glyph_ids) free((void*)kern_dsc->glyph_ids);
|
||||
|
||||
if(kern_dsc->values) free((void*)kern_dsc->values);
|
||||
|
||||
free((void*)kern_dsc);
|
||||
}
|
||||
} else {
|
||||
lv_font_fmt_txt_kern_classes_t* kern_dsc = (lv_font_fmt_txt_kern_classes_t*)dsc->kern_dsc;
|
||||
|
||||
if(NULL != kern_dsc) {
|
||||
if(kern_dsc->class_pair_values) free((void*)kern_dsc->class_pair_values);
|
||||
|
||||
if(kern_dsc->left_class_mapping) free((void*)kern_dsc->left_class_mapping);
|
||||
|
||||
if(kern_dsc->right_class_mapping) free((void*)kern_dsc->right_class_mapping);
|
||||
|
||||
free((void*)kern_dsc);
|
||||
}
|
||||
}
|
||||
|
||||
lv_font_fmt_txt_cmap_t* cmaps = (lv_font_fmt_txt_cmap_t*)dsc->cmaps;
|
||||
|
||||
if(NULL != cmaps) {
|
||||
for(int i = 0; i < dsc->cmap_num; ++i) {
|
||||
if(NULL != cmaps[i].glyph_id_ofs_list) free((void*)cmaps[i].glyph_id_ofs_list);
|
||||
if(NULL != cmaps[i].unicode_list) free((void*)cmaps[i].unicode_list);
|
||||
}
|
||||
free(cmaps);
|
||||
}
|
||||
|
||||
if(NULL != dsc->glyph_bitmap) {
|
||||
free((void*)dsc->glyph_bitmap);
|
||||
}
|
||||
if(NULL != dsc->glyph_dsc) {
|
||||
free((void*)dsc->glyph_dsc);
|
||||
}
|
||||
free(dsc);
|
||||
}
|
||||
free(font);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static bit_iterator_t init_bit_iterator(lv_fs_file_t* fp)
|
||||
{
|
||||
bit_iterator_t it;
|
||||
it.fp = fp;
|
||||
it.bit_pos = -1;
|
||||
it.byte_value = 0;
|
||||
return it;
|
||||
}
|
||||
|
||||
static unsigned int read_bits(bit_iterator_t* it, int n_bits, lv_fs_res_t* res)
|
||||
{
|
||||
unsigned int value = 0;
|
||||
while(n_bits--) {
|
||||
it->byte_value = it->byte_value << 1;
|
||||
it->bit_pos--;
|
||||
|
||||
if(it->bit_pos < 0) {
|
||||
it->bit_pos = 7;
|
||||
*res = lv_fs_read(it->fp, &(it->byte_value), 1, NULL);
|
||||
if(*res != LV_FS_RES_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int8_t bit = (it->byte_value & 0x80) ? 1 : 0;
|
||||
|
||||
value |= (bit << n_bits);
|
||||
}
|
||||
*res = LV_FS_RES_OK;
|
||||
return value;
|
||||
}
|
||||
|
||||
static int read_bits_signed(bit_iterator_t* it, int n_bits, lv_fs_res_t* res)
|
||||
{
|
||||
unsigned int value = read_bits(it, n_bits, res);
|
||||
if(value & (1 << (n_bits - 1))) {
|
||||
value |= ~0u << n_bits;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static int read_label(lv_fs_file_t* fp, int start, const char* label)
|
||||
{
|
||||
lv_fs_seek(fp, start);
|
||||
|
||||
uint32_t length;
|
||||
char buf[4];
|
||||
|
||||
if(lv_fs_read(fp, &length, 4, NULL) != LV_FS_RES_OK || lv_fs_read(fp, buf, 4, NULL) != LV_FS_RES_OK ||
|
||||
memcmp(label, buf, 4) != 0) {
|
||||
LOG_WARNING(TAG_FONT, "Error reading '%s' label.", label);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
static bool load_cmaps_tables(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc, uint32_t cmaps_start,
|
||||
cmap_table_bin_t* cmap_table)
|
||||
{
|
||||
if(lv_fs_read(fp, cmap_table, font_dsc->cmap_num * sizeof(cmap_table_bin_t), NULL) != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < font_dsc->cmap_num; ++i) {
|
||||
lv_fs_res_t res = lv_fs_seek(fp, cmaps_start + cmap_table[i].data_offset);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
lv_font_fmt_txt_cmap_t* cmap = (lv_font_fmt_txt_cmap_t*)&(font_dsc->cmaps[i]);
|
||||
|
||||
cmap->range_start = cmap_table[i].range_start;
|
||||
cmap->range_length = cmap_table[i].range_length;
|
||||
cmap->glyph_id_start = cmap_table[i].glyph_id_start;
|
||||
cmap->type = cmap_table[i].format_type;
|
||||
|
||||
switch(cmap_table[i].format_type) {
|
||||
case LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL: {
|
||||
uint8_t ids_size = sizeof(uint8_t) * cmap_table[i].data_entries_count;
|
||||
uint8_t* glyph_id_ofs_list = (uint8_t*)malloc(ids_size);
|
||||
|
||||
cmap->glyph_id_ofs_list = glyph_id_ofs_list;
|
||||
|
||||
if(lv_fs_read(fp, glyph_id_ofs_list, ids_size, NULL) != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cmap->list_length = cmap->range_length;
|
||||
break;
|
||||
}
|
||||
case LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY:
|
||||
break;
|
||||
case LV_FONT_FMT_TXT_CMAP_SPARSE_FULL:
|
||||
case LV_FONT_FMT_TXT_CMAP_SPARSE_TINY: {
|
||||
uint32_t list_size = sizeof(uint16_t) * cmap_table[i].data_entries_count;
|
||||
uint16_t* unicode_list = (uint16_t*)malloc(list_size);
|
||||
|
||||
cmap->unicode_list = unicode_list;
|
||||
cmap->list_length = cmap_table[i].data_entries_count;
|
||||
|
||||
if(lv_fs_read(fp, unicode_list, list_size, NULL) != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(cmap_table[i].format_type == LV_FONT_FMT_TXT_CMAP_SPARSE_FULL) {
|
||||
uint16_t* buf = (uint16_t*)malloc(sizeof(uint16_t) * cmap->list_length);
|
||||
|
||||
cmap->glyph_id_ofs_list = buf;
|
||||
|
||||
if(lv_fs_read(fp, buf, sizeof(uint16_t) * cmap->list_length, NULL) != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_WARNING(TAG_FONT, "Unknown cmaps format type %d.", cmap_table[i].format_type);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t load_cmaps(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc, uint32_t cmaps_start)
|
||||
{
|
||||
int32_t cmaps_length = read_label(fp, cmaps_start, "cmap");
|
||||
if(cmaps_length < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t cmaps_subtables_count;
|
||||
if(lv_fs_read(fp, &cmaps_subtables_count, sizeof(uint32_t), NULL) != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
lv_font_fmt_txt_cmap_t* cmaps =
|
||||
(lv_font_fmt_txt_cmap_t*)malloc(cmaps_subtables_count * sizeof(lv_font_fmt_txt_cmap_t));
|
||||
|
||||
memset(cmaps, 0, cmaps_subtables_count * sizeof(lv_font_fmt_txt_cmap_t));
|
||||
|
||||
font_dsc->cmaps = cmaps;
|
||||
font_dsc->cmap_num = cmaps_subtables_count;
|
||||
|
||||
cmap_table_bin_t* cmaps_tables = (cmap_table_bin_t*)malloc(sizeof(cmap_table_bin_t) * font_dsc->cmap_num);
|
||||
|
||||
bool success = load_cmaps_tables(fp, font_dsc, cmaps_start, cmaps_tables);
|
||||
|
||||
free(cmaps_tables);
|
||||
|
||||
return success ? cmaps_length : -1;
|
||||
}
|
||||
|
||||
static int32_t load_glyph(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc, uint32_t start, uint32_t* glyph_offset,
|
||||
uint32_t loca_count, font_header_bin_t* header)
|
||||
{
|
||||
int32_t glyph_length = read_label(fp, start, "glyf");
|
||||
if(glyph_length < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
lv_font_fmt_txt_glyph_dsc_t* glyph_dsc =
|
||||
(lv_font_fmt_txt_glyph_dsc_t*)malloc(loca_count * sizeof(lv_font_fmt_txt_glyph_dsc_t));
|
||||
|
||||
memset(glyph_dsc, 0, loca_count * sizeof(lv_font_fmt_txt_glyph_dsc_t));
|
||||
|
||||
font_dsc->glyph_dsc = glyph_dsc;
|
||||
|
||||
int cur_bmp_size = 0;
|
||||
|
||||
for(unsigned int i = 0; i < loca_count; ++i) {
|
||||
lv_font_fmt_txt_glyph_dsc_t* gdsc = &glyph_dsc[i];
|
||||
|
||||
lv_fs_res_t res = lv_fs_seek(fp, start + glyph_offset[i]);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bit_iterator_t bit_it = init_bit_iterator(fp);
|
||||
|
||||
if(header->advance_width_bits == 0) {
|
||||
gdsc->adv_w = header->default_advance_width;
|
||||
} else {
|
||||
gdsc->adv_w = read_bits(&bit_it, header->advance_width_bits, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(header->advance_width_format == 0) {
|
||||
gdsc->adv_w *= 16;
|
||||
}
|
||||
|
||||
gdsc->ofs_x = read_bits_signed(&bit_it, header->xy_bits, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
gdsc->ofs_y = read_bits_signed(&bit_it, header->xy_bits, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
gdsc->box_w = read_bits(&bit_it, header->wh_bits, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
gdsc->box_h = read_bits(&bit_it, header->wh_bits, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nbits = header->advance_width_bits + 2 * header->xy_bits + 2 * header->wh_bits;
|
||||
int next_offset = (i < loca_count - 1) ? glyph_offset[i + 1] : (uint32_t)glyph_length;
|
||||
int bmp_size = next_offset - glyph_offset[i] - nbits / 8;
|
||||
|
||||
if(i == 0) {
|
||||
gdsc->adv_w = 0;
|
||||
gdsc->box_w = 0;
|
||||
gdsc->box_h = 0;
|
||||
gdsc->ofs_x = 0;
|
||||
gdsc->ofs_y = 0;
|
||||
}
|
||||
|
||||
gdsc->bitmap_index = cur_bmp_size;
|
||||
if(gdsc->box_w * gdsc->box_h != 0) {
|
||||
cur_bmp_size += bmp_size;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* glyph_bmp;
|
||||
#ifdef ESP32
|
||||
if(psramFound())
|
||||
glyph_bmp = (uint8_t*)ps_malloc(sizeof(uint8_t) * cur_bmp_size);
|
||||
else
|
||||
glyph_bmp = (uint8_t*)malloc(sizeof(uint8_t) * cur_bmp_size);
|
||||
#else
|
||||
glyph_bmp = (uint8_t*)malloc(sizeof(uint8_t) * cur_bmp_size);
|
||||
#endif
|
||||
|
||||
font_dsc->glyph_bitmap = glyph_bmp;
|
||||
|
||||
cur_bmp_size = 0;
|
||||
|
||||
for(unsigned int i = 1; i < loca_count; ++i) {
|
||||
lv_fs_res_t res = lv_fs_seek(fp, start + glyph_offset[i]);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
bit_iterator_t bit_it = init_bit_iterator(fp);
|
||||
|
||||
int nbits = header->advance_width_bits + 2 * header->xy_bits + 2 * header->wh_bits;
|
||||
|
||||
read_bits(&bit_it, nbits, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(glyph_dsc[i].box_w * glyph_dsc[i].box_h == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int next_offset = (i < loca_count - 1) ? glyph_offset[i + 1] : (uint32_t)glyph_length;
|
||||
int bmp_size = next_offset - glyph_offset[i] - nbits / 8;
|
||||
|
||||
if(nbits % 8 == 0) { /* Fast path */
|
||||
if(lv_fs_read(fp, &glyph_bmp[cur_bmp_size], bmp_size, NULL) != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
for(int k = 0; k < bmp_size - 1; ++k) {
|
||||
glyph_bmp[cur_bmp_size + k] = read_bits(&bit_it, 8, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
glyph_bmp[cur_bmp_size + bmp_size - 1] = read_bits(&bit_it, 8 - nbits % 8, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
cur_bmp_size += bmp_size;
|
||||
}
|
||||
return glyph_length;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loads a `lv_font_t` from a binary file, given a `lv_fs_file_t`.
|
||||
*
|
||||
* Memory allocations on `lvgl_load_font` should be immediately zeroed and
|
||||
* the pointer should be set on the `lv_font_t` data before any possible return.
|
||||
*
|
||||
* When something fails, it returns `false` and the memory on the `lv_font_t`
|
||||
* still needs to be freed using `lv_font_free`.
|
||||
*
|
||||
* `lv_font_free` will assume that all non-null pointers are allocated and
|
||||
* should be freed.
|
||||
*/
|
||||
static bool lvgl_load_font(lv_fs_file_t* fp, lv_font_t* font)
|
||||
{
|
||||
lv_font_fmt_txt_dsc_t* font_dsc = (lv_font_fmt_txt_dsc_t*)malloc(sizeof(lv_font_fmt_txt_dsc_t));
|
||||
|
||||
memset(font_dsc, 0, sizeof(lv_font_fmt_txt_dsc_t));
|
||||
|
||||
font->dsc = font_dsc;
|
||||
|
||||
/* header */
|
||||
int32_t header_length = read_label(fp, 0, "head");
|
||||
if(header_length < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
font_header_bin_t font_header;
|
||||
if(lv_fs_read(fp, &font_header, sizeof(font_header_bin_t), NULL) != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
font->base_line = -font_header.descent;
|
||||
font->line_height = font_header.ascent - font_header.descent;
|
||||
font->get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt;
|
||||
font->get_glyph_bitmap = lv_font_get_bitmap_fmt_txt;
|
||||
font->subpx = font_header.subpixels_mode;
|
||||
font->underline_position = font_header.underline_position;
|
||||
font->underline_thickness = font_header.underline_thickness;
|
||||
|
||||
font_dsc->bpp = font_header.bits_per_pixel;
|
||||
font_dsc->kern_scale = font_header.kerning_scale;
|
||||
font_dsc->bitmap_format = font_header.compression_id;
|
||||
|
||||
/* cmaps */
|
||||
uint32_t cmaps_start = header_length;
|
||||
int32_t cmaps_length = load_cmaps(fp, font_dsc, cmaps_start);
|
||||
if(cmaps_length < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* loca */
|
||||
uint32_t loca_start = cmaps_start + cmaps_length;
|
||||
int32_t loca_length = read_label(fp, loca_start, "loca");
|
||||
if(loca_length < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t loca_count;
|
||||
if(lv_fs_read(fp, &loca_count, sizeof(uint32_t), NULL) != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool failed = false;
|
||||
uint32_t* glyph_offset = (uint32_t*)malloc(sizeof(uint32_t) * (loca_count + 1));
|
||||
|
||||
/*TODO check NULL*/
|
||||
|
||||
if(font_header.index_to_loc_format == 0) {
|
||||
for(unsigned int i = 0; i < loca_count; ++i) {
|
||||
uint16_t offset;
|
||||
if(lv_fs_read(fp, &offset, sizeof(uint16_t), NULL) != LV_FS_RES_OK) {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
glyph_offset[i] = offset;
|
||||
}
|
||||
} else if(font_header.index_to_loc_format == 1) {
|
||||
if(lv_fs_read(fp, glyph_offset, loca_count * sizeof(uint32_t), NULL) != LV_FS_RES_OK) {
|
||||
failed = true;
|
||||
}
|
||||
} else {
|
||||
LOG_WARNING(TAG_FONT, "Unknown index_to_loc_format: %d.", font_header.index_to_loc_format);
|
||||
failed = true;
|
||||
}
|
||||
|
||||
if(failed) {
|
||||
free(glyph_offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* glyph */
|
||||
uint32_t glyph_start = loca_start + loca_length;
|
||||
int32_t glyph_length = load_glyph(fp, font_dsc, glyph_start, glyph_offset, loca_count, &font_header);
|
||||
|
||||
free(glyph_offset);
|
||||
|
||||
if(glyph_length < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if(font_header.tables_count < 4) {
|
||||
font_dsc->kern_dsc = NULL;
|
||||
font_dsc->kern_classes = 0;
|
||||
font_dsc->kern_scale = 0;
|
||||
return true;
|
||||
// }
|
||||
|
||||
// uint32_t kern_start = glyph_start + glyph_length;
|
||||
|
||||
// int32_t kern_length = load_kern(fp, font_dsc, font_header.glyph_id_format, kern_start);
|
||||
|
||||
// return kern_length >= 0;
|
||||
}
|
||||
|
||||
// int32_t load_kern(lv_fs_file_t * fp, lv_font_fmt_txt_dsc_t * font_dsc, uint8_t format, uint32_t start)
|
||||
// {
|
||||
// int32_t kern_length = read_label(fp, start, "kern");
|
||||
// if(kern_length < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// uint8_t kern_format_type;
|
||||
// int32_t padding;
|
||||
// if(lv_fs_read(fp, &kern_format_type, sizeof(uint8_t), NULL) != LV_FS_RES_OK ||
|
||||
// lv_fs_read(fp, &padding, 3 * sizeof(uint8_t), NULL) != LV_FS_RES_OK) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// if(0 == kern_format_type) { /* sorted pairs */
|
||||
// lv_font_fmt_txt_kern_pair_t * kern_pair = malloc(sizeof(lv_font_fmt_txt_kern_pair_t));
|
||||
|
||||
// memset(kern_pair, 0, sizeof(lv_font_fmt_txt_kern_pair_t));
|
||||
|
||||
// font_dsc->kern_dsc = kern_pair;
|
||||
// font_dsc->kern_classes = 0;
|
||||
|
||||
// uint32_t glyph_entries;
|
||||
// if(lv_fs_read(fp, &glyph_entries, sizeof(uint32_t), NULL) != LV_FS_RES_OK) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// int ids_size;
|
||||
// if(format == 0) {
|
||||
// ids_size = sizeof(int8_t) * 2 * glyph_entries;
|
||||
// }
|
||||
// else {
|
||||
// ids_size = sizeof(int16_t) * 2 * glyph_entries;
|
||||
// }
|
||||
|
||||
// uint8_t * glyph_ids = malloc(ids_size);
|
||||
// int8_t * values = malloc(glyph_entries);
|
||||
|
||||
// kern_pair->glyph_ids_size = format;
|
||||
// kern_pair->pair_cnt = glyph_entries;
|
||||
// kern_pair->glyph_ids = glyph_ids;
|
||||
// kern_pair->values = values;
|
||||
|
||||
// if(lv_fs_read(fp, glyph_ids, ids_size, NULL) != LV_FS_RES_OK) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// if(lv_fs_read(fp, values, glyph_entries, NULL) != LV_FS_RES_OK) {
|
||||
// return -1;
|
||||
// }
|
||||
// }
|
||||
// else if(3 == kern_format_type) { /* array M*N of classes */
|
||||
|
||||
// lv_font_fmt_txt_kern_classes_t * kern_classes = malloc(sizeof(lv_font_fmt_txt_kern_classes_t));
|
||||
|
||||
// memset(kern_classes, 0, sizeof(lv_font_fmt_txt_kern_classes_t));
|
||||
|
||||
// font_dsc->kern_dsc = kern_classes;
|
||||
// font_dsc->kern_classes = 1;
|
||||
|
||||
// uint16_t kern_class_mapping_length;
|
||||
// uint8_t kern_table_rows;
|
||||
// uint8_t kern_table_cols;
|
||||
|
||||
// if(lv_fs_read(fp, &kern_class_mapping_length, sizeof(uint16_t), NULL) != LV_FS_RES_OK ||
|
||||
// lv_fs_read(fp, &kern_table_rows, sizeof(uint8_t), NULL) != LV_FS_RES_OK ||
|
||||
// lv_fs_read(fp, &kern_table_cols, sizeof(uint8_t), NULL) != LV_FS_RES_OK) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// int kern_values_length = sizeof(int8_t) * kern_table_rows * kern_table_cols;
|
||||
|
||||
// uint8_t * kern_left = malloc(kern_class_mapping_length);
|
||||
// uint8_t * kern_right = malloc(kern_class_mapping_length);
|
||||
// int8_t * kern_values = malloc(kern_values_length);
|
||||
|
||||
// kern_classes->left_class_mapping = kern_left;
|
||||
// kern_classes->right_class_mapping = kern_right;
|
||||
// kern_classes->left_class_cnt = kern_table_rows;
|
||||
// kern_classes->right_class_cnt = kern_table_cols;
|
||||
// kern_classes->class_pair_values = kern_values;
|
||||
|
||||
// if(lv_fs_read(fp, kern_left, kern_class_mapping_length, NULL) != LV_FS_RES_OK ||
|
||||
// lv_fs_read(fp, kern_right, kern_class_mapping_length, NULL) != LV_FS_RES_OK ||
|
||||
// lv_fs_read(fp, kern_values, kern_values_length, NULL) != LV_FS_RES_OK) {
|
||||
// return -1;
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// LOG_WARNING(TAG_FONT,"Unknown kern_format_type: %d", kern_format_type);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// return kern_length;
|
||||
// }
|
||||
|
||||
#endif /*LV_USE_FILESYSTEM*/
|
44
src/font/hasp_font_loader.h
Normal file
44
src/font/hasp_font_loader.h
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file hasp_font_loader.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HASP_FONT_LOADER_H
|
||||
#define HASP_FONT_LOADER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
#if LV_USE_FILESYSTEM
|
||||
|
||||
lv_font_t * hasp_font_load(const char * fontName);
|
||||
void hasp_font_free(lv_font_t * font);
|
||||
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_FONT_LOADER_H*/
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user