light_ws2812.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * License: GNU GPL v2 (see License.txt)
  10. +
  11. */
  12. #ifndef LIGHT_WS2812_H_
  13. #define LIGHT_WS2812_H_
  14. #include <avr/io.h>
  15. #include <avr/interrupt.h>
  16. //#include "ws2812_config.h"
  17. //#include "i2cmaster.h"
  18. #ifdef RGBW
  19. #define LED_TYPE struct cRGBW
  20. #else
  21. #define LED_TYPE struct cRGB
  22. #endif
  23. /*
  24. * Structure of the LED array
  25. *
  26. * cRGB: RGB for WS2812S/B/C/D, SK6812, SK6812Mini, SK6812WWA, APA104, APA106
  27. * cRGBW: RGBW for SK6812RGBW
  28. */
  29. struct cRGB { uint8_t g; uint8_t r; uint8_t b; };
  30. struct cRGBW { uint8_t g; uint8_t r; uint8_t b; uint8_t w;};
  31. /* User Interface
  32. *
  33. * Input:
  34. * ledarray: An array of GRB data describing the LED colors
  35. * number_of_leds: The number of LEDs to write
  36. * pinmask (optional): Bitmask describing the output bin. e.g. _BV(PB0)
  37. *
  38. * The functions will perform the following actions:
  39. * - Set the data-out pin as output
  40. * - Send out the LED data
  41. * - Wait 50�s to reset the LEDs
  42. */
  43. void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds);
  44. void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);
  45. void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
  46. /*
  47. * Old interface / Internal functions
  48. *
  49. * The functions take a byte-array and send to the data output as WS2812 bitstream.
  50. * The length is the number of bytes to send - three per LED.
  51. */
  52. void ws2812_sendarray (uint8_t *array,uint16_t length);
  53. void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask);
  54. /*
  55. * Internal defines
  56. */
  57. #ifndef CONCAT
  58. #define CONCAT(a, b) a ## b
  59. #endif
  60. #ifndef CONCAT_EXP
  61. #define CONCAT_EXP(a, b) CONCAT(a, b)
  62. #endif
  63. // #define ws2812_PORTREG CONCAT_EXP(PORT,ws2812_port)
  64. // #define ws2812_DDRREG CONCAT_EXP(DDR,ws2812_port)
  65. #endif /* LIGHT_WS2812_H_ */