FastLED 3.9.15
Loading...
Searching...
No Matches
stdint.h
Go to the documentation of this file.
1#pragma once
2
3// IWYU pragma: no_include "platforms/arm/is_arm.h"
4// IWYU pragma: no_include "platforms/shared/int.h"
5
7// FastLED Integer Type Definitions
8//
9// IMPORTANT: FastLED has carefully purged <stdint.h> and <stddef.h> from the
10// include path because including those headers alone adds approximately 500ms
11// to the compilation time of EVERY *.o file.
12//
13// Instead, FastLED defines its own integer types (fl::u8, fl::u16, fl::i32, etc.)
14// using primitive types (char, short, int, long, long long) in platform-specific
15// int.h files. These types are guaranteed to match stdint.h types exactly, and
16// this is enforced by compile-time tests in platforms/compile_test.cpp.
17//
18// This file defines:
19// 1. FastLED's core integer types (fl::u8, fl::i32, etc.)
20// 2. Fractional types (fract8, fract16, etc.) for LED math
21// 3. Standard integer type names (uint8_t, int32_t, size_t, etc.)
22//
23// The 500ms compile-time savings per object file translates to significant build
24// time reductions across large projects with many translation units.
26
28// ⚠️ TYPEDEF CONFLICT RESOLUTION - READ THIS IF YOU GET COMPILATION ERRORS
30//
31// IF YOU ENCOUNTER: "error: conflicting declaration 'typedef ...'"
32// ➜ DO NOT modify this file!
33// ➜ Fix must go in src/platforms/{platform}/int.h
34//
35// ============================================================================
36// WHY TYPEDEF CONFLICTS HAPPEN
37// ============================================================================
38//
39// This file creates standard types by wrapping FastLED's platform types:
40//
41// typedef fl::u32 uint32_t; // FastLED's definition (this file)
42// typedef __uint32_t uint32_t; // System header's definition
43//
44// Conflict occurs when fl::u32 ≠ __uint32_t (different base types)
45// No conflict when fl::u32 = __uint32_t (identical typedefs are allowed)
46//
47// ============================================================================
48// CONFLICT RESOLUTION PATTERN
49// ============================================================================
50//
51// ❌ DO NOT add #ifdef guards to this file
52// ❌ DO NOT change the typedef statements here
53// ✅ DO modify src/platforms/{platform}/int.h
54//
55// EXAMPLE: ESP32 IDF 3.3 uint32_t Conflict
56//
57// ERROR:
58// error: conflicting declaration 'typedef fl::u32 uint32_t'
59// note: previous declaration as 'typedef __uint32_t uint32_t'
60//
61// SOLUTION (in src/platforms/esp/int.h):
62// Changed: typedef __UINT32_TYPE__ u32; // Was: unsigned int
63// To: typedef __uint32_t u32; // Now: matches system exactly
64//
65// RESULT:
66// typedef fl::u32 uint32_t → typedef __uint32_t uint32_t
67// System also has: typedef __uint32_t uint32_t
68// Both IDENTICAL → No conflict!
69//
70// ============================================================================
71// WHERE TO FIX CONFLICTS
72// ============================================================================
73//
74// Platform-specific type files (modify these, not this file):
75//
76// ESP32/ESP8266: src/platforms/esp/int.h
77// src/platforms/esp/int_8266.h
78// AVR (Arduino): src/platforms/avr/int.h
79// ARM (general): src/platforms/arm/int.h
80// Teensy 4.x: src/platforms/arm/teensy/teensy4_common/int.h
81// Teensy 3.x: src/platforms/arm/teensy/teensy3_common/int.h
82// WebAssembly: src/platforms/wasm/int.h
83// Desktop/Generic: src/platforms/shared/int.h
84//
85// Platform selection logic is in: src/platforms/int.h
86//
87// ============================================================================
88// STEP-BY-STEP FIX GUIDE
89// ============================================================================
90//
91// 1. Read the error message to identify conflicting type (uint32_t, size_t, etc.)
92// 2. Note what base type the system uses (e.g., __uint32_t vs unsigned int)
93// 3. Find your platform's int.h file from the list above
94// 4. Modify the fl:: type to use the same base type as the system
95// 5. Add version checks if needed (see ESP32 IDF 3.3 example above)
96// 6. Test compilation
97//
98// ============================================================================
99// RESEARCH PAST FIXES
100// ============================================================================
101//
102// git log --oneline --all -- 'src/platforms/**/int*.h'
103// git show 32b3c80 # ESP32 IDF 3.3 fix
104// git show 4788f81 # Teensy 4.1 fix
105//
106// ============================================================================
107// INCLUDE CHAIN OVERVIEW
108// ============================================================================
109//
110// User code or FastLED.h
111// └─> fl/stl/stdint.h (this file)
112// ├─> platforms/int.h (platform dispatcher)
113// │ └─> platforms/{platform}/int.h (actual type definitions)
114// ├─> Defines fl::i8, fl::u8, fractional types
115// └─> Creates global typedefs: uint8_t, size_t, etc.
116//
117// The key insight: global typedefs (like uint32_t) wrap fl:: types
118// (like fl::u32), which are defined in platform files. If the platform
119// file makes fl::u32 identical to the system's base type, the typedef
120// becomes identical to the system's typedef, eliminating conflicts.
121//
123
124// Platform-specific integer type definitions
125// This includes platform-specific 16/32/64-bit types
126#include "platforms/int.h" // IWYU pragma: keep
127
128namespace fl {
129 // 8-bit types - char is reliably 8 bits on all supported platforms
130 typedef signed char i8;
131 typedef unsigned char u8;
132 typedef unsigned int uint;
133
134 // Pointer and size types are defined per-platform in platforms/int.h
135 // uptr (pointer type) and size (size type) are defined per-platform
136}
137
138namespace fl {
156
160 typedef u8 fract8;
161
165 typedef i8 sfract7;
166
170 typedef u16 fract16;
171
172 typedef i32 sfract31;
173
174 typedef u32 fract32;
175
179 typedef i16 sfract15;
180
181 typedef u16 accum88;
182 typedef i16 saccum78;
183 typedef u32 accum1616;
184 typedef i32 saccum1516;
185 typedef u16 accum124;
186 typedef i32 saccum114;
187}
188
189// Size assertions moved to src/platforms/compile_test.cpp.hpp
190
191// Make fractional types available in global namespace
192using fl::fract8; // ok bare using
193using fl::sfract7; // ok bare using
194using fl::fract16; // ok bare using
195using fl::sfract31; // ok bare using
196using fl::fract32; // ok bare using
197using fl::sfract15; // ok bare using
198using fl::accum88; // ok bare using
199using fl::saccum78; // ok bare using
200using fl::accum1616; // ok bare using
201using fl::saccum1516; // ok bare using
202using fl::accum124; // ok bare using
203using fl::saccum114; // ok bare using
204
205// Define standard integer type names for C++
206// This avoids the slow <stdint.h> include while maintaining compatibility
207// 8-bit types use raw primitives to match system headers exactly (allows duplicate typedefs)
208typedef unsigned char uint8_t;
209typedef signed char int8_t;
210
211// 16-bit types use platform-specific fl:: types to handle platform differences
212// (AVR: int is 16-bit, most others: short is 16-bit)
213typedef fl::u16 uint16_t;
214typedef fl::i16 int16_t;
215
216// Define standard types using fl:: types from platform-specific int.h
217// This ensures we match the platform's type sizes correctly
218typedef fl::u32 uint32_t;
219typedef fl::i32 int32_t;
220typedef fl::u64 u64;
221typedef fl::i64 i64;
222typedef fl::size size_t;
223typedef fl::uptr uintptr_t;
224typedef fl::iptr intptr_t;
225typedef fl::ptrdiff ptrdiff_t;
226
fl::size_t size_t
Definition cstddef.h:61
fl::ptrdiff_t ptrdiff_t
Definition cstddef.h:62
fl::i64 i64
Definition s16x16x4.h:222
fl::u64 u64
Definition s16x16x4.h:221
u16 fract16
ANSI: unsigned _Fract.
Definition s16x16x4.h:171
i16 saccum78
ANSI: signed short _Accum. 7 bits int, 8 bits fraction.
Definition s16x16x4.h:183
i16 sfract15
ANSI: signed _Fract.
Definition s16x16x4.h:180
i32 sfract31
ANSI: signed long _Fract. 31 bits int, 1 bit fraction.
Definition s16x16x4.h:173
i32 saccum1516
ANSI: signed _Accum. 15 bits int, 16 bits fraction.
Definition s16x16x4.h:185
u16 accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
Definition s16x16x4.h:182
u8 fract8
Fixed-Point Fractional Types.
Definition s16x16x4.h:161
u16 accum124
no direct ANSI counterpart. 12 bits int, 4 bits fraction
Definition s16x16x4.h:186
u32 fract32
ANSI: unsigned long _Fract. 32 bits int, 32 bits fraction.
Definition s16x16x4.h:175
i32 saccum114
no direct ANSI counterpart. 1 bit int, 14 bits fraction
Definition s16x16x4.h:187
i8 sfract7
ANSI: signed short _Fract.
Definition s16x16x4.h:166
u32 accum1616
ANSI: signed _Accum. 16 bits int, 16 bits fraction.
Definition s16x16x4.h:184
unsigned char u8
Definition stdint.h:131
unsigned int uint
Definition stdint.h:132
fl::i64 i64
Definition s16x16x4.h:222
signed char i8
Definition stdint.h:130
fl::u64 u64
Definition s16x16x4.h:221
Base definition for an LED controller.
Definition crgb.hpp:179