Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Late Initialization #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion SPIFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ SPIFlash::SPIFlash(uint8_t slaveSelectPin, uint16_t jedecID) {
_jedecID = jedecID;
}

/// Empty constructor to permit late pin and JedecID assignment.
SPIFlash::SPIFlash() {}

/// Set the pin and JedecID. (Only needed if the empty constructor was used.)
void SPIFlash::begin(uint8_t slaveSelectPin, uint16_t jedecID) {
_slaveSelectPin = slaveSelectPin;
_jedecID = jedecID;
}

/// Select the flash chip
void SPIFlash::select() {
//save current SPI settings
Expand Down Expand Up @@ -290,4 +299,4 @@ void SPIFlash::wakeup() {
/// cleanup
void SPIFlash::end() {
SPI.end();
}
}
4 changes: 3 additions & 1 deletion SPIFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class SPIFlash {
public:
static uint8_t UNIQUEID[8];
SPIFlash(uint8_t slaveSelectPin, uint16_t jedecID=0);
SPIFlash();
void begin(uint8_t slaveSelectPin, uint16_t jedecID=0);
boolean initialize();
void command(uint8_t cmd, boolean isWrite=false);
uint8_t readStatus();
Expand Down Expand Up @@ -120,4 +122,4 @@ class SPIFlash {
#endif
};

#endif
#endif
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SPIFlash KEYWORD1
initialize KEYWORD2
begin KEYWORD2
command KEYWORD2
readStatus KEYWORD2
readByte KEYWORD2
Expand All @@ -15,4 +16,4 @@ readUniqueId KEYWORD2
UNIQUEID KEYWORD2
sleep KEYWORD2
wakeup KEYWORD2
end KEYWORD2
end KEYWORD2