mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
first ESP32 compile
This commit is contained in:
parent
0a10dbea0b
commit
75dffd9dfa
2
DCC.h
2
DCC.h
|
@ -193,6 +193,8 @@ private:
|
|||
#define ARDUINO_TYPE "TEENSY41"
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
#define ARDUINO_TYPE "ESP8266"
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
#define ARDUINO_TYPE "ESP32"
|
||||
#else
|
||||
#error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH AN ARDUINO UNO, NANO 328, OR ARDUINO MEGA 1280/2560
|
||||
#endif
|
||||
|
|
7
DCCEX.h
7
DCCEX.h
|
@ -30,9 +30,12 @@
|
|||
#include "DIAG.h"
|
||||
#include "DCCEXParser.h"
|
||||
#include "version.h"
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include "WifiESP8266.h"
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
#include "WifiESP32.h"
|
||||
#else
|
||||
#include "WifiInterface.h"
|
||||
#ifdef ESP_FAMILY
|
||||
#include "WifiESP.h"
|
||||
#endif
|
||||
#if ETHERNET_ON == true
|
||||
#include "EthernetInterface.h"
|
||||
|
|
|
@ -789,8 +789,12 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
|
|||
|
||||
case HASH_KEYWORD_RESET:
|
||||
{
|
||||
wdt_enable( WDTO_15MS); // set Arduino watchdog timer for 15ms
|
||||
delay(50); // wait for the prescaller time to expire
|
||||
#ifndef ESP_FAMILY
|
||||
wdt_enable( WDTO_15MS); // set Arduino watchdog timer for 15ms
|
||||
delay(50); // wait for the prescaler time to expire
|
||||
#else
|
||||
/* XXX do right thing to reboot */
|
||||
#endif
|
||||
break; // and <X> if we didnt restart
|
||||
}
|
||||
|
||||
|
|
|
@ -37,4 +37,5 @@ class DCCTimer {
|
|||
private:
|
||||
};
|
||||
|
||||
extern portMUX_TYPE timerMux;
|
||||
#endif
|
||||
|
|
|
@ -255,7 +255,8 @@ void IRAM_ATTR DCCWaveform::interrupt2() {
|
|||
transmitRepeats--;
|
||||
}
|
||||
else if (packetPending) {
|
||||
// Copy pending packet to transmit packet
|
||||
portENTER_CRITICAL(&timerMux);
|
||||
// Copy pending packet to transmit packet
|
||||
// a fixed length memcpy is faster than a variable length loop for these small lengths
|
||||
// for (int b = 0; b < pendingLength; b++) transmitPacket[b] = pendingPacket[b];
|
||||
memcpy( transmitPacket, pendingPacket, sizeof(pendingPacket));
|
||||
|
@ -264,6 +265,7 @@ void IRAM_ATTR DCCWaveform::interrupt2() {
|
|||
transmitRepeats = pendingRepeats;
|
||||
packetPending = false;
|
||||
sentResetsSincePacket=0;
|
||||
portEXIT_CRITICAL(&timerMux);
|
||||
}
|
||||
else {
|
||||
// Fortunately reset and idle packets are the same length
|
||||
|
@ -282,7 +284,7 @@ void IRAM_ATTR DCCWaveform::interrupt2() {
|
|||
void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repeats) {
|
||||
if (byteCount > MAX_PACKET_SIZE) return; // allow for chksum
|
||||
while (packetPending);
|
||||
|
||||
portENTER_CRITICAL(&timerMux);
|
||||
byte checksum = 0;
|
||||
for (byte b = 0; b < byteCount; b++) {
|
||||
checksum ^= buffer[b];
|
||||
|
@ -294,6 +296,7 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea
|
|||
pendingRepeats = repeats;
|
||||
packetPending = true;
|
||||
sentResetsSincePacket=0;
|
||||
portEXIT_CRITICAL(&timerMux);
|
||||
}
|
||||
|
||||
// Operations applicable to PROG track ONLY.
|
||||
|
@ -330,7 +333,7 @@ byte DCCWaveform::getAck() {
|
|||
}
|
||||
|
||||
void IRAM_ATTR DCCWaveform::checkAck() {
|
||||
// This function operates in interrupt() time so must be fast and can't DIAG
|
||||
// This function operates in interrupt() time (not on ESP) so must be fast and can't DIAG
|
||||
if (sentResetsSincePacket > 6) { //ACK timeout
|
||||
ackCheckDuration=millis()-ackCheckStart;
|
||||
ackPending = false;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
#ifndef MotorDriver_h
|
||||
#define MotorDriver_h
|
||||
#include "defines.h"
|
||||
#include "FSH.h"
|
||||
|
||||
// Virtualised Motor shield 1-track hardware Interface
|
||||
|
@ -26,7 +27,7 @@
|
|||
#define UNUSED_PIN 127 // inside int8_t
|
||||
#endif
|
||||
|
||||
#if defined(__IMXRT1062__) || defined (ARDUINO_ARCH_ESP8266)
|
||||
#if defined(__IMXRT1062__) || defined(ESP_FAMILY)
|
||||
typedef uint32_t PORTTYPE;
|
||||
struct FASTPIN {
|
||||
volatile uint32_t *inout;
|
||||
|
|
39
WifiESP32.cpp
Normal file
39
WifiESP32.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
© 2021, Harald Barth.
|
||||
|
||||
This file is part of CommandStation-EX
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "defines.h"
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <WiFi.h>
|
||||
#include "WifiESP32.h"
|
||||
#include "DIAG.h"
|
||||
#include "RingStream.h"
|
||||
#include "CommandDistributor.h"
|
||||
|
||||
bool WifiESP::setup(const char *SSid,
|
||||
const char *password,
|
||||
const char *hostname,
|
||||
int port,
|
||||
const byte channel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WifiESP::loop() {
|
||||
|
||||
}
|
||||
#endif //ESP32
|
|
@ -17,8 +17,9 @@
|
|||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef WifiESP_h
|
||||
#define WifiESP_h
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#ifndef WifiESP32_h
|
||||
#define WifiESP32_h
|
||||
|
||||
#include "FSH.h"
|
||||
|
||||
|
@ -34,4 +35,5 @@ public:
|
|||
static void loop();
|
||||
private:
|
||||
};
|
||||
#endif
|
||||
#endif //WifiESP8266_h
|
||||
#endif //ESP8266
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
|
||||
#include "defines.h"
|
||||
#ifdef ESP_FAMILY
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "WifiESP.h"
|
||||
#include "WifiESP8266.h"
|
||||
#include "DIAG.h"
|
||||
#include "RingStream.h"
|
||||
#include "CommandDistributor.h"
|
39
WifiESP8266.h
Normal file
39
WifiESP8266.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* © 2021, Harald Barth.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#ifndef WifiESP8266_h
|
||||
#define WifiESP8266_h
|
||||
|
||||
#include "FSH.h"
|
||||
|
||||
class WifiESP
|
||||
{
|
||||
|
||||
public:
|
||||
static bool setup(const char *wifiESSID,
|
||||
const char *wifiPassword,
|
||||
const char *hostname,
|
||||
const int port,
|
||||
const byte channel);
|
||||
static void loop();
|
||||
private:
|
||||
};
|
||||
#endif //WifiESP8266_h
|
||||
#endif //ESP8266
|
|
@ -17,9 +17,10 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "WifiInterface.h" /* config.h included there */
|
||||
#ifndef ESP_FAMILY
|
||||
#ifndef ARDUINO_AVR_UNO_WIFI_REV2
|
||||
// This code is NOT compiled on a unoWifiRev2 processor which uses a different architecture
|
||||
#include "WifiInterface.h" /* config.h included there */
|
||||
#include <avr/pgmspace.h>
|
||||
#include "DIAG.h"
|
||||
#include "StringFormatter.h"
|
||||
|
@ -370,4 +371,5 @@ void WifiInterface::loop() {
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif //ARDUINO_AVR_UNO_WIFI_REV2
|
||||
#endif //ESP_FAMILY
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
*/
|
||||
#ifndef WifiInterface_h
|
||||
#define WifiInterface_h
|
||||
#include "defines.h"
|
||||
#ifndef ESP_FAMILY
|
||||
#include "FSH.h"
|
||||
#include "DCCEXParser.h"
|
||||
#include <Arduino.h>
|
||||
|
@ -50,4 +52,5 @@ private:
|
|||
static bool checkForOK(const unsigned int timeout, const FSH *waitfor, bool echo, bool escapeEcho = true);
|
||||
static bool connected;
|
||||
};
|
||||
#endif
|
||||
#endif //ESP_FAMILY
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#define ESP_FAMILY
|
||||
//#define ESP_DEBUG
|
||||
#define SLOW_ANALOG_READ
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP32)
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#define ESP_FAMILY
|
||||
#define SLOW_ANALOG_READ
|
||||
#else
|
||||
|
@ -42,7 +42,7 @@
|
|||
// WIFI_ON: All prereqs for running with WIFI are met
|
||||
// Note: WIFI_CHANNEL may not exist in early config.h files so is added here if needed.
|
||||
|
||||
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO) || defined(TEENSYDUINO) || defined (ESP_FAMILY))
|
||||
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO) || defined(TEENSYDUINO) || defined(ESP_FAMILY))
|
||||
#define WIFI_ON true
|
||||
#ifndef WIFI_CHANNEL
|
||||
#define WIFI_CHANNEL 1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* © 2020, Harald Barth
|
||||
* © 2020,2021 Harald Barth
|
||||
* © 2021, Neil McKechnie
|
||||
*
|
||||
* This file is part of Asbelos DCC-EX
|
||||
|
@ -27,7 +27,7 @@ extern "C" char* sbrk(int);
|
|||
#elif defined(__AVR__)
|
||||
extern char *__brkval;
|
||||
extern char *__malloc_heap_start;
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
// supported but nothing needed here
|
||||
#else
|
||||
#error Unsupported board type
|
||||
|
@ -36,7 +36,7 @@ extern char *__malloc_heap_start;
|
|||
|
||||
static volatile int minimum_free_memory = __INT_MAX__;
|
||||
|
||||
#if !defined(__IMXRT1062__) && !defined(ARDUINO_ARCH_ESP8266)
|
||||
#if !defined(__IMXRT1062__) && !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32)
|
||||
static inline int freeMemory() {
|
||||
char top;
|
||||
#if defined(__arm__)
|
||||
|
@ -57,8 +57,8 @@ int minimumFreeMemory() {
|
|||
return retval;
|
||||
}
|
||||
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
// ESP8266
|
||||
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
// ESP8266 and ESP32
|
||||
static inline int freeMemory() {
|
||||
return ESP.getFreeHeap();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user