light_ws2812.h 2.2 KB

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