mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-17 06:29:15 +01:00
changed IODevice code to use ADCee
This commit is contained in:
parent
08c114fd22
commit
452ffc5725
@ -100,7 +100,7 @@ public:
|
|||||||
// called PRIOR to the start of the waveform. It returns the
|
// called PRIOR to the start of the waveform. It returns the
|
||||||
// current value so that an offset can be initialized.
|
// current value so that an offset can be initialized.
|
||||||
static int init(uint8_t pin);
|
static int init(uint8_t pin);
|
||||||
static int read(uint8_t pin, bool fromISR);
|
static int read(uint8_t pin, bool fromISR=false);
|
||||||
private:
|
private:
|
||||||
static void scan();
|
static void scan();
|
||||||
static void begin();
|
static void begin();
|
||||||
|
@ -180,6 +180,15 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case OPCODE_ATGTE:
|
||||||
|
case OPCODE_ATLT:
|
||||||
|
case OPCODE_IFGTE:
|
||||||
|
case OPCODE_IFLT:
|
||||||
|
case OPCODE_DRIVE: {
|
||||||
|
IODevice::configureAnalogIn((VPIN)operand);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case OPCODE_TURNOUT: {
|
case OPCODE_TURNOUT: {
|
||||||
VPIN id=operand;
|
VPIN id=operand;
|
||||||
int addr=GET_OPERAND(1);
|
int addr=GET_OPERAND(1);
|
||||||
|
@ -1 +1 @@
|
|||||||
#define GITHUB_SHA "PORTX-HAL-202210042018Z"
|
#define GITHUB_SHA "PORTX-HAL-202210052105Z"
|
||||||
|
52
IODevice.cpp
52
IODevice.cpp
@ -25,6 +25,7 @@
|
|||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
#include "FSH.h"
|
#include "FSH.h"
|
||||||
#include "IO_MCP23017.h"
|
#include "IO_MCP23017.h"
|
||||||
|
#include "DCCTimer.h"
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
|
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
|
||||||
#define USE_FAST_IO
|
#define USE_FAST_IO
|
||||||
@ -195,7 +196,17 @@ int IODevice::readAnalogue(VPIN vpin) {
|
|||||||
#ifdef DIAG_IO
|
#ifdef DIAG_IO
|
||||||
DIAG(F("IODevice::readAnalogue(): Vpin %d not found!"), (int)vpin);
|
DIAG(F("IODevice::readAnalogue(): Vpin %d not found!"), (int)vpin);
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return -1023;
|
||||||
|
}
|
||||||
|
int IODevice::configureAnalogIn(VPIN vpin) {
|
||||||
|
for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) {
|
||||||
|
if (dev->owns(vpin))
|
||||||
|
return dev->_configureAnalogIn(vpin);
|
||||||
|
}
|
||||||
|
#ifdef DIAG_IO
|
||||||
|
DIAG(F("IODevice::configureAnalogIn(): Vpin %d not found!"), (int)vpin);
|
||||||
|
#endif
|
||||||
|
return -1023;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write value to virtual pin(s). If multiple devices are allocated the same pin
|
// Write value to virtual pin(s). If multiple devices are allocated the same pin
|
||||||
@ -361,11 +372,10 @@ int IODevice::read(VPIN vpin) {
|
|||||||
return !digitalRead(vpin); // Return inverted state (5v=0, 0v=1)
|
return !digitalRead(vpin); // Return inverted state (5v=0, 0v=1)
|
||||||
}
|
}
|
||||||
int IODevice::readAnalogue(VPIN vpin) {
|
int IODevice::readAnalogue(VPIN vpin) {
|
||||||
pinMode(vpin, INPUT);
|
return ADCee::read(vpin);
|
||||||
noInterrupts();
|
}
|
||||||
int value = analogRead(vpin);
|
int IODevice::configureAnalogIn(VPIN vpin) {
|
||||||
interrupts();
|
return ADCee::init(vpin);
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
void IODevice::loop() {}
|
void IODevice::loop() {}
|
||||||
void IODevice::DumpAll() {
|
void IODevice::DumpAll() {
|
||||||
@ -467,7 +477,18 @@ int ArduinoPins::_read(VPIN vpin) {
|
|||||||
|
|
||||||
// Device-specific readAnalogue function (analogue input)
|
// Device-specific readAnalogue function (analogue input)
|
||||||
int ArduinoPins::_readAnalogue(VPIN vpin) {
|
int ArduinoPins::_readAnalogue(VPIN vpin) {
|
||||||
int pin = vpin;
|
if (vpin > 255) return -1023;
|
||||||
|
uint8_t pin = vpin;
|
||||||
|
int value = ADCee::read(pin);
|
||||||
|
|
||||||
|
#ifdef DIAG_IO
|
||||||
|
DIAG(F("Arduino Read Pin:%d Value:%d"), pin, value);
|
||||||
|
#endif
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
int ArduinoPins::_configureAnalogIn(VPIN vpin) {
|
||||||
|
if (vpin > 255) return -1023;
|
||||||
|
uint8_t pin = vpin;
|
||||||
uint8_t mask = 1 << ((pin-_firstVpin) % 8);
|
uint8_t mask = 1 << ((pin-_firstVpin) % 8);
|
||||||
uint8_t index = (pin-_firstVpin) / 8;
|
uint8_t index = (pin-_firstVpin) / 8;
|
||||||
if (_pinModes[index] & mask) {
|
if (_pinModes[index] & mask) {
|
||||||
@ -479,22 +500,9 @@ int ArduinoPins::_readAnalogue(VPIN vpin) {
|
|||||||
else
|
else
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
}
|
}
|
||||||
|
int value = ADCee::init(pin);
|
||||||
// Since AnalogRead is also called from interrupt code, disable interrupts
|
|
||||||
// while we're using it. There's only one ADC shared by all analogue inputs
|
|
||||||
// on the Arduino, so we don't want interruptions.
|
|
||||||
//******************************************************************************
|
|
||||||
// NOTE: If the HAL is running on a computer without the DCC signal generator,
|
|
||||||
// then interrupts needn't be disabled. Also, the DCC signal generator puts
|
|
||||||
// the ADC into fast mode, so if it isn't present, analogueRead calls will be much
|
|
||||||
// slower!!
|
|
||||||
//******************************************************************************
|
|
||||||
noInterrupts();
|
|
||||||
int value = analogRead(pin);
|
|
||||||
interrupts();
|
|
||||||
|
|
||||||
#ifdef DIAG_IO
|
#ifdef DIAG_IO
|
||||||
DIAG(F("Arduino Read Pin:%d Value:%d"), pin, value);
|
DIAG(F("configureAnalogIn Pin:%d Value:%d"), pin, value);
|
||||||
#endif
|
#endif
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,7 @@ public:
|
|||||||
|
|
||||||
// read invokes the IODevice instance's _readAnalogue method.
|
// read invokes the IODevice instance's _readAnalogue method.
|
||||||
static int readAnalogue(VPIN vpin);
|
static int readAnalogue(VPIN vpin);
|
||||||
|
static int configureAnalogIn(VPIN vpin);
|
||||||
|
|
||||||
// loop invokes the IODevice instance's _loop method.
|
// loop invokes the IODevice instance's _loop method.
|
||||||
static void loop();
|
static void loop();
|
||||||
@ -201,6 +202,10 @@ protected:
|
|||||||
(void)vpin;
|
(void)vpin;
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
virtual int _configureAnalogIn(VPIN vpin) {
|
||||||
|
(void)vpin;
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
// Method to perform updates on an ongoing basis (optionally implemented within device class)
|
// Method to perform updates on an ongoing basis (optionally implemented within device class)
|
||||||
virtual void _loop(unsigned long currentMicros) {
|
virtual void _loop(unsigned long currentMicros) {
|
||||||
@ -356,6 +361,7 @@ private:
|
|||||||
// Device-specific read functions.
|
// Device-specific read functions.
|
||||||
int _read(VPIN vpin) override;
|
int _read(VPIN vpin) override;
|
||||||
int _readAnalogue(VPIN vpin) override;
|
int _readAnalogue(VPIN vpin) override;
|
||||||
|
int _configureAnalogIn(VPIN vpin) override;
|
||||||
void _display() override;
|
void _display() override;
|
||||||
|
|
||||||
|
|
||||||
@ -403,4 +409,4 @@ private:
|
|||||||
#include "IO_MCP23017.h"
|
#include "IO_MCP23017.h"
|
||||||
#include "IO_PCF8574.h"
|
#include "IO_PCF8574.h"
|
||||||
|
|
||||||
#endif // iodevice_h
|
#endif // iodevice_h
|
||||||
|
Loading…
Reference in New Issue
Block a user