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// Serial.
37#ifndef PLAQUETTE_SERIAL_BAUD_RATE
38#define PLAQUETTE_SERIAL_BAUD_RATE 9600
39#endif
40
41#define NO_SERIAL 0
42
43// Smoothing.
44#ifndef PLAQUETTE_DEFAULT_SMOOTH_WINDOW
45#define PLAQUETTE_DEFAULT_SMOOTH_WINDOW 0.1f
46#endif
47
48#define PLAQUETTE_NO_SMOOTH_WINDOW 0.0f
49#define PLAQUETTE_INFINITE_SMOOTH_WINDOW (-1)
50
51// Debouncing.
52#ifndef PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW
53#define PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW 0.02f // 20 ms
54#endif
55
56#define PLAQUETTE_NO_DEBOUNCE_WINDOW 0.0f
57
58// Sample rate.
59#define PLAQUETTE_MAX_SAMPLE_RATE FLT_MAX
60
61// ----------------------------------------------------------------------------
62// Default analog write and read values.
63// ----------------------------------------------------------------------------
64
65#if defined(ARDUINO_ARCH_AVR)
66 // Arduino Uno, Nano, Mega (8-bit PWM, 10-bit ADC)
67 #define ANALOG_WRITE_MAX_VALUE 255
68 #define ANALOG_READ_MAX_VALUE 1023
69
70#elif defined(ARDUINO_ARCH_SAMD)
71 // Arduino Zero, MKR series (12-bit PWM, 12-bit ADC)
72 #define ANALOG_WRITE_MAX_VALUE 4095
73 #define ANALOG_READ_MAX_VALUE 4095
74
75#elif defined(ARDUINO_ARCH_ESP8266)
76 // ESP8266 (10-bit PWM, 10-bit ADC)
77 #define ANALOG_WRITE_MAX_VALUE 1023
78 #define ANALOG_READ_MAX_VALUE 1024 // this is specific to ESP8266, the max is 1024 NOT 1023
79
80#elif defined(ARDUINO_ARCH_ESP32)
81 // ESP32 (8-bit default PWM, 12-bit default ADC, configurable)
82 #define ANALOG_WRITE_MAX_VALUE 255 // Can be configured up to 16-bit
83 #define ANALOG_READ_MAX_VALUE 4095 // Default 12-bit, configurable to 13-bit (8191)
84
85#elif defined(ARDUINO_ARCH_SAM)
86 // Arduino Due (12-bit PWM, 12-bit ADC)
87 #define ANALOG_WRITE_MAX_VALUE 4095
88 #define ANALOG_READ_MAX_VALUE 4095
89
90#elif defined(ARDUINO_ARCH_STM32)
91 // STM32 boards (12-bit PWM, 12-bit ADC)
92 #define ANALOG_WRITE_MAX_VALUE 4095
93 #define ANALOG_READ_MAX_VALUE 4095
94
95#else
96 // Fallback if architecture is unknown (assume standard 8-bit PWM, 10-bit ADC)
97 #define ANALOG_WRITE_MAX_VALUE 255
98 #define ANALOG_READ_MAX_VALUE 1023
99#endif
100
101
102// ----------------------------------------------------------------------------
103// Optimization flags.
104// ----------------------------------------------------------------------------
105
106// 32-bit vs 8-bit platforms.
107#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || defined(ESP32) || defined(TEENSYDUINO) || defined(__arm__) || defined(__riscv)
108 #define PQ_ARCH_32BITS
109// 8-bit AVR boards (Uno, Mega, Nano, ATtiny)
110#elif defined(__AVR__)
111 #define PQ_ARCH_8BITS
112#else
113 #define PQ_ARCH_8BITS
114#endif
115
116// IEEE 754 floating point supported.
117#if defined(__STDC_IEC_559__) || defined(__IEEE754__) || defined(ESP_PLATFORM) || defined(TEENSYDUINO) || defined(__AVR__) || defined(__ARM_FP)
118 #define PQ_IEEE_754_SUPPORTED
119#else
120 #warning "IEEE 754 floating point not supported on this architecture. This may cause unexpected behavior."
121#endif
122
123// Enable CPU optimization (as opposed to memory optimization).
124#ifndef PQ_OPTIMIZE_FOR_CPU
125
126// Disable CPU optimization for low-RAM AVR chips (≤ 2 KB SRAM)
127#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || \
128 defined(__AVR_ATmega88__) || defined(__AVR_ATmega48__) || \
129 defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || \
130 defined(__AVR_ATmega32__) || defined(__AVR_ATtiny85__) || \
131 defined(__AVR_ATtiny84__) || defined(__AVR_ATmega168PB__)|| \
132 defined(__AVR_AT90S2313__) || defined(__AVR_AT90S4433__)
133
134 #define PQ_OPTIMIZE_FOR_CPU 0
135
136// All other platforms: enable optimization by default
137#else
138 #define PQ_OPTIMIZE_FOR_CPU 1
139#endif
140
141#endif
142
143#endif