Mozzi  version v2.0
sound synthesis library for Arduino
config_checks_teensy.h
1 /*
2  * config_checks_teensy.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 #ifndef CONFIG_CHECK_TEENSY_H
13 #define CONFIG_CHECK_TEENSY_H
14 
15 /** @ingroup hardware
16  * @page hardware_teensy3 Mozzi on Teensy 3.0/3.1/3.2/3.4/3.5/LC boards.
17  *
18  * port by Tim Barrass
19  *
20  * @note
21  * For Teensy 4.x see @ref hardware_teensy4
22  *
23  * @section teensy3_status Port status and ussage notes
24  * This port requires the following two libraries (which should be part of a default installtion, however):
25  * - [Timer library](https://github.com/loglow/IntervalTimer) for Teensy 3.* by Daniel Gilbert
26  * - [ADC library](http://github.com/pedvide/ADC) by Pedro Villanueva
27  *
28  * Some of the differences for Teensy 3.* which will affect users include:
29  * - twi_nonblock code by Marije Baalman for non-blocking I2C is not compatible with Teensy 3.0/3.1/3.2.
30  *
31  * @section teensy3_output Output modes
32  * The following audio modes (see @ref MOZZI_AUDIO_MODE) are currently supported on this hardware:
33  * - MOZZI_OUTPUT_EXTERNAL_TIMED
34  * - MOZZI_OUTPUT_EXTERNAL_CUSTOM
35  * - MOZZI_OUTPUT_INTERNAL_DAC
36  *
37  * The default mode is @ref teensy3_internal_dac .
38  *
39  * @section teensy3_internal_dac MOZZI_OUTPUT_INTERNAL_DAC
40  * Output is to the inbuilt DAC. Output resolution is 12 bits. Mono, only. The DAC output pin differs from board to boards.
41  * In most cases the appropriate pin will be set outmatically. If needed, you can specify the DAC pin, explicitly:
42  *
43  * @code
44  * #define MOZZI_AUDIO_PIN_1 ... // Default: A14, A12, or A21, depending on board
45  * @endcode
46  *
47  * @section teensy3_external MOZZI_OUTPUT_EXTERNAL_TIMED and MOZZI_OUTPUT_EXTERNAL_CUSTOM
48  * See @ref external_audio
49 */
50 
51 
52 /** @ingroup hardware
53  * @page hardware_teensy4 Mozzi on Teensy 4.x boards.
54  *
55  * port by Thomas Combriat
56  *
57  * @note
58  * For Teensy 3.x see @ref hardware_teensy3
59  *
60  * @section teensy4_status Port status and ussage notes
61  * This port requires the following two libraries (which should be part of a default installtion, however):
62  * - [Timer library](https://github.com/loglow/IntervalTimer) for Teensy 4.* by Daniel Gilbert
63  * - [ADC library](http://github.com/pedvide/ADC) by Pedro Villanueva
64  *
65  * Contrary to the Teensy 3, the Teensy 4 do not have any DAC. The output is done on pin A8 (PWM) by default (see below).
66  * twi_nonblock is not ported.
67  *
68  * @section teensy3_output Output modes
69  * The following audio modes (see @ref MOZZI_AUDIO_MODE) are currently supported on this hardware:
70  * - MOZZI_OUTPUT_EXTERNAL_TIMED
71  * - MOZZI_OUTPUT_EXTERNAL_CUSTOM
72  * - MOZZI_OUTPUT_PWM
73  *
74  * The default mode is @ref teensy4_pwm .
75  *
76  * @section teensy4_pwm MOZZI_OUTPUT_PWM
77  * Output is to a GPIO pin (or two in stereo). The output resolution is fixed at 10 bits, and a 146484 kHz carrier frequency.
78  * The output pins can be configured as:
79  *
80  * @code
81  * #define MOZZI_AUDIO_PIN_1 ... // Left / mono output pin. Default: A8
82  * // For stereo, only:
83  * #define MOZZI_AUDIO_PIN_2 ... // Right channel output pin. Default: A9
84  * @endcode
85  *
86  * @section teensy4_external MOZZI_OUTPUT_EXTERNAL_TIMED and MOZZI_OUTPUT_EXTERNAL_CUSTOM
87  * See @ref external_audio
88 */
89 
90 
91 #if !(IS_TEENSY3() || IS_TEENSY4())
92 #error This header should be included for Teensy (3.x or 4.x) boards, only
93 #endif
94 
95 
96 
97 #if IS_TEENSY3()
98 # include "disable_2pinmode_on_github_workflow.h"
99 # if !defined(MOZZI_AUDIO_MODE)
100 # define MOZZI_AUDIO_MODE MOZZI_OUTPUT_INTERNAL_DAC
101 # endif
102 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM, MOZZI_OUTPUT_INTERNAL_DAC)
103 #elif IS_TEENSY4()
104 # include "disable_2pinmode_on_github_workflow.h"
105 # if !defined(MOZZI_AUDIO_MODE)
106 # define MOZZI_AUDIO_MODE MOZZI_OUTPUT_PWM
107 # endif
108 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM, MOZZI_OUTPUT_PWM)
109 #endif
110 
111 #if !defined(MOZZI_AUDIO_RATE)
112 #define MOZZI_AUDIO_RATE 32768
113 #endif
114 
115 #if defined(MOZZI_PWM_RATE)
116 #error Configuration of MOZZI_PWM_RATE is not currently supported on this platform (always same as MOZZI_AUDIO_RATE)
117 #endif
118 
119 #if !defined(MOZZI_ANALOG_READ)
120 # define MOZZI_ANALOG_READ MOZZI_ANALOG_READ_STANDARD
121 #endif
122 
123 MOZZI_CHECK_SUPPORTED(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_NONE, MOZZI_ANALOG_READ_STANDARD)
124 
125 #include "teensyPinMap.h"
126 
127 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC)
128 # define MOZZI_AUDIO_BITS 12 // not configurable
129 # if !defined(MOZZI_AUDIO_PIN_1)
130 # if defined(__MKL26Z64__)
131 # define MOZZI_AUDIO_PIN_1 A12
132 # elif defined(__MK20DX128__) || defined(__MK20DX256__)
133 # define MOZZI_AUDIO_PIN_1 A14
134 # elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
135 # define MOZZI_AUDIO_PIN_1 A21
136 # else
137 # error DAC pin not know for this board. Please define MOZZI_AUDIO_PIN_1 as appropriate
138 # endif
139 # endif
140 # include "disable_stereo_on_github_workflow.h"
141 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_CHANNELS, 1)
142 #elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM)
143 # define MOZZI_AUDIO_BITS 10 // not configurable
144 # if !defined(MOZZI_AUDIO_PIN_1)
145 # define MOZZI_AUDIO_PIN_1 A8
146 # endif
147 # if !defined(MOZZI_AUDIO_PIN_2)
148 # define MOZZI_AUDIO_PIN_2 A9
149 # endif
150 #endif
151 
152 //TODO: Not 100% sure this is correct in all cases.
153 #define MOZZI__INTERNAL_ANALOG_READ_RESOLUTION 10
154 
155 #endif // #ifndef CONFIG_CHECK_TEENSY_H