Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Option to reset AVR pin states (#25364)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
quiret and thinkyhead authored Aug 4, 2023
1 parent 820d2b5 commit 3baa318
Show file tree
Hide file tree
Showing 6 changed files with 6,221 additions and 170 deletions.
27 changes: 22 additions & 5 deletions Marlin/src/HAL/AVR/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,40 @@ void save_reset_reason() {
wdt_disable();
}

#include "registers.h"

MarlinHAL::MarlinHAL() {
TERN_(HAL_AVR_DIRTY_INIT, _ATmega_resetperipherals()); // Clean-wipe the device state.
}

void MarlinHAL::init() {
// Init Servo Pins
#define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
#if HAS_SERVO_0
INIT_SERVO(0);
OUT_WRITE(SERVO0_PIN, LOW);
#endif
#if HAS_SERVO_1
INIT_SERVO(1);
OUT_WRITE(SERVO1_PIN, LOW);
#endif
#if HAS_SERVO_2
INIT_SERVO(2);
OUT_WRITE(SERVO2_PIN, LOW);
#endif
#if HAS_SERVO_3
INIT_SERVO(3);
OUT_WRITE(SERVO3_PIN, LOW);
#endif

init_pwm_timers(); // Init user timers to default frequency - 1000HZ

#if PIN_EXISTS(BEEPER) && ENABLED(HAL_AVR_DIRTY_INIT) && DISABLED(ATMEGA_NO_BEEPFIX)
// Make sure no alternative is locked onto the BEEPER.
// This fixes the issue where the ATmega is constantly beeping.
// Might disable other peripherals using the pin; to circumvent that please undefine one of the above things!
// The true culprit is the AVR ArduinoCore that enables peripherals redundantly.
// (USART1 on the GeeeTech GT2560)
// https://www.youtube.com/watch?v=jMgCvRXkexk
_ATmega_savePinAlternate(BEEPER_PIN);

OUT_WRITE(BEEPER_PIN, LOW);
#endif
}

void MarlinHAL::reboot() {
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class MarlinHAL {
public:

// Earliest possible init, before setup()
MarlinHAL() {}
MarlinHAL();

// Watchdog
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
Expand Down
Loading

0 comments on commit 3baa318

Please sign in to comment.