Lab_interaccio/2021/Deimos/Deimos_master/mcp_can.cpp

44 lines
1.5 KiB
C++
Raw Permalink Normal View History

2025-02-25 21:29:42 +01:00
#include "mcp_can.h"
//SPIClass SPI_CAN(&sercom0, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);
//SPIClass SPI_CAN(&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3); // ???????
/*********************************************************************************************************
** Function name: MCP_CAN
** Descriptions: Constructor
*********************************************************************************************************/
MCP_CAN::MCP_CAN(byte _CS)
{
//pSPI = &SPI_CAN;
pSPI = &SPI;
init_CS(_CS);
}
/*********************************************************************************************************
** Function name: init_CS
** Descriptions: init CS pin and set UNSELECTED
*********************************************************************************************************/
void MCP_CAN::init_CS(byte _CS)
{
if (_CS == 0)
{
return;
}
SPICS = _CS;
pinMode(SPICS, OUTPUT);
digitalWrite(SPICS, HIGH);
}
void MCP_CAN::setSPI(SPIClass *_pSPI)
{
pSPI = _pSPI; // define SPI port to use before begin()
}
inline byte MCP_CAN::trySendExtMsgBuf(unsigned long id, byte len, const byte *buf, byte iTxBuf)
{ // as trySendMsgBuf, but set ext=1 and rtr=0
return trySendMsgBuf(id, 1, 0, len, buf, iTxBuf);
}
inline byte MCP_CAN::sendExtMsgBuf(byte status, unsigned long id, byte len, volatile const byte *buf)
{ // as sendMsgBuf, but set ext=1 and rtr=0
return sendMsgBuf(status, id, 1, 0, len, buf);
}