| TGX 1.0.7 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
tgx_config.h
Go to the documentation of this file.
1
5//
6// Copyright 2020 Arvind Singh
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11//version 2.1 of the License, or (at your option) any later version.
12//
13// This library 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 GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; If not, see <http://www.gnu.org/licenses/>.
20
21
22
23// disable mtools extensions by default
24#ifndef MTOOLS_TGX_EXTENSIONS
25#define MTOOLS_TGX_EXTENSIONS 0
26#endif
27
28#ifdef ARDUINO
29 #include <Arduino.h>
30 #define TGX_ON_ARDUINO
31#elif defined(ESP_PLATFORM)
32 #include "sdkconfig.h"
33#endif
34
35#ifndef PROGMEM
36 #define PROGMEM
37#endif
38
39#ifndef FLASHMEM
40 #define FLASHMEM
41#endif
42
43
44
45//
46// Board specific optimizations.
47//
48// - TGX_PROGMEM_DEFAULT_CACHE_SIZE : size of the cache when reading from PROGMEM. Use to optimize cache read when accesing image in flash.
49//
50// - TGX_USE_FAST_INV_SQRT_TRICK : fast inverse 'quake like' square root trick to speed up computations.
51// - TGX_USE_FAST_SQRT_TRICK : fast 'quake like' square root trick to speed up computations.
52// - TGX_USE_FAST_INV_TRICK : fast inverse 'quake like' trick to speed up computations.
53//
54// - TGX_INLINE/TGX_NOINLINE : inlining strategy for time critical/non-critical functions.
55//
56#if defined(_WIN32) || defined(_WIN64) || defined(__linux__) || defined(__APPLE__) || defined(__MACH__) || defined(__ANDROID__) || defined(__unix__)
57 // TGX is running on a computer.
58 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 262144
59 #define TGX_USE_FAST_INV_SQRT_TRICK 0
60 #define TGX_USE_FAST_SQRT_TRICK 0
61 #define TGX_USE_FAST_INV_TRICK 0
62 #define TGX_INLINE
63 #define TGX_NOINLINE
64
65#elif defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
66 // teensy 4.0 and 4.1
67 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 8192
68 #define TGX_USE_FAST_INV_SQRT_TRICK 1
69 #define TGX_USE_FAST_SQRT_TRICK 1
70 #define TGX_USE_FAST_INV_TRICK 1
71 #define TGX_INLINE __attribute__((always_inline))
72 #define TGX_NOINLINE __attribute__((noinline, noclone)) FLASHMEM
73
74#elif defined(ARDUINO_TEENSY36)
75 // teensy 3.6
76 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
77 #define TGX_USE_FAST_INV_SQRT_TRICK 1
78 #define TGX_USE_FAST_SQRT_TRICK 0
79 #define TGX_USE_FAST_INV_TRICK 0
80 #define TGX_INLINE __attribute__((always_inline))
81 #define TGX_NOINLINE
82
83#elif defined(ARDUINO_TEENSY35)
84 // teensy 3.5
85 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
86 #define TGX_USE_FAST_INV_SQRT_TRICK 1
87 #define TGX_USE_FAST_SQRT_TRICK 0
88 #define TGX_USE_FAST_INV_TRICK 0
89 #define TGX_INLINE __attribute__((always_inline))
90 #define TGX_NOINLINE
91
92#elif defined(ARDUINO_TEENSY32) || defined(ARDUINO_TEENSY31)
93 // teensy 3.1 and 3.2
94 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
95 #define TGX_USE_FAST_INV_SQRT_TRICK 1
96 #define TGX_USE_FAST_SQRT_TRICK 0
97 #define TGX_USE_FAST_INV_TRICK 0
98 #define TGX_INLINE __attribute__((always_inline))
99 #define TGX_NOINLINE
100
101#elif defined(ARDUINO_TEENSYLC)
102 // teensy LC
103 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 256
104 #define TGX_USE_FAST_INV_SQRT_TRICK 0
105 #define TGX_USE_FAST_SQRT_TRICK 0
106 #define TGX_USE_FAST_INV_TRICK 0
107 #define TGX_INLINE
108 #define TGX_NOINLINE
109
110#elif defined(ARDUINO_ARCH_RP2350) || defined(PICO_RP2350)
111 // Raspberry Pico 2350
112 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
113 #define TGX_USE_FAST_INV_SQRT_TRICK 1
114 #define TGX_USE_FAST_SQRT_TRICK 1
115 #define TGX_USE_FAST_INV_TRICK 1
116 #define TGX_INLINE __attribute__((always_inline))
117 #define TGX_NOINLINE
118
119#elif defined(ARUINO_ARCH_RP2040) ||defined(PICO_RP2040)
120 // Raspberry Pico 2040
121 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
122 #define TGX_USE_FAST_INV_SQRT_TRICK 1
123 #define TGX_USE_FAST_SQRT_TRICK 0
124 #define TGX_USE_FAST_INV_TRICK 0
125 #define TGX_INLINE
126 #define TGX_NOINLINE
127
128#elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(ESP32S2)
129 // ESP32 S2
130 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
131 #define TGX_USE_FAST_INV_SQRT_TRICK 0
132 #define TGX_USE_FAST_SQRT_TRICK 0
133 #define TGX_USE_FAST_INV_TRICK 0
134 #define TGX_INLINE
135 #define TGX_NOINLINE
136
137#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ESP32S3)
138 // ESP32 S3
139 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
140 #define TGX_USE_FAST_INV_SQRT_TRICK 0 // unused: specific assembly code used instead.
141 #define TGX_USE_FAST_SQRT_TRICK 0 //
142 #define TGX_USE_FAST_INV_TRICK 0 //
143 #define TGX_INLINE __attribute__((always_inline))
144 #define TGX_NOINLINE
145
146#elif defined(CONFIG_IDF_TARGET_ESP32P4) || defined(ESP32P4)
147 // ESP32 P4
148 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
149 #define TGX_USE_FAST_INV_SQRT_TRICK 0 // unused: specific assembly code used instead.
150 #define TGX_USE_FAST_SQRT_TRICK 0 //
151 #define TGX_USE_FAST_INV_TRICK 0 //
152 #define TGX_INLINE __attribute__((always_inline))
153 #define TGX_NOINLINE
154
155#elif defined(CONFIG_IDF_TARGET_ESP32) || defined(ESP32)
156 // fallback to original
157 // nb: `ESP32` is defined for all ESP32 variants so this case should be the last
158 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
159 #define TGX_USE_FAST_INV_SQRT_TRICK 0 // unused: specific assembly code used instead.
160 #define TGX_USE_FAST_SQRT_TRICK 0 //
161 #define TGX_USE_FAST_INV_TRICK 0 //
162 #define TGX_INLINE __attribute__((always_inline))
163 #define TGX_NOINLINE
164
165#elif defined(__ARM_ARCH_6M__)
166 // generic Cortex-M0 (use same setting as Teensy LC)
167 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 256
168 #define TGX_USE_FAST_INV_SQRT_TRICK 0
169 #define TGX_USE_FAST_SQRT_TRICK 0
170 #define TGX_USE_FAST_INV_TRICK 0
171 #define TGX_INLINE
172 #define TGX_NOINLINE
173
174#elif defined(__ARM_ARCH_7M__)
175 // generic Cortex-M3 (use same setting as Teensy3.2)
176 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
177 #define TGX_USE_FAST_INV_SQRT_TRICK 1
178 #define TGX_USE_FAST_SQRT_TRICK 0
179 #define TGX_USE_FAST_INV_TRICK 0
180 #define TGX_INLINE __attribute__((always_inline))
181 #define TGX_NOINLINE
182
183#elif (defined(__ARM_ARCH_7EM__) && defined(__ARM_FP) && (__ARM_FP == 0xC)) || defined(STM32H7xx)
184 // generic Cortex-M7 (use same setting as Teensy 4.0/4.1)
185 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
186 #define TGX_USE_FAST_INV_SQRT_TRICK 1
187 #define TGX_USE_FAST_SQRT_TRICK 1
188 #define TGX_USE_FAST_INV_TRICK 1
189 #define TGX_INLINE __attribute__((always_inline))
190 #define TGX_NOINLINE
191
192#elif defined(__ARM_ARCH_7EM__)
193 // generic Cortex-M4 (use same setting as Teensy 3.6/3.5)
194 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
195 #define TGX_USE_FAST_INV_SQRT_TRICK 1
196 #define TGX_USE_FAST_SQRT_TRICK 0
197 #define TGX_USE_FAST_INV_TRICK 0
198 #define TGX_INLINE __attribute__((always_inline))
199 #define TGX_NOINLINE
200
201#elif defined(__ARM_ARCH_8M_MAIN__)
202 // generic Cortex-M33 (use same setting as RP2350)
203 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
204 #define TGX_USE_FAST_INV_SQRT_TRICK 1
205 #define TGX_USE_FAST_SQRT_TRICK 1
206 #define TGX_USE_FAST_INV_TRICK 1
207 #define TGX_INLINE __attribute__((always_inline))
208 #define TGX_NOINLINE
209
210#else
211 // unkwown board/architecture
212 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
213 #define TGX_USE_FAST_INV_SQRT_TRICK 0
214 #define TGX_USE_FAST_SQRT_TRICK 0
215 #define TGX_USE_FAST_INV_TRICK 0
216 #define TGX_INLINE
217 #define TGX_NOINLINE
218#endif
219
220
221
222
223// Set this to 1 to use float as the default floating point type and set it to 0 to use double precision instead.
224#ifndef TGX_SINGLE_PRECISION_COMPUTATIONS
225 #define TGX_SINGLE_PRECISION_COMPUTATIONS 1
226#endif
227
228
229// Default blending operation for drawing primitive: overwrite instead of blending.
230#define TGX_DEFAULT_NO_BLENDING -1.0f
231
232