ws2812.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #pragma once
  23. #include <avr/io.h>
  24. #include <avr/interrupt.h>
  25. //#include "ws2812_config.h"
  26. //#include "i2cmaster.h"
  27. #include "rgblight_types.h"
  28. void WS2812_init(void);
  29. void WS2812_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
  30. void WS2812_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
  31. void WS2812_send_colors(void);
  32. /* User Interface
  33. *
  34. * Input:
  35. * ledarray: An array of GRB data describing the LED colors
  36. * number_of_leds: The number of LEDs to write
  37. * pinmask (optional): Bitmask describing the output bin. e.g. _BV(PB0)
  38. *
  39. * The functions will perform the following actions:
  40. * - Set the data-out pin as output
  41. * - Send out the LED data
  42. * - Wait 50�s to reset the LEDs
  43. */
  44. void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds);
  45. void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);
  46. void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
  47. /*
  48. * Old interface / Internal functions
  49. *
  50. * The functions take a byte-array and send to the data output as WS2812 bitstream.
  51. * The length is the number of bytes to send - three per LED.
  52. */
  53. void ws2812_sendarray (uint8_t *array,uint16_t length);
  54. void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask);
  55. /*
  56. * Internal defines
  57. */
  58. #ifndef CONCAT
  59. #define CONCAT(a, b) a ## b
  60. #endif
  61. #ifndef CONCAT_EXP
  62. #define CONCAT_EXP(a, b) CONCAT(a, b)
  63. #endif