Merge branch 'httpd' of github.com:sle118/squeezelite-esp32 into httpd

This commit is contained in:
Christian Herzog
2020-03-02 14:39:58 +01:00
10 changed files with 104 additions and 111 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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 ); }
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

@@ -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;

View File

@@ -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 );
}

View File

@@ -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 );
}
}

View File

@@ -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 ) {

View File

@@ -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 ) {

View File

@@ -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;
@@ -82,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)",
@@ -143,9 +143,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);
}
@@ -153,7 +153,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, ...){
@@ -282,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;
@@ -306,12 +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;
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;
@@ -428,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;
@@ -447,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;
@@ -457,27 +460,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, ...){
@@ -503,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;
@@ -512,7 +525,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){
@@ -556,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);
@@ -613,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);