PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

56 lines
1.7KB

  1. /*
  2. * Interrupt and PWM utilities for 16 bit Timer3 on ATmega168/328
  3. * Original code by Jesse Tane for http://labs.ideo.com August 2008
  4. * Modified March 2009 by Jérôme Despatis and Jesse Tane for ATmega328 support
  5. * Modified June 2009 by Michael Polli and Jesse Tane to fix a bug in setPeriod() which caused the timer to stop
  6. * Modified Oct 2009 by Dan Clemens to work with timer3 of the ATMega1280 or Arduino Mega
  7. * Modified April 2012 by Paul Stoffregen
  8. * Modified again, June 2014 by Paul Stoffregen
  9. *
  10. * This is free software. You can redistribute it and/or modify it under
  11. * the terms of Creative Commons Attribution 3.0 United States License.
  12. * To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/
  13. * or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
  14. *
  15. */
  16. #include "TimerThree.h"
  17. TimerThree Timer3; // preinstatiate
  18. unsigned short TimerThree::pwmPeriod = 0;
  19. unsigned char TimerThree::clockSelectBits = 0;
  20. void (*TimerThree::isrCallback)() = TimerThree::isrDefaultUnused;
  21. // interrupt service routine that wraps a user defined function supplied by attachInterrupt
  22. #if defined(__AVR__)
  23. ISR(TIMER3_OVF_vect)
  24. {
  25. Timer3.isrCallback();
  26. }
  27. #elif defined(__arm__) && defined(TEENSYDUINO) && (defined(KINETISK) || defined(KINETISL))
  28. void ftm2_isr(void)
  29. {
  30. uint32_t sc = FTM2_SC;
  31. #ifdef KINETISL
  32. if (sc & 0x80) FTM2_SC = sc;
  33. #else
  34. if (sc & 0x80) FTM2_SC = sc & 0x7F;
  35. #endif
  36. Timer3.isrCallback();
  37. }
  38. #elif defined(__arm__) && defined(TEENSYDUINO) && defined(__IMXRT1062__)
  39. void TimerThree::isr(void)
  40. {
  41. FLEXPWM2_SM2STS = FLEXPWM_SMSTS_RF;
  42. Timer3.isrCallback();
  43. }
  44. #endif
  45. void TimerThree::isrDefaultUnused()
  46. {
  47. }