Plaquette
 
Loading...
Searching...
No Matches
pq_globals.h
1/*
2 * pq_globals.h
3 *
4 * Global constants.
5 *
6 * (c) 2025 Sofian Audry :: info(@)sofianaudry(.)com
7 *
8 * This program 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 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef PQ_GLOBALS_H_
23#define PQ_GLOBALS_H_
24
25// ----------------------------------------------------------------------------
26// Global constants.
27// ----------------------------------------------------------------------------
28
29// Max. components that can be added. Can be pre-defined. Notice that the use of a
30// hybrid array list requires a fixed size at compile time but the size will automatically be
31// adjusted at runtime if necessary using dynamically-allocated memory.
32#ifndef PLAQUETTE_MAX_UNITS
33#define PLAQUETTE_MAX_UNITS 32
34#endif
35
36// Smoothing.
37#ifndef PLAQUETTE_DEFAULT_SMOOTH_WINDOW
38#define PLAQUETTE_DEFAULT_SMOOTH_WINDOW 0.1f
39#endif
40
41// Debouncing.
42#ifndef PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW
43#define PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW 0.02f // 20 ms
44#endif
45
46// Sample rate.
47#define PLAQUETTE_MAX_SAMPLE_RATE FLT_MAX
48
49#define INFINITE_TIME_WINDOW (-1)
50#define NO_TIME_WINDOW 0
51
52// Printing / serial.
53#define PLAQUETTE_PRINT_DEFAULT_DIGITS 2
54#define PLAQUETTE_PRINT_MAX_DIGITS 6
55
56// ----------------------------------------------------------------------------
57// Default analog write and read values.
58// ----------------------------------------------------------------------------
59
60#if defined(ARDUINO_ARCH_AVR)
61 // Arduino Uno, Nano, Mega (8-bit PWM, 10-bit ADC)
62 #define ANALOG_WRITE_MAX_VALUE 255
63 #define ANALOG_READ_MAX_VALUE 1023
64
65#elif defined(ARDUINO_ARCH_SAMD)
66 // Arduino Zero, MKR series (12-bit PWM, 12-bit ADC)
67 #define ANALOG_WRITE_MAX_VALUE 4095
68 #define ANALOG_READ_MAX_VALUE 4095
69
70#elif defined(ARDUINO_ARCH_ESP8266)
71 // ESP8266 (10-bit PWM, 10-bit ADC)
72 #define ANALOG_WRITE_MAX_VALUE 1023
73 #define ANALOG_READ_MAX_VALUE 1024 // this is specific to ESP8266, the max is 1024 NOT 1023
74
75#elif defined(ARDUINO_ARCH_ESP32)
76 // ESP32 (8-bit default PWM, 12-bit default ADC, configurable)
77 #define ANALOG_WRITE_MAX_VALUE 255 // Can be configured up to 16-bit
78 #define ANALOG_READ_MAX_VALUE 4095 // Default 12-bit, configurable to 13-bit (8191)
79
80#elif defined(ARDUINO_ARCH_SAM)
81 // Arduino Due (12-bit PWM, 12-bit ADC)
82 #define ANALOG_WRITE_MAX_VALUE 4095
83 #define ANALOG_READ_MAX_VALUE 4095
84
85#elif defined(ARDUINO_ARCH_STM32)
86 // STM32 boards (12-bit PWM, 12-bit ADC)
87 #define ANALOG_WRITE_MAX_VALUE 4095
88 #define ANALOG_READ_MAX_VALUE 4095
89
90#else
91 // Fallback if architecture is unknown (assume standard 8-bit PWM, 10-bit ADC)
92 #define ANALOG_WRITE_MAX_VALUE 255
93 #define ANALOG_READ_MAX_VALUE 1023
94#endif
95
96
97// ----------------------------------------------------------------------------
98// Optimization flags.
99// ----------------------------------------------------------------------------
100
101// 32-bit vs 8-bit platforms.
102#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || defined(ESP32) || defined(TEENSYDUINO) || defined(__arm__) || defined(__riscv)
103 #define PQ_ARCH_32BITS
104// 8-bit AVR boards (Uno, Mega, Nano, ATtiny)
105#elif defined(__AVR__)
106 #define PQ_ARCH_8BITS
107#else
108 #define PQ_ARCH_8BITS
109#endif
110
111// IEEE 754 floating point supported.
112#if defined(__STDC_IEC_559__) || defined(__IEEE754__) || defined(ESP_PLATFORM) || defined(TEENSYDUINO) || defined(__AVR__) || defined(__ARM_FP)
113 #define PQ_IEEE_754_SUPPORTED
114#else
115 #warning "IEEE 754 floating point not supported on this architecture. This may cause unexpected behavior."
116#endif
117
118// Enable CPU optimization (as opposed to memory optimization).
119#ifndef PQ_OPTIMIZE_FOR_CPU
120
121// Disable CPU optimization for low-RAM AVR chips (≤ 2 KB SRAM)
122#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || \
123 defined(__AVR_ATmega88__) || defined(__AVR_ATmega48__) || \
124 defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || \
125 defined(__AVR_ATmega32__) || defined(__AVR_ATtiny85__) || \
126 defined(__AVR_ATtiny84__) || defined(__AVR_ATmega168PB__)|| \
127 defined(__AVR_AT90S2313__) || defined(__AVR_AT90S4433__)
128
129 #define PQ_OPTIMIZE_FOR_CPU 0
130
131// All other platforms: enable optimization by default
132#else
133 #define PQ_OPTIMIZE_FOR_CPU 1
134#endif
135
136#endif
137
138#endif