Skip to content
Open
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
32 changes: 18 additions & 14 deletions mcp2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ const struct MCP2515::RXBn_REGS MCP2515::RXB[N_RXBUFFERS] = {
{MCP_RXB1CTRL, MCP_RXB1SIDH, MCP_RXB1DATA, CANINTF_RX1IF}
};

MCP2515::MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK, SPIClass * _SPI)
{
if (_SPI != nullptr) {
SPIn = _SPI;
}
else {
SPIn = &SPI;
SPIn->begin();
}

SPICS = _CS;
SPI_CLOCK = _SPI_CLOCK;
pinMode(SPICS, OUTPUT);
endSPI();
MCP2515::MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK, SPIClass *_SPI) {
if (_SPI != nullptr) { // It maintains compatibility with old sketches.
begin(_SPI);
}
SPICS = _CS;
SPI_CLOCK = _SPI_CLOCK;
}

bool MCP2515::begin(SPIClass *_SPI) {
if (_SPI != nullptr) {
SPIn = _SPI;
} else {
SPIn = &SPI;
SPIn->begin();
}
pinMode(SPICS, OUTPUT);
endSPI();
return true;
}

void MCP2515::startSPI() {
Expand Down