1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-24 03:18:51 +01:00

Select Pololu Motor shield

This commit is contained in:
David Cutting 2020-05-26 03:16:05 -06:00
parent 7455a45f4d
commit 37824f586b
4 changed files with 46 additions and 74 deletions

View File

@ -1,39 +0,0 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@ -9,15 +9,13 @@
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = samd21, mega2560
default_envs = samd21
[env]
lib_deps =
https://github.com/davidcutting42/CommandStation.git#master
https://github.com/davidcutting42/ArduinoTimers.git#master
SparkFun External EEPROM Arduino Library
DIO2
[env:samd21]
platform = atmelsam
board = sparkfun_samd21_dev_usb
@ -25,6 +23,7 @@ framework = arduino
upload_protocol = atmel-ice
lib_deps =
${env.lib_deps}
SparkFun External EEPROM Arduino Library
build_flags = -D ATSAMD21G
[env:mega2560]
@ -33,4 +32,14 @@ board = megaatmega2560
framework = arduino
lib_deps =
${env.lib_deps}
build_flags = -D ATMEGA2560
DIO2
build_flags = -D ATMEGA2560
[env:mega328]
platform = atmelavr
board = uno
framework = arduino
lib_deps =
${env.lib_deps}
DIO2
build_flags = -D ATMEGA328

View File

@ -2,37 +2,50 @@
#include <CommandStation.h>
#include <ArduinoTimers.h>
DCC* mainTrack = DCC::Create_WSM_SAMCommandStation_Main(50);
DCC* progTrack = DCC::Create_WSM_SAMCommandStation_Prog(2);
#define DCC_IRQ_MICROSECONDS 58
////////////////////////////////////////////////////////////////
// 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_Arduino_L298Shield_Main(50);
// DCC* progTrack = DCC::Create_Arduino_L298Shield_Prog(2);
DCC* mainTrack = DCC::Create_Pololu_MC33926Shield_Main(10);
DCC* progTrack = DCC::Create_Pololu_MC33926Shield_Prog(2);
////////////////////////////////////////////////////////////////
void main_IrqHandler() {
mainTrack->interrupt_handler();
progTrack->interrupt_handler();
mainTrack->interruptHandler();
progTrack->interruptHandler();
}
void setup() {
#if defined (ATSAMD21G)
CommManager::registerInterface(new USBInterface(SerialUSB)); // Register SerialUSB as an interface
TimerTCC0.initialize();
TimerTCC0.setPeriod(58);
TimerTCC0.attachInterrupt(main_IrqHandler);
TimerTCC0.start();
#elif defined(ATMEGA2560)
CommManager::registerInterface(new SerialInterface(Serial)); // Register Serial (USB port on mega/uno) as an interface
// 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();
Timer3.initialize();
Timer3.setPeriod(58);
Timer3.attachInterrupt(main_IrqHandler);
Timer3.start();
#if defined (ARDUINO_ARCH_SAMD)
CommManager::registerInterface(new USBInterface(SerialUSB)); // Register SerialUSB as an interface
#elif defined(ARDUINO_ARCH_AVR)
CommManager::registerInterface(new SerialInterface(Serial)); // Register Serial (USB port on mega/uno) as an interface
#endif
//EEStore::init();
StringParser::init(mainTrack, progTrack); // Set up the string parser to accept commands from the interfaces
CommManager::showInitInfo();
}
void loop() {
CommManager::update();
mainTrack->check();
progTrack->check();
mainTrack->loop();
progTrack->loop();
}

View File

@ -1,11 +0,0 @@
This directory is intended for PIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html