Skip to content

Commit

Permalink
"hardened" ioports code to avoid hardfault in some configurations.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Feb 2, 2024
1 parent 31830b4 commit 1e6e906
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
13 changes: 8 additions & 5 deletions main/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,13 @@ IRAM_ATTR static void driver_delay_ms (uint32_t ms, void (*callback)(void))
xTimerDelete(xDelayTimer, 3);
xDelayTimer = NULL;
}
xDelayTimer = xTimerCreate("msDelay", pdMS_TO_TICKS(ms), pdFALSE, callback, vTimerCallback);
xTimerStartFromISR(xDelayTimer, &xHigherPriorityTaskWoken);
if(xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
if(ms) {
xDelayTimer = xTimerCreate("msDelay", pdMS_TO_TICKS(ms), pdFALSE, callback, vTimerCallback);
xTimerStartFromISR(xDelayTimer, &xHigherPriorityTaskWoken);
if(xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
} else
callback();
} else {
if(xDelayTimer) {
xTimerDelete(xDelayTimer, 3);
Expand Down Expand Up @@ -2735,7 +2738,7 @@ bool driver_init (void)
#else
hal.info = "ESP32";
#endif
hal.driver_version = "240127";
hal.driver_version = "240202";
hal.driver_url = GRBL_URL "/ESP32";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
Expand Down
16 changes: 6 additions & 10 deletions main/ioports.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ static void on_setting_changed (setting_id_t id)
switch(id) {

case Settings_IoPort_InvertIn:
port = digital.in.n_ports;
do {
if((port = digital.in.n_ports)) do {
port--;
aux_in[port].mode.inverted = !!(settings.ioport.invert_in.mask & (1 << port));
if(aux_in[port].aux_ctrl) {
Expand All @@ -341,8 +340,7 @@ static void on_setting_changed (setting_id_t id)
break;

case Settings_IoPort_InvertOut:
if(invert_digital_out.mask != settings.ioport.invert_out.mask) {
port = digital.out.n_ports;
if((port = digital.out.n_ports) && invert_digital_out.mask != settings.ioport.invert_out.mask) {
do {
port--;
aux_out[port].mode.inverted = !!(settings.ioport.invert_out.mask & (1 << port));
Expand All @@ -355,8 +353,7 @@ static void on_setting_changed (setting_id_t id)
break;

case Setting_ControlInvertMask:
port = digital.in.n_ports;
do {
if((port = digital.in.n_ports)) do {
if(aux_in[--port].aux_ctrl) {
write = true;
if(settings.control_invert.mask & aux_in[port].aux_ctrl->cap.mask)
Expand All @@ -379,18 +376,17 @@ static void on_setting_changed (setting_id_t id)
static void on_settings_loaded (void)
{
bool write = false;
uint_fast8_t port = digital.out.n_ports;
uint_fast8_t port;

invert_digital_out = settings.ioport.invert_out;

if(digital.out.n_ports) do {
if((port = digital.out.n_ports)) do {
port--;
aux_out[port].mode.inverted = !!(settings.ioport.invert_out.mask & (1 << port));
DIGITAL_OUT(aux_out[port].pin, aux_out[port].mode.inverted);
} while(port);

port = digital.in.n_ports;
do {
if((port = digital.in.n_ports)) do {
if(aux_in[--port].aux_ctrl &&
!!(settings.control_invert.mask & aux_in[port].aux_ctrl->cap.mask) !=
!!(settings.ioport.invert_in.mask & (1 << port))) {
Expand Down

0 comments on commit 1e6e906

Please sign in to comment.