Reorganization, style fix, Terminus fonts
This commit is contained in:
parent
39b6cd8ce0
commit
861fe94bd3
22 changed files with 62103 additions and 75 deletions
|
|
@ -14,9 +14,8 @@
|
||||||
#define CIRCLE_COUNT_ICON_X 94
|
#define CIRCLE_COUNT_ICON_X 94
|
||||||
#define CIRCLE_COUNT_ICON_Y 42
|
#define CIRCLE_COUNT_ICON_Y 42
|
||||||
|
|
||||||
|
|
||||||
/* Remove this line if your display connected by SPI */
|
/* Remove this line if your display connected by SPI */
|
||||||
#define I2C_CONNECTION
|
//#define I2C_CONNECTION
|
||||||
|
|
||||||
#ifdef I2C_CONNECTION
|
#ifdef I2C_CONNECTION
|
||||||
#include <i2c/i2c.h>
|
#include <i2c/i2c.h>
|
||||||
|
|
@ -54,73 +53,94 @@ static const ssd1306_t dev = {
|
||||||
/* Local frame buffer */
|
/* Local frame buffer */
|
||||||
static uint8_t buffer[DISPLAY_WIDTH * DISPLAY_HEIGHT / 8];
|
static uint8_t buffer[DISPLAY_WIDTH * DISPLAY_HEIGHT / 8];
|
||||||
|
|
||||||
TimerHandle_t timerHandle = 0 ; // Timer handler
|
TimerHandle_t timerHandle = 0; // Timer handler
|
||||||
uint8_t frame_done = 0 ; // number of frame send.
|
uint8_t frame_done = 0; // number of frame send.
|
||||||
uint8_t fps = 0 ; // image per second.
|
uint8_t fps = 0; // image per second.
|
||||||
|
|
||||||
|
#define SECOND (1000 / portTICK_PERIOD_MS)
|
||||||
|
|
||||||
static void ssd1306_task(void *pvParameters)
|
static void ssd1306_task(void *pvParameters)
|
||||||
{
|
{
|
||||||
printf("%s: Started user interface task\n", __FUNCTION__);
|
printf("%s: Started user interface task\n", __FUNCTION__);
|
||||||
vTaskDelay(1000/portTICK_PERIOD_MS);
|
vTaskDelay(SECOND);
|
||||||
|
|
||||||
ssd1306_set_whole_display_lighting(&dev, false);
|
ssd1306_set_whole_display_lighting(&dev, false);
|
||||||
|
|
||||||
|
char text[20];
|
||||||
char text[20] ;
|
uint8_t x0 = LOAD_ICON_X;
|
||||||
uint8_t x0 = LOAD_ICON_X ;
|
uint8_t y0 = LOAD_ICON_Y;
|
||||||
uint8_t y0 = LOAD_ICON_Y ;
|
uint8_t x1 = LOAD_ICON_X + LOAD_ICON_SIZE;
|
||||||
uint8_t x1 = LOAD_ICON_X + LOAD_ICON_SIZE ;
|
uint8_t y1 = LOAD_ICON_Y + LOAD_ICON_SIZE;
|
||||||
uint8_t y1 = LOAD_ICON_Y + LOAD_ICON_SIZE ;
|
uint16_t count = 0;
|
||||||
uint16_t count = 0 ;
|
uint8_t font = 0;
|
||||||
ssd1306_select_font(1);
|
//ssd1306_select_font(FONT_FACE_TERMINUS_BOLD_8X14_KOI8_R);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
ssd1306_draw_string(&dev, buffer, 10, 10,"Hello, esp-open-rtos !", OLED_COLOR_WHITE, OLED_COLOR_BLACK) ;
|
if (!(count % 200))
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (font++ >= FONT_FACE_MAX) font = 0;
|
||||||
|
if (!ssd1306_select_font(font)) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssd1306_draw_string(&dev, buffer, 10, 10,"Hello, esp-open-rtos !", OLED_COLOR_WHITE, OLED_COLOR_BLACK);
|
||||||
sprintf(text,"FPS: %u",fps);
|
sprintf(text,"FPS: %u",fps);
|
||||||
ssd1306_draw_string(&dev, buffer, 10, 40, text, OLED_COLOR_WHITE, OLED_COLOR_BLACK) ;
|
ssd1306_draw_string(&dev, buffer, 10, 40, text, OLED_COLOR_WHITE, OLED_COLOR_BLACK);
|
||||||
|
|
||||||
//generate loading icon
|
//generate loading icon
|
||||||
ssd1306_draw_line(&dev, buffer, x0, y0, x1, y1, OLED_COLOR_BLACK);
|
ssd1306_draw_line(&dev, buffer, x0, y0, x1, y1, OLED_COLOR_BLACK);
|
||||||
if (x0 < (LOAD_ICON_X + LOAD_ICON_SIZE)) { x0++ ; x1-- ; }
|
if (x0 < (LOAD_ICON_X + LOAD_ICON_SIZE)) {
|
||||||
else if(y0< (LOAD_ICON_Y + LOAD_ICON_SIZE)) { y0++ ; y1-- ; }
|
x0++;
|
||||||
else { x0 = LOAD_ICON_X ; y0 = LOAD_ICON_Y ; x1 = LOAD_ICON_X + LOAD_ICON_SIZE ; y1 = LOAD_ICON_Y + LOAD_ICON_SIZE ; }
|
x1--;
|
||||||
|
}
|
||||||
|
else if (y0 < (LOAD_ICON_Y + LOAD_ICON_SIZE)) {
|
||||||
|
y0++;
|
||||||
|
y1--;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x0 = LOAD_ICON_X;
|
||||||
|
y0 = LOAD_ICON_Y;
|
||||||
|
x1 = LOAD_ICON_X + LOAD_ICON_SIZE;
|
||||||
|
y1 = LOAD_ICON_Y + LOAD_ICON_SIZE;
|
||||||
|
}
|
||||||
ssd1306_draw_line(&dev, buffer, x0, y0, x1, y1, OLED_COLOR_WHITE);
|
ssd1306_draw_line(&dev, buffer, x0, y0, x1, y1, OLED_COLOR_WHITE);
|
||||||
ssd1306_draw_rectangle(&dev, buffer, LOAD_ICON_X, LOAD_ICON_Y, LOAD_ICON_SIZE+1, LOAD_ICON_SIZE+1, OLED_COLOR_WHITE);
|
ssd1306_draw_rectangle(&dev, buffer, LOAD_ICON_X, LOAD_ICON_Y,
|
||||||
|
LOAD_ICON_SIZE + 1, LOAD_ICON_SIZE + 1, OLED_COLOR_WHITE);
|
||||||
|
|
||||||
//generate circle counting
|
//generate circle counting
|
||||||
for (uint8_t i = 0 ; i < 10 ; i++ ) {
|
for (uint8_t i = 0; i < 10; i++) {
|
||||||
if ((count>>i) & 0x01) ssd1306_draw_circle(&dev,buffer,CIRCLE_COUNT_ICON_X, CIRCLE_COUNT_ICON_Y, i, OLED_COLOR_BLACK);
|
if ((count >> i) & 0x01)
|
||||||
|
ssd1306_draw_circle(&dev, buffer, CIRCLE_COUNT_ICON_X, CIRCLE_COUNT_ICON_Y, i, OLED_COLOR_BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count != 0x03FF) count++;
|
count = count == 0x03FF ? 0 : count + 1;
|
||||||
else count = 0 ;
|
|
||||||
|
|
||||||
for (uint8_t i = 0 ; i < 10 ; i++ ) {
|
for (uint8_t i = 0; i < 10; i++) {
|
||||||
if ((count>>i) & 0x01) ssd1306_draw_circle(&dev,buffer, CIRCLE_COUNT_ICON_X, CIRCLE_COUNT_ICON_Y, i, OLED_COLOR_WHITE);
|
if ((count>>i) & 0x01)
|
||||||
|
ssd1306_draw_circle(&dev,buffer, CIRCLE_COUNT_ICON_X, CIRCLE_COUNT_ICON_Y, i, OLED_COLOR_WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ssd1306_load_frame_buffer(&dev, buffer))
|
if (ssd1306_load_frame_buffer(&dev, buffer))
|
||||||
goto error_loop;
|
goto error_loop;
|
||||||
frame_done++ ;
|
|
||||||
|
frame_done++;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_loop:
|
error_loop:
|
||||||
printf("%s: error while loading framebuffer into SSD1306\n", __func__);
|
printf("%s: error while loading framebuffer into SSD1306\n", __func__);
|
||||||
for(;;){
|
for (;;) {
|
||||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
vTaskDelay(2 * SECOND);
|
||||||
printf("%s: error loop\n", __FUNCTION__);
|
printf("%s: error loop\n", __FUNCTION__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoftTimer( TimerHandle_t xTimer ){
|
void SoftTimer(TimerHandle_t xTimer)
|
||||||
fps = frame_done ; // Save number of frame already send to screen
|
{
|
||||||
frame_done = 0 ;
|
fps = frame_done; // Save number of frame already send to screen
|
||||||
|
frame_done = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void user_init(void)
|
void user_init(void)
|
||||||
{
|
{
|
||||||
//uncomment to test with CPU overclocked
|
//uncomment to test with CPU overclocked
|
||||||
|
|
@ -135,16 +155,16 @@ void user_init(void)
|
||||||
i2c_init(SCL_PIN, SDA_PIN);
|
i2c_init(SCL_PIN, SDA_PIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (ssd1306_init(&dev) != 0)
|
while (ssd1306_init(&dev) != 0) {
|
||||||
{
|
|
||||||
printf("%s: failed to init SSD1306 lcd\n", __func__);
|
printf("%s: failed to init SSD1306 lcd\n", __func__);
|
||||||
vTaskDelay(1000/portTICK_PERIOD_MS);
|
vTaskDelay(SECOND);
|
||||||
}
|
}
|
||||||
ssd1306_set_whole_display_lighting(&dev, true);
|
ssd1306_set_whole_display_lighting(&dev, true);
|
||||||
vTaskDelay(1000/portTICK_PERIOD_MS);
|
vTaskDelay(SECOND);
|
||||||
// Create user interface task
|
|
||||||
|
|
||||||
|
// Create user interface task
|
||||||
xTaskCreate(ssd1306_task, "ssd1306_task", 256, NULL, 2, NULL);
|
xTaskCreate(ssd1306_task, "ssd1306_task", 256, NULL, 2, NULL);
|
||||||
timerHandle = xTimerCreate("Timer", 1000/portTICK_PERIOD_MS, pdTRUE, NULL, SoftTimer);
|
|
||||||
xTimerStart(timerHandle,0);
|
timerHandle = xTimerCreate("Timer", SECOND, pdTRUE, NULL, SoftTimer);
|
||||||
|
xTimerStart(timerHandle, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,14 @@ INC_DIRS += $(fonts_ROOT)..
|
||||||
# args for passing into compile rule generation
|
# args for passing into compile rule generation
|
||||||
fonts_SRC_DIR = $(fonts_ROOT)
|
fonts_SRC_DIR = $(fonts_ROOT)
|
||||||
|
|
||||||
|
FONTS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||||
|
|
||||||
|
# fonts by default
|
||||||
|
include $(FONTS_DIR)defaults.mk
|
||||||
|
|
||||||
|
fonts_CFLAGS = $(CFLAGS) \
|
||||||
|
-DFONTS_GLCD_5X7=$(FONTS_GLCD_5X7)
|
||||||
|
-DFONTS_ROBOTO_8PT=$(FONTS_ROBOTO_8PT)
|
||||||
|
-DFONTS_ROBOTO_10PT=$(FONTS_ROBOTO_10PT)
|
||||||
|
|
||||||
$(eval $(call component_compile_rules,fonts))
|
$(eval $(call component_compile_rules,fonts))
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,53 @@
|
||||||
#ifndef _EXTRAS_FONTS_CONFIG_H_
|
#ifndef _EXTRAS_FONTS_CONFIG_H_
|
||||||
#define _EXTRAS_FONTS_CONFIG_H_
|
#define _EXTRAS_FONTS_CONFIG_H_
|
||||||
|
|
||||||
#ifndef NUM_FONTS
|
#ifndef FONTS_GLCD_5X7
|
||||||
#define NUM_FONTS 3
|
#define FONTS_GLCD_5X7 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// FIXME: Proportional fonts drawing is broken
|
||||||
|
#ifndef FONTS_ROBOTO_8PT
|
||||||
|
#define FONTS_ROBOTO_8PT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_ROBOTO_10PT
|
||||||
|
#define FONTS_ROBOTO_10PT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_6X12_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_6X12_KOI8_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_8X14_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_8X14_KOI8_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_BOLD_8X14_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_BOLD_8X14_KOI8_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_8X16_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_8X16_KOI8_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_BOLD_8X16_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_BOLD_8X16_KOI8_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_14X28_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_14X28_KOI8_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_BOLD_14X28_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_BOLD_14X28_KOI8_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_16X32_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_16X32_KOI8_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FONTS_TERMINUS_BOLD_16X32_KOI8_R
|
||||||
|
#define FONTS_TERMINUS_BOLD_16X32_KOI8_R 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _EXTRAS_FONTS_CONFIG_H_ */
|
#endif /* _EXTRAS_FONTS_CONFIG_H_ */
|
||||||
|
|
|
||||||
2596
extras/fonts/data/font_glcd_5x7.h
Normal file
2596
extras/fonts/data/font_glcd_5x7.h
Normal file
File diff suppressed because it is too large
Load diff
1630
extras/fonts/data/font_roboto_10pt.h
Normal file
1630
extras/fonts/data/font_roboto_10pt.h
Normal file
File diff suppressed because it is too large
Load diff
1348
extras/fonts/data/font_roboto_8pt.h
Normal file
1348
extras/fonts/data/font_roboto_8pt.h
Normal file
File diff suppressed because it is too large
Load diff
7935
extras/fonts/data/font_terminus_14x28_koi8_r.h
Normal file
7935
extras/fonts/data/font_terminus_14x28_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
8955
extras/fonts/data/font_terminus_16x32_koi8_r.h
Normal file
8955
extras/fonts/data/font_terminus_16x32_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
3855
extras/fonts/data/font_terminus_6x12_koi8_r.h
Normal file
3855
extras/fonts/data/font_terminus_6x12_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
4365
extras/fonts/data/font_terminus_8x14_koi8_r.h
Normal file
4365
extras/fonts/data/font_terminus_8x14_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
4875
extras/fonts/data/font_terminus_8x16_koi8_r.h
Normal file
4875
extras/fonts/data/font_terminus_8x16_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
7935
extras/fonts/data/font_terminus_bold_14x28_koi8_r.h
Normal file
7935
extras/fonts/data/font_terminus_bold_14x28_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
8955
extras/fonts/data/font_terminus_bold_16x32_koi8_r.h
Normal file
8955
extras/fonts/data/font_terminus_bold_16x32_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
4365
extras/fonts/data/font_terminus_bold_8x14_koi8_r.h
Normal file
4365
extras/fonts/data/font_terminus_bold_8x14_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
4875
extras/fonts/data/font_terminus_bold_8x16_koi8_r.h
Normal file
4875
extras/fonts/data/font_terminus_bold_8x16_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
7
extras/fonts/defaults.mk
Normal file
7
extras/fonts/defaults.mk
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#########################################
|
||||||
|
# Default built-in fonts
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
FONTS_GLCD_5X7 ?= 1
|
||||||
|
FONTS_ROBOTO_8PT ?= 0
|
||||||
|
FONTS_ROBOTO_10PT ?= 0
|
||||||
|
|
@ -1,18 +1,106 @@
|
||||||
/*
|
/*
|
||||||
* oled_fonts.c
|
* fonts.c
|
||||||
*
|
*
|
||||||
* Created on: 8 dec. 2016
|
* Created on: 8 dec. 2016
|
||||||
* Author: zaltora
|
* Author: zaltora
|
||||||
*/
|
*/
|
||||||
#include "fonts.h"
|
#include "fonts.h"
|
||||||
|
|
||||||
extern const font_info_t glcd_5x7_font_info;
|
#if FONTS_GLCD_5X7
|
||||||
extern const font_info_t roboto_8ptFontInfo;
|
#include "data/font_glcd_5x7.h"
|
||||||
extern const font_info_t roboto_10ptFontInfo;
|
#endif
|
||||||
|
|
||||||
const font_info_t* fonts[NUM_FONTS] =
|
#if FONTS_ROBOTO_8PT
|
||||||
|
#include "data/font_roboto_8pt.h"
|
||||||
|
#endif
|
||||||
|
#if FONTS_ROBOTO_10PT
|
||||||
|
#include "data/font_roboto_10pt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_TERMINUS_6X12_KOI8_R
|
||||||
|
#include "data/font_terminus_6x12_koi8_r.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_TERMINUS_8X14_KOI8_R
|
||||||
|
#include "data/font_terminus_8x14_koi8_r.h"
|
||||||
|
#endif
|
||||||
|
#if FONTS_TERMINUS_BOLD_8X14_KOI8_R
|
||||||
|
#include "data/font_terminus_bold_8x14_koi8_r.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_TERMINUS_14X28_KOI8_R
|
||||||
|
#include "data/font_terminus_14x28_koi8_r.h"
|
||||||
|
#endif
|
||||||
|
#if FONTS_TERMINUS_BOLD_14X28_KOI8_R
|
||||||
|
#include "data/font_terminus_bold_14x28_koi8_r.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_TERMINUS_16X32_KOI8_R
|
||||||
|
#include "data/font_terminus_16x32_koi8_r.h"
|
||||||
|
#endif
|
||||||
|
#if FONTS_TERMINUS_BOLD_16X32_KOI8_R
|
||||||
|
#include "data/font_terminus_bold_16x32_koi8_r.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
|
||||||
|
const font_info_t *fonts[] =
|
||||||
{
|
{
|
||||||
&glcd_5x7_font_info,
|
#if FONTS_GLCD_5X7
|
||||||
&roboto_8ptFontInfo,
|
[FONT_FACE_GLCD5x7] = &_fonts_glcd_5x7_info,
|
||||||
&roboto_10ptFontInfo,
|
#else
|
||||||
|
[FONT_FACE_GLCD5x7] = NULL,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_ROBOTO_8PT
|
||||||
|
[FONT_FACE_ROBOTO_8PT] = &_fonts_roboto_8pt_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_ROBOTO_8PT] = NULL,
|
||||||
|
#endif
|
||||||
|
#if FONTS_ROBOTO_10PT
|
||||||
|
[FONT_FACE_ROBOTO_10PT] = &_fonts_roboto_10pt_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_ROBOTO_10PT] = NULL,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_TERMINUS_6X12_KOI8_R
|
||||||
|
[FONT_FACE_TERMINUS_6X12_KOI8_R] = &_fonts_terminus_6x12_koi8_r_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_TERMINUS_6X12_KOI8_R] = NULL,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_TERMINUS_8X14_KOI8_R
|
||||||
|
[FONT_FACE_TERMINUS_8X14_KOI8_R] = &_fonts_terminus_8x14_koi8_r_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_TERMINUS_8X14_KOI8_R] = NULL,
|
||||||
|
#endif
|
||||||
|
#if FONTS_TERMINUS_BOLD_8X14_KOI8_R
|
||||||
|
[FONT_FACE_TERMINUS_BOLD_8X14_KOI8_R] = &_fonts_terminus_bold_8x14_koi8_r_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_TERMINUS_BOLD_8X14_KOI8_R] = NULL,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_TERMINUS_14X28_KOI8_R
|
||||||
|
[FONT_FACE_TERMINUS_14X28_KOI8_R] = &_fonts_terminus_14x28_koi8_r_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_TERMINUS_14X28_KOI8_R] = NULL,
|
||||||
|
#endif
|
||||||
|
#if FONTS_TERMINUS_BOLD_14X28_KOI8_R
|
||||||
|
[FONT_FACE_TERMINUS_BOLD_14X28_KOI8_R] = &_fonts_terminus_bold_14x28_koi8_r_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_TERMINUS_BOLD_14X28_KOI8_R] = NULL,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FONTS_TERMINUS_16X32_KOI8_R
|
||||||
|
[FONT_FACE_TERMINUS_16X32_KOI8_R] = &_fonts_terminus_16x32_koi8_r_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_TERMINUS_16X32_KOI8_R] = NULL,
|
||||||
|
#endif
|
||||||
|
#if FONTS_TERMINUS_BOLD_16X32_KOI8_R
|
||||||
|
[FONT_FACE_TERMINUS_BOLD_16X32_KOI8_R] = &_fonts_terminus_bold_16x32_koi8_r_info,
|
||||||
|
#else
|
||||||
|
[FONT_FACE_TERMINUS_BOLD_16X32_KOI8_R] = NULL,
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const size_t fonts_count = (sizeof(fonts) / sizeof(font_info_t *));
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,42 @@
|
||||||
* Created on: 8 dec. 2016
|
* Created on: 8 dec. 2016
|
||||||
* Author: zaltora
|
* Author: zaltora
|
||||||
*/
|
*/
|
||||||
|
#ifndef _EXTRAS_FONTS_H_
|
||||||
|
#define _EXTRAS_FONTS_H_
|
||||||
|
|
||||||
#ifndef FONTS_H
|
#include <stdint.h>
|
||||||
#define FONTS_H
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <FreeRTOS.h>
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
FONT_FACE_GLCD5x7 = 0,
|
||||||
|
FONT_FACE_ROBOTO_8PT,
|
||||||
|
FONT_FACE_ROBOTO_10PT,
|
||||||
|
FONT_FACE_TERMINUS_6X12_KOI8_R,
|
||||||
|
FONT_FACE_TERMINUS_8X14_KOI8_R,
|
||||||
|
FONT_FACE_TERMINUS_BOLD_8X14_KOI8_R,
|
||||||
|
FONT_FACE_TERMINUS_8X16_KOI8_R,
|
||||||
|
FONT_FACE_TERMINUS_BOLD_8X16_KOI8_R,
|
||||||
|
FONT_FACE_TERMINUS_14X28_KOI8_R,
|
||||||
|
FONT_FACE_TERMINUS_BOLD_14X28_KOI8_R,
|
||||||
|
FONT_FACE_TERMINUS_16X32_KOI8_R,
|
||||||
|
FONT_FACE_TERMINUS_BOLD_16X32_KOI8_R,
|
||||||
|
} font_face_t;
|
||||||
|
|
||||||
|
#define FONT_FACE_MAX FONT_FACE_TERMINUS_BOLD_16X32_KOI8_R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Character descriptor
|
* Character descriptor
|
||||||
*/
|
*/
|
||||||
typedef struct _font_char_desc
|
typedef struct _font_char_desc
|
||||||
{
|
{
|
||||||
uint8_t width; //Character width in pixel
|
uint8_t width; ///< Character width in pixel
|
||||||
uint16_t offset; //Offset of this character in bitmap
|
uint16_t offset; ///< Offset of this character in bitmap
|
||||||
} font_char_desc_t;
|
} font_char_desc_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -25,14 +47,22 @@ typedef struct _font_char_desc
|
||||||
*/
|
*/
|
||||||
typedef struct _font_info
|
typedef struct _font_info
|
||||||
{
|
{
|
||||||
uint8_t height; //Character height in pixel, all characters have same height
|
uint8_t height; ///< Character height in pixel, all characters have same height
|
||||||
uint8_t c; //Simulation of "C" width in TrueType term, the space between adjacent characters
|
uint8_t c; ///< Simulation of "C" width in TrueType term, the space between adjacent characters
|
||||||
char char_start; //First character
|
char char_start; ///< First character
|
||||||
char char_end; //Last character
|
char char_end; ///< Last character
|
||||||
const font_char_desc_t* char_descriptors; //descriptor for each character
|
const font_char_desc_t *char_descriptors; ///< descriptor for each character
|
||||||
const uint8_t *bitmap; //Character bitmap
|
const uint8_t *bitmap; ///< Character bitmap
|
||||||
} font_info_t;
|
} font_info_t;
|
||||||
|
|
||||||
extern const font_info_t* fonts[NUM_FONTS]; //Built-in fonts
|
/**
|
||||||
|
* Built-in fonts
|
||||||
|
*/
|
||||||
|
extern const font_info_t *fonts[];
|
||||||
|
extern const size_t fonts_count;
|
||||||
|
|
||||||
#endif // _FONTS__H_
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _EXTRAS_FONTS_H_ */
|
||||||
|
|
|
||||||
88
extras/fonts/tools/create_font.py
Executable file
88
extras/fonts/tools/create_font.py
Executable file
|
|
@ -0,0 +1,88 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
import sys, os
|
||||||
|
from PIL import Image, ImageFont, ImageDraw
|
||||||
|
import argparse
|
||||||
|
import jinja2
|
||||||
|
import re
|
||||||
|
|
||||||
|
def gen_char(index, c, im):
|
||||||
|
bw = (im.size[0] + 7) // 8
|
||||||
|
res = {
|
||||||
|
'index': index,
|
||||||
|
'code': c,
|
||||||
|
'offset': bw * im.size[1] * index,
|
||||||
|
'rows': []
|
||||||
|
}
|
||||||
|
|
||||||
|
data = tuple(im.getdata())
|
||||||
|
|
||||||
|
for row in range(im.size[1]):
|
||||||
|
r = {
|
||||||
|
'data': [],
|
||||||
|
'asc': [],
|
||||||
|
}
|
||||||
|
for b in range(bw):
|
||||||
|
byte = 0
|
||||||
|
for i in range(8):
|
||||||
|
idx = b * 8 + i
|
||||||
|
bit = data[row * im.size[0] + idx] if idx < im.size[0] else 0
|
||||||
|
if bit:
|
||||||
|
byte |= 1
|
||||||
|
r['asc'].append('#')
|
||||||
|
else:
|
||||||
|
r['asc'].append('.')
|
||||||
|
byte <<= 1
|
||||||
|
r['data'].append(byte >> 1)
|
||||||
|
|
||||||
|
r['asc'] = ''.join(r['asc'])
|
||||||
|
res['rows'].append(r)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
fnt = ImageFont.load(args.font)
|
||||||
|
size = fnt.getsize('A')
|
||||||
|
|
||||||
|
im = Image.new('RGB', size)
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
if args.last - args.first < 1:
|
||||||
|
raise ValueError('Invalid --first or --last')
|
||||||
|
|
||||||
|
chars = []
|
||||||
|
for idx in range(args.last - args.first + 1):
|
||||||
|
draw.rectangle(((0, 0), size), fill = 0)
|
||||||
|
draw.text((0, 0), chr(idx + args.first), font=fnt)
|
||||||
|
chars.append(gen_char(idx, idx + args.first, im.convert('1')))
|
||||||
|
|
||||||
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(os.path.abspath(__file__))), finalize=lambda x: '' if x is None else x)
|
||||||
|
print(env.get_template('template.c').render({
|
||||||
|
'font': {
|
||||||
|
'name': args.name,
|
||||||
|
'size': size,
|
||||||
|
'charset': args.charset,
|
||||||
|
'first': args.first,
|
||||||
|
'last': args.last,
|
||||||
|
},
|
||||||
|
'chars': chars
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
_CLEAN_RE = re.compile(r'[^a-z0-9_]', re.I)
|
||||||
|
|
||||||
|
def clean_str(s):
|
||||||
|
return _CLEAN_RE.sub('_', s)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser=argparse.ArgumentParser(description='Fixed fonts converter')
|
||||||
|
parser.add_argument('-f', '--font', type=str, required=True, help='PIL font filename')
|
||||||
|
parser.add_argument('-n', '--name', type=clean_str, required=True, help='Font name')
|
||||||
|
parser.add_argument('-c', '--charset', type=clean_str, required=True, help='Charset')
|
||||||
|
parser.add_argument('--first', type=int, help='First character', default=1)
|
||||||
|
parser.add_argument('--last', type=int, help='Last character', default=255)
|
||||||
|
parser.add_argument('-t', '--template', type=str, help='Template filename', default='template.c')
|
||||||
|
main(parser.parse_args(sys.argv[1:]))
|
||||||
|
|
||||||
49
extras/fonts/tools/template.c
Normal file
49
extras/fonts/tools/template.c
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
{%- set header_id -%}
|
||||||
|
_EXTRAS_FONTS_FONT_{{ font.name|upper }}_{{ font.size[0] }}X{{ font.size[1] }}_{{ font.charset|upper }}_H_
|
||||||
|
{%- endset -%}
|
||||||
|
{%- set font_size -%}
|
||||||
|
{{ font.size[0] }}x{{ font.size[1] }}
|
||||||
|
{%- endset -%}
|
||||||
|
{%- set font_prefix -%}
|
||||||
|
_fonts_{{ font.name|lower }}_{{ font_size }}_{{ font.charset|lower }}
|
||||||
|
{%- endset -%}
|
||||||
|
/**
|
||||||
|
* This file contains generated binary font data.
|
||||||
|
*
|
||||||
|
* Font: {{ font.name }}
|
||||||
|
* Size: {{ font_size }}
|
||||||
|
* Charset: {{ font.charset }}
|
||||||
|
* {{ chars|length }} characters ({{ font.first }}..{{ font.last }})
|
||||||
|
*
|
||||||
|
* Generated: {{ created }}
|
||||||
|
*/
|
||||||
|
#ifndef {{ header_id }}
|
||||||
|
#define {{ header_id }}
|
||||||
|
|
||||||
|
static const uint8_t {{ font_prefix }}_bitmaps[] = {
|
||||||
|
{%- for char in chars %}
|
||||||
|
|
||||||
|
/* {{ 'Index: 0x%02x, char: \\x%02x, offset: 0x%04x'|format(char.index, char.code, char.offset) }} */
|
||||||
|
{%- for row in char.rows %}
|
||||||
|
{% for byte in row.data %}{{ '0x%02x'|format(byte) }}, {% endfor -%} /* {{ row.asc }} */
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- endfor %}
|
||||||
|
};
|
||||||
|
|
||||||
|
const font_char_desc_t {{ font_prefix }}_descriptors[] = {
|
||||||
|
{%- for char in chars %}
|
||||||
|
{ {{ '0x%02x'|format(font.size[0]) }}, {{ '0x%04x'|format(char.offset) }} }, /* {{ 'Index: 0x%02x, char: \\x%02x'|format(char.index, char.code) }} */
|
||||||
|
{%- endfor %}
|
||||||
|
};
|
||||||
|
|
||||||
|
const font_info_t {{ font_prefix }}_info =
|
||||||
|
{
|
||||||
|
.height = {{ font.size[1] }}, /* Character height */
|
||||||
|
.c = 0, /* C */
|
||||||
|
.char_start = {{ font.first }}, /* Start character */
|
||||||
|
.char_end = {{ font.last }}, /* End character */
|
||||||
|
.char_descriptors = {{ font_prefix }}_descriptors, /* Character descriptor array */
|
||||||
|
.bitmap = {{ font_prefix }}_bitmaps, /* Character bitmap array */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* {{ header_id }} */
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
#include <esp/gpio.h>
|
#include <esp/gpio.h>
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
#include <task.h>
|
#include <task.h>
|
||||||
#include <fonts/fonts.h>
|
|
||||||
|
|
||||||
#define SPI_BUS 1
|
#define SPI_BUS 1
|
||||||
|
|
||||||
|
|
@ -72,7 +71,7 @@
|
||||||
#define abs(x) ((x)<0 ? -(x) : (x))
|
#define abs(x) ((x)<0 ? -(x) : (x))
|
||||||
#define swap(x, y) do { typeof(x) temp##x##y = x; x = y; y = temp##x##y; } while (0)
|
#define swap(x, y) do { typeof(x) temp##x##y = x; x = y; y = temp##x##y; } while (0)
|
||||||
|
|
||||||
const font_info_t* font ; // save font selection
|
static const font_info_t *font; // save font selection
|
||||||
|
|
||||||
/* Issue a command to SSD1306 device
|
/* Issue a command to SSD1306 device
|
||||||
* I2C proto format:
|
* I2C proto format:
|
||||||
|
|
@ -772,7 +771,7 @@ int ssd1306_draw_line(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t y0,
|
||||||
ystep = -1;
|
ystep = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; x0<=x1; x0++) {
|
for (; x0 <= x1; x0++) {
|
||||||
if (steep) {
|
if (steep) {
|
||||||
if ((err = ssd1306_draw_pixel(dev, fb, y0, x0, color)))
|
if ((err = ssd1306_draw_pixel(dev, fb, y0, x0, color)))
|
||||||
return err;
|
return err;
|
||||||
|
|
@ -844,7 +843,7 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
|
||||||
if(y1 == y2) last = y1; // Include y1 scanline
|
if(y1 == y2) last = y1; // Include y1 scanline
|
||||||
else last = y1-1; // Skip it
|
else last = y1-1; // Skip it
|
||||||
|
|
||||||
for(y=y0; y<=last; y++) {
|
for (y = y0; y <= last; y++) {
|
||||||
a = x0 + sa / dy01;
|
a = x0 + sa / dy01;
|
||||||
b = x0 + sb / dy02;
|
b = x0 + sb / dy02;
|
||||||
sa += dx01;
|
sa += dx01;
|
||||||
|
|
@ -862,7 +861,7 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
|
||||||
// 0-2 and 1-2. This loop is skipped if y1=y2.
|
// 0-2 and 1-2. This loop is skipped if y1=y2.
|
||||||
sa = dx12 * (y - y1);
|
sa = dx12 * (y - y1);
|
||||||
sb = dx02 * (y - y0);
|
sb = dx02 * (y - y0);
|
||||||
for(; y<=y2; y++) {
|
for (; y <= y2; y++) {
|
||||||
a = x1 + sa / dy12;
|
a = x1 + sa / dy12;
|
||||||
b = x0 + sb / dy02;
|
b = x0 + sb / dy02;
|
||||||
sa += dx12;
|
sa += dx12;
|
||||||
|
|
@ -878,13 +877,15 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssd1306_select_font(uint8_t idx)
|
int ssd1306_select_font(font_face_t font_face)
|
||||||
{
|
{
|
||||||
if (idx < NUM_FONTS)
|
if (font_face < fonts_count)
|
||||||
font = fonts[idx];
|
font = fonts[font_face];
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
return 0 ;
|
if (!font)
|
||||||
|
return -EINVAL;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, uint8_t x, uint8_t y, char c, ssd1306_color_t foreground, ssd1306_color_t background)
|
uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, uint8_t x, uint8_t y, char c, ssd1306_color_t foreground, ssd1306_color_t background)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fonts/fonts.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
@ -418,7 +419,7 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
|
||||||
* @param idx id value of the font
|
* @param idx id value of the font
|
||||||
* @return Non-zero if error occured
|
* @return Non-zero if error occured
|
||||||
*/
|
*/
|
||||||
int ssd1306_select_font(uint8_t idx);
|
int ssd1306_select_font(font_face_t font_face);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the height of current selected font
|
* Get the height of current selected font
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue