1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-24 08:36:14 +01:00

pre-test storing of signal updates

This commit is contained in:
travis-farmer 2023-11-10 08:56:21 -05:00
parent c458e98cd3
commit 5c0ab9a311
No known key found for this signature in database
GPG Key ID: 0BC296791D14CB35
2 changed files with 39 additions and 58 deletions

View File

@ -43,14 +43,19 @@
INTERRUPT_CALLBACK interruptHandler=0; INTERRUPT_CALLBACK interruptHandler=0;
//HardwareTimer* timer = NULL; #ifndef DCC_EX_TIMER
//HardwareTimer* timerAux = NULL; #if defined(TIM6)
HardwareTimer timer(TIM3); #define DCC_EX_TIMER TIM6
HardwareTimer timerAux(TIM2); #elif defined(TIM7)
#define DCC_EX_TIMER TIM7
static bool tim2ModeHA = false; #elif defined(TIM12)
static bool tim3ModeHA = false; #define DCC_EX_TIMER TIM12
#else
#warning This Giga variant does not have Timers 1,8 or 11!!
#endif
#endif // ifndef DCC_EX_TIMER
HardwareTimer dcctimer(TIM8);
void DCCTimer_Handler() __attribute__((interrupt)); void DCCTimer_Handler() __attribute__((interrupt));
void DCCTimer_Handler() { void DCCTimer_Handler() {
@ -59,66 +64,38 @@ void DCCTimer_Handler() {
void DCCTimer::begin(INTERRUPT_CALLBACK callback) { void DCCTimer::begin(INTERRUPT_CALLBACK callback) {
interruptHandler=callback; interruptHandler=callback;
noInterrupts(); noInterrupts();
// adc_set_sample_rate(ADC_SAMPLETIME_480CYCLES);
timer.pause();
timerAux.pause();
timer.setPrescaleFactor(1);
timer.setOverflow(DCC_SIGNAL_TIME, MICROSEC_FORMAT);
timer.attachInterrupt(DCCTimer_Handler);
timer.refresh();
timerAux.setPrescaleFactor(1);
timerAux.setOverflow(DCC_SIGNAL_TIME, MICROSEC_FORMAT);
timerAux.refresh();
timer.resume(); dcctimer.pause();
timerAux.resume(); dcctimer.setPrescaleFactor(1);
// timer.setOverflow(CLOCK_CYCLES * 2);
dcctimer.setOverflow(DCC_SIGNAL_TIME, MICROSEC_FORMAT);
// dcctimer.attachInterrupt(Timer11_Handler);
dcctimer.attachInterrupt(DCCTimer_Handler);
dcctimer.setInterruptPriority(0, 0); // Set highest preemptive priority!
dcctimer.refresh();
dcctimer.resume();
interrupts(); interrupts();
} }
bool DCCTimer::isPWMPin(byte pin) { bool DCCTimer::isPWMPin(byte pin) {
switch (pin) { //TODO: STM32 whilst this call to digitalPinHasPWM will reveal which pins can do PWM,
case 12: // there's no support yet for High Accuracy, so for now return false
return true; // return digitalPinHasPWM(pin);
case 13: (void) pin;
return true; return false;
default:
return false;
}
} }
void DCCTimer::setPWM(byte pin, bool high) { void DCCTimer::setPWM(byte pin, bool high) {
switch (pin) { // TODO: High Accuracy mode is not supported as yet, and may never need to be
case 12: (void) pin;
if (!tim3ModeHA) { (void) high;
timerAux.setMode(1, TIMER_OUTPUT_COMPARE_INACTIVE, 12); return;
tim3ModeHA = true;
}
if (high)
TIM3->CCMR1 = (TIM3->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_0;
else
TIM3->CCMR1 = (TIM3->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_1;
break;
case 13:
if (!tim2ModeHA) {
timer.setMode(1, TIMER_OUTPUT_COMPARE_INACTIVE, 13);
tim2ModeHA = true;
}
if (high)
TIM2->CCMR1 = (TIM2->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_0;
else
TIM2->CCMR1 = (TIM2->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_1;
break;
}
} }
void DCCTimer::clearPWM() { void DCCTimer::clearPWM() {
timer.setMode(1, TIMER_OUTPUT_COMPARE_INACTIVE, NC); return;
tim2ModeHA = false;
timerAux.setMode(1, TIMER_OUTPUT_COMPARE_INACTIVE, NC);
tim3ModeHA = false;
} }
void DCCTimer::getSimulatedMacAddress(byte mac[6]) { void DCCTimer::getSimulatedMacAddress(byte mac[6]) {
@ -161,6 +138,7 @@ void DCCTimer::reset() {
//Watchdog::start(500); //Watchdog::start(500);
//while(true) {}; //while(true) {};
return;
} }
int * ADCee::analogvals = NULL; int * ADCee::analogvals = NULL;
@ -170,7 +148,7 @@ int16_t ADCee::ADCmax()
return 1023; return 1023;
} }
AdvancedADC adc(A0, A1); AdvancedADC adc(A0, A1, A2, A3);
int ADCee::init(uint8_t pin) { int ADCee::init(uint8_t pin) {
adc.begin(AN_RESOLUTION_10, 16000, 1, 512); adc.begin(AN_RESOLUTION_10, 16000, 1, 512);
return 123; return 123;

View File

@ -72,8 +72,11 @@ class TrackManager {
static void setJoinPower(POWERMODE mode) {setPower2(false,true,mode);} static void setJoinPower(POWERMODE mode) {setPower2(false,true,mode);}
static void setTrackPower(bool setProg, bool setJoin, POWERMODE mode, byte thistrack); static void setTrackPower(bool setProg, bool setJoin, POWERMODE mode, byte thistrack);
#if defined(ARduINO_GIGA) // yes giga
static const int16_t MAX_TRACKS=4;
#else // no giga
static const int16_t MAX_TRACKS=8; static const int16_t MAX_TRACKS=8;
#endif // giga
static bool setTrackMode(byte track, TRACK_MODE mode, int16_t DCaddr=0); static bool setTrackMode(byte track, TRACK_MODE mode, int16_t DCaddr=0);
static bool parseJ(Print * stream, int16_t params, int16_t p[]); static bool parseJ(Print * stream, int16_t params, int16_t p[]);
static void loop(); static void loop();