Skip to content

Commit b7c0c23

Browse files
committed
Fix for #164, hard fault when a basic on/off spindle is configured.
1 parent 5687b90 commit b7c0c23

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

main/driver.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,8 +1976,8 @@ static void spindlePulseOn (uint_fast16_t pulse_length)
19761976

19771977
IRAM_ATTR inline static void spindle_off (spindle_ptrs_t *spindle)
19781978
{
1979-
spindle->context.pwm->flags.enable_out = Off;
1980-
#ifdef SPINDLE_DIRECTION_PIN
1979+
#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM
1980+
#ifdef SPINDLE_DIRECTION_PIN
19811981
if(spindle->context.pwm->flags.cloned) {
19821982
#if SPINDLE_DIRECTION_PORT == EXPANDER_PORT
19831983
EXPANDER_OUT(SPINDLE_DIRECTION_PIN, settings.pwm_spindle.invert.ccw);
@@ -1991,12 +1991,16 @@ IRAM_ATTR inline static void spindle_off (spindle_ptrs_t *spindle)
19911991
DIGITAL_OUT(SPINDLE_ENABLE_PIN, settings.pwm_spindle.invert.on);
19921992
#endif
19931993
}
1994-
#else
1995-
#if SPINDLE_ENABLE_PORT == EXPANDER_PORT
1994+
#elif SPINDLE_ENABLE_PORT == EXPANDER_PORT
19961995
EXPANDER_OUT(SPINDLE_ENABLE_PIN, settings.pwm_spindle.invert.on);
1997-
#else
1996+
#else
1997+
DIGITAL_OUT(SPINDLE_ENABLE_PIN, settings.pwm_spindle.invert.on);
1998+
#endif
1999+
spindle->context.pwm->flags.enable_out = Off;
2000+
#elif SPINDLE_ENABLE_PORT == EXPANDER_PORT
2001+
EXPANDER_OUT(SPINDLE_ENABLE_PIN, settings.pwm_spindle.invert.on);
2002+
#else
19982003
DIGITAL_OUT(SPINDLE_ENABLE_PIN, settings.pwm_spindle.invert.on);
1999-
#endif
20002004
#endif
20012005
}
20022006

@@ -2007,7 +2011,8 @@ IRAM_ATTR static void spindleOffBasic (spindle_ptrs_t *spindle)
20072011

20082012
IRAM_ATTR inline static void spindle_on (spindle_ptrs_t *spindle)
20092013
{
2010-
#ifdef SPINDLE_DIRECTION_PIN
2014+
#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM
2015+
#ifdef SPINDLE_DIRECTION_PIN
20112016
if(spindle->context.pwm->flags.cloned) {
20122017
#if SPINDLE_DIRECTION_PORT == EXPANDER_PORT
20132018
EXPANDER_OUT(SPINDLE_DIRECTION_PIN, !settings.pwm_spindle.invert.ccw);
@@ -2019,16 +2024,19 @@ IRAM_ATTR inline static void spindle_on (spindle_ptrs_t *spindle)
20192024
EXPANDER_OUT(SPINDLE_ENABLE_PIN, !settings.pwm_spindle.invert.on);
20202025
#else
20212026
DIGITAL_OUT(SPINDLE_ENABLE_PIN, !settings.pwm_spindle.invert.on);
2022-
#endif
2027+
#endif
20232028
}
2024-
#else
2025-
#if SPINDLE_ENABLE_PORT == EXPANDER_PORT
2029+
#elif SPINDLE_ENABLE_PORT == EXPANDER_PORT
20262030
EXPANDER_OUT(SPINDLE_ENABLE_PIN, !settings.pwm_spindle.invert.on);
2027-
#else
2031+
#else
20282032
DIGITAL_OUT(SPINDLE_ENABLE_PIN, !settings.pwm_spindle.invert.on);
2029-
#endif
2030-
#endif
2033+
#endif
20312034
spindle->context.pwm->flags.enable_out = On;
2035+
#elif SPINDLE_ENABLE_PORT == EXPANDER_PORT
2036+
EXPANDER_OUT(SPINDLE_ENABLE_PIN, !settings.pwm_spindle.invert.on);
2037+
#else
2038+
DIGITAL_OUT(SPINDLE_ENABLE_PIN, !settings.pwm_spindle.invert.on);
2039+
#endif
20322040
}
20332041

20342042
IRAM_ATTR inline static void spindle_dir (bool ccw)
@@ -2090,7 +2098,7 @@ static void spindleSetSpeed (spindle_ptrs_t *spindle, uint_fast16_t pwm_value)
20902098
pwm_spindle.ramp.pwm_target = pwm_value;
20912099
ledc_set_fade_step_and_start(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel, pwm_spindle.ramp.pwm_target, 1, 4, LEDC_FADE_NO_WAIT);
20922100
#else
2093-
ledc_set_duty(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel, spindle->context.pwm->settings->invert.pwm ? pwm_spindle.pwm_max_value - pwm_value : pwm_value);
2101+
ledc_set_duty(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel, pwm_value);
20942102
ledc_update_duty(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel);
20952103
#endif
20962104
if(!spindle->context.pwm->flags.enable_out && spindle->context.pwm->flags.rpm_controlled)
@@ -2181,7 +2189,9 @@ bool spindleConfig (spindle_ptrs_t *spindle)
21812189
#endif
21822190
}
21832191
} else {
2192+
#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM
21842193
if(spindle->context.pwm->flags.enable_out)
2194+
#endif
21852195
spindle->set_state(spindle, (spindle_state_t){0}, 0.0f);
21862196
spindle->esp32_off = spindleOffBasic;
21872197
spindle->set_state = spindleSetState;
@@ -3426,10 +3436,10 @@ static void wdt_tickler (sys_state_t state)
34263436
}
34273437

34283438
// Initialize HAL pointers, setup serial comms and enable EEPROM
3429-
// NOTE: Grbl is not yet configured (from EEPROM data), driver_setup() will be called when done
3439+
// NOTE: grblHAL is not yet configured (from EEPROM data), driver_setup() will be called when done
34303440
bool driver_init (void)
34313441
{
3432-
// Enable EEPROM and serial port here for Grbl to be able to configure itself and report any errors
3442+
// Enable EEPROM and serial port here for grblHAL to be able to configure itself and report any errors
34333443
rtc_cpu_freq_config_t cpu;
34343444

34353445
rtc_clk_cpu_freq_get_config(&cpu);
@@ -3439,7 +3449,7 @@ bool driver_init (void)
34393449
#else
34403450
hal.info = "ESP32";
34413451
#endif
3442-
hal.driver_version = "250501";
3452+
hal.driver_version = "250514";
34433453
hal.driver_url = GRBL_URL "/ESP32";
34443454
#ifdef BOARD_NAME
34453455
hal.board = BOARD_NAME;

main/driver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ typedef struct {
154154
#include "boards/root_cnc_v3_map.h"
155155
#elif defined(BOARD_ROOTCNC_PRO)
156156
#include "boards/root_cnc_pro_map.h"
157-
#elif defined(BOARD_BLOX)
158-
#include "boards/blox_map.h"
159157
#elif defined(BOARD_CNC3040)
160158
#include "boards/cnc3040_map.h"
161159
#elif defined(BOARD_JACKPOT)

0 commit comments

Comments
 (0)