Skip to content

Commit 95f8696

Browse files
committed
Added esp-idf font and sprite example
1 parent 63b1fd9 commit 95f8696

File tree

6 files changed

+2293
-0
lines changed

6 files changed

+2293
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# For more information about build system see
2+
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
3+
# The following five lines of boilerplate have to be in your project's
4+
# CMakeLists in this exact order for cmake to work correctly
5+
cmake_minimum_required(VERSION 3.16)
6+
7+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8+
project(font_demo)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// This demo shows how to use both virtual display surfaces and
3+
// custom fonts. The fonts are created with the fontconvert tool (in this repo)
4+
// and a TTF (TrueType font) file as the source.
5+
// Use fontconvert to create the sizes and character ranges of fonts needed
6+
// for your projects. Characters 32 to 127 are the standard ASCII set and
7+
// 128 to 255 are the extended ASCII set which follows Microsoft's codepage 1252
8+
// CP1252 consists of most symbols and accented characters from European
9+
// Latin languages
10+
// The strings passed to FastEPD are in ASCII or UTF-8 format
11+
//
12+
// The fontconvert tool example:
13+
// ./fontconvert <source.ttf> <output.h> size start end
14+
// For example, to create the 80pt Roboto-Black font used in this example, the
15+
// command line arguments would be:
16+
// ./fontconvert Roboto-Black.ttf Roboto_Black_80.h 80 32 255
17+
// This creates the full ASCII and extended ASCII set of characters
18+
//
19+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
idf_component_register(SRCS "font_demo.c"
2+
INCLUDE_DIRS ".")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// Anti-aliased font demo
3+
//
4+
#include <stdio.h>
5+
#include "esp_sleep.h"
6+
#include "driver/gpio.h"
7+
#include "driver/rtc_io.h"
8+
#include "driver/i2c.h"
9+
#include "freertos/FreeRTOS.h"
10+
#include "freertos/task.h"
11+
12+
#include "../../../../src/FastEPD.h"
13+
#include "../../../../Fonts/Roboto_Black_80.h"
14+
#include "../../../../Fonts/Roboto_Black_40.h"
15+
16+
FASTEPDSTATE bbep, virt;
17+
18+
void app_main(void)
19+
{
20+
int rc;
21+
22+
// We have enough PSRAM to allocate full sized buffers
23+
// for a full screen virtual device and the physical
24+
// device (M5Stack PaperS3 in this case - 960x540)
25+
// We'll draw on the virtual memory device, then copy
26+
// it to the framebuffer of the physical device and
27+
// do a 16-gray update
28+
29+
bbepInitPanel(&virt, BB_PANEL_VIRTUAL, 0);
30+
// A virtual panel must be given a size
31+
bbepSetPanelSize(&virt, 960, 540, 0);
32+
33+
// Predefined devices can have a display size
34+
// associated with them already
35+
rc = bbepInitPanel(&bbep, BB_PANEL_M5PAPERS3, 20000000);
36+
if (rc == BBEP_SUCCESS) {
37+
bbepSetMode(&virt, BB_MODE_4BPP); // source and destination
38+
bbepSetMode(&bbep, BB_MODE_4BPP); // need to be the same bit depth
39+
bbepFillScreen(&virt, 0xf); // fill with white
40+
41+
// The y coordinate represents the character baseline
42+
// not the upper left corner
43+
bbepWriteStringCustom(&virt, Roboto_Black_40, 0, 200, "Normal, 1-bit font", BBEP_BLACK);
44+
virt.anti_alias = 1; // turn on antialiased mode
45+
// Use a font with a point size 2x bigger to get the same
46+
// size output in anti-alias mode. (80 vs 40pt)
47+
bbepWriteStringCustom(&virt, Roboto_Black_80, 0, 400, "Antialiased, 2-bit font", BBEP_BLACK);
48+
49+
// Draw the virtual device framebuffer onto the
50+
// physical device framebuffer at (0,0)
51+
bbepDrawSprite(&virt, &bbep, 0, 0, -1);
52+
53+
// Draw the physical device framebuffer onto the Eink panel
54+
bbepFullUpdate(&bbep, CLEAR_SLOW, 0, NULL);
55+
}
56+
}

0 commit comments

Comments
 (0)