Skip to content

Commit

Permalink
Enabled the Piezo buzzer for the Pi0
Browse files Browse the repository at this point in the history
  • Loading branch information
pi1541 committed Jan 23, 2021
1 parent be4abef commit ed797c0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/iec_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/iec_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 12 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -898,26 +898,24 @@ 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?
{
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?)
Expand Down Expand Up @@ -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.
Expand All @@ -985,7 +983,6 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser)
IEC_Bus::OutputSound = !IEC_Bus::OutputSound;
}
}
#endif

if (numberOfImages > 1)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1116,23 +1111,23 @@ 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?
{
oldTrack = track;
if (options.SoundOnGPIO())
{
headSoundCounter = 1000 * options.SoundOnGPIODuration();
headSoundCounter = headSoundCounterDuration;
headSoundFreqCounter = headSoundFreq;
}
else
{
#if not defined(EXPERIMENTALZERO)
PlaySoundDMA();
#endif
}
}
#endif

IEC_Bus::ReadGPIOUserInput();

Expand Down Expand Up @@ -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.
Expand All @@ -1193,7 +1187,6 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser)
IEC_Bus::OutputSound = !IEC_Bus::OutputSound;
}
}
#endif

if (numberOfImages > 1)
{
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 0 additions & 4 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit ed797c0

Please sign in to comment.