Skip to content

Commit

Permalink
I2C initiated reset and NMI changed to set flags that are handled by …
Browse files Browse the repository at this point in the history
…the main loop. Currently these functions, that are part of an ISR, call DoReset and DoNMI which use delay functions. That should not work correctly
  • Loading branch information
stefan-b-jakobsson committed Jan 17, 2024
1 parent 81dafb4 commit 8fa51db
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions x16-smc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ SmcButton RES_BUT(RESET_BUTTON_PIN);
#if defined(ENABLE_NMI_BUT)
SmcButton NMI_BUT(NMI_BUTTON_PIN);
#endif
bool powerOffRequest = false;
bool hardRebootRequest = false;
bool resetRequest = false;
bool NMIRequest = false;

// I2C
SmcWire smcWire;
Expand Down Expand Up @@ -210,13 +213,30 @@ void loop() {
//error handling?
}

// Process Hard Reboot Request
// Process Requests Received over I2C
if (powerOffRequest) {
powerOffRequest = false;
PowerOffSeq();
}

if (hardRebootRequest) {
hardRebootRequest = false;
HardReboot();
}

// Process Reset and NMI Requests
if (resetRequest) {
resetRequest = false;
DoReset();
}

if (NMIRequest) {
NMIRequest = false;
DoNMI();
}

// Process

// Process Keyboard Initiated Reset and NMI Requests
if (Keyboard.getResetRequest()) {
DoReset();
Keyboard.ackResetRequest();
Expand Down Expand Up @@ -354,7 +374,7 @@ void I2C_Receive(int) {
case CMD_POW_OFF:
switch (I2C_Data[1]) {
case 0:
PowerOffSeq();
powerOffRequest = true;
break;
case 1:
hardRebootRequest = true;
Expand All @@ -365,14 +385,15 @@ void I2C_Receive(int) {
case CMD_RESET:
switch (I2C_Data[1]) {
case 0:
DoReset();
resetRequest = true;
break;
}
break;

case CMD_NMI:
switch (I2C_Data[1]) {
case 0: DoNMI();
case 0:
NMIRequest = true;
break;
}
break;
Expand Down

0 comments on commit 8fa51db

Please sign in to comment.