39 #include "freertos/FreeRTOS.h" 40 #include "freertos/semphr.h" 42 #include <driver/adc.h> 43 #include <esp_system.h> 50 #ifdef ESP_IDF_VERSION 51 #define FABGL_ESP_IDF_VERSION_VAL ESP_IDF_VERSION_VAL 52 #define FABGL_ESP_IDF_VERSION ESP_IDF_VERSION 54 #define FABGL_ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) 55 #define FABGL_ESP_IDF_VERSION FABGL_ESP_IDF_VERSION_VAL(0, 0, 0) 60 #define GPIO_UNUSED GPIO_NUM_MAX 71 #ifdef BOARD_HAS_PSRAM 72 #define FABGL_NEED_PSRAM_DISABLE_HACK 75 #ifdef CONFIG_SPIRAM_SUPPORT 76 #define FABGL_NEED_PSRAM_DISABLE_HACK 80 #ifdef FABGL_NEED_PSRAM_DISABLE_HACK 81 #define PSRAM_HACK asm(" nop") 88 #define ASM_MEMW asm(" MEMW"); 100 template <
typename T>
101 const T & tmax(
const T & a,
const T & b)
103 return (a < b) ? b : a;
107 constexpr
auto imax = tmax<int>;
110 template <
typename T>
111 const T & tmin(
const T & a,
const T & b)
113 return !(b < a) ? a : b;
117 constexpr
auto imin = tmin<int>;
121 template <
typename T>
122 const T & tclamp(
const T & v,
const T & lo,
const T & hi)
124 return (v < lo ? lo : (v > hi ? hi : v));
128 constexpr
auto iclamp = tclamp<int>;
131 template <
typename T>
132 const T & twrap(
const T & v,
const T & lo,
const T & hi)
134 return (v < lo ? hi : (v > hi ? lo : v));
138 template <
typename T>
139 void tswap(T & v1, T & v2)
147 constexpr
auto iswap = tswap<int>;
150 template <
typename T>
151 T moveItems(T dest, T src,
size_t n)
157 for (pd += n, ps += n; n--;)
167 void rgb222_to_hsv(
int R,
int G,
int B,
double * h,
double * s,
double * v);
170 inline uint16_t changeEndiannesWord(uint16_t value)
172 return ((value & 0xff00) >> 8) | ((value & 0x00ff) << 8);
176 inline uint32_t changeEndiannesDWord(uint32_t value)
178 return ((value & 0xff) << 24) | ((value & 0xff00) << 8) | ((value & 0xff0000) >> 8) | ((value & 0xff000000) >> 24);
195 Point(
int X_,
int Y_) :
X(X_),
Y(Y_) { }
197 Point add(Point
const & p)
const {
return Point(
X + p.X,
Y + p.Y); }
198 Point sub(Point
const & p)
const {
return Point(
X - p.X,
Y - p.Y); }
199 Point neg()
const {
return Point(-
X, -
Y); }
200 bool operator==(Point
const & r) {
return X == r.X &&
Y == r.Y; }
201 bool operator!=(Point
const & r) {
return X != r.X ||
Y != r.Y; }
202 } __attribute__ ((packed));
214 bool operator==(Size
const & r) {
return width == r.width &&
height == r.height; }
215 bool operator!=(Size
const & r) {
return width != r.width ||
height != r.height; }
216 } __attribute__ ((packed));
232 Rect(
int X1_,
int Y1_,
int X2_,
int Y2_) :
X1(X1_),
Y1(Y1_),
X2(X2_),
Y2(Y2_) { }
233 Rect(Rect
const & r) {
X1 = r.X1;
Y1 = r.Y1;
X2 = r.X2;
Y2 = r.Y2; }
235 bool operator==(Rect
const & r) {
return X1 == r.X1 &&
Y1 == r.Y1 &&
X2 == r.X2 &&
Y2 == r.Y2; }
236 bool operator!=(Rect
const & r) {
return X1 != r.X1 ||
Y1 != r.Y1 ||
X2 != r.X2 ||
Y2 != r.Y2; }
237 Point pos()
const {
return Point(
X1,
Y1); }
238 Size size()
const {
return Size(
X2 -
X1 + 1,
Y2 -
Y1 + 1); }
239 int width()
const {
return X2 -
X1 + 1; }
240 int height()
const {
return Y2 -
Y1 + 1; }
241 Rect translate(
int offsetX,
int offsetY)
const {
return Rect(
X1 + offsetX,
Y1 + offsetY,
X2 + offsetX,
Y2 + offsetY); }
242 Rect translate(Point
const & offset)
const {
return Rect(
X1 + offset.X,
Y1 + offset.Y,
X2 + offset.X,
Y2 + offset.Y); }
243 Rect move(Point
const & position)
const {
return Rect(position.X, position.Y, position.X + width() - 1, position.Y + height() - 1); }
244 Rect move(
int x,
int y)
const {
return Rect(x, y, x + width() - 1, y + height() - 1); }
245 Rect shrink(
int value)
const {
return Rect(
X1 + value,
Y1 + value,
X2 - value,
Y2 - value); }
246 Rect hShrink(
int value)
const {
return Rect(
X1 + value,
Y1,
X2 - value,
Y2); }
247 Rect vShrink(
int value)
const {
return Rect(
X1,
Y1 + value,
X2,
Y2 - value); }
248 Rect resize(
int width,
int height)
const {
return Rect(
X1,
Y1,
X1 + width - 1,
Y1 + height - 1); }
249 Rect resize(Size size)
const {
return Rect(
X1,
Y1,
X1 + size.width - 1,
Y1 + size.height - 1); }
250 Rect intersection(Rect
const & rect)
const;
251 bool intersects(Rect
const & rect)
const {
return X1 <= rect.X2 &&
X2 >= rect.X1 &&
Y1 <= rect.Y2 &&
Y2 >= rect.Y1; }
252 bool contains(Rect
const & rect)
const {
return (rect.X1 >=
X1) && (rect.Y1 >=
Y1) && (rect.X2 <=
X2) && (rect.Y2 <=
Y2); }
253 bool contains(Point
const & point)
const {
return point.X >=
X1 && point.Y >=
Y1 && point.X <=
X2 && point.Y <=
Y2; }
254 bool contains(
int x,
int y)
const {
return x >=
X1 && y >=
Y1 && x <=
X2 && y <=
Y2; }
255 Rect merge(Rect
const & rect)
const;
256 } __attribute__ ((packed));
287 #define FONTINFOFLAGS_ITALIC 1 288 #define FONTINFOFLAGS_UNDERLINE 2 289 #define FONTINFODLAFS_STRIKEOUT 4 290 #define FONTINFOFLAGS_VARWIDTH 8 308 uint8_t
const *
data;
309 uint32_t
const * chptr;
324 bool expired(
int valueMS);
336 template <
typename T>
340 StackItem(StackItem * next_, T
const & item_) : next(next_), item(item_) { }
343 template <
typename T>
346 Stack() : m_items(nullptr) { }
347 bool isEmpty() {
return m_items ==
nullptr; }
348 void push(T
const & value) {
349 m_items =
new StackItem<T>(m_items, value);
353 StackItem<T> * iptr = m_items;
354 m_items = iptr->next;
363 for (
auto i = m_items; i; i = i->next)
368 StackItem<T> * m_items;
376 template <
typename ...Params>
380 Delegate() : m_func(nullptr) {
384 Delegate(
const Delegate & c) =
delete;
387 template <
typename Func>
388 Delegate(Func f) : Delegate() {
397 template <
typename Func>
398 void operator=(Func f) {
400 m_closure = [] (
void * func,
const Params & ...params) ->
void { (*(Func *)func)(params...); };
401 m_func = heap_caps_malloc(
sizeof(Func), MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
402 moveItems<uint32_t*>((uint32_t*)m_func, (uint32_t*)&f,
sizeof(Func) /
sizeof(uint32_t));
406 void operator=(
const Delegate&) =
delete;
408 void operator()(
const Params & ...params) {
410 m_closure(m_func, params...);
415 void (*m_closure)(
void * func,
const Params & ...params);
420 heap_caps_free(m_func);
434 int append(
char const * str);
435 int appendFmt(
const char *format, ...);
436 void append(
char const * strlist[],
int count);
437 void appendSepList(
char const * strlist,
char separator);
438 void insert(
int index,
char const * str);
439 void set(
int index,
char const * str);
440 void remove(
int index);
441 int count() {
return m_count; }
442 char const *
get(
int index) {
return m_items[index]; }
445 void select(
int index,
bool value);
447 bool selected(
int index);
448 int getFirstSelected();
449 void copyFrom(StringList
const & src);
450 void copySelectionMapFrom(StringList
const & src);
453 void checkAllocatedSpace(
int requiredItems);
455 char const * * m_items;
466 uint16_t m_allocated;
478 class LightMemoryPool {
480 LightMemoryPool(
int poolSize);
482 void * alloc(
int size);
483 void free(
void * mem) {
if (mem) markFree((uint8_t*)mem - m_mem - 2); }
492 void mark(
int pos, int16_t size,
bool allocated);
493 void markFree(
int pos) { m_mem[pos + 1] &= 0x7f; }
494 int16_t getSize(
int pos);
495 bool isFree(
int pos);
581 DirItem const *
get(
int index) {
return m_items + index; }
591 bool exists(
char const * name,
bool caseSensitive =
true);
615 bool fileCreationDate(
char const * name,
int * year,
int * month,
int * day,
int * hour,
int * minutes,
int * seconds);
630 bool fileUpdateDate(
char const * name,
int * year,
int * month,
int * day,
int * hour,
int * minutes,
int * seconds);
645 bool fileAccessDate(
char const * name,
int * year,
int * month,
int * day,
int * hour,
int * minutes,
int * seconds);
654 void setIncludeHiddenFiles(
bool value) { m_includeHiddenFiles = value; }
670 void remove(
char const * name);
678 void rename(
char const * oldName,
char const * newName);
688 bool truncate(
char const * name,
size_t size);
706 int getFullPath(
char const * name,
char * outPath =
nullptr,
int maxlen = 0);
716 FILE *
openFile(
char const * filename,
char const * mode);
772 static bool mountSDCard(
bool formatOnFail,
char const * mountPath,
size_t maxFiles = 4,
int allocationUnitSize = 16 * 1024,
int MISO = 16,
int MOSI = 17,
int CLK = 14,
int CS = 13);
800 static bool mountSPIFFS(
bool formatOnFail,
char const * mountPath,
size_t maxFiles = 4);
836 static bool getFSInfo(
DriveType driveType,
int drive, int64_t * total, int64_t * used);
841 int countDirEntries(
int * namesLength);
844 static bool s_SPIFFSMounted;
845 static char const * s_SPIFFSMountPath;
846 static size_t s_SPIFFSMaxFiles;
849 static bool s_SDCardMounted;
850 static char const * s_SDCardMountPath;
851 static size_t s_SDCardMaxFiles;
852 static int s_SDCardAllocationUnitSize;
853 static int8_t s_SDCardMISO;
854 static int8_t s_SDCardMOSI;
855 static int8_t s_SDCardCLK;
856 static int8_t s_SDCardCS;
862 bool m_includeHiddenFiles;
863 char * m_namesStorage;
873 bool clipLine(
int & x1,
int & y1,
int & x2,
int & y2, Rect
const & clipRect,
bool checkOnly);
876 void removeRectangle(Stack<Rect> & rects, Rect
const & mainRect, Rect
const & rectToRemove);
879 bool calcParity(uint8_t v);
883 void * realloc32(
void * ptr,
size_t size);
884 void free32(
void * ptr);
887 inline gpio_num_t int2gpio(
int gpio)
889 return gpio == -1 ? GPIO_UNUSED : (gpio_num_t)gpio;
894 inline char digit2hex(
int digit)
896 return digit < 10 ?
'0' + digit :
'a' + digit - 10;
901 inline int hex2digit(
char hex)
903 return hex <
'a' ? hex -
'0' : hex -
'a' + 10;
909 uint32_t msToTicks(
int ms);
926 inline __attribute__((always_inline)) uint32_t getCycleCount() {
928 __asm__ __volatile__(
930 "rsr %0, ccount \n\t" 942 void replacePathSep(
char * path,
char newSep);
952 inline uint32_t
UARTConf(
int parity,
int dataLength,
int stopBits)
954 uint32_t w = 0x8000000 | (dataLength << 2) | (stopBits << 4);
956 w |= (parity == 1 ? 0b10 : 0b11);
961 adc1_channel_t ADC1_GPIO2Channel(gpio_num_t gpio);
964 void esp_intr_alloc_pinnedToCore(
int source,
int flags, intr_handler_t handler,
void * arg, intr_handle_t * ret_handle,
int core);
973 void configureGPIO(gpio_num_t gpio, gpio_mode_t mode);
976 uint32_t getApbFrequency();
978 uint32_t getCPUFrequencyMHz();
984 struct AutoSemaphore {
985 AutoSemaphore(SemaphoreHandle_t mutex) : m_mutex(mutex) { xSemaphoreTake(m_mutex, portMAX_DELAY); }
986 ~AutoSemaphore() { xSemaphoreGive(m_mutex); }
988 SemaphoreHandle_t m_mutex;
1001 static int busiestCore() {
return s_busiestCore; }
1002 static int quietCore() {
return s_busiestCore != -1 ? s_busiestCore ^ 1 : -1; }
1003 static void setBusiestCore(
int core) { s_busiestCore = core; }
1006 static int s_busiestCore;
1332 #define ASCII_NUL 0x00 // Null 1333 #define ASCII_SOH 0x01 // Start of Heading 1334 #define ASCII_CTRLA 0x01 // CTRL-A 1335 #define ASCII_STX 0x02 // Start of Text 1336 #define ASCII_CTRLB 0x02 // CTRL-B 1337 #define ASCII_ETX 0x03 // End Of Text 1338 #define ASCII_CTRLC 0x03 // CTRL-C 1339 #define ASCII_EOT 0x04 // End Of Transmission 1340 #define ASCII_CTRLD 0x04 // CTRL-D 1341 #define ASCII_ENQ 0x05 // Enquiry 1342 #define ASCII_CTRLE 0x05 // CTRL-E 1343 #define ASCII_ACK 0x06 // Acknowledge 1344 #define ASCII_CTRLF 0x06 // CTRL-F 1345 #define ASCII_BEL 0x07 // Bell 1346 #define ASCII_CTRLG 0x07 // CTRL-G 1347 #define ASCII_BS 0x08 // Backspace 1348 #define ASCII_CTRLH 0x08 // CTRL-H 1349 #define ASCII_HT 0x09 // Horizontal Tab 1350 #define ASCII_TAB 0x09 // Horizontal Tab 1351 #define ASCII_CTRLI 0x09 // CTRL-I 1352 #define ASCII_LF 0x0A // Line Feed 1353 #define ASCII_CTRLJ 0x0A // CTRL-J 1354 #define ASCII_VT 0x0B // Vertical Tab 1355 #define ASCII_CTRLK 0x0B // CTRL-K 1356 #define ASCII_FF 0x0C // Form Feed 1357 #define ASCII_CTRLL 0x0C // CTRL-L 1358 #define ASCII_CR 0x0D // Carriage Return 1359 #define ASCII_CTRLM 0x0D // CTRL-M 1360 #define ASCII_SO 0x0E // Shift Out 1361 #define ASCII_CTRLN 0x0E // CTRL-N 1362 #define ASCII_SI 0x0F // Shift In 1363 #define ASCII_CTRLO 0x0F // CTRL-O 1364 #define ASCII_DLE 0x10 // Data Link Escape 1365 #define ASCII_CTRLP 0x10 // CTRL-P 1366 #define ASCII_DC1 0x11 // Device Control 1 1367 #define ASCII_CTRLQ 0x11 // CTRL-Q 1368 #define ASCII_XON 0x11 // Transmission On 1369 #define ASCII_DC2 0x12 // Device Control 2 1370 #define ASCII_CTRLR 0x12 // CTRL-R 1371 #define ASCII_DC3 0x13 // Device Control 3 1372 #define ASCII_XOFF 0x13 // Transmission Off 1373 #define ASCII_CTRLS 0x13 // CTRL-S 1374 #define ASCII_DC4 0x14 // Device Control 4 1375 #define ASCII_CTRLT 0x14 // CTRL-T 1376 #define ASCII_NAK 0x15 // Negative Acknowledge 1377 #define ASCII_CTRLU 0x15 // CTRL-U 1378 #define ASCII_SYN 0x16 // Synchronous Idle 1379 #define ASCII_CTRLV 0x16 // CTRL-V 1380 #define ASCII_ETB 0x17 // End-of-Transmission-Block 1381 #define ASCII_CTRLW 0x17 // CTRL-W 1382 #define ASCII_CAN 0x18 // Cancel 1383 #define ASCII_CTRLX 0x18 // CTRL-X 1384 #define ASCII_EM 0x19 // End of Medium 1385 #define ASCII_CTRLY 0x19 // CTRL-Y 1386 #define ASCII_SUB 0x1A // Substitute 1387 #define ASCII_CTRLZ 0x1A // CTRL-Z 1388 #define ASCII_ESC 0x1B // Escape 1389 #define ASCII_FS 0x1C // File Separator 1390 #define ASCII_GS 0x1D // Group Separator 1391 #define ASCII_RS 0x1E // Record Separator 1392 #define ASCII_US 0x1F // Unit Separator 1393 #define ASCII_SPC 0x20 // Space 1394 #define ASCII_DEL 0x7F // Delete
uint32_t UARTConf(int parity, int dataLength, int stopBits)
Composes UART configuration word.
bool truncate(char const *name, size_t size)
Truncates a file to the specified size.
void rename(char const *oldName, char const *newName)
Renames a file.
static bool mountSDCard(bool formatOnFail, char const *mountPath, size_t maxFiles=4, int allocationUnitSize=16 *1024, int MISO=16, int MOSI=17, int CLK=14, int CS=13)
Mounts filesystem on SD Card.
bool setDirectory(const char *path)
Sets absolute directory path.
A struct which contains a virtual key, key state and associated scan code.
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
size_t fileSize(char const *name)
Determines file size.
This class helps to choice a core for intensive processing tasks.
bool fileUpdateDate(char const *name, int *year, int *month, int *day, int *hour, int *minutes, int *seconds)
Gets file update date and time.
Describes mouse absolute position, scroll wheel delta and buttons status.
bool fileCreationDate(char const *name, int *year, int *month, int *day, int *hour, int *minutes, int *seconds)
Gets file creation date and time.
static void unmountSDCard()
Unmounts filesystem on SD Card.
Represents the coordinate of a point.
FileBrowser item specificator.
char * createTempFilename()
Creates a random temporary filename, with absolute path.
int getFullPath(char const *name, char *outPath=nullptr, int maxlen=0)
Composes a full file path given a relative name.
DriveType getCurrentDriveType()
Returns the drive type of current directory.
static bool format(DriveType driveType, int drive)
Formats SPIFFS or SD Card.
DriveType
This enum defines drive types (SPIFFS or SD Card)
static bool remountSDCard()
Remounts SDCard filesystem, using the same parameters.
char const * directory()
Determines absolute path of current directory.
void setSorted(bool value)
Determines if the items are sorted.
ChipPackage
This enum defines ESP32 module types (packages)
Represents a bidimensional size.
void makeDirectory(char const *dirname)
Creates a directory.
bool fileAccessDate(char const *name, int *year, int *month, int *day, int *hour, int *minutes, int *seconds)
Gets file access date and time.
static DriveType getDriveType(char const *path)
Returns the drive type of specified path.
void changeDirectory(const char *subdir)
Sets relative directory path.
FILE * openFile(char const *filename, char const *mode)
Opens a file from current directory.
static bool mountSPIFFS(bool formatOnFail, char const *mountPath, size_t maxFiles=4)
Mounts filesystem on SPIFFS (Flash)
bool exists(char const *name, bool caseSensitive=true)
Determines if a file or directory exists.
int count()
Determines number of files in current directory.
bool reload()
Reloads directory content.
static bool getFSInfo(DriveType driveType, int drive, int64_t *total, int64_t *used)
Gets total and free space on a filesystem.
static bool remountSPIFFS()
Remounts SPIFFS filesystem, using the same parameters.
static void unmountSPIFFS()
Unmounts filesystem on SPIFFS (Flash)
FileBrowser allows basic file system operations (dir, mkdir, remove and rename)