Browse Source

Add pinIsMOSI(), pinIsMISO(), pinIsSCK()

main
PaulStoffregen 7 years ago
parent
commit
3f5108d197
2 changed files with 54 additions and 0 deletions
  1. +48
    -0
      SPI.cpp
  2. +6
    -0
      SPI.h

+ 48
- 0
SPI.cpp View File

return true; return true;
} }


bool SPIClass::pinIsMOSI(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().mosi_pin); i++) {
if (pin == hardware().mosi_pin[i]) return true;
}
return false;
}

bool SPIClass::pinIsMISO(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().miso_pin); i++) {
if (pin == hardware().miso_pin[i]) return true;
}
return false;
}

bool SPIClass::pinIsSCK(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().sck_pin); i++) {
if (pin == hardware().sck_pin[i]) return true;
}
return false;
}

// setCS() is not intended for use from normal Arduino programs/sketches. // setCS() is not intended for use from normal Arduino programs/sketches.
uint8_t SPIClass::setCS(uint8_t pin) uint8_t SPIClass::setCS(uint8_t pin)
{ {
return 0; return 0;
} }


bool SPIClass::pinIsMOSI(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().mosi_pin); i++) {
if (pin == hardware().mosi_pin[i]) return true;
}
return false;
}

bool SPIClass::pinIsMISO(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().miso_pin); i++) {
if (pin == hardware().miso_pin[i]) return true;
}
return false;
}

bool SPIClass::pinIsSCK(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().sck_pin); i++) {
if (pin == hardware().sck_pin[i]) return true;
}
return false;
}

// setCS() is not intended for use from normal Arduino programs/sketches. // setCS() is not intended for use from normal Arduino programs/sketches.
uint8_t SPIClass::setCS(uint8_t pin) uint8_t SPIClass::setCS(uint8_t pin)
{ {

+ 6
- 0
SPI.h View File



// return true if "pin" has special chip select capability // return true if "pin" has special chip select capability
uint8_t pinIsChipSelect(uint8_t pin); uint8_t pinIsChipSelect(uint8_t pin);
bool pinIsMOSI(uint8_t pin);
bool pinIsMISO(uint8_t pin);
bool pinIsSCK(uint8_t pin);
// return true if both pin1 and pin2 have independent chip select capability // return true if both pin1 and pin2 have independent chip select capability
bool pinIsChipSelect(uint8_t pin1, uint8_t pin2); bool pinIsChipSelect(uint8_t pin1, uint8_t pin2);
// configure a pin for chip select and return its SPI_MCR_PCSIS bitmask // configure a pin for chip select and return its SPI_MCR_PCSIS bitmask
void setSCK(uint8_t pin); void setSCK(uint8_t pin);
// return true if "pin" has special chip select capability // return true if "pin" has special chip select capability
bool pinIsChipSelect(uint8_t pin); bool pinIsChipSelect(uint8_t pin);
bool pinIsMOSI(uint8_t pin);
bool pinIsMISO(uint8_t pin);
bool pinIsSCK(uint8_t pin);
// return true if both pin1 and pin2 have independent chip select capability // return true if both pin1 and pin2 have independent chip select capability
bool pinIsChipSelect(uint8_t pin1, uint8_t pin2) { return false; } bool pinIsChipSelect(uint8_t pin1, uint8_t pin2) { return false; }
// configure a pin for chip select and return its SPI_MCR_PCSIS bitmask // configure a pin for chip select and return its SPI_MCR_PCSIS bitmask

Loading…
Cancel
Save