2020-05-25 09:43:34 +02:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <CommandStation.h>
|
2020-05-25 12:56:03 +02:00
|
|
|
#include <ArduinoTimers.h>
|
2020-05-25 09:43:34 +02:00
|
|
|
|
2020-06-12 03:30:45 +02:00
|
|
|
const uint8_t kIRQmicros = 29;
|
|
|
|
const uint8_t kNumLocos = 50;
|
2020-06-03 00:37:58 +02:00
|
|
|
|
2020-05-26 11:16:05 +02:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
// Motor driver selection:
|
|
|
|
// Comment out all but the two lines that you want to use
|
|
|
|
|
2020-06-12 03:30:45 +02:00
|
|
|
// DCCMain* mainTrack = DCCMain::Create_WSM_SAMCommandStation_Main(kNumLocos);
|
|
|
|
// DCCService* progTrack = DCCService::Create_WSM_SAMCommandStation_Prog();
|
2020-05-26 11:16:05 +02:00
|
|
|
|
2020-06-12 03:30:45 +02:00
|
|
|
// DCCMain* mainTrack = DCCMain::Create_Arduino_L298Shield_Main(kNumLocos);
|
|
|
|
// DCCService* progTrack = DCCService::Create_Arduino_L298Shield_Prog();
|
2020-06-11 21:24:00 +02:00
|
|
|
|
2020-06-12 03:30:45 +02:00
|
|
|
DCCMain* mainTrack = DCCMain::Create_Pololu_MC33926Shield_Main(kNumLocos);
|
2020-06-11 21:24:00 +02:00
|
|
|
DCCService* progTrack = DCCService::Create_Pololu_MC33926Shield_Prog();
|
2020-05-26 11:16:05 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
2020-05-25 09:43:34 +02:00
|
|
|
|
2020-05-30 23:47:12 +02:00
|
|
|
void waveform_IrqHandler() {
|
2020-06-11 21:24:00 +02:00
|
|
|
mainTrack->interruptHandler();
|
|
|
|
progTrack->interruptHandler();
|
2020-05-25 09:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 23:47:12 +02:00
|
|
|
#if defined(ARDUINO_ARCH_SAMD)
|
2020-06-02 00:31:23 +02:00
|
|
|
void SERCOM4_Handler()
|
2020-05-30 23:47:12 +02:00
|
|
|
{
|
2020-06-11 21:24:00 +02:00
|
|
|
mainTrack->railcom.getSerial()->IrqHandler();
|
2020-05-30 23:47:12 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-25 09:43:34 +02:00
|
|
|
void setup() {
|
2020-06-12 03:30:45 +02:00
|
|
|
mainTrack->setup();
|
|
|
|
progTrack->setup();
|
2020-06-03 00:37:58 +02:00
|
|
|
|
2020-06-11 21:24:00 +02:00
|
|
|
// TimerA is TCC0 on SAMD21, Timer1 on MEGA2560, and Timer1 on MEGA328
|
|
|
|
// We will fire an interrupt every 29us to generate the signal on the track
|
|
|
|
TimerA.initialize();
|
2020-06-12 03:30:45 +02:00
|
|
|
TimerA.setPeriod(kIRQmicros);
|
2020-06-11 21:24:00 +02:00
|
|
|
TimerA.attachInterrupt(waveform_IrqHandler);
|
|
|
|
TimerA.start();
|
2020-05-26 11:16:05 +02:00
|
|
|
|
|
|
|
#if defined (ARDUINO_ARCH_SAMD)
|
2020-06-12 03:30:45 +02:00
|
|
|
CommManager::registerInterface(new USBInterface(SerialUSB));
|
2020-06-11 21:24:00 +02:00
|
|
|
Wire.begin(); // Needed for EEPROM to work
|
2020-05-26 11:16:05 +02:00
|
|
|
#elif defined(ARDUINO_ARCH_AVR)
|
2020-06-12 03:30:45 +02:00
|
|
|
CommManager::registerInterface(new SerialInterface(Serial));
|
2020-05-25 09:43:34 +02:00
|
|
|
#endif
|
|
|
|
|
2020-06-11 21:24:00 +02:00
|
|
|
EEStore::init();
|
2020-05-26 11:16:05 +02:00
|
|
|
|
2020-06-12 03:30:45 +02:00
|
|
|
// Set up the string parser to accept commands from the interfaces
|
|
|
|
DCCEXParser::init(mainTrack, progTrack);
|
|
|
|
|
2020-06-11 21:24:00 +02:00
|
|
|
CommManager::showInitInfo();
|
2020-05-25 09:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2020-06-11 21:24:00 +02:00
|
|
|
CommManager::update();
|
|
|
|
mainTrack->loop();
|
|
|
|
progTrack->loop();
|
2020-05-30 11:03:19 +02:00
|
|
|
}
|
|
|
|
|