From a33270dff389abbc44dcb2d149779704a5630eb5 Mon Sep 17 00:00:00 2001 From: David Cutting Date: Sat, 30 May 2020 03:03:19 -0600 Subject: [PATCH 1/4] Added railcom stuff --- src/main.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9a03cc4..7f5f6ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,20 +2,30 @@ #include #include -#define DCC_IRQ_MICROSECONDS 58 +#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 //////////////////////////////////////////////////////////////// // Motor driver selection: // Comment out all but the two lines that you want to use -// DCC* mainTrack = DCC::Create_WSM_SAMCommandStation_Main(50); -// DCC* progTrack = DCC::Create_WSM_SAMCommandStation_Prog(2); +DCC* mainTrack = DCC::Create_WSM_SAMCommandStation_Main(50); +DCC* progTrack = DCC::Create_WSM_SAMCommandStation_Prog(2); // DCC* mainTrack = DCC::Create_Arduino_L298Shield_Main(50); // DCC* progTrack = DCC::Create_Arduino_L298Shield_Prog(2); -DCC* mainTrack = DCC::Create_Pololu_MC33926Shield_Main(50); -DCC* progTrack = DCC::Create_Pololu_MC33926Shield_Prog(2); +// DCC* mainTrack = DCC::Create_Pololu_MC33926Shield_Main(50); +// DCC* progTrack = DCC::Create_Pololu_MC33926Shield_Prog(2); //////////////////////////////////////////////////////////////// @@ -32,6 +42,8 @@ void setup() { TimerA.attachInterrupt(main_IrqHandler); TimerA.start(); + mainRailcomUART.begin(250000); + #if defined (ARDUINO_ARCH_SAMD) CommManager::registerInterface(new USBInterface(SerialUSB)); // Register SerialUSB as an interface Wire.begin(); // Needed for EEPROM to work @@ -49,4 +61,5 @@ void loop() { CommManager::update(); mainTrack->loop(); progTrack->loop(); -} \ No newline at end of file +} + From 1dd214931f0a4062bf55292f7e90b3c0ddde815d Mon Sep 17 00:00:00 2001 From: David Cutting Date: Sat, 30 May 2020 13:06:45 -0600 Subject: [PATCH 2/4] Update main file to reflect library changes --- src/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7f5f6ae..4da0d75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,9 @@ void main_IrqHandler() { } void setup() { + mainTrack->hdw.init(); + progTrack->hdw.init(); + // 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(); @@ -53,7 +56,7 @@ void setup() { EEStore::init(); - StringParser::init(mainTrack, progTrack); // Set up the string parser to accept commands from the interfaces + JMRIParser::init(mainTrack, progTrack); // Set up the string parser to accept commands from the interfaces CommManager::showInitInfo(); } From ea3153279bfa4292180962c7cce68dac19a78efa Mon Sep 17 00:00:00 2001 From: David Cutting Date: Sat, 30 May 2020 15:47:12 -0600 Subject: [PATCH 3/4] More main file cleanup to reflect library changes --- src/main.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4da0d75..604633b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,16 +4,6 @@ #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 - //////////////////////////////////////////////////////////////// // Motor driver selection: // Comment out all but the two lines that you want to use @@ -29,11 +19,18 @@ DCC* progTrack = DCC::Create_WSM_SAMCommandStation_Prog(2); //////////////////////////////////////////////////////////////// -void main_IrqHandler() { +void waveform_IrqHandler() { mainTrack->interruptHandler(); progTrack->interruptHandler(); } +#if defined(ARDUINO_ARCH_SAMD) +void SERCOM2_Handler() +{ + mainTrack->hdw.railcom_serial->IrqHandler(); +} +#endif + void setup() { mainTrack->hdw.init(); progTrack->hdw.init(); @@ -42,11 +39,9 @@ void setup() { // 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.attachInterrupt(waveform_IrqHandler); TimerA.start(); - mainRailcomUART.begin(250000); - #if defined (ARDUINO_ARCH_SAMD) CommManager::registerInterface(new USBInterface(SerialUSB)); // Register SerialUSB as an interface Wire.begin(); // Needed for EEPROM to work From 9f60df9f01afd11bfa9cfceb35eca329345b823d Mon Sep 17 00:00:00 2001 From: David Cutting Date: Mon, 1 Jun 2020 16:31:23 -0600 Subject: [PATCH 4/4] Remove build flags and switch back to SERCOM4 --- platformio.ini | 5 +---- src/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index b133bed..2fb4226 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,7 +24,6 @@ upload_protocol = atmel-ice lib_deps = ${env.lib_deps} SparkFun External EEPROM Arduino Library -build_flags = -D ATSAMD21G [env:mega2560] platform = atmelavr @@ -33,7 +32,6 @@ framework = arduino lib_deps = ${env.lib_deps} DIO2 -build_flags = -D ATMEGA2560 [env:mega328] platform = atmelavr @@ -41,5 +39,4 @@ board = uno framework = arduino lib_deps = ${env.lib_deps} - DIO2 -build_flags = -D ATMEGA328 \ No newline at end of file + DIO2 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 604633b..10584d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ void waveform_IrqHandler() { } #if defined(ARDUINO_ARCH_SAMD) -void SERCOM2_Handler() +void SERCOM4_Handler() { mainTrack->hdw.railcom_serial->IrqHandler(); } @@ -52,7 +52,7 @@ void setup() { EEStore::init(); JMRIParser::init(mainTrack, progTrack); // Set up the string parser to accept commands from the interfaces - CommManager::showInitInfo(); + CommManager::showInitInfo(); } void loop() {