fix ST7789 + move VFLip/HFlip tp "Layout" option - release

This commit is contained in:
Philippe G
2020-07-31 14:50:56 -07:00
parent 4f90002c99
commit bf4358f340
13 changed files with 104 additions and 103 deletions

View File

@@ -73,8 +73,11 @@ static void Update( struct GDS_Device* Device ) {
#endif
}
static void SetHFlip( struct GDS_Device* Device, bool On ) { Device->WriteCommand( Device, On ? 0xA1 : 0xA0 ); }
static void SetVFlip( struct GDS_Device *Device, bool On ) { Device->WriteCommand( Device, On ? 0xC8 : 0xC0 ); }
static void SetLayout( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate ) {
Device->WriteCommand( Device, HFlip ? 0xA1 : 0xA0 );
Device->WriteCommand( Device, VFlip ? 0xC8 : 0xC0 );
}
static void DisplayOn( struct GDS_Device* Device ) { Device->WriteCommand( Device, 0xAF ); }
static void DisplayOff( struct GDS_Device* Device ) { Device->WriteCommand( Device, 0xAE ); }
@@ -117,8 +120,7 @@ static bool Init( struct GDS_Device* Device ) {
Device->WriteCommand( Device, 0x40 + 0x00 );
Device->SetContrast( Device, 0x7F );
// set flip modes
Device->SetVFlip( Device, false );
Device->SetHFlip( Device, false );
Device->SetLayout( Device, false, false, false );
// no Display Inversion
Device->WriteCommand( Device, 0xA6 );
// set Clocks
@@ -135,7 +137,7 @@ static bool Init( struct GDS_Device* Device ) {
static const struct GDS_Device SH1106 = {
.DisplayOn = DisplayOn, .DisplayOff = DisplayOff, .SetContrast = SetContrast,
.SetVFlip = SetVFlip, .SetHFlip = SetHFlip,
.SetLayout = SetLayout,
.Update = Update, .Init = Init,
.Depth = 1,
#if !defined SHADOW_BUFFER && defined USE_IRAM

View File

@@ -85,8 +85,11 @@ static void Update( struct GDS_Device* Device ) {
#endif
}
static void SetHFlip( struct GDS_Device* Device, bool On ) { Device->WriteCommand( Device, On ? 0xA1 : 0xA0 ); }
static void SetVFlip( struct GDS_Device *Device, bool On ) { Device->WriteCommand( Device, On ? 0xC8 : 0xC0 ); }
static void SetLayout( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate ) {
Device->WriteCommand( Device, HFlip ? 0xA1 : 0xA0 );
Device->WriteCommand( Device, VFlip ? 0xC8 : 0xC0 );
}
static void DisplayOn( struct GDS_Device* Device ) { Device->WriteCommand( Device, 0xAF ); }
static void DisplayOff( struct GDS_Device* Device ) { Device->WriteCommand( Device, 0xAE ); }
@@ -129,8 +132,7 @@ static bool Init( struct GDS_Device* Device ) {
Device->WriteCommand( Device, 0x40 + 0x00 );
Device->SetContrast( Device, 0x7F );
// set flip modes
Device->SetVFlip( Device, false );
Device->SetHFlip( Device, false );
Device->SetLayout( Device, false, false, false);
// no Display Inversion
Device->WriteCommand( Device, 0xA6 );
// set Clocks
@@ -150,7 +152,7 @@ static bool Init( struct GDS_Device* Device ) {
static const struct GDS_Device SSD1306 = {
.DisplayOn = DisplayOn, .DisplayOff = DisplayOff, .SetContrast = SetContrast,
.SetVFlip = SetVFlip, .SetHFlip = SetHFlip,
.SetLayout = SetLayout,
.Update = Update, .Init = Init,
.Mode = GDS_MONO, .Depth = 1,
#if !defined SHADOW_BUFFER && defined USE_IRAM

View File

@@ -96,17 +96,10 @@ static void Update( struct GDS_Device* Device ) {
#endif
}
static void SetHFlip( struct GDS_Device* Device, bool On ) {
static void SetLayout( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate ) {
struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private;
Private->ReMap = On ? (Private->ReMap & ~(1 << 1)) : (Private->ReMap | (1 << 1));
Device->WriteCommand( Device, 0xA0 );
Device->WriteData( Device, &Private->ReMap, 1 );
WriteDataByte( Device, 0x11 );
}
static void SetVFlip( struct GDS_Device *Device, bool On ) {
struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private;
Private->ReMap = On ? (Private->ReMap | (1 << 4)) : (Private->ReMap & ~(1 << 4));
Private->ReMap = HFlip ? (Private->ReMap & ~(1 << 1)) : (Private->ReMap | (1 << 1));
Private->ReMap = VFlip ? (Private->ReMap | (1 << 4)) : (Private->ReMap & ~(1 << 4));
Device->WriteCommand( Device, 0xA0 );
Device->WriteData( Device, &Private->ReMap, 1 );
WriteDataByte( Device, 0x11 );
@@ -152,8 +145,7 @@ static bool Init( struct GDS_Device* Device ) {
// set flip modes
Private->ReMap = 0;
Device->SetVFlip( Device, false );
Device->SetHFlip( Device, false );
Device->SetLayout( Device, false, false, false);
// set Clocks
Device->WriteCommand( Device, 0xB3 );
@@ -187,7 +179,7 @@ static bool Init( struct GDS_Device* Device ) {
static const struct GDS_Device SSD1322 = {
.DisplayOn = DisplayOn, .DisplayOff = DisplayOff, .SetContrast = SetContrast,
.SetVFlip = SetVFlip, .SetHFlip = SetHFlip,
.SetLayout = SetLayout,
.Update = Update, .Init = Init,
.Mode = GDS_GRAYSCALE, .Depth = 4,
};

View File

@@ -222,18 +222,15 @@ static void DrawBitmapCBR(struct GDS_Device* Device, uint8_t *Data, int Width, i
}
}
static void SetHFlip( struct GDS_Device* Device, bool On ) {
static void SetLayout( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate ) {
struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private;
if (Private->Model == SSD1326) Private->ReMap = On ? (Private->ReMap | ((1 << 0) | (1 << 2))) : (Private->ReMap & ~((1 << 0) | (1 << 2)));
else Private->ReMap = On ? (Private->ReMap | ((1 << 0) | (1 << 1))) : (Private->ReMap & ~((1 << 0) | (1 << 1)));
Device->WriteCommand( Device, 0xA0 );
Device->WriteCommand( Device, Private->ReMap );
if (Private->Model == SSD1326) {
Private->ReMap = HFlip ? (Private->ReMap | ((1 << 0) | (1 << 2))) : (Private->ReMap & ~((1 << 0) | (1 << 2)));
Private->ReMap = HFlip ? (Private->ReMap | (1 << 1)) : (Private->ReMap & ~(1 << 1));
} else {
Private->ReMap = VFlip ? (Private->ReMap | ((1 << 0) | (1 << 1))) : (Private->ReMap & ~((1 << 0) | (1 << 1)));
Private->ReMap = VFlip ? (Private->ReMap | (1 << 4)) : (Private->ReMap & ~(1 << 4));
}
static void SetVFlip( struct GDS_Device *Device, bool On ) {
struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private;
if (Private->Model == SSD1326) Private->ReMap = On ? (Private->ReMap | (1 << 1)) : (Private->ReMap & ~(1 << 1));
else Private->ReMap = On ? (Private->ReMap | (1 << 4)) : (Private->ReMap & ~(1 << 4));
Device->WriteCommand( Device, 0xA0 );
Device->WriteCommand( Device, Private->ReMap );
}
@@ -291,8 +288,7 @@ static bool Init( struct GDS_Device* Device ) {
Device->WriteCommand( Device, 0x00 );
Device->SetContrast( Device, 0x7F );
// set flip modes
Device->SetVFlip( Device, false );
Device->SetHFlip( Device, false );
Device->SetLayout( Device, false, false, false );
// no Display Inversion
Device->WriteCommand( Device, 0xA6 );
// set Clocks
@@ -316,7 +312,7 @@ static bool Init( struct GDS_Device* Device ) {
static const struct GDS_Device SSD132x = {
.DisplayOn = DisplayOn, .DisplayOff = DisplayOff, .SetContrast = SetContrast,
.SetVFlip = SetVFlip, .SetHFlip = SetHFlip,
.SetLayout = SetLayout,
.Update = Update4, .Init = Init,
.Mode = GDS_GRAYSCALE, .Depth = 4,
};

View File

@@ -164,30 +164,27 @@ static void Update24( struct GDS_Device* Device ) {
#else
// always update by full lines
SetColumnAddress( Device, 0, Device->Width - 1);
for (int r = 0; r < Device->Height; r += min(Private->PageSize, Device->Height - r)) {
int Height = min(Private->PageSize, Device->Height - r);
SetRowAddress( Device, r, r + Height - 1 );
Device->WriteCommand(Device, ENABLE_WRITE);
for (int r = 0; r < Device->Height; r += Private->PageSize) {
SetRowAddress( Device, r, r + Private->PageSize - 1 );
if (Private->iRAM) {
memcpy(Private->iRAM, Device->Framebuffer + r * Device->Width * 3, Private->PageSize * Device->Width * 3 );
Device->WriteData( Device, Private->iRAM, Private->PageSize * Device->Width * 3 );
memcpy(Private->iRAM, Device->Framebuffer + r * Device->Width * 3, Height * Device->Width * 3 );
Device->WriteData( Device, Private->iRAM, Height * Device->Width * 3 );
} else {
Device->WriteData( Device, Device->Framebuffer + r * Device->Width * 3, Private->PageSize * Device->Width * 3 );
Device->WriteData( Device, Device->Framebuffer + r * Device->Width * 3, Height * Device->Width * 3 );
}
}
#endif
}
static void SetHFlip( struct GDS_Device* Device, bool On ) {
static void SetLayout( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate ) {
struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private;
Private->ReMap = On ? (Private->ReMap & ~(1 << 1)) : (Private->ReMap | (1 << 1));
Device->WriteCommand( Device, 0xA0 );
WriteByte( Device, Private->ReMap );
}
static void SetVFlip( struct GDS_Device *Device, bool On ) {
struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private;
Private->ReMap = On ? (Private->ReMap | (1 << 4)) : (Private->ReMap & ~(1 << 4));
Private->ReMap = HFlip ? (Private->ReMap & ~(1 << 1)) : (Private->ReMap | (1 << 1));
Private->ReMap = VFlip ? (Private->ReMap | (1 << 4)) : (Private->ReMap & ~(1 << 4));
Device->WriteCommand( Device, 0xA0 );
WriteByte( Device, Private->ReMap );
}
@@ -242,8 +239,7 @@ static bool Init( struct GDS_Device* Device ) {
// set flip modes & contrast
Device->SetContrast( Device, 0x7F );
Device->SetVFlip( Device, false );
Device->SetHFlip( Device, false );
Device->SetLayout( Device, false, false, false );
// set Adressing Mode Horizontal
Private->ReMap |= (0 << 2);
@@ -265,7 +261,7 @@ static bool Init( struct GDS_Device* Device ) {
static const struct GDS_Device SSD1351 = {
.DisplayOn = DisplayOn, .DisplayOff = DisplayOff, .SetContrast = SetContrast,
.SetVFlip = SetVFlip, .SetHFlip = SetHFlip,
.SetLayout = SetLayout,
.Update = Update16, .Init = Init,
.Mode = GDS_RGB565, .Depth = 16,
};

View File

@@ -29,6 +29,9 @@ enum { ST7735, ST7789 };
struct PrivateSpace {
uint8_t *iRAM, *Shadowbuffer;
struct {
uint16_t Height, Width;
} Offset;
uint8_t MADCtl, PageSize;
uint8_t Model;
};
@@ -75,8 +78,8 @@ static void Update16( struct GDS_Device* Device ) {
FirstCol *= 2;
LastCol = LastCol * 2 + 1;
SetRowAddress( Device, FirstRow, LastRow );
SetColumnAddress( Device, FirstCol, LastCol );
SetRowAddress( Device, FirstRow + Private->Offset.Height, LastRow + Private->Offset.Height);
SetColumnAddress( Device, FirstCol + Private->Offset.Width, LastCol + Private->Offset.Width );
Device->WriteCommand( Device, ENABLE_WRITE );
int ChunkSize = (LastCol - FirstCol + 1) * 2;
@@ -100,12 +103,12 @@ static void Update16( struct GDS_Device* Device ) {
}
#else
// always update by full lines
SetColumnAddress( Device, 0, Device->Width - 1);
SetColumnAddress( Device, Private->Offset.Width, Device->Width - 1);
for (int r = 0; r < Device->Height; r += min(Private->PageSize, Device->Height - r)) {
int Height = min(Private->PageSize, Device->Height - r);
SetRowAddress( Device, r, r + Height - 1 );
SetRowAddress( Device, Private->Offset.Height + r, Private->Offset.Height + r + Height - 1 );
Device->WriteCommand(Device, ENABLE_WRITE);
if (Private->iRAM) {
@@ -142,8 +145,8 @@ static void Update24( struct GDS_Device* Device ) {
FirstCol = (FirstCol * 2) / 3;
LastCol = (LastCol * 2 + 1) / 3;
SetRowAddress( Device, FirstRow, LastRow );
SetColumnAddress( Device, FirstCol, LastCol );
SetRowAddress( Device, FirstRow + Private->Offset.Height, LastRow + Private->Offset.Height);
SetColumnAddress( Device, FirstCol + Private->Offset.Width, LastCol + Private->Offset.Width );
Device->WriteCommand( Device, ENABLE_WRITE );
int ChunkSize = (LastCol - FirstCol + 1) * 3;
@@ -167,33 +170,43 @@ static void Update24( struct GDS_Device* Device ) {
}
#else
// always update by full lines
SetColumnAddress( Device, 0, Device->Width - 1);
SetColumnAddress( Device, Private->Offset.Width, Device->Width - 1);
for (int r = 0; r < Device->Height; r += min(Private->PageSize, Device->Height - r)) {
int Height = min(Private->PageSize, Device->Height - r);
SetRowAddress( Device, Private->Offset.Height + r, Private->Offset.Height + r + Height - 1 );
Device->WriteCommand(Device, ENABLE_WRITE);
for (int r = 0; r < Device->Height; r += Private->PageSize) {
SetRowAddress( Device, r, r + Private->PageSize - 1 );
if (Private->iRAM) {
memcpy(Private->iRAM, Device->Framebuffer + r * Device->Width * 3, Private->PageSize * Device->Width * 3 );
Device->WriteData( Device, Private->iRAM, Private->PageSize * Device->Width * 3 );
memcpy(Private->iRAM, Device->Framebuffer + r * Device->Width * 3, Height * Device->Width * 3 );
Device->WriteData( Device, Private->iRAM, Height * Device->Width * 3 );
} else {
Device->WriteData( Device, Device->Framebuffer + r * Device->Width * 3, Private->PageSize * Device->Width * 3 );
Device->WriteData( Device, Device->Framebuffer + r * Device->Width * 3, Height * Device->Width * 3 );
}
}
#endif
}
static void SetHFlip( struct GDS_Device* Device, bool On ) {
static void SetLayout( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate ) {
struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private;
Private->MADCtl = On ? (Private->MADCtl & ~(1 << 7)) : (Private->MADCtl | (1 << 7));
Private->MADCtl = HFlip ? (Private->MADCtl | (1 << 7)) : (Private->MADCtl & ~(1 << 7));
Private->MADCtl = VFlip ? (Private->MADCtl | (1 << 6)) : (Private->MADCtl & ~(1 << 6));
Private->MADCtl = Rotate ? (Private->MADCtl | (1 << 5)) : (Private->MADCtl & ~(1 << 5));
Device->WriteCommand( Device, 0x36 );
WriteByte( Device, Private->MADCtl );
if (Private->Model == ST7789) {
if (Rotate) Private->Offset.Width = HFlip ? 320 - Device->Width : 0;
else Private->Offset.Height = HFlip ? 320 - Device->Height : 0;
}
static void SetVFlip( struct GDS_Device *Device, bool On ) {
struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private;
Private->MADCtl = On ? (Private->MADCtl | (1 << 6)) : (Private->MADCtl & ~(1 << 6));
Device->WriteCommand( Device, 0x36 );
WriteByte( Device, Private->MADCtl );
#ifdef SHADOW_BUFFER
// force a full refresh (almost ...)
memset(Private->Shadowbuffer, 0xAA, Device->FramebufferSize);
#endif
}
static void DisplayOn( struct GDS_Device* Device ) { Device->WriteCommand( Device, 0x29 ); }
@@ -202,6 +215,10 @@ static void DisplayOff( struct GDS_Device* Device ) { Device->WriteCommand( Devi
static void SetContrast( struct GDS_Device* Device, uint8_t Contrast ) {
Device->WriteCommand( Device, 0x51 );
WriteByte( Device, Contrast );
Device->SetContrast = NULL;
GDS_SetContrast( Device, Contrast );
Device->SetContrast = SetContrast;
}
static bool Init( struct GDS_Device* Device ) {
@@ -224,21 +241,21 @@ static bool Init( struct GDS_Device* Device ) {
Device->WriteCommand( Device, 0x11 );
// need BGR & Address Mode
Private->MADCtl = (1 << 3) | ((Device->Width > Device->Height ? 1 : 0) << 5);
Private->MADCtl = 1 << 3;
Device->WriteCommand( Device, 0x36 );
WriteByte( Device, Private->MADCtl );
// set flip modes & contrast
GDS_SetContrast( Device, 0x7F );
Device->SetVFlip( Device, false );
Device->SetHFlip( Device, false );
GDS_SetContrast( Device, 0x7f );
Device->SetLayout( Device, false, false, false );
// set screen depth (16/18)
Device->WriteCommand( Device, 0x3A );
WriteByte( Device, Device->Depth == 24 ? 0x06 : 0x05 );
if (Private->Model == ST7789) WriteByte( Device, Device->Depth == 24 ? 0x066 : 0x55 );
else WriteByte( Device, Device->Depth == 24 ? 0x06 : 0x05 );
// no Display Inversion
Device->WriteCommand( Device, 0x20 );
Device->WriteCommand( Device, Private->Model == ST7735 ? 0x20 : 0x21 );
// gone with the wind
Device->DisplayOn( Device );
@@ -249,7 +266,7 @@ static bool Init( struct GDS_Device* Device ) {
static const struct GDS_Device ST77xx = {
.DisplayOn = DisplayOn, .DisplayOff = DisplayOff,
.SetVFlip = SetVFlip, .SetHFlip = SetHFlip,
.SetLayout = SetLayout,
.Update = Update16, .Init = Init,
.Mode = GDS_RGB565, .Depth = 16,
};

View File

@@ -236,8 +236,7 @@ void GDS_SetContrast( struct GDS_Device* Device, uint8_t Contrast ) {
}
}
void GDS_SetHFlip( struct GDS_Device* Device, bool On ) { if (Device->SetHFlip) Device->SetHFlip( Device, On ); }
void GDS_SetVFlip( struct GDS_Device* Device, bool On ) { if (Device->SetVFlip) Device->SetVFlip( Device, On ); }
void GDS_SetLayout( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate ) { if (Device->SetLayout) Device->SetLayout( Device, HFlip, VFlip, Rotate ); }
void GDS_SetDirty( struct GDS_Device* Device ) { Device->Dirty = true; }
int GDS_GetWidth( struct GDS_Device* Device ) { return Device->Width; }
int GDS_GetHeight( struct GDS_Device* Device ) { return Device->Height; }

View File

@@ -35,8 +35,7 @@ void GDS_SetContrast( struct GDS_Device* Device, uint8_t Contrast );
void GDS_DisplayOn( struct GDS_Device* Device );
void GDS_DisplayOff( struct GDS_Device* Device );
void GDS_Update( struct GDS_Device* Device );
void GDS_SetHFlip( struct GDS_Device* Device, bool On );
void GDS_SetVFlip( struct GDS_Device* Device, bool On );
void GDS_SetLayout( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate );
void GDS_SetDirty( struct GDS_Device* Device );
int GDS_GetWidth( struct GDS_Device* Device );
int GDS_GetHeight( struct GDS_Device* Device );

View File

@@ -101,7 +101,7 @@ struct GDS_Device {
uint8_t Alloc;
uint8_t* Framebuffer;
uint16_t FramebufferSize;
uint32_t FramebufferSize;
bool Dirty;
// default fonts when using direct draw
@@ -117,8 +117,7 @@ struct GDS_Device {
void (*SetContrast)( struct GDS_Device* Device, uint8_t Contrast );
void (*DisplayOn)( struct GDS_Device* Device );
void (*DisplayOff)( struct GDS_Device* Device );
void (*SetHFlip)( struct GDS_Device* Device, bool On );
void (*SetVFlip)( struct GDS_Device* Device, bool On );
void (*SetLayout)( struct GDS_Device* Device, bool HFlip, bool VFlip, bool Rotate );
// must provide for depth other than 1 (vertical) and 4 (may provide for optimization)
void (*DrawPixelFast)( struct GDS_Device* Device, int X, int Y, int Color );
void (*DrawBitmapCBR)(struct GDS_Device* Device, uint8_t *Data, int Width, int Height, int Color );
@@ -130,8 +129,8 @@ struct GDS_Device {
WriteCommandProc WriteCommand;
WriteDataProc WriteData;
// 16 bytes for whatever the driver wants (should be aligned as it's 32 bits)
uint32_t Private[4];
// 32 bytes for whatever the driver wants (should be aligned as it's 32 bits)
uint32_t Private[8];
};
bool GDS_Reset( struct GDS_Device* Device );

View File

@@ -119,8 +119,7 @@ void display_init(char *welcome) {
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
static EXT_RAM_ATTR StackType_t xStack[DISPLAYER_STACK_SIZE] __attribute__ ((aligned (4)));
GDS_SetHFlip(display, strcasestr(config, "HFlip") ? true : false);
GDS_SetVFlip(display, strcasestr(config, "VFlip") ? true : false);
GDS_SetLayout( display, strcasestr(config, "HFlip"), strcasestr(config, "VFlip"), strcasestr(config, "rotate"));
GDS_SetFont(display, &Font_droid_sans_fallback_15x17 );
GDS_TextPos(display, GDS_FONT_MEDIUM, GDS_TEXT_CENTERED, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, welcome);

View File

@@ -28,7 +28,6 @@ extern struct buffer *outputbuf;
// this is the only system-wide loglevel variable
extern log_level loglevel;
static bool enable_bt_sink;
static bool enable_airplay;

View File

@@ -69,10 +69,11 @@ static void * squeezelite_thread(){
ESP_LOGV(TAG ,"Freeing argv pointer");
free(thread_parms.argv);
isRunning=false;
ESP_LOGE(TAG, "Exited from squeezelite thread, something's wrong ... rebooting");
ESP_LOGE(TAG, "Exited from squeezelite thread, something's wrong ... rebooting (wait 30s for user to take action)");
if(!wait_for_commit()){
ESP_LOGW(TAG,"Unable to commit configuration. ");
}
vTaskDelay( pdMS_TO_TICKS( 30*1000 ) );
esp_restart();
return NULL;
}