Skip to content

Commit df577bf

Browse files
committed
Fix for issue arduino#292
Replaced direct register manipulation with calls to bitWrite(). Fixed TIMSK5 usage on Leonardo (as well as some other preprocessor statements).
1 parent 3cde935 commit df577bf

File tree

1 file changed

+8
-8
lines changed
  • hardware/arduino/avr/cores/arduino

1 file changed

+8
-8
lines changed

Diff for: hardware/arduino/avr/cores/arduino/Tone.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,15 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
390390
break;
391391
#endif
392392

393-
#if defined(TIMSK3)
393+
#if defined(OCR3A) && defined(TIMSK3) && defined(OCIE3A)
394394
case 3:
395395
OCR3A = ocr;
396396
timer3_toggle_count = toggle_count;
397397
bitWrite(TIMSK3, OCIE3A, 1);
398398
break;
399399
#endif
400400

401-
#if defined(TIMSK4)
401+
#if defined(OCR4A) && defined(TIMSK4) && defined(OCIE4A)
402402
case 4:
403403
OCR4A = ocr;
404404
timer4_toggle_count = toggle_count;
@@ -455,21 +455,21 @@ void disableTimer(uint8_t _timer)
455455
#endif
456456
break;
457457

458-
#if defined(TIMSK3)
458+
#if defined(TIMSK3) && defined(OCIE3A)
459459
case 3:
460-
TIMSK3 &= ~(1 << OCIE3A);
460+
bitWrite(TIMSK3, OCIE3A, 0);
461461
break;
462462
#endif
463463

464-
#if defined(TIMSK4)
464+
#if defined(TIMSK4) && defined(OCIE4A)
465465
case 4:
466-
TIMSK4 &= ~(1 << OCIE4A);
466+
bitWrite(TIMSK4, OCIE4A, 0);
467467
break;
468468
#endif
469469

470-
#if defined(TIMSK5)
470+
#if defined(TIMSK5) && defined(OCIE5A)
471471
case 5:
472-
TIMSK5 &= ~(1 << OCIE5A);
472+
bitWrite(TIMSK5, OCIE5A, 0);
473473
break;
474474
#endif
475475
}

0 commit comments

Comments
 (0)