Fixed incorrect USB device state set when a suspended LUFA device is woken while...
[pub/USBasp.git] / LUFA / Drivers / Peripheral / AVR8 / TWI_AVR8.c
index b77aa08..e7629d5 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2011.
+     Copyright (C) Dean Camera, 2013.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2013  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -18,7 +18,7 @@
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
@@ -28,6 +28,9 @@
   this software.
 */
 
   this software.
 */
 
+#include "../../../Common/Common.h"
+#if (ARCH == ARCH_AVR8) && defined(TWCR)
+
 #define  __INCLUDE_FROM_TWI_C
 #include "../TWI.h"
 
 #define  __INCLUDE_FROM_TWI_C
 #include "../TWI.h"
 
@@ -42,7 +45,7 @@ uint8_t TWI_StartTransmission(const uint8_t SlaveAddress,
                TWCR = ((1 << TWINT) | (1 << TWSTA) | (1 << TWEN));
 
                TimeoutRemaining = (TimeoutMS * 100);
                TWCR = ((1 << TWINT) | (1 << TWSTA) | (1 << TWEN));
 
                TimeoutRemaining = (TimeoutMS * 100);
-               while (TimeoutRemaining-- && !(BusCaptured))
+               while (TimeoutRemaining && !(BusCaptured))
                {
                        if (TWCR & (1 << TWINT))
                        {
                {
                        if (TWCR & (1 << TWINT))
                        {
@@ -62,6 +65,7 @@ uint8_t TWI_StartTransmission(const uint8_t SlaveAddress,
                        }
 
                        _delay_us(10);
                        }
 
                        _delay_us(10);
+                       TimeoutRemaining--;
                }
 
                if (!(TimeoutRemaining))
                }
 
                if (!(TimeoutRemaining))
@@ -74,12 +78,13 @@ uint8_t TWI_StartTransmission(const uint8_t SlaveAddress,
                TWCR = ((1 << TWINT) | (1 << TWEN));
 
                TimeoutRemaining = (TimeoutMS * 100);
                TWCR = ((1 << TWINT) | (1 << TWEN));
 
                TimeoutRemaining = (TimeoutMS * 100);
-               while (TimeoutRemaining--)
+               while (TimeoutRemaining)
                {
                        if (TWCR & (1 << TWINT))
                          break;
 
                        _delay_us(10);
                {
                        if (TWCR & (1 << TWINT))
                          break;
 
                        _delay_us(10);
+                       TimeoutRemaining--;
                }
 
                if (!(TimeoutRemaining))
                }
 
                if (!(TimeoutRemaining))
@@ -201,3 +206,4 @@ uint8_t TWI_WritePacket(const uint8_t SlaveAddress,
        return ErrorCode;
 }
 
        return ErrorCode;
 }
 
+#endif