diff --git a/Changelog b/Changelog index f3a6b1d..c96013c 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,13 @@ Changelog: +V00.00.00.12 July 20, 2016 + + * Sped up movements + * No longer adjusts the motor E current since it might be putting too much stress on the motor when no filament is present and when the nozzle is clogged + * Compiled with the latest Atmel AVR 8-bit Toolchain V3.5.3 and Atmel Software Framework V3.31 + * Fixed issue where the bed orientation version in the printer's EEPROM would be updated after running a G32 command + * Sets unused pins as inputs with pull-up resistors enabled + V00.00.00.10 June 16, 2016 * Fixed compatibility with MatterControl diff --git a/M33 Manager/M33 Manager Linux.zip b/M33 Manager/M33 Manager Linux.zip index 8bc94d7..e8c4850 100644 Binary files a/M33 Manager/M33 Manager Linux.zip and b/M33 Manager/M33 Manager Linux.zip differ diff --git a/M33 Manager/M33 Manager OS X.zip b/M33 Manager/M33 Manager OS X.zip index f2c26aa..69485c4 100644 Binary files a/M33 Manager/M33 Manager OS X.zip and b/M33 Manager/M33 Manager OS X.zip differ diff --git a/M33 Manager/M33 Manager Windows.zip b/M33 Manager/M33 Manager Windows.zip index 5fba2ee..c982522 100644 Binary files a/M33 Manager/M33 Manager Windows.zip and b/M33 Manager/M33 Manager Windows.zip differ diff --git a/M33 Manager/Makefile b/M33 Manager/Makefile index 5ce60cc..0b87c6b 100644 --- a/M33 Manager/Makefile +++ b/M33 Manager/Makefile @@ -1,9 +1,9 @@ # Target platform options: WINDOWS32, WINDOWS64, OSX32, OSX64, LINUX32, LINUX64 PROGRAM_NAME = M33\ Manager -VERSION = 0.06 +VERSION = 0.07 TARGET_PLATFORM = LINUX64 USE_GUI = TRUE -IME_ROM_VERSION_STRING = 1900000010 +IME_ROM_VERSION_STRING = 1900000012 M3D_ROM_VERSION_STRING = 2016040401 SRCS = main.cpp printer.cpp gcode.cpp common.cpp @@ -91,9 +91,7 @@ ifeq ($(TARGET_PLATFORM), LINUX64) endif endif -all: $(EXECUTABLE) - -$(EXECUTABLE): $(SRCS) +all: $(CC) $(CFLAGS) "bin2h.cpp" -o "bin2h" ./bin2h "resources/files/icon.png" ./bin2h "resources/files/refresh.png" diff --git a/M33 Manager/gcode.cpp b/M33 Manager/gcode.cpp index 733e8bf..b05849e 100644 --- a/M33 Manager/gcode.cpp +++ b/M33 Manager/gcode.cpp @@ -538,7 +538,7 @@ vector Gcode::getBinary() const { // Set sums sum1 = (sum1 + request[index]) % 0xFF; - sum2 = (sum1 + sum2) % 0xFF; + sum2 = (sum1 + sum2) % 0xFF; } // Append Fletcher 16 checksum checksum to request diff --git a/M33 Manager/gui.cpp b/M33 Manager/gui.cpp index 69948ad..269b59d 100644 --- a/M33 Manager/gui.cpp +++ b/M33 Manager/gui.cpp @@ -1152,7 +1152,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, //sendCommand("M619 S" + eepromOffsets["bedHeightOffset"]["offset"] + " T" + eepromOffsets["bedHeightOffset"]["bytes"], // Send commands - if(printer.getFirmwareType() == "M3D" || printer.getFirmwareType() == "M3D Mod") { + if(printer.getFirmwareType() == M3D || printer.getFirmwareType() == M3D_MOD) { sendCommand("G91"); sendCommand("G0 Z0.1 F90"); } @@ -2006,7 +2006,7 @@ void MyFrame::installDrivers(wxCommandEvent& event) { fout.close(); // Check if applying udev rule failed - if(system("/etc/init.d/udev restart")) + if(system("udevadm control --reload-rules") || system("udevadm trigger")) // Return message return {"Failed to apply udev rule", wxOK | wxICON_ERROR | wxCENTRE}; @@ -3083,7 +3083,7 @@ void MyFrame::checkInvalidValues() { iMeVersion.insert(i * 2 + 2 + i, "."); // Display firmware installation dialog - wxMessageDialog *dial = new wxMessageDialog(NULL, "Firmware is corrupt. Install " + (printer.getFirmwareType() == "M3D" || printer.getFirmwareType() == "M3D Mod" ? "M3D V" TOSTRING(M3D_ROM_VERSION_STRING) : "iMe V" + iMeVersion) + "?", "M33 Manager", wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION); + wxMessageDialog *dial = new wxMessageDialog(NULL, "Firmware is corrupt. Install " + (printer.getFirmwareType() == M3D || printer.getFirmwareType() == M3D_MOD ? "M3D V" TOSTRING(M3D_ROM_VERSION_STRING) : "iMe V" + iMeVersion) + "?", "M33 Manager", wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION); // Check if installing firmware if(dial->ShowModal() == wxID_YES) { @@ -3092,7 +3092,7 @@ void MyFrame::checkInvalidValues() { fixingInvalidValues = true; // Check if installing M3D firmware - if(printer.getFirmwareType() == "M3D" || printer.getFirmwareType() == "M3D Mod") { + if(printer.getFirmwareType() == M3D || printer.getFirmwareType() == M3D_MOD) { // Install M3D firmware wxCommandEvent event(wxEVT_BUTTON, installM3dFirmwareButton->GetId()); @@ -3143,6 +3143,96 @@ void MyFrame::checkInvalidValues() { wxMessageBox("Failed to update firmware", "M33 Manager", wxOK | wxICON_ERROR | wxCENTRE); }); } + + // Otherwise + else + + // Disconnect printer + printer.disconnect(); + } + + // Otherwise check if firmware is incompatible or outdated + else if(printer.getFirmwareType() == UNKNOWN_FIRMWARE || ((printer.getFirmwareType() == M3D || printer.getFirmwareType() == M3D_MOD) && stoi(printer.getFirmwareRelease()) < M3D_ROM_VERSION_STRING) || (printer.getFirmwareType() == IME && printer.getFirmwareVersion() < IME_ROM_VERSION_STRING)) { + + // Set if firmware is incompatible + bool incompatible = true; + if((printer.getFirmwareType() == M3D || printer.getFirmwareType() == M3D_MOD) && stoi(printer.getFirmwareRelease()) >= 2015122112) + incompatible = false; + else if(printer.getFirmwareType() == IME && printer.getFirmwareVersion() >= 1900000006) + incompatible = false; + + // Get iMe version + string iMeVersion = static_cast(TOSTRING(IME_ROM_VERSION_STRING)).substr(2); + for(uint8_t i = 0; i < 3; i++) + iMeVersion.insert(i * 2 + 2 + i, "."); + + // Display firmware installation dialog + wxMessageDialog *dial = new wxMessageDialog(NULL, static_cast(incompatible ? "Firmware is incompatible" : "Newer firmware available") + ". Update to " + (printer.getFirmwareType() == M3D || printer.getFirmwareType() == M3D_MOD ? "M3D V" TOSTRING(M3D_ROM_VERSION_STRING) : "iMe V" + iMeVersion) + "?", "M33 Manager", wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION); + + // Check if installing firmware + if(dial->ShowModal() == wxID_YES) { + + // Set fixing invalid values + fixingInvalidValues = true; + + // Check if installing M3D firmware + if(printer.getFirmwareType() == M3D || printer.getFirmwareType() == M3D_MOD) { + + // Install M3D firmware + wxCommandEvent event(wxEVT_BUTTON, installM3dFirmwareButton->GetId()); + installM3dFirmwareButton->GetEventHandler()->ProcessEvent(event); + } + + // Otherwise + else { + + // Install iMe firmware + wxCommandEvent event(wxEVT_BUTTON, installImeFirmwareButton->GetId()); + installImeFirmwareButton->GetEventHandler()->ProcessEvent(event); + } + + // Lock + wxCriticalSectionLocker lock(criticalLock); + + // Append thread start callback to queue + threadStartCallbackQueue.push([=]() -> void {}); + + // Append thread task to queue + threadTaskQueue.push([=]() -> ThreadTaskResponse { + + // Return empty response + return {"", 0}; + }); + + // Append thread complete callback to queue + threadCompleteCallbackQueue.push([=](ThreadTaskResponse response) -> void { + + // Clear fixing invalid values + fixingInvalidValues = false; + + // Check if printer is still connected + if(printer.isConnected()) { + + // Display message + wxMessageBox("Firmware successfully installed", "M33 Manager", wxOK | wxICON_INFORMATION | wxCENTRE); + + // Display calibrate bed position dialog + calibrateBedPositionDialog(); + } + + // Otherwise + else + + // Display message + wxMessageBox("Failed to update firmware", "M33 Manager", wxOK | wxICON_ERROR | wxCENTRE); + }); + } + + // Otherwise check if firmware is incompatible + else if(incompatible) + + // Disconnect printer + printer.disconnect(); // Otherwise else diff --git a/M33 Manager/main.cpp b/M33 Manager/main.cpp index 752f8d4..74c561e 100644 --- a/M33 Manager/main.cpp +++ b/M33 Manager/main.cpp @@ -98,7 +98,7 @@ bool installFirmware(const string &firmwareLocation, const string &serialPort); iMeVersion.insert(i * 2 + 2 + i, "."); // Display help - cout << "Usage: \"M33 Manager\" -d -f -b -i -3 -m -r firmware.rom serialport" << endl; + cout << "Usage: \"M33 Manager\" -d -f -b -i -3 -r firmware.rom -m serialport" << endl; #ifndef OSX cout << "-d | --drivers: Install device drivers" << endl; #endif @@ -239,9 +239,9 @@ bool installFirmware(const string &firmwareLocation, const string &serialPort); for(uint64_t i = 0; i < _90_micro_3d_local_rulesSize; i++) fout.put(_90_micro_3d_local_rulesData[i]); fout.close(); - + // Check if applying udev rule failed - if(system("/etc/init.d/udev restart")) { + if(system("udevadm control --reload-rules") || system("udevadm trigger")) { // Display error cout << "Failed to install drivers" << endl; diff --git a/M33 Manager/printer.cpp b/M33 Manager/printer.cpp index b8bca2e..83c442f 100644 --- a/M33 Manager/printer.cpp +++ b/M33 Manager/printer.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -239,13 +238,13 @@ bool Printer::connect(const string &serialPort, bool connectingToNewPrinter) { // Restore current serial port if not connecting to a new printer if(!connectingToNewPrinter) currentSerialPort = savedSerialPort; - - // Attempt to connect to a specified port several times or all available ports once - string lastAttemptedSerialPort, initialSerialPort; - for(uint8_t i = 0; i < 5; i += serialPort.length() || !connectingToNewPrinter ? 1 : 0) { - - // Wait 100 milliseconds if connecting to a specified port - if(serialPort.length() || !connectingToNewPrinter) + + // Attempt to connect to a specified port several times or all available ports once + string lastAttemptedSerialPort, initialSerialPort; + for(uint8_t i = 0; i < 5; i += serialPort.length() || !connectingToNewPrinter ? 1 : 0) { + + // Wait 100 milliseconds if connecting to a specified port + if(serialPort.length() || !connectingToNewPrinter) sleepUs(100000); // Save current serial port @@ -345,7 +344,7 @@ bool Printer::connect(const string &serialPort, bool connectingToNewPrinter) { // Log end of successful connection if(logFunction) - logFunction("Connected to " + getSerialNumber() + " at " + getCurrentSerialPort() + " running " + getFirmwareType() + " firmware V" + getFirmwareRelease()); + logFunction("Connected to " + getSerialNumber() + " at " + getCurrentSerialPort() + " running " + getFirmwareTypeAsString(firmwareType) + " firmware V" + getFirmwareRelease()); // Return true return true; @@ -467,7 +466,7 @@ bool Printer::connect(const string &serialPort, bool connectingToNewPrinter) { // Log end of successful connection if(logFunction) - logFunction("Connected to " + getSerialNumber() + " at " + getCurrentSerialPort() + " running " + getFirmwareType() + " firmware V" + getFirmwareRelease()); + logFunction("Connected to " + getSerialNumber() + " at " + getCurrentSerialPort() + " running " + getFirmwareTypeAsString(firmwareType) + " firmware V" + getFirmwareRelease()); // Return true return true; @@ -738,7 +737,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating backlash speed failed - if(!eepromWriteFloat(EEPROM_BACKLASH_SPEED_OFFSET, EEPROM_BACKLASH_SPEED_LENGTH, DEFAULT_BACKLASH_SPEED)) { + if(!eepromWriteFloat(EEPROM_BACKLASH_SPEED_OFFSET, EEPROM_BACKLASH_SPEED_LENGTH, EEPROM_BACKLASH_SPEED_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -750,7 +749,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating backlash X failed - if(!eepromKeepFloatWithinRange(EEPROM_BACKLASH_X_OFFSET, EEPROM_BACKLASH_X_LENGTH, 0, 2, DEFAULT_BACKLASH_X)) { + if(!eepromKeepFloatWithinRange(EEPROM_BACKLASH_X_OFFSET, EEPROM_BACKLASH_X_LENGTH, EEPROM_BACKLASH_X_MIN, EEPROM_BACKLASH_X_MAX, EEPROM_BACKLASH_X_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -761,7 +760,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating backlash Y failed - if(!eepromKeepFloatWithinRange(EEPROM_BACKLASH_Y_OFFSET, EEPROM_BACKLASH_Y_LENGTH, 0, 2, DEFAULT_BACKLASH_Y)) { + if(!eepromKeepFloatWithinRange(EEPROM_BACKLASH_Y_OFFSET, EEPROM_BACKLASH_Y_LENGTH, EEPROM_BACKLASH_Y_MIN, EEPROM_BACKLASH_Y_MAX, EEPROM_BACKLASH_Y_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -772,7 +771,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating backlash speed failed - if(!eepromKeepFloatWithinRange(EEPROM_BACKLASH_SPEED_OFFSET, EEPROM_BACKLASH_SPEED_LENGTH, 1, 5000, DEFAULT_BACKLASH_SPEED)) { + if(!eepromKeepFloatWithinRange(EEPROM_BACKLASH_SPEED_OFFSET, EEPROM_BACKLASH_SPEED_LENGTH, EEPROM_BACKLASH_SPEED_MIN, EEPROM_BACKLASH_SPEED_MAX, EEPROM_BACKLASH_SPEED_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -783,7 +782,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed orientation back right failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_ORIENTATION_BACK_RIGHT_OFFSET, EEPROM_BED_ORIENTATION_BACK_RIGHT_LENGTH, -3, 3, DEFAULT_BED_ORIENTATION_BACK_RIGHT)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_ORIENTATION_BACK_RIGHT_OFFSET, EEPROM_BED_ORIENTATION_BACK_RIGHT_LENGTH, EEPROM_BED_ORIENTATION_BACK_RIGHT_MIN, EEPROM_BED_ORIENTATION_BACK_RIGHT_MAX, EEPROM_BED_ORIENTATION_BACK_RIGHT_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -794,7 +793,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed orientation back left failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_ORIENTATION_BACK_LEFT_OFFSET, EEPROM_BED_ORIENTATION_BACK_LEFT_LENGTH, -3, 3, DEFAULT_BED_ORIENTATION_BACK_LEFT)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_ORIENTATION_BACK_LEFT_OFFSET, EEPROM_BED_ORIENTATION_BACK_LEFT_LENGTH, EEPROM_BED_ORIENTATION_BACK_LEFT_MIN, EEPROM_BED_ORIENTATION_BACK_LEFT_MAX, EEPROM_BED_ORIENTATION_BACK_LEFT_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -805,7 +804,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed orientation front left failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_ORIENTATION_FRONT_LEFT_OFFSET, EEPROM_BED_ORIENTATION_FRONT_LEFT_LENGTH, -3, 3, DEFAULT_BED_ORIENTATION_FRONT_LEFT)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_ORIENTATION_FRONT_LEFT_OFFSET, EEPROM_BED_ORIENTATION_FRONT_LEFT_LENGTH, EEPROM_BED_ORIENTATION_FRONT_LEFT_MIN, EEPROM_BED_ORIENTATION_FRONT_LEFT_MAX, EEPROM_BED_ORIENTATION_FRONT_LEFT_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -816,7 +815,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed orientation front right failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_ORIENTATION_FRONT_RIGHT_OFFSET, EEPROM_BED_ORIENTATION_FRONT_RIGHT_LENGTH, -3, 3, DEFAULT_BED_ORIENTATION_FRONT_RIGHT)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_ORIENTATION_FRONT_RIGHT_OFFSET, EEPROM_BED_ORIENTATION_FRONT_RIGHT_LENGTH, EEPROM_BED_ORIENTATION_FRONT_RIGHT_MIN, EEPROM_BED_ORIENTATION_FRONT_RIGHT_MAX, EEPROM_BED_ORIENTATION_FRONT_RIGHT_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -827,7 +826,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed offset back right failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_OFFSET_BACK_RIGHT_OFFSET, EEPROM_BED_OFFSET_BACK_RIGHT_LENGTH, -FLT_MAX, FLT_MAX, DEFAULT_BED_OFFSET_BACK_RIGHT)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_OFFSET_BACK_RIGHT_OFFSET, EEPROM_BED_OFFSET_BACK_RIGHT_LENGTH, EEPROM_BED_OFFSET_BACK_RIGHT_MIN, EEPROM_BED_OFFSET_BACK_RIGHT_MAX, EEPROM_BED_OFFSET_BACK_RIGHT_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -838,7 +837,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed offset back left failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_OFFSET_BACK_LEFT_OFFSET, EEPROM_BED_OFFSET_BACK_LEFT_LENGTH, -FLT_MAX, FLT_MAX, DEFAULT_BED_OFFSET_BACK_LEFT)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_OFFSET_BACK_LEFT_OFFSET, EEPROM_BED_OFFSET_BACK_LEFT_LENGTH, EEPROM_BED_OFFSET_BACK_LEFT_MIN, EEPROM_BED_OFFSET_BACK_LEFT_MAX, EEPROM_BED_OFFSET_BACK_LEFT_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -849,7 +848,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed offset front left failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_OFFSET_FRONT_LEFT_OFFSET, EEPROM_BED_OFFSET_FRONT_LEFT_LENGTH, -FLT_MAX, FLT_MAX, DEFAULT_BED_OFFSET_FRONT_LEFT)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_OFFSET_FRONT_LEFT_OFFSET, EEPROM_BED_OFFSET_FRONT_LEFT_LENGTH, EEPROM_BED_OFFSET_FRONT_LEFT_MIN, EEPROM_BED_OFFSET_FRONT_LEFT_MAX, EEPROM_BED_OFFSET_FRONT_LEFT_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -860,7 +859,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed offset front right failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_OFFSET_FRONT_RIGHT_OFFSET, EEPROM_BED_OFFSET_FRONT_RIGHT_LENGTH, -FLT_MAX, FLT_MAX, DEFAULT_BED_OFFSET_FRONT_RIGHT)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_OFFSET_FRONT_RIGHT_OFFSET, EEPROM_BED_OFFSET_FRONT_RIGHT_LENGTH, EEPROM_BED_OFFSET_FRONT_RIGHT_MIN, EEPROM_BED_OFFSET_FRONT_RIGHT_MAX, EEPROM_BED_OFFSET_FRONT_RIGHT_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -871,7 +870,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating bed height offset failed - if(!eepromKeepFloatWithinRange(EEPROM_BED_HEIGHT_OFFSET_OFFSET, EEPROM_BED_HEIGHT_OFFSET_LENGTH, -FLT_MAX, FLT_MAX, DEFAULT_BED_HEIGHT_OFFSET)) { + if(!eepromKeepFloatWithinRange(EEPROM_BED_HEIGHT_OFFSET_OFFSET, EEPROM_BED_HEIGHT_OFFSET_LENGTH, EEPROM_BED_HEIGHT_OFFSET_MIN, EEPROM_BED_HEIGHT_OFFSET_MAX, EEPROM_BED_HEIGHT_OFFSET_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -882,7 +881,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating speed limit X failed - if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_X_OFFSET, EEPROM_SPEED_LIMIT_X_LENGTH, 120, 4800, DEFAULT_SPEED_LIMIT_X)) { + if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_X_OFFSET, EEPROM_SPEED_LIMIT_X_LENGTH, EEPROM_SPEED_LIMIT_X_MIN, EEPROM_SPEED_LIMIT_X_MAX, EEPROM_SPEED_LIMIT_X_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -893,7 +892,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating speed limit Y failed - if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_Y_OFFSET, EEPROM_SPEED_LIMIT_Y_LENGTH, 120, 4800, DEFAULT_SPEED_LIMIT_Y)) { + if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_Y_OFFSET, EEPROM_SPEED_LIMIT_Y_LENGTH, EEPROM_SPEED_LIMIT_Y_MIN, EEPROM_SPEED_LIMIT_Y_MAX, EEPROM_SPEED_LIMIT_Y_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -904,7 +903,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating speed limit Z failed - if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_Z_OFFSET, EEPROM_SPEED_LIMIT_Z_LENGTH, 30, 60, DEFAULT_SPEED_LIMIT_Z)) { + if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_Z_OFFSET, EEPROM_SPEED_LIMIT_Z_LENGTH, EEPROM_SPEED_LIMIT_Z_MIN, EEPROM_SPEED_LIMIT_Z_MAX, EEPROM_SPEED_LIMIT_Z_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -915,7 +914,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating speed limit E+ failed - if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_E_POSITIVE_OFFSET, EEPROM_SPEED_LIMIT_E_POSITIVE_LENGTH, 60, 600, DEFAULT_SPEED_LIMIT_E_POSITIVE)) { + if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_E_POSITIVE_OFFSET, EEPROM_SPEED_LIMIT_E_POSITIVE_LENGTH, EEPROM_SPEED_LIMIT_E_POSITIVE_MIN, EEPROM_SPEED_LIMIT_E_POSITIVE_MAX, EEPROM_SPEED_LIMIT_E_POSITIVE_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -926,7 +925,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating speed limit E- failed - if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_E_NEGATIVE_OFFSET, EEPROM_SPEED_LIMIT_E_NEGATIVE_LENGTH, 60, 720, DEFAULT_SPEED_LIMIT_E_NEGATIVE)) { + if(!eepromKeepFloatWithinRange(EEPROM_SPEED_LIMIT_E_NEGATIVE_OFFSET, EEPROM_SPEED_LIMIT_E_NEGATIVE_LENGTH, EEPROM_SPEED_LIMIT_E_NEGATIVE_MIN, EEPROM_SPEED_LIMIT_E_NEGATIVE_MAX, EEPROM_SPEED_LIMIT_E_NEGATIVE_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -940,7 +939,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { if(firmwareType == IME) { // Check if updating last recorded X value failed - if(!eepromKeepFloatWithinRange(EEPROM_LAST_RECORDED_X_VALUE_OFFSET, EEPROM_LAST_RECORDED_X_VALUE_LENGTH, -FLT_MAX, FLT_MAX, DEFAULT_LAST_RECORDED_X_VALUE)) { + if(!eepromKeepFloatWithinRange(EEPROM_LAST_RECORDED_X_VALUE_OFFSET, EEPROM_LAST_RECORDED_X_VALUE_LENGTH, EEPROM_LAST_RECORDED_X_VALUE_MIN, EEPROM_LAST_RECORDED_X_VALUE_MAX, EEPROM_LAST_RECORDED_X_VALUE_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -951,7 +950,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating last recorded Y value failed - if(!eepromKeepFloatWithinRange(EEPROM_LAST_RECORDED_Y_VALUE_OFFSET, EEPROM_LAST_RECORDED_Y_VALUE_LENGTH, -FLT_MAX, FLT_MAX, DEFAULT_LAST_RECORDED_Y_VALUE)) { + if(!eepromKeepFloatWithinRange(EEPROM_LAST_RECORDED_Y_VALUE_OFFSET, EEPROM_LAST_RECORDED_Y_VALUE_LENGTH, EEPROM_LAST_RECORDED_Y_VALUE_MIN, EEPROM_LAST_RECORDED_Y_VALUE_MAX, EEPROM_LAST_RECORDED_Y_VALUE_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -963,7 +962,7 @@ bool Printer::collectPrinterInformation(bool logDetails) { } // Check if updating last recorded Z value failed - if(!eepromKeepFloatWithinRange(EEPROM_LAST_RECORDED_Z_VALUE_OFFSET, EEPROM_LAST_RECORDED_Z_VALUE_LENGTH, -FLT_MAX, FLT_MAX, DEFAULT_LAST_RECORDED_Z_VALUE)) { + if(!eepromKeepFloatWithinRange(EEPROM_LAST_RECORDED_Z_VALUE_OFFSET, EEPROM_LAST_RECORDED_Z_VALUE_LENGTH, EEPROM_LAST_RECORDED_Z_VALUE_MIN, EEPROM_LAST_RECORDED_Z_VALUE_MAX, EEPROM_LAST_RECORDED_Z_VALUE_DEFAULT)) { // Log if logging details if(logFunction && logDetails) @@ -1163,12 +1162,12 @@ void Printer::disconnect() { status = "Disconnected"; // Check if file descriptor is open - if(fd) { - - // Check if using Windows - #ifdef WINDOWS - - // Close device + if(fd) { + + // Check if using Windows + #ifdef WINDOWS + + // Close device CloseHandle(fd); // Otherwise @@ -1810,7 +1809,7 @@ bool Printer::installFirmware(const string &file) { // Log printer details if(logFunction) - logFunction("Printer is running " + getFirmwareType() + " firmware V" + getFirmwareRelease()); + logFunction("Printer is running " + getFirmwareTypeAsString(firmwareType) + " firmware V" + getFirmwareRelease()); // Return true return true; @@ -2459,22 +2458,22 @@ void Printer::updateAvailableSerialPorts() { // Create device info string stringstream deviceInfoStringStream; - deviceInfoStringStream << "USB:V" << setfill('0') << setw(4) << hex << uppercase << PRINTER_VENDOR_ID << 'P' << setfill('0') << setw(4) << hex << uppercase << PRINTER_PRODUCT_ID; + deviceInfoStringStream << "USB:V" << setfill('0') << setw(4) << hex << uppercase << PRINTER_VENDOR_ID << 'P' << setfill('0') << setw(4) << hex << uppercase << PRINTER_PRODUCT_ID; string deviceInfoString = deviceInfoStringStream.str(); // Go through all serial devices dirent *entry; - while((entry = readdir(path))) { - - // Check if current device is a serial device - if(strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..") && !strncmp("ttyACM", entry->d_name, 6)) { - - // Check if uevent file exists for the device - ifstream device(static_cast("/sys/class/tty/") + entry->d_name + "/device/modalias", ios::binary); - if(device.good()) { - - // Read in file - string info; + while((entry = readdir(path))) { + + // Check if current device is a serial device + if(strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..") && !strncmp("ttyACM", entry->d_name, 6)) { + + // Check if uevent file exists for the device + ifstream device(static_cast("/sys/class/tty/") + entry->d_name + "/device/modalias", ios::binary); + if(device.good()) { + + // Read in file + string info; while(device.peek() != EOF) info.push_back(toupper(device.get())); @@ -2551,10 +2550,10 @@ string Printer::getNewSerialPort(string lastAttemptedPort, string stopAtPort) { for(uint8_t i = 0; i < availableSerialPorts.size(); i++) // Check if current serial port exists - if(currentSerialPort == availableSerialPorts[i]) - - // Return current serial port - return currentSerialPort; + if(currentSerialPort == availableSerialPorts[i]) + + // Return current serial port + return currentSerialPort; // Go through all available serial ports for(uint8_t i = 0; i < availableSerialPorts.size(); i++) { @@ -2780,10 +2779,10 @@ string Printer::getSerialNumber() { return serialNumber.substr(0, 2) + '-' + serialNumber.substr(2, 2) + '-' + serialNumber.substr(4, 2) + '-' + serialNumber.substr(6, 2) + '-' + serialNumber.substr(8, 2) + '-' + serialNumber.substr(10, 3) + '-' + serialNumber.substr(13, 13); } -string Printer::getFirmwareType() { +firmwareTypes Printer::getFirmwareType() { - // Return firmware type as string - return getFirmwareTypeAsString(firmwareType); + // Return firmware type + return firmwareType; } string Printer::getFirmwareRelease() { @@ -2792,6 +2791,12 @@ string Printer::getFirmwareRelease() { return getFirmwareReleaseFromFirmwareVersion(firmwareVersion); } +uint32_t Printer::getFirmwareVersion() { + + // Return firmware version + return firmwareVersion; +} + void Printer::setLogFunction(function function) { // Set log function @@ -2857,7 +2862,7 @@ string Printer::getFirmwareReleaseFromFirmwareVersion(uint32_t firmwareVersion) return to_string(firmwareVersion); case M3D_MOD: - return to_string(firmwareVersion - 100000000); + return to_string(firmwareVersion - 100000000); default: string temp = to_string(firmwareVersion); diff --git a/M33 Manager/printer.h b/M33 Manager/printer.h index e3ddf01..6069aea 100644 --- a/M33 Manager/printer.h +++ b/M33 Manager/printer.h @@ -174,7 +174,7 @@ class Printer { Name: Get firmware type Purpose: Returns the printer's firmware type */ - string getFirmwareType(); + firmwareTypes getFirmwareType(); /* Name: Get firmware release @@ -182,6 +182,12 @@ class Printer { */ string getFirmwareRelease(); + /* + Name: Get firmware version + Purpose: Returns the printer's firmware version number + */ + uint32_t getFirmwareVersion(); + /* Name: Set log function Purpose: Sets the function used to log the printer's actions diff --git a/M33 Manager/resources/Linux/90-micro-3d-local.rules b/M33 Manager/resources/Linux/90-micro-3d-local.rules index 85c895c..7d8649f 100644 --- a/M33 Manager/resources/Linux/90-micro-3d-local.rules +++ b/M33 Manager/resources/Linux/90-micro-3d-local.rules @@ -1,5 +1,6 @@ # Run the following commands to install this rule # cp ./90-micro-3d-local.rules /etc/udev/rules.d/ -# sudo /etc/init.d/udev restart +# sudo udevadm control --reload-rules +# sudo udevadm trigger ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2404", GROUP="users", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1" diff --git a/Makefile b/Makefile index fa835a5..6c1ecd8 100755 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Firmware name and version FIRMWARE_NAME = iMe -FIRMWARE_VERSION = 00.00.00.10 -ROM_VERSION_STRING = 1900000010 +FIRMWARE_VERSION = 00.00.00.12 +ROM_VERSION_STRING = 1900000012 # Tool locations ifeq ($(OS), Windows_NT) @@ -9,7 +9,7 @@ ifeq ($(OS), Windows_NT) COPY = "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" SIZE = "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" DUMP = "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" - M33MANAGER = "M33 Manager/M33 Manager.exe" + M33MANAGER = "M33 Manager\M33 Manager.exe" else CC = /opt/avr-toolchain/bin/avr-gcc COPY = /opt/avr-toolchain/bin/avr-objcopy @@ -94,7 +94,7 @@ INCPATH = . \ src/config # Compiler flags -FLAGS = -D BOARD=USER_BOARD -D FIRMWARE_NAME=$(FIRMWARE_NAME) -D FIRMWARE_VERSION=$(FIRMWARE_VERSION) -Os -mmcu=atxmega32c4 -Wall -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -fno-strict-aliasing -Werror-implicit-function-declaration -Wpointer-arith -mcall-prologues -mstrict-X -maccumulate-args -fno-tree-ter -mrelax -fno-math-errno -fno-signed-zeros -flto -flto-partition=1to1 +FLAGS = -D BOARD=USER_BOARD -D FIRMWARE_NAME=$(FIRMWARE_NAME) -D FIRMWARE_VERSION=$(FIRMWARE_VERSION) -Os -mmcu=atxmega32c4 -Wall -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -fno-strict-aliasing -Werror-implicit-function-declaration -Wpointer-arith -mcall-prologues -mstrict-X -maccumulate-args -fno-tree-ter -mrelax -fno-math-errno -fno-signed-zeros -flto -flto-partition=1to1 ASFLAGS = -std=c++14 -x assembler-with-cpp CFLAGS = -std=gnu99 -x c -Wstrict-prototypes -Wmissing-prototypes CPPFLAGS = -std=c++14 -x c++ @@ -102,10 +102,10 @@ LFLAGS = -Wl,--section-start=.BOOT=0x8000 -Wl,--start-group -Wl,--end-group -Wl, # Make - Compiles firmware all: - $(CC) $(foreach INC, $(addprefix , $(INCPATH)), -I $(INC)) $(FLAGS) $(ASFLAGS) -c $(ASSRCS) - $(CC) $(foreach INC, $(addprefix , $(INCPATH)), -I $(INC)) $(FLAGS) $(CFLAGS) -c $(CSRCS) - $(CC) $(foreach INC, $(addprefix , $(INCPATH)), -I $(INC)) $(FLAGS) $(CPPFLAGS) -c $(CPPSRCS) - $(CC) $(foreach INC, $(addprefix , $(INCPATH)), -I $(INC)) $(FLAGS) $(LFLAGS) *.o -o $(FIRMWARE_NAME).elf + $(CC) $(foreach INC, $(addprefix , $(INCPATH)),-I $(INC)) $(FLAGS) $(ASFLAGS) -c $(ASSRCS) + $(CC) $(foreach INC, $(addprefix , $(INCPATH)),-I $(INC)) $(FLAGS) $(CFLAGS) -c $(CSRCS) + $(CC) $(foreach INC, $(addprefix , $(INCPATH)),-I $(INC)) $(FLAGS) $(CPPFLAGS) -c $(CPPSRCS) + $(CC) $(foreach INC, $(addprefix , $(INCPATH)),-I $(INC)) $(FLAGS) $(LFLAGS) *.o -o $(FIRMWARE_NAME).elf @$(COPY) -O binary $(FIRMWARE_NAME).elf "$(FIRMWARE_NAME) $(ROM_VERSION_STRING).hex" @$(SIZE) --mcu=atxmega32c4 -C $(FIRMWARE_NAME).elf @rm -f *.o $(FIRMWARE_NAME).elf @@ -118,6 +118,7 @@ clean: # Make run - Flashes and runs compiled firmware run: @$(M33MANAGER) -r "$(FIRMWARE_NAME) $(ROM_VERSION_STRING).hex" + @$(M33MANAGER) -f # Make production debug - Adds debug information to a production elf named production.elf productionDebug: diff --git a/README.md b/README.md index 08e01c8..1b91f12 100755 --- a/README.md +++ b/README.md @@ -3,23 +3,21 @@ Firmware that allows using the Micro 3D printer with third-party 3D printing sof © 2015-2016 Exploit Kings. All rights reserved. -iMe has been discontinued on June 21st, 2016. I no longer feel like developing software for a product created by a company like M3D. - ### Description iMe is firmware for the Micro 3D printer that attempts to fix the printer's biggest problem: limited software compatibility. iMe uses RepRap G-code protocol, so it allows you to use the Micro 3D printer with any 3D printing software that supports that protocol. It also features builtin backlash and bed compensation which makes creating good looking prints with other software possible since the G-code never has to be pre-processed beforehand. -The latest version of iMe is V00.00.00.10 released on June 16th, 2016, and an entire changelog for it can be found [here](https://raw.githubusercontent.com/donovan6000/iMe/master/Changelog). +The latest version of iMe is V00.00.00.12 released on July 20th, 2016, and an entire changelog for it can be found [here](https://raw.githubusercontent.com/donovan6000/iMe/master/Changelog). ### Features * Uses RepRap's G-code protocol * Open source (iMe's source code can be found [here](https://github.com/donovan6000/iMe)) * Homing uses the accelerometer to minimize grinding * Builtin backlash and bed compensation -* Monitor's the extruder's current to maintain a steady flow of filament * Prevents moving the extruder out of bounds in the X and Y directions +* Faster printing ### Installation -The easiest way to install iMe is with M33 Manager, which is available for [Windows](https://raw.githubusercontent.com/donovan6000/iMe/master/M33%20Manager/M33%20Manager%20Windows.zip), [OS X](https://raw.githubusercontent.com/donovan6000/iMe/master/M33%20Manager/M33%20Manager%20OS%20X.zip), and [Linux](https://raw.githubusercontent.com/donovan6000/iMe/master/M33%20Manager/M33%20Manager%20Linux.zip). Just connect the printer to M33 Manager and click the 'Install iMe firmware' button to install iMe. +The easiest way to install iMe is with M33 Manager, which is available for [Windows](https://raw.githubusercontent.com/donovan6000/iMe/master/M33%20Manager/M33%20Manager%20Windows.zip), [OS X](https://raw.githubusercontent.com/donovan6000/iMe/master/M33%20Manager/M33%20Manager%20OS%20X.zip), and [Linux](https://raw.githubusercontent.com/donovan6000/iMe/master/M33%20Manager/M33%20Manager%20Linux.zip). Just connect the printer to M33 Manager and click the 'Install iMe firmware' button to install iMe. iMe is also fully compatible with [M33 Fio](https://github.com/donovan6000/M33-Fio), and it can be installed from there as well. diff --git a/accelerometer.cpp b/accelerometer.cpp index daa0bec..4c4937b 100755 --- a/accelerometer.cpp +++ b/accelerometer.cpp @@ -1,4 +1,6 @@ -// MMA8652FC http://cache.nxp.com/files/sensors/doc/data_sheet/MMA8652FC.pdf +// MMA8652FC accelerometer http://cache.nxp.com/files/sensors/doc/data_sheet/MMA8652FC.pdf + + // Header files extern "C" { #include @@ -50,7 +52,7 @@ enum {ACCELERATION_X, ACCELERATION_Y, ACCELERATION_Z, NUMBER_OF_ACCELERATION_AXE // Supporting function implementation void Accelerometer::initialize() { - // Configure enable, SDA and SCL pins + // Configure enable, SDA, and SCL pins ioport_set_pin_dir(ACCELEROMETER_ENABLE_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(ACCELEROMETER_ENABLE_PIN, ACCELEROMETER_ENABLE); ioport_set_pin_mode(ACCELEROMETER_SDA_PIN, IOPORT_MODE_WIREDANDPULL); diff --git a/accelerometer.h b/accelerometer.h index 7bceabf..2edc6b4 100755 --- a/accelerometer.h +++ b/accelerometer.h @@ -4,8 +4,8 @@ // Definitions -#define X_JERK_ACCELERATION 60 -#define Y_JERK_ACCELERATION 60 +#define X_JERK_ACCELERATION 39 +#define Y_JERK_ACCELERATION 38 #define Y_TILT_ACCELERATION 10 diff --git a/common.cpp b/common.cpp index 7353399..feaf101 100755 --- a/common.cpp +++ b/common.cpp @@ -116,7 +116,7 @@ int64_t strtoll(const char *nptr, char **endptr) { float strtof(const char *nptr, char **endptr) { // Initialize variables - float value = 0; + float value; bool negative = false; // Check if value contains a sign @@ -129,28 +129,57 @@ float strtof(const char *nptr, char **endptr) { nptr++; } - // Go through all characters - for(; isdigit(*nptr); nptr++) { + // Get the integer and fractional part of the value + for(bool firstPass = true;; firstPass = false) { - // Set digit in value - value *= 10; - value += *nptr - 0x30; - } - - // Check if value contains a decimal - if(*nptr == '.' && isdigit(nptr[1])) { + // Initialize variables + float *currentValue; + float decimalValue; + + // Check if getting integer part of the value + if(firstPass) + + // Set current value + currentValue = &value; + + // Otherwise + else { + + // Set current value + currentValue = &decimalValue; + + // Check if a value contains a fractional part + if(*nptr == '.' && isdigit(nptr[1])) - // Move to first decimal digit - nptr++; + // Move to first decimal digit + nptr++; + } + + // Clear current value + *currentValue = 0; - // Go through all decimal values - for(uint32_t i = 10; isdigit(*nptr); nptr++) - - // Set decimal digit in value - if(i < UINT32_MAX / 10) { - value += static_cast(*nptr - 0x30) / i; - i *= 10; - } + // Go through all characters + uint8_t numberOfDigits = 0; + for(; isdigit(*nptr); nptr++, numberOfDigits++) { + + // Set digit in current value + *currentValue *= 10; + *currentValue += *nptr - 0x30; + } + + // Check if getting fractional part of the value + if(!firstPass) { + + // Convert current value into a fractional value + for(uint8_t i = 0; i < numberOfDigits; i++) + decimalValue /= 10; + + // Append fractional value to integer value + value += decimalValue; + + // Break + break; + } } // Set end pointer to last valid character @@ -176,3 +205,9 @@ float getValueInRange(float value, float minValue, float maxValue) { // Return value limited by range return min(maxValue, max(minValue, value)); } + +uint32_t minimumOneCeil(float value) { + + // Return ceiling of value that is at least one + return max(1, ceil(value)); +} diff --git a/common.h b/common.h index 594f2d9..2de557d 100755 --- a/common.h +++ b/common.h @@ -81,5 +81,11 @@ Purpose: Returns a value limited by the ranges min and max */ float getValueInRange(float value, float minValue, float maxValue); +/* +Name: Minimum one ceil +Purpose: Returns the ceiling of the value that is at least one +*/ +uint32_t minimumOneCeil(float value); + #endif diff --git a/eeprom.h b/eeprom.h index 6934192..ff1a092 100755 --- a/eeprom.h +++ b/eeprom.h @@ -3,6 +3,10 @@ #define EEPROM_H +// Header files +#include + + // Definitions // EEPROM offsets and lengths @@ -121,27 +125,68 @@ #define EEPROM_SERIAL_NUMBER_OFFSET 0x2EF #define EEPROM_SERIAL_NUMBER_LENGTH 17 -// Default values -#define DEFAULT_BACKLASH_X 0.3 -#define DEFAULT_BACKLASH_Y 0.6 -#define DEFAULT_BACKLASH_SPEED 1500 -#define DEFAULT_BED_ORIENTATION_BACK_RIGHT 0 -#define DEFAULT_BED_ORIENTATION_BACK_LEFT 0 -#define DEFAULT_BED_ORIENTATION_FRONT_LEFT 0 -#define DEFAULT_BED_ORIENTATION_FRONT_RIGHT 0 -#define DEFAULT_BED_OFFSET_BACK_LEFT 0 -#define DEFAULT_BED_OFFSET_BACK_RIGHT 0 -#define DEFAULT_BED_OFFSET_FRONT_RIGHT 0 -#define DEFAULT_BED_OFFSET_FRONT_LEFT 0 -#define DEFAULT_BED_HEIGHT_OFFSET 0 -#define DEFAULT_SPEED_LIMIT_X 1500 -#define DEFAULT_SPEED_LIMIT_Y 1500 -#define DEFAULT_SPEED_LIMIT_Z 60 -#define DEFAULT_SPEED_LIMIT_E_POSITIVE 102 -#define DEFAULT_SPEED_LIMIT_E_NEGATIVE 360 -#define DEFAULT_LAST_RECORDED_X_VALUE 0 -#define DEFAULT_LAST_RECORDED_Y_VALUE 0 -#define DEFAULT_LAST_RECORDED_Z_VALUE 0 +// EEPROM default values +#define EEPROM_BACKLASH_X_DEFAULT 0.3 +#define EEPROM_BACKLASH_Y_DEFAULT 0.6 +#define EEPROM_BACKLASH_SPEED_DEFAULT 1500.0 +#define EEPROM_BED_ORIENTATION_BACK_RIGHT_DEFAULT 0.0 +#define EEPROM_BED_ORIENTATION_BACK_LEFT_DEFAULT 0.0 +#define EEPROM_BED_ORIENTATION_FRONT_LEFT_DEFAULT 0.0 +#define EEPROM_BED_ORIENTATION_FRONT_RIGHT_DEFAULT 0.0 +#define EEPROM_BED_OFFSET_BACK_LEFT_DEFAULT 0.0 +#define EEPROM_BED_OFFSET_BACK_RIGHT_DEFAULT 0.0 +#define EEPROM_BED_OFFSET_FRONT_RIGHT_DEFAULT 0.0 +#define EEPROM_BED_OFFSET_FRONT_LEFT_DEFAULT 0.0 +#define EEPROM_BED_HEIGHT_OFFSET_DEFAULT 0.0 +#define EEPROM_SPEED_LIMIT_X_DEFAULT 1500.0 +#define EEPROM_SPEED_LIMIT_Y_DEFAULT 1500.0 +#define EEPROM_SPEED_LIMIT_Z_DEFAULT 60.0 +#define EEPROM_SPEED_LIMIT_E_POSITIVE_DEFAULT 102.0 +#define EEPROM_SPEED_LIMIT_E_NEGATIVE_DEFAULT 360.0 +#define EEPROM_LAST_RECORDED_X_VALUE_DEFAULT 0.0 +#define EEPROM_LAST_RECORDED_Y_VALUE_DEFAULT 0.0 +#define EEPROM_LAST_RECORDED_Z_VALUE_DEFAULT 0.0 +// EEPROM min and max values +#define EEPROM_BACKLASH_X_MIN 0.0 +#define EEPROM_BACKLASH_X_MAX 2.0 +#define EEPROM_BACKLASH_Y_MIN 0.0 +#define EEPROM_BACKLASH_Y_MAX 2.0 +#define EEPROM_BACKLASH_SPEED_MIN 1.0 +#define EEPROM_BACKLASH_SPEED_MAX 5000.0 +#define EEPROM_BED_ORIENTATION_BACK_RIGHT_MIN -3.0 +#define EEPROM_BED_ORIENTATION_BACK_RIGHT_MAX 3.0 +#define EEPROM_BED_ORIENTATION_BACK_LEFT_MIN -3.0 +#define EEPROM_BED_ORIENTATION_BACK_LEFT_MAX 3.0 +#define EEPROM_BED_ORIENTATION_FRONT_LEFT_MIN -3.0 +#define EEPROM_BED_ORIENTATION_FRONT_LEFT_MAX 3.0 +#define EEPROM_BED_ORIENTATION_FRONT_RIGHT_MIN -3.0 +#define EEPROM_BED_ORIENTATION_FRONT_RIGHT_MAX 3.0 +#define EEPROM_BED_OFFSET_BACK_RIGHT_MIN -FLT_MAX +#define EEPROM_BED_OFFSET_BACK_RIGHT_MAX FLT_MAX +#define EEPROM_BED_OFFSET_BACK_LEFT_MIN -FLT_MAX +#define EEPROM_BED_OFFSET_BACK_LEFT_MAX FLT_MAX +#define EEPROM_BED_OFFSET_FRONT_LEFT_MIN -FLT_MAX +#define EEPROM_BED_OFFSET_FRONT_LEFT_MAX FLT_MAX +#define EEPROM_BED_OFFSET_FRONT_RIGHT_MIN -FLT_MAX +#define EEPROM_BED_OFFSET_FRONT_RIGHT_MAX FLT_MAX +#define EEPROM_BED_HEIGHT_OFFSET_MIN -FLT_MAX +#define EEPROM_BED_HEIGHT_OFFSET_MAX FLT_MAX +#define EEPROM_SPEED_LIMIT_X_MIN 120.0 +#define EEPROM_SPEED_LIMIT_X_MAX 4800.0 +#define EEPROM_SPEED_LIMIT_Y_MIN 120.0 +#define EEPROM_SPEED_LIMIT_Y_MAX 4800.0 +#define EEPROM_SPEED_LIMIT_Z_MIN 30.0 +#define EEPROM_SPEED_LIMIT_Z_MAX 60.0 +#define EEPROM_SPEED_LIMIT_E_POSITIVE_MIN 60.0 +#define EEPROM_SPEED_LIMIT_E_POSITIVE_MAX 600.0 +#define EEPROM_SPEED_LIMIT_E_NEGATIVE_MIN 60.0 +#define EEPROM_SPEED_LIMIT_E_NEGATIVE_MAX 720.0 +#define EEPROM_LAST_RECORDED_X_VALUE_MIN -FLT_MAX +#define EEPROM_LAST_RECORDED_X_VALUE_MAX FLT_MAX +#define EEPROM_LAST_RECORDED_Y_VALUE_MIN -FLT_MAX +#define EEPROM_LAST_RECORDED_Y_VALUE_MAX FLT_MAX +#define EEPROM_LAST_RECORDED_Z_VALUE_MIN -FLT_MAX +#define EEPROM_LAST_RECORDED_Z_VALUE_MAX FLT_MAX #endif diff --git a/fan.cpp b/fan.cpp index ba2b0eb..60861df 100755 --- a/fan.cpp +++ b/fan.cpp @@ -1,3 +1,6 @@ +// 5V 0.2A 25x25x7mm brushless axial DC fan with a PH2.0-2P connector + + // Header files extern "C" { #include @@ -28,7 +31,7 @@ void Fan::initialize() { tc_write_clock_source(&FAN_TIMER, TC_CLKSEL_DIV64_gc); // Turn off fan - setSpeed(0); + setSpeed(FAN_MIN_SPEED); } void Fan::setSpeed(uint8_t speed) { @@ -40,5 +43,5 @@ void Fan::setSpeed(uint8_t speed) { nvm_eeprom_read_buffer(EEPROM_FAN_SCALE_OFFSET, &fanScale, EEPROM_FAN_SCALE_LENGTH); // Set speed - tc_write_cc(&FAN_TIMER, FAN_CHANNEL, !speed ? 0 : (speed * fanScale + fanOffset) * FAN_TIMER_PERIOD / FAN_MAX_SPEED); + tc_write_cc(&FAN_TIMER, FAN_CHANNEL, speed <= FAN_MIN_SPEED ? 0 : (getValueInRange(speed, FAN_MIN_SPEED, FAN_MAX_SPEED) * fanScale + fanOffset) * FAN_TIMER_PERIOD / FAN_MAX_SPEED); } diff --git a/fan.h b/fan.h index afde681..c13479e 100755 --- a/fan.h +++ b/fan.h @@ -6,6 +6,7 @@ // Definitions #define FAN_TIMER TCE0 #define FAN_TIMER_PERIOD 0x208D +#define FAN_MIN_SPEED 0 #define FAN_MAX_SPEED 255 diff --git a/iMe 1900000010.hex b/iMe 1900000010.hex deleted file mode 100755 index c8e8d4a..0000000 Binary files a/iMe 1900000010.hex and /dev/null differ diff --git a/iMe 1900000012.hex b/iMe 1900000012.hex new file mode 100755 index 0000000..b7ce28c Binary files /dev/null and b/iMe 1900000012.hex differ diff --git a/iMe.cppproj b/iMe.cppproj index 14f7547..22cf30c 100755 --- a/iMe.cppproj +++ b/iMe.cppproj @@ -279,10 +279,11 @@ True - C:\Users\donovan6000\Desktop\iMe + + all clean - C:\Users\donovan6000\Desktop\iMe\Makefile + Makefile diff --git a/led.cpp b/led.cpp index aa7fe0d..e0c6686 100755 --- a/led.cpp +++ b/led.cpp @@ -4,6 +4,7 @@ extern "C" { } #include "led.h" #include "fan.h" +#include "common.h" // Definitions @@ -26,5 +27,5 @@ void Led::initialize() { void Led::setBrightness(uint8_t brightness) { // Set brightness - tc_write_cc(&LED_TIMER, LED_CHANNEL, static_cast(brightness) * LED_TIMER_PERIOD / LED_MAX_BRIGHTNESS); + tc_write_cc(&LED_TIMER, LED_CHANNEL, getValueInRange(brightness, LED_MIN_BRIGHTNESS, LED_MAX_BRIGHTNESS) * LED_TIMER_PERIOD / LED_MAX_BRIGHTNESS); } diff --git a/led.h b/led.h index 44415f4..5afa9b0 100755 --- a/led.h +++ b/led.h @@ -4,6 +4,7 @@ // Definitions +#define LED_MIN_BRIGHTNESS 0 #define LED_MAX_BRIGHTNESS 100 #define LED_CHANNEL_CAPTURE_COMPARE TC_CCDEN diff --git a/main.cpp b/main.cpp index 7b6c498..3e9477e 100755 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,8 @@ -// ATxmega32C4 http://www.atmel.com/Images/Atmel-8493-8-and-32-bit-AVR-XMEGA-Microcontrollers-ATxmega16C4-ATxmega32C4_Datasheet.pdf +// ATxmega32C4 microcontroller http://www.atmel.com/Images/Atmel-8493-8-and-32-bit-AVR-XMEGA-Microcontrollers-ATxmega16C4-ATxmega32C4_Datasheet.pdf +// 5V 4A 2.1mmx5.5mm DC power supply +// USB type B connection + + // Header files extern "C" { #include @@ -21,6 +25,13 @@ extern "C" { // Unknown pin (Connected to transistors above the microcontroller. Maybe related to detecting if USB is connected) #define UNKNOWN_PIN IOPORT_CREATE_PIN(PORTA, 1) +// Unused pins (None of them are connected to anything, so they could be used to easily connect additional hardware to the printer) +#define UNUSED_PIN_1 IOPORT_CREATE_PIN(PORTA, 6) +#define UNUSED_PIN_2 IOPORT_CREATE_PIN(PORTB, 0) +#define UNUSED_PIN_3 IOPORT_CREATE_PIN(PORTE, 0) +#define UNUSED_PIN_4 IOPORT_CREATE_PIN(PORTR, 0) +#define UNUSED_PIN_5 IOPORT_CREATE_PIN(PORTR, 1) + // Global variables char serialNumber[EEPROM_SERIAL_NUMBER_LENGTH]; @@ -103,6 +114,18 @@ int main() { ioport_set_pin_dir(UNKNOWN_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(UNKNOWN_PIN, IOPORT_PIN_LEVEL_LOW); + // Configure unused pins + ioport_set_pin_dir(UNUSED_PIN_1, IOPORT_DIR_INPUT); + ioport_set_pin_mode(UNUSED_PIN_1, IOPORT_MODE_PULLUP); + ioport_set_pin_dir(UNUSED_PIN_2, IOPORT_DIR_INPUT); + ioport_set_pin_mode(UNUSED_PIN_2, IOPORT_MODE_PULLUP); + ioport_set_pin_dir(UNUSED_PIN_3, IOPORT_DIR_INPUT); + ioport_set_pin_mode(UNUSED_PIN_3, IOPORT_MODE_PULLUP); + ioport_set_pin_dir(UNUSED_PIN_4, IOPORT_DIR_INPUT); + ioport_set_pin_mode(UNUSED_PIN_4, IOPORT_MODE_PULLUP); + ioport_set_pin_dir(UNUSED_PIN_5, IOPORT_DIR_INPUT); + ioport_set_pin_mode(UNUSED_PIN_5, IOPORT_MODE_PULLUP); + // Configure send wait interrupt tc_set_overflow_interrupt_callback(&WAIT_TIMER, []() -> void { @@ -280,26 +303,18 @@ int main() { case 106: case 107: - // Check if speed is valid - int32_t speed; - speed = requests[currentProcessingRequest].valueM == 107 || !(requests[currentProcessingRequest].commandParameters & PARAMETER_S_OFFSET) ? 0 : requests[currentProcessingRequest].valueS; - if(speed >= 0) { - - // Set fan's speed - fan.setSpeed(min(FAN_MAX_SPEED, speed)); - - // Set response to confirmation - strcpy(responseBuffer, "ok"); - } + // Set fan's speed + fan.setSpeed(requests[currentProcessingRequest].valueM == 106 && requests[currentProcessingRequest].commandParameters & PARAMETER_S_OFFSET ? requests[currentProcessingRequest].valueS : FAN_MIN_SPEED); + + // Set response to confirmation + strcpy(responseBuffer, "ok"); break; // M114 case 114: - // Set response to confirmation + // Set response to confirmation and motors current X strcpy(responseBuffer, "ok\nX:"); - - // Append motors current X to response ftoa(motors.currentValues[X], numberBuffer); strcat(responseBuffer, numberBuffer); @@ -331,7 +346,7 @@ int main() { // Otherwise else { - // Put device details into response + // Set response to device and firmware details strcpy(responseBuffer, "ok\nPROTOCOL:RepRap FIRMWARE_NAME:" TOSTRING(FIRMWARE_NAME) " FIRMWARE_VERSION:" TOSTRING(FIRMWARE_VERSION) " MACHINE_TYPE:Micro_3D SERIAL_NUMBER:"); strcat(responseBuffer, serialNumber); } @@ -362,7 +377,7 @@ int main() { case 420: // Set LED's brightness - led.setBrightness(min(LED_MAX_BRIGHTNESS, requests[currentProcessingRequest].commandParameters & PARAMETER_T_OFFSET ? requests[currentProcessingRequest].valueT : LED_MAX_BRIGHTNESS)); + led.setBrightness(requests[currentProcessingRequest].commandParameters & PARAMETER_T_OFFSET ? requests[currentProcessingRequest].valueT : LED_MAX_BRIGHTNESS); // Set response to confirmation strcpy(responseBuffer, "ok"); @@ -664,7 +679,7 @@ int main() { disableSendingWaitResponses(); // Reset all peripherals - fan.setSpeed(0); + fan.setSpeed(FAN_MIN_SPEED); heater.reset(); led.setBrightness(LED_MAX_BRIGHTNESS); motors.reset(); diff --git a/motors.cpp b/motors.cpp index b43ae84..7c2806c 100755 --- a/motors.cpp +++ b/motors.cpp @@ -1,4 +1,7 @@ -// DRV8834 http://www.ti.com/lit/ds/slvsb19d/slvsb19d.pdf +// DRV8834 motor driver http://www.ti.com/lit/ds/slvsb19d/slvsb19d.pdf +// 24BYJ-48 5V 1/64 ratio stepper motor used in 4 wire bipolar mode, so just ignore the common wire (usually red) if it has one http://robocraft.ru/files/datasheet/28BYJ-48.pdf + + // Header files extern "C" { #include @@ -12,14 +15,18 @@ extern "C" { // Definitions -#define SEGMENT_LENGTH 2 +#define SEGMENT_LENGTH 2.0 +#define HOMING_FEED_RATE 1500.0 +#define CALIBRATING_Z_FEED_RATE 17.0 +#define BED_ORIENTATION_VERSION 1 +//#define REGULATE_EXTRUDER_CURRENT // Bed dimensions -#define BED_CENTER_X 54 -#define BED_CENTER_Y 50 -#define BED_CENTER_X_DISTANCE_FROM_HOMING_CORNER 55 -#define BED_CENTER_Y_DISTANCE_FROM_HOMING_CORNER 55 -#define CORNER_DISTANCE_FROM_CENTER 45 +#define BED_CENTER_X 54.0 +#define BED_CENTER_Y 50.0 +#define BED_CENTER_X_DISTANCE_FROM_HOMING_CORNER 55.0 +#define BED_CENTER_Y_DISTANCE_FROM_HOMING_CORNER 55.0 +#define BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER 45.0 #define BED_LOW_MAX_X 106.0 #define BED_LOW_MIN_X -2.0 #define BED_LOW_MAX_Y 105.0 @@ -40,15 +47,15 @@ extern "C" { #define BED_HIGH_MIN_Z BED_MEDIUM_MAX_Z // Motors settings -#define MICROSTEPS_PER_STEP 32 +#define MICROSTEPS_PER_STEP 8 #define MOTORS_ENABLE_PIN IOPORT_CREATE_PIN(PORTB, 3) #define MOTORS_STEP_CONTROL_PIN IOPORT_CREATE_PIN(PORTB, 2) -#define MOTORS_STEP_TIMER TCC0 -#define MOTORS_STEP_TIMER_PERIOD 0x400 #define MOTORS_CURRENT_SENSE_RESISTANCE 0.1 -#define MOTORS_CURRENT_TO_VOLTAGE_SCALAR (5 * MOTORS_CURRENT_SENSE_RESISTANCE) +#define MOTORS_CURRENT_TO_VOLTAGE_SCALAR (5.0 * MOTORS_CURRENT_SENSE_RESISTANCE) #define MOTORS_SAVE_TIMER FAN_TIMER #define MOTORS_SAVE_TIMER_PERIOD FAN_TIMER_PERIOD +#define MOTORS_STEP_TIMER TCC0 +#define MOTORS_STEP_TIMER_PERIOD 0x400 // Motor X settings #define MOTOR_X_DIRECTION_PIN IOPORT_CREATE_PIN(PORTC, 2) @@ -59,8 +66,6 @@ extern "C" { #define MOTOR_X_CURRENT_IDLE 0.692018779 #define MOTOR_X_CURRENT_ACTIVE 0.723004695 #define MOTOR_X_STEPS_PER_MM 19.3067875 -#define MOTOR_X_MAX_FEEDRATE 4800 -#define MOTOR_X_MIN_FEEDRATE 120 // Motor Y settings #define MOTOR_Y_DIRECTION_PIN IOPORT_CREATE_PIN(PORTD, 5) @@ -71,8 +76,6 @@ extern "C" { #define MOTOR_Y_CURRENT_IDLE 0.692018779 #define MOTOR_Y_CURRENT_ACTIVE 0.82629108 #define MOTOR_Y_STEPS_PER_MM 18.00885 -#define MOTOR_Y_MAX_FEEDRATE 4800 -#define MOTOR_Y_MIN_FEEDRATE 120 // Motor Z settings #define MOTOR_Z_DIRECTION_PIN IOPORT_CREATE_PIN(PORTD, 4) @@ -83,8 +86,6 @@ extern "C" { #define MOTOR_Z_CURRENT_IDLE 0.196244131 #define MOTOR_Z_CURRENT_ACTIVE 0.650704225 #define MOTOR_Z_STEPS_PER_MM 646.3295 -#define MOTOR_Z_MAX_FEEDRATE 60 -#define MOTOR_Z_MIN_FEEDRATE 30 // Motor E settings #define MOTOR_E_DIRECTION_PIN IOPORT_CREATE_PIN(PORTC, 3) @@ -100,9 +101,6 @@ extern "C" { #define MOTOR_E_VREF_CHANNEL_CAPTURE_COMPARE TC_CCAEN #define MOTOR_E_CURRENT_IDLE 0.299530516 #define MOTOR_E_STEPS_PER_MM 128.451375 -#define MOTOR_E_MAX_FEEDRATE_EXTRUSION 600 -#define MOTOR_E_MAX_FEEDRATE_RETRACTION 720 -#define MOTOR_E_MIN_FEEDRATE 60 // Pin states #define MOTORS_ON IOPORT_PIN_LEVEL_LOW @@ -131,6 +129,95 @@ uint32_t motorsNumberOfSteps[NUMBER_OF_MOTORS]; // Supporting function implementation +void updateMotorsStepTimerInterrupts() { + + // Clear motor X, Y, Z, and E step pins + ioport_set_pin_level(MOTOR_X_STEP_PIN, IOPORT_PIN_LEVEL_LOW); + ioport_set_pin_level(MOTOR_Y_STEP_PIN, IOPORT_PIN_LEVEL_LOW); + ioport_set_pin_level(MOTOR_Z_STEP_PIN, IOPORT_PIN_LEVEL_LOW); + ioport_set_pin_level(MOTOR_E_STEP_PIN, IOPORT_PIN_LEVEL_LOW); + + // Set motor X step interrupt to a higher priority if enabled + if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCAINTLVL_gm) + tc_set_cca_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_HI); + + // Set motor Y step interrupt to a higher priority if enabled + if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCBINTLVL_gm) + tc_set_ccb_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_HI); + + // Set motor Z step interrupt to a higher priority if enabled + if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCCINTLVL_gm) + tc_set_ccc_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_HI); + + // Set motor E step interrupt to a higher priority if enabled + if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCDINTLVL_gm) + tc_set_ccd_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_HI); +} + +void motorsStepTimerInterrupt(AXES motor) { + + // Get set motor step interrupt level and motor step pin + void (*setMotorStepInterruptLevel)(volatile void *tc, TC_INT_LEVEL_t level); + ioport_pin_t motorStepPin; + switch(motor) { + + case X: + setMotorStepInterruptLevel = tc_set_cca_interrupt_level; + motorStepPin = MOTOR_X_STEP_PIN; + break; + + case Y: + setMotorStepInterruptLevel = tc_set_ccb_interrupt_level; + motorStepPin = MOTOR_Y_STEP_PIN; + break; + + case Z: + setMotorStepInterruptLevel = tc_set_ccc_interrupt_level; + motorStepPin = MOTOR_Z_STEP_PIN; + break; + + default: + setMotorStepInterruptLevel = tc_set_ccd_interrupt_level; + motorStepPin = MOTOR_E_STEP_PIN; + } + + // Set motor step interrupt to a lower priority + (*setMotorStepInterruptLevel)(&MOTORS_STEP_TIMER, TC_INT_LVL_LO); + + // Check if time to skip a motor delay + if(motorsDelaySkips[motor] > 1 && ++motorsDelaySkipsCounter[motor] >= motorsDelaySkips[motor]) { + + // Clear motor skip delay counter + motorsDelaySkipsCounter[motor] = 0; + + // Return + return; + } + + // Check if time to increment motor step + if(++motorsStepDelayCounter[motor] >= motorsStepDelay[motor]) { + + // Check if moving another step + if(motorsNumberOfSteps[motor]) { + + // Decrement step counter + motorsNumberOfSteps[motor]--; + + // Set motor step pin + ioport_set_pin_level(motorStepPin, IOPORT_PIN_LEVEL_HIGH); + } + + // Check if done moving motor + if(!motorsNumberOfSteps[motor]) + + // Disable motor step interrupt + (*setMotorStepInterruptLevel)(&MOTORS_STEP_TIMER, TC_INT_LVL_OFF); + + // Clear motor step counter + motorsStepDelayCounter[motor] = 0; + } +} + Vector calculatePlaneNormalVector(const Vector &v1, const Vector &v2, const Vector &v3) { // Initialize variables @@ -193,6 +280,25 @@ bool isPointInTriangle(const Vector &pt, const Vector &v1, const Vector &v2, con return flag == flag2 && flag2 == flag3; } +void startMotorsStepTimer() { + + // Update motors step timer interrupts + updateMotorsStepTimerInterrupts(); + + // Restart motors step timer + tc_restart(&MOTORS_STEP_TIMER); + tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_DIV1_gc); +} + +void stopMotorsStepTimer() { + + // Stop motors step timer + tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_OFF_gc); + + // Update motors step timer interrupts + updateMotorsStepTimerInterrupts(); +} + float Motors::getHeightAdjustmentRequired(float x, float y) { // Initialize variables @@ -237,84 +343,20 @@ float Motors::getHeightAdjustmentRequired(float x, float y) { return getZFromXYAndPlane(point, frontPlane); } -void stepTimerInterrupt(AXES motor) { - - // Get set motor step interrupt level and motor step pin - void (*setMotorStepInterruptLevel)(volatile void *tc, TC_INT_LEVEL_t level); - ioport_pin_t motorStepPin; - switch(motor) { - - case X: - setMotorStepInterruptLevel = tc_set_cca_interrupt_level; - motorStepPin = MOTOR_X_STEP_PIN; - break; - - case Y: - setMotorStepInterruptLevel = tc_set_ccb_interrupt_level; - motorStepPin = MOTOR_Y_STEP_PIN; - break; - - case Z: - setMotorStepInterruptLevel = tc_set_ccc_interrupt_level; - motorStepPin = MOTOR_Z_STEP_PIN; - break; - - default: - setMotorStepInterruptLevel = tc_set_ccd_interrupt_level; - motorStepPin = MOTOR_E_STEP_PIN; - } - - // Set motor step interrupt to a lower priority - (*setMotorStepInterruptLevel)(&MOTORS_STEP_TIMER, TC_INT_LVL_LO); - - // Check if time to skip a motor delay - if(motorsDelaySkips[motor] > 1 && ++motorsDelaySkipsCounter[motor] >= motorsDelaySkips[motor]) { - - // Clear motor skip delay counter - motorsDelaySkipsCounter[motor] = 0; - - // Return - return; - } - - // Check if time to increment motor step - if(++motorsStepDelayCounter[motor] >= motorsStepDelay[motor]) { - - // Check if moving another step - if(motorsNumberOfSteps[motor]--) - - // Set motor step pin - ioport_set_pin_level(motorStepPin, IOPORT_PIN_LEVEL_HIGH); - - // Otherwise - else { - - // Reset number of steps - motorsNumberOfSteps[motor] = 0; - - // Disable motor step interrupt - (*setMotorStepInterruptLevel)(&MOTORS_STEP_TIMER, TC_INT_LVL_OFF); - } - - // Clear motor step counter - motorsStepDelayCounter[motor] = 0; - } -} - void Motors::initialize() { // Set self self = this; // Restore state - changeState(); + restoreState(); // Set mode mode = ABSOLUTE; // Set initial values currentValues[E] = 0; - currentValues[F] = MOTOR_X_MAX_FEEDRATE; + currentValues[F] = EEPROM_SPEED_LIMIT_X_MAX; // Configure motors enable ioport_set_pin_dir(MOTORS_ENABLE_PIN, IOPORT_DIR_OUTPUT); @@ -385,58 +427,42 @@ void Motors::initialize() { tc_write_period(&MOTORS_STEP_TIMER, MOTORS_STEP_TIMER_PERIOD); tc_set_overflow_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_MED); + // Update motors step timer interrupts + updateMotorsStepTimerInterrupts(); + // Motors step timer overflow callback tc_set_overflow_interrupt_callback(&MOTORS_STEP_TIMER, []() -> void { - - // Clear motor X, Y, Z, and E step pins - ioport_set_pin_level(MOTOR_X_STEP_PIN, IOPORT_PIN_LEVEL_LOW); - ioport_set_pin_level(MOTOR_Y_STEP_PIN, IOPORT_PIN_LEVEL_LOW); - ioport_set_pin_level(MOTOR_Z_STEP_PIN, IOPORT_PIN_LEVEL_LOW); - ioport_set_pin_level(MOTOR_E_STEP_PIN, IOPORT_PIN_LEVEL_LOW); - - // Set motor X step interrupt to a higher priority if enabled - if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCAINTLVL_gm) - tc_set_cca_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_HI); - - // Set motor Y step interrupt to a higher priority if enabled - if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCBINTLVL_gm) - tc_set_ccb_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_HI); - - // Set motor Z step interrupt to a higher priority if enabled - if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCCINTLVL_gm) - tc_set_ccc_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_HI); - // Set motor E step interrupt to a higher priority if enabled - if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCDINTLVL_gm) - tc_set_ccd_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_HI); + // Update motors step timer interrupts + updateMotorsStepTimerInterrupts(); }); // Motor X step timer callback tc_set_cca_interrupt_callback(&MOTORS_STEP_TIMER, []() -> void { - // Run step timer interrupt - stepTimerInterrupt(X); + // Run motors step timer interrupt + motorsStepTimerInterrupt(X); }); // Motor Y step timer callback tc_set_ccb_interrupt_callback(&MOTORS_STEP_TIMER, []() -> void { - // Run step timer interrupt - stepTimerInterrupt(Y); + // Run motors step timer interrupt + motorsStepTimerInterrupt(Y); }); // Motor Z step timer callback tc_set_ccc_interrupt_callback(&MOTORS_STEP_TIMER, []() -> void { - // Run step timer interrupt - stepTimerInterrupt(Z); + // Run motors step timer interrupt + motorsStepTimerInterrupt(Z); }); // Motor E step timer callback tc_set_ccd_interrupt_callback(&MOTORS_STEP_TIMER, []() -> void { - // Run step timer interrupt - stepTimerInterrupt(E); + // Run motors step timer interrupt + motorsStepTimerInterrupt(E); }); // Set ADC controller to use unsigned, 12-bit, Vref refrence, and manual trigger @@ -453,10 +479,10 @@ void Motors::initialize() { accelerometer.initialize(); // Set vectors - backRightVector.initialize(BED_CENTER_X + CORNER_DISTANCE_FROM_CENTER, BED_CENTER_Y + CORNER_DISTANCE_FROM_CENTER); - backLeftVector.initialize(BED_CENTER_X - CORNER_DISTANCE_FROM_CENTER, BED_CENTER_Y + CORNER_DISTANCE_FROM_CENTER); - frontLeftVector.initialize(BED_CENTER_X - CORNER_DISTANCE_FROM_CENTER, BED_CENTER_Y - CORNER_DISTANCE_FROM_CENTER); - frontRightVector.initialize(BED_CENTER_X + CORNER_DISTANCE_FROM_CENTER, BED_CENTER_Y - CORNER_DISTANCE_FROM_CENTER); + backRightVector.initialize(BED_CENTER_X + BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_Y + BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER); + backLeftVector.initialize(BED_CENTER_X - BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_Y + BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER); + frontLeftVector.initialize(BED_CENTER_X - BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_Y - BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER); + frontRightVector.initialize(BED_CENTER_X + BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_Y - BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER); centerVector.initialize(BED_CENTER_X, BED_CENTER_Y); // Update bed changes @@ -468,18 +494,32 @@ void Motors::initialize() { // Initialize variables static uint8_t motorsSaveTimerCounter = 0; static AXES currentSaveMotor = Z; + static AXES_PARAMETER currentSaveParameter = VALUE; - // Check if one third of a second has passed - if(++motorsSaveTimerCounter >= sysclk_get_cpu_hz() / MOTORS_SAVE_TIMER_PERIOD / 64 / 3) { + // Check if one fifth of a second has passed + if(++motorsSaveTimerCounter >= sysclk_get_cpu_hz() / MOTORS_SAVE_TIMER_PERIOD / 64 / 5) { // Reset motors save timer counter motorsSaveTimerCounter = 0; + + // Check if all parameters for the current motor have been saved + if(currentSaveParameter == VALUE) { + + // Reset current save parameter + currentSaveParameter = DIRECTION; - // Set current save motor to next motor - currentSaveMotor = currentSaveMotor == Z ? X : static_cast(currentSaveMotor + 1); + // Set current save motor to next motor + currentSaveMotor = currentSaveMotor == Z ? X : static_cast(currentSaveMotor + 1); + } + + // Otherwise + else + + // Set current save parameter to next parameter + currentSaveParameter = static_cast(currentSaveParameter + 1); - // Save motor's state - self->changeState(true, currentSaveMotor); + // Save current motor's state + self->saveState(currentSaveMotor, currentSaveParameter); } }); tc_set_overflow_interrupt_level(&MOTORS_SAVE_TIMER, TC_INT_LVL_LO); @@ -506,7 +546,7 @@ void Motors::move(const Gcode &gcode, uint8_t tasks) { currentValues[F] = gcode.valueF; // Initialize variables - uint32_t slowestTime = 0; + float slowestTime = 0; uint32_t motorMoves[NUMBER_OF_MOTORS] = {}; BACKLASH_DIRECTION backlashDirectionX = NONE, backlashDirectionY = NONE; bool validValues[3]; @@ -581,8 +621,8 @@ void Motors::move(const Gcode &gcode, uint8_t tasks) { stepsPerMm = MOTOR_X_STEPS_PER_MM; ioport_set_pin_level(MOTOR_X_DIRECTION_PIN, lowerNewValue ? DIRECTION_LEFT : DIRECTION_RIGHT); nvm_eeprom_read_buffer(EEPROM_SPEED_LIMIT_X_OFFSET, &speedLimit, EEPROM_SPEED_LIMIT_X_LENGTH); - maxFeedRate = MOTOR_X_MAX_FEEDRATE; - minFeedRate = MOTOR_X_MIN_FEEDRATE; + maxFeedRate = EEPROM_SPEED_LIMIT_X_MAX; + minFeedRate = EEPROM_SPEED_LIMIT_X_MIN; break; case Y: @@ -596,8 +636,8 @@ void Motors::move(const Gcode &gcode, uint8_t tasks) { stepsPerMm = MOTOR_Y_STEPS_PER_MM; ioport_set_pin_level(MOTOR_Y_DIRECTION_PIN, lowerNewValue ? DIRECTION_FORWARD : DIRECTION_BACKWARD); nvm_eeprom_read_buffer(EEPROM_SPEED_LIMIT_Y_OFFSET, &speedLimit, EEPROM_SPEED_LIMIT_Y_LENGTH); - maxFeedRate = MOTOR_Y_MAX_FEEDRATE; - minFeedRate = MOTOR_Y_MIN_FEEDRATE; + maxFeedRate = EEPROM_SPEED_LIMIT_Y_MAX; + minFeedRate = EEPROM_SPEED_LIMIT_Y_MIN; break; case Z: @@ -605,8 +645,8 @@ void Motors::move(const Gcode &gcode, uint8_t tasks) { stepsPerMm = MOTOR_Z_STEPS_PER_MM; ioport_set_pin_level(MOTOR_Z_DIRECTION_PIN, lowerNewValue ? DIRECTION_DOWN : DIRECTION_UP); nvm_eeprom_read_buffer(EEPROM_SPEED_LIMIT_Z_OFFSET, &speedLimit, EEPROM_SPEED_LIMIT_Z_LENGTH); - maxFeedRate = MOTOR_Z_MAX_FEEDRATE; - minFeedRate = MOTOR_Z_MIN_FEEDRATE; + maxFeedRate = EEPROM_SPEED_LIMIT_Z_MAX; + minFeedRate = EEPROM_SPEED_LIMIT_Z_MIN; break; default: @@ -614,14 +654,15 @@ void Motors::move(const Gcode &gcode, uint8_t tasks) { if(lowerNewValue) { ioport_set_pin_level(MOTOR_E_DIRECTION_PIN, DIRECTION_RETRACT); nvm_eeprom_read_buffer(EEPROM_SPEED_LIMIT_E_NEGATIVE_OFFSET, &speedLimit, EEPROM_SPEED_LIMIT_E_NEGATIVE_LENGTH); - maxFeedRate = MOTOR_E_MAX_FEEDRATE_RETRACTION; + maxFeedRate = EEPROM_SPEED_LIMIT_E_NEGATIVE_MAX; + minFeedRate = EEPROM_SPEED_LIMIT_E_NEGATIVE_MIN; } else { ioport_set_pin_level(MOTOR_E_DIRECTION_PIN, DIRECTION_EXTRUDE); nvm_eeprom_read_buffer(EEPROM_SPEED_LIMIT_E_POSITIVE_OFFSET, &speedLimit, EEPROM_SPEED_LIMIT_E_POSITIVE_LENGTH); - maxFeedRate = MOTOR_E_MAX_FEEDRATE_EXTRUSION; + maxFeedRate = EEPROM_SPEED_LIMIT_E_POSITIVE_MAX; + minFeedRate = EEPROM_SPEED_LIMIT_E_POSITIVE_MIN; } - minFeedRate = MOTOR_E_MIN_FEEDRATE; // Clear saves valid value savesValidValue = false; @@ -646,11 +687,8 @@ void Motors::move(const Gcode &gcode, uint8_t tasks) { // Enforce min/max feed rates motorFeedRate = getValueInRange(motorFeedRate, minFeedRate, maxFeedRate); - // Set motor total time - uint32_t motorTotalTime = round(distanceTraveled / motorFeedRate * 60 * sysclk_get_cpu_hz() / MOTORS_STEP_TIMER_PERIOD); - // Set slowest time - slowestTime = max(motorTotalTime, slowestTime); + slowestTime = max(distanceTraveled / motorFeedRate * 60, slowestTime); } } } @@ -712,13 +750,13 @@ void Motors::move(const Gcode &gcode, uint8_t tasks) { // Set motor step delay motorsStepDelayCounter[i] = 0; - motorsStepDelay[i] = round(static_cast(slowestTime) / motorsNumberOfSteps[i]); + motorsStepDelay[i] = minimumOneCeil(slowestTime * sysclk_get_cpu_hz() / MOTORS_STEP_TIMER_PERIOD / motorsNumberOfSteps[i]); // Set motor total rounded time motorsTotalRoundedTime[i] = motorsNumberOfSteps[i] * motorsStepDelay[i]; // Set slowest rounded time - slowestRoundedTime = max(slowestRoundedTime, motorsTotalRoundedTime[i]); + slowestRoundedTime = max(motorsTotalRoundedTime[i], slowestRoundedTime); // Enable motor step interrupt and set motor Vref to active void (*setMotorStepInterruptLevel)(volatile void *tc, TC_INT_LEVEL_t level); @@ -751,65 +789,72 @@ void Motors::move(const Gcode &gcode, uint8_t tasks) { } (*setMotorStepInterruptLevel)(&MOTORS_STEP_TIMER, TC_INT_LVL_LO); } - + // Go through all motors for(uint8_t i = 0; i < NUMBER_OF_MOTORS; i++) { - + // Set motor delay skips motorsDelaySkipsCounter[i] = 0; motorsDelaySkips[i] = slowestRoundedTime != motorsTotalRoundedTime[i] ? round(static_cast(motorsTotalRoundedTime[i]) / (slowestRoundedTime - motorsTotalRoundedTime[i])) : 0; - } + } // Turn on motors turnOn(); - // Check if motor E moves - if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCDINTLVL_gm) + // Check if regulating extruder current + #ifdef REGULATE_EXTRUDER_CURRENT + + // Check if motor E moves + if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCDINTLVL_gm) - // Wait enough time for motor E voltage to stabilize - delay_us(500); + // Wait enough time for motor E voltage to stabilize + delay_us(500); + #endif // Start motors step timer - tc_write_count(&MOTORS_STEP_TIMER, MOTORS_STEP_TIMER_PERIOD - 1); - tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_DIV1_gc); + startMotorsStepTimer(); // Wait until all motors step interrupts have stopped or an emergency stop occurs while(MOTORS_STEP_TIMER.INTCTRLB & (TC0_CCAINTLVL_gm | TC0_CCBINTLVL_gm | TC0_CCCINTLVL_gm | TC0_CCDINTLVL_gm) && !emergencyStopOccured) { + + // Check if regulating extruder current + #ifdef REGULATE_EXTRUDER_CURRENT - // Check if motor E is moving - if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCDINTLVL_gm) { + // Check if motor E is moving + if(MOTORS_STEP_TIMER.INTCTRLB & TC0_CCDINTLVL_gm) { - // Prevent updating temperature - tc_set_overflow_interrupt_level(&TEMPERATURE_TIMER, TC_INT_LVL_OFF); + // Prevent updating temperature + tc_set_overflow_interrupt_level(&TEMPERATURE_TIMER, TC_INT_LVL_OFF); - // Read actual motor E voltages - adc_write_configuration(&MOTOR_E_CURRENT_SENSE_ADC, ¤tSenseAdcController); - adcch_write_configuration(&MOTOR_E_CURRENT_SENSE_ADC, MOTOR_E_CURRENT_SENSE_ADC_CHANNEL, ¤tSenseAdcChannel); + // Read actual motor E voltages + adc_write_configuration(&MOTOR_E_CURRENT_SENSE_ADC, ¤tSenseAdcController); + adcch_write_configuration(&MOTOR_E_CURRENT_SENSE_ADC, MOTOR_E_CURRENT_SENSE_ADC_CHANNEL, ¤tSenseAdcChannel); - uint32_t value = 0; - for(uint8_t i = 0; i < MOTOR_E_CURRENT_SENSE_ADC_SAMPLE_SIZE; i++) { - adc_start_conversion(&MOTOR_E_CURRENT_SENSE_ADC, MOTOR_E_CURRENT_SENSE_ADC_CHANNEL); - adc_wait_for_interrupt_flag(&MOTOR_E_CURRENT_SENSE_ADC, MOTOR_E_CURRENT_SENSE_ADC_CHANNEL); - value += adc_get_unsigned_result(&MOTOR_E_CURRENT_SENSE_ADC, MOTOR_E_CURRENT_SENSE_ADC_CHANNEL); - } + uint32_t value = 0; + for(uint8_t i = 0; i < MOTOR_E_CURRENT_SENSE_ADC_SAMPLE_SIZE; i++) { + adc_start_conversion(&MOTOR_E_CURRENT_SENSE_ADC, MOTOR_E_CURRENT_SENSE_ADC_CHANNEL); + adc_wait_for_interrupt_flag(&MOTOR_E_CURRENT_SENSE_ADC, MOTOR_E_CURRENT_SENSE_ADC_CHANNEL); + value += adc_get_unsigned_result(&MOTOR_E_CURRENT_SENSE_ADC, MOTOR_E_CURRENT_SENSE_ADC_CHANNEL); + } - // Allow updating temperature - tc_set_overflow_interrupt_level(&TEMPERATURE_TIMER, TC_INT_LVL_LO); + // Allow updating temperature + tc_set_overflow_interrupt_level(&TEMPERATURE_TIMER, TC_INT_LVL_LO); - // Set average actual motor E voltage - value /= MOTOR_E_CURRENT_SENSE_ADC_SAMPLE_SIZE; - float actualVoltage = ADC_VREF_VOLTAGE / UINT12_MAX * value; + // Set average actual motor E voltage + value /= MOTOR_E_CURRENT_SENSE_ADC_SAMPLE_SIZE; + float actualVoltage = ADC_VREF_VOLTAGE / UINT12_MAX * value; - // Get ideal motor E voltage - float idealVoltage = static_cast(tc_read_cc(&MOTORS_VREF_TIMER, MOTOR_E_VREF_CHANNEL)) / MOTORS_VREF_TIMER_PERIOD * MICROCONTROLLER_VOLTAGE; + // Get ideal motor E voltage + float idealVoltage = static_cast(tc_read_cc(&MOTORS_VREF_TIMER, MOTOR_E_VREF_CHANNEL)) / MOTORS_VREF_TIMER_PERIOD * MICROCONTROLLER_VOLTAGE; - // Adjust motor E voltage to maintain a constant motor current - tc_write_cc(&MOTORS_VREF_TIMER, MOTOR_E_VREF_CHANNEL, round((motorVoltageE + idealVoltage - actualVoltage) / MICROCONTROLLER_VOLTAGE * MOTORS_VREF_TIMER_PERIOD)); - } + // Adjust motor E voltage to maintain a constant motor current + tc_write_cc(&MOTORS_VREF_TIMER, MOTOR_E_VREF_CHANNEL, round((motorVoltageE + idealVoltage - actualVoltage) / MICROCONTROLLER_VOLTAGE * MOTORS_VREF_TIMER_PERIOD)); + } + #endif } // Stop motors step timer - tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_OFF_gc); + stopMotorsStepTimer(); // Set motors Vref to idle tc_write_cc(&MOTORS_VREF_TIMER, MOTOR_X_VREF_CHANNEL, round(MOTOR_X_CURRENT_IDLE * MOTORS_CURRENT_TO_VOLTAGE_SCALAR / MICROCONTROLLER_VOLTAGE * MOTORS_VREF_TIMER_PERIOD)); @@ -856,7 +901,7 @@ void Motors::moveToHeight(float height) { Gcode gcode; gcode.valueG = 0; gcode.valueZ = height; - gcode.valueF = MOTOR_Z_MAX_FEEDRATE; + gcode.valueF = EEPROM_SPEED_LIMIT_Z_MAX; gcode.commandParameters = PARAMETER_G_OFFSET | PARAMETER_Z_OFFSET | PARAMETER_F_OFFSET; move(gcode, SAVE_CHANGES_TASK); @@ -933,7 +978,7 @@ void Motors::compensateForBedLeveling() { } // Adjust current Z value for current real height - currentValues[Z] += getHeightAdjustmentRequired(currentValues[X], currentValues[Y]); + currentValues[Z] += getHeightAdjustmentRequired(startValues[X], startValues[Y]); // Get horizontal distance float horizontalDistance = sqrt(pow(valueChanges[X], 2) + pow(valueChanges[Y], 2)); @@ -948,14 +993,14 @@ void Motors::compensateForBedLeveling() { gcode.commandParameters = PARAMETER_G_OFFSET | PARAMETER_X_OFFSET | PARAMETER_Y_OFFSET | PARAMETER_Z_OFFSET | PARAMETER_E_OFFSET; // Go through all segments - for(uint32_t numberOfSegments = max(1, ceil(horizontalDistance / SEGMENT_LENGTH)), segmentCounter = 1; segmentCounter <= numberOfSegments; segmentCounter++) { + for(uint32_t numberOfSegments = minimumOneCeil(horizontalDistance / SEGMENT_LENGTH), segmentCounter = 1; segmentCounter <= numberOfSegments; segmentCounter++) { // Go through all motors for(uint8_t i = 0; i < NUMBER_OF_MOTORS; i++) { // Set segment value float segmentValue = segmentCounter != numberOfSegments ? startValues[i] + segmentCounter * SEGMENT_LENGTH * valueChanges[i] : endValues[i]; - + // Set G-code parameter switch(i) { @@ -995,10 +1040,10 @@ void Motors::updateBedChanges(bool adjustHeight) { // Set previous height adjustment float previousHeightAdjustment = getHeightAdjustmentRequired(currentValues[X], currentValues[Y]) + bedHeightOffset; - // Go through all corners + // Go through all positions for(uint8_t i = 0; i < 4; i++) { - // Set corner's orientation, offset, and value + // Set position's orientation, offset, and value eeprom_addr_t orientationOffset, offsetOffset; uint8_t orientationLength, offsetLength; float *value; @@ -1036,7 +1081,7 @@ void Motors::updateBedChanges(bool adjustHeight) { value = &frontRightVector.z; } - // Update corner vector + // Update position vector float orientation, offset; nvm_eeprom_read_buffer(orientationOffset, &orientation, orientationLength); nvm_eeprom_read_buffer(offsetOffset, &offset, offsetLength); @@ -1065,7 +1110,7 @@ bool Motors::gantryClipsDetected() { return false; } -void Motors::changeState(bool save, AXES motor) { +void Motors::changeState(bool save, AXES motor, AXES_PARAMETER parameter) { // Go through X, Y, and Z motors for(uint8_t i = motor; i <= (save ? motor : 2); i++) { @@ -1098,25 +1143,29 @@ void Motors::changeState(bool save, AXES motor) { // Check if saving state if(save) { - // Check if direction is saved and it's not up to date - if(savedDirectionOffset < EEPROM_SIZE && nvm_eeprom_read_byte(savedDirectionOffset) != currentMotorDirections[i]) + // Check if direction is being saved and it's not up to date + if(parameter == DIRECTION && savedDirectionOffset < EEPROM_SIZE && nvm_eeprom_read_byte(savedDirectionOffset) != currentMotorDirections[i]) // Save direction nvm_eeprom_write_byte(savedDirectionOffset, currentMotorDirections[i]); - // Check if value's validity is not up to date - if(nvm_eeprom_read_byte(savedStateOffset) != currentStateOfValues[i]) + // Otherwise check if validity is being saved and it's not up to date + else if(parameter == VALIDITY && nvm_eeprom_read_byte(savedStateOffset) != currentStateOfValues[i]) // Save if value is valid nvm_eeprom_write_byte(savedStateOffset, currentStateOfValues[i]); + + // Otherwise check if value is being saved + else if(parameter == VALUE) { - // Check if current value is not up to date - float value; - nvm_eeprom_read_buffer(savedValueOffset, &value, savedValueLength); - if(value != currentValues[i]) + // Check if current value is not up to date + float value; + nvm_eeprom_read_buffer(savedValueOffset, &value, savedValueLength); + if(value != currentValues[i]) - // Save current value - nvm_eeprom_erase_and_write_buffer(savedValueOffset, ¤tValues[i], savedValueLength); + // Save current value + nvm_eeprom_erase_and_write_buffer(savedValueOffset, ¤tValues[i], savedValueLength); + } } // Otherwise assume restoring state @@ -1146,13 +1195,13 @@ void Motors::homeXY(bool adjustHeight) { for(int8_t i = 1; i >= 0 && !emergencyStopOccured; i--) { // Set up motors to move all the way to the back right corner as a fallback - motorsDelaySkips[i] = 0; - motorsStepDelay[i] = 1; int16_t *accelerometerValue; int16_t jerkAcceleration; void (*setMotorStepInterruptLevel)(volatile void *tc, TC_INT_LEVEL_t level); + float distance; if(i) { - motorsNumberOfSteps[i] = round((max(max(BED_LOW_MAX_Y, BED_MEDIUM_MAX_Y), BED_HIGH_MAX_Y) - min(min(BED_LOW_MIN_Y, BED_MEDIUM_MIN_Y), BED_HIGH_MIN_Y) + 5) * MOTOR_Y_STEPS_PER_MM * MICROSTEPS_PER_STEP); + distance = max(max(BED_LOW_MAX_Y, BED_MEDIUM_MAX_Y), BED_HIGH_MAX_Y) - min(min(BED_LOW_MIN_Y, BED_MEDIUM_MIN_Y), BED_HIGH_MIN_Y) + 5; + motorsNumberOfSteps[i] = round(distance * MOTOR_Y_STEPS_PER_MM * MICROSTEPS_PER_STEP); ioport_set_pin_level(MOTOR_Y_DIRECTION_PIN, DIRECTION_BACKWARD); setMotorStepInterruptLevel = tc_set_ccb_interrupt_level; @@ -1164,7 +1213,8 @@ void Motors::homeXY(bool adjustHeight) { tc_write_cc(&MOTORS_VREF_TIMER, MOTOR_Y_VREF_CHANNEL, round(MOTOR_Y_CURRENT_ACTIVE * MOTORS_CURRENT_TO_VOLTAGE_SCALAR / MICROCONTROLLER_VOLTAGE * MOTORS_VREF_TIMER_PERIOD)); } else { - motorsNumberOfSteps[i] = round((max(max(BED_LOW_MAX_X, BED_MEDIUM_MAX_X), BED_HIGH_MAX_X) - min(min(BED_LOW_MIN_X, BED_MEDIUM_MIN_X), BED_HIGH_MIN_X) + 5) * MOTOR_X_STEPS_PER_MM * MICROSTEPS_PER_STEP); + distance = max(max(BED_LOW_MAX_X, BED_MEDIUM_MAX_X), BED_HIGH_MAX_X) - min(min(BED_LOW_MIN_X, BED_MEDIUM_MIN_X), BED_HIGH_MIN_X) + 5; + motorsNumberOfSteps[i] = round(distance * MOTOR_X_STEPS_PER_MM * MICROSTEPS_PER_STEP); ioport_set_pin_level(MOTOR_X_DIRECTION_PIN, DIRECTION_RIGHT); setMotorStepInterruptLevel = tc_set_cca_interrupt_level; @@ -1176,6 +1226,12 @@ void Motors::homeXY(bool adjustHeight) { tc_write_cc(&MOTORS_VREF_TIMER, MOTOR_X_VREF_CHANNEL, round(MOTOR_X_CURRENT_ACTIVE * MOTORS_CURRENT_TO_VOLTAGE_SCALAR / MICROCONTROLLER_VOLTAGE * MOTORS_VREF_TIMER_PERIOD)); } + // Set motor delay to achieve desired feed rate + motorsStepDelayCounter[i] = motorsDelaySkipsCounter[i] = 0; + motorsStepDelay[i] = minimumOneCeil((distance * 60 * sysclk_get_cpu_hz()) / (HOMING_FEED_RATE * MOTORS_STEP_TIMER_PERIOD * motorsNumberOfSteps[i])); + float denominator = (distance * 60 * sysclk_get_cpu_hz()) / (HOMING_FEED_RATE * MOTORS_STEP_TIMER_PERIOD * motorsNumberOfSteps[i] * motorsStepDelay[i]) - 1; + motorsDelaySkips[i] = denominator ? round(1 / denominator) : 0; + // Enable motor step interrupt (*setMotorStepInterruptLevel)(&MOTORS_STEP_TIMER, TC_INT_LVL_LO); @@ -1183,8 +1239,7 @@ void Motors::homeXY(bool adjustHeight) { turnOn(); // Start motors step timer - tc_write_count(&MOTORS_STEP_TIMER, MOTORS_STEP_TIMER_PERIOD - 1); - tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_DIV1_gc); + startMotorsStepTimer(); // Wait until all motors step interrupts have stopped or an emergency stop occurs int16_t lastValue; @@ -1213,7 +1268,7 @@ void Motors::homeXY(bool adjustHeight) { } // Stop motors step timer - tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_OFF_gc); + stopMotorsStepTimer(); // Set motors Vref to idle tc_write_cc(&MOTORS_VREF_TIMER, MOTOR_X_VREF_CHANNEL, round(MOTOR_X_CURRENT_IDLE * MOTORS_CURRENT_TO_VOLTAGE_SCALAR / MICROCONTROLLER_VOLTAGE * MOTORS_VREF_TIMER_PERIOD)); @@ -1238,7 +1293,7 @@ void Motors::homeXY(bool adjustHeight) { gcode.valueX = -BED_CENTER_X_DISTANCE_FROM_HOMING_CORNER; gcode.valueY = -BED_CENTER_Y_DISTANCE_FROM_HOMING_CORNER; gcode.valueZ = adjustHeight ? getHeightAdjustmentRequired(BED_CENTER_X, BED_CENTER_Y) - getHeightAdjustmentRequired(currentValues[X], currentValues[Y]) : 0; - gcode.valueF = MOTOR_X_MAX_FEEDRATE; + gcode.valueF = EEPROM_SPEED_LIMIT_X_MAX; gcode.commandParameters = PARAMETER_G_OFFSET | PARAMETER_X_OFFSET | PARAMETER_Y_OFFSET | PARAMETER_Z_OFFSET | PARAMETER_F_OFFSET; move(gcode, SAVE_CHANGES_TASK); @@ -1280,12 +1335,16 @@ void Motors::moveToZ0() { for(uint8_t matchCounter = 0; !emergencyStopOccured;) { // Set up motors to move down - motorsDelaySkips[Z] = 0; - motorsStepDelay[Z] = 4; motorsNumberOfSteps[Z] = UINT32_MAX; ioport_set_pin_level(MOTOR_Z_DIRECTION_PIN, DIRECTION_DOWN); tc_set_ccc_interrupt_level(&MOTORS_STEP_TIMER, TC_INT_LVL_LO); + // Set motor delay to achieve desired feed rate + motorsStepDelayCounter[Z] = motorsDelaySkipsCounter[Z] = 0; + motorsStepDelay[Z] = minimumOneCeil(((motorsNumberOfSteps[Z] / (MOTOR_Z_STEPS_PER_MM * MICROSTEPS_PER_STEP)) * 60 * sysclk_get_cpu_hz()) / (CALIBRATING_Z_FEED_RATE * MOTORS_STEP_TIMER_PERIOD * (motorsNumberOfSteps[Z] / (MOTOR_Z_STEPS_PER_MM * MICROSTEPS_PER_STEP)) * MOTOR_Z_STEPS_PER_MM * MICROSTEPS_PER_STEP)); + float denominator = ((motorsNumberOfSteps[Z] / (MOTOR_Z_STEPS_PER_MM * MICROSTEPS_PER_STEP)) * 60 * sysclk_get_cpu_hz()) / (CALIBRATING_Z_FEED_RATE * MOTORS_STEP_TIMER_PERIOD * (motorsNumberOfSteps[Z] / (MOTOR_Z_STEPS_PER_MM * MICROSTEPS_PER_STEP)) * MOTOR_Z_STEPS_PER_MM * MICROSTEPS_PER_STEP * motorsStepDelay[Z]) - 1; + motorsDelaySkips[Z] = denominator ? round(1 / denominator) : 0; + // Set motor Z Vref to active tc_write_cc(&MOTORS_VREF_TIMER, MOTOR_Z_VREF_CHANNEL, round(MOTOR_Z_CURRENT_ACTIVE * MOTORS_CURRENT_TO_VOLTAGE_SCALAR / MICROCONTROLLER_VOLTAGE * MOTORS_VREF_TIMER_PERIOD)); @@ -1297,8 +1356,7 @@ void Motors::moveToZ0() { int16_t stillValue = accelerometer.yAcceleration; // Start motors step timer - tc_write_count(&MOTORS_STEP_TIMER, MOTORS_STEP_TIMER_PERIOD - 1); - tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_DIV1_gc); + startMotorsStepTimer(); // Wait until Z motor step interrupts have stopped or an emergency stop occurs for(uint8_t counter = 0; MOTORS_STEP_TIMER.INTCTRLB & TC0_CCCINTLVL_gm && !emergencyStopOccured;) { @@ -1318,7 +1376,7 @@ void Motors::moveToZ0() { } // Stop motors step timer - tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_OFF_gc); + stopMotorsStepTimer(); // Set current Z currentValues[Z] -= (static_cast(UINT32_MAX) - motorsNumberOfSteps[Z]) / (MOTOR_Z_STEPS_PER_MM * MICROSTEPS_PER_STEP); @@ -1392,22 +1450,22 @@ void Motors::calibrateBedOrientation() { calibrateBedCenterZ0(); // Initialize X and Y positions - uint8_t positionsX[] = {BED_CENTER_X - CORNER_DISTANCE_FROM_CENTER, BED_CENTER_X + CORNER_DISTANCE_FROM_CENTER, BED_CENTER_X + CORNER_DISTANCE_FROM_CENTER, BED_CENTER_X - CORNER_DISTANCE_FROM_CENTER, BED_CENTER_X}; - uint8_t positionsY[] = {BED_CENTER_Y - CORNER_DISTANCE_FROM_CENTER, BED_CENTER_Y - CORNER_DISTANCE_FROM_CENTER, BED_CENTER_Y + CORNER_DISTANCE_FROM_CENTER, BED_CENTER_Y + CORNER_DISTANCE_FROM_CENTER, BED_CENTER_Y}; + float positionsX[] = {BED_CENTER_X - BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_X + BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_X + BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_X - BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_X}; + float positionsY[] = {BED_CENTER_Y - BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_Y - BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_Y + BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_Y + BED_CALIBRATION_POSITIONS_DISTANCE_FROM_CENTER, BED_CENTER_Y}; // Save mode MODES savedMode = mode; mode = ABSOLUTE; // Go through all positions - for(uint8_t i = 0; i < 5 && !emergencyStopOccured; i++) { + for(uint8_t i = 0; i < sizeof(positionsX) / sizeof(positionsX[0]) && !emergencyStopOccured; i++) { - // Move to corner + // Move to position Gcode gcode; gcode.valueG = 0; gcode.valueX = positionsX[i]; gcode.valueY = positionsY[i]; - gcode.valueF = MOTOR_X_MAX_FEEDRATE; + gcode.valueF = EEPROM_SPEED_LIMIT_X_MAX; gcode.commandParameters = PARAMETER_G_OFFSET | PARAMETER_X_OFFSET | PARAMETER_Y_OFFSET | PARAMETER_F_OFFSET; move(gcode, BACKLASH_TASK | SAVE_CHANGES_TASK); @@ -1426,7 +1484,7 @@ void Motors::calibrateBedOrientation() { // Break break; - // Get corner orientation offset and length + // Get position's orientation offset and length eeprom_addr_t eepromOffset = EEPROM_SIZE; uint8_t eepromLength; switch(i) { @@ -1454,15 +1512,22 @@ void Motors::calibrateBedOrientation() { // Check if saving orientation if(eepromOffset < EEPROM_SIZE) - // Save corner orientation + // Save position's orientation nvm_eeprom_erase_and_write_buffer(eepromOffset, ¤tValues[Z], eepromLength); // Move to height 3mm moveToHeight(3); } - // Update bed changes - updateBedChanges(false); + // Check if emergency stop hasn't occured + if(!emergencyStopOccured) { + + // Save bed orientation version + nvm_eeprom_write_byte(EEPROM_BED_ORIENTATION_VERSION_OFFSET, BED_ORIENTATION_VERSION); + + // Update bed changes + updateBedChanges(false); + } // Restore mode mode = savedMode; @@ -1471,7 +1536,7 @@ void Motors::calibrateBedOrientation() { void Motors::reset() { // Stop motors step timer - tc_write_clock_source(&MOTORS_STEP_TIMER, TC_CLKSEL_OFF_gc); + stopMotorsStepTimer(); // Turn off motors turnOff(); diff --git a/motors.h b/motors.h index 403b850..ef947ca 100644 --- a/motors.h +++ b/motors.h @@ -20,6 +20,10 @@ #define BED_LEVELING_TASK (1 << 1) #define SAVE_CHANGES_TASK (1 << 2) +// State changes +#define saveState(motor, parameter) changeState(true, motor, parameter) +#define restoreState() changeState() + // Modes enum MODES {RELATIVE, ABSOLUTE}; @@ -29,6 +33,9 @@ enum AXES {X, Y, Z, E, F}; // Backlash direction enum BACKLASH_DIRECTION {NONE, POSITIVE, NEGATIVE}; +// Axes parameter +enum AXES_PARAMETER {DIRECTION, VALIDITY, VALUE}; + // Motors class class Motors { @@ -87,7 +94,7 @@ class Motors { private: // Change state - void changeState(bool save = false, AXES motor = X); + void changeState(bool save = false, AXES motor = X, AXES_PARAMETER parameter = DIRECTION); // Move to height void moveToHeight(float height); diff --git a/src/ASF/common/boards/board.h b/src/ASF/common/boards/board.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/boards/user_board/init.c b/src/ASF/common/boards/user_board/init.c old mode 100755 new mode 100644 diff --git a/src/ASF/common/boards/user_board/user_board.h b/src/ASF/common/boards/user_board/user_board.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/clock/genclk.h b/src/ASF/common/services/clock/genclk.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/clock/osc.h b/src/ASF/common/services/clock/osc.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/clock/pll.h b/src/ASF/common/services/clock/pll.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/clock/sysclk.h b/src/ASF/common/services/clock/sysclk.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/clock/xmega/osc.h b/src/ASF/common/services/clock/xmega/osc.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/clock/xmega/pll.h b/src/ASF/common/services/clock/xmega/pll.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/clock/xmega/sysclk.c b/src/ASF/common/services/clock/xmega/sysclk.c old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/clock/xmega/sysclk.h b/src/ASF/common/services/clock/xmega/sysclk.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/delay/delay.h b/src/ASF/common/services/delay/delay.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/delay/xmega/cycle_counter.h b/src/ASF/common/services/delay/xmega/cycle_counter.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/ioport/ioport.h b/src/ASF/common/services/ioport/ioport.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/ioport/xmega/ioport.h b/src/ASF/common/services/ioport/xmega/ioport.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/ioport/xmega/ioport_compat.c b/src/ASF/common/services/ioport/xmega/ioport_compat.c old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/ioport/xmega/ioport_compat.h b/src/ASF/common/services/ioport/xmega/ioport_compat.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/sleepmgr/sleepmgr.h b/src/ASF/common/services/sleepmgr/sleepmgr.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/sleepmgr/xmega/sleepmgr.c b/src/ASF/common/services/sleepmgr/xmega/sleepmgr.c old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/sleepmgr/xmega/sleepmgr.h b/src/ASF/common/services/sleepmgr/xmega/sleepmgr.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/twi/twi_master.h b/src/ASF/common/services/twi/twi_master.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/twi/twi_slave.h b/src/ASF/common/services/twi/twi_slave.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/twi/xmega_twi/twi_master.h b/src/ASF/common/services/twi/xmega_twi/twi_master.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/twi/xmega_twi/twi_slave.h b/src/ASF/common/services/twi/xmega_twi/twi_slave.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/class/cdc/device/udi_cdc.c b/src/ASF/common/services/usb/class/cdc/device/udi_cdc.c old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/class/cdc/device/udi_cdc.h b/src/ASF/common/services/usb/class/cdc/device/udi_cdc.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/class/cdc/device/udi_cdc_conf.h b/src/ASF/common/services/usb/class/cdc/device/udi_cdc_conf.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/class/cdc/device/udi_cdc_desc.c b/src/ASF/common/services/usb/class/cdc/device/udi_cdc_desc.c old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/class/cdc/usb_protocol_cdc.h b/src/ASF/common/services/usb/class/cdc/usb_protocol_cdc.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/udc/udc.c b/src/ASF/common/services/usb/udc/udc.c old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/udc/udc.h b/src/ASF/common/services/usb/udc/udc.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/udc/udc_desc.h b/src/ASF/common/services/usb/udc/udc_desc.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/udc/udd.h b/src/ASF/common/services/usb/udc/udd.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/udc/udi.h b/src/ASF/common/services/usb/udc/udi.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/usb_atmel.h b/src/ASF/common/services/usb/usb_atmel.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/services/usb/usb_protocol.h b/src/ASF/common/services/usb/usb_protocol.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/utils/interrupt.h b/src/ASF/common/utils/interrupt.h old mode 100755 new mode 100644 diff --git a/src/ASF/common/utils/interrupt/interrupt_avr8.h b/src/ASF/common/utils/interrupt/interrupt_avr8.h old mode 100755 new mode 100644 index 1c55fb2..1e6928c --- a/src/ASF/common/utils/interrupt/interrupt_avr8.h +++ b/src/ASF/common/utils/interrupt/interrupt_avr8.h @@ -3,7 +3,7 @@ * * \brief Global interrupt management for 8-bit AVR * - * Copyright (C) 2010-2015 Atmel Corporation. All rights reserved. + * Copyright (C) 2010-2016 Atmel Corporation. All rights reserved. * * \asf_license_start * @@ -107,7 +107,7 @@ typedef uint8_t irqflags_t; static inline irqflags_t cpu_irq_save(void) { - irqflags_t flags = SREG; + volatile irqflags_t flags = SREG; cpu_irq_disable(); return flags; } diff --git a/src/ASF/common/utils/make/Makefile.avr.in b/src/ASF/common/utils/make/Makefile.avr.in old mode 100755 new mode 100644 diff --git a/src/ASF/common/utils/parts.h b/src/ASF/common/utils/parts.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/adc/adc.c b/src/ASF/xmega/drivers/adc/adc.c old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/adc/adc.h b/src/ASF/xmega/drivers/adc/adc.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/adc/xmega_bcd/adc_bcd.c b/src/ASF/xmega/drivers/adc/xmega_bcd/adc_bcd.c old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/cpu/ccp.h b/src/ASF/xmega/drivers/cpu/ccp.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/cpu/ccp.s b/src/ASF/xmega/drivers/cpu/ccp.s old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/cpu/xmega_reset_cause.h b/src/ASF/xmega/drivers/cpu/xmega_reset_cause.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/nvm/nvm.c b/src/ASF/xmega/drivers/nvm/nvm.c old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/nvm/nvm.h b/src/ASF/xmega/drivers/nvm/nvm.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/nvm/nvm_asm.s b/src/ASF/xmega/drivers/nvm/nvm_asm.s old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/pmic/pmic.h b/src/ASF/xmega/drivers/pmic/pmic.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/sleep/sleep.h b/src/ASF/xmega/drivers/sleep/sleep.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/tc/tc.c b/src/ASF/xmega/drivers/tc/tc.c old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/tc/tc.h b/src/ASF/xmega/drivers/tc/tc.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/twi/twi_common.h b/src/ASF/xmega/drivers/twi/twi_common.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/twi/twim.c b/src/ASF/xmega/drivers/twi/twim.c old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/twi/twim.h b/src/ASF/xmega/drivers/twi/twim.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/twi/twis.c b/src/ASF/xmega/drivers/twi/twis.c old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/twi/twis.h b/src/ASF/xmega/drivers/twi/twis.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/usb/usb_device.c b/src/ASF/xmega/drivers/usb/usb_device.c old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/drivers/usb/usb_device.h b/src/ASF/xmega/drivers/usb/usb_device.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/assembler.h b/src/ASF/xmega/utils/assembler.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/assembler/gas.h b/src/ASF/xmega/utils/assembler/gas.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/bit_handling/clz_ctz.h b/src/ASF/xmega/utils/bit_handling/clz_ctz.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/compiler.h b/src/ASF/xmega/utils/compiler.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/preprocessor/mrepeat.h b/src/ASF/xmega/utils/preprocessor/mrepeat.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/preprocessor/preprocessor.h b/src/ASF/xmega/utils/preprocessor/preprocessor.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/preprocessor/stringz.h b/src/ASF/xmega/utils/preprocessor/stringz.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/preprocessor/tpaste.h b/src/ASF/xmega/utils/preprocessor/tpaste.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/progmem.h b/src/ASF/xmega/utils/progmem.h old mode 100755 new mode 100644 diff --git a/src/ASF/xmega/utils/status_codes.h b/src/ASF/xmega/utils/status_codes.h old mode 100755 new mode 100644 diff --git a/src/config/conf_usb.h b/src/config/conf_usb.h index a6def1f..5a7a40c 100755 --- a/src/config/conf_usb.h +++ b/src/config/conf_usb.h @@ -4,8 +4,8 @@ // Header files -#include "compiler.h" -#include "eeprom.h" +#include +#include // Device definitions