Browse Source

Merge pull request #35 from facchinm/selectable_port

Dynamically switch SPI port in use
main
Paul Stoffregen 8 years ago
parent
commit
f383da63ff
2 changed files with 9 additions and 10 deletions
  1. +1
    -0
      SerialFlash.h
  2. +8
    -10
      SerialFlashChip.cpp

+ 1
- 0
SerialFlash.h View File

@@ -36,6 +36,7 @@ class SerialFlashFile;
class SerialFlashChip
{
public:
static bool begin(SPIClass& device, uint8_t pin = 6);
static bool begin(uint8_t pin = 6);
static uint32_t capacity(const uint8_t *id);
static uint32_t blockSize();

+ 8
- 10
SerialFlashChip.cpp View File

@@ -32,16 +32,6 @@
#define CSRELEASE() DIRECT_WRITE_HIGH(cspin_basereg, cspin_bitmask)
#define SPICONFIG SPISettings(50000000, MSBFIRST, SPI_MODE0)

#if defined(__arc__)
// Use SPI1 on Arduino 101 (accesses chip already on the board)
#define SPIPORT SPI1
#elif 0
// Add cases here, if you wish to use other SPI ports...
#else
// Otherwise, use the normal SPI port.
#define SPIPORT SPI
#endif

uint16_t SerialFlashChip::dirindex = 0;
uint8_t SerialFlashChip::flags = 0;
uint8_t SerialFlashChip::busy = 0;
@@ -49,6 +39,8 @@ uint8_t SerialFlashChip::busy = 0;
static volatile IO_REG_TYPE *cspin_basereg;
static IO_REG_TYPE cspin_bitmask;

static SPIClass& SPIPORT = SPI;

#define FLAG_32BIT_ADDR 0x01 // larger than 16 MByte address
#define FLAG_STATUS_CMD70 0x02 // requires special busy flag check
#define FLAG_DIFF_SUSPEND 0x04 // uses 2 different suspend commands
@@ -341,6 +333,12 @@ 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, uint8_t pin)
{
SPIPORT = device;
return begin(pin);
}

bool SerialFlashChip::begin(uint8_t pin)
{
uint8_t id[5];

Loading…
Cancel
Save