From 5c0ab9a31100bf22f3174dab1ffd983a6b7698a0 Mon Sep 17 00:00:00 2001 From: travis-farmer Date: Fri, 10 Nov 2023 08:56:21 -0500 Subject: [PATCH] pre-test storing of signal updates --- DCCTimerGiga.cpp | 92 ++++++++++++++++++------------------------------ TrackManager.h | 5 ++- 2 files changed, 39 insertions(+), 58 deletions(-) diff --git a/DCCTimerGiga.cpp b/DCCTimerGiga.cpp index 3217528..3ac964c 100644 --- a/DCCTimerGiga.cpp +++ b/DCCTimerGiga.cpp @@ -43,14 +43,19 @@ INTERRUPT_CALLBACK interruptHandler=0; -//HardwareTimer* timer = NULL; -//HardwareTimer* timerAux = NULL; -HardwareTimer timer(TIM3); -HardwareTimer timerAux(TIM2); - -static bool tim2ModeHA = false; -static bool tim3ModeHA = false; +#ifndef DCC_EX_TIMER +#if defined(TIM6) +#define DCC_EX_TIMER TIM6 +#elif defined(TIM7) +#define DCC_EX_TIMER TIM7 +#elif defined(TIM12) +#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() { @@ -59,66 +64,38 @@ void DCCTimer_Handler() { void DCCTimer::begin(INTERRUPT_CALLBACK callback) { interruptHandler=callback; - 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(); + noInterrupts(); - timer.resume(); - timerAux.resume(); + dcctimer.pause(); + 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) { - switch (pin) { - case 12: - return true; - case 13: - return true; - default: - return false; - } + //TODO: STM32 whilst this call to digitalPinHasPWM will reveal which pins can do PWM, + // there's no support yet for High Accuracy, so for now return false + // return digitalPinHasPWM(pin); + (void) pin; + return false; } void DCCTimer::setPWM(byte pin, bool high) { - switch (pin) { - case 12: - if (!tim3ModeHA) { - timerAux.setMode(1, TIMER_OUTPUT_COMPARE_INACTIVE, 12); - 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; - } + // TODO: High Accuracy mode is not supported as yet, and may never need to be + (void) pin; + (void) high; + return; } void DCCTimer::clearPWM() { - timer.setMode(1, TIMER_OUTPUT_COMPARE_INACTIVE, NC); - tim2ModeHA = false; - timerAux.setMode(1, TIMER_OUTPUT_COMPARE_INACTIVE, NC); - tim3ModeHA = false; + return; } void DCCTimer::getSimulatedMacAddress(byte mac[6]) { @@ -161,6 +138,7 @@ void DCCTimer::reset() { //Watchdog::start(500); //while(true) {}; + return; } int * ADCee::analogvals = NULL; @@ -170,7 +148,7 @@ int16_t ADCee::ADCmax() return 1023; } -AdvancedADC adc(A0, A1); +AdvancedADC adc(A0, A1, A2, A3); int ADCee::init(uint8_t pin) { adc.begin(AN_RESOLUTION_10, 16000, 1, 512); return 123; diff --git a/TrackManager.h b/TrackManager.h index d197751..b098073 100644 --- a/TrackManager.h +++ b/TrackManager.h @@ -72,8 +72,11 @@ class TrackManager { static void setJoinPower(POWERMODE mode) {setPower2(false,true,mode);} 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; +#endif // giga static bool setTrackMode(byte track, TRACK_MODE mode, int16_t DCaddr=0); static bool parseJ(Print * stream, int16_t params, int16_t p[]); static void loop();