Skip to content

Commit

Permalink
allows global object instances be switch off with defines (esp8266#2344)
Browse files Browse the repository at this point in the history
  • Loading branch information
everslick authored and igrr committed Aug 1, 2016
1 parent bd01e44 commit 1829745
Show file tree
Hide file tree
Showing 26 changed files with 72 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ using fs::SeekEnd;
using fs::FSInfo;
#endif //FS_NO_GLOBALS

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPIFFS)
extern fs::FS SPIFFS;
#endif

#endif //FS_H
2 changes: 2 additions & 0 deletions cores/esp8266/spiffs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ extern "C" uint32_t _SPIFFS_block;
#define SPIFFS_MAX_OPEN_FILES 5
#endif

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPIFFS)
FS SPIFFS = FS(FSImplPtr(new SPIFFSImpl(
SPIFFS_PHYS_ADDR,
SPIFFS_PHYS_SIZE,
SPIFFS_PHYS_PAGE,
SPIFFS_PHYS_BLOCK,
SPIFFS_MAX_OPEN_FILES)));
#endif

#endif
2 changes: 2 additions & 0 deletions libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,6 @@ int ArduinoOTAClass::getCommand() {
return _cmd;
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ARDUINOOTA)
ArduinoOTAClass ArduinoOTA;
#endif
2 changes: 2 additions & 0 deletions libraries/ArduinoOTA/ArduinoOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class ArduinoOTAClass
String readStringUntil(char end);
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ARDUINOOTA)
extern ArduinoOTAClass ArduinoOTA;
#endif

#endif /* __ARDUINO_OTA_H */
17 changes: 14 additions & 3 deletions libraries/EEPROM/EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
#include "Arduino.h"
#include "EEPROM.h"

