mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-19 23:46:02 +01:00
Teensy double speed interrupt
This commit is contained in:
parent
955362a033
commit
8e71dd8926
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ Release/*
|
|||||||
config.h
|
config.h
|
||||||
.vscode/extensions.json
|
.vscode/extensions.json
|
||||||
mySetup.h
|
mySetup.h
|
||||||
|
myFilter.cpp
|
||||||
|
51
DCCTimer.cpp
51
DCCTimer.cpp
@ -95,30 +95,65 @@ INTERRUPT_CALLBACK interruptHandler=0;
|
|||||||
|
|
||||||
#elif defined(TEENSYDUINO)
|
#elif defined(TEENSYDUINO)
|
||||||
IntervalTimer myDCCTimer;
|
IntervalTimer myDCCTimer;
|
||||||
|
bool interruptFlipflop=false;
|
||||||
|
byte railcomPin[2]={0,0];
|
||||||
|
enum RAILCOM_NEXT:byte {SKIP,CUT_OUT,CUT_IN);
|
||||||
|
RAILCOM_NEXT railcom1Next[]={SKIP,SKIP};
|
||||||
|
|
||||||
void DCCTimer::begin(INTERRUPT_CALLBACK callback) {
|
void DCCTimer::begin(INTERRUPT_CALLBACK callback) {
|
||||||
interruptHandler=callback;
|
interruptHandler=callback;
|
||||||
|
myDCCTimer.begin(interruptFast, DCC_SIGNAL_TIME/2);
|
||||||
|
}
|
||||||
|
|
||||||
myDCCTimer.begin(interruptHandler, DCC_SIGNAL_TIME);
|
// This interrupt happens every 29uS, and alternately calls the DCC waveform
|
||||||
|
// or handles any pending Railcom cutout pins.
|
||||||
|
void interruptFast() {
|
||||||
|
nterruptFlipflop=!interruptFlipflop;
|
||||||
|
if (interruptFiliflop) {
|
||||||
|
interruptHandler();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Railcom interrupt, half way between DCC interruots
|
||||||
|
for (byte channel=0;channel<2;channel++) {
|
||||||
|
byte pin=railcomPin[channel;
|
||||||
|
if (pin) {
|
||||||
|
switch (railcomNext[channel]) {
|
||||||
|
case CUT_OUT:
|
||||||
|
digitalWrite(pin,HIGH);
|
||||||
|
break;
|
||||||
|
case CUT_IN:
|
||||||
|
digitalWrite(pin,HIGH);
|
||||||
|
break;
|
||||||
|
case IGNORE: break;
|
||||||
|
}
|
||||||
|
railcomNext[channel]=IGNORE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DCCTimer::isPWMPin(byte pin) {
|
bool DCCTimer::isPWMPin(byte pin) {
|
||||||
//Teensy: digitalPinHasPWM, todo
|
|
||||||
(void) pin;
|
(void) pin;
|
||||||
return false; // TODO what are the relevant pins?
|
return true; // We are so fast we can pretend we do support this
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DCCTimer::isRailcomPin(byte pin) {
|
bool DCCTimer::isRailcomPin(byte pin) {
|
||||||
//Teensy: digitalPinHasPWM, todo
|
|
||||||
(void) pin;
|
(void) pin;
|
||||||
return false; // TODO what are the relevant pins?
|
if (railcomPin[0]==0) railcomPin[0]=pin;
|
||||||
|
else if (railcomPin[1]==0) railcomPin[1]=pin;
|
||||||
|
else return false;
|
||||||
|
return true; // We are so fast we can pretend we do support this
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCCTimer::setPWM(byte pin, bool high) {
|
void DCCTimer::setPWM(byte pin, bool high) {
|
||||||
// TODO what are the relevant pins?
|
// setting pwm on a railcom pin is deferred to the next railcom interruyupt.
|
||||||
(void) pin;
|
for (byte channel=0;channel<2;channel++) {
|
||||||
(void) high;
|
if (pin==railcomPin[channel]) {
|
||||||
|
railcomNext[channel]=high?CUT_OUT:CUT_IN;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
digitalWrite(pin,high?HIGH:LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCCTimer::getSimulatedMacAddress(byte mac[6]) {
|
void DCCTimer::getSimulatedMacAddress(byte mac[6]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user