From bbca4379d2dddbf96487d70733381960b5bde95c Mon Sep 17 00:00:00 2001 From: travis-farmer Date: Mon, 23 Oct 2023 14:38:29 -0400 Subject: [PATCH] sorta works, but no adc yet --- DCCTimerGiga.cpp | 15 +++++++++++---- defines.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/DCCTimerGiga.cpp b/DCCTimerGiga.cpp index c176209..580992c 100644 --- a/DCCTimerGiga.cpp +++ b/DCCTimerGiga.cpp @@ -33,6 +33,8 @@ #include "DCCTimer.h" #include "DIAG.h" #include "Portenta_H7_TimerInterrupt.h" +#include "pins_arduino.h" +#include "pinDefinitions.h" /////////////////////////////////////////////////////////////////////////////////////////////// // Experimental code for High Accuracy (HA) DCC Signal mode // Warning - use of TIM2 and TIM3 can affect the use of analogWrite() function on certain pins, @@ -173,13 +175,18 @@ int ADCee::init(uint8_t pin) { * Read function ADCee::read(pin) to get value instead of analogRead(pin) */ int ADCee::read(uint8_t pin, bool fromISR) { - int current; + //int current; //DIAG(F("ADCee Read:%d"),fromISR); //if (!fromISR) noInterrupts(); - current = analogRead(pin); + //current = analogRead(pin); //if (!fromISR) interrupts(); - - return current; + PinName name = analogPinToPinName(pin); + mbed::AnalogIn* adc = analogPinToAdcObj(pin); + if (adc == NULL) { + adc = new mbed::AnalogIn(name); + analogPinToAdcObj(pin) = adc; + } + return (adc->read_u16() >> (16 - 12)); } /* diff --git a/defines.h b/defines.h index c542182..4d486ac 100644 --- a/defines.h +++ b/defines.h @@ -157,7 +157,7 @@ //#endif #define SDA I2C_SDA #define SCL I2C_SCL - + #define DCC_EX_TIMER // these don't work... //extern const uint16_t PROGMEM port_to_input_PGM[]; //extern const uint16_t PROGMEM port_to_output_PGM[];