light_ws2812.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * light weight WS2812 lib include
  3. *
  4. * Version 2.3 - Nev 29th 2015
  5. * Author: Tim (cpldcpu@gmail.com)
  6. *
  7. * Please do not change this file! All configuration is handled in "ws2812_config.h"
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #ifndef LIGHT_WS2812_H_
  23. #define LIGHT_WS2812_H_
  24. #include <avr/io.h>
  25. #include <avr/interrupt.h>
  26. //#include "ws2812_config.h"
  27. //#include "i2cmaster.h"
  28. #ifdef RGBW
  29. #define LED_TYPE struct cRGBW
  30. #else
  31. #define LED_TYPE struct cRGB
  32. #endif
  33. /*
  34. * Structure of the LED array
  35. *
  36. * cRGB: RGB for WS2812S/B/C/D, SK6812, SK6812Mini, SK6812WWA, APA104, APA106
  37. * cRGBW: RGBW for SK6812RGBW
  38. */
  39. struct cRGB { uint8_t g; uint8_t r; uint8_t b; };
  40. struct cRGBW { uint8_t g; uint8_t r; uint8_t b; uint8_t w;};
  41. /* User Interface
  42. *
  43. * Input:
  44. * ledarray: An array of GRB data describing the LED colors
  45. * number_of_leds: The number of LEDs to write
  46. * pinmask (optional): Bitmask describing the output bin. e.g. _BV(PB0)
  47. *
  48. * The functions will perform the following actions:
  49. * - Set the data-out pin as output
  50. * - Send out the LED data
  51. * - Wait 50�s to reset the LEDs
  52. */
  53. void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds);
  54. void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);
  55. void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
  56. /*
  57. * Old interface / Internal functions
  58. *
  59. * The functions take a byte-array and send to the data output as WS2812 bitstream.
  60. * The length is the number of bytes to send - three per LED.
  61. */
  62. void ws2812_sendarray (uint8_t *array,uint16_t length);
  63. void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask);
  64. /*
  65. * Internal defines
  66. */
  67. #ifndef CONCAT
  68. #define CONCAT(a, b) a ## b
  69. #endif
  70. #ifndef CONCAT_EXP
  71. #define CONCAT_EXP(a, b) CONCAT(a, b)
  72. #endif
  73. // #define ws2812_PORTREG CONCAT_EXP(PORT,ws2812_port)
  74. // #define ws2812_DDRREG CONCAT_EXP(DDR,ws2812_port)
  75. #endif /* LIGHT_WS2812_H_ */