FabGL
ESP32 Display Controller and Graphics Library
fabutils.h
Go to the documentation of this file.
1/*
2 Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3 Copyright (c) 2019-2022 Fabrizio Di Vittorio.
4 All rights reserved.
5
6
7* Please contact fdivitto2013@gmail.com if you need a commercial license.
8
9
10* This library and related software is available under GPL v3.
11
12 FabGL is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FabGL is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26
27
28#pragma once
29
30
39#include "freertos/FreeRTOS.h"
40#include "freertos/semphr.h"
41
42#include <driver/adc.h>
43#include <esp_system.h>
44#include "sdmmc_cmd.h"
45
46
47namespace fabgl {
48
49
50// manage IDF versioning
51#ifdef ESP_IDF_VERSION
52 #define FABGL_ESP_IDF_VERSION_VAL ESP_IDF_VERSION_VAL
53 #define FABGL_ESP_IDF_VERSION ESP_IDF_VERSION
54#else
55 #define FABGL_ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
56 #define FABGL_ESP_IDF_VERSION FABGL_ESP_IDF_VERSION_VAL(0, 0, 0)
57#endif
58
59
60
61#define GPIO_UNUSED GPIO_NUM_MAX
62
63
65// PSRAM_HACK
66// ESP32 Revision 1 has following bug: "When the CPU accesses external SRAM through cache, under certain conditions read and write errors occur"
67// A workaround is done by the compiler, so whenever PSRAM is enabled the workaround is automatically applied (-mfix-esp32-psram-cache-issue compiler option).
68// Unfortunately this workaround reduces performance, even when SRAM is not access, like in VGAXController interrupt handler. This is unacceptable for the interrupt routine.
69// In order to confuse the compiler and prevent the workaround from being applied, a "nop" is added between load and store instructions (PSRAM_HACK).
70
71#ifdef ARDUINO
72 #ifdef BOARD_HAS_PSRAM
73 #define FABGL_NEED_PSRAM_DISABLE_HACK
74 #endif
75#else
76 #ifdef CONFIG_SPIRAM_SUPPORT
77 #define FABGL_NEED_PSRAM_DISABLE_HACK
78 #endif
79#endif
80
81#ifdef FABGL_NEED_PSRAM_DISABLE_HACK
82 #define PSRAM_HACK asm(" nop")
83#else
84 #define PSRAM_HACK
85#endif
86
87// ESP32 PSRAM bug workaround (use when the library is NOT compiled with PSRAM hack enabled)
88// Place between a write and a read PSRAM operation (write->ASM_MEMW->read), not viceversa
89#define ASM_MEMW asm(" MEMW");
90
91#define ASM_NOP asm(" NOP");
92
93#define PSRAM_WORKAROUND1 asm(" nop;nop;nop;nop");
94#define PSRAM_WORKAROUND2 asm(" memw");
95
96
97
98
100
101
102#define TORAD(a) ((a) * M_PI / 180.)
103
104
105// Integer square root by Halleck's method, with Legalize's speedup
106int isqrt (int x);
107
108
109template <typename T>
110const T & tmax(const T & a, const T & b)
111{
112 return (a < b) ? b : a;
113}
114
115
116constexpr auto imax = tmax<int>;
117
118
119template <typename T>
120const T & tmin(const T & a, const T & b)
121{
122 return !(b < a) ? a : b;
123}
124
125
126constexpr auto imin = tmin<int>;
127
128
129
130template <typename T>
131const T & tclamp(const T & v, const T & lo, const T & hi)
132{
133 return (v < lo ? lo : (v > hi ? hi : v));
134}
135
136
137constexpr auto iclamp = tclamp<int>;
138
139
140template <typename T>
141const T & twrap(const T & v, const T & lo, const T & hi)
142{
143 return (v < lo ? hi : (v > hi ? lo : v));
144}
145
146
147template <typename T>
148void tswap(T & v1, T & v2)
149{
150 T t = v1;
151 v1 = v2;
152 v2 = t;
153}
154
155
156constexpr auto iswap = tswap<int>;
157
158
159template <typename T>
160T moveItems(T dest, T src, size_t n)
161{
162 T pd = dest;
163 T ps = src;
164 if (pd != ps) {
165 if (ps < pd)
166 for (pd += n, ps += n; n--;)
167 *--pd = *--ps;
168 else
169 while (n--)
170 *pd++ = *ps++;
171 }
172 return dest;
173}
174
175
176void rgb222_to_hsv(int R, int G, int B, double * h, double * s, double * v);
177
178
179inline uint16_t changeEndiannesWord(uint16_t value)
180{
181 return ((value & 0xff00) >> 8) | ((value & 0x00ff) << 8);
182}
183
184
185inline uint32_t changeEndiannesDWord(uint32_t value)
186{
187 return ((value & 0xff) << 24) | ((value & 0xff00) << 8) | ((value & 0xff0000) >> 8) | ((value & 0xff000000) >> 24);
188}
189
190
191struct APLLParams {
192 uint8_t sdm0;
193 uint8_t sdm1;
194 uint8_t sdm2;
195 uint8_t o_div;
196};
197
198void APLLCalcParams(double freq, APLLParams * params, uint8_t * a, uint8_t * b, double * out_freq, double * error);
199
200
202
203
209struct Point {
210 int16_t X;
211 int16_t Y;
213 Point() : X(0), Y(0) { }
214 Point(int X_, int Y_) : X(X_), Y(Y_) { }
215
216 Point add(Point const & p) const { return Point(X + p.X, Y + p.Y); }
217 Point sub(Point const & p) const { return Point(X - p.X, Y - p.Y); }
218 Point neg() const { return Point(-X, -Y); }
219 bool operator==(Point const & r) { return X == r.X && Y == r.Y; }
220 bool operator!=(Point const & r) { return X != r.X || Y != r.Y; }
221} __attribute__ ((packed));
222
223
227struct Size {
228 int16_t width;
229 int16_t height;
231 Size() : width(0), height(0) { }
232 Size(int width_, int height_) : width(width_), height(height_) { }
233 bool operator==(Size const & r) { return width == r.width && height == r.height; }
234 bool operator!=(Size const & r) { return width != r.width || height != r.height; }
235} __attribute__ ((packed));
236
237
238
244struct Rect {
245 int16_t X1;
246 int16_t Y1;
247 int16_t X2;
248 int16_t Y2;
250 Rect() : X1(0), Y1(0), X2(0), Y2(0) { }
251 Rect(int X1_, int Y1_, int X2_, int Y2_) : X1(X1_), Y1(Y1_), X2(X2_), Y2(Y2_) { }
252 Rect(Rect const & r) { X1 = r.X1; Y1 = r.Y1; X2 = r.X2; Y2 = r.Y2; }
253
254 bool operator==(Rect const & r) { return X1 == r.X1 && Y1 == r.Y1 && X2 == r.X2 && Y2 == r.Y2; }
255 bool operator!=(Rect const & r) { return X1 != r.X1 || Y1 != r.Y1 || X2 != r.X2 || Y2 != r.Y2; }
256 Point pos() const { return Point(X1, Y1); }
257 Size size() const { return Size(X2 - X1 + 1, Y2 - Y1 + 1); }
258 int width() const { return X2 - X1 + 1; }
259 int height() const { return Y2 - Y1 + 1; }
260 Rect translate(int offsetX, int offsetY) const { return Rect(X1 + offsetX, Y1 + offsetY, X2 + offsetX, Y2 + offsetY); }
261 Rect translate(Point const & offset) const { return Rect(X1 + offset.X, Y1 + offset.Y, X2 + offset.X, Y2 + offset.Y); }
262 Rect move(Point const & position) const { return Rect(position.X, position.Y, position.X + width() - 1, position.Y + height() - 1); }
263 Rect move(int x, int y) const { return Rect(x, y, x + width() - 1, y + height() - 1); }
264 Rect shrink(int value) const { return Rect(X1 + value, Y1 + value, X2 - value, Y2 - value); }
265 Rect hShrink(int value) const { return Rect(X1 + value, Y1, X2 - value, Y2); }
266 Rect vShrink(int value) const { return Rect(X1, Y1 + value, X2, Y2 - value); }
267 Rect resize(int width, int height) const { return Rect(X1, Y1, X1 + width - 1, Y1 + height - 1); }
268 Rect resize(Size size) const { return Rect(X1, Y1, X1 + size.width - 1, Y1 + size.height - 1); }
269 Rect intersection(Rect const & rect) const;
270 bool intersects(Rect const & rect) const { return X1 <= rect.X2 && X2 >= rect.X1 && Y1 <= rect.Y2 && Y2 >= rect.Y1; }
271 bool contains(Rect const & rect) const { return (rect.X1 >= X1) && (rect.Y1 >= Y1) && (rect.X2 <= X2) && (rect.Y2 <= Y2); }
272 bool contains(Point const & point) const { return point.X >= X1 && point.Y >= Y1 && point.X <= X2 && point.Y <= Y2; }
273 bool contains(int x, int y) const { return x >= X1 && y >= Y1 && x <= X2 && y <= Y2; }
274 Rect merge(Rect const & rect) const;
275} __attribute__ ((packed));
276
277
278
283 uint8_t left : 1;
284 uint8_t middle : 1;
285 uint8_t right : 1;
287 MouseButtons() : left(0), middle(0), right(0) { }
288};
289
290
291
296 int16_t X;
297 int16_t Y;
298 int8_t wheelDelta;
301 MouseStatus() : X(0), Y(0), wheelDelta(0) { }
302};
303
304
305
306#define FONTINFOFLAGS_ITALIC 1
307#define FONTINFOFLAGS_UNDERLINE 2
308#define FONTINFODLAFS_STRIKEOUT 4
309#define FONTINFOFLAGS_VARWIDTH 8
310
311
312struct FontInfo {
313 uint8_t pointSize;
314 uint8_t width; // used only for fixed width fonts (FONTINFOFLAGS_VARWIDTH = 0)
315 uint8_t height;
316 uint8_t ascent;
317 uint8_t inleading;
318 uint8_t exleading;
319 uint8_t flags;
320 uint16_t weight;
321 uint16_t charset;
322 // when FONTINFOFLAGS_VARWIDTH = 0:
323 // data[] contains 256 items each one representing a single character
324 // when FONTINFOFLAGS_VARWIDTH = 1:
325 // data[] contains 256 items each one representing a single character. First byte contains the
326 // character width. "chptr" is filled with an array of pointers to the single characters.
327 uint8_t const * data;
328 uint32_t const * chptr; // used only for variable width fonts (FONTINFOFLAGS_VARWIDTH = 1)
329 uint16_t codepage;
330};
331
332
333
334
336// TimeOut
337
338
339struct TimeOut {
340 TimeOut();
341
342 // -1 means "infinite", never times out
343 bool expired(int valueMS);
344
345private:
346 int64_t m_start;
347};
348
349
350
352// Stack
353
354
355template <typename T>
356struct StackItem {
357 StackItem * next;
358 T item;
359 StackItem(StackItem * next_, T const & item_) : next(next_), item(item_) { }
360};
361
362template <typename T>
363class Stack {
364public:
365 Stack() : m_items(nullptr) { }
366 bool isEmpty() { return m_items == nullptr; }
367 void push(T const & value) {
368 m_items = new StackItem<T>(m_items, value);
369 }
370 T pop() {
371 if (m_items) {
372 StackItem<T> * iptr = m_items;
373 m_items = iptr->next;
374 T r = iptr->item;
375 delete iptr;
376 return r;
377 } else
378 return T();
379 }
380 int count() {
381 int r = 0;
382 for (auto i = m_items; i; i = i->next)
383 ++r;
384 return r;
385 }
386private:
387 StackItem<T> * m_items;
388};
389
390
391
393// Delegate
394
395template <typename ...Params>
396struct Delegate {
397
398 // empty constructor
399 Delegate() : m_func(nullptr) {
400 }
401
402 // denied copy
403 Delegate(const Delegate & c) = delete;
404
405 // construct from lambda
406 template <typename Func>
407 Delegate(Func f) : Delegate() {
408 *this = f;
409 }
410
411 ~Delegate() {
412 cleanUp();
413 }
414
415 // assignment operator from Func
416 template <typename Func>
417 void operator=(Func f) {
418 cleanUp();
419 m_closure = [] (void * func, const Params & ...params) -> void { (*(Func *)func)(params...); };
420 m_func = heap_caps_malloc(sizeof(Func), MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
421 moveItems<uint32_t*>((uint32_t*)m_func, (uint32_t*)&f, sizeof(Func) / sizeof(uint32_t));
422 }
423
424 // denied assignment from Delegate
425 void operator=(const Delegate&) = delete;
426
427 void operator()(const Params & ...params) {
428 if (m_func)
429 m_closure(m_func, params...);
430 }
431
432private:
433
434 void (*m_closure)(void * func, const Params & ...params);
435 void * m_func;
436
437 void cleanUp() {
438 if (m_func)
439 heap_caps_free(m_func);
440 }
441};
442
443
444
446// StringList
447
448class StringList {
449
450public:
451 StringList();
452 ~StringList();
453 int append(char const * str);
454 int appendFmt(const char *format, ...);
455 void append(char const * strlist[], int count);
456 void appendSepList(char const * strlist, char separator);
457 void insert(int index, char const * str);
458 void set(int index, char const * str);
459 void remove(int index);
460 int count() { return m_count; }
461 char const * get(int index) { return m_items[index]; }
462 void clear();
463 void takeStrings();
464 void select(int index, bool value);
465 void deselectAll();
466 bool selected(int index);
467 int getFirstSelected();
468 void copyFrom(StringList const & src);
469 void copySelectionMapFrom(StringList const & src);
470
471private:
472 void checkAllocatedSpace(int requiredItems);
473
474 char const * * m_items;
475
476 // each 32 bit word can select up to 32 items, one bit per item
477 uint32_t * m_selMap;
478
479 // If true (default is false) all strings added (append/insert/set) are copied.
480 // Strings will be released when no more used (destructor, clear(), etc...).
481 // This flag is permanently switched to True by takeStrings() call.
482 bool m_ownStrings;
483
484 uint16_t m_count; // actual items
485 uint16_t m_allocated; // allocated items
486
487};
488
489
491// LightMemoryPool
492// Each allocated block starts with a two bytes header (int16_t). Bit 15 is allocation flag (0=free, 1=allocated).
493// Bits 14..0 represent the block size.
494// The maximum size of a block is 32767 bytes.
495// free() just marks the block header as free.
496
497class LightMemoryPool {
498public:
499 LightMemoryPool(int poolSize);
500 ~LightMemoryPool();
501 void * alloc(int size);
502 void free(void * mem) { if (mem) markFree((uint8_t*)mem - m_mem - 2); }
503
504 bool memCheck();
505 int totFree(); // get total free memory
506 int totAllocated(); // get total allocated memory
507 int largestFree();
508
509private:
510
511 void mark(int pos, int16_t size, bool allocated);
512 void markFree(int pos) { m_mem[pos + 1] &= 0x7f; }
513 int16_t getSize(int pos);
514 bool isFree(int pos);
515
516 uint8_t * m_mem;
517 int m_poolSize;
518};
519
520
521
523// FileBrowser
524
525
529struct DirItem {
530 bool isDir;
531 char const * name;
532};
533
534
538enum class DriveType {
539 None,
540 SPIFFS,
541 SDCard,
542};
543
544
551public:
552
553 FileBrowser();
554
555 FileBrowser(char const * path);
556
557 ~FileBrowser();
558
566 bool setDirectory(const char * path);
567
573 void changeDirectory(const char * subdir);
574
580 bool reload();
581
587 char const * directory() { return m_dir; }
588
594 int count() { return m_count; }
595
603 DirItem const * get(int index) { return m_items + index; }
604
615 bool exists(char const * name, bool caseSensitive = true);
616
626 bool filePathExists(char const * filepath);
627
635 size_t fileSize(char const * name);
636
650 bool fileCreationDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
651
665 bool fileUpdateDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
666
680 bool fileAccessDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
681
687 void setSorted(bool value);
688
689 void setIncludeHiddenFiles(bool value) { m_includeHiddenFiles = value; }
690
696 void makeDirectory(char const * dirname);
697
705 void remove(char const * name);
706
713 void rename(char const * oldName, char const * newName);
714
723 bool truncate(char const * name, size_t size);
724
730 char * createTempFilename();
731
741 int getFullPath(char const * name, char * outPath = nullptr, int maxlen = 0);
742
751 FILE * openFile(char const * filename, char const * mode);
752
759
767 static DriveType getDriveType(char const * path);
768
786 static bool format(DriveType driveType, int drive);
787
807 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);
808
814 static bool remountSDCard();
815
816 static bool mountedSDCard() { return s_SDCardMounted; }
817
821 static void unmountSDCard();
822
837 static bool mountSPIFFS(bool formatOnFail, char const * mountPath, size_t maxFiles = 4);
838
844 static bool remountSPIFFS();
845
849 static void unmountSPIFFS();
850
873 static bool getFSInfo(DriveType driveType, int drive, int64_t * total, int64_t * used);
874
875private:
876
877 void clear();
878 int countDirEntries(int * namesLength);
879
880 // SPIFFS static infos
881 static bool s_SPIFFSMounted;
882 static char const * s_SPIFFSMountPath;
883 static size_t s_SPIFFSMaxFiles;
884
885 // SD Card static infos
886 static bool s_SDCardMounted;
887 static char const * s_SDCardMountPath;
888 static size_t s_SDCardMaxFiles;
889 static int s_SDCardAllocationUnitSize;
890 static int8_t s_SDCardMISO;
891 static int8_t s_SDCardMOSI;
892 static int8_t s_SDCardCLK;
893 static int8_t s_SDCardCS;
894 static sdmmc_card_t * s_SDCard;
895
896 char * m_dir;
897 int m_count;
898 DirItem * m_items;
899 bool m_sorted;
900 bool m_includeHiddenFiles;
901 char * m_namesStorage;
902};
903
904
905
906
908
909
910
911bool clipLine(int & x1, int & y1, int & x2, int & y2, Rect const & clipRect, bool checkOnly);
912
913
914void removeRectangle(Stack<Rect> & rects, Rect const & mainRect, Rect const & rectToRemove);
915
916
917bool calcParity(uint8_t v);
918
919// why these? this is like heap_caps_malloc with MALLOC_CAP_32BIT. Unfortunately
920// heap_caps_malloc crashes, so we need this workaround.
921void * realloc32(void * ptr, size_t size);
922void free32(void * ptr);
923
924
925inline gpio_num_t int2gpio(int gpio)
926{
927 return gpio == -1 ? GPIO_UNUSED : (gpio_num_t)gpio;
928}
929
930
931// converts 0..9 -> '0'..'9', 10..15 -> 'a'..'f'
932inline char digit2hex(int digit)
933{
934 return digit < 10 ? '0' + digit : 'a' + digit - 10;
935}
936
937
938// converts '0'..'9' -> 0..9, 'a'..'f' -> 10..15
939inline int hex2digit(char hex)
940{
941 return hex < 'a' ? hex - '0' : hex - 'a' + 10;
942}
943
944
945// milliseconds to FreeRTOS ticks.
946// ms = -1 => maximum delay (portMAX_DELAY)
947uint32_t msToTicks(int ms);
948
949
953enum class ChipPackage {
954 Unknown,
959};
960
961
962ChipPackage getChipPackage();
963
964inline __attribute__((always_inline)) uint32_t getCycleCount() {
965 uint32_t ccount;
966 __asm__ __volatile__(
967 "esync \n\t"
968 "rsr %0, ccount \n\t"
969 : "=a" (ccount)
970 );
971 return ccount;
972}
973
980void replacePathSep(char * path, char newSep);
981
982
990inline uint32_t UARTConf(int parity, int dataLength, int stopBits)
991{
992 uint32_t w = 0x8000000 | (dataLength << 2) | (stopBits << 4);
993 if (parity)
994 w |= (parity == 1 ? 0b10 : 0b11);
995 return w;
996}
997
998
999adc1_channel_t ADC1_GPIO2Channel(gpio_num_t gpio);
1000
1001
1002void esp_intr_alloc_pinnedToCore(int source, int flags, intr_handler_t handler, void * arg, intr_handle_t * ret_handle, int core);
1003
1004
1005// mode: GPIO_MODE_DISABLE,
1006// GPIO_MODE_INPUT,
1007// GPIO_MODE_OUTPUT,
1008// GPIO_MODE_OUTPUT_OD (open drain),
1009// GPIO_MODE_INPUT_OUTPUT_OD (open drain),
1010// GPIO_MODE_INPUT_OUTPUT
1011void configureGPIO(gpio_num_t gpio, gpio_mode_t mode);
1012
1013
1014uint32_t getApbFrequency();
1015
1016uint32_t getCPUFrequencyMHz();
1017
1018
1020// AutoSemaphore
1021
1022struct AutoSemaphore {
1023 AutoSemaphore(SemaphoreHandle_t mutex) : m_mutex(mutex) { xSemaphoreTake(m_mutex, portMAX_DELAY); }
1024 ~AutoSemaphore() { xSemaphoreGive(m_mutex); }
1025private:
1026 SemaphoreHandle_t m_mutex;
1027};
1028
1029
1030
1032// CoreUsage
1033
1038
1039 static int busiestCore() { return s_busiestCore; }
1040 static int quietCore() { return s_busiestCore != -1 ? s_busiestCore ^ 1 : -1; }
1041 static void setBusiestCore(int core) { s_busiestCore = core; }
1042
1043 private:
1044 static int s_busiestCore; // 0 = core 0, 1 = core 1 (default is FABGLIB_VIDEO_CPUINTENSIVE_TASKS_CORE)
1045};
1046
1047
1049
1050
1314 VK_LAST, // marks the last virtual key
1315
1316};
1317
1318
1324 uint8_t down;
1325 uint8_t scancode[8];
1326 uint8_t ASCII;
1327 uint8_t CTRL : 1;
1328 uint8_t LALT : 1;
1329 uint8_t RALT : 1;
1330 uint8_t SHIFT : 1;
1331 uint8_t GUI : 1;
1332 uint8_t CAPSLOCK : 1;
1333 uint8_t NUMLOCK : 1;
1334 uint8_t SCROLLLOCK : 1;
1335};
1336
1337
1338
1340// Virtual keys helpers
1341
1342inline bool isSHIFT(VirtualKey value)
1343{
1344 return value == VK_LSHIFT || value == VK_RSHIFT;
1345}
1346
1347
1348inline bool isALT(VirtualKey value)
1349{
1350 return value == VK_LALT || value == VK_RALT;
1351}
1352
1353
1354inline bool isCTRL(VirtualKey value)
1355{
1356 return value == VK_LCTRL || value == VK_RCTRL;
1357}
1358
1359
1360inline bool isGUI(VirtualKey value)
1361{
1362 return value == VK_LGUI || value == VK_RGUI;
1363}
1364
1365
1366
1368// ASCII control characters
1369
1370#define ASCII_NUL 0x00 // Null
1371#define ASCII_SOH 0x01 // Start of Heading
1372#define ASCII_CTRLA 0x01 // CTRL-A
1373#define ASCII_STX 0x02 // Start of Text
1374#define ASCII_CTRLB 0x02 // CTRL-B
1375#define ASCII_ETX 0x03 // End Of Text
1376#define ASCII_CTRLC 0x03 // CTRL-C
1377#define ASCII_EOT 0x04 // End Of Transmission
1378#define ASCII_CTRLD 0x04 // CTRL-D
1379#define ASCII_ENQ 0x05 // Enquiry
1380#define ASCII_CTRLE 0x05 // CTRL-E
1381#define ASCII_ACK 0x06 // Acknowledge
1382#define ASCII_CTRLF 0x06 // CTRL-F
1383#define ASCII_BEL 0x07 // Bell
1384#define ASCII_CTRLG 0x07 // CTRL-G
1385#define ASCII_BS 0x08 // Backspace
1386#define ASCII_CTRLH 0x08 // CTRL-H
1387#define ASCII_HT 0x09 // Horizontal Tab
1388#define ASCII_TAB 0x09 // Horizontal Tab
1389#define ASCII_CTRLI 0x09 // CTRL-I
1390#define ASCII_LF 0x0A // Line Feed
1391#define ASCII_CTRLJ 0x0A // CTRL-J
1392#define ASCII_VT 0x0B // Vertical Tab
1393#define ASCII_CTRLK 0x0B // CTRL-K
1394#define ASCII_FF 0x0C // Form Feed
1395#define ASCII_CTRLL 0x0C // CTRL-L
1396#define ASCII_CR 0x0D // Carriage Return
1397#define ASCII_CTRLM 0x0D // CTRL-M
1398#define ASCII_SO 0x0E // Shift Out
1399#define ASCII_CTRLN 0x0E // CTRL-N
1400#define ASCII_SI 0x0F // Shift In
1401#define ASCII_CTRLO 0x0F // CTRL-O
1402#define ASCII_DLE 0x10 // Data Link Escape
1403#define ASCII_CTRLP 0x10 // CTRL-P
1404#define ASCII_DC1 0x11 // Device Control 1
1405#define ASCII_CTRLQ 0x11 // CTRL-Q
1406#define ASCII_XON 0x11 // Transmission On
1407#define ASCII_DC2 0x12 // Device Control 2
1408#define ASCII_CTRLR 0x12 // CTRL-R
1409#define ASCII_DC3 0x13 // Device Control 3
1410#define ASCII_XOFF 0x13 // Transmission Off
1411#define ASCII_CTRLS 0x13 // CTRL-S
1412#define ASCII_DC4 0x14 // Device Control 4
1413#define ASCII_CTRLT 0x14 // CTRL-T
1414#define ASCII_NAK 0x15 // Negative Acknowledge
1415#define ASCII_CTRLU 0x15 // CTRL-U
1416#define ASCII_SYN 0x16 // Synchronous Idle
1417#define ASCII_CTRLV 0x16 // CTRL-V
1418#define ASCII_ETB 0x17 // End-of-Transmission-Block
1419#define ASCII_CTRLW 0x17 // CTRL-W
1420#define ASCII_CAN 0x18 // Cancel
1421#define ASCII_CTRLX 0x18 // CTRL-X
1422#define ASCII_EM 0x19 // End of Medium
1423#define ASCII_CTRLY 0x19 // CTRL-Y
1424#define ASCII_SUB 0x1A // Substitute
1425#define ASCII_CTRLZ 0x1A // CTRL-Z
1426#define ASCII_ESC 0x1B // Escape
1427#define ASCII_FS 0x1C // File Separator
1428#define ASCII_GS 0x1D // Group Separator
1429#define ASCII_RS 0x1E // Record Separator
1430#define ASCII_US 0x1F // Unit Separator
1431#define ASCII_SPC 0x20 // Space
1432#define ASCII_DEL 0x7F // Delete
1433
1434
1435} // end of namespace
1436
1437
1438
bool fileUpdateDate(char const *name, int *year, int *month, int *day, int *hour, int *minutes, int *seconds)
Gets file update date and time.
Definition: fabutils.cpp:802
static bool mountSPIFFS(bool formatOnFail, char const *mountPath, size_t maxFiles=4)
Mounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1278
bool filePathExists(char const *filepath)
Determines if a file exists.
Definition: fabutils.cpp:760
void changeDirectory(const char *subdir)
Sets relative directory path.
Definition: fabutils.cpp:682
bool fileAccessDate(char const *name, int *year, int *month, int *day, int *hour, int *minutes, int *seconds)
Gets file access date and time.
Definition: fabutils.cpp:820
void rename(char const *oldName, char const *newName)
Renames a file.
Definition: fabutils.cpp:1017
static bool remountSPIFFS()
Remounts SPIFFS filesystem, using the same parameters.
Definition: fabutils.cpp:1302
size_t fileSize(char const *name)
Determines file size.
Definition: fabutils.cpp:769
static bool format(DriveType driveType, int drive)
Formats SPIFFS or SD Card.
Definition: fabutils.cpp:1132
FILE * openFile(char const *filename, char const *mode)
Opens a file from current directory.
Definition: fabutils.cpp:1101
bool truncate(char const *name, size_t size)
Truncates a file to the specified size.
Definition: fabutils.cpp:1045
bool reload()
Reloads directory content.
Definition: fabutils.cpp:850
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.
Definition: fabutils.cpp:1179
bool setDirectory(const char *path)
Sets absolute directory path.
Definition: fabutils.cpp:669
static void unmountSPIFFS()
Unmounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1293
int count()
Determines number of files in current directory.
Definition: fabutils.h:594
DirItem const * get(int index)
Gets file/directory at index.
Definition: fabutils.h:603
static bool remountSDCard()
Remounts SDCard filesystem, using the same parameters.
Definition: fabutils.cpp:1271
int getFullPath(char const *name, char *outPath=nullptr, int maxlen=0)
Composes a full file path given a relative name.
Definition: fabutils.cpp:1095
char * createTempFilename()
Creates a random temporary filename, with absolute path.
Definition: fabutils.cpp:1030
bool fileCreationDate(char const *name, int *year, int *month, int *day, int *hour, int *minutes, int *seconds)
Gets file creation date and time.
Definition: fabutils.cpp:784
void remove(char const *name)
Removes a file or directory.
Definition: fabutils.cpp:979
static DriveType getDriveType(char const *path)
Returns the drive type of specified path.
Definition: fabutils.cpp:1120
void setSorted(bool value)
Determines if the items are sorted.
DriveType getCurrentDriveType()
Returns the drive type of current directory.
Definition: fabutils.cpp:1114
bool exists(char const *name, bool caseSensitive=true)
Determines if a file or directory exists.
Definition: fabutils.cpp:745
static void unmountSDCard()
Unmounts filesystem on SD Card.
Definition: fabutils.cpp:1258
static bool getFSInfo(DriveType driveType, int drive, int64_t *total, int64_t *used)
Gets total and free space on a filesystem.
Definition: fabutils.cpp:1309
void makeDirectory(char const *dirname)
Creates a directory.
Definition: fabutils.cpp:937
char const * directory()
Determines absolute path of current directory.
Definition: fabutils.h:587
FileBrowser allows basic file system operations (dir, mkdir, remove and rename)
Definition: fabutils.h:550
uint8_t B
uint8_t const * data
uint8_t G
uint8_t R
int16_t height
Definition: fabutils.h:1
uint32_t UARTConf(int parity, int dataLength, int stopBits)
Composes UART configuration word.
Definition: fabutils.h:990
int16_t width
Definition: fabutils.h:0
ChipPackage
This enum defines ESP32 module types (packages)
Definition: fabutils.h:953
DriveType
This enum defines drive types (SPIFFS or SD Card)
Definition: fabutils.h:538
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
Definition: fabutils.h:1054
@ VK_GRAVE_e
Definition: fabutils.h:1237
@ VK_n
Definition: fabutils.h:1093
@ VK_PRINTSCREEN
Definition: fabutils.h:1188
@ VK_APPLICATION
Definition: fabutils.h:1208
@ VK_V
Definition: fabutils.h:1127
@ VK_F12
Definition: fabutils.h:1234
@ VK_CARET_A
Definition: fabutils.h:1285
@ VK_H
Definition: fabutils.h:1113
@ VK_GRAVE_y
Definition: fabutils.h:1241
@ VK_KP_LEFT
Definition: fabutils.h:1218
@ VK_PERIOD
Definition: fabutils.h:1148
@ VK_F8
Definition: fabutils.h:1230
@ VK_ACUTEACCENT
Definition: fabutils.h:1134
@ VK_N
Definition: fabutils.h:1119
@ VK_BREAK
Definition: fabutils.h:1201
@ VK_CARET_o
Definition: fabutils.h:1281
@ VK_w
Definition: fabutils.h:1102
@ VK_NUMLOCK
Definition: fabutils.h:1203
@ VK_KP_RIGHT
Definition: fabutils.h:1220
@ VK_m
Definition: fabutils.h:1092
@ VK_y
Definition: fabutils.h:1104
@ VK_RIGHTBRACE
Definition: fabutils.h:1164
@ VK_GRAVE_I
Definition: fabutils.h:1252
@ VK_GRAVE_Y
Definition: fabutils.h:1255
@ VK_ESZETT
Definition: fabutils.h:1304
@ VK_F7
Definition: fabutils.h:1229
@ VK_KP_PERIOD
Definition: fabutils.h:1147
@ VK_GRAVE_U
Definition: fabutils.h:1254
@ VK_o
Definition: fabutils.h:1094
@ VK_GRAVE_a
Definition: fabutils.h:1236
@ VK_p
Definition: fabutils.h:1095
@ VK_RETURN
Definition: fabutils.h:1206
@ VK_KP_6
Definition: fabutils.h:1075
@ VK_D
Definition: fabutils.h:1109
@ VK_SYSREQ
Definition: fabutils.h:1189
@ VK_ESCAPE
Definition: fabutils.h:1186
@ VK_LSHIFT
Definition: fabutils.h:1177
@ VK_CARET_U
Definition: fabutils.h:1289
@ VK_KP_5
Definition: fabutils.h:1074
@ VK_UPPER_a
Definition: fabutils.h:1303
@ VK_GRAVE_E
Definition: fabutils.h:1251
@ VK_COMMA
Definition: fabutils.h:1150
@ VK_R
Definition: fabutils.h:1123
@ VK_UMLAUT_e
Definition: fabutils.h:1265
@ VK_Q
Definition: fabutils.h:1122
@ VK_MU
Definition: fabutils.h:1311
@ VK_TILDE_a
Definition: fabutils.h:1295
@ VK_PAGEUP
Definition: fabutils.h:1209
@ VK_KP_END
Definition: fabutils.h:1199
@ VK_9
Definition: fabutils.h:1068
@ VK_RALT
Definition: fabutils.h:1180
@ VK_f
Definition: fabutils.h:1085
@ VK_d
Definition: fabutils.h:1083
@ VK_x
Definition: fabutils.h:1103
@ VK_CEDILLA_c
Definition: fabutils.h:1292
@ VK_TILDE
Definition: fabutils.h:1174
@ VK_UMLAUT_a
Definition: fabutils.h:1264
@ VK_SPACE
Definition: fabutils.h:1057
@ VK_KP_8
Definition: fabutils.h:1077
@ VK_F11
Definition: fabutils.h:1233
@ VK_F9
Definition: fabutils.h:1231
@ VK_LEFTBRACKET
Definition: fabutils.h:1165
@ VK_UMLAUT_A
Definition: fabutils.h:1271
@ VK_7
Definition: fabutils.h:1066
@ VK_KP_9
Definition: fabutils.h:1078
@ VK_KP_4
Definition: fabutils.h:1073
@ VK_ACUTE_A
Definition: fabutils.h:1257
@ VK_ACUTE_a
Definition: fabutils.h:1243
@ VK_K
Definition: fabutils.h:1116
@ VK_F2
Definition: fabutils.h:1224
@ VK_POUND
Definition: fabutils.h:1158
@ VK_CARET_e
Definition: fabutils.h:1279
@ VK_F1
Definition: fabutils.h:1223
@ VK_HASH
Definition: fabutils.h:1154
@ VK_ACUTE_e
Definition: fabutils.h:1244
@ VK_UMLAUT_U
Definition: fabutils.h:1275
@ VK_KP_PAGEDOWN
Definition: fabutils.h:1212
@ VK_UMLAUT_O
Definition: fabutils.h:1274
@ VK_LALT
Definition: fabutils.h:1179
@ VK_GREATER
Definition: fabutils.h:1170
@ VK_KP_MULTIPLY
Definition: fabutils.h:1142
@ VK_u
Definition: fabutils.h:1100
@ VK_UP
Definition: fabutils.h:1213
@ VK_LEFTPAREN
Definition: fabutils.h:1167
@ VK_GRAVE_o
Definition: fabutils.h:1239
@ VK_CARET_I
Definition: fabutils.h:1287
@ VK_VERTICALBAR
Definition: fabutils.h:1153
@ VK_a
Definition: fabutils.h:1080
@ VK_r
Definition: fabutils.h:1097
@ VK_SLASH
Definition: fabutils.h:1146
@ VK_DEGREE
Definition: fabutils.h:1172
@ VK_RIGHTPAREN
Definition: fabutils.h:1168
@ VK_QUOTE
Definition: fabutils.h:1135
@ VK_KP_UP
Definition: fabutils.h:1214
@ VK_KP_1
Definition: fabutils.h:1070
@ VK_SEMICOLON
Definition: fabutils.h:1151
@ VK_QUESTION_INV
Definition: fabutils.h:1306
@ VK_GRAVE_A
Definition: fabutils.h:1250
@ VK_z
Definition: fabutils.h:1105
@ VK_UMLAUT_I
Definition: fabutils.h:1273
@ VK_ASTERISK
Definition: fabutils.h:1143
@ VK_ACUTE_i
Definition: fabutils.h:1245
@ VK_END
Definition: fabutils.h:1198
@ VK_PAUSE
Definition: fabutils.h:1200
@ VK_UNDERSCORE
Definition: fabutils.h:1171
@ VK_PAGEDOWN
Definition: fabutils.h:1211
@ VK_ACUTE_Y
Definition: fabutils.h:1262
@ VK_KP_DELETE
Definition: fabutils.h:1194
@ VK_RGUI
Definition: fabutils.h:1184
@ VK_B
Definition: fabutils.h:1107
@ VK_LCTRL
Definition: fabutils.h:1181
@ VK_ACUTE_O
Definition: fabutils.h:1260
@ VK_k
Definition: fabutils.h:1090
@ VK_KP_CENTER
Definition: fabutils.h:1221
@ VK_g
Definition: fabutils.h:1086
@ VK_AT
Definition: fabutils.h:1155
@ VK_O
Definition: fabutils.h:1120
@ VK_CARET_u
Definition: fabutils.h:1282
@ VK_KP_0
Definition: fabutils.h:1069
@ VK_DIAERESIS
Definition: fabutils.h:1308
@ VK_F5
Definition: fabutils.h:1227
@ VK_DOWN
Definition: fabutils.h:1215
@ VK_TILDE_O
Definition: fabutils.h:1300
@ VK_S
Definition: fabutils.h:1124
@ VK_AMPERSAND
Definition: fabutils.h:1152
@ VK_CURRENCY
Definition: fabutils.h:1310
@ VK_F6
Definition: fabutils.h:1228
@ VK_L
Definition: fabutils.h:1117
@ VK_HOME
Definition: fabutils.h:1196
@ VK_E
Definition: fabutils.h:1110
@ VK_C
Definition: fabutils.h:1108
@ VK_CARET_y
Definition: fabutils.h:1283
@ VK_SCROLLLOCK
Definition: fabutils.h:1202
@ VK_EQUALS
Definition: fabutils.h:1137
@ VK_CARET_O
Definition: fabutils.h:1288
@ VK_COLON
Definition: fabutils.h:1149
@ VK_F3
Definition: fabutils.h:1225
@ VK_P
Definition: fabutils.h:1121
@ VK_F
Definition: fabutils.h:1111
@ VK_6
Definition: fabutils.h:1065
@ VK_TAB
Definition: fabutils.h:1205
@ VK_v
Definition: fabutils.h:1101
@ VK_i
Definition: fabutils.h:1088
@ VK_U
Definition: fabutils.h:1126
@ VK_T
Definition: fabutils.h:1125
@ VK_KP_DOWN
Definition: fabutils.h:1216
@ VK_c
Definition: fabutils.h:1082
@ VK_TILDE_n
Definition: fabutils.h:1297
@ VK_KP_DIVIDE
Definition: fabutils.h:1145
@ VK_LEFTBRACE
Definition: fabutils.h:1163
@ VK_Y
Definition: fabutils.h:1130
@ VK_CEDILLA_C
Definition: fabutils.h:1293
@ VK_LESS
Definition: fabutils.h:1169
@ VK_EXCLAIM
Definition: fabutils.h:1161
@ VK_TILDE_N
Definition: fabutils.h:1301
@ VK_5
Definition: fabutils.h:1064
@ VK_CARET_E
Definition: fabutils.h:1286
@ VK_UMLAUT_u
Definition: fabutils.h:1268
@ VK_ACUTE_E
Definition: fabutils.h:1258
@ VK_t
Definition: fabutils.h:1099
@ VK_GRAVE_O
Definition: fabutils.h:1253
@ VK_UMLAUT_y
Definition: fabutils.h:1269
@ VK_DELETE
Definition: fabutils.h:1193
@ VK_NEGATION
Definition: fabutils.h:1175
@ VK_KP_7
Definition: fabutils.h:1076
@ VK_KP_ENTER
Definition: fabutils.h:1207
@ VK_0
Definition: fabutils.h:1059
@ VK_CARET_Y
Definition: fabutils.h:1290
@ VK_GRAVEACCENT
Definition: fabutils.h:1133
@ VK_ACUTE_I
Definition: fabutils.h:1259
@ VK_LGUI
Definition: fabutils.h:1183
@ VK_A
Definition: fabutils.h:1106
@ VK_DOLLAR
Definition: fabutils.h:1157
@ VK_8
Definition: fabutils.h:1067
@ VK_1
Definition: fabutils.h:1060
@ VK_SECTION
Definition: fabutils.h:1173
@ VK_KP_3
Definition: fabutils.h:1072
@ VK_UMLAUT_o
Definition: fabutils.h:1267
@ VK_Z
Definition: fabutils.h:1131
@ VK_GRAVE_u
Definition: fabutils.h:1240
@ VK_CARET_a
Definition: fabutils.h:1278
@ VK_s
Definition: fabutils.h:1098
@ VK_F10
Definition: fabutils.h:1232
@ VK_X
Definition: fabutils.h:1129
@ VK_ACUTE_o
Definition: fabutils.h:1246
@ VK_BACKSPACE
Definition: fabutils.h:1195
@ VK_TILDE_o
Definition: fabutils.h:1296
@ VK_QUESTION
Definition: fabutils.h:1162
@ VK_MINUS
Definition: fabutils.h:1138
@ VK_UMLAUT_E
Definition: fabutils.h:1272
@ VK_BACKSLASH
Definition: fabutils.h:1144
@ VK_l
Definition: fabutils.h:1091
@ VK_NONE
Definition: fabutils.h:1055
@ VK_RCTRL
Definition: fabutils.h:1182
@ VK_LEFT
Definition: fabutils.h:1217
@ VK_INTERPUNCT
Definition: fabutils.h:1307
@ VK_ACUTE_U
Definition: fabutils.h:1261
@ VK_b
Definition: fabutils.h:1081
@ VK_KP_INSERT
Definition: fabutils.h:1192
@ VK_J
Definition: fabutils.h:1115
@ VK_KP_MINUS
Definition: fabutils.h:1139
@ VK_CARET
Definition: fabutils.h:1156
@ VK_QUOTEDBL
Definition: fabutils.h:1136
@ VK_CARET_i
Definition: fabutils.h:1280
@ VK_ACUTE_y
Definition: fabutils.h:1248
@ VK_W
Definition: fabutils.h:1128
@ VK_UMLAUT_Y
Definition: fabutils.h:1276
@ VK_e
Definition: fabutils.h:1084
@ VK_EURO
Definition: fabutils.h:1159
@ VK_KP_2
Definition: fabutils.h:1071
@ VK_2
Definition: fabutils.h:1061
@ VK_RIGHTBRACKET
Definition: fabutils.h:1166
@ VK_KP_HOME
Definition: fabutils.h:1197
@ VK_UMLAUT_i
Definition: fabutils.h:1266
@ VK_h
Definition: fabutils.h:1087
@ VK_RIGHT
Definition: fabutils.h:1219
@ VK_ASCII
Definition: fabutils.h:1313
@ VK_F4
Definition: fabutils.h:1226
@ VK_PLUS
Definition: fabutils.h:1140
@ VK_SQUARE
Definition: fabutils.h:1309
@ VK_M
Definition: fabutils.h:1118
@ VK_4
Definition: fabutils.h:1063
@ VK_CAPSLOCK
Definition: fabutils.h:1204
@ VK_ACUTE_u
Definition: fabutils.h:1247
@ VK_I
Definition: fabutils.h:1114
@ VK_EXCLAIM_INV
Definition: fabutils.h:1305
@ VK_j
Definition: fabutils.h:1089
@ VK_KP_PAGEUP
Definition: fabutils.h:1210
@ VK_3
Definition: fabutils.h:1062
@ VK_RSHIFT
Definition: fabutils.h:1178
@ VK_q
Definition: fabutils.h:1096
@ VK_GRAVE_i
Definition: fabutils.h:1238
@ VK_G
Definition: fabutils.h:1112
@ VK_KP_PLUS
Definition: fabutils.h:1141
@ VK_PERCENT
Definition: fabutils.h:1160
@ VK_TILDE_A
Definition: fabutils.h:1299
@ VK_INSERT
Definition: fabutils.h:1191
This class helps to choice a core for intensive processing tasks.
Definition: fabutils.h:1037
char const * name
Definition: fabutils.h:531
FileBrowser item specificator.
Definition: fabutils.h:529
Describes mouse buttons status.
Definition: fabutils.h:282
MouseButtons buttons
Definition: fabutils.h:299
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: fabutils.h:295
int16_t X
Definition: fabutils.h:210
int16_t Y
Definition: fabutils.h:211
Represents the coordinate of a point.
Definition: fabutils.h:209
int16_t X1
Definition: fabutils.h:245
int16_t Y2
Definition: fabutils.h:248
int16_t X2
Definition: fabutils.h:247
int16_t Y1
Definition: fabutils.h:246
Represents a rectangle.
Definition: fabutils.h:244
int16_t height
Definition: fabutils.h:229
int16_t width
Definition: fabutils.h:228
Represents a bidimensional size.
Definition: fabutils.h:227
uint8_t scancode[8]
Definition: fabutils.h:1325
A struct which contains a virtual key, key state and associated scan code.
Definition: fabutils.h:1322