From f83be0522034d3ad9c9cdefd473095eb431b6a89 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 18 Jun 2023 19:26:38 +0200 Subject: [PATCH] STM32: Use mask as loop variable --- DCCTimerSTM32.cpp | 28 +++++++++++++++++++--------- GITHUB_SHA.h | 2 +- TrackManager.h | 12 +++++++++--- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/DCCTimerSTM32.cpp b/DCCTimerSTM32.cpp index a45c4d4..7ed2b95 100644 --- a/DCCTimerSTM32.cpp +++ b/DCCTimerSTM32.cpp @@ -30,6 +30,10 @@ #ifdef ARDUINO_ARCH_STM32 #include "DCCTimer.h" +#ifdef DEBUG_ADC +#include "TrackManager.h" +#endif +#include "DIAG.h" #if defined(ARDUINO_NUCLEO_F411RE) // Nucleo-64 boards don't have Serial1 defined by default @@ -307,6 +311,8 @@ int ADCee::init(uint8_t pin) { analogchans[id] = adcchan; // Keep track of which ADC channel is used for reading this pin usedpins |= (1 << id); // This pin is now ready + DIAG(F("ADCee::init(): value=%d, channel=%d, id=%d"), value, adcchan, id); + return value; } @@ -340,11 +346,13 @@ void ADCee::scan() { // found value analogvals[id] = ADC1->DR; // advance at least one track - // for scope debug TrackManager::track[1]->setBrake(0); +#ifdef DEBUG_ADC + if (id == 1) TrackManager::track[1]->setBrake(0); +#endif waiting = false; id++; mask = mask << 1; - if (id == NUM_ADC_INPUTS+1) { + if (mask == 0) { // the 1 has been shifted out id = 0; mask = 1; } @@ -355,18 +363,20 @@ void ADCee::scan() { // look for a valid track to sample or until we are around while (true) { if (mask & usedpins) { - // start new ADC aquire on id + // start new ADC aquire on id ADC1->SQR3 = analogchans[id]; //1st conversion in regular sequence ADC1->CR2 |= (1 << 30); //Start 1st conversion SWSTART - // for scope debug TrackManager::track[1]->setBrake(1); - waiting = true; - return; +#ifdef DEBUG_ADC + if (id == 1) TrackManager::track[1]->setBrake(1); +#endif + waiting = true; + return; } id++; mask = mask << 1; - if (id == NUM_ADC_INPUTS+1) { - id = 0; - mask = 1; + if (mask == 0) { // the 1 has been shifted out + id = 0; + mask = 1; } } } diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 37d7d5f..8bd3812 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202306180700Z" +#define GITHUB_SHA "devel-202306181725Z" diff --git a/TrackManager.h b/TrackManager.h index ef4a47c..19e756d 100644 --- a/TrackManager.h +++ b/TrackManager.h @@ -84,8 +84,15 @@ class TrackManager { static int16_t joinRelay; static bool progTrackSyncMain; // true when prog track is a siding switched to main - static bool progTrackBoosted; // true when prog track is not current limited - + static bool progTrackBoosted; // true when prog track is not current limited + +#ifdef DEBUG_ADC + public: +#else + private: +#endif + static MotorDriver* track[MAX_TRACKS]; + private: static void addTrack(byte t, MotorDriver* driver); static byte lastTrack; @@ -93,7 +100,6 @@ class TrackManager { static POWERMODE mainPowerGuess; static void applyDCSpeed(byte t); - static MotorDriver* track[MAX_TRACKS]; static TRACK_MODE trackMode[MAX_TRACKS]; static int16_t trackDCAddr[MAX_TRACKS]; // dc address if TRACK_MODE_DC or TRACK_MODE_DCX #ifdef ARDUINO_ARCH_ESP32