aboutsummaryrefslogtreecommitdiffstats
path: root/fw/usb.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-09-05 18:41:12 -0400
committerSam Anthony <sam@samanthony.xyz>2025-09-05 18:41:12 -0400
commitca008db4258598f14f6ec1891a4ab20c262ca924 (patch)
treea86161a75134df34d148293c9ae4f6a547399df7 /fw/usb.c
parent2aa9d6e2ef1294d42c742a9ce7b6e3eb88316f4e (diff)
downloadcan-gauge-interface-ca008db4258598f14f6ec1891a4ab20c262ca924.zip
usb: preemptive bug fix
Diffstat (limited to 'fw/usb.c')
-rw-r--r--fw/usb.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/fw/usb.c b/fw/usb.c
index bdf3b64..7f283e1 100644
--- a/fw/usb.c
+++ b/fw/usb.c
@@ -72,8 +72,10 @@ idleState(void) {
static State state;
uint8_t opcode;
+ state.next = idleState;
+
readLen = getsUSBUSART(readBuf, sizeof(readBuf));
- if (readLen >= 2u) {
+ if (readLen >= 2u) { // <opcode> <space> ...
opcode = readBuf[0u];
// skip <opcode> <space>
@@ -84,11 +86,8 @@ idleState(void) {
case 'e': state.next = echoState; break;
case 'w': state.next = writeEepromState; break;
case 'r': state.next = readEepromState; break;
- default: state.next = idleState; break; // invalid command
+ default: break; // invalid command
}
- } else {
- // Invalid command. Must start with <opcode> <space>
- state.next = idleState;
}
return &state;
@@ -97,9 +96,11 @@ idleState(void) {
// Handle "e" echo command.
static State *
echoState(void) {
- static State state = {echoState};
+ static State state;
uint8_t i;
+ state.next = echoState;
+
if (readLen == 0u) {
readLen = getsUSBUSART(readBuf, sizeof(readBuf));
}
@@ -125,16 +126,22 @@ echoState(void) {
// Handle "w" write eeprom command.
static State *
writeEepromState(void) {
- static State state = {idleState};
+ static State state;
+
// TODO
+
+ state.next = idleState;
return &state;
}
// Handle "r" read eeprom command.
static State *
readEepromState(void) {
- static State state = {idleState};
+ static State state;
+
// TODO
+
+ state.next = idleState;
return &state;
}