|
|
@ -9,19 +9,20 @@ |
|
|
|
|
|
|
|
#define TAG "main"
|
|
|
|
|
|
|
|
//
|
|
|
|
// port_tmc_DRV_ENN_pin_set_state
|
|
|
|
|
|
|
|
class TMC4361AImpl : public TMC4361A { |
|
|
|
virtual void setResetPinState(bool state){}; |
|
|
|
virtual void setFREEZEPinState(bool state){}; |
|
|
|
virtual void setENNPinState(bool state){}; |
|
|
|
protected: |
|
|
|
virtual void setResetPinState(bool state) { port_tmc_nRESET_pin_set_state(m_channel, state); }; |
|
|
|
virtual void setFREEZEPinState(bool state) { port_tmc_nFREEZE_pin_set_state(m_channel, state); }; |
|
|
|
virtual void setENNPinState(bool state) { port_tmc_ENN_pin_set_state(m_channel, state); }; |
|
|
|
virtual bool getTargetReachedPinState() { return false; }; |
|
|
|
virtual void sleepus(int32_t us) { port_delay_us(us); }; |
|
|
|
virtual void readWriteArray(uint8_t *data, size_t length) { //
|
|
|
|
if (m_channel == MOTOR_1_TMC4361A_CHANNEL) { |
|
|
|
port_tmc4361_spi_write_and_read(data, length); |
|
|
|
} |
|
|
|
port_tmc_motor_spi_write_and_read(m_channel, data, length); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
class TMC2160Impl : public TMC2160 { |
|
|
|
TMC4361A *m_tmc4361; |
|
|
|
|
|
|
@ -31,8 +32,9 @@ class TMC2160Impl : public TMC2160 { |
|
|
|
TMC2160::initialize(channel); |
|
|
|
} |
|
|
|
|
|
|
|
virtual void setENNPinState(bool state){}; |
|
|
|
virtual void sleepus(int32_t us){}; |
|
|
|
protected: |
|
|
|
virtual void setENNPinState(bool state) { port_tmc_ENN_pin_set_state(m_channel, state); }; |
|
|
|
virtual void sleepus(int32_t us) { port_delay_us(us); }; |
|
|
|
virtual void readWriteArray(uint8_t *data, size_t length) { m_tmc4361->readWriteCover(data, length); }; |
|
|
|
}; |
|
|
|
|
|
|
@ -48,13 +50,23 @@ int umain(int argc, char const *argv[]) { |
|
|
|
|
|
|
|
tmc4361motor1.initialize(MOTOR_1_TMC4361A_CHANNEL, TMC4361A::IC_TMC2160); |
|
|
|
tmc2160motor1.initialize(MOTOR_1_TMC2160_CHANNEL, &tmc4361motor1); |
|
|
|
|
|
|
|
HAL_Delay(100); |
|
|
|
tmc4361motor1.enableIC(true); |
|
|
|
tmc2160motor1.enableIC(true); |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 通过读取Version寄存器来判断芯片是否正常 |
|
|
|
*/ |
|
|
|
int32_t ic4361Version = tmc4361motor1.readICVersion(); |
|
|
|
int32_t ic2160Version = tmc2160motor1.readICVersion(); |
|
|
|
// 期望 4361Version:2 ic2160Version:30
|
|
|
|
ZLOGI(TAG, "4361Version:%x ic2160Version:%x", ic4361Version, ic2160Version); |
|
|
|
|
|
|
|
tmc4361motor1.setMaximumAcceleration(300000); |
|
|
|
tmc4361motor1.setMaximumDeceleration(300000); |
|
|
|
tmc4361motor1.rotate(100000); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
int32_t ic4361Version = tmc4361motor1.readICVersion(); |
|
|
|
int32_t ic2160Version = tmc2160motor1.readICVersion(); |
|
|
|
ZLOGI(TAG, "4361Version:%x ic2160Version:%x", ic4361Version, ic2160Version); |
|
|
|
port_do_debug_light_state(); |
|
|
|
} |
|
|
|
return 0; |
|
|
|