1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-02-16 22:19:14 +01:00

Change Adc to ADCee because of SAMD conflict

This commit is contained in:
Harald Barth 2022-10-04 22:19:51 +02:00
parent 3e214ab77a
commit e0bf978f2b
7 changed files with 26 additions and 26 deletions

View File

@ -1,7 +1,7 @@
/* /*
* © 2022 Paul M Antoine * © 2022 Paul M Antoine
* © 2021 Mike S * © 2021 Mike S
* © 2021 Harald Barth * © 2021-2022 Harald Barth
* © 2021 Fred Decker * © 2021 Fred Decker
* All rights reserved. * All rights reserved.
* *
@ -93,7 +93,7 @@ private:
}; };
class Adc { class ADCee {
public: public:
// On architectures that use the analog read during DCC waveform // On architectures that use the analog read during DCC waveform
// with specially configured ADC, for example AVR, init must be // with specially configured ADC, for example AVR, init must be

View File

@ -124,15 +124,15 @@ void DCCTimer::reset() {
#else #else
#define NUM_ADC_INPUTS 15 #define NUM_ADC_INPUTS 15
#endif #endif
uint16_t Adc::usedpins = 0; uint16_t ADCee::usedpins = 0;
int * Adc::analogvals = NULL; int * ADCee::analogvals = NULL;
/* /*
* Register a new pin to be scanned * Register a new pin to be scanned
* Returns current reading of pin and * Returns current reading of pin and
* stores that as well * stores that as well
*/ */
int Adc::init(uint8_t pin) { int ADCee::init(uint8_t pin) {
uint8_t id = pin - A0; uint8_t id = pin - A0;
if (id > NUM_ADC_INPUTS) if (id > NUM_ADC_INPUTS)
return -1023; return -1023;
@ -145,9 +145,9 @@ int Adc::init(uint8_t pin) {
return value; return value;
} }
/* /*
* Read function Adc::read(pin) to get value instead of analogRead(pin) * Read function ADCee::read(pin) to get value instead of analogRead(pin)
*/ */
int Adc::read(uint8_t pin, bool fromISR) { int ADCee::read(uint8_t pin, bool fromISR) {
(void)fromISR; // AVR does ignore this arg (void)fromISR; // AVR does ignore this arg
uint8_t id = pin - A0; uint8_t id = pin - A0;
if ((usedpins & (1<<id) ) == 0) if ((usedpins & (1<<id) ) == 0)
@ -161,7 +161,7 @@ int Adc::read(uint8_t pin, bool fromISR) {
*/ */
#pragma GCC push_options #pragma GCC push_options
#pragma GCC optimize ("-O3") #pragma GCC optimize ("-O3")
void Adc::scan() { void ADCee::scan() {
static byte id = 0; // id and mask are the same thing but it is faster to static byte id = 0; // id and mask are the same thing but it is faster to
static uint16_t mask = 1; // increment and shift instead to calculate mask from id static uint16_t mask = 1; // increment and shift instead to calculate mask from id
static bool waiting = false; static bool waiting = false;
@ -210,7 +210,7 @@ void Adc::scan() {
} }
#pragma GCC pop_options #pragma GCC pop_options
void Adc::begin() { void ADCee::begin() {
noInterrupts(); noInterrupts();
// ADCSRA = (ADCSRA & 0b11111000) | 0b00000100; // speed up analogRead sample time // ADCSRA = (ADCSRA & 0b11111000) | 0b00000100; // speed up analogRead sample time
// Set up ADC for free running mode // Set up ADC for free running mode

View File

@ -150,24 +150,24 @@ int DCCTimer::freeMemory() {
void DCCTimer::reset() { void DCCTimer::reset() {
ESP.restart(); ESP.restart();
} }
int Adc::init(uint8_t pin) { int ADCee::init(uint8_t pin) {
pinMode(pin, ANALOG); pinMode(pin, ANALOG);
adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_DB_11); adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_DB_11);
return local_adc1_get_raw(pinToADC1Channel(pin)); return local_adc1_get_raw(pinToADC1Channel(pin));
} }
/* /*
* Read function Adc::read(pin) to get value instead of analogRead(pin) * Read function ADCee::read(pin) to get value instead of analogRead(pin)
*/ */
int Adc::read(uint8_t pin, bool fromISR) { int ADCee::read(uint8_t pin, bool fromISR) {
return local_adc1_get_raw(pinToADC1Channel(pin)); return local_adc1_get_raw(pinToADC1Channel(pin));
} }
/* /*
* Scan function that is called from interrupt * Scan function that is called from interrupt
*/ */
void Adc::scan() { void ADCee::scan() {
} }
void Adc::begin() { void ADCee::begin() {
adc1_config_width(ADC_WIDTH_BIT_12); adc1_config_width(ADC_WIDTH_BIT_12);
} }

View File

@ -1,7 +1,7 @@
/* /*
* © 2022 Paul M Antoine * © 2022 Paul M Antoine
* © 2021 Mike S * © 2021 Mike S
* © 2021 Harald Barth * © 2021-2022 Harald Barth
* © 2021 Fred Decker * © 2021 Fred Decker
* © 2021 Chris Harlow * © 2021 Chris Harlow
* © 2021 David Cutting * © 2021 David Cutting
@ -155,13 +155,13 @@ void DCCTimer::reset() {
while(true) {}; while(true) {};
} }
int Adc::init(uint8_t pin) { int ADCee::init(uint8_t pin) {
return analogRead(pin); return analogRead(pin);
} }
/* /*
* Read function Adc::read(pin) to get value instead of analogRead(pin) * Read function ADCee::read(pin) to get value instead of analogRead(pin)
*/ */
int Adc::read(uint8_t pin, bool fromISR) { int ADCee::read(uint8_t pin, bool fromISR) {
int current; int current;
if (!fromISR) noInterrupts(); if (!fromISR) noInterrupts();
current = analogRead(pin); current = analogRead(pin);
@ -171,10 +171,10 @@ int Adc::read(uint8_t pin, bool fromISR) {
/* /*
* Scan function that is called from interrupt * Scan function that is called from interrupt
*/ */
void Adc::scan() { void ADCee::scan() {
} }
void Adc::begin() { void ADCee::begin() {
noInterrupts(); noInterrupts();
// Set up ADC to do faster reads... default for Arduino Zero platform configs is 436uS, // Set up ADC to do faster reads... default for Arduino Zero platform configs is 436uS,
// and we need sub-100uS. This code sets it to a read speed of around 21uS, and for now // and we need sub-100uS. This code sets it to a read speed of around 21uS, and for now

View File

@ -62,7 +62,7 @@ const bool signalTransform[]={
/* WAVE_PENDING (should not happen) -> */ LOW}; /* WAVE_PENDING (should not happen) -> */ LOW};
void DCCWaveform::begin() { void DCCWaveform::begin() {
Adc::begin(); ADCee::begin();
DCCTimer::begin(DCCWaveform::interruptHandler); DCCTimer::begin(DCCWaveform::interruptHandler);
} }
@ -82,8 +82,8 @@ void DCCWaveform::interruptHandler() {
TrackManager::setDCCSignal(sigMain); TrackManager::setDCCSignal(sigMain);
TrackManager::setPROGSignal(sigProg); TrackManager::setPROGSignal(sigProg);
// Refresh the values in the Adc object buffering the values of the ADC HW // Refresh the values in the ADCee object buffering the values of the ADC HW
Adc::scan(); ADCee::scan();
// Move on in the state engine // Move on in the state engine
mainTrack.state=stateTransform[mainTrack.state]; mainTrack.state=stateTransform[mainTrack.state];

View File

@ -1 +1 @@
#define GITHUB_SHA "PORTX-HAL-202210041956Z" #define GITHUB_SHA "PORTX-HAL-202210042018Z"

View File

@ -92,7 +92,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
currentPin=current_pin; currentPin=current_pin;
if (currentPin!=UNUSED_PIN) { if (currentPin!=UNUSED_PIN) {
senseOffset = Adc::init(currentPin); senseOffset = ADCee::init(currentPin);
} }
faultPin=fault_pin; faultPin=fault_pin;
@ -194,7 +194,7 @@ int MotorDriver::getCurrentRaw(bool fromISR) {
(void)fromISR; (void)fromISR;
if (currentPin==UNUSED_PIN) return 0; if (currentPin==UNUSED_PIN) return 0;
int current; int current;
current = Adc::read(currentPin, fromISR)-senseOffset; current = ADCee::read(currentPin, fromISR)-senseOffset;
if (current<0) current=0-current; if (current<0) current=0-current;
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && powerMode==POWERMODE::ON) if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && powerMode==POWERMODE::ON)
return (current == 0 ? -1 : -current); return (current == 0 ? -1 : -current);