extern "C" {
extern "C" {
#include "c_types.h"
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "spi_flash.h"
}

extern "C" uint32_t _SPIFFS_end;

EEPROMClass::EEPROMClass(uint32_t sector)
: _sector(sector)
, _data(0)
Expand All @@ -38,6 +40,14 @@ EEPROMClass::EEPROMClass(uint32_t sector)
{
}

EEPROMClass::EEPROMClass(void)
: _sector((((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE))
, _data(0)
, _size(0)
, _dirty(false)
{
}

void EEPROMClass::begin(size_t size) {
if (size <= 0)
return;
Expand Down Expand Up @@ -121,5 +131,6 @@ uint8_t * EEPROMClass::getDataPtr() {
return &_data[0];
}

extern "C" uint32_t _SPIFFS_end;
EEPROMClass EEPROM((((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE));
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
EEPROMClass EEPROM;
#endif
3 changes: 3 additions & 0 deletions libraries/EEPROM/EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
class EEPROMClass {
public:
EEPROMClass(uint32_t sector);
EEPROMClass(void);

void begin(size_t size);
uint8_t read(int address);
Expand Down Expand Up @@ -64,7 +65,9 @@ class EEPROMClass {
bool _dirty;
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
extern EEPROMClass EEPROM;
#endif

#endif

3 changes: 3 additions & 0 deletions libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,8 @@ void ESP8266NetBIOS::_s_recv(void *arg, udp_pcb *upcb, pbuf *p, struct ip_addr *
reinterpret_cast<ESP8266NetBIOS*>(arg)->_recv(upcb, p, addr, port);
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_NETBIOS)
ESP8266NetBIOS NBNS;
#endif

// EOF
2 changes: 2 additions & 0 deletions libraries/ESP8266NetBIOS/ESP8266NetBIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ESP8266NetBIOS
void end();
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_NETBIOS)
extern ESP8266NetBIOS NBNS;
#endif

#endif
2 changes: 2 additions & 0 deletions libraries/ESP8266SSDP/ESP8266SSDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,6 @@ void SSDPClass::_startTimer() {
os_timer_arm(tm, interval, 1 /* repeat */);
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
SSDPClass SSDP;
#endif
2 changes: 2 additions & 0 deletions libraries/ESP8266SSDP/ESP8266SSDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class SSDPClass{
char _modelNumber[SSDP_MODEL_VERSION_SIZE];
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
extern SSDPClass SSDP;
#endif

#endif
4 changes: 2 additions & 2 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,6 @@ bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int com
return true;
}



#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE)
ESP8266HTTPUpdate ESPhttpUpdate;
#endif
2 changes: 2 additions & 0 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class ESP8266HTTPUpdate
bool _rebootOnUpdate = true;
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE)
extern ESP8266HTTPUpdate ESPhttpUpdate;
#endif

#endif /* ESP8266HTTPUPDATE_H_ */
4 changes: 3 additions & 1 deletion libraries/ESP8266mDNS/ESP8266mDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,4 +1046,6 @@ void MDNSResponder::_reply(uint8_t replyMask, char * service, char *proto, uint1
_conn->send();
}

MDNSResponder MDNS = MDNSResponder();
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_MDNS)
MDNSResponder MDNS;
#endif
2 changes: 2 additions & 0 deletions libraries/ESP8266mDNS/ESP8266mDNS.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class MDNSResponder {
void _restart();
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_MDNS)
extern MDNSResponder MDNS;
#endif

#endif //ESP8266MDNS_H
4 changes: 3 additions & 1 deletion libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,6 @@ IPAddress EthernetClass::dnsServerIP()
return _dnsServerAddress;
}

EthernetClass Ethernet;
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ETHERNET)
EthernetClass Ethernet;
#endif
2 changes: 2 additions & 0 deletions libraries/Ethernet/src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class EthernetClass {
friend class EthernetServer;
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ETHERNET)
extern EthernetClass Ethernet;
#endif

#endif
2 changes: 2 additions & 0 deletions libraries/SD/src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,6 @@ void File::rewindDirectory(void) {
_file->rewind();
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SD)
SDClass SD;
#endif
2 changes: 2 additions & 0 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class SDClass {
friend boolean callback_openPath(SdFile&, char *, boolean, void *);
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SD)
extern SDClass SD;
#endif

#endif
5 changes: 3 additions & 2 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ typedef union {
};
} spiClk_t;

SPIClass SPI;

SPIClass::SPIClass() {
useHwCs = false;
}
Expand Down Expand Up @@ -486,3 +484,6 @@ void SPIClass::transferBytes_(uint8_t * out, uint8_t * in, uint8_t size) {
}
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPI)
SPIClass SPI;
#endif
2 changes: 2 additions & 0 deletions libraries/SPI/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class SPIClass {
inline void setDataBits(uint16_t bits);
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPI)
extern SPIClass SPI;
#endif

#endif
2 changes: 2 additions & 0 deletions libraries/SPISlave/src/SPISlave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ void SPISlaveClass::onStatusSent(SpiSlaveSentHandler cb)
_status_sent_cb = cb;
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPISLAVE)
SPISlaveClass SPISlave;
#endif
2 changes: 2 additions & 0 deletions libraries/SPISlave/src/SPISlave.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class SPISlaveClass
void onStatusSent(SpiSlaveSentHandler cb);
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPISLAVE)
extern SPISlaveClass SPISlave;
#endif

#endif
5 changes: 4 additions & 1 deletion libraries/TFT_Touch_Shield_V2/TFTv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,10 @@ INT8U TFT::drawFloat(float floatNumber,INT16U poX, INT16U poY,INT16U size,INT16U
return f;
}

TFT Tft=TFT();
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_TFT)
TFT Tft;
#endif

/*********************************************************************************************************
END FILE
*********************************************************************************************************/
2 changes: 2 additions & 0 deletions libraries/TFT_Touch_Shield_V2/TFTv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ class TFT

};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_TFT)
extern TFT Tft;
#endif

#endif

Expand Down
4 changes: 3 additions & 1 deletion libraries/Wire/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,6 @@ void TwoWire::onRequest( void (*function)(void) ){

// Preinstantiate Objects //////////////////////////////////////////////////////

TwoWire Wire = TwoWire();
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_TWOWIRE)
TwoWire Wire;
#endif
2 changes: 2 additions & 0 deletions libraries/Wire/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class TwoWire : public Stream
using Print::write;
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_TWOWIRE)
extern TwoWire Wire;
#endif

#endif

0 comments on commit 1829745

Please sign in to comment.