mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-29 05:40:50 +03:00
big merge
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
idf_component_register(SRCS operator.cpp utf8.c trace.c
|
||||
REQUIRES esp_common pthread
|
||||
idf_component_register(SRCS operator.cpp tools.c
|
||||
REQUIRES esp_common pthread
|
||||
INCLUDE_DIRS .
|
||||
PRIV_REQUIRES services freertos pthread esp_common
|
||||
)
|
||||
|
||||
#doing our own implementation of new operator for some pre-compiled binaries
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
#include <stdlib.h> // for malloc and free
|
||||
void* operator new(unsigned int size) { return malloc(size); }
|
||||
void operator delete(void* ptr) { if (ptr) free(ptr); }
|
||||
#include <memory>
|
||||
#include <esp_heap_caps.h>
|
||||
|
||||
void* operator new(std::size_t count) {
|
||||
return heap_caps_malloc(count, MALLOC_CAP_SPIRAM);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr) noexcept {
|
||||
if (ptr) free(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
// C++17 only
|
||||
void* operator new (std::size_t count, std::align_val_t alignment) {
|
||||
return heap_caps_malloc(count, MALLOC_CAP_SPIRAM);
|
||||
}
|
||||
|
||||
// C++17 only
|
||||
void operator delete(void* ptr, std::align_val_t alignment) noexcept {
|
||||
if (ptr) free(ptr);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
#define SQUEEZELITE_ESP32_RELEASE_URL "https://github.com/sle118/squeezelite-esp32/releases"
|
||||
#endif
|
||||
extern bool is_recovery_running;
|
||||
extern esp_err_t run_command(char * line);
|
||||
extern bool wait_for_wifi();
|
||||
extern bool console_push(const char * data, size_t size);
|
||||
extern void console_start();
|
||||
extern pthread_cond_t wifi_connect_suspend_cond;
|
||||
extern pthread_t wifi_connect_suspend_mutex;
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
/*
|
||||
* (c) Philippe G. 20201, philippe_44@outlook.com
|
||||
* see other copyrights below
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "tools.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
const static char TAG[] = "tools";
|
||||
|
||||
/****************************************************************************************
|
||||
* UTF-8 tools
|
||||
*/
|
||||
|
||||
// Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
|
||||
// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
|
||||
// Copyright (c) 2017 ZephRay <zephray@outlook.com>
|
||||
//
|
||||
// utf8to1252 - almost equivalent to iconv -f utf-8 -t windows-1252, but better
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
|
||||
#define TAG "aa"
|
||||
|
||||
#define UTF8_ACCEPT 0
|
||||
#define UTF8_REJECT 1
|
||||
|
||||
@@ -90,4 +105,69 @@ void utf8_decode(char *src) {
|
||||
}
|
||||
|
||||
*dst = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* URL tools
|
||||
*/
|
||||
|
||||
static inline char from_hex(char ch) {
|
||||
return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
|
||||
}
|
||||
|
||||
void url_decode(char *url) {
|
||||
char *p, *src = strdup(url);
|
||||
for (p = src; *src; url++) {
|
||||
*url = *src++;
|
||||
if (*url == '%') {
|
||||
*url = from_hex(*src++) << 4;
|
||||
*url |= from_hex(*src++);
|
||||
} else if (*url == '+') {
|
||||
*url = ' ';
|
||||
}
|
||||
}
|
||||
*url = '\0';
|
||||
free(p);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Memory tools
|
||||
*/
|
||||
|
||||
void * malloc_init_external(size_t sz){
|
||||
void * ptr=NULL;
|
||||
ptr = heap_caps_malloc(sz, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(ptr==NULL){
|
||||
ESP_LOGE(TAG,"malloc_init_external: unable to allocate %d bytes of PSRAM!",sz);
|
||||
}
|
||||
else {
|
||||
memset(ptr,0x00,sz);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void * clone_obj_psram(void * source, size_t source_sz){
|
||||
void * ptr=NULL;
|
||||
ptr = heap_caps_malloc(source_sz, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(ptr==NULL){
|
||||
ESP_LOGE(TAG,"clone_obj_psram: unable to allocate %d bytes of PSRAM!",source_sz);
|
||||
}
|
||||
else {
|
||||
memcpy(ptr,source,source_sz);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char * strdup_psram(const char * source){
|
||||
void * ptr=NULL;
|
||||
size_t source_sz = strlen(source)+1;
|
||||
ptr = heap_caps_malloc(source_sz, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(ptr==NULL){
|
||||
ESP_LOGE(TAG,"strdup_psram: unable to allocate %d bytes of PSRAM! Cannot clone string %s",source_sz,source);
|
||||
}
|
||||
else {
|
||||
memset(ptr,0x00,source_sz);
|
||||
strcpy(ptr,source);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
@@ -10,4 +10,59 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
void utf8_decode(char *src);
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef QUOTE
|
||||
#define QUOTE(name) #name
|
||||
#endif
|
||||
|
||||
#ifndef STR
|
||||
#define STR(macro) QUOTE(macro)
|
||||
#endif
|
||||
|
||||
#ifndef STR_OR_ALT
|
||||
#define STR_OR_ALT(str,alt) (str?str:alt)
|
||||
#endif
|
||||
|
||||
#ifndef STR_OR_BLANK
|
||||
#define STR_OR_BLANK(p) p == NULL ? "" : p
|
||||
#endif
|
||||
|
||||
#define ESP_LOG_DEBUG_EVENT(tag,e) ESP_LOGD(tag,"evt: " e)
|
||||
|
||||
#ifdef ENABLE_MEMTRACE
|
||||
#define MEMTRACE_PRINT_DELTA() memtrace_print_delta(NULL,TAG,__FUNCTION__);
|
||||
#define MEMTRACE_PRINT_DELTA_MESSAGE(x) memtrace_print_delta(x,TAG,__FUNCTION__);
|
||||
#else
|
||||
#define MEMTRACE_PRINT_DELTA()
|
||||
#define MEMTRACE_PRINT_DELTA_MESSAGE(x) ESP_LOGD(TAG,"%s",x);
|
||||
#endif
|
||||
|
||||
#ifndef FREE_AND_NULL
|
||||
#define FREE_AND_NULL(x) if(x) { free(x); x=NULL; }
|
||||
#endif
|
||||
|
||||
#ifndef CASE_TO_STR
|
||||
#define CASE_TO_STR(x) case x: return STR(x); break;
|
||||
#endif
|
||||
|
||||
#define ENUM_TO_STRING(g) \
|
||||
case g: \
|
||||
return STR(g); \
|
||||
break;
|
||||
|
||||
void utf8_decode(char *src);
|
||||
void url_decode(char *url);
|
||||
void* malloc_init_external(size_t sz);
|
||||
void* clone_obj_psram(void * source, size_t source_sz);
|
||||
char* strdup_psram(const char * source);
|
||||
const char* str_or_unknown(const char * str);
|
||||
const char* str_or_null(const char * str);
|
||||
|
||||
extern const char unknown_string_placeholder[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "globdefs.h"
|
||||
#include "esp_event.h"
|
||||
#include "trace.h"
|
||||
|
||||
|
||||
@@ -11,39 +11,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef QUOTE
|
||||
#define QUOTE(name) #name
|
||||
#endif
|
||||
#ifndef STR
|
||||
#define STR(macro) QUOTE(macro)
|
||||
#endif
|
||||
#define ESP_LOG_DEBUG_EVENT(tag,e) ESP_LOGD(tag,"evt: " e)
|
||||
#ifndef STR_OR_ALT
|
||||
#define STR_OR_ALT(str,alt) (str?str:alt)
|
||||
#endif
|
||||
#ifndef STR_OR_BLANK
|
||||
#define STR_OR_BLANK(p) p == NULL ? "" : p
|
||||
#endif
|
||||
#define ENUM_TO_STRING(g) \
|
||||
case g: \
|
||||
return STR(g); \
|
||||
break;
|
||||
extern const char unknown_string_placeholder[];
|
||||
extern const char * str_or_unknown(const char * str);
|
||||
extern const char * str_or_null(const char * str);
|
||||
void memtrace_print_delta(const char * msg, const char * TAG, const char * function);
|
||||
#ifdef ENABLE_MEMTRACE
|
||||
#define MEMTRACE_PRINT_DELTA() memtrace_print_delta(NULL,TAG,__FUNCTION__);
|
||||
#define MEMTRACE_PRINT_DELTA_MESSAGE(x) memtrace_print_delta(x,TAG,__FUNCTION__);
|
||||
#else
|
||||
#define MEMTRACE_PRINT_DELTA()
|
||||
#define MEMTRACE_PRINT_DELTA_MESSAGE(x) ESP_LOGD(TAG,"%s",x);
|
||||
#endif
|
||||
|
||||
#ifndef FREE_AND_NULL
|
||||
#define FREE_AND_NULL(x) if(x) { free(x); x=NULL; }
|
||||
#endif
|
||||
|
||||
#ifndef CASE_TO_STR
|
||||
#define CASE_TO_STR(x) case x: return STR(x); break;
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user