From ed797c00fe08a1177f7903ae845afcf1a881bc44 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Sat, 23 Jan 2021 14:35:38 +1100 Subject: [PATCH] Enabled the Piezo buzzer for the Pi0 --- src/iec_bus.cpp | 3 +-- src/iec_bus.h | 2 -- src/main.cpp | 28 ++++++++++++---------------- src/options.h | 4 ---- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/iec_bus.cpp b/src/iec_bus.cpp index 4f3782a..ba73867 100644 --- a/src/iec_bus.cpp +++ b/src/iec_bus.cpp @@ -384,10 +384,9 @@ void IEC_Bus::RefreshOuts1541(void) if (OutputLED) set |= 1 << PIGPIO_OUT_LED; else clear |= 1 << PIGPIO_OUT_LED; -#if not defined(EXPERIMENTALZERO) + if (OutputSound) set |= 1 << PIGPIO_OUT_SOUND; else clear |= 1 << PIGPIO_OUT_SOUND; -#endif write32(ARM_GPIO_GPCLR0, clear); write32(ARM_GPIO_GPSET0, set); diff --git a/src/iec_bus.h b/src/iec_bus.h index 9f6bd36..6705828 100644 --- a/src/iec_bus.h +++ b/src/iec_bus.h @@ -537,10 +537,8 @@ class IEC_Bus if (OutputLED) set |= 1 << PIGPIO_OUT_LED; else clear |= 1 << PIGPIO_OUT_LED; -#if not defined(EXPERIMENTALZERO) if (OutputSound) set |= 1 << PIGPIO_OUT_SOUND; else clear |= 1 << PIGPIO_OUT_SOUND; -#endif write32(ARM_GPIO_GPSET0, set); write32(ARM_GPIO_GPCLR0, clear); diff --git a/src/main.cpp b/src/main.cpp index e294c39..349b6c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -133,6 +133,8 @@ unsigned int screenHeight = 768; const char* termainalTextRed = "\E[31m"; const char* termainalTextNormal = "\E[0m"; +int headSoundFreq; +int headSoundCounterDuration; // Hooks required for USPi library extern "C" @@ -785,8 +787,6 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser) unsigned caddyIndex; int headSoundCounter = 0; int headSoundFreqCounter = 0; - // const int headSoundFreq = 833; // 1200Hz = 1/1200 * 10^6; - const int headSoundFreq = 1000000 / options.SoundOnGPIOFreq(); // 1200Hz = 1/1200 * 10^6; unsigned char oldHeadDir = 0; int resetCount = 0; bool refreshOutsAfterCPUStep = true; @@ -898,7 +898,6 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser) } #endif -#if not defined(EXPERIMENTALZERO) // Do head moving sound unsigned char headDir = pi1541.drive.GetLastHeadDirection(); if (headDir != oldHeadDir) // Need to start a new sound? @@ -906,18 +905,17 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser) oldHeadDir = headDir; if (options.SoundOnGPIO()) { - headSoundCounter = 1000 * options.SoundOnGPIODuration(); + headSoundCounter = headSoundCounterDuration; headSoundFreqCounter = headSoundFreq; } else { +#if not defined(EXPERIMENTALZERO) PlaySoundDMA(); +#endif } } - -#endif - IEC_Bus::ReadGPIOUserInput(); // Other core will check the uart (as it is slow) (could enable uart irqs - will they execute on this core?) @@ -974,7 +972,7 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser) IEC_Bus::ReadEmulationMode1541(); IEC_Bus::RefreshOuts1541(); // Now output all outputs. } -#if not defined(EXPERIMENTALZERO) + if (options.SoundOnGPIO() && headSoundCounter > 0) { headSoundFreqCounter--; // Continue updating a GPIO non DMA sound. @@ -985,7 +983,6 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser) IEC_Bus::OutputSound = !IEC_Bus::OutputSound; } } -#endif if (numberOfImages > 1) { @@ -1039,8 +1036,6 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser) unsigned caddyIndex; int headSoundCounter = 0; int headSoundFreqCounter = 0; - // const int headSoundFreq = 833; // 1200Hz = 1/1200 * 10^6; - const int headSoundFreq = 1000000 / options.SoundOnGPIOFreq(); // 1200Hz = 1/1200 * 10^6; unsigned int oldTrack = 0; int resetCount = 0; @@ -1116,7 +1111,6 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser) } #endif -#if not defined(EXPERIMENTALZERO) // Do head moving sound unsigned int track = pi1581.wd177x.GetCurrentTrack(); if (track != oldTrack) // Need to start a new sound? @@ -1124,15 +1118,16 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser) oldTrack = track; if (options.SoundOnGPIO()) { - headSoundCounter = 1000 * options.SoundOnGPIODuration(); + headSoundCounter = headSoundCounterDuration; headSoundFreqCounter = headSoundFreq; } else { +#if not defined(EXPERIMENTALZERO) PlaySoundDMA(); +#endif } } -#endif IEC_Bus::ReadGPIOUserInput(); @@ -1182,7 +1177,6 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser) #endif ctBefore = ctAfter; -#if not defined(EXPERIMENTALZERO) if (options.SoundOnGPIO() && headSoundCounter > 0) { headSoundFreqCounter--; // Continue updating a GPIO non DMA sound. @@ -1193,7 +1187,6 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser) IEC_Bus::OutputSound = !IEC_Bus::OutputSound; } } -#endif if (numberOfImages > 1) { @@ -1915,6 +1908,9 @@ extern "C" DisplayOptions(y_pos+=32); #endif + headSoundFreq = 1000000 / options.SoundOnGPIOFreq(); // 1200Hz = 1/1200 * 10^6; + headSoundCounterDuration = 1000 * options.SoundOnGPIODuration(); + //if (!options.QuickBoot()) //IEC_Bus::WaitMicroSeconds(3 * 1000000); diff --git a/src/options.h b/src/options.h index 889e4b9..f736bcf 100644 --- a/src/options.h +++ b/src/options.h @@ -64,11 +64,7 @@ class Options : public TextParser inline unsigned int QuickBoot() const { return quickBoot; } inline unsigned int ShowOptions() const { return showOptions; } inline unsigned int DisplayPNGIcons() const { return displayPNGIcons; } -#if defined(EXPERIMENTALZERO) - inline unsigned int SoundOnGPIO() const { return false; } -#else inline unsigned int SoundOnGPIO() const { return soundOnGPIO; } -#endif inline unsigned int SoundOnGPIODuration() const { return soundOnGPIODuration; } inline unsigned int SoundOnGPIOFreq() const { return soundOnGPIOFreq; } inline unsigned int SplitIECLines() const { return splitIECLines; }