Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external PCM input. #25

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CRIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DigitalPin<coilOutPin> _coilOutPin(OUTPUT, LOW);
DigitalPin<diagOutPin> _diagOutPin(OUTPUT, LOW);
DigitalPin<speakerOutPin> _speakerOutPin(OUTPUT, LOW);


CRIO::CRIO() : _remainingPulseUs(0), pw(pulseWindowUs), maxPitch(maxMidiPitch), breakoutUs(minBreakoutUs), _ticksSinceLastPulse(0), handlePulsePtr(&CRIO::handleNoPulse) {
}

Expand All @@ -26,6 +27,10 @@ bool CRIO::fixedPulseEnabled() {
return false;
}

bool CRIO::midiEnabled() {
return true;
}

inline void CRIO::pulseOn() {
_speakerOutPin.high();
_diagOutPin.high();
Expand Down Expand Up @@ -99,15 +104,23 @@ bool CRIO::pollPots() {
void CRIO::updateLcd() {
}

void CRIO::updateLcdAll() {
}

void CRIO::updateCoeff() {
}

void CRIO::updateLcdCoeff() {
}

void CRIO::runPcm() {
}

#ifdef CR_UI
DigitalPin<fixedVarPulseInPin> _fixedVarInPin(INPUT, LOW);
DigitalPin<percussionEnableInPin> _percussionEnableInPin(INPUT, LOW);
DigitalPin<pcmMidiInPin> _pcmMidiPin(INPUT, LOW);
DigitalPin<pcmInPin> _pcmPin(INPUT, LOW);

// TODO: Regular LCD library uses timers and isn't interruptable.
#include "CRLiquidCrystal.h"
Expand Down Expand Up @@ -144,6 +157,10 @@ bool CRIOLcd::fixedPulseEnabled() {
return _fixedVarInPin.read();
}

bool CRIOLcd::midiEnabled() {
return _pcmMidiPin.read();
}

inline cr_fp_t CRIOLcd::_scalePot(uint8_t pin) {
uint16_t sample = analogRead(pin);
sample = sample >> 2 << 2;
Expand Down Expand Up @@ -171,6 +188,25 @@ bool CRIOLcd::pollPots() {
return false;
}

void CRIOLcd::updateLcdAll() {
for (byte i = 0; i < sizeof(_lcdBuffer); ++i) {
updateLcd();
}
}

void CRIOLcd::runPcm() {
memset(_lcdLine1, ' ', lcdWidth);
const char pcmDisplay[] = "PCM";
memcpy(_lcdLine1, pcmDisplay, sizeof(pcmDisplay));
updateLcdAll();
for (;;) {
pulseOff();
while (!_pcmPin.read()) {};
pulseOn();
while (_pcmPin.read()) {};
}
}

void CRIOLcd::updateLcd() {
char c = _lcdBuffer[_lcdRow][_lcdCol];
if (c == 0) {
Expand Down
10 changes: 8 additions & 2 deletions CRIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ class CRIO {
void schedulePulse(cr_fp_t pulseUs);
virtual bool handlePulse();
virtual void updateLcd();
virtual void updateLcdAll();
virtual bool pollPots();
virtual void updateCoeff();
virtual void updateLcdCoeff();
virtual bool percussionEnabled();
virtual bool fixedPulseEnabled();
virtual bool midiEnabled();
virtual void runPcm();
void pulseOff();
void pulseOn();
cr_fp_t pw;
uint8_t maxPitch;
cr_fp_t breakoutUs;
Expand All @@ -48,8 +53,6 @@ class CRIO {
bool handleLongPulse();
bool handlePulseOff();
bool handleNoPulse();
void pulseOff();
void pulseOn();
bool (CRIO::*handlePulsePtr)(void);
cr_pulse_t _remainingPulseUs;
uint16_t _ticksSinceLastPulse;
Expand All @@ -60,11 +63,14 @@ class CRIOLcd : public CRIO {
public:
CRIOLcd();
void updateLcd() override;
void updateLcdAll() override;
bool pollPots() override;
void updateCoeff() override;
void updateLcdCoeff() override;
bool percussionEnabled() override;
bool fixedPulseEnabled() override;
bool midiEnabled() override;
void runPcm() override;
private:
cr_fp_t _scalePot(uint8_t);
char _lcdBuffer[lcdLines][lcdWidth+1];
Expand Down
4 changes: 4 additions & 0 deletions chime_red2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ void enableMidi() {
// cppcheck-suppress unusedFunction
void setup() {
resetAll();
if (!crio.midiEnabled()) {
crio.runPcm();
}
enableMidi();
crio.updateLcdAll();
}

// cppcheck-suppress unusedFunction
Expand Down
2 changes: 2 additions & 0 deletions pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
const uint8_t coilOutPin = 11;
const uint8_t diagOutPin = 12;
const uint8_t speakerOutPin = 13;
const uint8_t pcmInPin = 2;
const uint8_t fixedVarPulseInPin = 32;
const uint8_t percussionEnableInPin = 36;
const uint8_t pcmMidiInPin = 44;

const uint8_t lcd_d7 = 45;
const uint8_t lcd_d6 = 43;
Expand Down