From 4423fa2ad3b8647ae8c2397eb937bf0542d98697 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Fri, 28 Feb 2020 10:30:11 -0800 Subject: [PATCH 1/6] y line draw boundary --- components/display/core/gds_draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/display/core/gds_draw.c b/components/display/core/gds_draw.c index 60467a33..7e6995e0 100644 --- a/components/display/core/gds_draw.c +++ b/components/display/core/gds_draw.c @@ -58,7 +58,7 @@ void GDS_DrawHLine( struct GDS_Device* Device, int x, int y, int Width, int Colo if (XEnd >= Device->Width) XEnd = Device->Width - 1; if (y < 0) y = 0; - else if (y >= Device->Height) x = Device->Height - 1; + else if (y >= Device->Height) y = Device->Height - 1; for ( ; x < XEnd; x++ ) GDS_DrawPixelFast( Device, x, y, Color ); } From efa818e7949e615c6c3da6e5a4926f27eb0e42e6 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Fri, 28 Feb 2020 20:56:49 -0800 Subject: [PATCH 2/6] Display improvements --- components/display/SH1106.c | 25 +++------ components/display/SSD1306.c | 25 +++------ components/display/SSD132x.c | 51 +++++++------------ components/display/core/gds.c | 22 ++++++-- components/display/core/gds.h | 2 +- components/display/core/gds_private.h | 16 ++++-- .../display/core/ifaces/default_if_i2c.c | 4 +- .../display/core/ifaces/default_if_spi.c | 4 +- components/display/display.c | 4 +- 9 files changed, 67 insertions(+), 86 deletions(-) diff --git a/components/display/SH1106.c b/components/display/SH1106.c index f4b93dfe..ccdc36b8 100644 --- a/components/display/SH1106.c +++ b/components/display/SH1106.c @@ -21,7 +21,7 @@ static char TAG[] = "SH1106"; -struct SH1106_Private { +struct PrivateSpace { uint8_t *Shadowbuffer; }; @@ -40,7 +40,7 @@ static void SetPageAddress( struct GDS_Device* Device, uint8_t Start, uint8_t En static void Update( struct GDS_Device* Device ) { #ifdef SHADOW_BUFFER - struct SH1106_Private *Private = (struct SH1106_Private*) Device->Private; + struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private; // not sure the compiler does not have to redo all calculation in for loops, so local it is int width = Device->Width, rows = Device->Height / 8; uint8_t *optr = Private->Shadowbuffer, *iptr = Device->Framebuffer; @@ -84,27 +84,15 @@ static void SetContrast( struct GDS_Device* Device, uint8_t Contrast ) { } static bool Init( struct GDS_Device* Device ) { - Device->FramebufferSize = ( Device->Width * Device->Height ) / 8; - -// benchmarks showed little gain to have SPI memory already in IRAL vs letting driver copy #ifdef SHADOW_BUFFER - struct SH1106_Private *Private = (struct SH1106_Private*) Device->Private; - Device->Framebuffer = calloc( 1, Device->FramebufferSize ); - NullCheck( Device->Framebuffer, return false ); + struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private; #ifdef USE_IRAM - if (Device->IF == IF_SPI) Private->Shadowbuffer = heap_caps_malloc( Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); + if (Device->IF == GDS_IF_SPI) Private->Shadowbuffer = heap_caps_malloc( Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); else #endif Private->Shadowbuffer = malloc( Device->FramebufferSize ); NullCheck( Private->Shadowbuffer, return false ); memset(Private->Shadowbuffer, 0xFF, Device->FramebufferSize); -#else // not SHADOW_BUFFER -#ifdef USE_IRAM - // benchmarks showed little gain to have SPI memory already in IRAL vs letting driver copy - if (Device->IF == IF_SPI) Device->Framebuffer = heap_caps_calloc( 1, Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); - else -#endif - Device->Framebuffer = calloc( 1, Device->FramebufferSize ); #endif // need to be off and disable display RAM @@ -149,8 +137,6 @@ static const struct GDS_Device SH1106 = { .DisplayOn = DisplayOn, .DisplayOff = DisplayOff, .SetContrast = SetContrast, .SetVFlip = SetVFlip, .SetHFlip = SetHFlip, .Update = Update, .Init = Init, - //.DrawPixelFast = GDS_DrawPixelFast, - //.ClearWindow = ClearWindow, }; struct GDS_Device* SH1106_Detect(char *Driver, struct GDS_Device* Device) { @@ -159,6 +145,9 @@ struct GDS_Device* SH1106_Detect(char *Driver, struct GDS_Device* Device) { if (!Device) Device = calloc(1, sizeof(struct GDS_Device)); *Device = SH1106; Device->Depth = 1; +#if !defined SHADOW_BUFFER && defined USE_IRAM + Device->Alloc = GDS_ALLOC_IRAM_SPI; +#endif ESP_LOGI(TAG, "SH1106 driver"); return Device; diff --git a/components/display/SSD1306.c b/components/display/SSD1306.c index eada1e12..faaacea2 100644 --- a/components/display/SSD1306.c +++ b/components/display/SSD1306.c @@ -21,7 +21,7 @@ static char TAG[] = "SSD1306"; -struct SSD1306_Private { +struct PrivateSpace { uint8_t *Shadowbuffer; }; @@ -40,7 +40,7 @@ static void SetPageAddress( struct GDS_Device* Device, uint8_t Start, uint8_t En static void Update( struct GDS_Device* Device ) { #ifdef SHADOW_BUFFER - struct SSD1306_Private *Private = (struct SSD1306_Private*) Device->Private; + struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private; // not sure the compiler does not have to redo all calculation in for loops, so local it is int width = Device->Width, rows = Device->Height / 8; uint8_t *optr = Private->Shadowbuffer, *iptr = Device->Framebuffer; @@ -96,27 +96,15 @@ static void SetContrast( struct GDS_Device* Device, uint8_t Contrast ) { } static bool Init( struct GDS_Device* Device ) { - Device->FramebufferSize = ( Device->Width * Device->Height ) / 8; - - // benchmarks showed little gain to have SPI memory already in IRAL vs letting driver copy #ifdef SHADOW_BUFFER - struct SSD1306_Private *Private = (struct SSD1306_Private*) Device->Private; - Device->Framebuffer = calloc( 1, Device->FramebufferSize ); - NullCheck( Device->Framebuffer, return false ); + struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private; #ifdef USE_IRAM - if (Device->IF == IF_SPI) Private->Shadowbuffer = heap_caps_malloc( Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); + if (Device->IF == GDS_IF_SPI) Private->Shadowbuffer = heap_caps_malloc( Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); else #endif Private->Shadowbuffer = malloc( Device->FramebufferSize ); NullCheck( Private->Shadowbuffer, return false ); memset(Private->Shadowbuffer, 0xFF, Device->FramebufferSize); -#else // not SHADOW_BUFFER -#ifdef USE_IRAM - // benchmarks showed little gain to have SPI memory already in IRAL vs letting driver copy - if (Device->IF == IF_SPI) Device->Framebuffer = heap_caps_calloc( 1, Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); - else -#endif - Device->Framebuffer = calloc( 1, Device->FramebufferSize ); #endif // need to be off and disable display RAM @@ -164,8 +152,6 @@ static const struct GDS_Device SSD1306 = { .DisplayOn = DisplayOn, .DisplayOff = DisplayOff, .SetContrast = SetContrast, .SetVFlip = SetVFlip, .SetHFlip = SetHFlip, .Update = Update, .Init = Init, - //.DrawPixelFast = GDS_DrawPixelFast, - //.ClearWindow = ClearWindow, }; struct GDS_Device* SSD1306_Detect(char *Driver, struct GDS_Device* Device) { @@ -174,6 +160,9 @@ struct GDS_Device* SSD1306_Detect(char *Driver, struct GDS_Device* Device) { if (!Device) Device = calloc(1, sizeof(struct GDS_Device)); *Device = SSD1306; Device->Depth = 1; +#if !defined SHADOW_BUFFER && defined USE_IRAM + Device->Alloc = GDS_ALLOC_IRAM_SPI; +#endif ESP_LOGI(TAG, "SSD1306 driver"); return Device; diff --git a/components/display/SSD132x.c b/components/display/SSD132x.c index cdbadc2b..217c51c9 100644 --- a/components/display/SSD132x.c +++ b/components/display/SSD132x.c @@ -26,7 +26,7 @@ static char TAG[] = "SSD132x"; enum { SSD1326, SSD1327 }; -struct SSD132x_Private { +struct PrivateSpace { uint8_t *iRAM, *Shadowbuffer; uint8_t ReMap, PageSize; uint8_t Model; @@ -67,7 +67,7 @@ static void SetRowAddress( struct GDS_Device* Device, uint8_t Start, uint8_t End } static void Update4( struct GDS_Device* Device ) { - struct SSD132x_Private *Private = (struct SSD132x_Private*) Device->Private; + struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private; // always update by full lines SetColumnAddress( Device, 0, Device->Width / 2 - 1); @@ -122,7 +122,7 @@ static void Update4( struct GDS_Device* Device ) { */ static void Update1( struct GDS_Device* Device ) { #ifdef SHADOW_BUFFER - struct SSD132x_Private *Private = (struct SSD132x_Private*) Device->Private; + struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private; // not sure the compiler does not have to redo all calculation in for loops, so local it is int width = Device->Width / 8, rows = Device->Height; uint8_t *optr = Private->Shadowbuffer, *iptr = Device->Framebuffer; @@ -198,7 +198,7 @@ static void DrawBitmapCBR(struct GDS_Device* Device, uint8_t *Data, int Width, i } static void SetHFlip( struct GDS_Device* Device, bool On ) { - struct SSD132x_Private *Private = (struct SSD132x_Private*) Device->Private; + 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 ); @@ -206,7 +206,7 @@ static void SetHFlip( struct GDS_Device* Device, bool On ) { } static void SetVFlip( struct GDS_Device *Device, bool On ) { - struct SSD132x_Private *Private = (struct SSD132x_Private*) Device->Private; + 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 ); @@ -222,26 +222,15 @@ static void SetContrast( struct GDS_Device* Device, uint8_t Contrast ) { } static bool Init( struct GDS_Device* Device ) { - struct SSD132x_Private *Private = (struct SSD132x_Private*) Device->Private; + struct PrivateSpace *Private = (struct PrivateSpace*) Device->Private; // find a page size that is not too small is an integer of height Private->PageSize = min(8, PAGE_BLOCK / (Device->Width / 2)); Private->PageSize = Device->Height / (Device->Height / Private->PageSize) ; -#ifdef USE_IRAM - // let SPI driver allocate memory, it has not proven to be more efficient - if (Device->IF == IF_SPI) Private->iRAM = heap_caps_malloc( Private->PageSize * Device->Width / 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); -#endif - Device->FramebufferSize = ( Device->Width * Device->Height ) / 2; - Device->Framebuffer = calloc( 1, Device->FramebufferSize ); - NullCheck( Device->Framebuffer, return false ); - -// benchmarks showed little gain to have SPI memory already in IRAM vs letting driver copy #ifdef SHADOW_BUFFER - Device->Framebuffer = calloc( 1, Device->FramebufferSize ); - NullCheck( Device->Framebuffer, return false ); #ifdef USE_IRAM - if (Device->IF == IF_SPI) { + if (Device->IF == GDS_IF_SPI) { if (Device->Depth == 1) { Private->Shadowbuffer = heap_caps_malloc( Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); } else { @@ -252,20 +241,13 @@ static bool Init( struct GDS_Device* Device ) { #endif Private->Shadowbuffer = malloc( Device->FramebufferSize ); memset(Private->Shadowbuffer, 0xFF, Device->FramebufferSize); -#else // not SHADOW_BUFFER -#ifdef USE_IRAM - if (Device->IF == IF_SPI) { - if (Device->Depth == 1) { - Device->Framebuffer = heap_caps_calloc( 1, Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); - } else { - Device->Framebuffer = calloc( 1, Device->FramebufferSize ); - Private->iRAM = heap_caps_malloc( Private->PageSize * Device->Width / 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); - } - } else -#endif - Device->Framebuffer = calloc( 1, Device->FramebufferSize ); +#else +#ifdef USE_IRAM + if (Device->Depth == 4 && Device->IF == GDS_IF_SPI) Private->iRAM = heap_caps_malloc( Private->PageSize * Device->Width / 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); #endif +#endif + ESP_LOGI(TAG, "SSD1326/7 with bit depth %u, page %u, iRAM %p", Device->Depth, Private->PageSize, Private->iRAM); // need to be off and disable display RAM @@ -317,14 +299,14 @@ static const struct GDS_Device SSD132x = { struct GDS_Device* SSD132x_Detect(char *Driver, struct GDS_Device* Device) { uint8_t Model; - if (!strcasestr(Driver, "SSD1326")) Model = SSD1326; - else if (!strcasestr(Driver, "SSD1327")) Model = SSD1327; + if (strcasestr(Driver, "SSD1326")) Model = SSD1326; + else if (strcasestr(Driver, "SSD1327")) Model = SSD1327; else return NULL; if (!Device) Device = calloc(1, sizeof(struct GDS_Device)); *Device = SSD132x; - ((struct SSD132x_Private*) Device->Private)->Model = Model; + ((struct PrivateSpace*) Device->Private)->Model = Model; sscanf(Driver, "%*[^:]:%c", &Device->Depth); @@ -333,6 +315,9 @@ struct GDS_Device* SSD132x_Detect(char *Driver, struct GDS_Device* Device) { Device->DrawPixelFast = DrawPixel1Fast; Device->DrawBitmapCBR = DrawBitmapCBR; Device->ClearWindow = ClearWindow; +#if !defined SHADOW_BUFFER && defined USE_IRAM + Device->Alloc = GDS_ALLOC_IRAM_SPI; +#endif } else { Device->Depth = 4; } diff --git a/components/display/core/gds.c b/components/display/core/gds.c index 7f59f79e..72567ba4 100644 --- a/components/display/core/gds.c +++ b/components/display/core/gds.c @@ -132,10 +132,22 @@ bool GDS_Reset( struct GDS_Device* Device ) { return true; } -void GDS_SetContrast( struct GDS_Device* Device, uint8_t Contrast ) { Device->SetContrast( Device, Contrast); } -void GDS_SetHFlip( struct GDS_Device* Device, bool On ) { Device->SetHFlip( Device, On ); } -void GDS_SetVFlip( struct GDS_Device* Device, bool On ) { Device->SetVFlip( Device, On ); } +bool GDS_Init( struct GDS_Device* Device ) { + Device->FramebufferSize = ( Device->Width * Device->Height ) / (8 / Device->Depth); + + if ((Device->Alloc && GDS_ALLOC_IRAM) || ((Device->Alloc & GDS_ALLOC_IRAM_SPI) && Device->IF == GDS_IF_SPI)) heap_caps_calloc( 1, Device->FramebufferSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA ); + else Device->Framebuffer = calloc( 1, Device->FramebufferSize ); + NullCheck( Device->Framebuffer, return false ); + + bool Res = Device->Init( Device ); + if (!Res) free(Device->Framebuffer); + return Res; +} + +void GDS_SetContrast( struct GDS_Device* Device, uint8_t Contrast ) { if (Device->SetContrast) Device->SetContrast( Device, 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 ); } int GDS_GetWidth( struct GDS_Device* Device ) { return Device->Width; } int GDS_GetHeight( struct GDS_Device* Device ) { return Device->Height; } -void GDS_DisplayOn( struct GDS_Device* Device ) { Device->DisplayOn( Device ); } -void GDS_DisplayOff( struct GDS_Device* Device ) { Device->DisplayOff( Device ); } \ No newline at end of file +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 ); } \ No newline at end of file diff --git a/components/display/core/gds.h b/components/display/core/gds.h index f1b5475c..d0ec7ef9 100644 --- a/components/display/core/gds.h +++ b/components/display/core/gds.h @@ -19,7 +19,7 @@ enum { GDS_COLOR_L0 = 0, GDS_COLOR_L1 = 1, GDS_COLOR_L2, GDS_COLOR_L3, GDS_COLO }; #define GDS_COLOR_BLACK GDS_COLOR_L0 -#define GDS_COLOR_WHITE GDS_COLOR_L1 +#define GDS_COLOR_WHITE (GDS_COLOR_MAX - 1) #define GDS_COLOR_XOR (GDS_COLOR_MAX + 1) struct GDS_Device; diff --git a/components/display/core/gds_private.h b/components/display/core/gds_private.h index 76fcb167..74fd8630 100644 --- a/components/display/core/gds_private.h +++ b/components/display/core/gds_private.h @@ -7,6 +7,9 @@ #include "gds.h" #include "gds_err.h" +#define GDS_ALLOC_IRAM 0x01 +#define GDS_ALLOC_IRAM_SPI 0x02 + #define GDS_CLIPDEBUG_NONE 0 #define GDS_CLIPDEBUG_WARNING 1 #define GDS_CLIPDEBUG_ERROR 2 @@ -55,8 +58,8 @@ typedef bool ( *WriteDataProc ) ( struct GDS_Device* Device, const uint8_t* Data struct spi_device_t; typedef struct spi_device_t* spi_device_handle_t; -#define IF_SPI 0 -#define IF_I2C 1 +#define GDS_IF_SPI 0 +#define GDS_IF_I2C 1 struct GDS_Device { uint8_t IF; @@ -82,7 +85,8 @@ struct GDS_Device { uint16_t Width; uint16_t Height; uint8_t Depth; - + + uint8_t Alloc; uint8_t* Framebuffer; uint16_t FramebufferSize; bool Dirty; @@ -95,12 +99,13 @@ struct GDS_Device { // various driver-specific method // must always provide bool (*Init)( struct GDS_Device* Device); + void (*Update)( struct GDS_Device* Device ); + // may provide if supported 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 (*Update)( struct GDS_Device* Device ); // 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 ); @@ -117,6 +122,7 @@ struct GDS_Device { }; bool GDS_Reset( struct GDS_Device* Device ); +bool GDS_Init( struct GDS_Device* Device ); inline bool IsPixelVisible( struct GDS_Device* Device, int x, int y ) { bool Result = ( @@ -152,7 +158,7 @@ inline void IRAM_ATTR GDS_DrawPixel1Fast( struct GDS_Device* Device, int X, int if ( Color == GDS_COLOR_XOR ) { *FBOffset ^= BIT( YBit ); } else { - *FBOffset = ( Color == GDS_COLOR_WHITE ) ? *FBOffset | BIT( YBit ) : *FBOffset & ~BIT( YBit ); + *FBOffset = ( Color >= GDS_COLOR_WHITE / 2 ) ? *FBOffset | BIT( YBit ) : *FBOffset & ~BIT( YBit ); } } diff --git a/components/display/core/ifaces/default_if_i2c.c b/components/display/core/ifaces/default_if_i2c.c index c4b91b16..a7545b45 100644 --- a/components/display/core/ifaces/default_if_i2c.c +++ b/components/display/core/ifaces/default_if_i2c.c @@ -73,7 +73,7 @@ bool GDS_I2CAttachDevice( struct GDS_Device* Device, int Width, int Height, int Device->WriteData = I2CDefaultWriteData; Device->Address = I2CAddress; Device->RSTPin = RSTPin; - Device->IF = IF_I2C; + Device->IF = GDS_IF_I2C; Device->Width = Width; Device->Height = Height; @@ -83,7 +83,7 @@ bool GDS_I2CAttachDevice( struct GDS_Device* Device, int Width, int Height, int GDS_Reset( Device ); } - return Device->Init( Device ); + return GDS_Init( Device ); } static bool I2CDefaultWriteBytes( int Address, bool IsCommand, const uint8_t* Data, size_t DataLength ) { diff --git a/components/display/core/ifaces/default_if_spi.c b/components/display/core/ifaces/default_if_spi.c index 0bfb7c4e..7ab48e7a 100644 --- a/components/display/core/ifaces/default_if_spi.c +++ b/components/display/core/ifaces/default_if_spi.c @@ -58,7 +58,7 @@ bool GDS_SPIAttachDevice( struct GDS_Device* Device, int Width, int Height, int Device->SPIHandle = SPIDevice; Device->RSTPin = RSTPin; Device->CSPin = CSPin; - Device->IF = IF_SPI; + Device->IF = GDS_IF_SPI; Device->Width = Width; Device->Height = Height; @@ -68,7 +68,7 @@ bool GDS_SPIAttachDevice( struct GDS_Device* Device, int Width, int Height, int GDS_Reset( Device ); } - return Device->Init( Device ); + return GDS_Init( Device ); } static bool SPIDefaultWriteBytes( spi_device_handle_t SPIHandle, int WriteMode, const uint8_t* Data, size_t DataLength ) { diff --git a/components/display/display.c b/components/display/display.c index 8741cd7b..bcdc505b 100644 --- a/components/display/display.c +++ b/components/display/display.c @@ -59,8 +59,8 @@ static EXT_RAM_ATTR struct { static void displayer_task(void *args); struct GDS_Device *display; -extern GDS_DetectFunc SSD1306_Detect, SSD132x_Detect, SH1106_Detect; -GDS_DetectFunc *drivers[] = { SH1106_Detect, SSD1306_Detect, SSD132x_Detect, NULL }; +extern GDS_DetectFunc SSD1306_Detect, SSD132x_Detect, SH1106_Detect, ELD_Detect; +GDS_DetectFunc *drivers[] = { SH1106_Detect, SSD1306_Detect, SSD132x_Detect, ELD_Detect, NULL }; /**************************************************************************************** * From 2d0eac5aee4a7abebb8c5a0ac80b18151ac2f1c2 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Fri, 28 Feb 2020 20:58:29 -0800 Subject: [PATCH 3/6] Remove ELD reference --- components/display/display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/display/display.c b/components/display/display.c index bcdc505b..8741cd7b 100644 --- a/components/display/display.c +++ b/components/display/display.c @@ -59,8 +59,8 @@ static EXT_RAM_ATTR struct { static void displayer_task(void *args); struct GDS_Device *display; -extern GDS_DetectFunc SSD1306_Detect, SSD132x_Detect, SH1106_Detect, ELD_Detect; -GDS_DetectFunc *drivers[] = { SH1106_Detect, SSD1306_Detect, SSD132x_Detect, ELD_Detect, NULL }; +extern GDS_DetectFunc SSD1306_Detect, SSD132x_Detect, SH1106_Detect; +GDS_DetectFunc *drivers[] = { SH1106_Detect, SSD1306_Detect, SSD132x_Detect, NULL }; /**************************************************************************************** * From a690b177ca702d750263114eed8759756537a915 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sat, 29 Feb 2020 08:41:28 -0500 Subject: [PATCH 4/6] http ota buffer length fix - release --- components/squeezelite-ota/squeezelite-ota.c | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/components/squeezelite-ota/squeezelite-ota.c b/components/squeezelite-ota/squeezelite-ota.c index 1ca23773..0f35e13d 100644 --- a/components/squeezelite-ota/squeezelite-ota.c +++ b/components/squeezelite-ota/squeezelite-ota.c @@ -47,7 +47,7 @@ extern const char * get_certificate(); static const char *TAG = "squeezelite-ota"; esp_http_client_handle_t ota_http_client = NULL; #define IMAGE_HEADER_SIZE sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t) + 1 -#define BUFFSIZE 2048 +#define BUFFSIZE 4096 #define HASH_LEN 32 /* SHA-256 digest length */ typedef struct { char * url; @@ -68,6 +68,7 @@ static struct { ota_type_t ota_type; char * ota_write_data; char * bin_data; + char * http_client_write_buf; bool bOTAStarted; size_t buffer_size; uint8_t lastpct; @@ -312,6 +313,7 @@ esp_err_t init_config(ota_thread_parms_t * p_ota_thread_parms){ ota_config.skip_cert_common_name_check = false; ota_config.url = strdup(p_ota_thread_parms->url); ota_config.max_redirection_count = 3; + ota_config.buffer_size = ota_status.buffer_size; break; case OTA_TYPE_BUFFER: ota_status.bin_data = p_ota_thread_parms->bin; @@ -435,14 +437,14 @@ static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client return ESP_ERR_NO_MEM; } while (1) { - ESP_LOGD(TAG, "Buffer successfully allocated. Reading data chunk. "); + ESP_LOGI(TAG, "Buffer successfully allocated. Reading data chunk. "); int data_read = esp_http_client_read(http_client, local_buff, ota_status.buffer_size); if (data_read < 0) { ESP_LOGE(TAG, "Error: SSL data read error"); err= ESP_FAIL; break; } else if (data_read == 0) { - ESP_LOGD(TAG, "No more data. "); + ESP_LOGI(TAG, "No more data. "); err= ESP_OK; break; } @@ -457,27 +459,37 @@ static esp_err_t _http_connect(esp_http_client_handle_t http_client) esp_err_t err = ESP_FAIL; int status_code, header_ret; do { - ESP_LOGD(TAG, "connecting the http client. "); + ESP_LOGI(TAG, "connecting the http client. "); err = esp_http_client_open(http_client, 0); if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err)); + sendMessaging(MESSAGING_ERROR,"Failed to open HTTP connection: %s", esp_err_to_name(err)); return err; } - ESP_LOGD(TAG, "Fetching headers"); + ESP_LOGI(TAG, "Fetching headers"); header_ret = esp_http_client_fetch_headers(http_client); if (header_ret < 0) { // Error found + sendMessaging(MESSAGING_ERROR,"Header fetch failed"); return header_ret; } - ESP_LOGD(TAG, "HTTP Header fetch completed, found content length of %d",header_ret); + ESP_LOGI(TAG, "HTTP Header fetch completed, found content length of %d",header_ret); status_code = esp_http_client_get_status_code(http_client); ESP_LOGD(TAG, "HTTP status code was %d",status_code); err = _http_handle_response_code(http_client, status_code); if (err != ESP_OK) { + sendMessaging(MESSAGING_ERROR,"HTTP connect error: %s", esp_err_to_name(err)); return err; } + } while (process_again(status_code)); + + if(status_code >=400 && status_code <=900){ + sendMessaging(MESSAGING_ERROR,"Error: HTTP Status %d",status_code); + err=ESP_FAIL; + } + return err; } void ota_task_cleanup(const char * message, ...){ @@ -512,7 +524,6 @@ esp_err_t ota_buffer_all(){ // Open the http connection and follow any redirection err = _http_connect(ota_http_client); if (err != ESP_OK) { - sendMessaging(MESSAGING_ERROR,"Error: HTTP Start read failed. (%s)",esp_err_to_name(err)); return err; } if(ota_status.total_image_len<=0){ From e2d77684e3e8c1bdccfdd9175c8236a67497037d Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sat, 29 Feb 2020 08:45:19 -0500 Subject: [PATCH 5/6] HTTP and Binary upload ota work - release decrease logging verbosity on low level messages merging with master branch correcting buffer size for better OTA redirection/http header parsing --- components/squeezelite-ota/squeezelite-ota.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/squeezelite-ota/squeezelite-ota.c b/components/squeezelite-ota/squeezelite-ota.c index 0f35e13d..e99f2e71 100644 --- a/components/squeezelite-ota/squeezelite-ota.c +++ b/components/squeezelite-ota/squeezelite-ota.c @@ -144,9 +144,9 @@ static void loc_displayer_progressbar(uint8_t pct){ if(!progress_coordinates) progress_coordinates = loc_displayer_get_progress_dft(); int filler_x=progress_coordinates->filler.x1+(int)((float)progress_coordinates->filler.width*(float)pct/(float)100); - ESP_LOGI(TAG,"Drawing %d,%d,%d,%d",progress_coordinates->border.x1,progress_coordinates->border.y1,progress_coordinates->border.x2,progress_coordinates->border.y2); + ESP_LOGD(TAG,"Drawing %d,%d,%d,%d",progress_coordinates->border.x1,progress_coordinates->border.y1,progress_coordinates->border.x2,progress_coordinates->border.y2); GDS_DrawBox(display,progress_coordinates->border.x1,progress_coordinates->border.y1,progress_coordinates->border.x2,progress_coordinates->border.y2,GDS_COLOR_WHITE,false); - ESP_LOGI(TAG,"Drawing %d,%d,%d,%d",progress_coordinates->filler.x1,progress_coordinates->filler.y1,filler_x,progress_coordinates->filler.y2); + ESP_LOGD(TAG,"Drawing %d,%d,%d,%d",progress_coordinates->filler.x1,progress_coordinates->filler.y1,filler_x,progress_coordinates->filler.y2); if(filler_x > progress_coordinates->filler.x1){ GDS_DrawBox(display,progress_coordinates->filler.x1,progress_coordinates->filler.y1,filler_x,progress_coordinates->filler.y2,GDS_COLOR_WHITE,true); } @@ -154,7 +154,7 @@ static void loc_displayer_progressbar(uint8_t pct){ // Clear the inner box GDS_DrawBox(display,progress_coordinates->filler.x1,progress_coordinates->filler.y1,progress_coordinates->filler.x2,progress_coordinates->filler.y2,GDS_COLOR_BLACK,true); } - ESP_LOGI(TAG,"Updating Display"); + ESP_LOGD(TAG,"Updating Display"); GDS_Update(display); } void sendMessaging(messaging_types type,const char * fmt, ...){ @@ -437,14 +437,14 @@ static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client return ESP_ERR_NO_MEM; } while (1) { - ESP_LOGI(TAG, "Buffer successfully allocated. Reading data chunk. "); + ESP_LOGD(TAG, "Buffer successfully allocated. Reading data chunk. "); int data_read = esp_http_client_read(http_client, local_buff, ota_status.buffer_size); if (data_read < 0) { ESP_LOGE(TAG, "Error: SSL data read error"); err= ESP_FAIL; break; } else if (data_read == 0) { - ESP_LOGI(TAG, "No more data. "); + ESP_LOGD(TAG, "No more data. "); err= ESP_OK; break; } @@ -459,21 +459,21 @@ static esp_err_t _http_connect(esp_http_client_handle_t http_client) esp_err_t err = ESP_FAIL; int status_code, header_ret; do { - ESP_LOGI(TAG, "connecting the http client. "); + ESP_LOGD(TAG, "connecting the http client. "); err = esp_http_client_open(http_client, 0); if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err)); sendMessaging(MESSAGING_ERROR,"Failed to open HTTP connection: %s", esp_err_to_name(err)); return err; } - ESP_LOGI(TAG, "Fetching headers"); + ESP_LOGD(TAG, "Fetching headers"); header_ret = esp_http_client_fetch_headers(http_client); if (header_ret < 0) { // Error found sendMessaging(MESSAGING_ERROR,"Header fetch failed"); return header_ret; } - ESP_LOGI(TAG, "HTTP Header fetch completed, found content length of %d",header_ret); + ESP_LOGD(TAG, "HTTP Header fetch completed, found content length of %d",header_ret); status_code = esp_http_client_get_status_code(http_client); ESP_LOGD(TAG, "HTTP status code was %d",status_code); From 4944210ef1f610776b38792fd51950dc6c8a2bf8 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sat, 29 Feb 2020 09:41:13 -0500 Subject: [PATCH 6/6] buffering fix on http OTA - release --- components/squeezelite-ota/squeezelite-ota.c | 47 ++++++++++---------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/components/squeezelite-ota/squeezelite-ota.c b/components/squeezelite-ota/squeezelite-ota.c index e99f2e71..6202c051 100644 --- a/components/squeezelite-ota/squeezelite-ota.c +++ b/components/squeezelite-ota/squeezelite-ota.c @@ -68,7 +68,6 @@ static struct { ota_type_t ota_type; char * ota_write_data; char * bin_data; - char * http_client_write_buf; bool bOTAStarted; size_t buffer_size; uint8_t lastpct; @@ -83,7 +82,7 @@ static struct { } ota_status; struct timeval tv; -static esp_http_client_config_t ota_config; +static esp_http_client_config_t http_client_config; void _printMemStats(){ ESP_LOGD(TAG,"Heap internal:%zu (min:%zu) external:%zu (min:%zu)", @@ -283,7 +282,7 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt) } esp_err_t init_config(ota_thread_parms_t * p_ota_thread_parms){ - memset(&ota_config, 0x00, sizeof(ota_config)); + memset(&http_client_config, 0x00, sizeof(http_client_config)); sendMessaging(MESSAGING_INFO,"Initializing..."); loc_displayer_progressbar(0); ota_status.ota_type= OTA_TYPE_INVALID; @@ -307,13 +306,14 @@ esp_err_t init_config(ota_thread_parms_t * p_ota_thread_parms){ } switch (ota_status.ota_type) { case OTA_TYPE_HTTP: - ota_config.cert_pem =get_certificate(); - ota_config.event_handler = _http_event_handler; - ota_config.disable_auto_redirect=true; - ota_config.skip_cert_common_name_check = false; - ota_config.url = strdup(p_ota_thread_parms->url); - ota_config.max_redirection_count = 3; - ota_config.buffer_size = ota_status.buffer_size; + http_client_config.cert_pem =get_certificate(); + http_client_config.event_handler = _http_event_handler; + http_client_config.disable_auto_redirect=true; + http_client_config.skip_cert_common_name_check = false; + http_client_config.url = strdup(p_ota_thread_parms->url); + http_client_config.max_redirection_count = 3; + // buffer size below is for http read chunks + http_client_config.buffer_size = 1024 ; break; case OTA_TYPE_BUFFER: ota_status.bin_data = p_ota_thread_parms->bin; @@ -430,15 +430,16 @@ static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client ESP_LOGD(TAG, "Redirection done, checking if we need to read the data. "); if (process_again(status_code)) { //ESP_LOGD(TAG, "We have to read some more data. Allocating buffer size %u",ota_config.buffer_size+1); - char * local_buff = heap_caps_malloc(ota_status.buffer_size+1, (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)); + //char * local_buff = heap_caps_malloc(ota_status.buffer_size+1, (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)); + +// if(local_buff==NULL){ +// ESP_LOGE(TAG,"Failed to allocate internal memory buffer for http processing"); +// return ESP_ERR_NO_MEM; +// } - if(local_buff==NULL){ - ESP_LOGE(TAG,"Failed to allocate internal memory buffer for http processing"); - return ESP_ERR_NO_MEM; - } while (1) { - ESP_LOGD(TAG, "Buffer successfully allocated. Reading data chunk. "); - int data_read = esp_http_client_read(http_client, local_buff, ota_status.buffer_size); + ESP_LOGD(TAG, "Reading data chunk. "); + int data_read = esp_http_client_read(http_client, ota_status.ota_write_data, ota_status.buffer_size); if (data_read < 0) { ESP_LOGE(TAG, "Error: SSL data read error"); err= ESP_FAIL; @@ -449,7 +450,7 @@ static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client break; } } - FREE_RESET(local_buff); + //FREE_RESET(local_buff); } return err; @@ -459,21 +460,21 @@ static esp_err_t _http_connect(esp_http_client_handle_t http_client) esp_err_t err = ESP_FAIL; int status_code, header_ret; do { - ESP_LOGD(TAG, "connecting the http client. "); + ESP_LOGI(TAG, "connecting the http client. "); err = esp_http_client_open(http_client, 0); if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err)); sendMessaging(MESSAGING_ERROR,"Failed to open HTTP connection: %s", esp_err_to_name(err)); return err; } - ESP_LOGD(TAG, "Fetching headers"); + ESP_LOGI(TAG, "Fetching headers"); header_ret = esp_http_client_fetch_headers(http_client); if (header_ret < 0) { // Error found sendMessaging(MESSAGING_ERROR,"Header fetch failed"); return header_ret; } - ESP_LOGD(TAG, "HTTP Header fetch completed, found content length of %d",header_ret); + ESP_LOGI(TAG, "HTTP Header fetch completed, found content length of %d",header_ret); status_code = esp_http_client_get_status_code(http_client); ESP_LOGD(TAG, "HTTP status code was %d",status_code); @@ -515,7 +516,7 @@ esp_err_t ota_buffer_all(){ esp_err_t err=ESP_OK; if (ota_status.ota_type == OTA_TYPE_HTTP){ GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Downloading file"); - ota_http_client = esp_http_client_init(&ota_config); + ota_http_client = esp_http_client_init(&http_client_config); if (ota_http_client == NULL) { sendMessaging(MESSAGING_ERROR,"Error: Failed to initialize HTTP connection."); return ESP_FAIL; @@ -567,7 +568,6 @@ esp_err_t ota_header_check(){ ota_status.configured = esp_ota_get_boot_partition(); ota_status.running = esp_ota_get_running_partition(); - ota_status.update_partition = esp_ota_get_next_update_partition(NULL); ota_status.last_invalid_app= esp_ota_get_last_invalid_partition(); ota_status.ota_partition = _get_ota_partition(ESP_PARTITION_SUBTYPE_APP_OTA_0); @@ -624,6 +624,7 @@ void ota_task(void *pvParameter) ESP_LOGD(TAG, "HTTP ota Thread started"); _printMemStats(); + ota_status.update_partition = esp_ota_get_next_update_partition(NULL); ESP_LOGI(TAG,"Initializing OTA configuration"); err = init_config(pvParameter);