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

Make SPICONFIG configurable #61

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
2 changes: 2 additions & 0 deletions SerialFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class SerialFlashFile;
class SerialFlashChip
{
public:
static bool begin(SPIClass& device, SPISettings config, uint8_t pin = 6);
static bool begin(SPISettings config, uint8_t pin = 6);
static bool begin(SPIClass& device, uint8_t pin = 6);
static bool begin(uint8_t pin = 6);
static uint32_t capacity(const uint8_t *id);
Expand Down
15 changes: 14 additions & 1 deletion SerialFlashChip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#define CSASSERT() DIRECT_WRITE_LOW(cspin_basereg, cspin_bitmask)
#define CSRELEASE() DIRECT_WRITE_HIGH(cspin_basereg, cspin_bitmask)
#define SPICONFIG SPISettings(50000000, MSBFIRST, SPI_MODE0)

uint16_t SerialFlashChip::dirindex = 0;
uint8_t SerialFlashChip::flags = 0;
Expand All @@ -40,6 +39,7 @@ static volatile IO_REG_TYPE *cspin_basereg;
static IO_REG_TYPE cspin_bitmask;

static SPIClass& SPIPORT = SPI;
static SPISettings SPICONFIG = SPISettings(50000000, MSBFIRST, SPI_MODE0);

#define FLAG_32BIT_ADDR 0x01 // larger than 16 MByte address
#define FLAG_STATUS_CMD70 0x02 // requires special busy flag check
Expand Down Expand Up @@ -333,6 +333,19 @@ bool SerialFlashChip::ready()
//#define FLAG_DIFF_SUSPEND 0x04 // uses 2 different suspend commands
//#define FLAG_256K_BLOCKS 0x10 // has 256K erase blocks

bool SerialFlashChip::begin(SPIClass& device, SPISettings config, uint8_t pin)
{
SPIPORT = device;
SPICONFIG = config;

return begin(pin);
}
bool SerialFlashChip::begin(SPISettings config, uint8_t pin)
{
SPICONFIG = config;

return begin(pin);
}
bool SerialFlashChip::begin(SPIClass& device, uint8_t pin)
{
SPIPORT = device;
Expand Down