소스 검색

Dynamically switch SPI port in use

This allows "derived" libraries (like the one in Arduino101 core) to use both the onboard or an external flash, while avoiding forks

Still not sure about SPIClass, is it universal? I coundn't find a core declaring it differently but I'm quite sure it exists. "typeof" SPI would be better.
main
Martino Facchin 8 년 전
부모
커밋
ea513149de
2개의 변경된 파일9개의 추가작업 그리고 10개의 파일을 삭제
  1. +1
    -0
      SerialFlash.h
  2. +8
    -10
      SerialFlashChip.cpp

+ 1
- 0
SerialFlash.h 파일 보기

@@ -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 파일 보기

@@ -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…
취소
저장