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/** @file MozziGuts_impl_template.hpp Template for implementation of new ports
13 *
14 * README!
15 * This file is meant to be used as a template when adding support for a new platform. Please read these instructions, first.
16 *
17 * Files involved:
18 * 1. Modify hardware_defines.h, adding a macro to detect your target platform
19 * 2. Modify MozziGuts.cpp to include MozziGuts_impl_YOURPLATFORM.hpp
20 * 3. Modify internal/config_checks_generic.h to include internal/config_checks_YOURPLATFORM.h
21 * 4. Copy this file to MozziGuts_impl_YOURPLATFORM.hpp and adjust as necessary, same for internal/config_checks_template.h
22 * (If your platform is very similar to an existing port, it may instead be better to modify the existing MozziGuts_impl_XYZ.hpp/config_checks_XYZ.h,
23 * instead of steps 2-3.).
24 * Some platforms may need small modifications to other files as well, e.g. mozzi_pgmspace.h
25 *
26 * How to implement MozziGuts_impl_YOURPLATFORM.hpp:
27 * - Follow the NOTEs provided in this file
28 * - Read the doc at the top of AudioOutput.h for a better understanding of the basic audio output framework
29 * - Take a peek at existing implementations for other hardware (e.g. TEENSY3/4 is rather complete while also simple at the time of this writing)
30 * - Wait for more documentation to arrive
31 * - Ask when in doubt
32 * - Don't forget to provide a PR when done (it does not have to be perfect; e.g. many ports skip analog input, initially)
33 */
34
35// The main point of this check is to document, what platform & variants this implementation file is for.
36#if!(IS_MYPLATFORM())
37#error"Wrong implementation included for this platform"
38#endif
39// Add platform specific includes and declarations, here
40
41//#include <my_hardware_header.h>
42
43// In order to allow simple yet efficient user configuration, the entire contents of this file are compiled in the same translation unit
44// as (the main file of) the user sketch. To avoid name clashes, we encapsulate everyghing in a namespace.
45// For the most part, this namescape can just extend from the start of the file to the end (as shown, here), and you will not have to
46// worry about it. However, there may be a few situations, where you have to "leave" the MozziPrivate namespace. This includes:
47// - When you include a further (hardware-dependent library). Consider gathering all includes at the top of this file, instead.
48// - When you provide definitions for special names, importantly for ISR-functions. If these would be placed in the namespace, the linker would not
49// recognize them as the definition of the intended ISR-vector. See MozziGuts_impl_AVR.hpp for examples.
56/** NOTE: This section deals with implementing (fast) asynchronous analog reads, which form the backbone of mozziAnalogRead(), but also of MOZZI_AUDIO_INPUT (if enabled).
57 *
58 * It is possible, and even recommended, to skip over this section, initially, when starting a new port. Once you have an implementation, be sure to include something like this
59 * in your platform configuration checks:
60 *
61 * // analog reads shall be enabled by default on platforms that support it
74/** NOTE: On "pins" vs. "channels" vs. "indices"
75 * "Pin" is the pin number as would usually be specified by the user in mozziAnalogRead().
76 * "Channel" is an internal ADC channel number corresponding to that pin. On many platforms this is simply the same as the pin number, on others it differs.
77 * In other words, this is an internal representation of "pin".
78 * "Index" is the index of the reading for a certain pin/channel in the array of analog_readings, ranging from 0 to NUM_ANALOG_PINS. This, again may be the
79 * same as "channel" (e.g. on AVR), however, on platforms where ADC-capable "channels" are not numbered sequentially starting from 0, the channel needs
96/** NOTE: Code needed to trigger a subsequent conversion on the latest channel. If your platform has no special code for it, you should store the channel from
97 * adcStartConversion(), and simply call adcStartConversion(previous_channel), here. */
101/** NOTE: Code needed to initialize the ADC for asynchronous reads. Typically involves setting up an interrupt handler for when conversion is done, and
108/* NOTE: Most platforms call a specific function/ISR when conversion is complete. Provide this function, here.
109 * From inside its body, simply call advanceADCStep(). E.g.:
110void stm32_adc_eoc_handler() {
111 advanceADCStep();
112}
113*/
114
115/** NOTE: Code needed to set up faster than usual analog reads, e.g. specifying the number of CPU cycles that the ADC waits for the result to stabilize.
116 * This particular function is not super important, so may be ok to leave empty, at least, if the ADC is fast enough by default. */
125/* NOTE: Some platforms rely on control returning from loop() every so often. However, updateAudio() may take too long (it tries to completely fill the output buffer,
126 * which of course is being drained at the same time, theoretically it may not return at all). If you set this define, it will be called once per audio frame to keep things
127 * running smoothly. */
128//#define LOOP_YIELD yield();
129
130/* NOTE: On some platforms, what can be called in the ISR used to output the sound is limited.
131 * This define can be used, for instance, to output the sound in audioHook() instead to overcome
132 * this limitation (see MozziGuts_impl_MBED.hpp). It can also be used if something needs to be called in audioHook() regarding
133 * analog reads for instance. */
134//#define AUDIO_HOOK_HOOK
135
136/* NOTE: Code sections that are needed for a certain audio mode, only, should be guarded as follows (in this example, code will compile for the
137 * two modes MOZZI_OUTPUT_PWM, and MOZZI_OUTPUT_INTERNAL_DAC (should your port happen to support these two).
138 *
139 * Keep in mind that you probably want to support MOZZI_OUTPUT_EXTERNAL_TIMED, and MOZZI_OUTPUT_EXTERNAL_CUSTOM, too, which is usually very
140 * easy: For both, do *not* provide an audioOutput() function, as this will be provided by the user. For MOZZI_OUTPUT_EXTERNAL_TIMED make sure some
141 * timer is set up to call defaultAudioOutput() at MOZZI_AUDIO_RATE. For MOZZI_OUTPUT_EXTERNAL_CUSTOM, nothing else will be needed. */
142
143#ifMOZZI_IS(MOZZI_AUDIO_MODE,MOZZI_OUTPUT_PWM,MOZZI_OUTPUT_INTERNAL_DAC)// just an example!
144/** NOTE: This is the function that actually write a sample to the output. In case of the two EXTERNAL modes, it is provided by the library user, instead. */
Generated automatically using Doxygen. If info on this page is outdated, incomplete, or wrong, please open an issue at https://github.com/sensorium/Mozzi/issues