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:
parent
cade89ba16
commit
f83be05220
|
@ -30,6 +30,10 @@
|
||||||
#ifdef ARDUINO_ARCH_STM32
|
#ifdef ARDUINO_ARCH_STM32
|
||||||
|
|
||||||
#include "DCCTimer.h"
|
#include "DCCTimer.h"
|
||||||
|
#ifdef DEBUG_ADC
|
||||||
|
#include "TrackManager.h"
|
||||||
|
#endif
|
||||||
|
#include "DIAG.h"
|
||||||
|
|
||||||
#if defined(ARDUINO_NUCLEO_F411RE)
|
#if defined(ARDUINO_NUCLEO_F411RE)
|
||||||
// Nucleo-64 boards don't have Serial1 defined by default
|
// 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
|
analogchans[id] = adcchan; // Keep track of which ADC channel is used for reading this pin
|
||||||
usedpins |= (1 << id); // This pin is now ready
|
usedpins |= (1 << id); // This pin is now ready
|
||||||
|
|
||||||
|
DIAG(F("ADCee::init(): value=%d, channel=%d, id=%d"), value, adcchan, id);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,11 +346,13 @@ void ADCee::scan() {
|
||||||
// found value
|
// found value
|
||||||
analogvals[id] = ADC1->DR;
|
analogvals[id] = ADC1->DR;
|
||||||
// advance at least one track
|
// 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;
|
waiting = false;
|
||||||
id++;
|
id++;
|
||||||
mask = mask << 1;
|
mask = mask << 1;
|
||||||
if (id == NUM_ADC_INPUTS+1) {
|
if (mask == 0) { // the 1 has been shifted out
|
||||||
id = 0;
|
id = 0;
|
||||||
mask = 1;
|
mask = 1;
|
||||||
}
|
}
|
||||||
|
@ -355,18 +363,20 @@ void ADCee::scan() {
|
||||||
// look for a valid track to sample or until we are around
|
// look for a valid track to sample or until we are around
|
||||||
while (true) {
|
while (true) {
|
||||||
if (mask & usedpins) {
|
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->SQR3 = analogchans[id]; //1st conversion in regular sequence
|
||||||
ADC1->CR2 |= (1 << 30); //Start 1st conversion SWSTART
|
ADC1->CR2 |= (1 << 30); //Start 1st conversion SWSTART
|
||||||
// for scope debug TrackManager::track[1]->setBrake(1);
|
#ifdef DEBUG_ADC
|
||||||
waiting = true;
|
if (id == 1) TrackManager::track[1]->setBrake(1);
|
||||||
return;
|
#endif
|
||||||
|
waiting = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
id++;
|
id++;
|
||||||
mask = mask << 1;
|
mask = mask << 1;
|
||||||
if (id == NUM_ADC_INPUTS+1) {
|
if (mask == 0) { // the 1 has been shifted out
|
||||||
id = 0;
|
id = 0;
|
||||||
mask = 1;
|
mask = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "devel-202306180700Z"
|
#define GITHUB_SHA "devel-202306181725Z"
|
||||||
|
|
|
@ -84,7 +84,14 @@ class TrackManager {
|
||||||
|
|
||||||
static int16_t joinRelay;
|
static int16_t joinRelay;
|
||||||
static bool progTrackSyncMain; // true when prog track is a siding switched to main
|
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:
|
private:
|
||||||
static void addTrack(byte t, MotorDriver* driver);
|
static void addTrack(byte t, MotorDriver* driver);
|
||||||
|
@ -93,7 +100,6 @@ class TrackManager {
|
||||||
static POWERMODE mainPowerGuess;
|
static POWERMODE mainPowerGuess;
|
||||||
static void applyDCSpeed(byte t);
|
static void applyDCSpeed(byte t);
|
||||||
|
|
||||||
static MotorDriver* track[MAX_TRACKS];
|
|
||||||
static TRACK_MODE trackMode[MAX_TRACKS];
|
static TRACK_MODE trackMode[MAX_TRACKS];
|
||||||
static int16_t trackDCAddr[MAX_TRACKS]; // dc address if TRACK_MODE_DC or TRACK_MODE_DCX
|
static int16_t trackDCAddr[MAX_TRACKS]; // dc address if TRACK_MODE_DC or TRACK_MODE_DCX
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
|
Loading…
Reference in New Issue
Block a user