]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Remove superfluous JTAG disable code (#6445)
authorfauxpark <fauxpark@gmail.com>
Wed, 21 Aug 2019 05:18:52 +0000 (15:18 +1000)
committerDrashna Jaelre <drashna@live.com>
Wed, 21 Aug 2019 05:18:52 +0000 (22:18 -0700)
* Remove superfluous JTAG disable code

* 32A has differently named register

* Accidentally some operators

* 32A also has different JTAG pins

* Wrap disable_jtag() in an ifndef

* Document this new define

* Rename the define, it conflicts with a LUFA thing

Also, move the ifndef wrapping to the call in keyboard_setup()

19 files changed:
docs/faq_debug.md
docs/zh-cn/faq_debug.md
keyboards/amj96/matrix.c
keyboards/clueboard/17/17.c
keyboards/clueboard/66/rev2/rev2.c
keyboards/clueboard/66_hotswap/prototype/prototype.c
keyboards/ergodone/matrix.c
keyboards/handwired/promethium/matrix.c
keyboards/hhkb/rn42/rn42.c
keyboards/hid_liber/matrix.c
keyboards/hotdox/matrix.c
keyboards/launchpad/rev1/rev1.c
keyboards/lets_split/sockets/sockets.h
keyboards/miniaxe/config.h
keyboards/sx60/matrix.c
keyboards/vitamins_included/matrix.c
keyboards/vitamins_included/rev1/rev1.h
tmk_core/common/keyboard.c
tmk_core/common/keyboard.h

index f6cc729b61236bf2b2104d54867cb3d4c3feb5b8..5cc20251d309442495d90b9bf9fc0f5ecc339bd2 100644 (file)
@@ -184,22 +184,15 @@ Pressing any key during sleep should wake host.
 
 Arduino Leonardo and micro have **ATMega32U4** and can be used for TMK, though Arduino bootloader may be a problem.
 
+## Enabling JTAG
 
-## Using PF4-7 Pins of USB AVR?
-You need to set JTD bit of MCUCR yourself to use PF4-7 as GPIO. Those pins are configured to serve JTAG function by default. MCUs like ATMega*U* or AT90USB* are affected with this.
+By default, the JTAG debugging interface is disabled as soon as the keyboard starts up. JTAG-capable MCUs come from the factory with the `JTAGEN` fuse set, and it takes over certain pins of the MCU that the board may be using for the switch matrix, LEDs, etc.
 
-If you are using Teensy this isn't needed. Teensy is shipped with JTAGEN fuse bit unprogrammed to disable the function.
+If you would like to keep JTAG enabled, just add the following to your `config.h`:
 
-See this code.
+```c
+#define NO_JTAG_DISABLE
 ```
-    // JTAG disable for PORT F. write JTD bit twice within four cycles.
-    MCUCR |= (1<<JTD);
-    MCUCR |= (1<<JTD);
-```
-https://github.com/tmk/tmk_keyboard/blob/master/keyboard/hbkb/matrix.c#L67
-
-And read **26.5.1 MCU Control Register – MCUCR** of ATMega32U4 datasheet.
-
 
 ## Adding LED Indicators of Lock Keys
 You need your own LED indicators for CapsLock, ScrollLock and NumLock? See this post.
index ca8b3fd25dc2e00dfc016397720e9816aa476a1b..a3cc7c510ca24238bf0fc3e8f2de0d88dce5908b 100644 (file)
@@ -173,23 +173,6 @@ EXTRAKEY_ENABLE = yes          # 音频控制和系统控制
 
 Arduino Leonardo和micro使用**ATMega32U4**,该芯片TMK可用,但Arduino的bootloader会导致问题。
 
-
-## 在USB AVR使用PF4-7针脚?
-你要置位MCUCR寄存器JTD位来将PF4-7设置为GPIO。这些针脚默认是JTAG功能。 像ATMega*U* or AT90USB*这样的MCU会受影响。
-
-如果是用Teensy的话就不需要了。Tennsy自带JTAGEN位未编程来失能该功能。
-<!--翻译问题:上句可能有错,原文为:Teensy is shipped with JTAGEN fuse bit unprogrammed to disable the function. -->
-代码如下。
-```
-    // F接口JTAG失能。在四个周期内写入两次JTD位。
-    MCUCR |= (1<<JTD);
-    MCUCR |= (1<<JTD);
-```
-https://github.com/tmk/tmk_keyboard/blob/master/keyboard/hbkb/matrix.c#L67
-
-阅读ATMega32U4的datasheet中的**26.5.1 MCU Control Register – MCUCR**。
-
-
 ## 为锁定键添加指示灯
 你要自制CapsLock, ScrollLock 和 NumLock指示灯?见下文。
 
index e41bbec728d308decfb5e1c622f7f9706b7ac5a7..5d00ea98f5a8a3c974b15253e786afefbfae13b0 100644 (file)
@@ -63,9 +63,6 @@ void matrix_init(void)
 #ifdef UART_RGB_ENABLE
     uart_rgb_init();
 #endif
-    // disable JTAG
-    MCUCR = _BV(JTD);
-    MCUCR = _BV(JTD);
 
     // 85 REST
     DDRD |= _BV(PD7);
index 627aa236ddb21239cae27109f242046d62d37c91..9e8ca644ec4fc11be8ae919f024804b3b750e2fb 100644 (file)
@@ -6,10 +6,6 @@ void matrix_init_kb(void) {
     // put your keyboard start-up code here
     // runs once when the firmware starts up
     matrix_init_user();
-
-    // JTAG disable for PORT F. write JTD bit twice within four cycles.
-    MCUCR |= (1<<JTD);
-    MCUCR |= (1<<JTD);
 };
 
 void led_set_kb(uint8_t usb_led) {
index 1a35b87b8409ff32e19d327d6fe8508762088cdd..d676b6d5fb4af8485e6543d79bbabc9ed46f663a 100644 (file)
@@ -8,10 +8,6 @@ void matrix_init_kb(void) {
        // runs once when the firmware starts up
        matrix_init_user();
        led_init_ports();
-
-    // JTAG disable for PORT F. write JTD bit twice within four cycles.
-    MCUCR |= (1<<JTD);
-    MCUCR |= (1<<JTD);
 }
 
 
index 991d4b8faea1fc481f03c5b9429f9b0b1f928cef..7c307be61ac4a066f4e2911038ab7eaddee27a79 100644 (file)
@@ -8,10 +8,6 @@ void matrix_init_kb(void) {
        // runs once when the firmware starts up
        matrix_init_user();
        led_init_ports();
-
-    // JTAG disable for PORT F. write JTD bit twice within four cycles.
-    MCUCR |= (1<<JTD);
-    MCUCR |= (1<<JTD);
 }
 
 
index 2eb8f24ba8bf12f38c1b9d82d5a034b127bd2365..4a8230aa81d778ca7519a468c896b4b069a21778 100644 (file)
@@ -77,10 +77,6 @@ uint8_t matrix_cols(void)
 
 void matrix_init(void)
 {
-  // disable JTAG
-  MCUCR = (1<<JTD);
-  MCUCR = (1<<JTD);
-
   unselect_rows();
   init_cols();
 
index 3b8e5af820a7717efe9caedb8a018119bfc581e1..b4a4c6396afe0174b16ea952630b13b2fc90a34a 100644 (file)
@@ -104,13 +104,6 @@ uint8_t matrix_cols(void) {
 }
 
 void matrix_init(void) {
-
-    // To use PORTF disable JTAG with writing JTD bit twice within four cycles.
-    #if  (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
-        MCUCR |= _BV(JTD);
-        MCUCR |= _BV(JTD);
-    #endif
-
     // initialize row and col
     unselect_rows();
     init_cols();
index 154da4e10103595cdfd8d331c65c00f4c09675d9..06665425cedc26addcf5effe4f5a74195fe5e635 100644 (file)
@@ -26,10 +26,6 @@ host_driver_t rn42_driver = {
 
 void rn42_init(void)
 {
-    // JTAG disable for PORT F. write JTD bit twice within four cycles.
-    MCUCR |= (1<<JTD);
-    MCUCR |= (1<<JTD);
-
     // PF7: BT connection control(high: connect, low: disconnect)
     rn42_autoconnect();
 
index de154890d540fc685caab92ba90d94c642e2da7f..05554a24c8ab370423cdf63af7b90df7234c1587 100755 (executable)
@@ -172,10 +172,6 @@ uint8_t matrix_cols(void)
 
 void matrix_init(void)
 {
-    // To use PORTF disable JTAG with writing JTD bit twice within four cycles.
-    MCUCR |= (1<<JTD);
-    MCUCR |= (1<<JTD);
-
     // initialize row and col
     setup_io_pins();
     setup_leds();
index 9d3a98db21af75af59debec64da3a3848f977e87..11a1142d41a952819f491253674a33366390ecfe 100644 (file)
@@ -77,10 +77,6 @@ uint8_t matrix_cols(void)
 
 void matrix_init(void)
 {
-  // disable JTAG
-  MCUCR = (1<<JTD);
-  MCUCR = (1<<JTD);
-
   unselect_rows();
   init_cols();
 
index a7aec80e10f7afd10441125555409a7484594737..cff4edf9f8744258fa52da6674fc5371747720c8 100644 (file)
@@ -1,14 +1,9 @@
 #include "launchpad.h"
 
 void matrix_init_kb(void) {
-       
-       // JTAG disable for PORT F. write JTD bit twice within four cycles.
-    MCUCR |= (1<<JTD);
-    MCUCR |= (1<<JTD);
-       
        // Undo init of RX LED, we use that port currently
        //DDRB &= ~(1<<0);
        
        matrix_init_user();
        
-};
\ No newline at end of file
+};
index 0ee93c0206a4825e22227588cad538a862f6ca9a..a1a3f00a0eb08b657e1b9b94f9834ce1d5f0b947 100644 (file)
@@ -1,5 +1,4 @@
 #pragma once
-#define DISABLE_JTAG // The keyboard uses PF4 and PF7, which are used by JTAG.
 
 #include "lets_split.h"
 
index db850971772f5286042ffc47a6c727c4843b8f10..b0b9d4c4755ec3fc26cb3b4a5437d5e5bf42cf20 100644 (file)
@@ -237,5 +237,3 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //#define EE_HANDS
 #define I2C_MASTER_LEFT
 //#define I2C_MASTER_RIGHT
-
-#define DISABLE_JTAG
index e8e9d6574e853553a1278a33a30e39be78b58aee..58647d13b088f2e8aa31c88725713bdf9bc977d4 100644 (file)
@@ -113,13 +113,6 @@ uint8_t matrix_cols(void) {
 }
 
 void matrix_init(void) {
-
-    /* To use PORTF disable JTAG with writing JTD bit twice within four cycles. */
-    #if  (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
-        MCUCR |= _BV(JTD);
-        MCUCR |= _BV(JTD);
-    #endif
-
     mcp23018_status = true;
 
     /* initialize row and col */
index 1f5071c693256e45f2dafb74d5497219e1d35528..d44e70f08ee6df82f1f46860c004190ac8a5aed2 100644 (file)
@@ -136,12 +136,6 @@ bool has_usb(void) {
 
 void matrix_init(void)
 {
-#ifdef DISABLE_JTAG
-  // JTAG disable for PORT F. write JTD bit twice within four cycles.
-  MCUCR |= (1<<JTD);
-  MCUCR |= (1<<JTD);
-#endif
-
     // initialize row and col
 #if (DIODE_DIRECTION == COL2ROW)
     unselect_rows();
index aa5029034993de1e7122b17855f98b727a7d6850..ee97e09cfdecdf26c9491adcdab26552d6591def 100644 (file)
@@ -1,6 +1,5 @@
 #ifndef REV1_H
 #define REV1_H
-#define DISABLE_JTAG // The keyboard uses PF4, PF5 and PF7, which are used by JTAG.
 #define EE_HANDS // This isn't optional for the vitamins included
 
 #include QMK_KEYBOARD_H
index 85d25254808946a0a627b35f8e2470278daf1a7f..8f0257cf66606de1f52489c52e5309c125ab2f42 100644 (file)
@@ -130,10 +130,15 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata)
 #endif
 
 void disable_jtag(void) {
-// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
-#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
+// To use PF4-7 (PC2-5 on ATmega32A), disable JTAG by writing JTD bit twice within four cycles.
+#if (defined(__AVR_AT90USB646__)  || defined(__AVR_AT90USB647__)  || \
+     defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || \
+     defined(__AVR_ATmega16U4__)  || defined(__AVR_ATmega32U4__))
     MCUCR |= _BV(JTD);
     MCUCR |= _BV(JTD);
+#elif defined(__AVR_ATmega32A__)
+    MCUCSR |= _BV(JTD);
+    MCUCSR |= _BV(JTD);
 #endif
 }
 
@@ -184,7 +189,9 @@ void keyboard_post_init_kb(void) {
  * FIXME: needs doc
  */
 void keyboard_setup(void) {
+#ifndef NO_JTAG_DISABLE
     disable_jtag();
+#endif
     matrix_setup();
     keyboard_pre_init_kb();
 }
index bf8b71fb78f74f9f7294d470211312890f62ad12..19f98c74ec770af90220ccf841073e2c95ea9b40 100644 (file)
@@ -57,8 +57,6 @@ static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) &&
     .time = (timer_read() | 1)                          \
 }
 
-void disable_jtag(void);
-
 /* it runs once at early stage of startup before keyboard_init. */
 void keyboard_setup(void);
 /* it runs once after initializing host side protocol, debug and MCU peripherals. */