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_progmem_utils.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_PROGMEM_UTILS_H
  15. #define TLC_PROGMEM_UTILS_H
  16. /** \file
  17. PROGMEM utility functions for setting grayscale or dot correction data
  18. from PROGMEM. See the UsingProgmem Example for an example. */
  19. #include "Tlc5940.h"
  20. #include "pinouts/pin_functions.h"
  21. void tlc_setGSfromProgmem(const uint8_t /*PROGMEM*/ *gsArray);
  22. #if VPRG_ENABLED
  23. void tlc_setDCfromProgmem(const uint8_t /*PROGMEM*/ *dcArray);
  24. #endif
  25. /** \addtogroup ExtendedFunctions
  26. \code #include "tlc_progmem_utils.h" \endcode
  27. - void tlc_setGSfromProgmem(const uint8_t PROGMEM *gsArray) - copies the progmem
  28. grayscale to current grayscale array. Requires a
  29. \link Tlc5940::update Tlc.update() \endlink.
  30. - void tlc_setDCfromProgmem(const uint8_t PROGMEM *dcArray) - shifts the data from a
  31. progmem dot correction array (doesn't need an update). */
  32. /* @{ */
  33. /** Sets the grayscale data from an array in progmem. This doesn't shift out
  34. any data: call Tlc.update(). An example:
  35. \code
  36. #include "tlc_progmem_utils.h"
  37. const uint8_t PROGMEM gsArray1[NUM_TLCS * 24] = {
  38. GS_DUO((4095 * 16)/16, (4095 * 15)/16), GS_DUO((4095 * 14)/16, (4095 * 13)/16),
  39. GS_DUO((4095 * 12)/16, (4095 * 11)/16), GS_DUO((4095 * 10)/16, (4095 * 9)/16),
  40. GS_DUO((4095 * 8)/16, (4095 * 7)/16), GS_DUO((4095 * 6)/16, (4095 * 5)/16),
  41. GS_DUO((4095 * 4)/16, (4095 * 3)/16), GS_DUO((4095 * 2)/16, (4095 * 1)/16),
  42. };
  43. // sometime after Tlc.init()
  44. tlc_setGSfromProgmem(gsArray1);
  45. Tlc.update();
  46. \endcode
  47. This would set a ramp of values from OUT0 to OUT15. (Although the
  48. NUM_TLCS * 24 looks like an error, each #GS_DUO is 3 bytes). The array
  49. would have to be expanded if #NUM_TLCS != 1.
  50. The format of the grayscale array is explained in #tlc_GSData.
  51. \param gsArray A progmem array of grayscale data. */
  52. void tlc_setGSfromProgmem(const uint8_t /*PROGMEM*/ *gsArray)
  53. {
  54. const uint8_t /*PROGMEM*/ *gsArrayp = gsArray;
  55. uint8_t *gsDatap = tlc_GSData;
  56. while (gsDatap < tlc_GSData + NUM_TLCS * 24) {
  57. *gsDatap++ = pgm_read_byte(gsArrayp++);
  58. *gsDatap++ = pgm_read_byte(gsArrayp++);
  59. *gsDatap++ = pgm_read_byte(gsArrayp++);
  60. }
  61. }
  62. #if VPRG_ENABLED
  63. /** \addtogroup ReqVPRG_ENABLED
  64. From tlc_progmem_utils.h:
  65. - tlc_setDCfromProgmem(const uint8_t PROGMEM *dcArray) - shifts the data from a
  66. progmem dot correction array (doesn't need an update). */
  67. /* @{ */
  68. /** Sets the dot correction data from an array in progmem. An example:
  69. \code
  70. #include "tlc_progmem_utils.h"
  71. const uint8_t PROGMEM dcArray1[NUM_TLCS * 12] = {
  72. DC_QUARTET(32, 63, 32, 63), DC_QUARTET(32, 63, 32, 63),
  73. DC_QUARTET(32, 63, 32, 63), DC_QUARTET(32, 63, 32, 63),
  74. };
  75. // sometime after Tlc.init()
  76. tlc_setDCfromProgmem(dcArray1);
  77. \endcode
  78. This would set every other channel to have a dot correction value of 32.
  79. (Although the NUM_TLCS * 12 looks like an error, each #DC_QUARTET is 3
  80. bytes). The array would have to be expanded if #NUM_TLCS != 1.
  81. The Format of the array is similar to #tlc_GSData, the last channel of
  82. the last TLC is the first value in the array. In the example above,
  83. the first 32 is setting OUT15, and the last 63 is setting OUT0.
  84. \param dcArray A progmem array of dot correction data to be shifted out.
  85. \see \link Tlc5940::setAllDC Tlc.setAllDC \endlink */
  86. void tlc_setDCfromProgmem(const uint8_t PROGMEM *dcArray)
  87. {
  88. tlc_dcModeStart();
  89. const uint8_t PROGMEM *p = dcArray;
  90. const uint8_t PROGMEM *dcArrayEnd = dcArray + NUM_TLCS * 12;
  91. while (p < dcArrayEnd) {
  92. tlc_shift8(pgm_read_byte(p++));
  93. }
  94. pulse_pin(XLAT_PORT, XLAT_PIN);
  95. tlc_dcModeStop();
  96. }
  97. /* @} */
  98. #endif
  99. /* @} */
  100. #endif