Skip to content

Commit

Permalink
Merge pull request #980 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored Jul 21, 2023
2 parents fdd10af + 10bd9a8 commit fec80d9
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 48 deletions.
14 changes: 6 additions & 8 deletions FluidNC/src/Configuration/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <vector>
#include <sstream>

#include "../Pin.h"
#include "../Report.h" // report_gcode_modes()
Expand Down Expand Up @@ -53,21 +54,18 @@ namespace Configuration {
void item(const char* name, float& value, float minValue, float maxValue) override { send_item(name, std::to_string(value)); }

void item(const char* name, std::vector<speedEntry>& value) {
std::string s;
if (value.size() == 0) {
s += "None";
send_item(name, "None");
} else {
std::ostringstream s;
s.precision(2);
const char* separator = "";
for (speedEntry n : value) {
s += separator;
s << separator << n.speed << "=" << std::fixed << n.percent << "%";
separator = " ";
s += std::to_string(n.speed);
s += '=';
s += std::to_string(n.percent);
s += '%';
}
send_item(name, s.str());
}
send_item(name, s);
}

void item(const char* name, UartData& wordLength, UartParity& parity, UartStop& stopBits) override {
Expand Down
2 changes: 2 additions & 0 deletions FluidNC/src/Configuration/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ namespace Configuration {
return {};
}
entry_str.remove_prefix(next_pct_delim + 1);

speed_entries.push_back(entry);
}

if (!speed_entries.size()) {
Expand Down
7 changes: 6 additions & 1 deletion FluidNC/src/Configuration/RuntimeSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,14 @@ namespace Configuration {
if (value.size() == 0) {
log_to(out_, "None");
} else {
LogStream msg(out_, "");
msg << setting_prefix();
const char* separator = "";
for (speedEntry n : value) {
log_to(out_, "", n.speed << "=" << n.percent << "%")
msg << separator << n.speed << "=" << setprecision(2) << n.percent << "%";
separator = " ";
}
// The destructor sends the line when msg goes out of scope
}
} else {
// It is distasteful to have this code that essentially duplicates
Expand Down
2 changes: 2 additions & 0 deletions FluidNC/src/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Control::Control() {
_pins.push_back(new ControlPin(&macro1Event, "macro1_pin", '1'));
_pins.push_back(new ControlPin(&macro2Event, "macro2_pin", '2'));
_pins.push_back(new ControlPin(&macro3Event, "macro3_pin", '3'));
_pins.push_back(new ControlPin(&faultPinEvent, "fault_pin", 'F'));
_pins.push_back(new ControlPin(&faultPinEvent, "estop_pin", 'E'));
}

void Control::init() {
Expand Down
6 changes: 3 additions & 3 deletions FluidNC/src/Machine/Axes.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ namespace Machine {
static MotorMask limitMask;
static MotorMask motorMask;

Pin _sharedStepperDisable;
Pin _sharedStepperReset;

inline char axisName(int index) { return index < MAX_N_AXIS ? _names[index] : '?'; } // returns axis letter

static inline size_t motor_bit(size_t axis, size_t motor) { return motor ? axis + 16 : axis; }
static inline AxisMask motors_to_axes(MotorMask motors) { return (motors & 0xffff) | (motors >> 16); }
static inline MotorMask axes_to_motors(AxisMask axes) { return axes | (axes << 16); }

Pin _sharedStepperDisable;
Pin _sharedStepperReset;

int _numberAxis = 0;
Axis* _axis[MAX_N_AXIS];

Expand Down
13 changes: 13 additions & 0 deletions FluidNC/src/Motors/TMC2208Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ namespace MotorDrivers {
}

void TMC2208Driver::config_motor() {
_cs_pin.synchronousWrite(true);
tmc2208->begin();
TrinamicBase::config_motor();
_cs_pin.synchronousWrite(false);
}

void TMC2208Driver::set_registers(bool isHoming) {
Expand All @@ -41,6 +43,9 @@ namespace MotorDrivers {
// but the TMCStepper library expresses run current as (uint16_t) mA
// and hold current as (float) fraction of run current.
uint16_t run_i = (uint16_t)(_run_current * 1000.0);

_cs_pin.synchronousWrite(true);

tmc2208->I_scale_analog(false); // do not scale via pot
tmc2208->rms_current(run_i, TrinamicBase::holdPercent());

Expand All @@ -51,20 +56,26 @@ namespace MotorDrivers {
// This driver does not support multiple modes
tmc2208->en_spreadCycle(false);
tmc2208->pwm_autoscale(true);

_cs_pin.synchronousWrite(false);
}

void TMC2208Driver::debug_message() {}

void TMC2208Driver::set_disable(bool disable) {
_cs_pin.synchronousWrite(true);
if (TrinamicUartDriver::startDisable(disable)) {
if (_use_enable) {
tmc2208->toff(TrinamicUartDriver::toffValue());
}
}
_cs_pin.synchronousWrite(false);
}

bool TMC2208Driver::test() {
_cs_pin.synchronousWrite(true);
if (!checkVersion(0x20, tmc2208->version())) {
_cs_pin.synchronousWrite(false);
return false;
}
uint8_t ifcnt_before = tmc2208->IFCNT();
Expand All @@ -73,8 +84,10 @@ namespace MotorDrivers {
bool okay = ((ifcnt_before + 1) & 0xff) == ifcnt_after;
if (!okay) {
TrinamicBase::reportCommsFailure();
_cs_pin.synchronousWrite(false);
return false;
}
_cs_pin.synchronousWrite(false);
return true;
}

Expand Down
19 changes: 19 additions & 0 deletions FluidNC/src/Motors/TMC2209Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ namespace MotorDrivers {
}

void TMC2209Driver::config_motor() {
_cs_pin.synchronousWrite(true);
tmc2209->begin();
TrinamicBase::config_motor();
_cs_pin.synchronousWrite(false);
}

void TMC2209Driver::set_registers(bool isHoming) {
Expand All @@ -42,6 +44,9 @@ namespace MotorDrivers {
// but the TMCStepper library expresses run current as (uint16_t) mA
// and hold current as (float) fraction of run current.
uint16_t run_i = (uint16_t)(_run_current * 1000.0);

_cs_pin.synchronousWrite(true);

tmc2209->I_scale_analog(false); // do not scale via pot
tmc2209->rms_current(run_i, TrinamicBase::holdPercent());

Expand Down Expand Up @@ -82,45 +87,59 @@ namespace MotorDrivers {
log_debug("GCONF: 0x" << to_hex(tmc2209->GCONF()));
log_debug("PWMCONF: 0x" << to_hex(tmc2209->PWMCONF()));
log_debug("IHOLD_IRUN: 0x" << to_hex(tmc2209->IHOLD_IRUN()));

_cs_pin.synchronousWrite(false);
}

void TMC2209Driver::debug_message() {
if (_has_errors) {
return;
}

_cs_pin.synchronousWrite(true);

uint32_t tstep = tmc2209->TSTEP();

if (tstep == 0xFFFFF || tstep < 1) { // if axis is not moving return
_cs_pin.synchronousWrite(false);
return;
}
float feedrate = Stepper::get_realtime_rate(); //* settings.microsteps[axis_index] / 60.0 ; // convert mm/min to Hz

if (tmc2209) {
log_info(axisName() << " SG_Val: " << tmc2209->SG_RESULT() << " Rate: " << feedrate << " mm/min SG_Setting:" << _stallguard);
}

_cs_pin.synchronousWrite(false);
}

void TMC2209Driver::set_disable(bool disable) {
_cs_pin.synchronousWrite(true);
if (TrinamicUartDriver::startDisable(disable)) {
if (_use_enable) {
tmc2209->toff(TrinamicUartDriver::toffValue());
}
}
_cs_pin.synchronousWrite(false);
}

bool TMC2209Driver::test() {
_cs_pin.synchronousWrite(true);
if (!checkVersion(0x21, tmc2209->version())) {
_cs_pin.synchronousWrite(false);
return false;
}

uint8_t ifcnt_before = tmc2209->IFCNT();
tmc2209->GSTAT(0); // clear GSTAT to increase ifcnt
uint8_t ifcnt_after = tmc2209->IFCNT();
bool okay = ((ifcnt_before + 1) & 0xff) == ifcnt_after;
if (!okay) {
TrinamicBase::reportCommsFailure();
_cs_pin.synchronousWrite(false);
return false;
}
_cs_pin.synchronousWrite(false);
return true;
}

Expand Down
10 changes: 7 additions & 3 deletions FluidNC/src/Motors/TrinamicUartDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ namespace MotorDrivers {
void TrinamicUartDriver::init() {
_uart = config->_uarts[_uart_num];
if (!_uart) {
log_error("TMC2208: Missing uart" << _uart_num << "section");
log_error("TMC Driver missing uart" << _uart_num << " section");
return;
}

_cs_pin.setAttr(Pin::Attr::Output);
}

/*
This is the startup message showing the basic definition.
log_info(" UART CS:" << );
*/
void TrinamicUartDriver::config_message() { //TODO: The RX/TX pin could be added to the msg.
log_info(" " << name() << " UART" << _uart_num << " Addr:" << _addr << " Step:" << _step_pin.name() << " Dir:" << _dir_pin.name()
<< " Disable:" << _disable_pin.name() << " R:" << _r_sense);
log_info(" " << name() << " UART" << _uart_num << " Addr:" << _addr << " CS:" << _cs_pin.name() << " Step:" << _step_pin.name()
<< " Dir:" << _dir_pin.name() << " Disable:" << _disable_pin.name() << " R:" << _r_sense);
}

uint8_t TrinamicUartDriver::toffValue() {
Expand Down
14 changes: 5 additions & 9 deletions FluidNC/src/Motors/TrinamicUartDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ namespace MotorDrivers {
TrinamicUartDriver() = default;

void init() override;
//void read_settings() override;
//bool set_homing_mode(bool is_homing) override;
void set_disable(bool disable) override;

void debug_message();

bool hw_serial_init();

uint8_t _addr;

Expand All @@ -37,13 +30,17 @@ namespace MotorDrivers {

void group(Configuration::HandlerBase& handler) override {
handler.item("addr", _addr);
handler.item("cs_pin", _cs_pin);
handler.item("uart_num", _uart_num);

TrinamicBase::group(handler);
}

protected:
Uart* _uart = nullptr;

Pin _cs_pin;

int _uart_num = -1;

static bool _uart_started;
Expand All @@ -52,8 +49,7 @@ namespace MotorDrivers {
uint8_t toffValue(); // TO DO move to Base?

private:
bool test();
void set_mode(bool isHoming);

};

}
9 changes: 2 additions & 7 deletions FluidNC/src/ProcessSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static bool auth_failed(Word* w, const char* value, WebUI::AuthenticationLevel a
if (!value) { // User can read anything
return false; // No read is a User auth fail
}
return permissions == WA; // User cannot write WA
return permissions == WA; // User cannot write WA
default:
return true;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ void settings_restore(uint8_t restore_flag) {
for (Setting* s : Setting::List) {
if (!s->getDescription()) {
const char* name = s->getName();
if (restore_startup) { // all settings get restored
if (restore_startup) { // all settings get restored
s->setDefault();
} else if ((strcmp(name, "Line0") != 0) && (strcmp(name, "Line1") != 0)) { // non startup settings get restored
s->setDefault();
Expand Down Expand Up @@ -493,11 +493,6 @@ static Error doJog(const char* value, WebUI::AuthenticationLevel auth_level, Cha
return gc_execute_line(jogLine);
}

static const char* alarmString(ExecAlarm alarmNumber) {
auto it = AlarmNames.find(alarmNumber);
return it == AlarmNames.end() ? NULL : it->second;
}

static Error listAlarms(const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) {
if (sys.state == State::ConfigAlarm) {
log_to(out, "Configuration alarm is active. Check the boot messages for 'ERR'.");
Expand Down
Loading

0 comments on commit fec80d9

Please sign in to comment.