|
|
@ -30,17 +30,21 @@ void TMC5130::initialize(cfg_t *cfg) { |
|
|
|
// m_port = config->m_port;
|
|
|
|
m_registerAccessTable = &tmc5130_defaultRegisterAccess[0]; |
|
|
|
m_defaultRegisterResetState = &tmc5130_defaultRegisterResetState[0]; |
|
|
|
if (cfg->csn_pin != PinNull) { |
|
|
|
if (cfg->csgpio != PinNull) { |
|
|
|
m_csnpin = new ZGPIO(); |
|
|
|
m_csnpin->initAsOutput(cfg->csn_pin, ZGPIO::kMode_nopull, false, true); |
|
|
|
m_csnpin->initAsOutput(cfg->csgpio, ZGPIO::kMode_nopull, false, true); |
|
|
|
ZASSERT(m_csnpin); |
|
|
|
} |
|
|
|
if (cfg->enn_pin != PinNull) { |
|
|
|
if (cfg->ennPin != PinNull) { |
|
|
|
m_ennpin = new ZGPIO(); |
|
|
|
m_ennpin->initAsOutput(cfg->enn_pin, ZGPIO::kMode_nopull, false, true); |
|
|
|
m_ennpin->initAsOutput(cfg->ennPin, ZGPIO::kMode_nopull, false, true); |
|
|
|
ZASSERT(m_ennpin); |
|
|
|
} |
|
|
|
m_hspi = cfg->hspi; |
|
|
|
if (cfg->spi_mode_select != PinNull) { |
|
|
|
m_spi_mode_select_gpio = new ZGPIO(); |
|
|
|
m_spi_mode_select_gpio->initAsOutput(cfg->spi_mode_select, ZGPIO::kMode_nopull, false, false); |
|
|
|
} |
|
|
|
m_hspi = cfg->spi; |
|
|
|
|
|
|
|
enableIC(false); |
|
|
|
// tmc5130_init(&m_TMC5130, channel, &m_tmc_api_config, &tmc5130_defaultRegisterResetState[0]);
|
|
|
@ -93,16 +97,14 @@ uint8_t TMC5130::reset() { |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t TMC5130::getXACTUAL() { return readInt(TMC5130_XACTUAL) / m_scale; } |
|
|
|
void TMC5130::setXACTUAL(int32_t value) { writeInt(TMC5130_XACTUAL, value * m_scale); } |
|
|
|
int32_t TMC5130::getVACTUAL() { return readInt(TMC5130_VACTUAL) / m_scale; } |
|
|
|
void TMC5130::setAcceleration(float accelerationpps2) { writeInt(TMC5130_AMAX, (int32_t)(accelerationpps2 * m_scale)); } // 设置最大加速度
|
|
|
|
void TMC5130::setDeceleration(float accelerationpps2) { writeInt(TMC5130_DMAX, (int32_t)(accelerationpps2 * m_scale)); } // 设置最大减速度
|
|
|
|
void TMC5130::setMotorShaft(bool reverse) { PRV_FIELD_WRITE(TMC5130_GCONF, TMC5130_SHAFT_MASK, TMC5130_SHAFT_SHIFT, reverse); } |
|
|
|
void TMC5130::setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) { |
|
|
|
writeInt(TMC5130_IHOLD_IRUN, (iholddelay << TMC5130_IHOLDDELAY_SHIFT) | (irun << TMC5130_IRUN_SHIFT) | (ihold << TMC5130_IHOLD_SHIFT)); |
|
|
|
} |
|
|
|
uint32_t TMC5130::readChipVERSION() { |
|
|
|
int32_t TMC5130::getXACTUAL() { return readInt(TMC5130_XACTUAL) / m_scale; } |
|
|
|
void TMC5130::setXACTUAL(int32_t value) { writeInt(TMC5130_XACTUAL, value * m_scale); } |
|
|
|
int32_t TMC5130::getVACTUAL() { return readInt(TMC5130_VACTUAL) / m_scale; } |
|
|
|
void TMC5130::setAcceleration(float accelerationpps2) { writeInt(TMC5130_AMAX, (int32_t)(accelerationpps2 * m_scale)); } // 设置最大加速度
|
|
|
|
void TMC5130::setDeceleration(float accelerationpps2) { writeInt(TMC5130_DMAX, (int32_t)(accelerationpps2 * m_scale)); } // 设置最大减速度
|
|
|
|
void TMC5130::setMotorShaft(bool reverse) { PRV_FIELD_WRITE(TMC5130_GCONF, TMC5130_SHAFT_MASK, TMC5130_SHAFT_SHIFT, reverse); } |
|
|
|
void TMC5130::setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) { writeInt(TMC5130_IHOLD_IRUN, (iholddelay << TMC5130_IHOLDDELAY_SHIFT) | (irun << TMC5130_IRUN_SHIFT) | (ihold << TMC5130_IHOLD_SHIFT)); } |
|
|
|
uint32_t TMC5130::readICVersion() { |
|
|
|
uint32_t chipID = PRV_FIELD_READ(TMC5130_IOIN, TMC5130_VERSION_MASK, TMC5130_VERSION_SHIFT); |
|
|
|
return chipID; |
|
|
|
} |
|
|
|