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 #include "sdmmc_cmd.h"
45 
46 
47 namespace 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 
92 
93 
95 
96 
97 // Integer square root by Halleck's method, with Legalize's speedup
98 int isqrt (int x);
99 
100 
101 template <typename T>
102 const T & tmax(const T & a, const T & b)
103 {
104  return (a < b) ? b : a;
105 }
106 
107 
108 constexpr auto imax = tmax<int>;
109 
110 
111 template <typename T>
112 const T & tmin(const T & a, const T & b)
113 {
114  return !(b < a) ? a : b;
115 }
116 
117 
118 constexpr auto imin = tmin<int>;
119 
120 
121 
122 template <typename T>
123 const T & tclamp(const T & v, const T & lo, const T & hi)
124 {
125  return (v < lo ? lo : (v > hi ? hi : v));
126 }
127 
128 
129 constexpr auto iclamp = tclamp<int>;
130 
131 
132 template <typename T>
133 const T & twrap(const T & v, const T & lo, const T & hi)
134 {
135  return (v < lo ? hi : (v > hi ? lo : v));
136 }
137 
138 
139 template <typename T>
140 void tswap(T & v1, T & v2)
141 {
142  T t = v1;
143  v1 = v2;
144  v2 = t;
145 }
146 
147 
148 constexpr auto iswap = tswap<int>;
149 
150 
151 template <typename T>
152 T moveItems(T dest, T src, size_t n)
153 {
154  T pd = dest;
155  T ps = src;
156  if (pd != ps) {
157  if (ps < pd)
158  for (pd += n, ps += n; n--;)
159  *--pd = *--ps;
160  else
161  while (n--)
162  *pd++ = *ps++;
163  }
164  return dest;
165 }
166 
167 
168 void rgb222_to_hsv(int R, int G, int B, double * h, double * s, double * v);
169 
170 
171 inline uint16_t changeEndiannesWord(uint16_t value)
172 {
173  return ((value & 0xff00) >> 8) | ((value & 0x00ff) << 8);
174 }
175 
176 
177 inline uint32_t changeEndiannesDWord(uint32_t value)
178 {
179  return ((value & 0xff) << 24) | ((value & 0xff00) << 8) | ((value & 0xff0000) >> 8) | ((value & 0xff000000) >> 24);
180 }
182 
184 
185 
191 struct Point {
192  int16_t X;
193  int16_t Y;
195  Point() : X(0), Y(0) { }
196  Point(int X_, int Y_) : X(X_), Y(Y_) { }
197 
198  Point add(Point const & p) const { return Point(X + p.X, Y + p.Y); }
199  Point sub(Point const & p) const { return Point(X - p.X, Y - p.Y); }
200  Point neg() const { return Point(-X, -Y); }
201  bool operator==(Point const & r) { return X == r.X && Y == r.Y; }
202  bool operator!=(Point const & r) { return X != r.X || Y != r.Y; }
203 } __attribute__ ((packed));
204 
205 
209 struct Size {
210  int16_t width;
211  int16_t height;
213  Size() : width(0), height(0) { }
214  Size(int width_, int height_) : width(width_), height(height_) { }
215  bool operator==(Size const & r) { return width == r.width && height == r.height; }
216  bool operator!=(Size const & r) { return width != r.width || height != r.height; }
217 } __attribute__ ((packed));
218 
219 
220 
226 struct Rect {
227  int16_t X1;
228  int16_t Y1;
229  int16_t X2;
230  int16_t Y2;
232  Rect() : X1(0), Y1(0), X2(0), Y2(0) { }
233  Rect(int X1_, int Y1_, int X2_, int Y2_) : X1(X1_), Y1(Y1_), X2(X2_), Y2(Y2_) { }
234  Rect(Rect const & r) { X1 = r.X1; Y1 = r.Y1; X2 = r.X2; Y2 = r.Y2; }
235 
236  bool operator==(Rect const & r) { return X1 == r.X1 && Y1 == r.Y1 && X2 == r.X2 && Y2 == r.Y2; }
237  bool operator!=(Rect const & r) { return X1 != r.X1 || Y1 != r.Y1 || X2 != r.X2 || Y2 != r.Y2; }
238  Point pos() const { return Point(X1, Y1); }
239  Size size() const { return Size(X2 - X1 + 1, Y2 - Y1 + 1); }
240  int width() const { return X2 - X1 + 1; }
241  int height() const { return Y2 - Y1 + 1; }
242  Rect translate(int offsetX, int offsetY) const { return Rect(X1 + offsetX, Y1 + offsetY, X2 + offsetX, Y2 + offsetY); }
243  Rect translate(Point const & offset) const { return Rect(X1 + offset.X, Y1 + offset.Y, X2 + offset.X, Y2 + offset.Y); }
244  Rect move(Point const & position) const { return Rect(position.X, position.Y, position.X + width() - 1, position.Y + height() - 1); }
245  Rect move(int x, int y) const { return Rect(x, y, x + width() - 1, y + height() - 1); }
246  Rect shrink(int value) const { return Rect(X1 + value, Y1 + value, X2 - value, Y2 - value); }
247  Rect hShrink(int value) const { return Rect(X1 + value, Y1, X2 - value, Y2); }
248  Rect vShrink(int value) const { return Rect(X1, Y1 + value, X2, Y2 - value); }
249  Rect resize(int width, int height) const { return Rect(X1, Y1, X1 + width - 1, Y1 + height - 1); }
250  Rect resize(Size size) const { return Rect(X1, Y1, X1 + size.width - 1, Y1 + size.height - 1); }
251  Rect intersection(Rect const & rect) const;
252  bool intersects(Rect const & rect) const { return X1 <= rect.X2 && X2 >= rect.X1 && Y1 <= rect.Y2 && Y2 >= rect.Y1; }
253  bool contains(Rect const & rect) const { return (rect.X1 >= X1) && (rect.Y1 >= Y1) && (rect.X2 <= X2) && (rect.Y2 <= Y2); }
254  bool contains(Point const & point) const { return point.X >= X1 && point.Y >= Y1 && point.X <= X2 && point.Y <= Y2; }
255  bool contains(int x, int y) const { return x >= X1 && y >= Y1 && x <= X2 && y <= Y2; }
256  Rect merge(Rect const & rect) const;
257 } __attribute__ ((packed));
258 
259 
260 
264 struct MouseButtons {
265  uint8_t left : 1;
266  uint8_t middle : 1;
267  uint8_t right : 1;
269  MouseButtons() : left(0), middle(0), right(0) { }
270 };
271 
272 
273 
277 struct MouseStatus {
278  int16_t X;
279  int16_t Y;
280  int8_t wheelDelta;
283  MouseStatus() : X(0), Y(0), wheelDelta(0) { }
284 };
285 
286 
287 
288 #define FONTINFOFLAGS_ITALIC 1
289 #define FONTINFOFLAGS_UNDERLINE 2
290 #define FONTINFODLAFS_STRIKEOUT 4
291 #define FONTINFOFLAGS_VARWIDTH 8
292 
293 
294 struct FontInfo {
295  uint8_t pointSize;
296  uint8_t width; // used only for fixed width fonts (FONTINFOFLAGS_VARWIDTH = 0)
297  uint8_t height;
298  uint8_t ascent;
299  uint8_t inleading;
300  uint8_t exleading;
301  uint8_t flags;
302  uint16_t weight;
303  uint16_t charset;
304  // when FONTINFOFLAGS_VARWIDTH = 0:
305  // data[] contains 256 items each one representing a single character
306  // when FONTINFOFLAGS_VARWIDTH = 1:
307  // data[] contains 256 items each one representing a single character. First byte contains the
308  // character width. "chptr" is filled with an array of pointers to the single characters.
309  uint8_t const * data;
310  uint32_t const * chptr; // used only for variable width fonts (FONTINFOFLAGS_VARWIDTH = 1)
311  uint16_t codepage;
312 };
313 
314 
315 
316 
318 // TimeOut
319 
320 
321 struct TimeOut {
322  TimeOut();
323 
324  // -1 means "infinite", never times out
325  bool expired(int valueMS);
326 
327 private:
328  int64_t m_start;
329 };
330 
331 
332 
334 // Stack
335 
336 
337 template <typename T>
338 struct StackItem {
339  StackItem * next;
340  T item;
341  StackItem(StackItem * next_, T const & item_) : next(next_), item(item_) { }
342 };
343 
344 template <typename T>
345 class Stack {
346 public:
347  Stack() : m_items(nullptr) { }
348  bool isEmpty() { return m_items == nullptr; }
349  void push(T const & value) {
350  m_items = new StackItem<T>(m_items, value);
351  }
352  T pop() {
353  if (m_items) {
354  StackItem<T> * iptr = m_items;
355  m_items = iptr->next;
356  T r = iptr->item;
357  delete iptr;
358  return r;
359  } else
360  return T();
361  }
362  int count() {
363  int r = 0;
364  for (auto i = m_items; i; i = i->next)
365  ++r;
366  return r;
367  }
368 private:
369  StackItem<T> * m_items;
370 };
371 
372 
373 
375 // Delegate
376 
377 template <typename ...Params>
378 struct Delegate {
379 
380  // empty constructor
381  Delegate() : m_func(nullptr) {
382  }
383 
384  // denied copy
385  Delegate(const Delegate & c) = delete;
386 
387  // construct from lambda
388  template <typename Func>
389  Delegate(Func f) : Delegate() {
390  *this = f;
391  }
392 
393  ~Delegate() {
394  cleanUp();
395  }
396 
397  // assignment operator from Func
398  template <typename Func>
399  void operator=(Func f) {
400  cleanUp();
401  m_closure = [] (void * func, const Params & ...params) -> void { (*(Func *)func)(params...); };
402  m_func = heap_caps_malloc(sizeof(Func), MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
403  moveItems<uint32_t*>((uint32_t*)m_func, (uint32_t*)&f, sizeof(Func) / sizeof(uint32_t));
404  }
405 
406  // denied assignment from Delegate
407  void operator=(const Delegate&) = delete;
408 
409  void operator()(const Params & ...params) {
410  if (m_func)
411  m_closure(m_func, params...);
412  }
413 
414 private:
415 
416  void (*m_closure)(void * func, const Params & ...params);
417  void * m_func;
418 
419  void cleanUp() {
420  if (m_func)
421  heap_caps_free(m_func);
422  }
423 };
424 
425 
426 
428 // StringList
429 
430 class StringList {
431 
432 public:
433  StringList();
434  ~StringList();
435  int append(char const * str);
436  int appendFmt(const char *format, ...);
437  void append(char const * strlist[], int count);
438  void appendSepList(char const * strlist, char separator);
439  void insert(int index, char const * str);
440  void set(int index, char const * str);
441  void remove(int index);
442  int count() { return m_count; }
443  char const * get(int index) { return m_items[index]; }
444  void clear();
445  void takeStrings();
446  void select(int index, bool value);
447  void deselectAll();
448  bool selected(int index);
449  int getFirstSelected();
450  void copyFrom(StringList const & src);
451  void copySelectionMapFrom(StringList const & src);
452 
453 private:
454  void checkAllocatedSpace(int requiredItems);
455 
456  char const * * m_items;
457 
458  // each 32 bit word can select up to 32 items, one bit per item
459  uint32_t * m_selMap;
460 
461  // If true (default is false) all strings added (append/insert/set) are copied.
462  // Strings will be released when no more used (destructor, clear(), etc...).
463  // This flag is permanently switched to True by takeStrings() call.
464  bool m_ownStrings;
465 
466  uint16_t m_count; // actual items
467  uint16_t m_allocated; // allocated items
468 
469 };
470 
471 
473 // LightMemoryPool
474 // Each allocated block starts with a two bytes header (int16_t). Bit 15 is allocation flag (0=free, 1=allocated).
475 // Bits 14..0 represent the block size.
476 // The maximum size of a block is 32767 bytes.
477 // free() just marks the block header as free.
478 
479 class LightMemoryPool {
480 public:
481  LightMemoryPool(int poolSize);
482  ~LightMemoryPool();
483  void * alloc(int size);
484  void free(void * mem) { if (mem) markFree((uint8_t*)mem - m_mem - 2); }
485 
486  bool memCheck();
487  int totFree(); // get total free memory
488  int totAllocated(); // get total allocated memory
489  int largestFree();
490 
491 private:
492 
493  void mark(int pos, int16_t size, bool allocated);
494  void markFree(int pos) { m_mem[pos + 1] &= 0x7f; }
495  int16_t getSize(int pos);
496  bool isFree(int pos);
497 
498  uint8_t * m_mem;
499  int m_poolSize;
500 };
501 
502 
503 
505 // FileBrowser
506 
507 
511 struct DirItem {
512  bool isDir;
513  char const * name;
514 };
515 
516 
520 enum class DriveType {
521  None,
522  SPIFFS,
523  SDCard,
524 };
525 
526 
532 class FileBrowser {
533 public:
534 
535  FileBrowser();
536 
537  FileBrowser(char const * path);
538 
539  ~FileBrowser();
540 
548  bool setDirectory(const char * path);
549 
555  void changeDirectory(const char * subdir);
556 
562  bool reload();
563 
569  char const * directory() { return m_dir; }
570 
576  int count() { return m_count; }
577 
585  DirItem const * get(int index) { return m_items + index; }
586 
597  bool exists(char const * name, bool caseSensitive = true);
598 
608  bool filePathExists(char const * filepath);
609 
617  size_t fileSize(char const * name);
618 
632  bool fileCreationDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
633 
647  bool fileUpdateDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
648 
662  bool fileAccessDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
663 
669  void setSorted(bool value);
670 
671  void setIncludeHiddenFiles(bool value) { m_includeHiddenFiles = value; }
672 
678  void makeDirectory(char const * dirname);
679 
687  void remove(char const * name);
688 
695  void rename(char const * oldName, char const * newName);
696 
705  bool truncate(char const * name, size_t size);
706 
712  char * createTempFilename();
713 
723  int getFullPath(char const * name, char * outPath = nullptr, int maxlen = 0);
724 
733  FILE * openFile(char const * filename, char const * mode);
734 
741 
749  static DriveType getDriveType(char const * path);
750 
768  static bool format(DriveType driveType, int drive);
769 
789  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);
790 
796  static bool remountSDCard();
797 
798  static bool mountedSDCard() { return s_SDCardMounted; }
799 
803  static void unmountSDCard();
804 
819  static bool mountSPIFFS(bool formatOnFail, char const * mountPath, size_t maxFiles = 4);
820 
826  static bool remountSPIFFS();
827 
831  static void unmountSPIFFS();
832 
855  static bool getFSInfo(DriveType driveType, int drive, int64_t * total, int64_t * used);
856 
857 private:
858 
859  void clear();
860  int countDirEntries(int * namesLength);
861 
862  // SPIFFS static infos
863  static bool s_SPIFFSMounted;
864  static char const * s_SPIFFSMountPath;
865  static size_t s_SPIFFSMaxFiles;
866 
867  // SD Card static infos
868  static bool s_SDCardMounted;
869  static char const * s_SDCardMountPath;
870  static size_t s_SDCardMaxFiles;
871  static int s_SDCardAllocationUnitSize;
872  static int8_t s_SDCardMISO;
873  static int8_t s_SDCardMOSI;
874  static int8_t s_SDCardCLK;
875  static int8_t s_SDCardCS;
876  static sdmmc_card_t * s_SDCard;
877 
878  char * m_dir;
879  int m_count;
880  DirItem * m_items;
881  bool m_sorted;
882  bool m_includeHiddenFiles;
883  char * m_namesStorage;
884 };
885 
886 
887 
888 
890 
891 
892 
893 bool clipLine(int & x1, int & y1, int & x2, int & y2, Rect const & clipRect, bool checkOnly);
894 
895 
896 void removeRectangle(Stack<Rect> & rects, Rect const & mainRect, Rect const & rectToRemove);
897 
898 
899 bool calcParity(uint8_t v);
900 
901 // why these? this is like heap_caps_malloc with MALLOC_CAP_32BIT. Unfortunately
902 // heap_caps_malloc crashes, so we need this workaround.
903 void * realloc32(void * ptr, size_t size);
904 void free32(void * ptr);
905 
906 
907 inline gpio_num_t int2gpio(int gpio)
908 {
909  return gpio == -1 ? GPIO_UNUSED : (gpio_num_t)gpio;
910 }
911 
912 
913 // converts 0..9 -> '0'..'9', 10..15 -> 'a'..'f'
914 inline char digit2hex(int digit)
915 {
916  return digit < 10 ? '0' + digit : 'a' + digit - 10;
917 }
918 
919 
920 // converts '0'..'9' -> 0..9, 'a'..'f' -> 10..15
921 inline int hex2digit(char hex)
922 {
923  return hex < 'a' ? hex - '0' : hex - 'a' + 10;
924 }
925 
926 
927 // milliseconds to FreeRTOS ticks.
928 // ms = -1 => maximum delay (portMAX_DELAY)
929 uint32_t msToTicks(int ms);
930 
931 
935 enum class ChipPackage {
936  Unknown,
937  ESP32D0WDQ6,
938  ESP32D0WDQ5,
939  ESP32D2WDQ5,
940  ESP32PICOD4,
941 };
942 
943 
944 ChipPackage getChipPackage();
945 
946 inline __attribute__((always_inline)) uint32_t getCycleCount() {
947  uint32_t ccount;
948  __asm__ __volatile__(
949  "esync \n\t"
950  "rsr %0, ccount \n\t"
951  : "=a" (ccount)
952  );
953  return ccount;
954 }
955 
962 void replacePathSep(char * path, char newSep);
963 
964 
972 inline uint32_t UARTConf(int parity, int dataLength, int stopBits)
973 {
974  uint32_t w = 0x8000000 | (dataLength << 2) | (stopBits << 4);
975  if (parity)
976  w |= (parity == 1 ? 0b10 : 0b11);
977  return w;
978 }
979 
980 
981 adc1_channel_t ADC1_GPIO2Channel(gpio_num_t gpio);
982 
983 
984 void esp_intr_alloc_pinnedToCore(int source, int flags, intr_handler_t handler, void * arg, intr_handle_t * ret_handle, int core);
985 
986 
987 // mode: GPIO_MODE_DISABLE,
988 // GPIO_MODE_INPUT,
989 // GPIO_MODE_OUTPUT,
990 // GPIO_MODE_OUTPUT_OD (open drain),
991 // GPIO_MODE_INPUT_OUTPUT_OD (open drain),
992 // GPIO_MODE_INPUT_OUTPUT
993 void configureGPIO(gpio_num_t gpio, gpio_mode_t mode);
994 
995 
996 uint32_t getApbFrequency();
997 
998 uint32_t getCPUFrequencyMHz();
999 
1000 
1002 // AutoSemaphore
1003 
1004 struct AutoSemaphore {
1005  AutoSemaphore(SemaphoreHandle_t mutex) : m_mutex(mutex) { xSemaphoreTake(m_mutex, portMAX_DELAY); }
1006  ~AutoSemaphore() { xSemaphoreGive(m_mutex); }
1007 private:
1008  SemaphoreHandle_t m_mutex;
1009 };
1010 
1011 
1012 
1014 // CoreUsage
1015 
1019 struct CoreUsage {
1020 
1021  static int busiestCore() { return s_busiestCore; }
1022  static int quietCore() { return s_busiestCore != -1 ? s_busiestCore ^ 1 : -1; }
1023  static void setBusiestCore(int core) { s_busiestCore = core; }
1024 
1025  private:
1026  static int s_busiestCore; // 0 = core 0, 1 = core 1 (default is FABGLIB_VIDEO_CPUINTENSIVE_TASKS_CORE)
1027 };
1028 
1029 
1031 
1032 
1296  VK_LAST, // marks the last virtual key
1297 
1298 };
1299 
1300 
1306  uint8_t down;
1307  uint8_t scancode[8];
1308  uint8_t ASCII;
1309  uint8_t CTRL : 1;
1310  uint8_t LALT : 1;
1311  uint8_t RALT : 1;
1312  uint8_t SHIFT : 1;
1313  uint8_t GUI : 1;
1314  uint8_t CAPSLOCK : 1;
1315  uint8_t NUMLOCK : 1;
1316  uint8_t SCROLLLOCK : 1;
1317 };
1318 
1319 
1320 
1322 // Virtual keys helpers
1323 
1324 inline bool isSHIFT(VirtualKey value)
1325 {
1326  return value == VK_LSHIFT || value == VK_RSHIFT;
1327 }
1328 
1329 
1330 inline bool isALT(VirtualKey value)
1331 {
1332  return value == VK_LALT || value == VK_RALT;
1333 }
1334 
1335 
1336 inline bool isCTRL(VirtualKey value)
1337 {
1338  return value == VK_LCTRL || value == VK_RCTRL;
1339 }
1340 
1341 
1342 inline bool isGUI(VirtualKey value)
1343 {
1344  return value == VK_LGUI || value == VK_RGUI;
1345 }
1346 
1347 
1348 
1350 // ASCII control characters
1351 
1352 #define ASCII_NUL 0x00 // Null
1353 #define ASCII_SOH 0x01 // Start of Heading
1354 #define ASCII_CTRLA 0x01 // CTRL-A
1355 #define ASCII_STX 0x02 // Start of Text
1356 #define ASCII_CTRLB 0x02 // CTRL-B
1357 #define ASCII_ETX 0x03 // End Of Text
1358 #define ASCII_CTRLC 0x03 // CTRL-C
1359 #define ASCII_EOT 0x04 // End Of Transmission
1360 #define ASCII_CTRLD 0x04 // CTRL-D
1361 #define ASCII_ENQ 0x05 // Enquiry
1362 #define ASCII_CTRLE 0x05 // CTRL-E
1363 #define ASCII_ACK 0x06 // Acknowledge
1364 #define ASCII_CTRLF 0x06 // CTRL-F
1365 #define ASCII_BEL 0x07 // Bell
1366 #define ASCII_CTRLG 0x07 // CTRL-G
1367 #define ASCII_BS 0x08 // Backspace
1368 #define ASCII_CTRLH 0x08 // CTRL-H
1369 #define ASCII_HT 0x09 // Horizontal Tab
1370 #define ASCII_TAB 0x09 // Horizontal Tab
1371 #define ASCII_CTRLI 0x09 // CTRL-I
1372 #define ASCII_LF 0x0A // Line Feed
1373 #define ASCII_CTRLJ 0x0A // CTRL-J
1374 #define ASCII_VT 0x0B // Vertical Tab
1375 #define ASCII_CTRLK 0x0B // CTRL-K
1376 #define ASCII_FF 0x0C // Form Feed
1377 #define ASCII_CTRLL 0x0C // CTRL-L
1378 #define ASCII_CR 0x0D // Carriage Return
1379 #define ASCII_CTRLM 0x0D // CTRL-M
1380 #define ASCII_SO 0x0E // Shift Out
1381 #define ASCII_CTRLN 0x0E // CTRL-N
1382 #define ASCII_SI 0x0F // Shift In
1383 #define ASCII_CTRLO 0x0F // CTRL-O
1384 #define ASCII_DLE 0x10 // Data Link Escape
1385 #define ASCII_CTRLP 0x10 // CTRL-P
1386 #define ASCII_DC1 0x11 // Device Control 1
1387 #define ASCII_CTRLQ 0x11 // CTRL-Q
1388 #define ASCII_XON 0x11 // Transmission On
1389 #define ASCII_DC2 0x12 // Device Control 2
1390 #define ASCII_CTRLR 0x12 // CTRL-R
1391 #define ASCII_DC3 0x13 // Device Control 3
1392 #define ASCII_XOFF 0x13 // Transmission Off
1393 #define ASCII_CTRLS 0x13 // CTRL-S
1394 #define ASCII_DC4 0x14 // Device Control 4
1395 #define ASCII_CTRLT 0x14 // CTRL-T
1396 #define ASCII_NAK 0x15 // Negative Acknowledge
1397 #define ASCII_CTRLU 0x15 // CTRL-U
1398 #define ASCII_SYN 0x16 // Synchronous Idle
1399 #define ASCII_CTRLV 0x16 // CTRL-V
1400 #define ASCII_ETB 0x17 // End-of-Transmission-Block
1401 #define ASCII_CTRLW 0x17 // CTRL-W
1402 #define ASCII_CAN 0x18 // Cancel
1403 #define ASCII_CTRLX 0x18 // CTRL-X
1404 #define ASCII_EM 0x19 // End of Medium
1405 #define ASCII_CTRLY 0x19 // CTRL-Y
1406 #define ASCII_SUB 0x1A // Substitute
1407 #define ASCII_CTRLZ 0x1A // CTRL-Z
1408 #define ASCII_ESC 0x1B // Escape
1409 #define ASCII_FS 0x1C // File Separator
1410 #define ASCII_GS 0x1D // Group Separator
1411 #define ASCII_RS 0x1E // Record Separator
1412 #define ASCII_US 0x1F // Unit Separator
1413 #define ASCII_SPC 0x20 // Space
1414 #define ASCII_DEL 0x7F // Delete
1415 
1416 
1417 } // end of namespace
1418 
1419 
1420 
MouseButtons buttons
Definition: fabutils.h:281
int16_t Y1
Definition: fabutils.h:228
char const * name
Definition: fabutils.h:513
uint32_t UARTConf(int parity, int dataLength, int stopBits)
Composes UART configuration word.
Definition: fabutils.h:972
int16_t width
Definition: fabutils.h:178
int16_t Y
Definition: fabutils.h:193
bool truncate(char const *name, size_t size)
Truncates a file to the specified size.
Definition: fabutils.cpp:1045
void rename(char const *oldName, char const *newName)
Renames a file.
Definition: fabutils.cpp:1017
bool filePathExists(char const *filepath)
Determines if a file exists.
Definition: fabutils.cpp:760
uint8_t const * data
int16_t X
Definition: fabutils.h:192
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
uint8_t B
A struct which contains a virtual key, key state and associated scan code.
Definition: fabutils.h:1304
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
Definition: fabutils.h:1036
int16_t X1
Definition: fabutils.h:227
size_t fileSize(char const *name)
Determines file size.
Definition: fabutils.cpp:769
This class helps to choice a core for intensive processing tasks.
Definition: fabutils.h:1019
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
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: fabutils.h:277
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
static void unmountSDCard()
Unmounts filesystem on SD Card.
Definition: fabutils.cpp:1258
uint8_t G
Represents the coordinate of a point.
Definition: fabutils.h:191
Definition: canvas.cpp:36
FileBrowser item specificator.
Definition: fabutils.h:511
char * createTempFilename()
Creates a random temporary filename, with absolute path.
Definition: fabutils.cpp:1030
int getFullPath(char const *name, char *outPath=nullptr, int maxlen=0)
Composes a full file path given a relative name.
Definition: fabutils.cpp:1095
int16_t Y2
Definition: fabutils.h:230
DriveType getCurrentDriveType()
Returns the drive type of current directory.
Definition: fabutils.cpp:1114
static bool format(DriveType driveType, int drive)
Formats SPIFFS or SD Card.
Definition: fabutils.cpp:1132
DriveType
This enum defines drive types (SPIFFS or SD Card)
Definition: fabutils.h:520
Represents a rectangle.
Definition: fabutils.h:226
int16_t width
Definition: fabutils.h:210
Describes mouse buttons status.
Definition: fabutils.h:264
uint8_t R
int16_t height
Definition: fabutils.h:211
static bool remountSDCard()
Remounts SDCard filesystem, using the same parameters.
Definition: fabutils.cpp:1271
char const * directory()
Determines absolute path of current directory.
Definition: fabutils.h:569
void setSorted(bool value)
Determines if the items are sorted.
ChipPackage
This enum defines ESP32 module types (packages)
Definition: fabutils.h:935
uint8_t scancode[8]
Definition: fabutils.h:1307
Represents a bidimensional size.
Definition: fabutils.h:209
void makeDirectory(char const *dirname)
Creates a directory.
Definition: fabutils.cpp:937
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
static DriveType getDriveType(char const *path)
Returns the drive type of specified path.
Definition: fabutils.cpp:1120
int16_t X2
Definition: fabutils.h:229
void changeDirectory(const char *subdir)
Sets relative directory path.
Definition: fabutils.cpp:682
int16_t height
Definition: fabutils.h:179
FILE * openFile(char const *filename, char const *mode)
Opens a file from current directory.
Definition: fabutils.cpp:1101
static bool mountSPIFFS(bool formatOnFail, char const *mountPath, size_t maxFiles=4)
Mounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1278
bool exists(char const *name, bool caseSensitive=true)
Determines if a file or directory exists.
Definition: fabutils.cpp:745
int count()
Determines number of files in current directory.
Definition: fabutils.h:576
bool reload()
Reloads directory content.
Definition: fabutils.cpp:850
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
static bool remountSPIFFS()
Remounts SPIFFS filesystem, using the same parameters.
Definition: fabutils.cpp:1302
static void unmountSPIFFS()
Unmounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1293
FileBrowser allows basic file system operations (dir, mkdir, remove and rename)
Definition: fabutils.h:532