You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
2.7 KiB

  1. /* Copyright 2021 QMK
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "bootloader.h"
  17. #include <avr/interrupt.h>
  18. #include <util/delay.h>
  19. __attribute__((weak)) void bootloader_jump(void) {
  20. // http://www.pjrc.com/teensy/jump_to_bootloader.html
  21. cli();
  22. // disable watchdog, if enabled (it's not)
  23. // disable all peripherals
  24. // a shutdown call might make sense here
  25. UDCON = 1;
  26. USBCON = (1 << FRZCLK); // disable USB
  27. UCSR1B = 0;
  28. _delay_ms(5);
  29. #if defined(__AVR_AT90USB162__) // Teensy 1.0
  30. EIMSK = 0;
  31. PCICR = 0;
  32. SPCR = 0;
  33. ACSR = 0;
  34. EECR = 0;
  35. TIMSK0 = 0;
  36. TIMSK1 = 0;
  37. UCSR1B = 0;
  38. DDRB = 0;
  39. DDRC = 0;
  40. DDRD = 0;
  41. PORTB = 0;
  42. PORTC = 0;
  43. PORTD = 0;
  44. asm volatile("jmp 0x3E00");
  45. #elif defined(__AVR_ATmega32U4__) // Teensy 2.0
  46. EIMSK = 0;
  47. PCICR = 0;
  48. SPCR = 0;
  49. ACSR = 0;
  50. EECR = 0;
  51. ADCSRA = 0;
  52. TIMSK0 = 0;
  53. TIMSK1 = 0;
  54. TIMSK3 = 0;
  55. TIMSK4 = 0;
  56. UCSR1B = 0;
  57. TWCR = 0;
  58. DDRB = 0;
  59. DDRC = 0;
  60. DDRD = 0;
  61. DDRE = 0;
  62. DDRF = 0;
  63. TWCR = 0;
  64. PORTB = 0;
  65. PORTC = 0;
  66. PORTD = 0;
  67. PORTE = 0;
  68. PORTF = 0;
  69. asm volatile("jmp 0x7E00");
  70. #elif defined(__AVR_AT90USB646__) // Teensy++ 1.0
  71. EIMSK = 0;
  72. PCICR = 0;
  73. SPCR = 0;
  74. ACSR = 0;
  75. EECR = 0;
  76. ADCSRA = 0;
  77. TIMSK0 = 0;
  78. TIMSK1 = 0;
  79. TIMSK2 = 0;
  80. TIMSK3 = 0;
  81. UCSR1B = 0;
  82. TWCR = 0;
  83. DDRA = 0;
  84. DDRB = 0;
  85. DDRC = 0;
  86. DDRD = 0;
  87. DDRE = 0;
  88. DDRF = 0;
  89. PORTA = 0;
  90. PORTB = 0;
  91. PORTC = 0;
  92. PORTD = 0;
  93. PORTE = 0;
  94. PORTF = 0;
  95. asm volatile("jmp 0xFC00");
  96. #elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0
  97. EIMSK = 0;
  98. PCICR = 0;
  99. SPCR = 0;
  100. ACSR = 0;
  101. EECR = 0;
  102. ADCSRA = 0;
  103. TIMSK0 = 0;
  104. TIMSK1 = 0;
  105. TIMSK2 = 0;
  106. TIMSK3 = 0;
  107. UCSR1B = 0;
  108. TWCR = 0;
  109. DDRA = 0;
  110. DDRB = 0;
  111. DDRC = 0;
  112. DDRD = 0;
  113. DDRE = 0;
  114. DDRF = 0;
  115. PORTA = 0;
  116. PORTB = 0;
  117. PORTC = 0;
  118. PORTD = 0;
  119. PORTE = 0;
  120. PORTF = 0;
  121. asm volatile("jmp 0x1FC00");
  122. #endif
  123. }