Skip to content

Commit

Permalink
Merge pull request #599 from Paciente8159/move-tmc-to-modules
Browse files Browse the repository at this point in the history
Move TMC driver to modules
  • Loading branch information
Paciente8159 authored Feb 3, 2024
2 parents 04ba6aa + 4b8a93c commit 7d5e3e6
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 2,579 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ List of Supported G-Codes since µCNC 1.3.0:
- Outside the RS274NGC scope
- Bilinear surface mapping: G39,G39.1,G39.2*
- Servo Control: M10*
- Trinamic settings: M350* (set/get microsteps), M906* (set/get current), 913* (stealthchop threshold), 914* (stall sensitivity-stallGuard capable chips only), 920* (set/get register)
- Digital pins/trimpot settings: M351* (set/get microsteps), M907* (set/get current via digipot)
- Laser PPI M126*(mode) M127*(PPI) and M128*(Pulse width)
- Valid Non-Command Words: E (used by 3D printing firmware like [Marlin](https://github.com/MarlinFirmware/Marlin)) (currently not used)
Expand Down Expand Up @@ -182,6 +181,7 @@ Other G/M codes available via [external modules](https://github.com/Paciente8159
- Wait for digital/analog input: M66
- Set home position from current position: G28.1/G30.1
- Play tone via PWM pin: M300
- Trinamic driver support and config commands: M350* (set/get microsteps), M906* (set/get current), 913* (stealthchop threshold), 914* (stall sensitivity-stallGuard capable chips only), 920* (set/get register)

**ALL custom G/M codes require at least ENABLE_PARSER_MODULES option enabled**

Expand Down
Binary file modified docs/mcumap_gen.xlsx
Binary file not shown.
457 changes: 111 additions & 346 deletions uCNC/cnc_hal_config.h

Large diffs are not rendered by default.

120 changes: 0 additions & 120 deletions uCNC/src/cnc_hal_config_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,126 +340,6 @@ extern "C"
#define STEPPERS_ENCODERS_MASK 0
#endif

#ifdef STEPPER0_HAS_TMC
#if (STEPPER0_TMC_INTERFACE == TMC_UART)
// if driver uses uart set pins
#if (!ASSERT_PIN(STEPPER0_UART_TX) || !ASSERT_PIN(STEPPER0_UART_RX))
#undef STEPPER0_HAS_TMC
#error "Stepper 0 undefined UART pins"
#endif
#elif (STEPPER0_TMC_INTERFACE == TMC_SPI)
#if (!ASSERT_PIN(STEPPER0_UART_DO) || !ASSERT_PIN(STEPPER0_UART_DI) || !ASSERT_PIN(STEPPER0_UART_CLK) || !ASSERT_PIN(STEPPER0_UART_CS))
#undef STEPPER0_HAS_TMC
#error "Stepper 0 undefined SPI pins"
#endif
#endif
#endif
#ifdef STEPPER1_HAS_TMC
#if (STEPPER1_TMC_INTERFACE == TMC_UART)
// if driver uses uart set pins
#if (!ASSERT_PIN(STEPPER1_UART_TX) || !ASSERT_PIN(STEPPER1_UART_RX))
#undef STEPPER1_HAS_TMC
#error "Stepper 1 undefined UART pins"
#endif
#elif (STEPPER1_TMC_INTERFACE == TMC_SPI)
#if (!ASSERT_PIN(STEPPER1_UART_DO) || !ASSERT_PIN(STEPPER1_UART_DI) || !ASSERT_PIN(STEPPER1_UART_CLK) || !ASSERT_PIN(STEPPER1_UART_CS))
#undef STEPPER1_HAS_TMC
#error "Stepper 1 undefined SPI pins"
#endif
#endif
#endif
#ifdef STEPPER2_HAS_TMC
#if (STEPPER2_TMC_INTERFACE == TMC_UART)
// if driver uses uart set pins
#if (!ASSERT_PIN(STEPPER2_UART_TX) || !ASSERT_PIN(STEPPER2_UART_RX))
#undef STEPPER2_HAS_TMC
#error "Stepper 2 undefined UART pins"
#endif
#elif (STEPPER2_TMC_INTERFACE == TMC_SPI)
#if (!ASSERT_PIN(STEPPER2_UART_DO) || !ASSERT_PIN(STEPPER2_UART_DI) || !ASSERT_PIN(STEPPER2_UART_CLK) || !ASSERT_PIN(STEPPER2_UART_CS))
#undef STEPPER2_HAS_TMC
#error "Stepper 2 undefined SPI pins"
#endif
#endif
#endif
#ifdef STEPPER3_HAS_TMC
#if (STEPPER3_TMC_INTERFACE == TMC_UART)
// if driver uses uart set pins
#if (!ASSERT_PIN(STEPPER3_UART_TX) || !ASSERT_PIN(STEPPER3_UART_RX))
#undef STEPPER3_HAS_TMC
#error "Stepper 3 undefined UART pins"
#endif
#elif (STEPPER3_TMC_INTERFACE == TMC_SPI)
#if (!ASSERT_PIN(STEPPER3_UART_DO) || !ASSERT_PIN(STEPPER3_UART_DI) || !ASSERT_PIN(STEPPER3_UART_CLK) || !ASSERT_PIN(STEPPER3_UART_CS))
#undef STEPPER3_HAS_TMC
#error "Stepper 3 undefined SPI pins"
#endif
#endif
#endif
#ifdef STEPPER4_HAS_TMC
#if (STEPPER4_TMC_INTERFACE == TMC_UART)
// if driver uses uart set pins
#if (!ASSERT_PIN(STEPPER4_UART_TX) || !ASSERT_PIN(STEPPER4_UART_RX))
#undef STEPPER4_HAS_TMC
#error "Stepper 4 undefined UART pins"
#endif
#elif (STEPPER4_TMC_INTERFACE == TMC_SPI)
#if (!ASSERT_PIN(STEPPER4_UART_DO) || !ASSERT_PIN(STEPPER4_UART_DI) || !ASSERT_PIN(STEPPER4_UART_CLK) || !ASSERT_PIN(STEPPER4_UART_CS))
#undef STEPPER4_HAS_TMC
#error "Stepper 4 undefined SPI pins"
#endif
#endif
#endif
#ifdef STEPPER5_HAS_TMC
#if (STEPPER5_TMC_INTERFACE == TMC_UART)
// if driver uses uart set pins
#if (!ASSERT_PIN(STEPPER5_UART_TX) || !ASSERT_PIN(STEPPER5_UART_RX))
#undef STEPPER5_HAS_TMC
#error "Stepper 5 undefined UART pins"
#endif
#elif (STEPPER5_TMC_INTERFACE == TMC_SPI)
#if (!ASSERT_PIN(STEPPER5_UART_DO) || !ASSERT_PIN(STEPPER5_UART_DI) || !ASSERT_PIN(STEPPER5_UART_CLK) || !ASSERT_PIN(STEPPER5_UART_CS))
#undef STEPPER5_HAS_TMC
#error "Stepper 5 undefined SPI pins"
#endif
#endif
#endif
#ifdef STEPPER6_HAS_TMC
#if (STEPPER6_TMC_INTERFACE == TMC_UART)
// if driver uses uart set pins
#if (!ASSERT_PIN(STEPPER6_UART_TX) || !ASSERT_PIN(STEPPER6_UART_RX))
#undef STEPPER6_HAS_TMC
#error "Stepper 6 undefined UART pins"
#endif
#elif (STEPPER6_TMC_INTERFACE == TMC_SPI)
#if (!ASSERT_PIN(STEPPER6_UART_DO) || !ASSERT_PIN(STEPPER6_UART_DI) || !ASSERT_PIN(STEPPER6_UART_CLK) || !ASSERT_PIN(STEPPER6_UART_CS))
#undef STEPPER6_HAS_TMC
#error "Stepper 6 undefined SPI pins"
#endif
#endif
#endif
#ifdef STEPPER7_HAS_TMC
#if (STEPPER7_TMC_INTERFACE == TMC_UART)
// if driver uses uart set pins
#if (!ASSERT_PIN(STEPPER7_UART_TX) || !ASSERT_PIN(STEPPER7_UART_RX))
#undef STEPPER7_HAS_TMC
#error "Stepper 7 undefined UART pins"
#endif
#elif (STEPPER7_TMC_INTERFACE == TMC_SPI)
#if (!ASSERT_PIN(STEPPER7_UART_DO) || !ASSERT_PIN(STEPPER7_UART_DI) || !ASSERT_PIN(STEPPER7_UART_CLK) || !ASSERT_PIN(STEPPER7_UART_CS))
#undef STEPPER7_HAS_TMC
#error "Stepper 7 undefined SPI pins"
#endif
#endif
#endif

#if defined(STEPPER0_HAS_TMC) || defined(STEPPER1_HAS_TMC) || defined(STEPPER2_HAS_TMC) || defined(STEPPER3_HAS_TMC) || defined(STEPPER4_HAS_TMC) || defined(STEPPER5_HAS_TMC) || defined(STEPPER6_HAS_TMC) || defined(STEPPER7_HAS_TMC)
#define ENABLE_TMC_DRIVERS
#ifndef ENABLE_MAIN_LOOP_MODULES
#define ENABLE_MAIN_LOOP_MODULES
#endif
#endif

#if defined(STEPPER0_HAS_MSTEP) || defined(STEPPER1_HAS_MSTEP) || defined(STEPPER2_HAS_MSTEP) || defined(STEPPER3_HAS_MSTEP) || defined(STEPPER4_HAS_MSTEP) || defined(STEPPER5_HAS_MSTEP) || defined(STEPPER6_HAS_MSTEP) || defined(STEPPER7_HAS_MSTEP)
#define ENABLE_DIGITAL_MSTEP
#endif
Expand Down
5 changes: 0 additions & 5 deletions uCNC/src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

#include "cnc.h"
#include "modules/tmcdriver.h"
#include "modules/digimstep.h"
#include "modules/digipot.h"
#include "modules/encoder.h"
Expand Down Expand Up @@ -60,10 +59,6 @@ void mod_init(void)
LOAD_MODULE(encoder);
#endif

#ifdef ENABLE_TMC_DRIVERS
LOAD_MODULE(tmcdriver);
#endif

#ifdef ENABLE_LASER_PPI
LOAD_MODULE(laser_ppi);
#endif
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C"
#include <stdint.h>
#include <stdbool.h>

#define UCNC_MODULE_VERSION 10801
#define UCNC_MODULE_VERSION 10807

#define EVENT_CONTINUE false
#define EVENT_HANDLED true
Expand Down
8 changes: 5 additions & 3 deletions uCNC/src/modules/softuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void softuart_putc(softuart_port_t *port, char c)
if (!port)
{
#if (defined(MCU_HAS_UART2) && defined(DETACH_UART2_FROM_MAIN_PROTOCOL))
mcu_uart_putc(c);
mcu_uart2_putc(c);
#endif
}
else
Expand Down Expand Up @@ -58,18 +58,20 @@ int16_t softuart_getc(softuart_port_t *port, uint32_t ms_timeout)
}
else
{
ms_timeout += mcu_millis();
ms_timeout *= 1000;
while (port->rx())
{
if (ms_timeout < mcu_millis())
if (!ms_timeout--)
{
return -1;
}
mcu_delay_us(1);
}
port->waithalf();

uint8_t bits = 8;
uint8_t mask = 0x01;

do
{
port->wait();
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/modules/softuart.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern "C"
} \
bool NAME##_rx(void) \
{ \
return io_get_input(RXPIN); \
return io_get_input(TRXPIN); \
} \
void NAME##_wait(void) { mcu_delay_cycles(F_CPU / BAUD); } \
void NAME##_waithalf(void) { mcu_delay_cycles(F_CPU / 2 / BAUD); } \
Expand Down
Loading

0 comments on commit 7d5e3e6

Please sign in to comment.