1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00
CommandStation-EX/src/main.cpp

69 lines
2.0 KiB
C++
Raw Normal View History

2020-05-25 09:43:34 +02:00
#include <Arduino.h>
#include <CommandStation.h>
#include <ArduinoTimers.h>
2020-05-25 09:43:34 +02:00
2020-05-30 11:03:19 +02:00
#define DCC_IRQ_MICROSECONDS 29
#if defined(ARDUINO_ARCH_SAMD)
Uart mainRailcomUART(&sercom2, 5, 2, SERCOM_RX_PAD_3, UART_TX_PAD_2);
void SERCOM2_Handler()
{
mainRailcomUART.IrqHandler();
}
#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-05-30 11:03:19 +02:00
DCC* mainTrack = DCC::Create_WSM_SAMCommandStation_Main(50);
DCC* progTrack = DCC::Create_WSM_SAMCommandStation_Prog(2);
2020-05-26 11:16:05 +02:00
// DCC* mainTrack = DCC::Create_Arduino_L298Shield_Main(50);
// DCC* progTrack = DCC::Create_Arduino_L298Shield_Prog(2);
2020-05-30 11:03:19 +02:00
// DCC* mainTrack = DCC::Create_Pololu_MC33926Shield_Main(50);
// DCC* progTrack = DCC::Create_Pololu_MC33926Shield_Prog(2);
2020-05-26 11:16:05 +02:00
////////////////////////////////////////////////////////////////
2020-05-25 09:43:34 +02:00
void main_IrqHandler() {
2020-05-26 11:16:05 +02:00
mainTrack->interruptHandler();
progTrack->interruptHandler();
2020-05-25 09:43:34 +02:00
}
void setup() {
mainTrack->hdw.init();
progTrack->hdw.init();
2020-05-26 11:16:05 +02:00
// TimerA is TCC0 on SAMD21, Timer1 on MEGA2560, and Timer1 on MEGA328
// We will fire an interrupt every 58us to generate the signal on the track
TimerA.initialize();
TimerA.setPeriod(DCC_IRQ_MICROSECONDS);
TimerA.attachInterrupt(main_IrqHandler);
TimerA.start();
2020-05-30 11:03:19 +02:00
mainRailcomUART.begin(250000);
2020-05-26 11:16:05 +02:00
#if defined (ARDUINO_ARCH_SAMD)
CommManager::registerInterface(new USBInterface(SerialUSB)); // Register SerialUSB as an interface
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
EEStore::init();
2020-05-26 11:16:05 +02:00
JMRIParser::init(mainTrack, progTrack); // Set up the string parser to accept commands from the interfaces
2020-05-25 09:43:34 +02:00
CommManager::showInitInfo();
}
void loop() {
CommManager::update();
2020-05-26 11:16:05 +02:00
mainTrack->loop();
progTrack->loop();
2020-05-30 11:03:19 +02:00
}