@@ -66,6 +66,22 @@ bool ExternalEEPROM::begin(uint8_t deviceAddress, TwoWire &wirePort)
66
66
67
67
return true ;
68
68
}
69
+ bool ExternalEEPROM::begin (uint8_t WP = LED_BUILTIN, uint8_t deviceAddress, TwoWire &wirePort)
70
+ {
71
+ pinMode (WP, OUTPUT);
72
+ digitalWrite (WP, HIGH);
73
+ settings.wpPin = WP;
74
+ settings.usingWP = true ;
75
+ settings.i2cPort = &wirePort; // Grab which port the user wants us to use
76
+ settings.deviceAddress = deviceAddress;
77
+
78
+ if (isConnected () == false )
79
+ {
80
+ return false ;
81
+ }
82
+
83
+ return true ;
84
+ }
69
85
70
86
// Erase entire EEPROM
71
87
void ExternalEEPROM::erase (uint8_t toWrite)
@@ -876,6 +892,9 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
876
892
while (isBusy (settings.deviceAddress ) == true ) // Poll device's original address, not the modified one
877
893
delayMicroseconds (100 ); // This shortens the amount of time waiting between writes but hammers the I2C bus
878
894
895
+ // Check if we are using Write Protection then disable WP for write access
896
+ if (settings.usingWP ) digitalWrite (settings.wpPin , LOW);
897
+
879
898
settings.i2cPort ->beginTransmission (i2cAddress);
880
899
if (settings.addressSize_bytes > 1 ) // Device larger than 16,384 bits have two byte addresses
881
900
settings.i2cPort ->write ((uint8_t )((eepromLocation + recorded) >> 8 )); // MSB
@@ -885,6 +904,8 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
885
904
settings.i2cPort ->write (dataToWrite[recorded + x]);
886
905
887
906
result = settings.i2cPort ->endTransmission (); // Send stop condition
907
+ // Enable Write Protection if we are using WP
908
+ if (settings.usingWP ) digitalWrite (settings.wpPin , HIGH);
888
909
889
910
recorded += amtToWrite;
890
911
0 commit comments