PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

tlc_animations.h 3.3KB

3 年之前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright (c) 2009 by Alex Leone <acleone ~AT~ gmail.com>
  2. This file is part of the Arduino TLC5940 Library.
  3. The Arduino TLC5940 Library is free software: you can redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. The Arduino TLC5940 Library is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with The Arduino TLC5940 Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef TLC_ANIMATIONS_H
  15. #define TLC_ANIMATIONS_H
  16. /** \file
  17. TLC Animation functions. These play animations from PROGMEM. */
  18. #include <avr/pgmspace.h>
  19. #include <avr/io.h>
  20. #include "tlc_config.h"
  21. #include "Tlc5940.h"
  22. #include "tlc_progmem_utils.h"
  23. /** The currently playing animation */
  24. const uint8_t *tlc_currentAnimation;
  25. /** The number of frames in the current animation */
  26. volatile uint16_t tlc_animationFrames;
  27. /** The number of PWM periods to display each frame - 1 */
  28. volatile uint16_t tlc_animationPeriodsPerFrame;
  29. /** The current number of periods we've displayed this frame for */
  30. volatile uint16_t tlc_animationPeriodsWait;
  31. volatile void tlc_animationXLATCallback(void);
  32. void tlc_playAnimation(const uint8_t PROGMEM *animation, uint16_t frames, uint16_t periodsPerFrame);
  33. /** \addtogroup ExtendedFunctions
  34. \code #include "tlc_animations.h" \endcode
  35. - void tlc_playAnimation(const uint8_t PROGMEM *animation, uint16_t frames,
  36. uint16_t periodsPerFrame) - plays an animation from progmem. */
  37. /* @{ */
  38. /** Plays an animation from progmem in the "background" (with interrupts).
  39. \param animation A progmem array of grayscale data, length NUM_TLCS *
  40. 24 * frames, in reverse order. Ensure that there is not an update
  41. waiting to happen before calling this.
  42. \param frames the number of frames in animation
  43. \param periodsPerFrame number of PWM periods to wait between each frame
  44. (0 means play the animation as fast as possible).
  45. The default PWM period for a 16MHz clock is 1.024ms. */
  46. void tlc_playAnimation(const uint8_t PROGMEM *animation, uint16_t frames, uint16_t periodsPerFrame)
  47. {
  48. tlc_currentAnimation = animation;
  49. tlc_animationFrames = frames;
  50. tlc_animationPeriodsPerFrame = periodsPerFrame;
  51. tlc_animationPeriodsWait = 0;
  52. tlc_onUpdateFinished = tlc_animationXLATCallback;
  53. tlc_animationXLATCallback();
  54. }
  55. /** This is called by the XLAT interrupt every PWM period to do stuff. */
  56. volatile void tlc_animationXLATCallback(void)
  57. {
  58. if (tlc_animationPeriodsWait) {
  59. tlc_animationPeriodsWait--;
  60. set_XLAT_interrupt();
  61. } else {
  62. if (tlc_animationFrames) {
  63. tlc_setGSfromProgmem(tlc_currentAnimation +
  64. (--tlc_animationFrames * NUM_TLCS * 24));
  65. tlc_animationPeriodsWait = tlc_animationPeriodsPerFrame;
  66. Tlc.update();
  67. } else { // animation is done
  68. tlc_onUpdateFinished = 0;
  69. }
  70. }
  71. }
  72. /* @} */
  73. #endif