Mozzi  version v2.0
sound synthesis library for Arduino
hardware_defines.h
1 /*
2  * hardware_defines.h.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2023-2024 Thomas Friedrichsmeier and the Mozzi Team
7  *
8  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
9  *
10  */
11 
12 
13 #ifndef HARDWARE_DEFINES_H_
14 #define HARDWARE_DEFINES_H_
15 
16 #include "Arduino.h"
17 
18 /* Macros to tell apart the supported platforms. The advantages of using these are, rather than the underlying defines
19 - Easier to read and write
20 - Compiler protection against typos
21 - Easy to extend for new but compatible boards */
22 
23 // "Classic" Arduino boards
24 #if (defined(__AVR__))
25 #define IS_AVR() 1
26 #else
27 #define IS_AVR() 0
28 #endif
29 
30 // SAMD
31 #if (defined(ARDUINO_ARCH_SAMD))
32 #define IS_SAMD21() 1
33 #else
34 #define IS_SAMD21() 0
35 #endif
36 
37 // 32bit arm-based Teensy
38 #if (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__))
39 #define IS_TEENSY3() 1
40 #else
41 #define IS_TEENSY3() 0
42 #endif
43 
44 // Teensy4 (no DAC)
45 #if (defined(__IMXRT1062__))
46 #define IS_TEENSY4() 1
47 #else
48 #define IS_TEENSY4() 0
49 #endif
50 
51 // RP2040 (Raspberry Pi Pico and friends)
52 #if (defined(ARDUINO_ARCH_RP2040))
53 #define IS_RP2040() 1
54 #else
55 #define IS_RP2040() 0
56 #endif
57 
58 // STM32 boards (libmaple based)
59 // https://github.com/stevstrong/Arduino_STM32
60 #if (defined(__arm__) && !IS_TEENSY3() && !IS_TEENSY4() && __has_include("libmaple/libmaple.h"))
61 #define IS_STM32MAPLE() 1
62 #else
63 #define IS_STM32MAPLE() 0
64 #endif
65 
66 // Mbed OS based boards
67 #if (defined(ARDUINO_ARCH_MBED))
68 #define IS_MBED() 1
69 #else
70 #define IS_MBED() 0
71 #endif
72 
73 // Arduino Giga
74 #if (IS_MBED() && defined(ARDUINO_GIGA))
75 #define IS_GIGA() 1
76 #else
77 #define IS_GIGA() 0
78 #endif
79 
80 // Arduino Uno R4 (Renesas arch)
81 #if (defined(ARDUINO_FSP))
82 #define IS_RENESAS() 1
83 #else
84 #define IS_RENESAS() 0
85 #endif
86 
87 #if (defined(__arm__) && !IS_STM32MAPLE() && !IS_TEENSY3() && !IS_TEENSY4() && !IS_RP2040() && !IS_SAMD21() && !IS_MBED() && !IS_RENESAS())
88 #define IS_STM32DUINO() 1
89 #else
90 #define IS_STM32DUINO() 0
91 #endif
92 
93 #if (defined(ESP8266))
94 #define IS_ESP8266() 1
95 #else
96 #define IS_ESP8266() 0
97 #endif
98 
99 #if (defined(ESP32))
100 #define IS_ESP32() 1
101 #else
102 #define IS_ESP32() 0
103 #endif
104 
105 #if !(IS_AVR() || IS_TEENSY3() || IS_TEENSY4() || IS_STM32MAPLE() || IS_STM32DUINO() || IS_ESP8266() || IS_SAMD21() || IS_ESP32() || IS_RP2040() || IS_MBED() || IS_RENESAS())
106 // TODO: add an exception for MOZZI_OUTPUT_EXTERNAL_CUSTOM
107 #error Your hardware is not supported by Mozzi or not recognized. Edit hardware_defines.h to proceed.
108 #endif
109 
110 // Hardware detail defines
111 #if IS_STM32MAPLE()
112 #define NUM_ANALOG_INPUTS 16 // probably wrong, but mostly needed to allocate an array of readings
113 #elif IS_ESP8266()
114 #define NUM_ANALOG_INPUTS 1
115 #endif
116 
117 #if IS_ESP8266() || IS_ESP32()
118 #define CACHED_FUNCTION_ATTR IRAM_ATTR
119 #else
120 #define CACHED_FUNCTION_ATTR
121 #endif
122 
123 #if IS_STM32MAPLE()
124 // This is a little silly, but with Arduino 1.8.13, including this header inside MozziGuts.cpp does not work (fails to detect the proper include path).
125 // Putting it here, instead, seem to work.
126 #include <STM32ADC.h>
127 #endif
128 
129 #endif /* HARDWARE_DEFINES_H_ */