Saved some 50K flash memory by modifying the singleton implementation

This commit is contained in:
lacklustrlabs 2017-12-22 20:04:24 +01:00 committed by Lacklustrlabs
parent b46b7461f4
commit 4ad4de080f
1 changed files with 10 additions and 4 deletions

View File

@ -492,14 +492,20 @@ TwoWire& Wire1 = TwoWire::getInstance1(); //SCL: D1 SDA: D0
// Static methods ////////////////////////////////////////////////////////////// // Static methods //////////////////////////////////////////////////////////////
TwoWire& TwoWire::getInstance(){ TwoWire& TwoWire::getInstance(){
static TwoWire instance(I2C1); static TwoWire* instance = nullptr;
return instance; if (!instance) {
instance = new TwoWire(I2C1);
}
return *instance;
} }
#if WIRE_INTERFACES_COUNT > 1 #if WIRE_INTERFACES_COUNT > 1
TwoWire& TwoWire::getInstance1(){ TwoWire& TwoWire::getInstance1(){
static TwoWire instance(I2C2); static TwoWire* instance = nullptr;
return instance; if (!instance) {
instance = new TwoWire(I2C2);
}
return *instance;
} }
#endif #endif