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-05-30 11:03:19 +02:00
|
|
|
#define DCC_IRQ_MICROSECONDS 29
|
|
|
|
|
2020-06-03 00:37:58 +02:00
|
|
|
#if defined(ARDUINO_AVR_UNO)
|
|
|
|
#define NUM_LOCOS_MAIN 20
|
|
|
|
#else
|
|
|
|
#define NUM_LOCOS_MAIN 50
|
|
|
|
#endif
|
|
|
|
|
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-03 00:37:58 +02:00
|
|
|
// DCC* mainTrack = DCC::Create_WSM_SAMCommandStation_Main(NUM_LOCOS_MAIN);
|
2020-06-02 21:46:37 +02:00
|
|
|
// DCC* progTrack = DCC::Create_WSM_SAMCommandStation_Prog(2);
|
2020-05-26 11:16:05 +02:00
|
|
|
|
2020-06-03 00:37:58 +02:00
|
|
|
DCC* mainTrack = DCC::Create_Arduino_L298Shield_Main(NUM_LOCOS_MAIN);
|
2020-06-02 21:46:37 +02:00
|
|
|
DCC* progTrack = DCC::Create_Arduino_L298Shield_Prog(2);
|
2020-05-26 11:16:05 +02:00
|
|
|
|
2020-06-03 00:37:58 +02:00
|
|
|
// DCC* mainTrack = DCC::Create_Pololu_MC33926Shield_Main(NUM_LOCOS_MAIN);
|
2020-05-30 11:03:19 +02:00
|
|
|
// DCC* progTrack = DCC::Create_Pololu_MC33926Shield_Prog(2);
|
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-05-26 11:16:05 +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-02 21:46:37 +02:00
|
|
|
mainTrack->hdw.railcomSerial()->IrqHandler();
|
2020-05-30 23:47:12 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-25 09:43:34 +02:00
|
|
|
void setup() {
|
2020-06-02 21:46:37 +02:00
|
|
|
mainTrack->hdw.setup();
|
|
|
|
progTrack->hdw.setup();
|
2020-06-03 00:37:58 +02:00
|
|
|
|
2020-05-26 11:16:05 +02:00
|
|
|
// TimerA is TCC0 on SAMD21, Timer1 on MEGA2560, and Timer1 on MEGA328
|
2020-06-02 21:46:37 +02:00
|
|
|
// We will fire an interrupt every 29us to generate the signal on the track
|
2020-05-26 11:16:05 +02:00
|
|
|
TimerA.initialize();
|
|
|
|
TimerA.setPeriod(DCC_IRQ_MICROSECONDS);
|
2020-05-30 23:47:12 +02:00
|
|
|
TimerA.attachInterrupt(waveform_IrqHandler);
|
2020-05-26 11:16:05 +02:00
|
|
|
TimerA.start();
|
|
|
|
|
|
|
|
#if defined (ARDUINO_ARCH_SAMD)
|
2020-05-25 12:56:03 +02:00
|
|
|
CommManager::registerInterface(new USBInterface(SerialUSB)); // Register SerialUSB as an interface
|
2020-05-28 06:56:29 +02:00
|
|
|
Wire.begin(); // Needed for EEPROM to work
|
2020-05-26 11:16:05 +02:00
|
|
|
#elif defined(ARDUINO_ARCH_AVR)
|
2020-05-25 09:43:34 +02:00
|
|
|
CommManager::registerInterface(new SerialInterface(Serial)); // Register Serial (USB port on mega/uno) as an interface
|
|
|
|
#endif
|
|
|
|
|
2020-05-28 06:56:29 +02:00
|
|
|
EEStore::init();
|
2020-05-26 11:16:05 +02:00
|
|
|
|
2020-06-04 20:45:49 +02:00
|
|
|
DCCEXParser::init(mainTrack, progTrack); // Set up the string parser to accept commands from the interfaces
|
2020-06-02 00:31:23 +02:00
|
|
|
CommManager::showInitInfo();
|
2020-05-25 09:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
CommManager::update();
|
2020-05-26 11:16:05 +02:00
|
|
|
mainTrack->loop();
|
|
|
|
progTrack->loop();
|
2020-05-30 11:03:19 +02:00
|
|
|
}
|
|
|
|
|