├── ArduinoUSBLinker.ino ├── LICENSE.TXT ├── README.md └── Serial.patch /ArduinoUSBLinker.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012-2013 Chris Osgood 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. No 7 | other versions are acceptable. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 | 02110-1301, USA. 18 | */ 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | 22 | // Check for MultiWii 23 | #if defined(MSP_VERSION) 24 | #define MULTIWII 25 | #else 26 | #include 27 | #endif 28 | 29 | #define AUL_SERIALRATE 19200 30 | 31 | #define AUL_MIN_BITTIME 4 32 | #define AUL_MAX_BITTIME 136 33 | #define AUL_DEFAULT_BITTIME 32 34 | 35 | #define AUL_MICROS_TO_TICKS(x) ((x) * (F_CPU / 1000000) / g_timerScale) 36 | #define AUL_MICROS_TO_TICKS_R(x) ((x) * g_timerScale / (F_CPU / 1000000)) 37 | 38 | #if defined(__AVR_ATmega8__) 39 | #define AUL_SET_TIMER_MODE TCCR2 = g_timerConfig 40 | #else 41 | #define AUL_SET_TIMER_MODE TCCR2B = g_timerConfig 42 | #endif 43 | 44 | // Default PD2/INT0 45 | #define AUL_DEFAULT_PIN 18 46 | 47 | #define AUL_BUFSIZE 300 48 | 49 | #define AUL_SERIALTIMEOUT ((F_CPU >> 7) / (9600 >> 4)) 50 | 51 | #define AUL_PININPUT ((*g_signalDDR) &= ~(g_signalPinPortNum)) 52 | #define AUL_PINOUTPUT ((*g_signalDDR) |= (g_signalPinPortNum)) 53 | #define AUL_PINHIGH ((*g_signalPORT) |= (g_signalPinPortNum)) 54 | #define AUL_PINLOW ((*g_signalPORT) &= ~(g_signalPinPortNum)) 55 | 56 | #define AUL_PINREAD ((*g_signalPIN) & (g_signalPinPortNum)) 57 | 58 | #define AUL_DELAYTICKS(x) \ 59 | TCNT2 = 0; \ 60 | while (TCNT2 < (x)); 61 | 62 | #if defined(__AVR_ATmega8__) 63 | #define AUL_SYNC_PRESCALER \ 64 | SFIOR = (1 << PSR2); \ 65 | while (SFIOR & (1 << PSR2)); 66 | #else 67 | #define AUL_SYNC_PRESCALER \ 68 | GTCCR = (1 << PSRASY); \ 69 | while (GTCCR & (1 << PSRASY)); 70 | #endif 71 | 72 | // Save space on MultWii since baud rate changes are not supported and it is the 73 | // only thing that requires a value greater than uint8 74 | #if defined(MULTIWII) 75 | #define AUL_ASCII_INT_TYPE uint8_t 76 | #else 77 | #define AUL_ASCII_INT_TYPE uint32_t 78 | #endif 79 | 80 | #define AUL_EEPROM_PIN 4 81 | #define AUL_EEPROM_BITTIME 5 82 | #define AUL_EEPROM_BAUD 6 83 | 84 | /////////////////////////////////////////////////////////////////////////////// 85 | // Globals 86 | /////////////////////////////////////////////////////////////////////////////// 87 | 88 | static uint8_t g_timerConfig; 89 | static uint16_t g_timerScale; 90 | 91 | // Approximate microseconds for each bit when sending 92 | static uint8_t g_bitTimeSend; 93 | static uint8_t g_bitTimeSendHalf; 94 | 95 | // Calculated leader timing for receive 96 | static uint8_t g_bitTime, g_shortBitTime; 97 | 98 | static volatile uint8_t* g_signalDDR; 99 | static volatile uint8_t* g_signalPORT; 100 | static volatile uint8_t* g_signalPIN; 101 | static int8_t g_signalPinPortNum, g_signalPinNum; 102 | 103 | #if defined(MULTIWII) 104 | static uint32_t g_baudRate = 0; 105 | #else 106 | static uint32_t g_baudRate = AUL_SERIALRATE; 107 | #endif 108 | 109 | /////////////////////////////////////////////////////////////////////////////// 110 | // stdlib type utility functions (mostly to save space) 111 | /////////////////////////////////////////////////////////////////////////////// 112 | 113 | // int to ASCII base 10 114 | // Returns the address of the null terminator 115 | static char* AUL_itoa(AUL_ASCII_INT_TYPE n, char *b) 116 | { 117 | uint8_t i = 0, s; 118 | 119 | do { 120 | s = n % 10; 121 | n = n / 10; 122 | b[i++] = '0' + s; 123 | } while (n > 0); 124 | 125 | b[i] = '\0'; 126 | 127 | strrev(b); 128 | 129 | return &b[i]; 130 | } 131 | 132 | // ASCII to int base 10 133 | static AUL_ASCII_INT_TYPE AUL_atoi(const char* s) 134 | { 135 | AUL_ASCII_INT_TYPE b = 0; 136 | while (*s) b = (b << 3) + (b << 1) + (*s++ - '0'); 137 | return(b); 138 | } 139 | 140 | /////////////////////////////////////////////////////////////////////////////// 141 | // Serial port. MultiWii helpers. 142 | /////////////////////////////////////////////////////////////////////////////// 143 | 144 | #if !defined(MULTIWII) 145 | 146 | #define AUL_SerialInit(x) Serial.begin(g_baudRate) 147 | #define AUL_SerialAvailable() Serial.available() 148 | #define AUL_SerialRead() Serial.read() 149 | #define AUL_SerialWrite(x) Serial.write(x) 150 | #define AUL_SerialWriteBuf(x,y) Serial.write(x,y) 151 | #define AUL_SerialWriteStr(x) Serial.write((const char*)x) 152 | 153 | #else // MULTIWII 154 | 155 | static volatile uint8_t* g_serialUCSRA; 156 | static volatile uint8_t* g_serialUDR; 157 | static uint8_t g_serialRXC, g_serialUDRE; 158 | 159 | static void AUL_SerialInit(uint8_t port) 160 | { 161 | #define AUL_INIT_PORT(x) \ 162 | UCSR##x##C = (1 << UCSZ##x##1) | (1 << UCSZ##x##0); \ 163 | UCSR##x##B = (1 << RXEN##x) | (1 << TXEN##x); \ 164 | g_serialUCSRA = &UCSR##x##A; \ 165 | g_serialUDR = &UDR##x; \ 166 | g_serialRXC = (1 << RXC##x); \ 167 | g_serialUDRE = (1 << UDRE##x); 168 | 169 | switch (port) 170 | { 171 | case 0: 172 | AUL_INIT_PORT(0) 173 | break; 174 | #if defined(UBRR1H) 175 | case 1: 176 | AUL_INIT_PORT(1) 177 | break; 178 | #endif 179 | #if defined(UBRR2H) 180 | case 2: 181 | AUL_INIT_PORT(2) 182 | break; 183 | #endif 184 | #if defined(UBRR3H) 185 | case 3: 186 | AUL_INIT_PORT(3) 187 | break; 188 | #endif 189 | #if defined(UBRR4H) 190 | case 4: 191 | AUL_INIT_PORT(4) 192 | break; 193 | #endif 194 | default: 195 | break; 196 | } 197 | } 198 | 199 | #define AUL_SerialAvailable() \ 200 | ((*g_serialUCSRA) & g_serialRXC) 201 | 202 | #define AUL_SerialRead() \ 203 | (*g_serialUDR) 204 | 205 | #define AUL_SerialWrite(x) \ 206 | { while (!((*g_serialUCSRA) & g_serialUDRE)); (*g_serialUDR) = (x); } 207 | 208 | static void AUL_SerialWriteBuf(const uint8_t* b, int16_t len) 209 | { 210 | int16_t i; 211 | for (i = 0; i < len; i++) 212 | AUL_SerialWrite(b[i]); 213 | } 214 | 215 | static void AUL_SerialWriteStr(const char* b) 216 | { 217 | int16_t i; 218 | for (i = 0; b[i] != '\0'; i++) 219 | AUL_SerialWrite(b[i]); 220 | } 221 | 222 | #endif // MULTIWII 223 | 224 | /////////////////////////////////////////////////////////////////////////////// 225 | // Signal pin 226 | /////////////////////////////////////////////////////////////////////////////// 227 | 228 | // Clear all timers and PWM settings 229 | static void DisableAllTimers() 230 | { 231 | #define AUL_RESET_PORT(x) \ 232 | TCCR##x##B = 0; \ 233 | TCCR##x##A = 0; 234 | 235 | // For mega8 and similar 236 | #if defined(TCCR0) 237 | TCCR0 = 0; 238 | #endif 239 | #if defined(TCCR1) 240 | TCCR1 = 0; 241 | #endif 242 | #if defined(TCCR2) 243 | TCCR2 = 0; 244 | #endif 245 | 246 | #if defined(TCCR0B) 247 | AUL_RESET_PORT(0) 248 | #endif 249 | #if defined(TCCR1B) 250 | AUL_RESET_PORT(1) 251 | #endif 252 | #if defined(TCCR2B) 253 | AUL_RESET_PORT(2) 254 | #endif 255 | #if defined(TCCR3B) 256 | AUL_RESET_PORT(3) 257 | #endif 258 | #if defined(TCCR4B) 259 | AUL_RESET_PORT(4) 260 | #endif 261 | #if defined(TCCR5B) 262 | AUL_RESET_PORT(5) 263 | #endif 264 | #if defined(TCCR6B) 265 | AUL_RESET_PORT(6) 266 | #endif 267 | } 268 | 269 | static void SignalPinStatus(char* buf) 270 | { 271 | #define AUL_WRITE_PORT_INFO(x) \ 272 | *pos++ = #x[0]; \ 273 | pos = AUL_itoa(pincnt, pos); \ 274 | *pos++ = ':'; \ 275 | pincnt += 8; 276 | 277 | char* pos = buf; 278 | int8_t pincnt = 0; 279 | 280 | pos[0] = 'P'; 281 | pos[1] = 'I'; 282 | pos[2] = 'N'; 283 | pos[3] = 'S'; 284 | pos[4] = ':'; 285 | pos += 5; 286 | 287 | #if defined(PORTB) 288 | AUL_WRITE_PORT_INFO(B) 289 | #endif 290 | #if defined(PORTC) 291 | AUL_WRITE_PORT_INFO(C) 292 | #endif 293 | #if defined(PORTD) 294 | AUL_WRITE_PORT_INFO(D) 295 | #endif 296 | #if defined(PORTE) 297 | AUL_WRITE_PORT_INFO(E) 298 | #endif 299 | #if defined(PORTF) 300 | AUL_WRITE_PORT_INFO(F) 301 | #endif 302 | #if defined(PORTG) 303 | AUL_WRITE_PORT_INFO(G) 304 | #endif 305 | #if defined(PORTH) 306 | AUL_WRITE_PORT_INFO(H) 307 | #endif 308 | #if defined(PORTI) 309 | AUL_WRITE_PORT_INFO(I) 310 | #endif 311 | #if defined(PORTJ) 312 | AUL_WRITE_PORT_INFO(J) 313 | #endif 314 | #if defined(PORTK) 315 | AUL_WRITE_PORT_INFO(K) 316 | #endif 317 | #if defined(PORTL) 318 | AUL_WRITE_PORT_INFO(L) 319 | #endif 320 | 321 | #if defined(PORTA) 322 | AUL_WRITE_PORT_INFO(A) 323 | #endif 324 | 325 | *pos = '\0'; 326 | } 327 | 328 | static void SignalPinInit(int8_t pin) 329 | { 330 | #define AUL_SETUP_PORT(x) \ 331 | if (pin < (pincnt += 8)) \ 332 | { \ 333 | g_signalDDR = &DDR##x; \ 334 | g_signalPORT = &PORT##x; \ 335 | g_signalPIN = &PIN##x; \ 336 | g_signalPinPortNum = (1 << (pin - (pincnt - 8))); \ 337 | goto finished; \ 338 | } 339 | 340 | int8_t pincnt = 0; 341 | 342 | g_signalPinNum = pin; 343 | 344 | #if defined(PORTB) 345 | AUL_SETUP_PORT(B); 346 | #endif 347 | #if defined(PORTC) 348 | AUL_SETUP_PORT(C); 349 | #endif 350 | #if defined(PORTD) 351 | AUL_SETUP_PORT(D); 352 | #endif 353 | #if defined(PORTE) 354 | AUL_SETUP_PORT(E); 355 | #endif 356 | #if defined(PORTF) 357 | AUL_SETUP_PORT(F); 358 | #endif 359 | #if defined(PORTG) 360 | AUL_SETUP_PORT(G); 361 | #endif 362 | #if defined(PORTH) 363 | AUL_SETUP_PORT(H); 364 | #endif 365 | #if defined(PORTI) 366 | AUL_SETUP_PORT(I); 367 | #endif 368 | #if defined(PORTJ) 369 | AUL_SETUP_PORT(J); 370 | #endif 371 | #if defined(PORTK) 372 | AUL_SETUP_PORT(K); 373 | #endif 374 | #if defined(PORTL) 375 | AUL_SETUP_PORT(L); 376 | #endif 377 | 378 | #if defined(PORTA) 379 | AUL_SETUP_PORT(A); 380 | #endif 381 | 382 | finished: 383 | AUL_PINHIGH; // Enable pull-up 384 | AUL_PININPUT; 385 | } 386 | 387 | /////////////////////////////////////////////////////////////////////////////// 388 | // SENDING on signal pin 389 | /////////////////////////////////////////////////////////////////////////////// 390 | 391 | static void SendByte(uint8_t b) 392 | { 393 | uint8_t i; 394 | for (i = 1; i; i <<= 1) 395 | { 396 | if (b & i) 397 | { 398 | AUL_PINHIGH; 399 | AUL_DELAYTICKS(g_bitTimeSend); 400 | AUL_PINLOW; 401 | AUL_DELAYTICKS(g_bitTimeSend); 402 | } 403 | else 404 | { 405 | AUL_PINHIGH; 406 | AUL_DELAYTICKS(g_bitTimeSendHalf); 407 | AUL_PINLOW; 408 | AUL_DELAYTICKS(g_bitTimeSendHalf); 409 | AUL_PINHIGH; 410 | AUL_DELAYTICKS(g_bitTimeSendHalf); 411 | AUL_PINLOW; 412 | AUL_DELAYTICKS(g_bitTimeSendHalf); 413 | } 414 | } 415 | } 416 | 417 | /////////////////////////////////////////////////////////////////////////////// 418 | // RECEIVE on signal pin 419 | /////////////////////////////////////////////////////////////////////////////// 420 | 421 | #define AUL_SPINPINHIGH \ 422 | TCNT2 = 0; \ 423 | while (AUL_PINREAD) { if (TCNT2 > 250) goto timeout; } 424 | 425 | #define AUL_SPINPINLOW \ 426 | TCNT2 = 0; \ 427 | while (!AUL_PINREAD) { if (TCNT2 > 250) goto timeout; } 428 | 429 | #define AUL_NT_SPINPINHIGH \ 430 | while (AUL_PINREAD) { if (TCNT2 > 250) goto timeout; } 431 | 432 | #define AUL_NT_SPINPINLOW \ 433 | while (!AUL_PINREAD) { if (TCNT2 > 250) goto timeout; } 434 | 435 | #define AUL_READBIT \ 436 | AUL_SPINPINHIGH \ 437 | AUL_NT_SPINPINLOW \ 438 | if (TCNT2 <= g_shortBitTime) \ 439 | { \ 440 | AUL_SPINPINHIGH \ 441 | AUL_NT_SPINPINLOW \ 442 | b = 0; \ 443 | } \ 444 | else \ 445 | b = 1; 446 | 447 | static int8_t ReadLeader() 448 | { 449 | uint8_t i; 450 | 451 | // Skip the first few to let things stabilize 452 | for (i = 0; i < 9; i++) 453 | { 454 | AUL_SPINPINHIGH 455 | AUL_NT_SPINPINLOW 456 | } 457 | 458 | #ifndef AUL_FIXED_TIMING 459 | // Calculate timing from header 460 | AUL_SPINPINHIGH 461 | AUL_NT_SPINPINLOW 462 | g_bitTime = TCNT2; 463 | g_shortBitTime = (g_bitTime >> 1) + (g_bitTime >> 2); 464 | #else 465 | // Use fixed timing 466 | g_bitTime = g_bitTimeSend << 1; 467 | g_shortBitTime = g_bitTimeSend + g_bitTimeSendHalf; 468 | #endif 469 | 470 | // Read until we get a 0 bit 471 | while (1) 472 | { 473 | uint8_t b; 474 | AUL_READBIT // Sets b to the bit value 475 | 476 | if (!b) 477 | return 0; 478 | } 479 | 480 | timeout: 481 | return -1; 482 | } 483 | 484 | static void SetBitTime(uint16_t t) 485 | { 486 | if (t < AUL_MIN_BITTIME) 487 | t = AUL_MIN_BITTIME; 488 | else if (t > AUL_MAX_BITTIME) 489 | t = AUL_MAX_BITTIME; 490 | 491 | if (t * (F_CPU / 1000000) < 242) 492 | { 493 | g_timerScale = 2; 494 | g_timerConfig = (1 << CS20); 495 | } 496 | else if (t * (F_CPU / 1000000) / 8 < 242) 497 | { 498 | g_timerScale = 16; 499 | g_timerConfig = (1 << CS21); 500 | } 501 | else if (t * (F_CPU / 1000000) / 32 < 242) 502 | { 503 | g_timerScale = 64; 504 | g_timerConfig = (1 << CS21) | (1 << CS20); 505 | } 506 | else 507 | { 508 | return; // invalid time, no change 509 | } 510 | 511 | g_bitTimeSend = AUL_MICROS_TO_TICKS(t); 512 | g_bitTimeSendHalf = (g_bitTimeSend >> 1); 513 | } 514 | 515 | #if !defined(MULTIWII) 516 | static uint32_t EERead32(int pos) 517 | { 518 | uint32_t value; 519 | ((char*)&value)[0] = EEPROM.read(pos); 520 | ((char*)&value)[1] = EEPROM.read(pos + 1); 521 | ((char*)&value)[2] = EEPROM.read(pos + 2); 522 | ((char*)&value)[3] = EEPROM.read(pos + 3); 523 | return value; 524 | } 525 | 526 | static void EEWrite32(int pos, uint32_t value) 527 | { 528 | EEPROM.write(pos, ((char*)&value)[0]); 529 | EEPROM.write(pos + 1, ((char*)&value)[1]); 530 | EEPROM.write(pos + 2, ((char*)&value)[2]); 531 | EEPROM.write(pos + 3, ((char*)&value)[3]); 532 | } 533 | #endif // !MULTIWII 534 | 535 | /////////////////////////////////////////////////////////////////////////////// 536 | // Main 537 | /////////////////////////////////////////////////////////////////////////////// 538 | 539 | void AUL_loop(uint8_t port) 540 | { 541 | // Disable interrupts and timers 542 | cli(); 543 | DisableAllTimers(); 544 | 545 | #if defined(MULTIWII) 546 | #if defined(BUZZERPIN_OFF) 547 | BUZZERPIN_OFF; 548 | #endif 549 | #if defined(LEDPIN_OFF) 550 | LEDPIN_OFF; 551 | #endif 552 | #endif 553 | 554 | #if defined(MULTIWII) 555 | AUL_SerialInit(port); 556 | SetBitTime(AUL_DEFAULT_BITTIME); 557 | SignalPinInit(AUL_DEFAULT_PIN); 558 | #else 559 | if (EEPROM.read(0) != 'a' || 560 | EEPROM.read(1) != 'u' || 561 | EEPROM.read(2) != 'l') 562 | { 563 | EEPROM.write(0, 'a'); 564 | EEPROM.write(1, 'u'); 565 | EEPROM.write(2, 'l'); 566 | EEPROM.write(3, 1); // version 567 | EEPROM.write(AUL_EEPROM_PIN, AUL_DEFAULT_PIN); 568 | EEPROM.write(AUL_EEPROM_BITTIME, AUL_DEFAULT_BITTIME); 569 | EEWrite32(AUL_EEPROM_BAUD, AUL_SERIALRATE); 570 | } 571 | 572 | SignalPinInit(EEPROM.read(AUL_EEPROM_PIN)); 573 | SetBitTime(EEPROM.read(AUL_EEPROM_BITTIME)); 574 | 575 | g_baudRate = EERead32(AUL_EEPROM_BAUD); 576 | AUL_SerialInit(port); 577 | 578 | sei(); // Re-enable interrupts for Serial 579 | #endif 580 | 581 | // Set timer2 to count ticks 582 | AUL_SET_TIMER_MODE; 583 | 584 | // The buffer always has the leader at the start 585 | uint8_t buf[AUL_BUFSIZE] = { 0xFF, 0xFF, 0x7F }; 586 | uint8_t lastPin = 0; 587 | int16_t buflen, i; 588 | 589 | while (1) 590 | { 591 | if (AUL_SerialAvailable()) 592 | { 593 | buflen = 3; 594 | buf[buflen++] = AUL_SerialRead(); 595 | 596 | // Temporarily set timer2 to count ticks/128 597 | #if defined(__AVR_ATmega8__) 598 | TCCR2 = (1 << CS22) | (1 << CS20); 599 | #else 600 | TCCR2B = (1 << CS22) | (1 << CS20); 601 | #endif 602 | AUL_SYNC_PRESCALER; 603 | TCNT2 = 0; 604 | // Buffer data until the serial timeout 605 | do { 606 | if (AUL_SerialAvailable()) 607 | { 608 | buf[buflen++] = AUL_SerialRead(); 609 | TCNT2 = 0; 610 | } 611 | } while (TCNT2 < AUL_SERIALTIMEOUT); 612 | 613 | // Set timer2 back to normal 614 | AUL_SET_TIMER_MODE; 615 | 616 | if (buf[3] == '$' && buf[4] == 'M' && buf[5] == '<') 617 | { 618 | #if !defined(MULTIWII) 619 | int8_t setbaud = 0; 620 | #endif 621 | 622 | buf[buflen] = '\0'; 623 | 624 | switch(buf[6]) 625 | { 626 | case 'B': { // BITTIME 627 | SetBitTime(AUL_atoi((const char*)&buf[7])); 628 | break; } 629 | case 'P': // SELECT PORT 630 | SignalPinInit(AUL_atoi((const char*)&buf[7])); 631 | break; 632 | #if !defined(MULTIWII) 633 | case 'R': // BAUD RATE 634 | g_baudRate = AUL_atoi((const char*)&buf[7]); 635 | 636 | if (g_baudRate < 9600) 637 | g_baudRate = 9600; 638 | 639 | setbaud = 1; 640 | break; 641 | case 'W': // WRITE EEPROM settings 642 | EEPROM.write(AUL_EEPROM_PIN, g_signalPinNum); 643 | EEPROM.write(AUL_EEPROM_BITTIME, AUL_MICROS_TO_TICKS_R(g_bitTimeSend)); 644 | EEWrite32(AUL_EEPROM_BAUD, g_baudRate); 645 | AUL_SerialWriteStr("saved:"); 646 | break; 647 | #endif // !MULTIWII 648 | default: 649 | break; 650 | } 651 | 652 | // Send status afterwards 653 | char* pos = (char*)&buf[3]; 654 | *pos++ = 'P'; 655 | pos = AUL_itoa(g_signalPinNum, pos); 656 | pos[0] = ':'; 657 | pos[1] = 'B'; 658 | pos += 2; 659 | pos = AUL_itoa(AUL_MICROS_TO_TICKS_R(g_bitTimeSend), pos); 660 | pos[0] = ':'; 661 | pos[1] = 'R'; 662 | pos += 2; 663 | pos = AUL_itoa(g_baudRate, pos); 664 | *pos++ = ':'; 665 | 666 | SignalPinStatus(pos); 667 | 668 | AUL_SerialWriteStr((const char*)&buf[3]); 669 | AUL_SerialWrite('\n'); 670 | 671 | #if !defined(MULTIWII) 672 | if (setbaud) 673 | { 674 | // Arduino Serial.flush does not work correctly 675 | Serial.flush(); 676 | 677 | // Temporarily set timer2 to count ticks/128 678 | #if defined(__AVR_ATmega8__) 679 | TCCR2 = (1 << CS22) | (1 << CS20); 680 | #else 681 | TCCR2B = (1 << CS22) | (1 << CS20); 682 | #endif 683 | AUL_DELAYTICKS(AUL_SERIALTIMEOUT); 684 | AUL_DELAYTICKS(AUL_SERIALTIMEOUT); 685 | AUL_SET_TIMER_MODE; 686 | 687 | AUL_SerialInit(port); 688 | } 689 | #endif // !MULTIWII 690 | } 691 | else 692 | { 693 | AUL_PINOUTPUT; 694 | AUL_SYNC_PRESCALER; 695 | 696 | // Send data over signal pin 697 | for (i = 0; i < buflen; i++) 698 | SendByte(buf[i]); 699 | 700 | // Trailer 701 | AUL_PINHIGH; 702 | AUL_DELAYTICKS(g_bitTimeSendHalf); 703 | 704 | AUL_PININPUT; // Pull-up is enabled from previous PINHIGH 705 | lastPin = 1; 706 | } 707 | } 708 | else 709 | { 710 | // Here we look for a low to high transition on the signal pin 711 | uint8_t curPin = AUL_PINREAD; 712 | 713 | if (!lastPin && curPin) 714 | { 715 | AUL_SYNC_PRESCALER; 716 | 717 | // Buffer data from signal pin then write to serial port 718 | if (ReadLeader() == 0) 719 | { 720 | uint8_t i, byt, b; 721 | buflen = 3; 722 | 723 | // Read bytes until timeout 724 | while (1) 725 | { 726 | for (i = 0, byt = 0; i < 8; i++) 727 | { 728 | AUL_READBIT // Sets b to the bit value 729 | byt |= b << i; 730 | } 731 | 732 | buf[buflen++] = byt; 733 | } 734 | 735 | timeout: 736 | AUL_SerialWriteBuf(&buf[3], buflen - 3); 737 | } 738 | } 739 | 740 | lastPin = curPin; 741 | } 742 | } 743 | } 744 | 745 | #if !defined(MULTIWII) 746 | 747 | int main(int argc, char* argv[]) 748 | { 749 | AUL_loop(0); 750 | return 0; 751 | } 752 | 753 | #endif // !MULTIWII 754 | 755 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ArduinoUSBLinker 2 | ================ 3 | 4 | ** WARNING ** 5 | Always use great care when working with powered ESC's that are connected 6 | to motors. Especially when reflashing firmware and reseting devices it is 7 | easily possible to get a situation where the motors start running on their 8 | own. 9 | 10 | To use: 11 | 12 | * Load this sketch on to your Arduino or similar with at least 512 bytes 13 | RAM. 14 | 15 | * Hook up the serial port/USB from the Arduino to your computer. 16 | 17 | * Make sure the ESC and Arduino have a common ground (GND) connection. 18 | 19 | * Connect an ESC that has the simonk bootloader enabled by connecting the 20 | servo signal wire to PD2/INT0 on the Arduino. I recommend a 470 ohm resistor 21 | in series on this line as a general protective measure. 22 | 23 | * Finally use something like avrdude or KKmulticopter Flash Tool to flash over 24 | the serial port at 19200 baud using STK500v2 protocol. Look at the simonk 25 | Makefile for avrdude usage examples. 26 | 27 | 28 | Known issues: 29 | When applying power to the Arduino and the ESC at the same time the ESC will 30 | arm before we are able to set the signal pin HIGH. It will still work but be 31 | careful. Best is to connect and power the Arduino first then power up the 32 | ESC to ensure that it is held in the bootloader (there should be no beeps 33 | from the ESC). 34 | 35 | Message sizes of more than 297 bytes (total) not not supported and will 36 | likely crash this software. The STK500 firmware is currently limited to 281 37 | bytes so it is not an issue at this time. 38 | 39 | Note that the default serial port rate is 19200 and this is separate from 40 | the servo wire signaling rate. Make sure your tools are using the same 41 | serial port rate. 42 | 43 | Both the serial port baud rate and the signaling rate can be changed on the 44 | fly or stored in EEPROM, see below. 45 | 46 | 47 | Advanced usage: 48 | 49 | ** WARNING ** It is critically important that you don't have multiple 50 | applications accessing the serial port at the same time. The Arduino serial 51 | monitor in particular because it holds the port open and intercepts data. 52 | Typically in this situation avrdude will get errors, recover, and then 53 | eventually finish successfully. HOWEVER, dispite finishing successfully your 54 | firmware will most likely be corrupted. This goes for both reading and 55 | writing over the serial port. 56 | 57 | * The ArduinoUSBLinker supports run-time configuration of which pin to use for 58 | signaling and at what bit rate to run at. These options are configured by 59 | using text commands sent over the serial port. 60 | 61 | The command format is similar to but not the same as the MultiWii serial 62 | protocol. All messages start with "$M<" followed by a command character 63 | and its parameter(s). A description of how pin numbers are determined is 64 | below. 65 | 66 | Supported commands are: 67 | 68 | $M<Pn : Select pin number n. This will also set the pull-up resistor for 69 | the pin. The currently selected pin will be used for signaling. 70 | It is recommened to make one pass through all the ESC pins 71 | selecting each one before doing anything else. This will put them 72 | all in bootloader mode and prevent "no-signal" beeping. 73 | Example: "$M<P18" will select pin 18 (PD2/INT0). 74 | 75 | $M<Bn : Sets the bit time in microseconds. 76 | Example: "$M<B32" will set a 32µs signaling rate. 77 | 78 | $M<Rn : Sets the serial port baud rate. Only for non-MultiWii builds. In 79 | MultiWii builds this will always return "0" in the status line. 80 | Example: "$M<R115200" will set the serial port to 115200 bps. 81 | 82 | $M<W : Write the pin, bit time, and serial port baud to EEPROM. These 83 | will be restored on reset. Only for non-MultiWii builds. 84 | 85 | All commands, including invalid commands that start with "$M<" will 86 | print the current settings back over the serial port. The settings are 87 | followed by a list of all the ports and the starting pin number for each. 88 | 89 | Example status line: 90 | P18:B136:R9600:PINS:B0:C8:D16: 91 | 92 | Pin 18 is selected, bit rate is 136µs, baud rate is 9600, and there are 93 | 3 ports: 94 | PORTB starts with pin 0. 95 | PORTC starts with pin 8. 96 | PORTD starts with pin 16. 97 | 98 | This indicates pin 0-7 is PB0..7, pin 8-15 is PC0..7, pin 16-24 is PD0..7, 99 | and so on. These are the pin numbers used with the above commands. 100 | 101 | * This sketch can be integrated with MultiWii and has been tested with 102 | MultiWii\_shared latest SVN source. Copy the "ArduinoUSBLinker.ino" file in 103 | to the MultiWii sketch folder and rename it as "ArduinoUSBLinker.h". Apply 104 | the supplied patch "Serial.patch" to the MultiWii "Serial.ino" file. 105 | 106 | The ArduinoUSBLinker code adds approximately 1800 bytes to the firmware size 107 | and depending on which MultiWii options are configured there may not be 108 | enough room for everything. 109 | 110 | Baud rate for the serial interface is the same as MultiWii (usually 115200). 111 | 112 | To enter the ArduinoUSBLinker mode a MultiWii command 239 must be sent using 113 | the MultiWii serial protocol. This is a binary string of the following 114 | 6 characters (in hex): 24 4D 3C 00 EF EF
115 | In pseudo text: 116 | '$' 'M' '<' <datalen> <239> <checksum> 117 | 118 | Note the "239" command is subject to change and is not part of the official 119 | MultiWii code base. 120 | 121 | To exit ArduinoUSBLinker mode power cycle or reset the device. 122 | 123 | Donations are accepted: http://luadev.com/rc 124 | -------------------------------------------------------------------------------- /Serial.patch: -------------------------------------------------------------------------------- 1 | --- MultiWii.old/Serial.ino 2013-03-15 09:43:59.831324921 -0400 2 | +++ MultiWii.new/Serial.ino 2013-03-16 05:32:19.280242687 -0400 3 | @@ -72,6 +72,8 @@ 4 | #define MSP_SELECT_SETTING 210 //in message Select Setting Number (0-2) 5 | #define MSP_SET_HEAD 211 //in message define a new heading hold direction 6 | 7 | +#define MSP_USBLINKER 239 //in message Select USB Linker mode 8 | + 9 | #define MSP_BIND 240 //in message no param 10 | 11 | #define MSP_EEPROM_WRITE 250 //in message no param 12 | @@ -525,6 +527,9 @@ 13 | } 14 | break; 15 | #endif 16 | + case MSP_USBLINKER: 17 | + { void AUL_loop(uint8_t); AUL_loop(CURRENTPORT); } 18 | + break; 19 | default: // we do not know how to handle the (valid) message, indicate error MSP $M! 20 | headSerialError(0); 21 | break; 22 | @@ -868,3 +873,5 @@ 23 | #else 24 | void debugmsg_append_str(const char *str) {}; 25 | #endif 26 | + 27 | +#include "ArduinoUSBLinker.h" 28 | --------------------------------------------------------------------------------