diff --git a/Grbl_Esp32/src/Motors/Dynamixel2.cpp b/Grbl_Esp32/src/Motors/Dynamixel2.cpp index b42a47cd..eaa603cb 100644 --- a/Grbl_Esp32/src/Motors/Dynamixel2.cpp +++ b/Grbl_Esp32/src/Motors/Dynamixel2.cpp @@ -31,7 +31,7 @@ #include "../Limits.h" // limitsMinPosition namespace Motors { - bool Motors::Dynamixel2::uart_ready = false; + bool Motors::Dynamixel2::_uart_started = false; uint8_t Motors::Dynamixel2::ids[MAX_N_AXIS][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; void Dynamixel2::init() { @@ -40,7 +40,7 @@ namespace Motors { ids[_axis_index][dual_axis_index()] = _id; // learn all the ids - if (!uart_ready) { + if (!_uart_started) { if (_uart->baud != 1000000) { info_serial("Warning: The baud rate is %d. Dynamixels typically use 1000000 baud."); } @@ -54,7 +54,7 @@ namespace Motors { info_serial("Dynamixel:"); _uart->config_message(); - uart_ready = true; + _uart_started = true; } read_settings(); diff --git a/Grbl_Esp32/src/Motors/Dynamixel2.h b/Grbl_Esp32/src/Motors/Dynamixel2.h index f693345f..8627ac2b 100644 --- a/Grbl_Esp32/src/Motors/Dynamixel2.h +++ b/Grbl_Esp32/src/Motors/Dynamixel2.h @@ -62,7 +62,7 @@ namespace Motors { Uart* _uart = nullptr; - static const int DYNAMIXEL_BAUD_RATE = 1000000; + static bool _uart_started; static const int DXL_RESPONSE_WAIT_TICKS = 20; // how long to wait for a response @@ -114,7 +114,6 @@ namespace Motors { void set_disable(bool disable) override; void update() override; - static bool uart_ready; static uint8_t ids[MAX_N_AXIS][2]; // Configuration handlers: diff --git a/Grbl_Esp32/src/Motors/TrinamicUartDriver.cpp b/Grbl_Esp32/src/Motors/TrinamicUartDriver.cpp index dfde530a..12afa459 100644 --- a/Grbl_Esp32/src/Motors/TrinamicUartDriver.cpp +++ b/Grbl_Esp32/src/Motors/TrinamicUartDriver.cpp @@ -32,8 +32,6 @@ #include // https://github.com/teemuatlut/TMCStepper #include -Uart tmc_serial(TMC_UART); - namespace Motors { bool TrinamicUartDriver::_uart_started = false; @@ -43,10 +41,9 @@ namespace Motors { void TrinamicUartDriver::init() { if (!_uart_started) { -#ifdef LATER - tmc_serial.setPins(TMC_UART_TX, TMC_UART_RX); -#endif - tmc_serial.begin(115200, UartData::Bits8, UartStop::Bits1, UartParity::None); + _uart->begin(); + info_serial("Trinamic:"); + _uart->config_message(); _uart_started = true; } _has_errors = hw_serial_init(); @@ -89,7 +86,7 @@ namespace Motors { bool TrinamicUartDriver::hw_serial_init() { if (_driver_part_number == 2209) { - tmcstepper = new TMC2209Stepper(&tmc_serial, _r_sense, _addr); + tmcstepper = new TMC2209Stepper(_uart, _r_sense, _addr); return false; } info_serial("Unsupported Trinamic motor p/n:%d", _driver_part_number); @@ -100,20 +97,12 @@ namespace Motors { This is the startup message showing the basic definition. */ void TrinamicUartDriver::config_message() { //TODO: The RX/TX pin could be added to the msg. - info_serial("%s motor Trinamic TMC%d Step:%s Dir:%s Disable:%s UART%d Rx:%s Tx:%s Addr:%d R:%0.3f %s", + info_serial("%s motor Trinamic TMC%d Step:%s Dir:%s Disable:%s Addr:%d R:%0.3f %s", reportAxisNameMsg(axis_index(), dual_axis_index()), _driver_part_number, _step_pin.name().c_str(), _dir_pin.name().c_str(), _disable_pin.name().c_str(), - TMC_UART, -#ifdef LATER - pinName(TMC_UART_RX), - pinName(TMC_UART_TX), -#else - 0, - 0, -#endif _addr, _r_sense, reportAxisLimitsMsg(axis_index())); diff --git a/Grbl_Esp32/src/Motors/TrinamicUartDriver.h b/Grbl_Esp32/src/Motors/TrinamicUartDriver.h index 4690b903..6407f351 100644 --- a/Grbl_Esp32/src/Motors/TrinamicUartDriver.h +++ b/Grbl_Esp32/src/Motors/TrinamicUartDriver.h @@ -25,31 +25,14 @@ #include -const float TMC2208_RSENSE_DEFAULT = 0.11f; -const float TMC2209_RSENSE_DEFAULT = 0.11f; - -#ifndef TMC_UART -# define TMC_UART UART_NUM_2 -#endif - -#ifdef LATER -# ifndef TMC_UART_RX -# define TMC_UART_RX UNDEFINED_PIN -# endif - -# ifndef TMC_UART_TX -# define TMC_UART_TX UNDEFINED_PIN -# endif -#endif - class TMC2209Stepper; // Forward declaration -extern Uart tmc_serial; - namespace Motors { class TrinamicUartDriver : public TrinamicBase { private: + Uart* _uart = nullptr; + static bool _uart_started; TMC2209Stepper* tmcstepper; // all other driver types are subclasses of this one