limit display checks

This commit is contained in:
philippe44
2025-02-17 22:39:48 +01:00
parent 1f220895e6
commit a22f75a13a
4 changed files with 17 additions and 18 deletions

View File

@@ -1,3 +1,6 @@
2025-02-17
- reverse some checks on display not NULL in gds.c. As it is about being fast, I'd prefer the caller to know that there is no display and don't call. I'm sure I have missed something when there is only led_vu and no display, but people will remind me soon enough :-)
2024-09-28
- add dedicated volume encoder
- fix memory leak in rotary config creation

View File

@@ -54,7 +54,6 @@ struct GDS_Device* GDS_AutoDetect( char *Driver, GDS_DetectFunc* DetectFunc[], s
}
void GDS_ClearExt(struct GDS_Device* Device, bool full, ...) {
GDS_CHECK_FOR_DEVICE(Device,return);
bool commit = true;
if (full) {
@@ -75,7 +74,6 @@ void GDS_ClearExt(struct GDS_Device* Device, bool full, ...) {
}
void GDS_Clear( struct GDS_Device* Device, int Color ) {
GDS_CHECK_FOR_DEVICE(Device,return);
if (Color == GDS_COLOR_BLACK) memset( Device->Framebuffer, 0, Device->FramebufferSize );
else if (Device->Depth == 1) memset( Device->Framebuffer, 0xff, Device->FramebufferSize );
else if (Device->Depth == 4) memset( Device->Framebuffer, Color | (Color << 4), Device->FramebufferSize );
@@ -91,7 +89,6 @@ void GDS_Clear( struct GDS_Device* Device, int Color ) {
}
void GDS_ClearWindow( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color ) {
GDS_CHECK_FOR_DEVICE(Device,return);
// -1 means up to width/height
if (x2 < 0) x2 = Device->Width - 1;
if (y2 < 0) y2 = Device->Height - 1;
@@ -161,13 +158,11 @@ void GDS_ClearWindow( struct GDS_Device* Device, int x1, int y1, int x2, int y2,
}
void GDS_Update( struct GDS_Device* Device ) {
GDS_CHECK_FOR_DEVICE(Device,return);
if (Device->Dirty) Device->Update( Device );
Device->Dirty = false;
}
bool GDS_Reset( struct GDS_Device* Device ) {
GDS_CHECK_FOR_DEVICE(Device,return false);
if ( Device->RSTPin >= 0 ) {
gpio_set_level( Device->RSTPin, 0 );
vTaskDelay( pdMS_TO_TICKS( 100 ) );
@@ -232,7 +227,7 @@ static void IRAM_ATTR DrawPixel24Fast( struct GDS_Device* Device, int X, int Y,
}
bool GDS_Init( struct GDS_Device* Device ) {
GDS_CHECK_FOR_DEVICE(Device,return false);
if (Device->Depth > 8) Device->FramebufferSize = Device->Width * Device->Height * ((8 + Device->Depth - 1) / 8);
else Device->FramebufferSize = (Device->Width * Device->Height) / (8 / Device->Depth);
@@ -279,7 +274,6 @@ bool GDS_Init( struct GDS_Device* Device ) {
}
int GDS_GrayMap( struct GDS_Device* Device, uint8_t Level) {
GDS_CHECK_FOR_DEVICE(Device,return -1);
switch(Device->Mode) {
case GDS_MONO: return Level;
case GDS_GRAYSCALE: return Level >> (8 - Device->Depth);
@@ -306,7 +300,6 @@ int GDS_GrayMap( struct GDS_Device* Device, uint8_t Level) {
}
void GDS_SetContrast( struct GDS_Device* Device, uint8_t Contrast ) {
GDS_CHECK_FOR_DEVICE(Device,return);
if (Device->SetContrast) Device->SetContrast( Device, Contrast );
else if (Device->Backlight.Pin >= 0) {
Device->Backlight.PWM = PWMConfig.Max * powf(Contrast / 255.0, 3);
@@ -315,12 +308,12 @@ void GDS_SetContrast( struct GDS_Device* Device, uint8_t Contrast ) {
}
}
void GDS_SetLayout( struct GDS_Device* Device, struct GDS_Layout *Layout ) { if (Device && Device->SetLayout) Device->SetLayout( Device, Layout ); }
void GDS_SetDirty( struct GDS_Device* Device ) { GDS_CHECK_FOR_DEVICE(Device,return); Device->Dirty = true; }
void GDS_SetLayout( struct GDS_Device* Device, struct GDS_Layout *Layout ) { if (Device->SetLayout) Device->SetLayout( Device, Layout ); }
void GDS_SetDirty( struct GDS_Device* Device ) { Device->Dirty = true; }
int GDS_GetWidth( struct GDS_Device* Device ) { return Device ? Device->Width : 0; }
void GDS_SetTextWidth( struct GDS_Device* Device, int TextWidth ) { GDS_CHECK_FOR_DEVICE(Device,return); Device->TextWidth = Device && TextWidth && TextWidth < Device->Width ? TextWidth : Device->Width; }
void GDS_SetTextWidth( struct GDS_Device* Device, int TextWidth ) { Device->TextWidth = Device && TextWidth && TextWidth < Device->Width ? TextWidth : Device->Width; }
int GDS_GetHeight( struct GDS_Device* Device ) { return Device ? Device->Height : 0; }
int GDS_GetDepth( struct GDS_Device* Device ) { return Device ? Device->Depth : 0; }
int GDS_GetMode( struct GDS_Device* Device ) { return Device ? Device->Mode : 0; }
void GDS_DisplayOn( struct GDS_Device* Device ) { if (Device && Device->DisplayOn) Device->DisplayOn( Device ); }
void GDS_DisplayOff( struct GDS_Device* Device ) { if (Device && Device->DisplayOff) Device->DisplayOff( Device ); }
void GDS_DisplayOn( struct GDS_Device* Device ) { if (Device->DisplayOn) Device->DisplayOn( Device ); }
void GDS_DisplayOff( struct GDS_Device* Device ) { if (Device->DisplayOff) Device->DisplayOff( Device ); }

View File

@@ -52,6 +52,5 @@ int GDS_GrayMap( struct GDS_Device* Device, uint8_t Level );
void GDS_ClearExt( struct GDS_Device* Device, bool full, ...);
void GDS_Clear( struct GDS_Device* Device, int Color );
void GDS_ClearWindow( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color );
#define GDS_CHECK_FOR_DEVICE(dev,ret_act) if(!dev) ret_act
#endif

View File

@@ -687,7 +687,8 @@ void draw_VU(struct GDS_Device * display, int level, int x, int y, int width, bo
static void grfe_handler( u8_t *data, int len) {
struct grfe_packet *pkt = (struct grfe_packet*) data;
GDS_CHECK_FOR_DEVICE(display,return);
if (!display) return;
// we don't support transition, simply claim we're done
if (pkt->transition != 'c') {
LOG_INFO("Transition %c requested with offset %hu, param %d", pkt->transition, pkt->offset, pkt->param);
@@ -764,6 +765,8 @@ static void grfs_handler(u8_t *data, int len) {
int size = len - sizeof(struct grfs_packet);
int offset = htons(pkt->offset);
if (!display) return;
LOG_DEBUG("grfs s:%u d:%u p:%u sp:%u by:%hu m:%hu w:%hu o:%hu",
(int) pkt->screen,
(int) pkt->direction, // 1=left, 2=right
@@ -775,7 +778,6 @@ static void grfs_handler(u8_t *data, int len) {
htons(pkt->offset) // offset if multiple packets are sent
);
GDS_CHECK_FOR_DEVICE(display,return);
// new grfs frame, build scroller info
if (!offset) {
// use the display as a general lock
@@ -820,9 +822,10 @@ static void grfs_handler(u8_t *data, int len) {
static void grfg_handler(u8_t *data, int len) {
struct grfg_packet *pkt = (struct grfg_packet*) data;
if (!display) return;
LOG_DEBUG("gfrg s:%hu w:%hu (len:%u)", htons(pkt->screen), htons(pkt->width), len);
GDS_CHECK_FOR_DEVICE(display,return);
// full screen artwork or for small screen, visu has priority when full screen
if (((visu.mode & VISU_ESP32) && !visu.col && visu.row < displayer.height) || artwork.full) {
return;
@@ -867,7 +870,8 @@ static void grfa_handler(u8_t *data, int len) {
int offset = htonl(pkt->offset);
int length = htonl(pkt->length);
GDS_CHECK_FOR_DEVICE(display,return);
if (!display) return;
// when using full screen visualizer on small screen there is a brief overlay
artwork.enable = (length != 0);