mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-01 10:23:19 +02:00
Fixed move semantics of Pin usage.
This commit is contained in:
@@ -55,7 +55,7 @@ namespace Motors {
|
|||||||
MsgLevel::Info,
|
MsgLevel::Info,
|
||||||
"%s RC Servo Pin:%d Pulse Len(%.0f,%.0f) %s",
|
"%s RC Servo Pin:%d Pulse Len(%.0f,%.0f) %s",
|
||||||
reportAxisNameMsg(axis_index(), dual_axis_index()),
|
reportAxisNameMsg(axis_index(), dual_axis_index()),
|
||||||
_pwm_pin,
|
_pwm_pin.name().c_str(),
|
||||||
_pwm_pulse_min,
|
_pwm_pulse_min,
|
||||||
_pwm_pulse_max,
|
_pwm_pulse_max,
|
||||||
reportAxisLimitsMsg(axis_index()));
|
reportAxisLimitsMsg(axis_index()));
|
||||||
|
@@ -62,7 +62,7 @@ public:
|
|||||||
|
|
||||||
// inline Pin(Pins::PinDetail* detail) : _detail(detail) {}
|
// inline Pin(Pins::PinDetail* detail) : _detail(detail) {}
|
||||||
inline Pin() : _detail(undefinedPin) {}
|
inline Pin() : _detail(undefinedPin) {}
|
||||||
|
|
||||||
inline void define(Pins::PinDetail* implementation) { _detail = implementation; }
|
inline void define(Pins::PinDetail* implementation) { _detail = implementation; }
|
||||||
|
|
||||||
static const bool On = true;
|
static const bool On = true;
|
||||||
@@ -74,10 +74,10 @@ public:
|
|||||||
static Pins::PinDetail* create(const String& str);
|
static Pins::PinDetail* create(const String& str);
|
||||||
static bool validate(const String& str);
|
static bool validate(const String& str);
|
||||||
|
|
||||||
inline Pin(const Pin& o) = default;
|
inline Pin(const Pin& o) = delete;
|
||||||
inline Pin(Pin&& o) = default;
|
inline Pin(Pin&& o) = default;
|
||||||
|
|
||||||
inline Pin& operator=(const Pin& o) = default;
|
inline Pin& operator=(const Pin& o) = delete;
|
||||||
inline Pin& operator=(Pin&& o) = default;
|
inline Pin& operator=(Pin&& o) = default;
|
||||||
|
|
||||||
// Some convenience operators:
|
// Some convenience operators:
|
||||||
|
@@ -99,7 +99,7 @@ namespace PinUsers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NativePwm(Pin pin, uint32_t frequency, uint32_t maxDuty) : pin_(pin), frequency_(frequency), maxDuty_(maxDuty) {
|
NativePwm(Pin&& pin, uint32_t frequency, uint32_t maxDuty) : pin_(std::move(pin)), frequency_(frequency), maxDuty_(maxDuty) {
|
||||||
auto native = pin.getNative(Pin::Capabilities::PWM | Pin::Capabilities::Native);
|
auto native = pin.getNative(Pin::Capabilities::PWM | Pin::Capabilities::Native);
|
||||||
|
|
||||||
pwmChannel_ = TryGrabChannel(frequency);
|
pwmChannel_ = TryGrabChannel(frequency);
|
||||||
@@ -148,10 +148,10 @@ namespace PinUsers {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PwmPin::PwmPin(Pin pin, uint32_t frequency, uint32_t maxDuty) {
|
PwmPin::PwmPin(Pin&& pin, uint32_t frequency, uint32_t maxDuty) {
|
||||||
Assert(pin.capabilities().has(Pin::Capabilities::PWM | Pin::Capabilities::Native), "Pin does not support PWM");
|
Assert(pin.capabilities().has(Pin::Capabilities::PWM | Pin::Capabilities::Native), "Pin does not support PWM");
|
||||||
|
|
||||||
// For now, we only support Native pins. In the future, we might support other pins.
|
// For now, we only support Native pins. In the future, we might support other pins.
|
||||||
_detail = new NativePwm(pin, frequency, maxDuty);
|
_detail = new NativePwm(std::move(pin), frequency, maxDuty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,7 @@ namespace PinUsers {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
PwmPin() : _detail(nullptr) {}
|
PwmPin() : _detail(nullptr) {}
|
||||||
PwmPin(Pin pin, uint32_t frequency, uint32_t maxDuty);
|
PwmPin(Pin&& pin, uint32_t frequency, uint32_t maxDuty);
|
||||||
|
|
||||||
// Returns actual frequency which might not be exactly the same as requested(nearest supported value)
|
// Returns actual frequency which might not be exactly the same as requested(nearest supported value)
|
||||||
inline uint32_t getFrequency() const { return _detail->getFrequency(); }
|
inline uint32_t getFrequency() const { return _detail->getFrequency(); }
|
||||||
|
@@ -46,8 +46,8 @@ namespace PinUsers {
|
|||||||
uart_mode_t uartMode_;
|
uart_mode_t uartMode_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NativeUart(Pin tx, Pin rx, Pin rts, Pins::PinOptionsParser& options, Pins::PinOptionsParser& userOptions) :
|
NativeUart(Pin&& tx, Pin&& rx, Pin&& rts, Pins::PinOptionsParser& options, Pins::PinOptionsParser& userOptions) :
|
||||||
tx_(tx), rx_(rx), rts_(rts), uartPort_(UART_NUM_MAX) {
|
tx_(std::move(tx)), rx_(std::move(rx)), rts_(std::move(rts)), uartPort_(UART_NUM_MAX) {
|
||||||
// Validate if claiming the resources will err:
|
// Validate if claiming the resources will err:
|
||||||
Assert(tx.capabilities().has(Pin::Capabilities::Native | Pin::Capabilities::UART | Pin::Capabilities::Output));
|
Assert(tx.capabilities().has(Pin::Capabilities::Native | Pin::Capabilities::UART | Pin::Capabilities::Output));
|
||||||
Assert(rx.capabilities().has(Pin::Capabilities::Native | Pin::Capabilities::UART | Pin::Capabilities::Input));
|
Assert(rx.capabilities().has(Pin::Capabilities::Native | Pin::Capabilities::UART | Pin::Capabilities::Input));
|
||||||
@@ -179,13 +179,13 @@ namespace PinUsers {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Uart::Uart(Pin tx, Pin rx, Pin rts, String config, String userConfig) {
|
Uart::Uart(Pin&& tx, Pin&& rx, Pin&& rts, String config, String userConfig) {
|
||||||
Pins::PinOptionsParser configParser(config.begin(), config.end());
|
Pins::PinOptionsParser configParser(config.begin(), config.end());
|
||||||
Pins::PinOptionsParser userConfigParser(userConfig.begin(), userConfig.end());
|
Pins::PinOptionsParser userConfigParser(userConfig.begin(), userConfig.end());
|
||||||
|
|
||||||
// Decide on the RX pin what to do:
|
// Decide on the RX pin what to do:
|
||||||
if (rx.capabilities().has(Pin::Capabilities::Native)) {
|
if (rx.capabilities().has(Pin::Capabilities::Native)) {
|
||||||
this->_detail = new NativeUart(tx, rx, rts, configParser, userConfigParser);
|
this->_detail = new NativeUart(std::move(tx), std::move(rx), std::move(rts), configParser, userConfigParser);
|
||||||
} else {
|
} else {
|
||||||
Assert(false, "Pin is not supported for UART.");
|
Assert(false, "Pin is not supported for UART.");
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ namespace PinUsers {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Uart() : _detail(nullptr) {}
|
Uart() : _detail(nullptr) {}
|
||||||
Uart(Pin tx, Pin rx, Pin rts, String config, String userConfig);
|
Uart(Pin&& tx, Pin&& rx, Pin&& rts, String config, String userConfig);
|
||||||
|
|
||||||
// TODO FIXME: If _detail is null is currently asserted. We can also just 'do nothing', which might
|
// TODO FIXME: If _detail is null is currently asserted. We can also just 'do nothing', which might
|
||||||
// be easier in the application.
|
// be easier in the application.
|
||||||
|
@@ -29,8 +29,9 @@ namespace Spindles {
|
|||||||
public:
|
public:
|
||||||
PWM() = default;
|
PWM() = default;
|
||||||
|
|
||||||
PWM(Pin output, Pin enable, Pin direction, uint32_t minRpm, uint32_t maxRpm) :
|
// PWM(Pin&& output, Pin&& enable, Pin&& direction, uint32_t minRpm, uint32_t maxRpm) :
|
||||||
_min_rpm(minRpm), _max_rpm(maxRpm), _output_pin(output), _enable_pin(enable), _direction_pin(direction) {}
|
// _min_rpm(minRpm), _max_rpm(maxRpm), _output_pin(std::move(output)), _enable_pin(std::move(enable)),
|
||||||
|
// _direction_pin(std::move(direction)) {}
|
||||||
|
|
||||||
PWM(const PWM&) = delete;
|
PWM(const PWM&) = delete;
|
||||||
PWM(PWM&&) = delete;
|
PWM(PWM&&) = delete;
|
||||||
|
@@ -20,12 +20,7 @@
|
|||||||
#include "Grbl.h"
|
#include "Grbl.h"
|
||||||
|
|
||||||
namespace UserOutput {
|
namespace UserOutput {
|
||||||
DigitalOutput::DigitalOutput() {}
|
DigitalOutput::DigitalOutput(uint8_t number, Pin& pin) : _number(number), _pin(pin) {
|
||||||
|
|
||||||
DigitalOutput::DigitalOutput(uint8_t number, Pin pin) {
|
|
||||||
_number = number;
|
|
||||||
_pin = pin;
|
|
||||||
|
|
||||||
if (_pin.undefined()) {
|
if (_pin.undefined()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -55,13 +50,7 @@ namespace UserOutput {
|
|||||||
|
|
||||||
// ==================================================================
|
// ==================================================================
|
||||||
|
|
||||||
AnalogOutput::AnalogOutput() {}
|
AnalogOutput::AnalogOutput(uint8_t number, Pin& pin, float pwm_frequency) : _number(number), _pin(pin), _pwm_frequency(pwm_frequency) {
|
||||||
|
|
||||||
AnalogOutput::AnalogOutput(uint8_t number, Pin pin, float pwm_frequency) {
|
|
||||||
_number = number;
|
|
||||||
_pin = pin;
|
|
||||||
_pwm_frequency = pwm_frequency;
|
|
||||||
|
|
||||||
if (pin.undefined()) {
|
if (pin.undefined()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -26,8 +26,7 @@ namespace UserOutput {
|
|||||||
|
|
||||||
class DigitalOutput {
|
class DigitalOutput {
|
||||||
public:
|
public:
|
||||||
DigitalOutput();
|
DigitalOutput(uint8_t number, Pin& pin);
|
||||||
DigitalOutput(uint8_t number, Pin pin);
|
|
||||||
|
|
||||||
bool set_level(bool isOn);
|
bool set_level(bool isOn);
|
||||||
|
|
||||||
@@ -36,13 +35,12 @@ namespace UserOutput {
|
|||||||
void config_message();
|
void config_message();
|
||||||
|
|
||||||
uint8_t _number = UNDEFINED_OUTPUT;
|
uint8_t _number = UNDEFINED_OUTPUT;
|
||||||
Pin _pin;
|
Pin& _pin;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AnalogOutput {
|
class AnalogOutput {
|
||||||
public:
|
public:
|
||||||
AnalogOutput();
|
AnalogOutput(uint8_t number, Pin& pin, float pwm_frequency);
|
||||||
AnalogOutput(uint8_t number, Pin pin, float pwm_frequency);
|
|
||||||
bool set_level(uint32_t numerator);
|
bool set_level(uint32_t numerator);
|
||||||
uint32_t denominator() { return 1UL << _resolution_bits; };
|
uint32_t denominator() { return 1UL << _resolution_bits; };
|
||||||
|
|
||||||
@@ -51,7 +49,7 @@ namespace UserOutput {
|
|||||||
void config_message();
|
void config_message();
|
||||||
|
|
||||||
uint8_t _number = UNDEFINED_OUTPUT;
|
uint8_t _number = UNDEFINED_OUTPUT;
|
||||||
Pin _pin;
|
Pin& _pin;
|
||||||
uint8_t _pwm_channel = -1; // -1 means invalid or not setup
|
uint8_t _pwm_channel = -1; // -1 means invalid or not setup
|
||||||
float _pwm_frequency;
|
float _pwm_frequency;
|
||||||
uint8_t _resolution_bits;
|
uint8_t _resolution_bits;
|
||||||
|
Reference in New Issue
Block a user