Add support for Raspberry Pico (#56)

* fix ESP32 bug on interrupt reinitialisation

* - add first version of Raspberry Pico support

* - add first version of Raspberry Pico support

* Fix problem with missing type PinStatus
merge changes from master project

* fix encoding issue
This commit is contained in:
Jueff
2021-04-26 13:33:17 +02:00
committed by GitHub
parent eb15c25491
commit 037070b899
3 changed files with 33 additions and 28 deletions

View File

@@ -38,6 +38,7 @@
// 2018-12-17 added ESP32 support by Trusty (thierry@lapajaparis.net)
// 2019-02-17 added ESP32 specific changes by Hans Tanner
// 2020-05-15 changes to pass NMRA Tests ( always search for preamble )
// 2021-03-11 fix ESP32 bug on interrupt reinitialisation
//------------------------------------------------------------------------
//
// purpose: Provide a simplified interface to decode NMRA DCC packets
@@ -490,8 +491,10 @@ void ExternalInterruptHandler(void)
#if defined ( __STM32F1__ )
detachInterrupt( DccProcState.ExtIntNum );
#endif
#ifdef ESP32
ISRWatch = ISREdge;
#if defined(ESP32)
ISRWatch = ISREdge;
#elif defined(ARDUINO_ARCH_RP2040)
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, (PinStatus)ISREdge );
#else
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, ISREdge );
#endif
@@ -540,8 +543,10 @@ void ExternalInterruptHandler(void)
#if defined ( __STM32F1__ )
detachInterrupt( DccProcState.ExtIntNum );
#endif
#ifdef ESP32
#if defined(ESP32)
ISRWatch = ISREdge;
#elif defined(ARDUINO_ARCH_RP2040)
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, (PinStatus)ISREdge );
#else
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, ISREdge );
#endif
@@ -583,14 +588,17 @@ void ExternalInterruptHandler(void)
#if defined ( __STM32F1__ )
detachInterrupt( DccProcState.ExtIntNum );
#endif
#ifdef ESP32
ISRWatch = ISREdge;
#else
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, ISREdge );
#endif
// enable level-checking
ISRChkMask = DccProcState.ExtIntMask;
ISRLevel = (ISREdge==RISING)? DccProcState.ExtIntMask : 0 ;
#if defined(ESP32)
ISRWatch = ISREdge;
#elif defined(ARDUINO_ARCH_RP2040)
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, (PinStatus)ISREdge );
#else
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, ISREdge );
#endif
// enable level-checking
ISRChkMask = DccProcState.ExtIntMask;
ISRLevel = (ISREdge==RISING)? DccProcState.ExtIntMask : 0 ;
//CLR_TP4;
break;
@@ -755,10 +763,7 @@ uint8_t readEEPROM( unsigned int CV )
void writeEEPROM( unsigned int CV, uint8_t Value )
{
EEPROM.write(CV, Value) ;
#if defined(ESP8266)
EEPROM.commit();
#endif
#if defined(ESP32)
#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
EEPROM.commit();
#endif
}
@@ -1542,10 +1547,7 @@ void NmraDcc::initAccessoryDecoder( uint8_t ManufacturerId, uint8_t VersionId, u
////////////////////////////////////////////////////////////////////////
void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV )
{
#if defined(ESP8266)
EEPROM.begin(MAXCV);
#endif
#if defined(ESP32)
#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
EEPROM.begin(MAXCV);
#endif
// Clear all the static member variables

View File

@@ -125,6 +125,9 @@ typedef struct
#undef ALLOW_NESTED_IRQ // This is done with NVIC on STM32
#define PRIO_DCC_IRQ 9
#define PRIO_SYSTIC 8 // MUST be higher priority than DCC Irq
#elif defined(ARDUINO_ARCH_RP2040)
#define MAXCV 256 // todo: maybe somebody knows a good define for it
#else
#define MAXCV E2END // the upper limit of the CV value currently defined to max memory.
#endif

View File

@@ -1,9 +1,9 @@
name=NmraDcc
version=2.0.7
author=Alex Shepherd, Wolfgang Kuffer, Geoff Bunza, Martin Pischky, Franz-Peter Müller, Sven (littleyoda), Hans Tanner
maintainer=Alex Shepherd <kiwi64ajs@gmail.com>
sentence=Enables NMRA DCC Communication
paragraph=This library allows you to interface to a NMRA DCC track signal and receive DCC commands. The library has been tested on AVR ATTiny84/85 & ATMega88/168/328/32u4, ESP8266 and Teensy 3.x using the INT0/1 Hardware Interrupt and micros() ONLY and no longer uses Timer0 Compare Match B, which makes it much more portable to other platforms.
category=Communication
url=https://github.com/mrrwa/NmraDcc
architectures=*
name=NmraDcc
version=2.0.8
author=Alex Shepherd, Wolfgang Kuffer, Geoff Bunza, Martin Pischky, Franz-Peter Müller, Sven (littleyoda), Hans Tanner, bugfixes by Jueff
maintainer=Alex Shepherd <kiwi64ajs@gmail.com>
sentence=Enables NMRA DCC Communication
paragraph=This library allows you to interface to a NMRA DCC track signal and receive DCC commands. The library has been tested on AVR ATTiny84/85 & ATMega88/168/328/32u4, ESP8266 and Teensy 3.x using the INT0/1 Hardware Interrupt and micros() ONLY and no longer uses Timer0 Compare Match B, which makes it much more portable to other platforms.
category=Communication
url=https://github.com/mrrwa/NmraDcc
architectures=*