fix: broken build with ATmega88A and ATmega168A caused by toolchain
[pub/USBaspLoader.git] / firmware / bootloaderconfig.h
index f469f8d..e0ba814 100644 (file)
@@ -11,7 +11,7 @@
 
 #ifndef __bootloaderconfig_h_included__
 #define __bootloaderconfig_h_included__
-#include <avr/io.h>
+#include "../misc/iofixes.h"
 
 /*
 General Description:
@@ -57,7 +57,7 @@ these macros are defined, the boot loader usees them.
  * "B", the registers PORTB, PINB and DDRB will be used.
  */
 #ifndef USB_CFG_INTPORT_BIT
-  #if (defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__))
+  #if (defined(__AVR_ATmega640__) || defined (__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__))
     #define USB_CFG_INTPORT_BIT 0
   #else
     #define USB_CFG_INTPORT_BIT 2
@@ -334,8 +334,10 @@ these macros are defined, the boot loader usees them.
  * as soon as the programming software disconnects.
  */
 
-#ifndef BOOTLOADER_LOOPCYCLES_TIMEOUT
-#      define BOOTLOADER_LOOPCYCLES_TIMEOUT    0
+#ifdef CONFIG_BOOTLOADER_LOOPCYCLES_TIMEOUT
+#      define BOOTLOADER_LOOPCYCLES_TIMEOUT    (CONFIG_BOOTLOADER_LOOPCYCLES_TIMEOUT)
+#else 
+#      define BOOTLOADER_LOOPCYCLES_TIMEOUT    (0)
 #endif
 /* 
  * When greater than "0", "BOOTLOADER_LOOPCYCLES_TIMEOUT"
@@ -358,11 +360,55 @@ these macros are defined, the boot loader usees them.
  */
 
 #ifdef CONFIG_HAVE__BOOTLOADER_ALWAYSENTERPROGRAMMODE
+#      if (BOOTLOADER_CAN_EXIT)
+#              define BOOTLOADER_ALWAYSENTERPROGRAMMODE 1
+#      else
+#              define BOOTLOADER_ALWAYSENTERPROGRAMMODE 0
+#      endif
+#else
+#      define BOOTLOADER_ALWAYSENTERPROGRAMMODE 0
 #endif
 /*
  * Ignore bootLoaderCondition() (BUT NOT bootLoaderConditionSimple())
  * and always enter the program-mode.
  * This is helpful to emulate behaviour of Arduino bootloaders
+ * 
+ * However, this feature may be dangerous, since bootloader may never exit.
+ * So it is enabled, only if "CONFIG_NO__BOOTLOADER_CAN_EXIT" is disabled.
+ * 
+ */
+
+#ifdef CONFIG_HAVE__BOOTLOADER_IGNOREPROGBUTTON
+#      if ( (BOOTLOADER_ALWAYSENTERPROGRAMMODE) && (defined(BOOTLOADER_CAN_EXIT)) && (BOOTLOADER_LOOPCYCLES_TIMEOUT >= 8) )
+#              define BOOTLOADER_IGNOREPROGBUTTON      1
+#      else
+#              define BOOTLOADER_IGNOREPROGBUTTON      0
+#      endif
+#endif
+/*
+ * Generates an USBaspLoader without using the PROGBUTTON.
+ * It can be used to reduce the required PINcount for USBaspLoader
+ * on the MCU.
+ * However this feature is very dangerous, so it becomes only
+ * enabled, if "CONFIG_HAVE__BOOTLOADER_ALWAYSENTERPROGRAMMODE" is
+ * enabled and "CONFIG_NO__BOOTLOADER_CAN_EXIT" is disabled, too.
+ * Additionally "BOOTLOADER_LOOPCYCLES_TIMEOUT" must be greater 
+ * or equal than 8 (In order to give user enough time to program).
+ * 
+ * When active, "JUMPER_PORT" and "JUMPER_BIT" are ignored and
+ * can be soldered otherwise.
+ */
+
+#ifdef CONFIG_NO__BOOTLOADER_ADDITIONALDEVICEWAIT
+#      define HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT 0
+#else
+#      define HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT 50
+#endif
+/* 
+ * When enabling "HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT", then
+ * the bootloader will alway delay its bootup by the configured
+ * number of milliseconds.
+ * This gives the pullups additional time to charge up.
  */
 
 //#define SIGNATURE_BYTES             0x1e, 0x93, 0x07, 0     /* ATMega8 */
@@ -395,8 +441,11 @@ these macros are defined, the boot loader usees them.
 
 static inline void  bootLoaderInit(void)
 {
+#if (BOOTLOADER_IGNOREPROGBUTTON)
+#else
     PIN_DDR(JUMPER_PORT)  = 0;
     PIN_PORT(JUMPER_PORT) = (1<< PIN(JUMPER_PORT, JUMPER_BIT)); /* activate pull-up */
+#endif
 
 //     deactivated by Stephan - reset after each avrdude op is annoing!
 //     if(!(MCUCSR & (1 << EXTRF)))    /* If this was not an external reset, ignore */
@@ -405,11 +454,18 @@ static inline void  bootLoaderInit(void)
 
 static inline void  bootLoaderExit(void)
 {
+#if (BOOTLOADER_IGNOREPROGBUTTON)
+#else
     PIN_PORT(JUMPER_PORT) = 0;         /* undo bootLoaderInit() changes */
+#endif
 }
 
 
-#define bootLoaderConditionSimple()    ((PIN_PIN(JUMPER_PORT) & (1 << PIN(JUMPER_PORT, JUMPER_BIT))) == 0)
+#if (BOOTLOADER_IGNOREPROGBUTTON)
+#      define bootLoaderConditionSimple()      (false)
+#else
+#      define bootLoaderConditionSimple()      ((PIN_PIN(JUMPER_PORT) & (1 << PIN(JUMPER_PORT, JUMPER_BIT))) == 0)
+#endif
 
 #if (HAVE_BOOTLOADERENTRY_FROMSOFTWARE)
 /*
@@ -430,7 +486,7 @@ static inline void  bootLoaderExit(void)
 static volatile uint8_t __BOOTLOADERENTRY_FROMSOFTWARE__bootup_RAMEND_doesmatch __attribute__ ((section(".noinit")));
 static volatile uint8_t __BOOTLOADERENTRY_FROMSOFTWARE__bootup_MCUCSR __attribute__ ((section(".noinit")));
 
-#      ifdef CONFIG_HAVE__BOOTLOADER_ALWAYSENTERPROGRAMMODE
+#      if (BOOTLOADER_ALWAYSENTERPROGRAMMODE)
 #              define bootLoaderCondition()    (true)
 #      else
 static inline bool bootLoaderCondition(void)
@@ -446,7 +502,7 @@ static inline bool bootLoaderCondition(void)
 }
 #      endif
 #else
-#      ifdef CONFIG_HAVE__BOOTLOADER_ALWAYSENTERPROGRAMMODE
+#      if (BOOTLOADER_ALWAYSENTERPROGRAMMODE)
 #              define bootLoaderCondition()    (true)
 #      else
 #              define bootLoaderCondition      bootLoaderConditionSimple