Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fterretf committed Jun 14, 2023
1 parent 4f50e9e commit c85c1c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
19 changes: 17 additions & 2 deletions src/ACAN2517FD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static uint16_t u16FromBufferAtIndex (uint8_t ioBuffer [], const uint8_t inIndex

//----------------------------------------------------------------------------------------------------------------------

ACAN2517FD::ACAN2517FD (const CanCmn::eCanBusId busId,
ACAN2517FD::ACAN2517FD (const CanCmn::eCanBusFdId busId,
const uint8_t inCS, // CS input of MCP2517FD
SPIClass & inSPI, // Hardware SPI object
const uint8_t inINT) : // INT output of MCP2517FD
Expand Down Expand Up @@ -351,7 +351,7 @@ uint32_t ACAN2517FD::begin (const ACAN2517FDSettings & inSettings,
}
}
//----------------------------------- Set full speed clock
mSPISettings = SPISettings (inSettings.sysClock () / 2, MSBFIRST, SPI_MODE0) ;
mSPISettings = SPISettings (8000UL*1000, MSBFIRST, SPI_MODE0) ;
//----------------------------------- Checking SPI connection is on (with a full speed clock)
// We write and read back 2517 RAM at address 0x400
for (uint32_t i=1 ; (i != 0) && (errorCode == 0) ; i <<= 1) {
Expand Down Expand Up @@ -1260,3 +1260,18 @@ uint32_t ACAN2517FD::diagInfos (const int inIndex) { // thanks to Flole998 and t
}

//----------------------------------------------------------------------------------------------------------------------
//Gpio
void ACAN2517FD::ledRedToggle() { //rxobfOn; avaible on CAN1,2
if (readRegister8(IOCON_REGISTER) & 0x01) {
ledRedOn();
}
else{
ledRedOff();
}
}
void ACAN2517FD::ledRedOn() {
writeRegister8 (IOCON_REGISTER, 0) ; // write 1 to gpio0
}
void ACAN2517FD::ledRedOff() {
writeRegister8 (IOCON_REGISTER, 1) ; // write 0 to gpio0
}
25 changes: 9 additions & 16 deletions src/ACAN2517FD.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ACAN2517FD {
// CONSTRUCTOR
//······················································································································

public: ACAN2517FD (const CanCmn::eCanBusId busId,
public: ACAN2517FD (const CanCmn::eCanBusFdId busId,
const uint8_t inCS, // CS input of MCP2517FD
SPIClass & inSPI, // Hardware SPI object
const uint8_t inINT) ; // INT output of MCP2517FD
Expand Down Expand Up @@ -137,7 +137,7 @@ class ACAN2517FD {
#endif
private: SPISettings mSPISettings ;
private: SPIClass & mSPI ;
private: CanCmn::eCanBusId mBusId;
private: CanCmn::eCanBusFdId mBusId;
private: const uint8_t mCS ;
private: const uint8_t mINT ;
private: bool mUsesTXQ ;
Expand Down Expand Up @@ -173,6 +173,11 @@ class ACAN2517FD {
public: uint32_t driverTransmitBufferCount (void) const { return mDriverTransmitBuffer.count () ; }

public: uint32_t driverTransmitBufferPeakCount (void) const { return mDriverTransmitBuffer.peakCount () ; }
// Gpio
public:
void ledRedToggle();
void ledRedOn();
void ledRedOff();

//······················································································································
// Private methods
Expand Down Expand Up @@ -308,13 +313,7 @@ class ACAN2517FD {
}
private: inline void assertCS() {
switch (mBusId) {
case CanCmn::eCanBusId::eCan0:
digitalWrite(mCS, LOW);
break;
case CanCmn::eCanBusId::eCan1:
_Mux.can1Cs();
break;
case CanCmn::eCanBusId::eCan2:
case CanCmn::eCanBusFdId::eCanFd2:
_Mux.can2Cs();
break;

Expand All @@ -324,13 +323,7 @@ class ACAN2517FD {
}
private: inline void deassertCS() {
switch (mBusId) {
case CanCmn::eCanBusId::eCan0:
digitalWrite(mCS, HIGH);
break;
case CanCmn::eCanBusId::eCan1:
_Mux.can1UnCs();
break;
case CanCmn::eCanBusId::eCan2:
case CanCmn::eCanBusFdId::eCanFd2:
_Mux.can2UnCs();
break;
default:
Expand Down

0 comments on commit c85c1c3

Please sign in to comment.