|
| 1 | +/** |
| 2 | + * Marlin 3D Printer Firmware |
| 3 | + * Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] |
| 4 | + * |
| 5 | + * Based on Sprinter and grbl. |
| 6 | + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | +#include "../../inc/MarlinConfig.h" |
| 23 | + |
| 24 | +#if ENABLED(OTA_FIRMWARE_UPDATE) |
| 25 | + |
| 26 | +#include "../gcode.h" |
| 27 | +#include "../../libs/BL24CXX.h" |
| 28 | + |
| 29 | +#if ENABLED(CREALITY_RTS) |
| 30 | + #include "../../lcd/rts/lcd_rts.h" |
| 31 | +#endif |
| 32 | + |
| 33 | +#define OTA_FLAG_EEPROM 90 |
| 34 | + |
| 35 | +//#define DEBUG_OUT 1 |
| 36 | +#include "../../core/debug_out.h" |
| 37 | + |
| 38 | +/** |
| 39 | + * M936: Set one of the OTA update flags. |
| 40 | + * V2 = Upgrade the motherboard firmware |
| 41 | + * V3 = Upgrade the RTS controller firmware |
| 42 | + */ |
| 43 | +void GcodeSuite::M936() { |
| 44 | + static uint8_t ota_update_flag = 0x00; |
| 45 | + const int16_t ota = parser.intval('V', -1); |
| 46 | + switch (ota) { |
| 47 | + case 2: |
| 48 | + // Set the OTA board firmware upgrade flag ahead of reboot. |
| 49 | + ota_update_flag = 0x01; |
| 50 | + DEBUG_ECHOLNPGM("Motherboard upgrade flag set"); |
| 51 | + TERN_(CREALITY_RTS, RTS_Error(Error_205)); |
| 52 | + break; |
| 53 | + |
| 54 | + #if ENABLED(CREALITY_RTS) |
| 55 | + case 3: |
| 56 | + // Set the OTA screen firmware upgrade flag ahead of reboot. |
| 57 | + ota_update_flag = 0x02; |
| 58 | + DEBUG_ECHOLNPGM("DWIN upgrade flag set"); |
| 59 | + TERN_(CREALITY_RTS, RTS_Error(Error_206)); |
| 60 | + break; |
| 61 | + #endif |
| 62 | + } |
| 63 | + |
| 64 | + switch (ota) { |
| 65 | + case 2: TERN_(CREALITY_RTS, case 3:) |
| 66 | + BL24CXX::write(OTA_FLAG_EEPROM, &ota_update_flag, sizeof(ota_update_flag)); |
| 67 | + safe_delay(100); |
| 68 | + hal.reboot(); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +#endif // OTA_FIRMWARE_UPDATE |
0 commit comments