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-2021 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 
45 
46 namespace fabgl {
47 
48 
49 // manage IDF versioning
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
53 #else
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)
56 #endif
57 
58 
59 
60 #define GPIO_UNUSED GPIO_NUM_MAX
61 
62 
64 // PSRAM_HACK
65 // ESP32 Revision 1 has following bug: "When the CPU accesses external SRAM through cache, under certain conditions read and write errors occur"
66 // A workaround is done by the compiler, so whenever PSRAM is enabled the workaround is automatically applied (-mfix-esp32-psram-cache-issue compiler option).
67 // Unfortunately this workaround reduces performance, even when SRAM is not access, like in VGAXController interrupt handler. This is unacceptable for the interrupt routine.
68 // In order to confuse the compiler and prevent the workaround from being applied, a "nop" is added between load and store instructions (PSRAM_HACK).
69 
70 #ifdef ARDUINO
71  #ifdef BOARD_HAS_PSRAM
72  #define FABGL_NEED_PSRAM_DISABLE_HACK
73  #endif
74 #else
75  #ifdef CONFIG_SPIRAM_SUPPORT
76  #define FABGL_NEED_PSRAM_DISABLE_HACK
77  #endif
78 #endif
79 
80 #ifdef FABGL_NEED_PSRAM_DISABLE_HACK
81  #define PSRAM_HACK asm(" nop")
82 #else
83  #define PSRAM_HACK
84 #endif
85 
86 // ESP32 PSRAM bug workaround (use when the library is NOT compiled with PSRAM hack enabled)
87 // Plase between a write and a read PSRAM operation (write->ASM_MEMW->read), not viceversa
88 #define ASM_MEMW asm(" MEMW");
89 
90 
91 
92 
94 
95 
96 // Integer square root by Halleck's method, with Legalize's speedup
97 int isqrt (int x);
98 
99 
100 template <typename T>
101 const T & tmax(const T & a, const T & b)
102 {
103  return (a < b) ? b : a;
104 }
105 
106 
107 constexpr auto imax = tmax<int>;
108 
109 
110 template <typename T>
111 const T & tmin(const T & a, const T & b)
112 {
113  return !(b < a) ? a : b;
114 }
115 
116 
117 constexpr auto imin = tmin<int>;
118 
119 
120 
121 template <typename T>
122 const T & tclamp(const T & v, const T & lo, const T & hi)
123 {
124  return (v < lo ? lo : (v > hi ? hi : v));
125 }
126 
127 
128 constexpr auto iclamp = tclamp<int>;
129 
130 
131 template <typename T>
132 const T & twrap(const T & v, const T & lo, const T & hi)
133 {
134  return (v < lo ? hi : (v > hi ? lo : v));
135 }
136 
137 
138 template <typename T>
139 void tswap(T & v1, T & v2)
140 {
141  T t = v1;
142  v1 = v2;
143  v2 = t;
144 }
145 
146 
147 constexpr auto iswap = tswap<int>;
148 
149 
150 template <typename T>
151 T moveItems(T dest, T src, size_t n)
152 {
153  T pd = dest;
154  T ps = src;
155  if (pd != ps) {
156  if (ps < pd)
157  for (pd += n, ps += n; n--;)
158  *--pd = *--ps;
159  else
160  while (n--)
161  *pd++ = *ps++;
162  }
163  return dest;
164 }
165 
166 
167 void rgb222_to_hsv(int R, int G, int B, double * h, double * s, double * v);
168 
169 
170 inline uint16_t changeEndiannesWord(uint16_t value)
171 {
172  return ((value & 0xff00) >> 8) | ((value & 0x00ff) << 8);
173 }
174 
175 
176 inline uint32_t changeEndiannesDWord(uint32_t value)
177 {
178  return ((value & 0xff) << 24) | ((value & 0xff00) << 8) | ((value & 0xff0000) >> 8) | ((value & 0xff000000) >> 24);
179 }
181 
183 
184 
190 struct Point {
191  int16_t X;
192  int16_t Y;
194  Point() : X(0), Y(0) { }
195  Point(int X_, int Y_) : X(X_), Y(Y_) { }
196 
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));
203 
204 
208 struct Size {
209  int16_t width;
210  int16_t height;
212  Size() : width(0), height(0) { }
213  Size(int width_, int height_) : width(width_), height(height_) { }
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));
217 
218 
219 
225 struct Rect {
226  int16_t X1;
227  int16_t Y1;
228  int16_t X2;
229  int16_t Y2;
231  Rect() : X1(0), Y1(0), X2(0), Y2(0) { }
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; }
234 
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));
257 
258 
259 
263 struct MouseButtons {
264  uint8_t left : 1;
265  uint8_t middle : 1;
266  uint8_t right : 1;
268  MouseButtons() : left(0), middle(0), right(0) { }
269 };
270 
271 
272 
276 struct MouseStatus {
277  int16_t X;
278  int16_t Y;
279  int8_t wheelDelta;
282  MouseStatus() : X(0), Y(0), wheelDelta(0) { }
283 };
284 
285 
286 
287 #define FONTINFOFLAGS_ITALIC 1
288 #define FONTINFOFLAGS_UNDERLINE 2
289 #define FONTINFODLAFS_STRIKEOUT 4
290 #define FONTINFOFLAGS_VARWIDTH 8
291 
292 
293 struct FontInfo {
294  uint8_t pointSize;
295  uint8_t width; // used only for fixed width fonts (FONTINFOFLAGS_VARWIDTH = 0)
296  uint8_t height;
297  uint8_t ascent;
298  uint8_t inleading;
299  uint8_t exleading;
300  uint8_t flags;
301  uint16_t weight;
302  uint16_t charset;
303  // when FONTINFOFLAGS_VARWIDTH = 0:
304  // data[] contains 256 items each one representing a single character
305  // when FONTINFOFLAGS_VARWIDTH = 1:
306  // data[] contains 256 items each one representing a single character. First byte contains the
307  // character width. "chptr" is filled with an array of pointers to the single characters.
308  uint8_t const * data;
309  uint32_t const * chptr; // used only for variable width fonts (FONTINFOFLAGS_VARWIDTH = 1)
310  uint16_t codepage;
311 };
312 
313 
314 
315 
317 // TimeOut
318 
319 
320 struct TimeOut {
321  TimeOut();
322 
323  // -1 means "infinite", never times out
324  bool expired(int valueMS);
325 
326 private:
327  int64_t m_start;
328 };
329 
330 
331 
333 // Stack
334 
335 
336 template <typename T>
337 struct StackItem {
338  StackItem * next;
339  T item;
340  StackItem(StackItem * next_, T const & item_) : next(next_), item(item_) { }
341 };
342 
343 template <typename T>
344 class Stack {
345 public:
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);
350  }
351  T pop() {
352  if (m_items) {
353  StackItem<T> * iptr = m_items;
354  m_items = iptr->next;
355  T r = iptr->item;
356  delete iptr;
357  return r;
358  } else
359  return T();
360  }
361  int count() {
362  int r = 0;
363  for (auto i = m_items; i; i = i->next)
364  ++r;
365  return r;
366  }
367 private:
368  StackItem<T> * m_items;
369 };
370 
371 
372 
374 // Delegate
375 
376 template <typename ...Params>
377 struct Delegate {
378 
379  // empty constructor
380  Delegate() : m_func(nullptr) {
381  }
382 
383  // denied copy
384  Delegate(const Delegate & c) = delete;
385 
386  // construct from lambda
387  template <typename Func>
388  Delegate(Func f) : Delegate() {
389  *this = f;
390  }
391 
392  ~Delegate() {
393  cleanUp();
394  }
395 
396  // assignment operator from Func
397  template <typename Func>
398  void operator=(Func f) {
399  cleanUp();
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));
403  }
404 
405  // denied assignment from Delegate
406  void operator=(const Delegate&) = delete;
407 
408  void operator()(const Params & ...params) {
409  if (m_func)
410  m_closure(m_func, params...);
411  }
412 
413 private:
414 
415  void (*m_closure)(void * func, const Params & ...params);
416  void * m_func;
417 
418  void cleanUp() {
419  if (m_func)
420  heap_caps_free(m_func);
421  }
422 };
423 
424 
425 
427 // StringList
428 
429 class StringList {
430 
431 public:
432  StringList();
433  ~StringList();
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]; }
443  void clear();
444  void takeStrings();
445  void select(int index, bool value);
446  void deselectAll();
447  bool selected(int index);
448  int getFirstSelected();
449  void copyFrom(StringList const & src);
450  void copySelectionMapFrom(StringList const & src);
451 
452 private:
453  void checkAllocatedSpace(int requiredItems);
454 
455  char const * * m_items;
456 
457  // each 32 bit word can select up to 32 items, one bit per item
458  uint32_t * m_selMap;
459 
460  // If true (default is false) all strings added (append/insert/set) are copied.
461  // Strings will be released when no more used (destructor, clear(), etc...).
462  // This flag is permanently switched to True by takeStrings() call.
463  bool m_ownStrings;
464 
465  uint16_t m_count; // actual items
466  uint16_t m_allocated; // allocated items
467 
468 };
469 
470 
472 // LightMemoryPool
473 // Each allocated block starts with a two bytes header (int16_t). Bit 15 is allocation flag (0=free, 1=allocated).
474 // Bits 14..0 represent the block size.
475 // The maximum size of a block is 32767 bytes.
476 // free() just marks the block header as free.
477 
478 class LightMemoryPool {
479 public:
480  LightMemoryPool(int poolSize);
481  ~LightMemoryPool();
482  void * alloc(int size);
483  void free(void * mem) { if (mem) markFree((uint8_t*)mem - m_mem - 2); }
484 
485  bool memCheck();
486  int totFree(); // get total free memory
487  int totAllocated(); // get total allocated memory
488  int largestFree();
489 
490 private:
491 
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);
496 
497  uint8_t * m_mem;
498  int m_poolSize;
499 };
500 
501 
502 
504 // FileBrowser
505 
506 
510 struct DirItem {
511  bool isDir;
512  char const * name;
513 };
514 
515 
519 enum class DriveType {
520  None,
521  SPIFFS,
522  SDCard,
523 };
524 
525 
531 class FileBrowser {
532 public:
533 
534  FileBrowser();
535  ~FileBrowser();
536 
544  bool setDirectory(const char * path);
545 
551  void changeDirectory(const char * subdir);
552 
558  bool reload();
559 
565  char const * directory() { return m_dir; }
566 
572  int count() { return m_count; }
573 
581  DirItem const * get(int index) { return m_items + index; }
582 
591  bool exists(char const * name, bool caseSensitive = true);
592 
600  size_t fileSize(char const * name);
601 
615  bool fileCreationDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
616 
630  bool fileUpdateDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
631 
645  bool fileAccessDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
646 
652  void setSorted(bool value);
653 
654  void setIncludeHiddenFiles(bool value) { m_includeHiddenFiles = value; }
655 
661  void makeDirectory(char const * dirname);
662 
670  void remove(char const * name);
671 
678  void rename(char const * oldName, char const * newName);
679 
688  bool truncate(char const * name, size_t size);
689 
695  char * createTempFilename();
696 
706  int getFullPath(char const * name, char * outPath = nullptr, int maxlen = 0);
707 
716  FILE * openFile(char const * filename, char const * mode);
717 
724 
732  static DriveType getDriveType(char const * path);
733 
751  static bool format(DriveType driveType, int drive);
752 
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);
773 
779  static bool remountSDCard();
780 
784  static void unmountSDCard();
785 
800  static bool mountSPIFFS(bool formatOnFail, char const * mountPath, size_t maxFiles = 4);
801 
807  static bool remountSPIFFS();
808 
812  static void unmountSPIFFS();
813 
836  static bool getFSInfo(DriveType driveType, int drive, int64_t * total, int64_t * used);
837 
838 private:
839 
840  void clear();
841  int countDirEntries(int * namesLength);
842 
843  // SPIFFS static infos
844  static bool s_SPIFFSMounted;
845  static char const * s_SPIFFSMountPath;
846  static size_t s_SPIFFSMaxFiles;
847 
848  // SD Card static infos
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;
857 
858  char * m_dir;
859  int m_count;
860  DirItem * m_items;
861  bool m_sorted;
862  bool m_includeHiddenFiles;
863  char * m_namesStorage;
864 };
865 
866 
867 
868 
870 
871 
872 
873 bool clipLine(int & x1, int & y1, int & x2, int & y2, Rect const & clipRect, bool checkOnly);
874 
875 
876 void removeRectangle(Stack<Rect> & rects, Rect const & mainRect, Rect const & rectToRemove);
877 
878 
879 bool calcParity(uint8_t v);
880 
881 // why these? this is like heap_caps_malloc with MALLOC_CAP_32BIT. Unfortunately
882 // heap_caps_malloc crashes, so we need this workaround.
883 void * realloc32(void * ptr, size_t size);
884 void free32(void * ptr);
885 
886 
887 inline gpio_num_t int2gpio(int gpio)
888 {
889  return gpio == -1 ? GPIO_UNUSED : (gpio_num_t)gpio;
890 }
891 
892 
893 // converts 0..9 -> '0'..'9', 10..15 -> 'a'..'f'
894 inline char digit2hex(int digit)
895 {
896  return digit < 10 ? '0' + digit : 'a' + digit - 10;
897 }
898 
899 
900 // converts '0'..'9' -> 0..9, 'a'..'f' -> 10..15
901 inline int hex2digit(char hex)
902 {
903  return hex < 'a' ? hex - '0' : hex - 'a' + 10;
904 }
905 
906 
907 // milliseconds to FreeRTOS ticks.
908 // ms = -1 => maximum delay (portMAX_DELAY)
909 uint32_t msToTicks(int ms);
910 
911 
915 enum class ChipPackage {
916  Unknown,
917  ESP32D0WDQ6,
918  ESP32D0WDQ5,
919  ESP32D2WDQ5,
920  ESP32PICOD4,
921 };
922 
923 
924 ChipPackage getChipPackage();
925 
926 inline __attribute__((always_inline)) uint32_t getCycleCount() {
927  uint32_t ccount;
928  __asm__ __volatile__(
929  "esync \n\t"
930  "rsr %0, ccount \n\t"
931  : "=a" (ccount)
932  );
933  return ccount;
934 }
935 
942 void replacePathSep(char * path, char newSep);
943 
944 
952 inline uint32_t UARTConf(int parity, int dataLength, int stopBits)
953 {
954  uint32_t w = 0x8000000 | (dataLength << 2) | (stopBits << 4);
955  if (parity)
956  w |= (parity == 1 ? 0b10 : 0b11);
957  return w;
958 }
959 
960 
961 adc1_channel_t ADC1_GPIO2Channel(gpio_num_t gpio);
962 
963 
964 void esp_intr_alloc_pinnedToCore(int source, int flags, intr_handler_t handler, void * arg, intr_handle_t * ret_handle, int core);
965 
966 
967 // mode: GPIO_MODE_DISABLE,
968 // GPIO_MODE_INPUT,
969 // GPIO_MODE_OUTPUT,
970 // GPIO_MODE_OUTPUT_OD (open drain),
971 // GPIO_MODE_INPUT_OUTPUT_OD (open drain),
972 // GPIO_MODE_INPUT_OUTPUT
973 void configureGPIO(gpio_num_t gpio, gpio_mode_t mode);
974 
975 
976 uint32_t getApbFrequency();
977 
978 uint32_t getCPUFrequencyMHz();
979 
980 
982 // AutoSemaphore
983 
984 struct AutoSemaphore {
985  AutoSemaphore(SemaphoreHandle_t mutex) : m_mutex(mutex) { xSemaphoreTake(m_mutex, portMAX_DELAY); }
986  ~AutoSemaphore() { xSemaphoreGive(m_mutex); }
987 private:
988  SemaphoreHandle_t m_mutex;
989 };
990 
991 
992 
994 // CoreUsage
995 
999 struct CoreUsage {
1000 
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; }
1004 
1005  private:
1006  static int s_busiestCore; // 0 = core 0, 1 = core 1 (default is FABGLIB_VIDEO_CPUINTENSIVE_TASKS_CORE)
1007 };
1008 
1009 
1011 
1012 
1276  VK_LAST, // marks the last virtual key
1277 
1278 };
1279 
1280 
1286  uint8_t down;
1287  uint8_t scancode[8];
1288  uint8_t ASCII;
1289  uint8_t CTRL : 1;
1290  uint8_t LALT : 1;
1291  uint8_t RALT : 1;
1292  uint8_t SHIFT : 1;
1293  uint8_t GUI : 1;
1294  uint8_t CAPSLOCK : 1;
1295  uint8_t NUMLOCK : 1;
1296  uint8_t SCROLLLOCK : 1;
1297 };
1298 
1299 
1300 
1302 // Virtual keys helpers
1303 
1304 inline bool isSHIFT(VirtualKey value)
1305 {
1306  return value == VK_LSHIFT || value == VK_RSHIFT;
1307 }
1308 
1309 
1310 inline bool isALT(VirtualKey value)
1311 {
1312  return value == VK_LALT || value == VK_RALT;
1313 }
1314 
1315 
1316 inline bool isCTRL(VirtualKey value)
1317 {
1318  return value == VK_LCTRL || value == VK_RCTRL;
1319 }
1320 
1321 
1322 inline bool isGUI(VirtualKey value)
1323 {
1324  return value == VK_LGUI || value == VK_RGUI;
1325 }
1326 
1327 
1328 
1330 // ASCII control characters
1331 
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
1395 
1396 
1397 } // end of namespace
1398 
1399 
1400 
MouseButtons buttons
Definition: fabutils.h:280
int16_t Y1
Definition: fabutils.h:227
char const * name
Definition: fabutils.h:512
uint32_t UARTConf(int parity, int dataLength, int stopBits)
Composes UART configuration word.
Definition: fabutils.h:952
int16_t width
Definition: fabutils.h:177
int16_t Y
Definition: fabutils.h:192
bool truncate(char const *name, size_t size)
Truncates a file to the specified size.
Definition: fabutils.cpp:1028
void rename(char const *oldName, char const *newName)
Renames a file.
Definition: fabutils.cpp:1000
uint8_t const * data
int16_t X
Definition: fabutils.h:191
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:1162
bool setDirectory(const char *path)
Sets absolute directory path.
Definition: fabutils.cpp:661
uint8_t B
A struct which contains a virtual key, key state and associated scan code.
Definition: fabutils.h:1284
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
Definition: fabutils.h:1016
int16_t X1
Definition: fabutils.h:226
size_t fileSize(char const *name)
Determines file size.
Definition: fabutils.cpp:752
This class helps to choice a core for intensive processing tasks.
Definition: fabutils.h:999
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:785
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: fabutils.h:276
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:767
static void unmountSDCard()
Unmounts filesystem on SD Card.
Definition: fabutils.cpp:1201
uint8_t G
Represents the coordinate of a point.
Definition: fabutils.h:190
Definition: canvas.cpp:36
FileBrowser item specificator.
Definition: fabutils.h:510
char * createTempFilename()
Creates a random temporary filename, with absolute path.
Definition: fabutils.cpp:1013
int getFullPath(char const *name, char *outPath=nullptr, int maxlen=0)
Composes a full file path given a relative name.
Definition: fabutils.cpp:1078
int16_t Y2
Definition: fabutils.h:229
DriveType getCurrentDriveType()
Returns the drive type of current directory.
Definition: fabutils.cpp:1097
static bool format(DriveType driveType, int drive)
Formats SPIFFS or SD Card.
Definition: fabutils.cpp:1115
DriveType
This enum defines drive types (SPIFFS or SD Card)
Definition: fabutils.h:519
Represents a rectangle.
Definition: fabutils.h:225
int16_t width
Definition: fabutils.h:209
Describes mouse buttons status.
Definition: fabutils.h:263
uint8_t R
int16_t height
Definition: fabutils.h:210
static bool remountSDCard()
Remounts SDCard filesystem, using the same parameters.
Definition: fabutils.cpp:1210
char const * directory()
Determines absolute path of current directory.
Definition: fabutils.h:565
void setSorted(bool value)
Determines if the items are sorted.
ChipPackage
This enum defines ESP32 module types (packages)
Definition: fabutils.h:915
uint8_t scancode[8]
Definition: fabutils.h:1287
Represents a bidimensional size.
Definition: fabutils.h:208
void makeDirectory(char const *dirname)
Creates a directory.
Definition: fabutils.cpp:920
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:803
static DriveType getDriveType(char const *path)
Returns the drive type of specified path.
Definition: fabutils.cpp:1103
int16_t X2
Definition: fabutils.h:228
void changeDirectory(const char *subdir)
Sets relative directory path.
Definition: fabutils.cpp:674
int16_t height
Definition: fabutils.h:178
FILE * openFile(char const *filename, char const *mode)
Opens a file from current directory.
Definition: fabutils.cpp:1084
static bool mountSPIFFS(bool formatOnFail, char const *mountPath, size_t maxFiles=4)
Mounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1217
bool exists(char const *name, bool caseSensitive=true)
Determines if a file or directory exists.
Definition: fabutils.cpp:737
int count()
Determines number of files in current directory.
Definition: fabutils.h:572
bool reload()
Reloads directory content.
Definition: fabutils.cpp:833
static bool getFSInfo(DriveType driveType, int drive, int64_t *total, int64_t *used)
Gets total and free space on a filesystem.
Definition: fabutils.cpp:1248
static bool remountSPIFFS()
Remounts SPIFFS filesystem, using the same parameters.
Definition: fabutils.cpp:1241
static void unmountSPIFFS()
Unmounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1232
FileBrowser allows basic file system operations (dir, mkdir, remove and rename)
Definition: fabutils.h:531