mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
CPU handling
Technique adapted from David Cutting's solution
This commit is contained in:
parent
b89c9068ff
commit
e933172ef3
17
Hardware.cpp
17
Hardware.cpp
|
@ -6,6 +6,13 @@
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
|
#include <DIO2.h>
|
||||||
|
#define WritePin digitalWrite2
|
||||||
|
#else
|
||||||
|
#define WritePin digitalWrite
|
||||||
|
#endif
|
||||||
|
|
||||||
void Hardware::init() {
|
void Hardware::init() {
|
||||||
pinMode(MAIN_POWER_PIN, OUTPUT);
|
pinMode(MAIN_POWER_PIN, OUTPUT);
|
||||||
pinMode(MAIN_SIGNAL_PIN, OUTPUT);
|
pinMode(MAIN_SIGNAL_PIN, OUTPUT);
|
||||||
|
@ -19,17 +26,17 @@ void Hardware::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hardware::setPower(bool isMainTrack, bool on) {
|
void Hardware::setPower(bool isMainTrack, bool on) {
|
||||||
digitalWrite(isMainTrack ? MAIN_POWER_PIN : PROG_POWER_PIN, on ? HIGH : LOW);
|
WritePin(isMainTrack ? MAIN_POWER_PIN : PROG_POWER_PIN, on ? HIGH : LOW);
|
||||||
}
|
}
|
||||||
void Hardware::setBrake(bool isMainTrack, bool on) {
|
void Hardware::setBrake(bool isMainTrack, bool on) {
|
||||||
digitalWrite(isMainTrack ? MAIN_BRAKE_PIN : PROG_BRAKE_PIN, on ? LOW:HIGH);
|
WritePin(isMainTrack ? MAIN_BRAKE_PIN : PROG_BRAKE_PIN, on ? LOW:HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hardware::setSignal(bool isMainTrack, bool high) {
|
void Hardware::setSignal(bool isMainTrack, bool high) {
|
||||||
byte pin = isMainTrack ? MAIN_SIGNAL_PIN : PROG_SIGNAL_PIN;
|
byte pin = isMainTrack ? MAIN_SIGNAL_PIN : PROG_SIGNAL_PIN;
|
||||||
byte pin2 = isMainTrack ? MAIN_SIGNAL_PIN_ALT : PROG_SIGNAL_PIN_ALT;
|
byte pin2 = isMainTrack ? MAIN_SIGNAL_PIN_ALT : PROG_SIGNAL_PIN_ALT;
|
||||||
digitalWrite(pin, high ? HIGH : LOW);
|
WritePin(pin, high ? HIGH : LOW);
|
||||||
if (pin2) digitalWrite(pin2, high ? LOW : HIGH);
|
if (pin2) WritePin(pin2, high ? LOW : HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Hardware::getCurrentMilliamps(bool isMainTrack) {
|
int Hardware::getCurrentMilliamps(bool isMainTrack) {
|
||||||
|
@ -46,12 +53,14 @@ void Hardware::setCallback(int duration, void (*isr)()) {
|
||||||
Timer3.disablePwm(TIMER3_B_PIN);
|
Timer3.disablePwm(TIMER3_B_PIN);
|
||||||
Timer3.attachInterrupt(isr);
|
Timer3.attachInterrupt(isr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hardware::setSingleCallback(int duration, void (*isr)()) {
|
void Hardware::setSingleCallback(int duration, void (*isr)()) {
|
||||||
Timer1.initialize(duration);
|
Timer1.initialize(duration);
|
||||||
Timer1.disablePwm(TIMER1_A_PIN);
|
Timer1.disablePwm(TIMER1_A_PIN);
|
||||||
Timer1.disablePwm(TIMER1_B_PIN);
|
Timer1.disablePwm(TIMER1_B_PIN);
|
||||||
Timer1.attachInterrupt(isr);
|
Timer1.attachInterrupt(isr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hardware::resetSingleCallback(int duration) {
|
void Hardware::resetSingleCallback(int duration) {
|
||||||
if (duration==0) Timer1.stop();
|
if (duration==0) Timer1.stop();
|
||||||
else Timer1.initialize(duration);
|
else Timer1.initialize(duration);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user