1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

STM32: Use mask as loop variable

This commit is contained in:
Harald Barth 2023-06-18 19:26:38 +02:00
parent cade89ba16
commit f83be05220
3 changed files with 29 additions and 13 deletions

View File

@ -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;
}
@ -358,13 +366,15 @@ void ADCee::scan() {
// 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);
#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) {
if (mask == 0) { // the 1 has been shifted out
id = 0;
mask = 1;
}

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202306180700Z"
#define GITHUB_SHA "devel-202306181725Z"

View File

@ -86,6 +86,13 @@ class TrackManager {
static bool progTrackSyncMain; // true when prog track is a siding switched to main
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