drop mcp_can_dfs.h

This commit is contained in:
Dmitry
2016-01-06 18:47:52 +03:00
parent 3fb00a093e
commit a9cbfcbf66
3 changed files with 133 additions and 139 deletions
+39 -40
View File
@@ -21,10 +21,10 @@ void MCP_CAN::endSPI() {
SPI.endTransaction();
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: reset
** Descriptions: reset the device
*********************************************************************************************************/
******************************************************************************/
void MCP_CAN::reset(void)
{
startSPI();
@@ -33,10 +33,10 @@ void MCP_CAN::reset(void)
delay(10);
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: readRegister
** Descriptions: read register
*********************************************************************************************************/
******************************************************************************/
uint8_t MCP_CAN::readRegister(const REGISTER reg)
{
startSPI();
@@ -48,10 +48,10 @@ uint8_t MCP_CAN::readRegister(const REGISTER reg)
return ret;
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: readRegisterS
** Descriptions: read registerS
*********************************************************************************************************/
******************************************************************************/
void MCP_CAN::readRegisterS(const REGISTER address, uint8_t values[], const uint8_t n)
{
startSPI();
@@ -64,10 +64,10 @@ void MCP_CAN::readRegisterS(const REGISTER address, uint8_t values[], const uint
endSPI();
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: setRegister
** Descriptions: set register
*********************************************************************************************************/
******************************************************************************/
void MCP_CAN::setRegister(const REGISTER reg, const uint8_t value)
{
startSPI();
@@ -77,10 +77,10 @@ void MCP_CAN::setRegister(const REGISTER reg, const uint8_t value)
endSPI();
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: setRegisterS
** Descriptions: set registerS
*********************************************************************************************************/
******************************************************************************/
void MCP_CAN::setRegisterS(const REGISTER reg, const uint8_t values[], const uint8_t n)
{
startSPI();
@@ -92,24 +92,24 @@ void MCP_CAN::setRegisterS(const REGISTER reg, const uint8_t values[], const uin
endSPI();
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: modifyRegister
** Descriptions: set bit of one register
*********************************************************************************************************/
void MCP_CAN::modifyRegister(const REGISTER address, const uint8_t mask, const uint8_t data)
******************************************************************************/
void MCP_CAN::modifyRegister(const REGISTER reg, const uint8_t mask, const uint8_t data)
{
startSPI();
SPI.transfer(INSTRUCTION_BITMOD);
SPI.transfer(address);
SPI.transfer(reg);
SPI.transfer(mask);
SPI.transfer(data);
endSPI();
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: getStatus
** Descriptions: read mcp2515's Status
*********************************************************************************************************/
******************************************************************************/
uint8_t MCP_CAN::getStatus(void)
{
startSPI();
@@ -120,10 +120,10 @@ uint8_t MCP_CAN::getStatus(void)
return i;
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: setCANCTRL_Mode
** Descriptions: set control mode
*********************************************************************************************************/
******************************************************************************/
MCP_CAN::ERROR MCP_CAN::setCANCTRL_Mode(const MODE newmode)
{
modifyRegister(MCP_CANCTRL, MODE_MASK, newmode);
@@ -133,10 +133,10 @@ MCP_CAN::ERROR MCP_CAN::setCANCTRL_Mode(const MODE newmode)
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: configRate
** Descriptions: set boadrate
*********************************************************************************************************/
******************************************************************************/
MCP_CAN::ERROR MCP_CAN::configRate(const CAN_SPEED canSpeed)
{
uint8_t set, cfg1, cfg2, cfg3;
@@ -255,10 +255,10 @@ MCP_CAN::ERROR MCP_CAN::configRate(const CAN_SPEED canSpeed)
}
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: init
** Descriptions: init the device
*********************************************************************************************************/
******************************************************************************/
MCP_CAN::ERROR MCP_CAN::init(const CAN_SPEED canSpeed)
{
reset();
@@ -287,10 +287,9 @@ MCP_CAN::ERROR MCP_CAN::init(const CAN_SPEED canSpeed)
setRegister(MCP_CANINTE, CANINTF_RX0IF | CANINTF_RX1IF);
modifyRegister(MCP_RXB0CTRL,
MCP_RXB_RX_MASK | MCP_RXB_BUKT_MASK,
MCP_RXB_RX_STDEXT | MCP_RXB_BUKT_MASK );
modifyRegister(MCP_RXB1CTRL, MCP_RXB_RX_MASK,
MCP_RXB_RX_STDEXT);
RXBnCTRL_RXM_MASK | RXB0CTRL_BUKT,
RXBnCTRL_RXM_STDEXT | RXB0CTRL_BUKT);
modifyRegister(MCP_RXB1CTRL, RXBnCTRL_RXM_MASK, RXBnCTRL_RXM_STDEXT);
res = setCANCTRL_Mode(m_mode);
delay(10);
@@ -299,10 +298,10 @@ MCP_CAN::ERROR MCP_CAN::init(const CAN_SPEED canSpeed)
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: write_id
** Descriptions: write can id
*********************************************************************************************************/
******************************************************************************/
void MCP_CAN::write_id(const REGISTER reg, const bool ext, const uint32_t id)
{
uint8_t tbufdata[4];
@@ -332,10 +331,10 @@ void MCP_CAN::prepareId(uint8_t *buffer, const bool ext, const uint32_t id)
}
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: set CS
** Descriptions: init CS pin and set UNSELECTED
*********************************************************************************************************/
******************************************************************************/
MCP_CAN::MCP_CAN(const uint8_t _CS, const MODE mode)
{
m_mode = mode;
@@ -344,20 +343,20 @@ MCP_CAN::MCP_CAN(const uint8_t _CS, const MODE mode)
endSPI();
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: init
** Descriptions: init can and set speed
*********************************************************************************************************/
******************************************************************************/
MCP_CAN::ERROR MCP_CAN::begin(const CAN_SPEED speedset)
{
SPI.begin();
return init(speedset);
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: initMask
** Descriptions: init canid Masks
*********************************************************************************************************/
******************************************************************************/
MCP_CAN::ERROR MCP_CAN::initMask(const uint8_t num, const bool ext, const uint32_t ulData)
{
delay(10);
@@ -381,10 +380,10 @@ MCP_CAN::ERROR MCP_CAN::initMask(const uint8_t num, const bool ext, const uint32
return res;
}
/*********************************************************************************************************
/******************************************************************************
** Function name: initFilt
** Descriptions: init canid filters
*********************************************************************************************************/
******************************************************************************/
MCP_CAN::ERROR MCP_CAN::initFilt(const RXF num, const bool ext, const uint32_t ulData)
{
delay(10);
@@ -524,10 +523,10 @@ MCP_CAN::ERROR MCP_CAN::readMessage(uint32_t *id, uint8_t *dlc, uint8_t buf[], b
return rc;
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: checkReceive
** Descriptions: check if got something
*********************************************************************************************************/
******************************************************************************/
bool MCP_CAN::checkReceive(void)
{
uint8_t res = getStatus();
@@ -538,10 +537,10 @@ bool MCP_CAN::checkReceive(void)
}
}
/*********************************************************************************************************
/*****************************************************************************
** Function name: checkError
** Descriptions: if something error
*********************************************************************************************************/
******************************************************************************/
bool MCP_CAN::checkError(void)
{
uint8_t eflg = readRegister(MCP_EFLG);