From: Jonathan McDowell Date: Tue, 8 May 2018 20:45:13 +0000 (+0100) Subject: Reset 1-Wire state if we get a USB reset X-Git-Url: https://the.earth.li/gitweb/?p=temper-clone.git;a=commitdiff_plain;h=b45ff61935c58083c18d718c410604489080af76 Reset 1-Wire state if we get a USB reset A client can decide to reset us if we fail to reply to USB messages appropriately while doing the 1-Wire bits for temperature retrieval. This may leave us in the state were we have a message ready to go, but the client isn't going to read it. If we see a USB reset, reset our state and clear any indication that we have a message to go. --- diff --git a/libs-device/osccal.h b/libs-device/osccal.h index 3452aa7..a1fb2ef 100644 --- a/libs-device/osccal.h +++ b/libs-device/osccal.h @@ -43,7 +43,8 @@ deviation! All other frequency modules require at least 0.2% precision. #ifndef __ASSEMBLER__ void calibrateOscillatorASM(void); -#define USB_RESET_HOOK(resetStarts) if(!resetStarts){ calibrateOscillatorASM();} +void hadUsbReset(void); +#define USB_RESET_HOOK(resetStarts) if(!resetStarts){ calibrateOscillatorASM(); hadUsbReset();} #endif /* This function calibrates the RC oscillator so that the CPU runs at F_CPU. * It MUST be called immediately after the end of a USB RESET condition! diff --git a/main.c b/main.c index 0adfed8..61064a0 100644 --- a/main.c +++ b/main.c @@ -358,6 +358,13 @@ usbMsgLen_t usbFunctionWrite(uint8_t * data, uchar len) return 0; } +void hadUsbReset(void) +{ + /* Reset our state machine back to having nothing to send */ + temp_state = 0; + have_temp_int = false; +} + int main(void) { unsigned char i;