Skip to content

Commit

Permalink
Merge pull request #13 from anarkiwi/freq
Browse files Browse the repository at this point in the history
optimize even divis.
  • Loading branch information
anarkiwi committed Aug 8, 2022
2 parents 85eac7b + 3b378a1 commit 744f2a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
27 changes: 15 additions & 12 deletions CRIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ bool CRIO::handlePulse() {
return (this->*handlePulsePtr)();
}

bool CRIO::handlePulseOff() {
pulseOff();
return handleNoPulse();
}

bool CRIO::handleNoPulse() {
++_ticksSinceLastPulse;
return false;
Expand All @@ -53,26 +58,24 @@ bool CRIO::handleLongPulse() {
pulseOn();
++_ticksSinceLastPulse;
_remainingPulseUs -= masterClockPeriodUs;
if (_remainingPulseUs <= masterClockPeriodUs) {
handlePulsePtr = &CRIO::handleShortPulse;
if (_remainingPulseUs) {
if (_remainingPulseUs < masterClockPeriodUs) {
handlePulsePtr = &CRIO::handleShortPulse;
}
} else {
handlePulsePtr = &CRIO::handlePulseOff;
}
return false;
}

bool CRIO::handleShortPulse() {
if (_remainingPulseUs) {
pulseOn();
delayMicroseconds(_remainingPulseUs);
pulseOff();
_remainingPulseUs = 0;
++_ticksSinceLastPulse;
handlePulsePtr = &CRIO::handleNoPulse;
return true;
}
pulseOn();
delayMicroseconds(_remainingPulseUs);
pulseOff();
_remainingPulseUs = 0;
++_ticksSinceLastPulse;
handlePulsePtr = &CRIO::handleNoPulse;
return false;
return true;
}

void CRIO::schedulePulse(cr_fp_t pulseUs) {
Expand Down
1 change: 1 addition & 0 deletions CRIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CRIO {
private:
bool handleShortPulse();
bool handleLongPulse();
bool handlePulseOff();
bool handleNoPulse();
void pulseOff();
void pulseOn();
Expand Down

0 comments on commit 744f2a2

Please sign in to comment.