Skip to content

Commit

Permalink
Size optimization, replacing ifs with switch statement
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-b-jakobsson committed Nov 18, 2024
1 parent b6025eb commit 9cf0890
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions ps2.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,29 +299,30 @@ class PS2Port
a PS/2 device
*/
void timerInterrupt() {
if (timerCountdown == PS2_CMD_TIMER::CMD_INACTIVE) {
//Do nothing
return;
}

if (timerCountdown == PS2_CMD_TIMER::CMD_TIMEOUT) {
// Host to device time out (25,200 us)
resetInput();
commandStatus = CMD_ERR;
}

else if (timerCountdown == PS2_CMD_TIMER::CMD_START) {
//Initiate request-to-send sequence
gpio_driveLow(clkPin);
gpio_driveLow(datPin);
ps2ddr = 1;
}
switch (timerCountdown) {
case PS2_CMD_TIMER::CMD_INACTIVE:
// Do nothing
return;

case PS2_CMD_TIMER::CMD_TIMEOUT:
// Host to device time out
resetInput();
commandStatus = CMD_ERR;
break;

else if (timerCountdown == PS2_CMD_TIMER::CMD_DEVICE_READY) {
//We are at end of the request-to-send clock hold time of minimum 100 us
gpio_inputWithPullup(clkPin);
rxBitCount = 0;
parity = 0;
case PS2_CMD_TIMER::CMD_START:
// Initiate request-to-send sequence
gpio_driveLow(clkPin);
gpio_driveLow(datPin);
ps2ddr = 1;
break;

case PS2_CMD_TIMER::CMD_DEVICE_READY:
// We are at end of the request-to-send clock hold time of minimum 100 us
gpio_inputWithPullup(clkPin);
rxBitCount = 0;
parity = 0;
break;
}

// Decrement counter
Expand Down

0 comments on commit 9cf0890

Please sign in to comment.