DCCpp
This is the library version of a program for Arduino to control railroading DCC devices.
Config.h
1 /**********************************************************************
2 
3 Config.h
4 COPYRIGHT (c) 2013-2016 Gregg E. Berman
5 Adapted for DcDcc by Thierry PARIS
6 
7 Part of DCC++ BASE STATION for the Arduino
8 
9 **********************************************************************/
10 #ifndef __config_h
11 #define __config_h
12 
13 #include "Arduino.h"
14 
16 #define UNDEFINED_PIN 255
17 
19 //
20 // DEFINE NUMBER OF MAIN TRACK REGISTER
21 
22 #if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) // Configuration for UNO or NANO
23 
25 #define MAX_MAIN_REGISTERS 12
26 
27 #elif defined(ARDUINO_AVR_MEGA2560)
28 
30 #define MAX_MAIN_REGISTERS 21
31 
32 #elif defined(ARDUINO_ARCH_ESP32)
33 
35 #define MAX_MAIN_REGISTERS 41
36 
37 #endif
38 
40 #define MAX_PROG_REGISTERS 3
41 
43 //
44 // DEFINE PINS ACCORDING TO MOTOR SHIELD MODEL
45 //
46 
47 #ifdef ARDUINO_AVR_MEGA // is using Mega 1280, define as Mega 2560 (pinouts and functionality are identical)
48 #ifndef ARDUINO_AVR_MEGA2560
49 #define ARDUINO_AVR_MEGA2560
50 #endif
51 #endif
52 
53 #if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) // Configuration for UNO or NANO
54 
56 #define DCC_SIGNAL_PIN_MAIN 10 // Arduino Uno - uses OC1B
57 
58 #define DCC_SIGNAL_PIN_PROG 5 // Arduino Uno - uses OC0B
59 
60 #elif defined(ARDUINO_AVR_MEGA2560)
61 
62 #define DCC_SIGNAL_PIN_MAIN 12 // Arduino Mega - uses OC1B
63 #define DCC_SIGNAL_PIN_PROG 2 // Arduino Mega - uses OC3B
64 
65 #endif
66 
68 // SELECT MOTOR SHIELD
70 
72 #define MOTOR_SHIELD_SIGNAL_ENABLE_PIN_MAIN 3
73 #define MOTOR_SHIELD_SIGNAL_ENABLE_PIN_PROG 11
74 
75 #define MOTOR_SHIELD_CURRENT_MONITOR_PIN_MAIN A0
76 #define MOTOR_SHIELD_CURRENT_MONITOR_PIN_PROG A1
77 
78 #define MOTOR_SHIELD_DIRECTION_MOTOR_CHANNEL_PIN_A 12
79 #define MOTOR_SHIELD_DIRECTION_MOTOR_CHANNEL_PIN_B 13
80 
81 #define POLOLU_SIGNAL_ENABLE_PIN_MAIN 9
82 #define POLOLU_SIGNAL_ENABLE_PIN_PROG 11
83 
84 #define POLOLU_CURRENT_MONITOR_PIN_MAIN A0
85 #define POLOLU_CURRENT_MONITOR_PIN_PROG A1
86 
87 #define POLOLU_DIRECTION_MOTOR_CHANNEL_PIN_A 7
88 #define POLOLU_DIRECTION_MOTOR_CHANNEL_PIN_B 8
89 
90 #if defined(USE_ETHERNET)
91 enum EthernetProtocol
92 {
93  HTTP,
94  TCP
95 };
96 #endif
97 
99 {
100 #if defined(USE_ETHERNET)
101  static uint8_t EthernetIp[4];
102  static uint8_t EthernetMac[6];
103  static int EthernetPort;
104  static EthernetProtocol Protocol;
105 #endif
106 
107 #ifdef USE_ONLY1_INTERRUPT
108  static uint8_t SignalPortMaskMain;
109  static uint8_t SignalPortMaskProg;
110  static volatile uint8_t *SignalPortInMain;
111  static volatile uint8_t *SignalPortInProg;
112 #endif
113 
114  static byte SignalEnablePinMain; // PWM : *_SIGNAL_ENABLE_PIN_MAIN
115  static byte CurrentMonitorMain; // Current sensor : *_CURRENT_MONITOR_PIN_MAIN
116 
117  static byte SignalEnablePinProg; // PWM : *_SIGNAL_ENABLE_PIN_PROG
118  static byte CurrentMonitorProg; // Current sensor : *_CURRENT_MONITOR_PIN_PROG
119 
120 #ifndef USE_ONLY1_INTERRUPT
121  // Only for shields : indirection of the signal from SignalPinMain to DirectionMotor of the shield
122  static byte DirectionMotorA; // *_DIRECTION_MOTOR_CHANNEL_PIN_A
123  static byte DirectionMotorB; // *_DIRECTION_MOTOR_CHANNEL_PIN_B
124 #endif
125 };
126 
128 
129 #endif