From ff3e24dff4a8253947f221ee614e4266629815b6 Mon Sep 17 00:00:00 2001 From: Thierry Paris Date: Wed, 23 Jan 2019 02:15:46 +0100 Subject: [PATCH] Add ESP32 support (#21) * Update README.md * Added ESP32 support. --- NmraDcc.cpp | 22 +++++++++++++++++++++- NmraDcc.h | 17 ++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/NmraDcc.cpp b/NmraDcc.cpp index 39c80c8..48ed11d 100644 --- a/NmraDcc.cpp +++ b/NmraDcc.cpp @@ -25,6 +25,7 @@ // 2017-01-19 added STM32F1 support by Franz-Peter // 2017-11-29 Ken West (kgw4449@gmail.com): // Minor fixes to pass NMRA Baseline Conformance Tests. +// 2018-12-17 added ESP32 support by Trusty (thierry@lapajaparis.net) // //------------------------------------------------------------------------ // @@ -174,9 +175,22 @@ #define MODE_TP3 pinMode( D7,OUTPUT ) ; // GPIO 13 #define SET_TP3 GPOS = (1 << D7); #define CLR_TP3 GPOC = (1 << D7); - #define MODE_TP4 pinMode( D7,OUTPUT ); // GPIO 15 + #define MODE_TP4 pinMode( D8,OUTPUT ) ; // GPIO 15 #define SET_TP4 GPOC = (1 << D8); #define CLR_TP4 GPOC = (1 << D8); + #elif defined(ESP32) + #define MODE_TP1 pinMode( 33,OUTPUT ) ; // GPIO 33 + #define SET_TP1 GPOS = (1 << 33); + #define CLR_TP1 GPOC = (1 << 33); + #define MODE_TP2 pinMode( 25,OUTPUT ) ; // GPIO 25 + #define SET_TP2 GPOS = (1 << 25); + #define CLR_TP2 GPOC = (1 << 25); + #define MODE_TP3 pinMode( 26,OUTPUT ) ; // GPIO 26 + #define SET_TP3 GPOS = (1 << 26); + #define CLR_TP3 GPOC = (1 << 26); + #define MODE_TP4 pinMode( 27,OUTPUT ) ; // GPIO 27 + #define SET_TP4 GPOC = (1 << 27); + #define CLR_TP4 GPOC = (1 << 27); //#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) @@ -536,6 +550,9 @@ void writeEEPROM( unsigned int CV, uint8_t Value ) { #if defined(ESP8266) EEPROM.commit(); #endif + #if defined(ESP32) + EEPROM.commit(); + #endif } bool readyEEPROM() { @@ -1299,6 +1316,9 @@ void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, ui #if defined(ESP8266) EEPROM.begin(MAXCV); #endif + #if defined(ESP32) + EEPROM.begin(MAXCV); + #endif // Clear all the static member variables memset( &DccRx, 0, sizeof( DccRx) ); diff --git a/NmraDcc.h b/NmraDcc.h index d5ae4b8..d1834c7 100644 --- a/NmraDcc.h +++ b/NmraDcc.h @@ -32,7 +32,7 @@ // Uncomment the following Line to Enable Service Mode CV Programming #define NMRA_DCC_PROCESS_SERVICEMODE -// Uncomment the following line to Enable MutliFunction Decoder Operations +// Uncomment the following line to Enable MultiFunction Decoder Operations #define NMRA_DCC_PROCESS_MULTIFUNCTION // Uncomment the following line to Enable 14 Speed Step Support @@ -96,14 +96,17 @@ typedef struct #define CV_MANUFACTURER_ID 8 #define CV_29_CONFIG 29 -#if defined(ESP8266) -#include -#define MAXCV SPI_FLASH_SEC_SIZE +#if defined(ESP32) + #include + #define MAXCV SPI_FLASH_SEC_SIZE +#elif defined(ESP8266) + #include + #define MAXCV SPI_FLASH_SEC_SIZE #elif defined( __STM32F1__) -#define MAXCV (EEPROM_PAGE_SIZE/4 - 1) // number of storage places (CV address could be larger + #define MAXCV (EEPROM_PAGE_SIZE/4 - 1) // number of storage places (CV address could be larger // because STM32 uses virtual adresses) #else -#define MAXCV E2END // the upper limit of the CV value currently defined to max memory. + #define MAXCV E2END // the upper limit of the CV value currently defined to max memory. #endif typedef enum { @@ -651,7 +654,7 @@ extern uint8_t notifyIsSetCVReady(void) __attribute__ ((weak)); * notifyCVChange() Called when a CV value is changed. * This is called whenever a CV's value is changed. * notifyDccCVChange() Called only when a CV value is changed by a Dcc packet or a internal lib function. - * it is NOT called if the CV is chaged by means of the setCV() method. + * it is NOT called if the CV is changed by means of the setCV() method. * Note: It is not called if notifyCVWrite() is defined * or if the value in the EEPROM is the same as the value * in the write command.