diff --git a/avr/main.c b/avr/main.c index 9b4a61b..c06762a 100644 --- a/avr/main.c +++ b/avr/main.c @@ -186,17 +186,19 @@ int main() { while (1) { uint8_t c = uart_getchar(NULL); - received++; - switch (state) { - case TABBY_COMMAND_NONE: + case TABBY_COMMAND_NONE: { state = c; - break; + continue; + } - case TABBY_COMMAND_SEND: - if (received == 2 || received == 3) { - buffer.len = (buffer.len >> 8) | (c << 8); + case TABBY_COMMAND_SEND: { + received++; + + if (received == 1 || received == 2) { + buffer.len <<= 8; + buffer.len |= c; } else { buffer.data[buffer.read++] = c; @@ -206,33 +208,37 @@ int main() { } break; + } case TABBY_COMMAND_CLOCK_SOURCE: switch (c) { - case TABBY_CLOCK_SOURCE_INTERNAL: + case TABBY_CLOCK_SOURCE_INTERNAL: { source = c; setup_clock_internal(speed); goto reset; + } - case TABBY_CLOCK_SOURCE_EXTERNAL: + case TABBY_CLOCK_SOURCE_EXTERNAL: { source = c; setup_clock_external(); goto reset; + } - default: + default: { goto reset; + } } - case TABBY_COMMAND_CLOCK_SPEED: + case TABBY_COMMAND_CLOCK_SPEED: { switch (c) { case TABBY_CLOCK_SPEED_8192HZ: case TABBY_CLOCK_SPEED_16384HZ: case TABBY_CLOCK_SPEED_262144HZ: - case TABBY_CLOCK_SPEED_524288HZ: + case TABBY_CLOCK_SPEED_524288HZ: { speed = c; if (source == TABBY_CLOCK_SOURCE_INTERNAL) { @@ -240,13 +246,16 @@ int main() { } goto reset; + } default: goto reset; } + } - default: - goto reset; + default: { + break; + } } continue;