mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-31 18:11:48 +02:00
Fixed move semantics of Pin usage.
This commit is contained in:
@@ -55,7 +55,7 @@ namespace Motors {
|
||||
MsgLevel::Info,
|
||||
"%s RC Servo Pin:%d Pulse Len(%.0f,%.0f) %s",
|
||||
reportAxisNameMsg(axis_index(), dual_axis_index()),
|
||||
_pwm_pin,
|
||||
_pwm_pin.name().c_str(),
|
||||
_pwm_pulse_min,
|
||||
_pwm_pulse_max,
|
||||
reportAxisLimitsMsg(axis_index()));
|
||||
|
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
// inline Pin(Pins::PinDetail* detail) : _detail(detail) {}
|
||||
inline Pin() : _detail(undefinedPin) {}
|
||||
|
||||
|
||||
inline void define(Pins::PinDetail* implementation) { _detail = implementation; }
|
||||
|
||||
static const bool On = true;
|
||||
@@ -74,10 +74,10 @@ public:
|
||||
static Pins::PinDetail* create(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& operator=(const Pin& o) = default;
|
||||
inline Pin& operator=(const Pin& o) = delete;
|
||||
inline Pin& operator=(Pin&& o) = default;
|
||||
|
||||
// Some convenience operators:
|
||||
|
@@ -99,7 +99,7 @@ namespace PinUsers {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
|
||||
// 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:
|
||||
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)
|
||||
inline uint32_t getFrequency() const { return _detail->getFrequency(); }
|
||||
|
@@ -46,8 +46,8 @@ namespace PinUsers {
|
||||
uart_mode_t uartMode_;
|
||||
|
||||
public:
|
||||
NativeUart(Pin tx, Pin rx, Pin rts, Pins::PinOptionsParser& options, Pins::PinOptionsParser& userOptions) :
|
||||
tx_(tx), rx_(rx), rts_(rts), uartPort_(UART_NUM_MAX) {
|
||||
NativeUart(Pin&& tx, Pin&& rx, Pin&& rts, Pins::PinOptionsParser& options, Pins::PinOptionsParser& userOptions) :
|
||||
tx_(std::move(tx)), rx_(std::move(rx)), rts_(std::move(rts)), uartPort_(UART_NUM_MAX) {
|
||||
// Validate if claiming the resources will err:
|
||||
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));
|
||||
@@ -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 userConfigParser(userConfig.begin(), userConfig.end());
|
||||
|
||||
// Decide on the RX pin what to do:
|
||||
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 {
|
||||
Assert(false, "Pin is not supported for UART.");
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ namespace PinUsers {
|
||||
|
||||
public:
|
||||
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
|
||||
// be easier in the application.
|
||||
|
@@ -29,8 +29,9 @@ namespace Spindles {
|
||||
public:
|
||||
PWM() = default;
|
||||
|
||||
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) {}
|
||||
// PWM(Pin&& output, Pin&& enable, Pin&& direction, uint32_t minRpm, uint32_t maxRpm) :
|
||||
// _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(PWM&&) = delete;
|
||||
|
@@ -20,12 +20,7 @@
|
||||
#include "Grbl.h"
|
||||
|
||||
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()) {
|
||||
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()) {
|
||||
return;
|
||||
}
|
||||
|
@@ -26,8 +26,7 @@ namespace UserOutput {
|
||||
|
||||
class DigitalOutput {
|
||||
public:
|
||||
DigitalOutput();
|
||||
DigitalOutput(uint8_t number, Pin pin);
|
||||
DigitalOutput(uint8_t number, Pin& pin);
|
||||
|
||||
bool set_level(bool isOn);
|
||||
|
||||
@@ -36,13 +35,12 @@ namespace UserOutput {
|
||||
void config_message();
|
||||
|
||||
uint8_t _number = UNDEFINED_OUTPUT;
|
||||
Pin _pin;
|
||||
Pin& _pin;
|
||||
};
|
||||
|
||||
class AnalogOutput {
|
||||
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);
|
||||
uint32_t denominator() { return 1UL << _resolution_bits; };
|
||||
|
||||
@@ -51,7 +49,7 @@ namespace UserOutput {
|
||||
void config_message();
|
||||
|
||||
uint8_t _number = UNDEFINED_OUTPUT;
|
||||
Pin _pin;
|
||||
Pin& _pin;
|
||||
uint8_t _pwm_channel = -1; // -1 means invalid or not setup
|
||||
float _pwm_frequency;
|
||||
uint8_t _resolution_bits;
|
||||
|
Reference in New Issue
Block a user