mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 15:46:14 +01:00
STM32 ADCee highestPin
This commit is contained in:
parent
d5dad767a4
commit
c3eb6b8d8a
|
@ -199,7 +199,7 @@ void ADCee::scan() {
|
||||||
waiting = false;
|
waiting = false;
|
||||||
id++;
|
id++;
|
||||||
mask = mask << 1;
|
mask = mask << 1;
|
||||||
if (id > highestPin) { // the 1 has been shifted out
|
if (id > highestPin) {
|
||||||
id = 0;
|
id = 0;
|
||||||
mask = 1;
|
mask = 1;
|
||||||
}
|
}
|
||||||
|
@ -230,8 +230,8 @@ void ADCee::scan() {
|
||||||
id++;
|
id++;
|
||||||
mask = mask << 1;
|
mask = mask << 1;
|
||||||
if (id > highestPin) {
|
if (id > highestPin) {
|
||||||
id = 0;
|
id = 0;
|
||||||
mask = 1;
|
mask = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,13 +233,16 @@ void DCCTimer::reset() {
|
||||||
while(true) {};
|
while(true) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NUM_ADC_INPUTS NUM_ANALOG_INPUTS
|
|
||||||
|
|
||||||
// TODO: may need to use uint32_t on STMF4xx variants with > 16 analog inputs!
|
// TODO: may need to use uint32_t on STMF4xx variants with > 16 analog inputs!
|
||||||
#if defined(ARDUINO_NUCLEO_F446RE) || defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F446ZE)
|
#if defined(ARDUINO_NUCLEO_F446RE) || defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F446ZE)
|
||||||
#warning STM32 board selected not fully supported - only use ADC1 inputs 0-15 for current sensing!
|
#warning STM32 board selected not fully supported - only use ADC1 inputs 0-15 for current sensing!
|
||||||
#endif
|
#endif
|
||||||
|
// For now, define the max of 16 ports - some variants have more, but this not **yet** supported
|
||||||
|
#define NUM_ADC_INPUTS 16
|
||||||
|
// #define NUM_ADC_INPUTS NUM_ANALOG_INPUTS
|
||||||
|
|
||||||
uint16_t ADCee::usedpins = 0;
|
uint16_t ADCee::usedpins = 0;
|
||||||
|
uint8_t ADCee::highestPin = 0;
|
||||||
int * ADCee::analogvals = NULL;
|
int * ADCee::analogvals = NULL;
|
||||||
uint32_t * analogchans = NULL;
|
uint32_t * analogchans = NULL;
|
||||||
bool adc1configured = false;
|
bool adc1configured = false;
|
||||||
|
@ -310,6 +313,7 @@ int ADCee::init(uint8_t pin) {
|
||||||
analogvals[id] = value; // Store sampled value
|
analogvals[id] = value; // Store sampled value
|
||||||
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
|
||||||
|
if (id > highestPin) highestPin = id; // Store our highest pin in use
|
||||||
|
|
||||||
DIAG(F("ADCee::init(): value=%d, channel=%d, id=%d"), value, adcchan, id);
|
DIAG(F("ADCee::init(): value=%d, channel=%d, id=%d"), value, adcchan, id);
|
||||||
|
|
||||||
|
@ -352,7 +356,7 @@ void ADCee::scan() {
|
||||||
waiting = false;
|
waiting = false;
|
||||||
id++;
|
id++;
|
||||||
mask = mask << 1;
|
mask = mask << 1;
|
||||||
if (mask == 0) { // the 1 has been shifted out
|
if (id > highestPin) { // the 1 has been shifted out
|
||||||
id = 0;
|
id = 0;
|
||||||
mask = 1;
|
mask = 1;
|
||||||
}
|
}
|
||||||
|
@ -374,9 +378,9 @@ void ADCee::scan() {
|
||||||
}
|
}
|
||||||
id++;
|
id++;
|
||||||
mask = mask << 1;
|
mask = mask << 1;
|
||||||
if (mask == 0) { // the 1 has been shifted out
|
if (id > highestPin) {
|
||||||
id = 0;
|
id = 0;
|
||||||
mask = 1;
|
mask = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ platform = ststm32
|
||||||
board = nucleo_f446re
|
board = nucleo_f446re
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = ${env.lib_deps}
|
lib_deps = ${env.lib_deps}
|
||||||
build_flags = -std=c++17 -Os -g2 -Wunused-variable -DDIAG_LOOPTIMES ; -DDIAG_IO
|
build_flags = -std=c++17 -Os -g2 -Wunused-variable ; -DDIAG_LOOPTIMES ; -DDIAG_IO
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
monitor_echo = yes
|
monitor_echo = yes
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user