introduce new feature: BOOTLOADER_IGNOREPROGBUTTON
authorStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Thu, 12 Sep 2013 13:24:18 +0000 (15:24 +0200)
committerStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Thu, 12 Sep 2013 14:26:58 +0000 (14:26 +0000)
"CONFIG_HAVE__BOOTLOADER_IGNOREPROGBUTTON" 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.

Default if off. But the Option can be enabled by adding
"-DCONFIG_HAVE__BOOTLOADER_IGNOREPROGBUTTON" to the DEFINES variable of
Makefile.inc

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
firmware/bootloaderconfig.h
firmware/main.c

index f469f8d..58b44ca 100644 (file)
@@ -365,6 +365,27 @@ these macros are defined, the boot loader usees them.
  * This is helpful to emulate behaviour of Arduino bootloaders
  */
 
+#ifdef CONFIG_HAVE__BOOTLOADER_IGNOREPROGBUTTON
+#      if ( (defined(CONFIG_HAVE__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.
+ */
+
 //#define SIGNATURE_BYTES             0x1e, 0x93, 0x07, 0     /* ATMega8 */
 /* This macro defines the signature bytes returned by the emulated USBasp to
  * the programmer software. They should match the actual device at least in
@@ -395,8 +416,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 +429,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)
 /*
index d08ed23..038368c 100644 (file)
@@ -783,6 +783,21 @@ int __attribute__((__noreturn__)) main(void)
 #endif
             usbPoll();
 #if BOOTLOADER_CAN_EXIT
+#if BOOTLOADER_IGNOREPROGBUTTON
+  /* 
+   * remove the high nibble as it would be subtracted due to:
+   * "(!bootLoaderConditionSimple())"
+   */ 
+#if USE_EXCESSIVE_ASSEMBLER
+asm  volatile  (
+  "andi                %[sil],         0x0f\n\t"
+  : [sil]        "+d" (stayinloader)
+  :
+);
+#else
+  stayinloader &= 0x0f;
+#endif
+#else
 #if USE_EXCESSIVE_ASSEMBLER
 asm  volatile  (
   "cpi         %[sil],         0x10\n\t"
@@ -814,6 +829,7 @@ asm  volatile  (
        }
 #endif
 #endif
+#endif
 
 #if BOOTLOADER_CAN_EXIT
         }while (stayinloader); /* main event loop, if BOOTLOADER_CAN_EXIT*/