PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

82 rindas
2.9KB

  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_SHIFTS_H
  15. #define TLC_SHIFTS_H
  16. /** \file
  17. TLC channel shifting functions. */
  18. #include "Tlc5940.h"
  19. uint16_t tlc_shiftUp(uint16_t zeroValue = 0);
  20. uint16_t tlc_shiftDown(uint16_t topValue = 0);
  21. /** \addtogroup ExtendedFunctions
  22. \code #include "tlc_shifts.h" \endcode
  23. - uint16_t tlc_shiftUp(uint16_t zeroValue = 0) - shifts all channel data
  24. up (OUT0 becomes OUT1 ...) and returns OUT15
  25. - uint16_t tlc_shiftDown(uint16_t topValue = 0) - shifts all channel data
  26. down (OUT15 becomes OUT14 ...) and returns OUT0 */
  27. /* @{ */
  28. /** Shifts all the channel data up (OUT0 becomes OUT1 ...). Needs a
  29. Tlc.update() after.
  30. \param zeroValue the value of channel 0.
  31. \returns the value that was shifted off the end (OUT15) */
  32. uint16_t tlc_shiftUp(uint16_t zeroValue)
  33. {
  34. uint16_t topValue = ((uint16_t)(*tlc_GSData) << 4)
  35. | (*(tlc_GSData + 1) >> 4);
  36. uint8_t *p = tlc_GSData + 1;
  37. while (p < tlc_GSData + NUM_TLCS * 24 - 1) {
  38. *(p - 1) = (*p << 4) | (*(p + 1) >> 4);
  39. *p = (*(p + 1) << 4) | (*(p + 2) >> 4);
  40. p += 2;
  41. }
  42. *(tlc_GSData + NUM_TLCS * 24 - 2) = (*(tlc_GSData + NUM_TLCS * 24 - 1) << 4)
  43. | ((zeroValue & 0x0F00) >> 8);
  44. *(tlc_GSData + NUM_TLCS * 24 - 1) = (uint8_t)zeroValue;
  45. return topValue;
  46. }
  47. /** Shifts all the channel data down (OUT 15 -> OUT 14 ...). Needs a
  48. Tlc.update() after.
  49. \param topValue the value of Tlc (n) channel 15.
  50. \returns the value that was shifted off the bottom (OUT0) */
  51. uint16_t tlc_shiftDown(uint16_t topValue)
  52. {
  53. uint8_t *p = tlc_GSData + NUM_TLCS * 24 - 2;
  54. uint16_t zeroValue =
  55. ((uint16_t)(*(tlc_GSData + NUM_TLCS * 24 - 2) & 0x0F) << 8)
  56. | *(tlc_GSData + NUM_TLCS * 24 - 1);
  57. while (p > tlc_GSData) {
  58. *(p + 1) = (*p >> 4) | (*(p - 1) << 4);
  59. *p = (*(p - 1) >> 4) | (*(p - 2) << 4);
  60. p -= 2;
  61. }
  62. *(tlc_GSData + 1) = (*tlc_GSData >> 4) | ((uint8_t)topValue << 4);
  63. *tlc_GSData = topValue >> 4;
  64. return zeroValue;
  65. }
  66. /* @} */
  67. #endif