diff --git a/tmcdriver/tmc51x0/tmc51x0.cpp b/tmcdriver/tmc51x0/tmc51x0.cpp index 126006a..1e81a9d 100644 --- a/tmcdriver/tmc51x0/tmc51x0.cpp +++ b/tmcdriver/tmc51x0/tmc51x0.cpp @@ -42,7 +42,8 @@ static const uint8_t tmc5130_defaultRegisterAccess[TMC5130_REGISTER_COUNT] = { #define TMC51x0_ADDRESS(x) ((x) & (TMC5130_ADDRESS_MASK)) #define TAG "TMC51X0" -void TMC51X0::initialize(TMC51X0Cfg cfg) { +void TMC51X0::initialize(int mid, TMC51X0Cfg cfg) { + m_mid = mid; m_cfg = cfg; m_hspi = cfg.hspi; @@ -211,6 +212,10 @@ void TMC51X0::moveToEnd(int32_t direction, uint32_t velocityMax) { void TMC51X0::moveBy(int32_t relativePosition, uint32_t velocityMax) { // determine actual position and add numbers of ticks to move zlock_guard lkg(m_mutex); + // m_mid + + // ZLOGI(TAG, "m[%d] moveBy %d,%d", m_mid, relativePosition, velocityMax); + int32_t pos = getXACTUAL(); int32_t target = pos + relativePosition; moveTo(target, velocityMax); @@ -264,7 +269,7 @@ bool TMC51X0::isTMC5130() { return chipId == kTMC5130; } -TMC5130DevStatusReg_t TMC51X0::getDevStatus() { // R +TMC5130DevStatusReg_t TMC51X0::getDevStatus() { // R zlock_guard lkg(m_mutex); static_assert(sizeof(TMC5130DevStatusReg_t) == 4); uint32_t value = readInt(TMC5130_DRVSTATUS); @@ -272,7 +277,7 @@ TMC5130DevStatusReg_t TMC51X0::getDevStatus() { // R memcpy(&val, &value, sizeof(TMC5130DevStatusReg_t)); return val; } -TMC5130GState_t TMC51X0::getGState() { // R+C +TMC5130GState_t TMC51X0::getGState() { // R+C zlock_guard lkg(m_mutex); static_assert(sizeof(TMC5130GState_t) == 4); uint32_t value = readInt(TMC5130_GSTAT); @@ -370,9 +375,6 @@ bool TMC51X0::setEncResolution(int32_t enc_resolution) { /** * @brief * - * 1.假?电机是256细分 - * 2.假?TMC5130_ENC_CONST?十进制模? - * 3.??持指定分辨率的编码器 */ int32_t enc_resolution_tmp = enc_resolution * 4; diff --git a/tmcdriver/tmc51x0/tmc51x0.hpp b/tmcdriver/tmc51x0/tmc51x0.hpp index d9b97ac..34dab70 100644 --- a/tmcdriver/tmc51x0/tmc51x0.hpp +++ b/tmcdriver/tmc51x0/tmc51x0.hpp @@ -31,21 +31,21 @@ class TMC51X0 { SPI_HandleTypeDef *m_hspi = NULL; ZGPIO m_csnpin; ZGPIO m_ennpin; + int m_mid = 0; int32_t m_scale = 10000; int32_t m_scale_deceleration = 1; mres_type_t m_MRES = kmres_256; double m_onecirclepulse = 51200; - int32_t m_enc_resolution = 0; // + int32_t m_enc_resolution = 0; // zmutex m_mutex = {"TMC51X0"}; bool m_driErr = false; public: - void initialize(TMC51X0Cfg cfg); + void initialize(int mid, TMC51X0Cfg cfg); private: - void readWriteArray(uint8_t *data, size_t length); void writeDatagram(uint8_t address, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4); void writeInt(uint8_t address, int32_t value); @@ -78,7 +78,7 @@ class TMC51X0 { TMC5130GState_t getGState(); // R+C read and clear int32_t readICVersion(); - int32_t getXactualRAW();// now pos 51200 + int32_t getXactualRAW(); // now pos 51200 bool isReachTarget(TMC5130RampStat *state); // is reach target bool isTMC5130();