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

Update mcp2515.cpp #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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