From b0388bfc671d2b672c6acfd7501b257aea1e166d Mon Sep 17 00:00:00 2001 From: dexslab Date: Tue, 8 Dec 2020 14:42:21 -0500 Subject: [PATCH] Fixes for compile arduino unowifi r2 --- AnalogReadFast.h | 15 ++++++++++++++- ArduinoTimers.h | 2 +- DCC.h | 2 +- DCCWaveform.cpp | 2 +- Timer.cpp | 12 +++++++++++- platformio.ini | 1 + 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/AnalogReadFast.h b/AnalogReadFast.h index cc474ee..66f1817 100644 --- a/AnalogReadFast.h +++ b/AnalogReadFast.h @@ -25,6 +25,17 @@ #include int inline analogReadFast(uint8_t ADCpin); +#if defined(ARDUINO_AVR_UNO_WIFI_REV2) + +int inline analogReadFast(uint8_t ADCpin) +{ byte ADC0CTRLCoriginal = ADC0.CTRLC; + ADC0.CTRLC = (ADC0CTRLCoriginal & 0b00110000) + 0b01000011; + int adc = analogRead(ADCpin); + ADC0.CTRLC = ADC0CTRLCoriginal; + return adc; +} + +#else int inline analogReadFast(uint8_t ADCpin) { byte ADCSRAoriginal = ADCSRA; @@ -33,5 +44,7 @@ int inline analogReadFast(uint8_t ADCpin) ADCSRA = ADCSRAoriginal; return adc; } +#endif -#endif // COMMANDSTATION_DCC_ANALOGREADFAST_H_ \ No newline at end of file +#endif +// COMMANDSTATION_DCC_ANALOGREADFAST_H_v \ No newline at end of file diff --git a/ArduinoTimers.h b/ArduinoTimers.h index 85e3644..84fb17b 100644 --- a/ArduinoTimers.h +++ b/ArduinoTimers.h @@ -11,7 +11,7 @@ #include "ATMEGA2560/Timer.h" #elif defined(ARDUINO_AVR_UNO) #include "ATMEGA328/Timer.h" -#elif defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) #include "ATMEGA4809/Timer.h" #else #error "Cannot compile - ArduinoTimers library does not support your board, or you are missing compatible build flags." diff --git a/DCC.h b/DCC.h index 05c50e1..149af36 100644 --- a/DCC.h +++ b/DCC.h @@ -155,7 +155,7 @@ private: #define ARDUINO_TYPE "NANO" #elif defined(ARDUINO_AVR_MEGA2560) #define ARDUINO_TYPE "MEGA" -#elif defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) #define ARDUINO_TYPE "UNOWIFIR2" #else #error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH AN ARDUINO UNO, NANO 328, OR ARDUINO MEGA 1280/2560 diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 6c71696..25cb6e7 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -41,7 +41,7 @@ void DCCWaveform::begin(MotorDriver * mainDriver, MotorDriver * progDriver, byte progTrack.setPowerMode(POWERMODE::OFF); switch (timerNumber) { case 1: interruptTimer= &TimerA; break; -#ifndef ARDUINO_AVR_UNO_WIFI_DEV_ED +#ifndef ARDUINO_AVR_UNO_WIFI_REV2 case 2: interruptTimer= &TimerB; break; #ifndef ARDUINO_AVR_UNO case 3: interruptTimer= &TimerC; break; diff --git a/Timer.cpp b/Timer.cpp index 10673ec..d7706ad 100644 --- a/Timer.cpp +++ b/Timer.cpp @@ -49,4 +49,14 @@ ISR(TIMER2_OVF_vect) TimerB.isrCallback(); } -#endif +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) + +#include "ATMEGA4809/Timer.h" + +Timer TimerA(0); + +ISR(TCA0_OVF_vect) { + TimerA.isrCallback(); +} + +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index f53a690..565af0f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -65,6 +65,7 @@ lib_deps = mathertel/LiquidCrystal_PCF8574 monitor_speed = 115200 monitor_flags = --echo +build_flags = "-DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO_WIFI_DEV_ED -DARDUINO_ARCH_AVR -DESP_CH_UART -DESP_CH_UART_BR=19200"g [env:uno] platform = atmelavr