@@ -66,12 +66,14 @@ 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)
69
+ bool ExternalEEPROM::begin (uint8_t deviceAddress, TwoWire &wirePort, uint8_t WP )
70
70
{
71
- pinMode (WP, OUTPUT);
72
- digitalWrite (WP, HIGH);
73
- settings.wpPin = WP;
74
- settings.usingWP = true ;
71
+ if (WP != 255 )
72
+ {
73
+ pinMode (WP, OUTPUT);
74
+ digitalWrite (WP, HIGH);
75
+ settings.wpPin = WP;
76
+ }
75
77
settings.i2cPort = &wirePort; // Grab which port the user wants us to use
76
78
settings.deviceAddress = deviceAddress;
77
79
@@ -893,7 +895,7 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
893
895
delayMicroseconds (100 ); // This shortens the amount of time waiting between writes but hammers the I2C bus
894
896
895
897
// Check if we are using Write Protection then disable WP for write access
896
- if (settings.usingWP ) digitalWrite (settings.wpPin , LOW);
898
+ if (settings.wpPin != 255 ) digitalWrite (settings.wpPin , LOW);
897
899
898
900
settings.i2cPort ->beginTransmission (i2cAddress);
899
901
if (settings.addressSize_bytes > 1 ) // Device larger than 16,384 bits have two byte addresses
@@ -904,8 +906,6 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
904
906
settings.i2cPort ->write (dataToWrite[recorded + x]);
905
907
906
908
result = settings.i2cPort ->endTransmission (); // Send stop condition
907
- // Enable Write Protection if we are using WP
908
- if (settings.usingWP ) digitalWrite (settings.wpPin , HIGH);
909
909
910
910
recorded += amtToWrite;
911
911
@@ -914,6 +914,9 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
914
914
915
915
if (settings.pollForWriteComplete == false )
916
916
delay (settings.writeTime_ms ); // Delay the amount of time to record a page
917
+
918
+ // Enable Write Protection if we are using WP
919
+ if (settings.wpPin != 255 ) digitalWrite (settings.wpPin , HIGH);
917
920
}
918
921
919
922
return (result);
0 commit comments