2017-02-20 18:55:16 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include "teensy-speaker.h"
|
|
|
|
|
2017-02-27 01:34:38 +00:00
|
|
|
#include "globals.h"
|
2017-02-20 18:55:16 +00:00
|
|
|
|
|
|
|
TeensySpeaker::TeensySpeaker(uint8_t pinNum) : PhysicalSpeaker()
|
|
|
|
{
|
2017-02-26 16:00:41 +00:00
|
|
|
toggleState = false;
|
2017-02-20 18:55:16 +00:00
|
|
|
speakerPin = pinNum;
|
|
|
|
pinMode(speakerPin, OUTPUT); // analog speaker output, used as digital volume control
|
2017-02-26 16:00:41 +00:00
|
|
|
mixerValue = numMixed = 0;
|
2017-02-20 18:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TeensySpeaker::~TeensySpeaker()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-31 22:21:34 +00:00
|
|
|
void TeensySpeaker::toggle(uint32_t c)
|
2017-02-20 18:55:16 +00:00
|
|
|
{
|
2018-01-03 01:28:47 +00:00
|
|
|
toggleState = !toggleState;
|
|
|
|
|
|
|
|
mixerValue = (toggleState ? 0x1FF : 0x00);
|
|
|
|
mixerValue >>= (16-g_volume);
|
2020-07-08 13:43:44 +00:00
|
|
|
|
|
|
|
// FIXME: this is one helluva hack
|
|
|
|
if (g_volume >= 8)
|
|
|
|
digitalWrite(speakerPin, toggleState ? HIGH : LOW);
|
|
|
|
//analogWrite(speakerPin, mixerValue);
|
2017-02-20 18:55:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 01:28:47 +00:00
|
|
|
void TeensySpeaker::maintainSpeaker(uint32_t c, uint64_t runtimeInMicros)
|
2017-02-20 18:55:16 +00:00
|
|
|
{
|
2018-01-03 01:28:47 +00:00
|
|
|
// Nothing to do here. We can't run the speaker async, b/c not
|
|
|
|
// enough CPU time. So we run the CPU close to sync and hope that
|
|
|
|
// the direct pulsing of the speaker is reasonably close to on-time.
|
2017-02-20 18:55:16 +00:00
|
|
|
}
|
2017-02-24 15:15:17 +00:00
|
|
|
|
2017-02-26 16:00:41 +00:00
|
|
|
void TeensySpeaker::beginMixing()
|
2017-02-24 15:15:17 +00:00
|
|
|
{
|
2017-12-31 22:21:34 +00:00
|
|
|
// unused
|
2017-02-24 15:15:17 +00:00
|
|
|
}
|
2017-02-26 16:00:41 +00:00
|
|
|
|
|
|
|
void TeensySpeaker::mixOutput(uint8_t v)
|
|
|
|
{
|
2017-12-31 22:21:34 +00:00
|
|
|
// unused
|
2017-02-26 16:00:41 +00:00
|
|
|
}
|
|
|
|
|