mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
Change Adc to ADCee because of SAMD conflict
This commit is contained in:
parent
3e214ab77a
commit
e0bf978f2b
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* © 2022 Paul M Antoine
|
||||
* © 2021 Mike S
|
||||
* © 2021 Harald Barth
|
||||
* © 2021-2022 Harald Barth
|
||||
* © 2021 Fred Decker
|
||||
* All rights reserved.
|
||||
*
|
||||
|
@ -93,7 +93,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class Adc {
|
||||
class ADCee {
|
||||
public:
|
||||
// On architectures that use the analog read during DCC waveform
|
||||
// with specially configured ADC, for example AVR, init must be
|
||||
|
|
|
@ -124,15 +124,15 @@ void DCCTimer::reset() {
|
|||
#else
|
||||
#define NUM_ADC_INPUTS 15
|
||||
#endif
|
||||
uint16_t Adc::usedpins = 0;
|
||||
int * Adc::analogvals = NULL;
|
||||
uint16_t ADCee::usedpins = 0;
|
||||
int * ADCee::analogvals = NULL;
|
||||
|
||||
/*
|
||||
* Register a new pin to be scanned
|
||||
* Returns current reading of pin and
|
||||
* stores that as well
|
||||
*/
|
||||
int Adc::init(uint8_t pin) {
|
||||
int ADCee::init(uint8_t pin) {
|
||||
uint8_t id = pin - A0;
|
||||
if (id > NUM_ADC_INPUTS)
|
||||
return -1023;
|
||||
|
@ -145,9 +145,9 @@ int Adc::init(uint8_t pin) {
|
|||
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
|
||||
uint8_t id = pin - A0;
|
||||
if ((usedpins & (1<<id) ) == 0)
|
||||
|
@ -161,7 +161,7 @@ int Adc::read(uint8_t pin, bool fromISR) {
|
|||
*/
|
||||
#pragma GCC push_options
|
||||
#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 uint16_t mask = 1; // increment and shift instead to calculate mask from id
|
||||
static bool waiting = false;
|
||||
|
@ -210,7 +210,7 @@ void Adc::scan() {
|
|||
}
|
||||
#pragma GCC pop_options
|
||||
|
||||
void Adc::begin() {
|
||||
void ADCee::begin() {
|
||||
noInterrupts();
|
||||
// ADCSRA = (ADCSRA & 0b11111000) | 0b00000100; // speed up analogRead sample time
|
||||
// Set up ADC for free running mode
|
||||
|
|
|
@ -150,24 +150,24 @@ int DCCTimer::freeMemory() {
|
|||
void DCCTimer::reset() {
|
||||
ESP.restart();
|
||||
}
|
||||
int Adc::init(uint8_t pin) {
|
||||
int ADCee::init(uint8_t pin) {
|
||||
pinMode(pin, ANALOG);
|
||||
adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_DB_11);
|
||||
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));
|
||||
}
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* © 2022 Paul M Antoine
|
||||
* © 2021 Mike S
|
||||
* © 2021 Harald Barth
|
||||
* © 2021-2022 Harald Barth
|
||||
* © 2021 Fred Decker
|
||||
* © 2021 Chris Harlow
|
||||
* © 2021 David Cutting
|
||||
|
@ -155,13 +155,13 @@ void DCCTimer::reset() {
|
|||
while(true) {};
|
||||
}
|
||||
|
||||
int Adc::init(uint8_t pin) {
|
||||
int ADCee::init(uint8_t 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;
|
||||
if (!fromISR) noInterrupts();
|
||||
current = analogRead(pin);
|
||||
|
@ -171,10 +171,10 @@ int Adc::read(uint8_t pin, bool fromISR) {
|
|||
/*
|
||||
* Scan function that is called from interrupt
|
||||
*/
|
||||
void Adc::scan() {
|
||||
void ADCee::scan() {
|
||||
}
|
||||
|
||||
void Adc::begin() {
|
||||
void ADCee::begin() {
|
||||
noInterrupts();
|
||||
// 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
|
||||
|
|
|
@ -62,7 +62,7 @@ const bool signalTransform[]={
|
|||
/* WAVE_PENDING (should not happen) -> */ LOW};
|
||||
|
||||
void DCCWaveform::begin() {
|
||||
Adc::begin();
|
||||
ADCee::begin();
|
||||
DCCTimer::begin(DCCWaveform::interruptHandler);
|
||||
}
|
||||
|
||||
|
@ -82,8 +82,8 @@ void DCCWaveform::interruptHandler() {
|
|||
TrackManager::setDCCSignal(sigMain);
|
||||
TrackManager::setPROGSignal(sigProg);
|
||||
|
||||
// Refresh the values in the Adc object buffering the values of the ADC HW
|
||||
Adc::scan();
|
||||
// Refresh the values in the ADCee object buffering the values of the ADC HW
|
||||
ADCee::scan();
|
||||
|
||||
// Move on in the state engine
|
||||
mainTrack.state=stateTransform[mainTrack.state];
|
||||
|
|
|
@ -1 +1 @@
|
|||
#define GITHUB_SHA "PORTX-HAL-202210041956Z"
|
||||
#define GITHUB_SHA "PORTX-HAL-202210042018Z"
|
||||
|
|
|
@ -92,7 +92,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
|||
|
||||
currentPin=current_pin;
|
||||
if (currentPin!=UNUSED_PIN) {
|
||||
senseOffset = Adc::init(currentPin);
|
||||
senseOffset = ADCee::init(currentPin);
|
||||
}
|
||||
|
||||
faultPin=fault_pin;
|
||||
|
@ -194,7 +194,7 @@ int MotorDriver::getCurrentRaw(bool fromISR) {
|
|||
(void)fromISR;
|
||||
if (currentPin==UNUSED_PIN) return 0;
|
||||
int current;
|
||||
current = Adc::read(currentPin, fromISR)-senseOffset;
|
||||
current = ADCee::read(currentPin, fromISR)-senseOffset;
|
||||
if (current<0) current=0-current;
|
||||
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && powerMode==POWERMODE::ON)
|
||||
return (current == 0 ? -1 : -current);
|
||||
|
|
Loading…
Reference in New Issue
Block a user