light_ws2812.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * light weight WS2812 lib include
  3. *
  4. * Version 2.0a3 - Jan 18th 2014
  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. /*
  18. * Structure of the LED array
  19. */
  20. struct cRGB { uint8_t g; uint8_t r; uint8_t b; };
  21. /* User Interface
  22. *
  23. * Input:
  24. * ledarray: An array of GRB data describing the LED colors
  25. * number_of_leds: The number of LEDs to write
  26. * pinmask (optional): Bitmask describing the output bin. e.g. _BV(PB0)
  27. *
  28. * The functions will perform the following actions:
  29. * - Set the data-out pin as output
  30. * - Send out the LED data
  31. * - Wait 50�s to reset the LEDs
  32. */
  33. void ws2812_setleds (struct cRGB *ledarray, uint16_t number_of_leds);
  34. void ws2812_setleds_pin(struct cRGB *ledarray, uint16_t number_of_leds,uint8_t pinmask);
  35. /*
  36. * Old interface / Internal functions
  37. *
  38. * The functions take a byte-array and send to the data output as WS2812 bitstream.
  39. * The length is the number of bytes to send - three per LED.
  40. */
  41. void ws2812_sendarray (uint8_t *array,uint16_t length);
  42. void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask);
  43. /*
  44. * Internal defines
  45. */
  46. #define CONCAT(a, b) a ## b
  47. #define CONCAT_EXP(a, b) CONCAT(a, b)
  48. #define ws2812_PORTREG CONCAT_EXP(PORT,ws2812_port)
  49. #define ws2812_DDRREG CONCAT_EXP(DDR,ws2812_port)
  50. #endif /* LIGHT_WS2812_H_ */