PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

60 行
1.9KB

  1. /*
  2. * Interrupt and PWM utilities for 16 bit Timer1 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 timer1 of the ATMega1280 or Arduino Mega
  7. * Modified April 2012 by Paul Stoffregen
  8. * Modified again, June 2014 by Paul Stoffregen
  9. * Modified July 2017 by Stoyko Dimitrov - added support for ATTiny85 except for the PWM functionality
  10. *
  11. * This is free software. You can redistribute it and/or modify it under
  12. * the terms of Creative Commons Attribution 3.0 United States License.
  13. * To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/
  14. * or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
  15. *
  16. */
  17. #include "TimerOne.h"
  18. TimerOne Timer1; // preinstatiate
  19. unsigned short TimerOne::pwmPeriod = 0;
  20. unsigned char TimerOne::clockSelectBits = 0;
  21. void (*TimerOne::isrCallback)() = TimerOne::isrDefaultUnused;
  22. // interrupt service routine that wraps a user defined function supplied by attachInterrupt
  23. #if defined (__AVR_ATtiny85__)
  24. ISR(TIMER1_COMPA_vect)
  25. {
  26. Timer1.isrCallback();
  27. }
  28. #elif defined(__AVR__)
  29. ISR(TIMER1_OVF_vect)
  30. {
  31. Timer1.isrCallback();
  32. }
  33. #elif defined(__arm__) && defined(TEENSYDUINO) && (defined(KINETISK) || defined(KINETISL))
  34. void ftm1_isr(void)
  35. {
  36. uint32_t sc = FTM1_SC;
  37. #ifdef KINETISL
  38. if (sc & 0x80) FTM1_SC = sc;
  39. #else
  40. if (sc & 0x80) FTM1_SC = sc & 0x7F;
  41. #endif
  42. Timer1.isrCallback();
  43. }
  44. #elif defined(__arm__) && defined(TEENSYDUINO) && defined(__IMXRT1062__)
  45. void TimerOne::isr(void)
  46. {
  47. FLEXPWM1_SM3STS = FLEXPWM_SMSTS_RF;
  48. Timer1.isrCallback();
  49. }
  50. #endif
  51. void TimerOne::isrDefaultUnused()
  52. {
  53. }