Browse Source

add gstate and dev status to tmc5130

master
zhaohe 1 year ago
parent
commit
15dc8ec2ad
  1. 34
      components/tmc/ic/ztmc5130.cpp
  2. 28
      components/tmc/ic/ztmc5130.hpp

34
components/tmc/ic/ztmc5130.cpp

@ -38,37 +38,53 @@ void TMC5130::initialize(cfg_t *cfg) {
ZASSERT(m_ennpin);
}
m_hspi = cfg->hspi;
reInitialize();
}
void TMC5130::reInitialize() {
enableIC(false);
// tmc5130_init(&m_TMC5130, channel, &m_tmc_api_config, &tmc5130_defaultRegisterResetState[0]);
// tmc5130_setCallback(&m_TMC5130, pri_tmc4361A_callback);
reset();
writeInt(TMC5130_PWMCONF, 0x000500C8);
// writeInt( TMC5130_GCONF, 0x00000004);
writeInt(TMC5130_CHOPCONF, 0x000100c3);
writeInt(TMC5130_IHOLD_IRUN, 0x00051A00);
writeInt(TMC5130_PWMCONF, 0x000401c8);
writeInt(TMC5130_XTARGET, 0);
writeInt(TMC5130_XACTUAL, 0x00000000);
writeInt(TMC5130_VACTUAL, 0x00000000);
writeInt(TMC5130_VSTART, 5);
writeInt(TMC5130_A1, 1000);
writeInt(TMC5130_V1, 0);
writeInt(TMC5130_D1, 1000);
writeInt(TMC5130_VSTOP, 10);
writeInt(TMC5130_TZEROWAIT, 1000);
setAcceleration(100000);
setDeceleration(100000);
setIHOLD_IRUN(2, 10, 1);
enableIC(true);
}
DevStatusReg_t TMC5130::getDevStatus() {
static_assert(sizeof(DevStatusReg_t) == 4);
uint32_t value = readInt(TMC5130_DRVSTATUS);
return *(DevStatusReg_t *)&value;
}
GState_t TMC5130::getGState() {
static_assert(sizeof(GState_t) == 4);
uint32_t value = readInt(TMC5130_GSTAT);
return *(GState_t *)&value;
}
// TMC5130_GSTAT
bool TMC5130::ping() {
uint32_t chipID = readChipVERSION();
if (0x11 == chipID) {
return true;
} else {
return false;
}
}
void TMC5130::enableIC(bool enable) {
// m_port->TMC5130Port_setENNPinState(m_channel, !enable);
SET_PIN(m_ennpin, !enable);

28
components/tmc/ic/ztmc5130.hpp

@ -58,6 +58,28 @@ class Tmc5130RampStat {
bool isSetted(ramp_stat_bit_t bit) { return (m_state & bit) != 0; }
};
typedef struct {
uint32_t sg_result : 10;
uint32_t reserved0 : 5;
uint32_t fsactive : 1;
uint32_t cs_actual : 5;
uint32_t reserved1 : 3;
uint32_t stallguard : 1;
uint32_t ot : 1;
uint32_t otpw : 1;
uint32_t s2ga : 1;
uint32_t s2gb : 1;
uint32_t ola : 1;
uint32_t olb : 1;
uint32_t stst : 1;
} DevStatusReg_t;
typedef struct {
uint32_t reset : 1;
uint32_t drv_err : 1;
uint32_t uv_cp : 1;
} GState_t;
class TMC5130 : public IStepperMotor {
public:
typedef struct {
@ -88,6 +110,7 @@ class TMC5130 : public IStepperMotor {
// static void createDeafultTMC5130Config(TMC5130Config_t *config, TMC5130Port *m_port);
void initialize(cfg_t *cfg);
void reInitialize();
void enableIC(bool enable);
uint8_t reset();
@ -127,6 +150,9 @@ class TMC5130 : public IStepperMotor {
virtual bool isReachTarget(); // 是否到达目标位置
virtual bool isStoped() { return isReachTarget(); }
bool ping();
DevStatusReg_t getDevStatus();
GState_t getGState();
/*******************************************************************************
* *
*******************************************************************************/
@ -140,4 +166,4 @@ class TMC5130 : public IStepperMotor {
uint32_t haspassedms(uint32_t now, uint32_t last);
};
} // namespace iflytop
#endif
#endif
Loading…
Cancel
Save