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  This file is part of FabGL Library.
7 
8  FabGL is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  FabGL is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 
24 #pragma once
25 
26 
35 #include "freertos/FreeRTOS.h"
36 #include "freertos/semphr.h"
37 
38 #include <driver/adc.h>
39 #include <esp_system.h>
40 
41 
42 namespace fabgl {
43 
44 
45 // manage IDF versioning
46 #ifdef ESP_IDF_VERSION
47  #define FABGL_ESP_IDF_VERSION_VAL ESP_IDF_VERSION_VAL
48  #define FABGL_ESP_IDF_VERSION ESP_IDF_VERSION
49 #else
50  #define FABGL_ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
51  #define FABGL_ESP_IDF_VERSION FABGL_ESP_IDF_VERSION_VAL(0, 0, 0)
52 #endif
53 
54 
55 
56 #define GPIO_UNUSED GPIO_NUM_MAX
57 
58 
60 // PSRAM_HACK
61 // ESP32 Revision 1 has following bug: "When the CPU accesses external SRAM through cache, under certain conditions read and write errors occur"
62 // A workaround is done by the compiler, so whenever PSRAM is enabled the workaround is automatically applied (-mfix-esp32-psram-cache-issue compiler option).
63 // Unfortunately this workaround reduces performance, even when SRAM is not access, like in VGAXController interrupt handler. This is unacceptable for the interrupt routine.
64 // In order to confuse the compiler and prevent the workaround from being applied, a "nop" is added between load and store instructions (PSRAM_HACK).
65 
66 #ifdef ARDUINO
67  #ifdef BOARD_HAS_PSRAM
68  #define FABGL_NEED_PSRAM_DISABLE_HACK
69  #endif
70 #else
71  #ifdef CONFIG_SPIRAM_SUPPORT
72  #define FABGL_NEED_PSRAM_DISABLE_HACK
73  #endif
74 #endif
75 
76 #ifdef FABGL_NEED_PSRAM_DISABLE_HACK
77  #define PSRAM_HACK asm(" nop")
78 #else
79  #define PSRAM_HACK
80 #endif
81 
82 // ESP32 PSRAM bug workaround (use when the library is NOT compiled with PSRAM hack enabled)
83 // Plase between a write and a read PSRAM operation (write->ASM_MEMW->read), not viceversa
84 #define ASM_MEMW asm(" MEMW");
85 
86 
87 
88 
90 
91 
92 // Integer square root by Halleck's method, with Legalize's speedup
93 int isqrt (int x);
94 
95 
96 template <typename T>
97 const T & tmax(const T & a, const T & b)
98 {
99  return (a < b) ? b : a;
100 }
101 
102 
103 constexpr auto imax = tmax<int>;
104 
105 
106 template <typename T>
107 const T & tmin(const T & a, const T & b)
108 {
109  return !(b < a) ? a : b;
110 }
111 
112 
113 constexpr auto imin = tmin<int>;
114 
115 
116 
117 template <typename T>
118 const T & tclamp(const T & v, const T & lo, const T & hi)
119 {
120  return (v < lo ? lo : (v > hi ? hi : v));
121 }
122 
123 
124 constexpr auto iclamp = tclamp<int>;
125 
126 
127 template <typename T>
128 const T & twrap(const T & v, const T & lo, const T & hi)
129 {
130  return (v < lo ? hi : (v > hi ? lo : v));
131 }
132 
133 
134 template <typename T>
135 void tswap(T & v1, T & v2)
136 {
137  T t = v1;
138  v1 = v2;
139  v2 = t;
140 }
141 
142 
143 constexpr auto iswap = tswap<int>;
144 
145 
146 template <typename T>
147 T moveItems(T dest, T src, size_t n)
148 {
149  T pd = dest;
150  T ps = src;
151  if (pd != ps) {
152  if (ps < pd)
153  for (pd += n, ps += n; n--;)
154  *--pd = *--ps;
155  else
156  while (n--)
157  *pd++ = *ps++;
158  }
159  return dest;
160 }
161 
162 
163 void rgb222_to_hsv(int R, int G, int B, double * h, double * s, double * v);
168 
174 struct Point {
175  int16_t X;
176  int16_t Y;
178  Point() : X(0), Y(0) { }
179  Point(int X_, int Y_) : X(X_), Y(Y_) { }
180 
181  Point add(Point const & p) const { return Point(X + p.X, Y + p.Y); }
182  Point sub(Point const & p) const { return Point(X - p.X, Y - p.Y); }
183  Point neg() const { return Point(-X, -Y); }
184  bool operator==(Point const & r) { return X == r.X && Y == r.Y; }
185  bool operator!=(Point const & r) { return X != r.X || Y != r.Y; }
186 } __attribute__ ((packed));
187 
188 
192 struct Size {
193  int16_t width;
194  int16_t height;
196  Size() : width(0), height(0) { }
197  Size(int width_, int height_) : width(width_), height(height_) { }
198  bool operator==(Size const & r) { return width == r.width && height == r.height; }
199  bool operator!=(Size const & r) { return width != r.width || height != r.height; }
200 } __attribute__ ((packed));
201 
202 
203 
209 struct Rect {
210  int16_t X1;
211  int16_t Y1;
212  int16_t X2;
213  int16_t Y2;
215  Rect() : X1(0), Y1(0), X2(0), Y2(0) { }
216  Rect(int X1_, int Y1_, int X2_, int Y2_) : X1(X1_), Y1(Y1_), X2(X2_), Y2(Y2_) { }
217  Rect(Rect const & r) { X1 = r.X1; Y1 = r.Y1; X2 = r.X2; Y2 = r.Y2; }
218 
219  bool operator==(Rect const & r) { return X1 == r.X1 && Y1 == r.Y1 && X2 == r.X2 && Y2 == r.Y2; }
220  bool operator!=(Rect const & r) { return X1 != r.X1 || Y1 != r.Y1 || X2 != r.X2 || Y2 != r.Y2; }
221  Point pos() const { return Point(X1, Y1); }
222  Size size() const { return Size(X2 - X1 + 1, Y2 - Y1 + 1); }
223  int width() const { return X2 - X1 + 1; }
224  int height() const { return Y2 - Y1 + 1; }
225  Rect translate(int offsetX, int offsetY) const { return Rect(X1 + offsetX, Y1 + offsetY, X2 + offsetX, Y2 + offsetY); }
226  Rect translate(Point const & offset) const { return Rect(X1 + offset.X, Y1 + offset.Y, X2 + offset.X, Y2 + offset.Y); }
227  Rect move(Point const & position) const { return Rect(position.X, position.Y, position.X + width() - 1, position.Y + height() - 1); }
228  Rect move(int x, int y) const { return Rect(x, y, x + width() - 1, y + height() - 1); }
229  Rect shrink(int value) const { return Rect(X1 + value, Y1 + value, X2 - value, Y2 - value); }
230  Rect hShrink(int value) const { return Rect(X1 + value, Y1, X2 - value, Y2); }
231  Rect vShrink(int value) const { return Rect(X1, Y1 + value, X2, Y2 - value); }
232  Rect resize(int width, int height) const { return Rect(X1, Y1, X1 + width - 1, Y1 + height - 1); }
233  Rect resize(Size size) const { return Rect(X1, Y1, X1 + size.width - 1, Y1 + size.height - 1); }
234  Rect intersection(Rect const & rect) const;
235  bool intersects(Rect const & rect) const { return X1 <= rect.X2 && X2 >= rect.X1 && Y1 <= rect.Y2 && Y2 >= rect.Y1; }
236  bool contains(Rect const & rect) const { return (rect.X1 >= X1) && (rect.Y1 >= Y1) && (rect.X2 <= X2) && (rect.Y2 <= Y2); }
237  bool contains(Point const & point) const { return point.X >= X1 && point.Y >= Y1 && point.X <= X2 && point.Y <= Y2; }
238  bool contains(int x, int y) const { return x >= X1 && y >= Y1 && x <= X2 && y <= Y2; }
239  Rect merge(Rect const & rect) const;
240 } __attribute__ ((packed));
241 
242 
243 
247 struct MouseButtons {
248  uint8_t left : 1;
249  uint8_t middle : 1;
250  uint8_t right : 1;
252  MouseButtons() : left(0), middle(0), right(0) { }
253 };
254 
255 
256 
260 struct MouseStatus {
261  int16_t X;
262  int16_t Y;
263  int8_t wheelDelta;
266  MouseStatus() : X(0), Y(0), wheelDelta(0) { }
267 };
268 
269 
270 
271 #define FONTINFOFLAGS_ITALIC 1
272 #define FONTINFOFLAGS_UNDERLINE 2
273 #define FONTINFODLAFS_STRIKEOUT 4
274 #define FONTINFOFLAGS_VARWIDTH 8
275 
276 
277 struct FontInfo {
278  uint8_t pointSize;
279  uint8_t width; // used only for fixed width fonts (FONTINFOFLAGS_VARWIDTH = 0)
280  uint8_t height;
281  uint8_t ascent;
282  uint8_t inleading;
283  uint8_t exleading;
284  uint8_t flags;
285  uint16_t weight;
286  uint16_t charset;
287  // when FONTINFOFLAGS_VARWIDTH = 0:
288  // data[] contains 256 items each one representing a single character
289  // when FONTINFOFLAGS_VARWIDTH = 1:
290  // data[] contains 256 items each one representing a single character. First byte contains the
291  // character width. "chptr" is filled with an array of pointers to the single characters.
292  uint8_t const * data;
293  uint32_t const * chptr; // used only for variable width fonts (FONTINFOFLAGS_VARWIDTH = 1)
294 };
295 
296 
297 
298 
300 // TimeOut
301 
302 
303 struct TimeOut {
304  TimeOut();
305 
306  // -1 means "infinite", never times out
307  bool expired(int valueMS);
308 
309 private:
310  int64_t m_start;
311 };
312 
313 
314 
316 // Stack
317 
318 
319 template <typename T>
320 struct StackItem {
321  StackItem * next;
322  T item;
323  StackItem(StackItem * next_, T const & item_) : next(next_), item(item_) { }
324 };
325 
326 template <typename T>
327 class Stack {
328 public:
329  Stack() : m_items(nullptr) { }
330  bool isEmpty() { return m_items == nullptr; }
331  void push(T const & value) {
332  m_items = new StackItem<T>(m_items, value);
333  }
334  T pop() {
335  if (m_items) {
336  StackItem<T> * iptr = m_items;
337  m_items = iptr->next;
338  T r = iptr->item;
339  delete iptr;
340  return r;
341  } else
342  return T();
343  }
344  int count() {
345  int r = 0;
346  for (auto i = m_items; i; i = i->next)
347  ++r;
348  return r;
349  }
350 private:
351  StackItem<T> * m_items;
352 };
353 
354 
355 
357 // Delegate
358 
359 template <typename ...Params>
360 struct Delegate {
361 
362  // empty constructor
363  Delegate() : m_func(nullptr) {
364  }
365 
366  // denied copy
367  Delegate(const Delegate & c) = delete;
368 
369  // construct from lambda
370  template <typename Func>
371  Delegate(Func f) : Delegate() {
372  *this = f;
373  }
374 
375  ~Delegate() {
376  cleanUp();
377  }
378 
379  // assignment operator from Func
380  template <typename Func>
381  void operator=(Func f) {
382  cleanUp();
383  m_closure = [] (void * func, const Params & ...params) -> void { (*(Func *)func)(params...); };
384  m_func = heap_caps_malloc(sizeof(Func), MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
385  moveItems<uint32_t*>((uint32_t*)m_func, (uint32_t*)&f, sizeof(Func) / sizeof(uint32_t));
386  }
387 
388  // denied assignment from Delegate
389  void operator=(const Delegate&) = delete;
390 
391  void operator()(const Params & ...params) {
392  if (m_func)
393  m_closure(m_func, params...);
394  }
395 
396 private:
397 
398  void (*m_closure)(void * func, const Params & ...params);
399  void * m_func;
400 
401  void cleanUp() {
402  if (m_func)
403  heap_caps_free(m_func);
404  }
405 };
406 
407 
408 
410 // StringList
411 
412 class StringList {
413 
414 public:
415  StringList();
416  ~StringList();
417  int append(char const * str);
418  int appendFmt(const char *format, ...);
419  void append(char const * strlist[], int count);
420  void appendSepList(char const * strlist, char separator);
421  void insert(int index, char const * str);
422  void set(int index, char const * str);
423  void remove(int index);
424  int count() { return m_count; }
425  char const * get(int index) { return m_items[index]; }
426  void clear();
427  void takeStrings();
428  void select(int index, bool value);
429  void deselectAll();
430  bool selected(int index);
431  int getFirstSelected();
432  void copyFrom(StringList const & src);
433  void copySelectionMapFrom(StringList const & src);
434 
435 private:
436  void checkAllocatedSpace(int requiredItems);
437 
438  char const * * m_items;
439 
440  // each 32 bit word can select up to 32 items, one bit per item
441  uint32_t * m_selMap;
442 
443  // If true (default is false) all strings added (append/insert/set) are copied.
444  // Strings will be released when no more used (destructor, clear(), etc...).
445  // This flag is permanently switched to True by takeStrings() call.
446  bool m_ownStrings;
447 
448  uint16_t m_count; // actual items
449  uint16_t m_allocated; // allocated items
450 
451 };
452 
453 
455 // LightMemoryPool
456 // Each allocated block starts with a two bytes header (int16_t). Bit 15 is allocation flag (0=free, 1=allocated).
457 // Bits 14..0 represent the block size.
458 // The maximum size of a block is 32767 bytes.
459 // free() just marks the block header as free.
460 
461 class LightMemoryPool {
462 public:
463  LightMemoryPool(int poolSize);
464  ~LightMemoryPool();
465  void * alloc(int size);
466  void free(void * mem) { if (mem) markFree((uint8_t*)mem - m_mem - 2); }
467 
468  bool memCheck();
469  int totFree(); // get total free memory
470  int totAllocated(); // get total allocated memory
471  int largestFree();
472 
473 private:
474 
475  void mark(int pos, int16_t size, bool allocated);
476  void markFree(int pos) { m_mem[pos + 1] &= 0x7f; }
477  int16_t getSize(int pos);
478  bool isFree(int pos);
479 
480  uint8_t * m_mem;
481  int m_poolSize;
482 };
483 
484 
485 
487 // FileBrowser
488 
489 
493 struct DirItem {
494  bool isDir;
495  char const * name;
496 };
497 
498 
502 enum class DriveType {
503  None,
504  SPIFFS,
505  SDCard,
506 };
507 
508 
514 class FileBrowser {
515 public:
516 
517  FileBrowser();
518  ~FileBrowser();
519 
527  bool setDirectory(const char * path);
528 
534  void changeDirectory(const char * subdir);
535 
541  bool reload();
542 
548  char const * directory() { return m_dir; }
549 
555  int count() { return m_count; }
556 
564  DirItem const * get(int index) { return m_items + index; }
565 
574  bool exists(char const * name, bool caseSensitive = true);
575 
583  size_t fileSize(char const * name);
584 
598  bool fileCreationDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
599 
613  bool fileUpdateDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
614 
628  bool fileAccessDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
629 
635  void setSorted(bool value);
636 
637  void setIncludeHiddenFiles(bool value) { m_includeHiddenFiles = value; }
638 
644  void makeDirectory(char const * dirname);
645 
653  void remove(char const * name);
654 
661  void rename(char const * oldName, char const * newName);
662 
671  bool truncate(char const * name, size_t size);
672 
678  char * createTempFilename();
679 
689  int getFullPath(char const * name, char * outPath = nullptr, int maxlen = 0);
690 
699  FILE * openFile(char const * filename, char const * mode);
700 
707 
715  static DriveType getDriveType(char const * path);
716 
734  static bool format(DriveType driveType, int drive);
735 
755  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);
756 
762  static bool remountSDCard();
763 
767  static void unmountSDCard();
768 
783  static bool mountSPIFFS(bool formatOnFail, char const * mountPath, size_t maxFiles = 4);
784 
790  static bool remountSPIFFS();
791 
795  static void unmountSPIFFS();
796 
819  static bool getFSInfo(DriveType driveType, int drive, int64_t * total, int64_t * used);
820 
821 private:
822 
823  void clear();
824  int countDirEntries(int * namesLength);
825 
826  // SPIFFS static infos
827  static bool s_SPIFFSMounted;
828  static char const * s_SPIFFSMountPath;
829  static size_t s_SPIFFSMaxFiles;
830 
831  // SD Card static infos
832  static bool s_SDCardMounted;
833  static char const * s_SDCardMountPath;
834  static size_t s_SDCardMaxFiles;
835  static int s_SDCardAllocationUnitSize;
836  static int8_t s_SDCardMISO;
837  static int8_t s_SDCardMOSI;
838  static int8_t s_SDCardCLK;
839  static int8_t s_SDCardCS;
840 
841  char * m_dir;
842  int m_count;
843  DirItem * m_items;
844  bool m_sorted;
845  bool m_includeHiddenFiles;
846  char * m_namesStorage;
847 };
848 
849 
850 
851 
853 
854 
855 
856 bool clipLine(int & x1, int & y1, int & x2, int & y2, Rect const & clipRect, bool checkOnly);
857 
858 
859 void removeRectangle(Stack<Rect> & rects, Rect const & mainRect, Rect const & rectToRemove);
860 
861 
862 bool calcParity(uint8_t v);
863 
864 // why these? this is like heap_caps_malloc with MALLOC_CAP_32BIT. Unfortunately
865 // heap_caps_malloc crashes, so we need this workaround.
866 void * realloc32(void * ptr, size_t size);
867 void free32(void * ptr);
868 
869 
870 inline gpio_num_t int2gpio(int gpio)
871 {
872  return gpio == -1 ? GPIO_UNUSED : (gpio_num_t)gpio;
873 }
874 
875 
876 // converts 0..9 -> '0'..'9', 10..15 -> 'a'..'f'
877 inline char digit2hex(int digit)
878 {
879  return digit < 10 ? '0' + digit : 'a' + digit - 10;
880 }
881 
882 
883 // converts '0'..'9' -> 0..9, 'a'..'f' -> 10..15
884 inline int hex2digit(char hex)
885 {
886  return hex < 'a' ? hex - '0' : hex - 'a' + 10;
887 }
888 
889 
890 // milliseconds to FreeRTOS ticks.
891 // ms = -1 => maximum delay (portMAX_DELAY)
892 uint32_t msToTicks(int ms);
893 
894 
898 enum class ChipPackage {
899  Unknown,
900  ESP32D0WDQ6,
901  ESP32D0WDQ5,
902  ESP32D2WDQ5,
903  ESP32PICOD4,
904 };
905 
906 
907 ChipPackage getChipPackage();
908 
909 inline __attribute__((always_inline)) uint32_t getCycleCount() {
910  uint32_t ccount;
911  __asm__ __volatile__(
912  "esync \n\t"
913  "rsr %0, ccount \n\t"
914  : "=a" (ccount)
915  );
916  return ccount;
917 }
918 
925 void replacePathSep(char * path, char newSep);
926 
927 
935 inline uint32_t UARTConf(int parity, int dataLength, int stopBits)
936 {
937  uint32_t w = 0x8000000 | (dataLength << 2) | (stopBits << 4);
938  if (parity)
939  w |= (parity == 1 ? 0b10 : 0b11);
940  return w;
941 }
942 
943 
944 adc1_channel_t ADC1_GPIO2Channel(gpio_num_t gpio);
945 
946 
947 void esp_intr_alloc_pinnedToCore(int source, int flags, intr_handler_t handler, void * arg, intr_handle_t * ret_handle, int core);
948 
949 
950 // mode: GPIO_MODE_DISABLE,
951 // GPIO_MODE_INPUT,
952 // GPIO_MODE_OUTPUT,
953 // GPIO_MODE_OUTPUT_OD (open drain),
954 // GPIO_MODE_INPUT_OUTPUT_OD (open drain),
955 // GPIO_MODE_INPUT_OUTPUT
956 void configureGPIO(gpio_num_t gpio, gpio_mode_t mode);
957 
958 
959 uint32_t getApbFrequency();
960 
961 uint32_t getCPUFrequencyMHz();
962 
963 
965 // AutoSemaphore
966 
967 struct AutoSemaphore {
968  AutoSemaphore(SemaphoreHandle_t mutex) : m_mutex(mutex) { xSemaphoreTake(m_mutex, portMAX_DELAY); }
969  ~AutoSemaphore() { xSemaphoreGive(m_mutex); }
970 private:
971  SemaphoreHandle_t m_mutex;
972 };
973 
974 
975 
977 // CoreUsage
978 
982 struct CoreUsage {
983 
984  static int busiestCore() { return s_busiestCore; }
985  static int quietCore() { return s_busiestCore != -1 ? s_busiestCore ^ 1 : -1; }
986  static void setBusiestCore(int core) { s_busiestCore = core; }
987 
988  private:
989  static int s_busiestCore; // 0 = core 0, 1 = core 1 (default is FABGLIB_VIDEO_CPUINTENSIVE_TASKS_CORE)
990 };
991 
992 
994 
995 
1195  // For spanish keyboard layout
1196 
1248  VK_LAST, // marks the last virtual key
1249 
1250 };
1251 
1252 
1254 // Virtual keys helpers
1255 
1256 inline bool isSHIFT(VirtualKey value)
1257 {
1258  return value == VK_LSHIFT || value == VK_RSHIFT;
1259 }
1260 
1261 
1262 inline bool isALT(VirtualKey value)
1263 {
1264  return value == VK_LALT || value == VK_RALT;
1265 }
1266 
1267 
1268 inline bool isCTRL(VirtualKey value)
1269 {
1270  return value == VK_LCTRL || value == VK_RCTRL;
1271 }
1272 
1273 
1274 inline bool isGUI(VirtualKey value)
1275 {
1276  return value == VK_LGUI || value == VK_RGUI;
1277 }
1278 
1279 
1280 
1282 // ASCII control characters
1283 
1284 #define ASCII_NUL 0x00 // Null
1285 #define ASCII_SOH 0x01 // Start of Heading
1286 #define ASCII_CTRLA 0x01 // CTRL-A
1287 #define ASCII_STX 0x02 // Start of Text
1288 #define ASCII_CTRLB 0x02 // CTRL-B
1289 #define ASCII_ETX 0x03 // End Of Text
1290 #define ASCII_CTRLC 0x03 // CTRL-C
1291 #define ASCII_EOT 0x04 // End Of Transmission
1292 #define ASCII_CTRLD 0x04 // CTRL-D
1293 #define ASCII_ENQ 0x05 // Enquiry
1294 #define ASCII_CTRLE 0x05 // CTRL-E
1295 #define ASCII_ACK 0x06 // Acknowledge
1296 #define ASCII_CTRLF 0x06 // CTRL-F
1297 #define ASCII_BEL 0x07 // Bell
1298 #define ASCII_CTRLG 0x07 // CTRL-G
1299 #define ASCII_BS 0x08 // Backspace
1300 #define ASCII_CTRLH 0x08 // CTRL-H
1301 #define ASCII_HT 0x09 // Horizontal Tab
1302 #define ASCII_TAB 0x09 // Horizontal Tab
1303 #define ASCII_CTRLI 0x09 // CTRL-I
1304 #define ASCII_LF 0x0A // Line Feed
1305 #define ASCII_CTRLJ 0x0A // CTRL-J
1306 #define ASCII_VT 0x0B // Vertical Tab
1307 #define ASCII_CTRLK 0x0B // CTRL-K
1308 #define ASCII_FF 0x0C // Form Feed
1309 #define ASCII_CTRLL 0x0C // CTRL-L
1310 #define ASCII_CR 0x0D // Carriage Return
1311 #define ASCII_CTRLM 0x0D // CTRL-M
1312 #define ASCII_SO 0x0E // Shift Out
1313 #define ASCII_CTRLN 0x0E // CTRL-N
1314 #define ASCII_SI 0x0F // Shift In
1315 #define ASCII_CTRLO 0x0F // CTRL-O
1316 #define ASCII_DLE 0x10 // Data Link Escape
1317 #define ASCII_CTRLP 0x10 // CTRL-P
1318 #define ASCII_DC1 0x11 // Device Control 1
1319 #define ASCII_CTRLQ 0x11 // CTRL-Q
1320 #define ASCII_XON 0x11 // Transmission On
1321 #define ASCII_DC2 0x12 // Device Control 2
1322 #define ASCII_CTRLR 0x12 // CTRL-R
1323 #define ASCII_DC3 0x13 // Device Control 3
1324 #define ASCII_XOFF 0x13 // Transmission Off
1325 #define ASCII_CTRLS 0x13 // CTRL-S
1326 #define ASCII_DC4 0x14 // Device Control 4
1327 #define ASCII_CTRLT 0x14 // CTRL-T
1328 #define ASCII_NAK 0x15 // Negative Acknowledge
1329 #define ASCII_CTRLU 0x15 // CTRL-U
1330 #define ASCII_SYN 0x16 // Synchronous Idle
1331 #define ASCII_CTRLV 0x16 // CTRL-V
1332 #define ASCII_ETB 0x17 // End-of-Transmission-Block
1333 #define ASCII_CTRLW 0x17 // CTRL-W
1334 #define ASCII_CAN 0x18 // Cancel
1335 #define ASCII_CTRLX 0x18 // CTRL-X
1336 #define ASCII_EM 0x19 // End of Medium
1337 #define ASCII_CTRLY 0x19 // CTRL-Y
1338 #define ASCII_SUB 0x1A // Substitute
1339 #define ASCII_CTRLZ 0x1A // CTRL-Z
1340 #define ASCII_ESC 0x1B // Escape
1341 #define ASCII_FS 0x1C // File Separator
1342 #define ASCII_GS 0x1D // Group Separator
1343 #define ASCII_RS 0x1E // Record Separator
1344 #define ASCII_US 0x1F // Unit Separator
1345 #define ASCII_SPC 0x20 // Space
1346 #define ASCII_DEL 0x7F // Delete
1347 
1348 
1349 } // end of namespace
1350 
1351 
1352 
MouseButtons buttons
Definition: fabutils.h:264
int16_t Y1
Definition: fabutils.h:211
char const * name
Definition: fabutils.h:495
uint32_t UARTConf(int parity, int dataLength, int stopBits)
Composes UART configuration word.
Definition: fabutils.h:935
int16_t width
Definition: fabutils.h:164
int16_t Y
Definition: fabutils.h:176
bool truncate(char const *name, size_t size)
Truncates a file to the specified size.
Definition: fabutils.cpp:1024
void rename(char const *oldName, char const *newName)
Renames a file.
Definition: fabutils.cpp:996
uint8_t const * data
int16_t X
Definition: fabutils.h:175
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:1158
bool setDirectory(const char *path)
Sets absolute directory path.
Definition: fabutils.cpp:657
uint8_t B
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
Definition: fabutils.h:999
int16_t X1
Definition: fabutils.h:210
size_t fileSize(char const *name)
Determines file size.
Definition: fabutils.cpp:748
This class helps to choice a core for intensive processing tasks.
Definition: fabutils.h:982
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:781
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: fabutils.h:260
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:763
static void unmountSDCard()
Unmounts filesystem on SD Card.
Definition: fabutils.cpp:1197
uint8_t G
Represents the coordinate of a point.
Definition: fabutils.h:174
Definition: canvas.cpp:32
FileBrowser item specificator.
Definition: fabutils.h:493
char * createTempFilename()
Creates a random temporary filename, with absolute path.
Definition: fabutils.cpp:1009
int getFullPath(char const *name, char *outPath=nullptr, int maxlen=0)
Composes a full file path given a relative name.
Definition: fabutils.cpp:1074
int16_t Y2
Definition: fabutils.h:213
DriveType getCurrentDriveType()
Returns the drive type of current directory.
Definition: fabutils.cpp:1093
static bool format(DriveType driveType, int drive)
Formats SPIFFS or SD Card.
Definition: fabutils.cpp:1111
DriveType
This enum defines drive types (SPIFFS or SD Card)
Definition: fabutils.h:502
Represents a rectangle.
Definition: fabutils.h:209
int16_t width
Definition: fabutils.h:193
Describes mouse buttons status.
Definition: fabutils.h:247
uint8_t R
int16_t height
Definition: fabutils.h:194
static bool remountSDCard()
Remounts SDCard filesystem, using the same parameters.
Definition: fabutils.cpp:1206
char const * directory()
Determines absolute path of current directory.
Definition: fabutils.h:548
void setSorted(bool value)
Determines if the items are sorted.
ChipPackage
This enum defines ESP32 module types (packages)
Definition: fabutils.h:898
Represents a bidimensional size.
Definition: fabutils.h:192
void makeDirectory(char const *dirname)
Creates a directory.
Definition: fabutils.cpp:916
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:799
static DriveType getDriveType(char const *path)
Returns the drive type of specified path.
Definition: fabutils.cpp:1099
int16_t X2
Definition: fabutils.h:212
void changeDirectory(const char *subdir)
Sets relative directory path.
Definition: fabutils.cpp:670
int16_t height
Definition: fabutils.h:165
FILE * openFile(char const *filename, char const *mode)
Opens a file from current directory.
Definition: fabutils.cpp:1080
static bool mountSPIFFS(bool formatOnFail, char const *mountPath, size_t maxFiles=4)
Mounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1213
bool exists(char const *name, bool caseSensitive=true)
Determines if a file or directory exists.
Definition: fabutils.cpp:733
int count()
Determines number of files in current directory.
Definition: fabutils.h:555
bool reload()
Reloads directory content.
Definition: fabutils.cpp:829
static bool getFSInfo(DriveType driveType, int drive, int64_t *total, int64_t *used)
Gets total and free space on a filesystem.
Definition: fabutils.cpp:1244
static bool remountSPIFFS()
Remounts SPIFFS filesystem, using the same parameters.
Definition: fabutils.cpp:1237
static void unmountSPIFFS()
Unmounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1228
FileBrowser allows basic file system operations (dir, mkdir, remove and rename)
Definition: fabutils.h:514