mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 04:57:06 +03:00
initial refactoring
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "Configurator.h"
|
||||
#include "gds.h"
|
||||
#include "gds_private.h"
|
||||
|
||||
@@ -24,14 +24,14 @@
|
||||
#else
|
||||
#define LEDC_SPEED_MODE LEDC_HIGH_SPEED_MODE
|
||||
#endif
|
||||
|
||||
extern bool gds_init_fonts();
|
||||
static struct GDS_Device Display;
|
||||
static struct GDS_BacklightPWM PWMConfig;
|
||||
|
||||
static char TAG[] = "gds";
|
||||
|
||||
struct GDS_Device* GDS_AutoDetect( char *Driver, GDS_DetectFunc* DetectFunc[], struct GDS_BacklightPWM* PWM ) {
|
||||
if (!Driver) return NULL;
|
||||
struct GDS_Device* GDS_AutoDetect( sys_Display * Driver, GDS_DetectFunc* DetectFunc[], struct GDS_BacklightPWM* PWM ) {
|
||||
if (!Driver->has_common || Driver->common.driver == sys_DisplayDriverEnum_UNSPECIFIED_DRIVER) return NULL;
|
||||
if (PWM) PWMConfig = *PWM;
|
||||
|
||||
for (int i = 0; DetectFunc[i]; i++) {
|
||||
@@ -203,7 +203,11 @@ bool GDS_Init( struct GDS_Device* Device ) {
|
||||
}
|
||||
|
||||
bool Res = Device->Init( Device );
|
||||
if(Res){
|
||||
Res = gds_init_fonts();
|
||||
}
|
||||
if (!Res && Device->Framebuffer) free(Device->Framebuffer);
|
||||
|
||||
return Res;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "Configurator.h"
|
||||
|
||||
/* NOTE for drivers:
|
||||
The build-in DrawPixel(Fast), DrawCBR and ClearWindow have optimized for 1 bit
|
||||
@@ -33,9 +34,9 @@ struct GDS_Layout {
|
||||
bool ColorSwap;
|
||||
};
|
||||
|
||||
typedef struct GDS_Device* GDS_DetectFunc(char *Driver, struct GDS_Device *Device);
|
||||
typedef struct GDS_Device* GDS_DetectFunc(sys_Display * Driver, struct GDS_Device *Device);
|
||||
|
||||
struct GDS_Device* GDS_AutoDetect( char *Driver, GDS_DetectFunc* DetectFunc[], struct GDS_BacklightPWM *PWM );
|
||||
struct GDS_Device* GDS_AutoDetect( sys_Display * Driver, GDS_DetectFunc* DetectFunc[], struct GDS_BacklightPWM *PWM );
|
||||
|
||||
void GDS_SetContrast( struct GDS_Device* Device, uint8_t Contrast );
|
||||
void GDS_DisplayOn( struct GDS_Device* Device );
|
||||
|
||||
@@ -14,7 +14,67 @@
|
||||
#include "gds_font.h"
|
||||
#include "gds_draw.h"
|
||||
#include "gds_err.h"
|
||||
#include "esp_spiffs.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "tools.h"
|
||||
static const char * TAG = "gds_font";
|
||||
struct GDS_FontDef * Font_droid_sans_fallback_11x13 = NULL;
|
||||
struct GDS_FontDef * Font_line_1 = NULL;
|
||||
struct GDS_FontDef * Font_line_2 = NULL;
|
||||
|
||||
// struct GDS_FontDef * Font_droid_sans_fallback_15x17 = NULL;
|
||||
// struct GDS_FontDef * Font_droid_sans_fallback_24x28 = NULL;
|
||||
// struct GDS_FontDef * Font_droid_sans_mono_7x13 = NULL;
|
||||
// struct GDS_FontDef * Font_droid_sans_mono_13x24 = NULL;
|
||||
// struct GDS_FontDef * Font_droid_sans_mono_16x31 = NULL;
|
||||
// struct GDS_FontDef * Font_liberation_mono_9x15 = NULL;
|
||||
// struct GDS_FontDef * Font_liberation_mono_13x21 = NULL;
|
||||
// struct GDS_FontDef * Font_liberation_mono_17x30 = NULL;
|
||||
// struct GDS_FontDef * Font_Tarable7Seg_16x32 = NULL;
|
||||
// struct GDS_FontDef * Font_Tarable7Seg_32x64 = NULL;
|
||||
|
||||
|
||||
static bool LoadFont(struct GDS_FontDef ** fontPtr, const char * fileName){
|
||||
if(!fontPtr){
|
||||
ESP_LOGE(TAG, "Invalid pointer for LoadFont");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allocate DMA-capable memory for the font
|
||||
struct GDS_FontDef* loadedFont = load_file_dma(NULL,"fonts",fileName);
|
||||
|
||||
// Check if allocation succeeded
|
||||
if (loadedFont == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to load font");
|
||||
return false;
|
||||
}
|
||||
// Update the pointer
|
||||
*fontPtr = loadedFont;
|
||||
|
||||
ESP_LOGI(TAG, "Successfully loaded font: %s", fileName);
|
||||
return true;
|
||||
}
|
||||
bool gds_init_fonts() {
|
||||
bool success = true;
|
||||
|
||||
// Load the Font_droid_sans_fallback_11x13
|
||||
if (!LoadFont(&Font_droid_sans_fallback_11x13, "droid_sans_fb_11x13.bin")) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Load the Font_line_1
|
||||
if (!LoadFont(&Font_line_1, "line_1.bin")) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Load the Font_line_2
|
||||
if (!LoadFont(&Font_line_2, "line_2.bin")) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
static int RoundUpFontHeight( const struct GDS_FontDef* Font ) {
|
||||
int Height = Font->Height;
|
||||
|
||||
@@ -26,7 +86,7 @@ static int RoundUpFontHeight( const struct GDS_FontDef* Font ) {
|
||||
}
|
||||
|
||||
static const uint8_t* GetCharPtr( const struct GDS_FontDef* Font, char Character ) {
|
||||
return &Font->FontData[ ( Character - Font->StartChar ) * ( ( Font->Width * ( RoundUpFontHeight( Font ) / 8 ) ) + 1 ) ];
|
||||
return &Font->FontData[( Character - Font->StartChar ) * ( ( Font->Width * ( RoundUpFontHeight( Font ) / 8 ) ) + 1 )];
|
||||
}
|
||||
|
||||
void GDS_FontDrawChar( struct GDS_Device* Device, char Character, int x, int y, int Color ) {
|
||||
@@ -130,9 +190,7 @@ int GDS_FontGetCharWidth( struct GDS_Device* Display, char Character ) {
|
||||
|
||||
if ( Character >= Display->Font->StartChar && Character <= Display->Font->EndChar ) {
|
||||
CharPtr = GetCharPtr( Display->Font, Character );
|
||||
|
||||
Width = ( Display->Font->Monospace == true ) ? Display->Font->Width : *CharPtr;
|
||||
|
||||
if ( Display->FontForceMonospace == true ) {
|
||||
Width = Display->Font->Width;
|
||||
}
|
||||
@@ -168,7 +226,6 @@ int GDS_FontMeasureString( struct GDS_Device* Display, const char* Text ) {
|
||||
Width+= GDS_FontGetCharWidth( Display, *Text );
|
||||
}
|
||||
}
|
||||
|
||||
return Width;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,17 +22,21 @@ struct GDS_Device;
|
||||
* 'c': And so on...
|
||||
*/
|
||||
|
||||
#pragma pack(push, 1) // Disable padding
|
||||
struct GDS_FontDef {
|
||||
const uint8_t* FontData;
|
||||
const void* dummy; // 4 bytes (assuming 32-bit pointers)
|
||||
|
||||
int Width;
|
||||
int Height;
|
||||
int Width; // 4 bytes
|
||||
int Height; // 4 bytes
|
||||
int StartChar; // 4 bytes
|
||||
int EndChar; // 4 bytes
|
||||
bool Monospace; // 1 byte
|
||||
|
||||
int StartChar;
|
||||
int EndChar;
|
||||
|
||||
bool Monospace;
|
||||
uint8_t padding[3]; // 3 bytes padding to align to 24 bytes
|
||||
const uint8_t FontData[]; // 4 bytes (assuming 32-bit pointers)
|
||||
};
|
||||
#pragma pack(pop) // Re-enable padding
|
||||
|
||||
|
||||
typedef enum {
|
||||
TextAnchor_East = 0,
|
||||
@@ -45,7 +49,7 @@ typedef enum {
|
||||
TextAnchor_SouthWest,
|
||||
TextAnchor_Center
|
||||
} TextAnchor;
|
||||
|
||||
bool gds_init_fonts();
|
||||
const struct GDS_FontDef* GDS_SetFont( struct GDS_Device* Display, const struct GDS_FontDef* Font );
|
||||
|
||||
void GDS_FontForceProportional( struct GDS_Device* Display, bool Force );
|
||||
@@ -67,23 +71,23 @@ void GDS_FontDrawString( struct GDS_Device* Display, int x, int y, const char* T
|
||||
void GDS_FontDrawAnchoredString( struct GDS_Device* Display, TextAnchor Anchor, const char* Text, int Color );
|
||||
void GDS_FontGetAnchoredStringCoords( struct GDS_Device* Display, int* OutX, int* OutY, TextAnchor Anchor, const char* Text );
|
||||
|
||||
extern const struct GDS_FontDef Font_droid_sans_fallback_11x13;
|
||||
extern const struct GDS_FontDef Font_droid_sans_fallback_15x17;
|
||||
extern const struct GDS_FontDef Font_droid_sans_fallback_24x28;
|
||||
struct GDS_FontDef * Font_droid_sans_fallback_11x13;
|
||||
// const struct GDS_FontDef * Font_droid_sans_fallback_15x17;
|
||||
// const struct GDS_FontDef * Font_droid_sans_fallback_24x28;
|
||||
|
||||
extern const struct GDS_FontDef Font_droid_sans_mono_7x13;
|
||||
extern const struct GDS_FontDef Font_droid_sans_mono_13x24;
|
||||
extern const struct GDS_FontDef Font_droid_sans_mono_16x31;
|
||||
// const struct GDS_FontDef * Font_droid_sans_mono_7x13;
|
||||
// const struct GDS_FontDef * Font_droid_sans_mono_13x24;
|
||||
// const struct GDS_FontDef * Font_droid_sans_mono_16x31;
|
||||
|
||||
extern const struct GDS_FontDef Font_liberation_mono_9x15;
|
||||
extern const struct GDS_FontDef Font_liberation_mono_13x21;
|
||||
extern const struct GDS_FontDef Font_liberation_mono_17x30;
|
||||
// const struct GDS_FontDef * Font_liberation_mono_9x15;
|
||||
// const struct GDS_FontDef * Font_liberation_mono_13x21;
|
||||
// const struct GDS_FontDef * Font_liberation_mono_17x30;
|
||||
|
||||
extern const struct GDS_FontDef Font_Tarable7Seg_16x32;
|
||||
extern const struct GDS_FontDef Font_Tarable7Seg_32x64;
|
||||
// const struct GDS_FontDef * Font_Tarable7Seg_16x32;
|
||||
// const struct GDS_FontDef * Font_Tarable7Seg_32x64;
|
||||
|
||||
extern const struct GDS_FontDef Font_line_1;
|
||||
extern const struct GDS_FontDef Font_line_2;
|
||||
struct GDS_FontDef * Font_line_1;
|
||||
struct GDS_FontDef * Font_line_2;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ static const struct GDS_FontDef *GuessFont( struct GDS_Device *Device, int FontT
|
||||
case GDS_FONT_DEFAULT:
|
||||
return Device->Font;
|
||||
case GDS_FONT_LINE_1:
|
||||
return &Font_line_1;
|
||||
return Font_line_1;
|
||||
case GDS_FONT_LINE_2:
|
||||
return &Font_line_2;
|
||||
return Font_line_2;
|
||||
case GDS_FONT_MEDIUM:
|
||||
//return &Font_droid_sans_fallback_15x17;
|
||||
case GDS_FONT_SMALL:
|
||||
default:
|
||||
return &Font_droid_sans_fallback_11x13;
|
||||
return Font_droid_sans_fallback_11x13;
|
||||
#ifdef USE_LARGE_FONTS
|
||||
case GDS_FONT_LARGE:
|
||||
return &Font_droid_sans_fallback_24x28;
|
||||
@@ -48,7 +48,7 @@ static const struct GDS_FontDef *GuessFont( struct GDS_Device *Device, int FontT
|
||||
case GDS_FONT_SEGMENT:
|
||||
ESP_LOGW(TAG, "large fonts disabled");
|
||||
//return &Font_droid_sans_fallback_15x17;
|
||||
return &Font_droid_sans_fallback_11x13;
|
||||
return Font_droid_sans_fallback_11x13;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user