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-2020 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 
40 
41 namespace fabgl {
42 
43 
44 
45 #define GPIO_UNUSED GPIO_NUM_MAX
46 
47 
49 // PSRAM_HACK
50 // ESP32 Revision 1 has following bug: "When the CPU accesses external SRAM through cache, under certain conditions read and write errors occur"
51 // A workaround is done by the compiler, so whenever PSRAM is enabled the workaround is automatically applied (-mfix-esp32-psram-cache-issue compiler option).
52 // Unfortunately this workaround reduces performance, even when SRAM is not access, like in VGAXController interrupt handler. This is unacceptable for the interrupt routine.
53 // In order to confuse the compiler and prevent the workaround from being applied, a "nop" is added between load and store instructions (PSRAM_HACK).
54 
55 #ifdef ARDUINO
56  #ifdef BOARD_HAS_PSRAM
57  #define FABGL_NEED_PSRAM_DISABLE_HACK
58  #endif
59 #else
60  #ifdef CONFIG_SPIRAM_SUPPORT
61  #define FABGL_NEED_PSRAM_DISABLE_HACK
62  #endif
63 #endif
64 
65 #ifdef FABGL_NEED_PSRAM_DISABLE_HACK
66  #define PSRAM_HACK asm(" nop")
67 #else
68  #define PSRAM_HACK
69 #endif
70 
71 
72 
74 
75 
76 // Integer square root by Halleck's method, with Legalize's speedup
77 int isqrt (int x);
78 
79 
80 template <typename T>
81 const T & tmax(const T & a, const T & b)
82 {
83  return (a < b) ? b : a;
84 }
85 
86 
87 constexpr auto imax = tmax<int>;
88 
89 
90 template <typename T>
91 const T & tmin(const T & a, const T & b)
92 {
93  return !(b < a) ? a : b;
94 }
95 
96 
97 constexpr auto imin = tmin<int>;
98 
99 
100 
101 template <typename T>
102 const T & tclamp(const T & v, const T & lo, const T & hi)
103 {
104  return (v < lo ? lo : (v > hi ? hi : v));
105 }
106 
107 
108 constexpr auto iclamp = tclamp<int>;
109 
110 
111 template <typename T>
112 const T & twrap(const T & v, const T & lo, const T & hi)
113 {
114  return (v < lo ? hi : (v > hi ? lo : v));
115 }
116 
117 
118 template <typename T>
119 void tswap(T & v1, T & v2)
120 {
121  T t = v1;
122  v1 = v2;
123  v2 = t;
124 }
125 
126 
127 constexpr auto iswap = tswap<int>;
128 
129 
130 template <typename T>
131 T moveItems(T dest, T src, size_t n)
132 {
133  T pd = dest;
134  T ps = src;
135  if (pd != ps) {
136  if (ps < pd)
137  for (pd += n, ps += n; n--;)
138  *--pd = *--ps;
139  else
140  while (n--)
141  *pd++ = *ps++;
142  }
143  return dest;
144 }
145 
146 
147 void rgb222_to_hsv(int R, int G, int B, double * h, double * s, double * v);
152 
158 struct Point {
159  int16_t X;
160  int16_t Y;
162  Point() : X(0), Y(0) { }
163  Point(int X_, int Y_) : X(X_), Y(Y_) { }
164 
165  Point add(Point const & p) const { return Point(X + p.X, Y + p.Y); }
166  Point sub(Point const & p) const { return Point(X - p.X, Y - p.Y); }
167  Point neg() const { return Point(-X, -Y); }
168  bool operator==(Point const & r) { return X == r.X && Y == r.Y; }
169  bool operator!=(Point const & r) { return X != r.X || Y != r.Y; }
170 } __attribute__ ((packed));
171 
172 
176 struct Size {
177  int16_t width;
178  int16_t height;
180  Size() : width(0), height(0) { }
181  Size(int width_, int height_) : width(width_), height(height_) { }
182 } __attribute__ ((packed));
183 
184 
185 
191 struct Rect {
192  int16_t X1;
193  int16_t Y1;
194  int16_t X2;
195  int16_t Y2;
197  Rect() : X1(0), Y1(0), X2(0), Y2(0) { }
198  Rect(int X1_, int Y1_, int X2_, int Y2_) : X1(X1_), Y1(Y1_), X2(X2_), Y2(Y2_) { }
199  Rect(Rect const & r) { X1 = r.X1; Y1 = r.Y1; X2 = r.X2; Y2 = r.Y2; }
200 
201  bool operator==(Rect const & r) { return X1 == r.X1 && Y1 == r.Y1 && X2 == r.X2 && Y2 == r.Y2; }
202  bool operator!=(Rect const & r) { return X1 != r.X1 || Y1 != r.Y1 || X2 != r.X2 || Y2 != r.Y2; }
203  Point pos() const { return Point(X1, Y1); }
204  Size size() const { return Size(X2 - X1 + 1, Y2 - Y1 + 1); }
205  int width() const { return X2 - X1 + 1; }
206  int height() const { return Y2 - Y1 + 1; }
207  Rect translate(int offsetX, int offsetY) const { return Rect(X1 + offsetX, Y1 + offsetY, X2 + offsetX, Y2 + offsetY); }
208  Rect translate(Point const & offset) const { return Rect(X1 + offset.X, Y1 + offset.Y, X2 + offset.X, Y2 + offset.Y); }
209  Rect move(Point const & position) const { return Rect(position.X, position.Y, position.X + width() - 1, position.Y + height() - 1); }
210  Rect move(int x, int y) const { return Rect(x, y, x + width() - 1, y + height() - 1); }
211  Rect shrink(int value) const { return Rect(X1 + value, Y1 + value, X2 - value, Y2 - value); }
212  Rect hShrink(int value) const { return Rect(X1 + value, Y1, X2 - value, Y2); }
213  Rect vShrink(int value) const { return Rect(X1, Y1 + value, X2, Y2 - value); }
214  Rect resize(int width, int height) const { return Rect(X1, Y1, X1 + width - 1, Y1 + height - 1); }
215  Rect resize(Size size) const { return Rect(X1, Y1, X1 + size.width - 1, Y1 + size.height - 1); }
216  Rect intersection(Rect const & rect) const;
217  bool intersects(Rect const & rect) const { return X1 <= rect.X2 && X2 >= rect.X1 && Y1 <= rect.Y2 && Y2 >= rect.Y1; }
218  bool contains(Rect const & rect) const { return (rect.X1 >= X1) && (rect.Y1 >= Y1) && (rect.X2 <= X2) && (rect.Y2 <= Y2); }
219  bool contains(Point const & point) const { return point.X >= X1 && point.Y >= Y1 && point.X <= X2 && point.Y <= Y2; }
220  bool contains(int x, int y) const { return x >= X1 && y >= Y1 && x <= X2 && y <= Y2; }
221  Rect merge(Rect const & rect) const;
222 } __attribute__ ((packed));
223 
224 
225 
229 struct MouseButtons {
230  uint8_t left : 1;
231  uint8_t middle : 1;
232  uint8_t right : 1;
234  MouseButtons() : left(0), middle(0), right(0) { }
235 };
236 
237 
238 
242 struct MouseStatus {
243  int16_t X;
244  int16_t Y;
245  int8_t wheelDelta;
248  MouseStatus() : X(0), Y(0), wheelDelta(0) { }
249 };
250 
251 
252 
253 #define FONTINFOFLAGS_ITALIC 1
254 #define FONTINFOFLAGS_UNDERLINE 2
255 #define FONTINFODLAFS_STRIKEOUT 4
256 #define FONTINFOFLAGS_VARWIDTH 8
257 
258 
259 struct FontInfo {
260  uint8_t pointSize;
261  uint8_t width; // used only for fixed width fonts (FONTINFOFLAGS_VARWIDTH = 0)
262  uint8_t height;
263  uint8_t ascent;
264  uint8_t inleading;
265  uint8_t exleading;
266  uint8_t flags;
267  uint16_t weight;
268  uint16_t charset;
269  // when FONTINFOFLAGS_VARWIDTH = 0:
270  // data[] contains 256 items each one representing a single character
271  // when FONTINFOFLAGS_VARWIDTH = 1:
272  // data[] contains 256 items each one representing a single character. First byte contains the
273  // character width. "chptr" is filled with an array of pointers to the single characters.
274  uint8_t const * data;
275  uint32_t const * chptr; // used only for variable width fonts (FONTINFOFLAGS_VARWIDTH = 1)
276 };
277 
278 
279 
280 
282 // TimeOut
283 
284 
285 struct TimeOut {
286  TimeOut();
287 
288  // -1 means "infinite", never times out
289  bool expired(int valueMS);
290 
291 private:
292  int64_t m_start;
293 };
294 
295 
296 
298 // Stack
299 
300 
301 template <typename T>
302 struct StackItem {
303  StackItem * next;
304  T item;
305  StackItem(StackItem * next_, T const & item_) : next(next_), item(item_) { }
306 };
307 
308 template <typename T>
309 class Stack {
310 public:
311  Stack() : m_items(nullptr) { }
312  bool isEmpty() { return m_items == nullptr; }
313  void push(T const & value) {
314  m_items = new StackItem<T>(m_items, value);
315  }
316  T pop() {
317  if (m_items) {
318  StackItem<T> * iptr = m_items;
319  m_items = iptr->next;
320  T r = iptr->item;
321  delete iptr;
322  return r;
323  } else
324  return T();
325  }
326  int count() {
327  int r = 0;
328  for (auto i = m_items; i; i = i->next)
329  ++r;
330  return r;
331  }
332 private:
333  StackItem<T> * m_items;
334 };
335 
336 
337 
339 // Delegate
340 
341 template <typename ...Params>
342 struct Delegate {
343 
344  template <typename Func>
345  void operator=(Func f) {
346  m_closure = [] (void * func, const Params & ...params) -> void { (*(Func *)func)(params...); };
347  m_func = heap_caps_malloc(sizeof(Func), MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
348  moveItems<uint32_t*>((uint32_t*)m_func, (uint32_t*)&f, sizeof(Func) / sizeof(uint32_t));
349  }
350 
351  ~Delegate() {
352  heap_caps_free(m_func);
353  }
354 
355  void operator()(const Params & ...params) {
356  if (m_func)
357  m_closure(m_func, params...);
358  }
359 
360 private:
361  void (*m_closure)(void * func, const Params & ...params);
362  void * m_func = nullptr;
363 };
364 
365 
366 
368 // StringList
369 
370 class StringList {
371 
372 public:
373  StringList();
374  ~StringList();
375  int append(char const * str);
376  int appendFmt(const char *format, ...);
377  void append(char const * strlist[], int count);
378  void insert(int index, char const * str);
379  void set(int index, char const * str);
380  void remove(int index);
381  int count() { return m_count; }
382  char const * get(int index) { return m_items[index]; }
383  void clear();
384  void takeStrings();
385  void select(int index, bool value);
386  void deselectAll();
387  bool selected(int index);
388  void copyFrom(StringList const & src);
389 
390 private:
391  void checkAllocatedSpace(int requiredItems);
392 
393  char const * * m_items;
394 
395  // each 32 bit word can select up to 32 items, one bit per item
396  uint32_t * m_selMap;
397 
398  // If true (default is false) all strings added (append/insert/set) are copied.
399  // Strings will be released when no more used (destructor, clear(), etc...).
400  // This flag is permanently switched to True by takeStrings() call.
401  bool m_ownStrings;
402 
403  uint16_t m_count; // actual items
404  uint16_t m_allocated; // allocated items
405 
406 };
407 
408 
410 // LightMemoryPool
411 // Each allocated block starts with a two bytes header (int16_t). Bit 15 is allocation flag (0=free, 1=allocated).
412 // Bits 14..0 represent the block size.
413 // The maximum size of a block is 32767 bytes.
414 // free() just marks the block header as free.
415 
416 class LightMemoryPool {
417 public:
418  LightMemoryPool(int poolSize);
419  ~LightMemoryPool();
420  void * alloc(int size);
421  void free(void * mem) { if (mem) markFree((uint8_t*)mem - m_mem - 2); }
422 
423  bool memCheck();
424  int totFree(); // get total free memory
425  int totAllocated(); // get total allocated memory
426  int largestFree();
427 
428 private:
429 
430  void mark(int pos, int16_t size, bool allocated);
431  void markFree(int pos) { m_mem[pos + 1] &= 0x7f; }
432  int16_t getSize(int pos);
433  bool isFree(int pos);
434 
435  uint8_t * m_mem;
436  int m_poolSize;
437 };
438 
439 
440 
442 // FileBrowser
443 
444 
448 struct DirItem {
449  bool isDir;
450  char const * name;
451 };
452 
453 
457 enum class DriveType {
458  None,
459  SPIFFS,
460  SDCard,
461 };
462 
463 
469 class FileBrowser {
470 public:
471 
472  FileBrowser();
473  ~FileBrowser();
474 
482  bool setDirectory(const char * path);
483 
489  void changeDirectory(const char * subdir);
490 
496  bool reload();
497 
503  char const * directory() { return m_dir; }
504 
510  int count() { return m_count; }
511 
519  DirItem const * get(int index) { return m_items + index; }
520 
529  bool exists(char const * name, bool caseSensitive = true);
530 
538  size_t fileSize(char const * name);
539 
553  bool fileCreationDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
554 
568  bool fileUpdateDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
569 
583  bool fileAccessDate(char const * name, int * year, int * month, int * day, int * hour, int * minutes, int * seconds);
584 
590  void setSorted(bool value);
591 
592  void setIncludeHiddenFiles(bool value) { m_includeHiddenFiles = value; }
593 
599  void makeDirectory(char const * dirname);
600 
608  void remove(char const * name);
609 
616  void rename(char const * oldName, char const * newName);
617 
626  bool truncate(char const * name, size_t size);
627 
633  char * createTempFilename();
634 
644  int getFullPath(char const * name, char * outPath = nullptr, int maxlen = 0);
645 
654  FILE * openFile(char const * filename, char const * mode);
655 
662 
670  static DriveType getDriveType(char const * path);
671 
689  static bool format(DriveType driveType, int drive);
690 
710  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);
711 
717  static bool remountSDCard();
718 
722  static void unmountSDCard();
723 
738  static bool mountSPIFFS(bool formatOnFail, char const * mountPath, size_t maxFiles = 4);
739 
745  static bool remountSPIFFS();
746 
750  static void unmountSPIFFS();
751 
774  static bool getFSInfo(DriveType driveType, int drive, int64_t * total, int64_t * used);
775 
776 private:
777 
778  void clear();
779  int countDirEntries(int * namesLength);
780 
781  // SPIFFS static infos
782  static bool s_SPIFFSMounted;
783  static char const * s_SPIFFSMountPath;
784  static size_t s_SPIFFSMaxFiles;
785 
786  // SD Card static infos
787  static bool s_SDCardMounted;
788  static char const * s_SDCardMountPath;
789  static size_t s_SDCardMaxFiles;
790  static int s_SDCardAllocationUnitSize;
791  static int8_t s_SDCardMISO;
792  static int8_t s_SDCardMOSI;
793  static int8_t s_SDCardCLK;
794  static int8_t s_SDCardCS;
795 
796  char * m_dir;
797  int m_count;
798  DirItem * m_items;
799  bool m_sorted;
800  bool m_includeHiddenFiles;
801  char * m_namesStorage;
802 };
803 
804 
805 
806 
808 
809 
810 
811 bool clipLine(int & x1, int & y1, int & x2, int & y2, Rect const & clipRect, bool checkOnly);
812 
813 
814 void removeRectangle(Stack<Rect> & rects, Rect const & mainRect, Rect const & rectToRemove);
815 
816 
817 bool calcParity(uint8_t v);
818 
819 // why these? this is like heap_caps_malloc with MALLOC_CAP_32BIT. Unfortunately
820 // heap_caps_malloc crashes, so we need this workaround.
821 void * realloc32(void * ptr, size_t size);
822 void free32(void * ptr);
823 
824 
825 inline gpio_num_t int2gpio(int gpio)
826 {
827  return gpio == -1 ? GPIO_UNUSED : (gpio_num_t)gpio;
828 }
829 
830 
831 // converts 0..9 -> '0'..'9', 10..15 -> 'a'..'f'
832 inline char digit2hex(int digit)
833 {
834  return digit < 10 ? '0' + digit : 'a' + digit - 10;
835 }
836 
837 
838 // converts '0'..'9' -> 0..9, 'a'..'f' -> 10..15
839 inline int hex2digit(char hex)
840 {
841  return hex < 'a' ? hex - '0' : hex - 'a' + 10;
842 }
843 
844 
845 // milliseconds to FreeRTOS ticks.
846 // ms = -1 => maximum delay (portMAX_DELAY)
847 uint32_t msToTicks(int ms);
848 
849 
850 enum class ChipPackage {
851  Unknown,
852  ESP32D0WDQ6,
853  ESP32D0WDQ5,
854  ESP32D2WDQ5,
855  ESP32PICOD4,
856 };
857 
858 
859 ChipPackage getChipPackage();
860 
861 inline __attribute__((always_inline)) uint32_t getCycleCount() {
862  uint32_t ccount;
863  __asm__ __volatile__(
864  "esync \n\t"
865  "rsr %0, ccount \n\t"
866  : "=a" (ccount)
867  );
868  return ccount;
869 }
870 
877 void replacePathSep(char * path, char newSep);
878 
879 
887 inline uint32_t UARTConf(int parity, int dataLength, int stopBits)
888 {
889  uint32_t w = 0x8000000 | (dataLength << 2) | (stopBits << 4);
890  if (parity)
891  w |= (parity == 1 ? 0b10 : 0b11);
892  return w;
893 }
894 
895 
896 adc1_channel_t ADC1_GPIO2Channel(gpio_num_t gpio);
897 
898 
899 void esp_intr_alloc_pinnedToCore(int source, int flags, intr_handler_t handler, void * arg, intr_handle_t * ret_handle, int core);
900 
901 
902 // mode: GPIO_MODE_DISABLE,
903 // GPIO_MODE_INPUT,
904 // GPIO_MODE_OUTPUT,
905 // GPIO_MODE_OUTPUT_OD (open drain),
906 // GPIO_MODE_INPUT_OUTPUT_OD (open drain),
907 // GPIO_MODE_INPUT_OUTPUT
908 void configureGPIO(gpio_num_t gpio, gpio_mode_t mode);
909 
910 
911 uint32_t getApbFrequency();
912 
913 uint32_t getCPUFrequencyMHz();
914 
915 
917 // AutoSemaphore
918 
919 struct AutoSemaphore {
920  AutoSemaphore(SemaphoreHandle_t mutex) : m_mutex(mutex) { xSemaphoreTake(m_mutex, portMAX_DELAY); }
921  ~AutoSemaphore() { xSemaphoreGive(m_mutex); }
922 private:
923  SemaphoreHandle_t m_mutex;
924 };
925 
926 
927 
929 // CoreUsage
930 
934 struct CoreUsage {
935 
936  static int busiestCore() { return s_busiestCore; }
937  static int quietCore() { return s_busiestCore != -1 ? s_busiestCore ^ 1 : -1; }
938  static void setBusiestCore(int core) { s_busiestCore = core; }
939 
940  private:
941  static int s_busiestCore; // -1 = none, 0 = core 0, 1 = core 1
942 };
943 
944 
946 
947 
1148  // For spanish keyboard layout
1149 
1200  VK_LAST, // marks the last virtual key
1201 };
1202 
1203 
1205 // ASCII control characters
1206 
1207 #define ASCII_NUL 0x00 // Null
1208 #define ASCII_SOH 0x01 // Start of Heading
1209 #define ASCII_CTRLA 0x01 // CTRL-A
1210 #define ASCII_STX 0x02 // Start of Text
1211 #define ASCII_CTRLB 0x02 // CTRL-B
1212 #define ASCII_ETX 0x03 // End Of Text
1213 #define ASCII_CTRLC 0x03 // CTRL-C
1214 #define ASCII_EOT 0x04 // End Of Transmission
1215 #define ASCII_CTRLD 0x04 // CTRL-D
1216 #define ASCII_ENQ 0x05 // Enquiry
1217 #define ASCII_CTRLE 0x05 // CTRL-E
1218 #define ASCII_ACK 0x06 // Acknowledge
1219 #define ASCII_CTRLF 0x06 // CTRL-F
1220 #define ASCII_BEL 0x07 // Bell
1221 #define ASCII_CTRLG 0x07 // CTRL-G
1222 #define ASCII_BS 0x08 // Backspace
1223 #define ASCII_CTRLH 0x08 // CTRL-H
1224 #define ASCII_HT 0x09 // Horizontal Tab
1225 #define ASCII_TAB 0x09 // Horizontal Tab
1226 #define ASCII_CTRLI 0x09 // CTRL-I
1227 #define ASCII_LF 0x0A // Line Feed
1228 #define ASCII_CTRLJ 0x0A // CTRL-J
1229 #define ASCII_VT 0x0B // Vertical Tab
1230 #define ASCII_CTRLK 0x0B // CTRL-K
1231 #define ASCII_FF 0x0C // Form Feed
1232 #define ASCII_CTRLL 0x0C // CTRL-L
1233 #define ASCII_CR 0x0D // Carriage Return
1234 #define ASCII_CTRLM 0x0D // CTRL-M
1235 #define ASCII_SO 0x0E // Shift Out
1236 #define ASCII_CTRLN 0x0E // CTRL-N
1237 #define ASCII_SI 0x0F // Shift In
1238 #define ASCII_CTRLO 0x0F // CTRL-O
1239 #define ASCII_DLE 0x10 // Data Link Escape
1240 #define ASCII_CTRLP 0x10 // CTRL-P
1241 #define ASCII_DC1 0x11 // Device Control 1
1242 #define ASCII_CTRLQ 0x11 // CTRL-Q
1243 #define ASCII_XON 0x11 // Transmission On
1244 #define ASCII_DC2 0x12 // Device Control 2
1245 #define ASCII_CTRLR 0x12 // CTRL-R
1246 #define ASCII_DC3 0x13 // Device Control 3
1247 #define ASCII_XOFF 0x13 // Transmission Off
1248 #define ASCII_CTRLS 0x13 // CTRL-S
1249 #define ASCII_DC4 0x14 // Device Control 4
1250 #define ASCII_CTRLT 0x14 // CTRL-T
1251 #define ASCII_NAK 0x15 // Negative Acknowledge
1252 #define ASCII_CTRLU 0x15 // CTRL-U
1253 #define ASCII_SYN 0x16 // Synchronous Idle
1254 #define ASCII_CTRLV 0x16 // CTRL-V
1255 #define ASCII_ETB 0x17 // End-of-Transmission-Block
1256 #define ASCII_CTRLW 0x17 // CTRL-W
1257 #define ASCII_CAN 0x18 // Cancel
1258 #define ASCII_CTRLX 0x18 // CTRL-X
1259 #define ASCII_EM 0x19 // End of Medium
1260 #define ASCII_CTRLY 0x19 // CTRL-Y
1261 #define ASCII_SUB 0x1A // Substitute
1262 #define ASCII_CTRLZ 0x1A // CTRL-Z
1263 #define ASCII_ESC 0x1B // Escape
1264 #define ASCII_FS 0x1C // File Separator
1265 #define ASCII_GS 0x1D // Group Separator
1266 #define ASCII_RS 0x1E // Record Separator
1267 #define ASCII_US 0x1F // Unit Separator
1268 #define ASCII_SPC 0x20 // Space
1269 #define ASCII_DEL 0x7F // Delete
1270 
1271 
1272 } // end of namespace
1273 
1274 
1275 
MouseButtons buttons
Definition: fabutils.h:246
int16_t Y1
Definition: fabutils.h:193
char const * name
Definition: fabutils.h:450
uint32_t UARTConf(int parity, int dataLength, int stopBits)
Composes UART configuration word.
Definition: fabutils.h:887
int16_t width
Definition: fabutils.h:148
int16_t Y
Definition: fabutils.h:160
bool truncate(char const *name, size_t size)
Truncates a file to the specified size.
Definition: fabutils.cpp:981
void rename(char const *oldName, char const *newName)
Renames a file.
Definition: fabutils.cpp:953
uint8_t const * data
int16_t X
Definition: fabutils.h:159
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:1115
bool setDirectory(const char *path)
Sets absolute directory path.
Definition: fabutils.cpp:614
uint8_t B
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
Definition: fabutils.h:951
int16_t X1
Definition: fabutils.h:192
size_t fileSize(char const *name)
Determines file size.
Definition: fabutils.cpp:705
This class helps to choice a core for intensive processing tasks.
Definition: fabutils.h:934
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:738
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: fabutils.h:242
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:720
static void unmountSDCard()
Unmounts filesystem on SD Card.
Definition: fabutils.cpp:1146
uint8_t G
Represents the coordinate of a point.
Definition: fabutils.h:158
Definition: canvas.cpp:31
FileBrowser item specificator.
Definition: fabutils.h:448
char * createTempFilename()
Creates a random temporary filename, with absolute path.
Definition: fabutils.cpp:966
int getFullPath(char const *name, char *outPath=nullptr, int maxlen=0)
Composes a full file path given a relative name.
Definition: fabutils.cpp:1031
int16_t Y2
Definition: fabutils.h:195
DriveType getCurrentDriveType()
Returns the drive type of current directory.
Definition: fabutils.cpp:1050
static bool format(DriveType driveType, int drive)
Formats SPIFFS or SD Card.
Definition: fabutils.cpp:1068
DriveType
This enum defines drive types (SPIFFS or SD Card)
Definition: fabutils.h:457
Represents a rectangle.
Definition: fabutils.h:191
int16_t width
Definition: fabutils.h:177
Describes mouse buttons status.
Definition: fabutils.h:229
uint8_t R
int16_t height
Definition: fabutils.h:178
static bool remountSDCard()
Remounts SDCard filesystem, using the same parameters.
Definition: fabutils.cpp:1155
char const * directory()
Determines absolute path of current directory.
Definition: fabutils.h:503
void setSorted(bool value)
Determines if the items are sorted.
Represents a bidimensional size.
Definition: fabutils.h:176
void makeDirectory(char const *dirname)
Creates a directory.
Definition: fabutils.cpp:873
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:756
static DriveType getDriveType(char const *path)
Returns the drive type of specified path.
Definition: fabutils.cpp:1056
int16_t X2
Definition: fabutils.h:194
void changeDirectory(const char *subdir)
Sets relative directory path.
Definition: fabutils.cpp:627
int16_t height
Definition: fabutils.h:149
FILE * openFile(char const *filename, char const *mode)
Opens a file from current directory.
Definition: fabutils.cpp:1037
static bool mountSPIFFS(bool formatOnFail, char const *mountPath, size_t maxFiles=4)
Mounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1162
bool exists(char const *name, bool caseSensitive=true)
Determines if a file or directory exists.
Definition: fabutils.cpp:690
int count()
Determines number of files in current directory.
Definition: fabutils.h:510
bool reload()
Reloads directory content.
Definition: fabutils.cpp:786
static bool getFSInfo(DriveType driveType, int drive, int64_t *total, int64_t *used)
Gets total and free space on a filesystem.
Definition: fabutils.cpp:1193
static bool remountSPIFFS()
Remounts SPIFFS filesystem, using the same parameters.
Definition: fabutils.cpp:1186
static void unmountSPIFFS()
Unmounts filesystem on SPIFFS (Flash)
Definition: fabutils.cpp:1177
FileBrowser allows basic file system operations (dir, mkdir, remove and rename)
Definition: fabutils.h:469