From ef7c77646160a170415ba3ba9125e64a42344181 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 4 Jul 2021 17:46:15 +0200 Subject: [PATCH] Update Motion for the new TMC2130/pins definitions --- src/modules/motion.cpp | 38 +------------------------- src/modules/motion.h | 33 ++++------------------ src/pins.h | 12 ++++++++ tests/unit/logic/stubs/stub_motion.cpp | 2 +- 4 files changed, 20 insertions(+), 65 deletions(-) diff --git a/src/modules/motion.cpp b/src/modules/motion.cpp index 22914f6..783f0d3 100644 --- a/src/modules/motion.cpp +++ b/src/modules/motion.cpp @@ -1,5 +1,4 @@ #include "motion.h" -#include "../hal/shr16.h" namespace modules { namespace motion { @@ -22,7 +21,7 @@ uint16_t Motion::CurrentPos(Axis axis) const { return 0; } void Motion::Home(Axis axis, bool direction) {} -void Motion::SetMode(MotorMode mode) {} +void Motion::SetMode(hal::tmc2130::MotorMode mode) {} void Motion::Step() {} @@ -32,40 +31,5 @@ void Motion::AbortPlannedMoves() {} void ISR() {} -//@@TODO check the directions -void StepDirPins::SetIdlerDirUp() { - hal::shr16::shr16.SetTMCDir(Axis::Idler, true); -} - -void StepDirPins::SetIdlerDirDown() { - hal::shr16::shr16.SetTMCDir(Axis::Idler, false); -} - -void StepDirPins::SetSelectorDirLeft() { - hal::shr16::shr16.SetTMCDir(Axis::Selector, true); -} -void StepDirPins::SetSelectorDirRight() { - hal::shr16::shr16.SetTMCDir(Axis::Selector, false); -} - -void StepDirPins::SetPulleyDirPull() { - hal::shr16::shr16.SetTMCDir(Axis::Pulley, true); -} -void StepDirPins::SetPulleyDirPush() { - hal::shr16::shr16.SetTMCDir(Axis::Pulley, false); -} - -void StepDirPins::StepIdler(uint8_t on) { - // PORTD |= idler_step_pin; -} - -void StepDirPins::StepSelector(uint8_t on) { - // PORTD |= selector_step_pin; -} - -void StepDirPins::StepPulley(uint8_t on) { - // PORTB |= pulley_step_pin; -} - } // namespace motion } // namespace modules diff --git a/src/modules/motion.h b/src/modules/motion.h index 17eefdd..6e82696 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -1,5 +1,10 @@ #pragma once #include +#include "../config/config.h" +#include "../hal/tmc2130.h" +#include "../pins.h" + +namespace modules { /// @@TODO /// Logic of motor handling @@ -20,8 +25,6 @@ /// rotate(speed) /// rotate(speed, angle/steps) /// home? - -namespace modules { namespace motion { enum Axis { @@ -30,35 +33,11 @@ enum Axis { Idler, }; -enum MotorMode { - Stealth, - Normal -}; - enum IdlerMode { Engage, Disengage }; -/// As step and dir pins are randomly scattered on the board for each of the axes/motors -/// it is convenient to make a common interface for them -class StepDirPins { -public: - static void SetIdlerDirUp(); - static void SetIdlerDirDown(); - - static void SetSelectorDirLeft(); - static void SetSelectorDirRight(); - - static void SetPulleyDirPull(); - static void SetPulleyDirPush(); - - static void StepIdler(uint8_t on); - static void StepSelector(uint8_t on); - static void StepPulley(uint8_t on); -}; - -/// @@TODO this is subject of discussion and change in the future class Motion { public: inline constexpr Motion() = default; @@ -96,7 +75,7 @@ public: /// Set mode of TMC/motors operation /// Common for all axes/motors - void SetMode(MotorMode mode); + void SetMode(hal::tmc2130::MotorMode mode); /// State machine doing all the planning and stepping preparation based on received commands void Step(); diff --git a/src/pins.h b/src/pins.h index 5476621..9d8ff75 100644 --- a/src/pins.h +++ b/src/pins.h @@ -13,3 +13,15 @@ static constexpr hal::gpio::GPIO_pin SHR16_CLOCK = { GPIOC, 7 }; ///SHCP static constexpr hal::gpio::GPIO_pin USART_RX = { GPIOD, 2 }; static constexpr hal::gpio::GPIO_pin USART_TX = { GPIOD, 3 }; + +static constexpr hal::gpio::GPIO_pin IDLER_CS_PIN = { GPIOB, 0 }; // TODO +static constexpr hal::gpio::GPIO_pin IDLER_SG_PIN = { GPIOB, 0 }; // TODO +static constexpr hal::gpio::GPIO_pin IDLER_STEP_PIN = { GPIOB, 0 }; // TODO + +static constexpr hal::gpio::GPIO_pin PULLEY_CS_PIN = { GPIOB, 0 }; // TODO +static constexpr hal::gpio::GPIO_pin PULLEY_SG_PIN = { GPIOB, 0 }; // TODO +static constexpr hal::gpio::GPIO_pin PULLEY_STEP_PIN = { GPIOB, 0 }; // TODO + +static constexpr hal::gpio::GPIO_pin SELECTOR_CS_PIN = { GPIOB, 0 }; // TODO +static constexpr hal::gpio::GPIO_pin SELECTOR_SG_PIN = { GPIOB, 0 }; // TODO +static constexpr hal::gpio::GPIO_pin SELECTOR_STEP_PIN = { GPIOB, 0 }; // TODO diff --git a/tests/unit/logic/stubs/stub_motion.cpp b/tests/unit/logic/stubs/stub_motion.cpp index 07e5d50..c053c2b 100644 --- a/tests/unit/logic/stubs/stub_motion.cpp +++ b/tests/unit/logic/stubs/stub_motion.cpp @@ -49,7 +49,7 @@ void Motion::Home(Axis axis, bool direction) { axes[Pulley].homed = true; } -void Motion::SetMode(MotorMode mode) { +void Motion::SetMode(hal::tmc2130::MotorMode mode) { } void Motion::Step() {