1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-29 17:19:50 +02:00

Fixed a few more bugs in machine config. This should be test-able.

This commit is contained in:
Stefan de Bruijn
2021-03-26 11:21:08 +01:00
parent faf8f44888
commit 920c934c34
3 changed files with 58 additions and 55 deletions

View File

@@ -373,11 +373,6 @@ void MachineConfig::afterParse() {
_coolant = new CoolantControl();
}
if (_spi == nullptr) {
log_info("SPI config missing; building default SPI bus.");
_spi = new SPIBus();
}
if (_probe == nullptr) {
log_info("Probe config missing; building default probe.");
_probe = new Probe();

View File

@@ -91,32 +91,36 @@ namespace Motors {
config_message();
auto spiConfig = MachineConfig::instance()->_spi;
if (spiConfig != nullptr) {
auto ssPin = spiConfig->_ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto mosiPin = spiConfig->_mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto sckPin = spiConfig->_sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto misoPin = spiConfig->_miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native);
auto ssPin = spiConfig->_ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto mosiPin = spiConfig->_mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto sckPin = spiConfig->_sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto misoPin = spiConfig->_miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native);
SPI.begin(sckPin, misoPin, mosiPin, ssPin); // this will get called for each motor, but does not seem to hurt anything
SPI.begin(sckPin, misoPin, mosiPin, ssPin); // this will get called for each motor, but does not seem to hurt anything
tmcstepper->begin();
tmcstepper->begin();
_has_errors = !test(); // Try communicating with motor. Prints an error if there is a problem.
_has_errors = !test(); // Try communicating with motor. Prints an error if there is a problem.
read_settings(); // pull info from settings
set_mode(false);
read_settings(); // pull info from settings
set_mode(false);
// After initializing all of the TMC drivers, create a task to
// display StallGuard data. List == this for the final instance.
if (List == this) {
xTaskCreatePinnedToCore(readSgTask, // task
"readSgTask", // name for task
4096, // size of task stack
NULL, // parameters
1, // priority
NULL,
0 // core
);
// After initializing all of the TMC drivers, create a task to
// display StallGuard data. List == this for the final instance.
if (List == this) {
xTaskCreatePinnedToCore(readSgTask, // task
"readSgTask", // name for task
4096, // size of task stack
NULL, // parameters
1, // priority
NULL,
0 // core
);
}
} else {
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "SPI bus is not available; cannot initialize TMC driver.");
_has_errors = true;
}
}

View File

@@ -129,44 +129,48 @@ uint32_t sd_get_current_line_number() {
uint8_t sd_state = SDCARD_IDLE;
uint8_t get_sd_state(bool refresh) {
// Before we use the SD library, we *must* make sure SPI is properly initialized. Re-initialization
// Before we use the SD library, we *must* make sure SPI is properly initialized. Re-initialization
// fortunately doesn't change any of the settings.
auto spiConfig = MachineConfig::instance()->_spi;
auto ssPin = spiConfig->_ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto mosiPin = spiConfig->_mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto sckPin = spiConfig->_sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto misoPin = spiConfig->_miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native);
if (spiConfig != nullptr) {
auto ssPin = spiConfig->_ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto mosiPin = spiConfig->_mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto sckPin = spiConfig->_sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
auto misoPin = spiConfig->_miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native);
SPI.begin(sckPin, misoPin, mosiPin, ssPin); // this will get called for each motor, but does not seem to hurt anything
SPI.begin(sckPin, misoPin, mosiPin, ssPin); // this will get called for each motor, but does not seem to hurt anything
//no need to go further if SD detect is not correct
if (SDCardDetPin->get() != Pin::UNDEFINED) {
if (!((SDCardDetPin->get().read() == SDCARD_DET_VAL) ? true : false)) {
sd_state = SDCARD_NOT_PRESENT;
//no need to go further if SD detect is not correct
if (SDCardDetPin->get() != Pin::UNDEFINED) {
if (!((SDCardDetPin->get().read() == SDCARD_DET_VAL) ? true : false)) {
sd_state = SDCARD_NOT_PRESENT;
return sd_state;
}
}
//if busy doing something return state
if (!((sd_state == SDCARD_NOT_PRESENT) || (sd_state == SDCARD_IDLE))) {
return sd_state;
}
}
//if busy doing something return state
if (!((sd_state == SDCARD_NOT_PRESENT) || (sd_state == SDCARD_IDLE))) {
return sd_state;
}
if (!refresh) {
return sd_state; //to avoid refresh=true + busy to reset SD and waste time
}
//SD is idle or not detected, let see if still the case
SD.end();
sd_state = SDCARD_NOT_PRESENT;
//using default value for speed ? should be parameter
//refresh content if card was removed
if (SD.begin((GRBL_SPI_SS == -1) ? SS : GRBL_SPI_SS, SPI, GRBL_SPI_FREQ, "/sd", 2)) {
if (SD.cardSize() > 0) {
sd_state = SDCARD_IDLE;
if (!refresh) {
return sd_state; //to avoid refresh=true + busy to reset SD and waste time
}
//SD is idle or not detected, let see if still the case
SD.end();
sd_state = SDCARD_NOT_PRESENT;
//using default value for speed ? should be parameter
//refresh content if card was removed
if (SD.begin((GRBL_SPI_SS == -1) ? SS : GRBL_SPI_SS, SPI, GRBL_SPI_FREQ, "/sd", 2)) {
if (SD.cardSize() > 0) {
sd_state = SDCARD_IDLE;
}
}
return sd_state;
} else {
return SDCARD_NOT_PRESENT;
}
return sd_state;
}
uint8_t set_sd_state(uint8_t flag) {