Skip to content

Commit

Permalink
Support for Teensy LC, 3.5, 3.6 and AVR 8Mhz
Browse files Browse the repository at this point in the history
Added support for Teensy 3 LC, 3.5, 3.6.
Corrected bad #ifdef added with STM32 support that broke Teensy support
  • Loading branch information
adrianfreed committed Mar 18, 2018
1 parent e95d33b commit 8c0d503
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions AudioConfigTeensy3_12bit.h
Expand Up @@ -7,7 +7,17 @@
/* Used internally to put the 0-biased generated audio into the centre of the output range (12 bits on Teensy 3) */
#define AUDIO_BIAS ((uint16_t) 2048)

#if !defined(AUDIO_CHANNEL_1_PIN) && defined(__arm__) && defined(CORE_TEENSY)
#if defined(__MKL26Z64__)
#define AUDIO_CHANNEL_1_PIN A12
#elif defined(__MK20DX128__) || defined(__MK20DX256__)
#define AUDIO_CHANNEL_1_PIN A14
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
#define AUDIO_CHANNEL_1_PIN A21
#else
#error "Unknown Teensy"
#endif
#endif

#endif // #ifndef AUDIOCONFIGTEENSY3_12BIT_H

8 changes: 4 additions & 4 deletions MozziGuts.cpp
Expand Up @@ -464,9 +464,9 @@ static void startAudioStandard()
pinMode(AUDIO_CHANNEL_1_PIN, OUTPUT); // set pin to output for audio
// pinMode(AUDIO_CHANNEL_2_PIN, OUTPUT); // set pin to output for audio
#if (AUDIO_MODE == STANDARD)
Timer1.initializeCPUCycles(16000000UL/AUDIO_RATE, PHASE_FREQ_CORRECT); // set period, phase and frequency correct
Timer1.initializeCPUCycles(F_CPU/AUDIO_RATE, PHASE_FREQ_CORRECT); // set period, phase and frequency correct
#else // (AUDIO_MODE == STANDARD_PLUS)
Timer1.initializeCPUCycles(16000000UL/PWM_RATE, FAST); // fast mode enables higher PWM rate
Timer1.initializeCPUCycles(F_CPU/PWM_RATE, FAST); // fast mode enables higher PWM rate
#endif
Timer1.pwm(AUDIO_CHANNEL_1_PIN, AUDIO_BIAS); // pwm pin, 50% of Mozzi's duty cycle, ie. 0 signal
#if (STEREO_HACK == true)
Expand Down Expand Up @@ -549,7 +549,7 @@ static void startAudioHiFi()
// pwm on timer 1
pinMode(AUDIO_CHANNEL_1_highByte_PIN, OUTPUT); // set pin to output for audio, use 3.9k resistor
pinMode(AUDIO_CHANNEL_1_lowByte_PIN, OUTPUT); // set pin to output for audio, use 499k resistor
Timer1.initializeCPUCycles(16000000UL/125000, FAST); // set period for 125000 Hz fast pwm carrier frequency = 14 bits
Timer1.initializeCPUCycles(F_CPU/125000, FAST); // set period for 125000 Hz fast pwm carrier frequency = 14 bits
Timer1.pwm(AUDIO_CHANNEL_1_highByte_PIN, 0); // pwm pin, 0% duty cycle, ie. 0 signal
Timer1.pwm(AUDIO_CHANNEL_1_lowByte_PIN, 0); // pwm pin, 0% duty cycle, ie. 0 signal
backupMozziTimer1();
Expand Down Expand Up @@ -613,7 +613,7 @@ static void backupMozziTimer2()
static void setupTimer2()
{
backupPreMozziTimer2(); // to reset while pausing
unsigned long period = 16000000UL/AUDIO_RATE;
unsigned long period = F_CPU/AUDIO_RATE;
FrequencyTimer2::setPeriodCPUCycles(period);
FrequencyTimer2::setOnOverflow(dummy);
FrequencyTimer2::enable();
Expand Down
4 changes: 2 additions & 2 deletions hardware_defines.h
Expand Up @@ -13,8 +13,8 @@
- Easy to extend for new but compatible boards */

#define IS_AVR() (defined(__AVR__)) // "Classic" Arduino boards
#define IS_TEENSY3() (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(TEENSYDUINO)) // 32bit arm-based Teensy
#define IS_STM32() (defined(__arm__) && !IS_TEENSY3) // STM32 boards (note that only the maple based core is supported at this time. If another cores is to be supported in the future, this define should be split.
#define IS_TEENSY3() (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__) || defined(TEENSYDUINO)) // 32bit arm-based Teensy
#define IS_STM32() (defined(__arm__) && !IS_TEENSY3()) // STM32 boards (note that only the maple based core is supported at this time. If another cores is to be supported in the future, this define should be split.
#define IS_ESP8266() (defined(ESP8266))

#if !(IS_AVR() || IS_TEENSY3() || IS_STM32() || IS_ESP8266())
Expand Down

0 comments on commit 8c0d503

Please sign in to comment.