My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

neopixel.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * NeoPixel support
  25. */
  26. #ifndef _NEOPIXEL_INCLUDE_
  27. #error "Always include 'leds.h' and not 'neopixel.h' directly."
  28. #endif
  29. // ------------------------
  30. // Includes
  31. // ------------------------
  32. #include "../../inc/MarlinConfig.h"
  33. #include <Adafruit_NeoPixel.h>
  34. #include <stdint.h>
  35. // ------------------------
  36. // Defines
  37. // ------------------------
  38. #define _NEO_IS_RGB(N) (N == NEO_RGB || N == NEO_RBG || N == NEO_GRB || N == NEO_GBR || N == NEO_BRG || N == NEO_BGR)
  39. #if !_NEO_IS_RGB(NEOPIXEL_TYPE)
  40. #define HAS_WHITE_LED 1
  41. #endif
  42. #if HAS_WHITE_LED
  43. #define NEO_WHITE 0, 0, 0, 255
  44. #else
  45. #define NEO_WHITE 255, 255, 255
  46. #endif
  47. #if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE)
  48. #define MULTIPLE_NEOPIXEL_TYPES 1
  49. #endif
  50. #if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
  51. #define CONJOINED_NEOPIXEL 1
  52. #endif
  53. // ------------------------
  54. // Types
  55. // ------------------------
  56. typedef IF<(TERN0(NEOPIXEL_LED, NEOPIXEL_PIXELS > 127)), int16_t, int8_t>::type pixel_index_t;
  57. // ------------------------
  58. // Classes
  59. // ------------------------
  60. class Marlin_NeoPixel {
  61. private:
  62. static Adafruit_NeoPixel adaneo1;
  63. #if CONJOINED_NEOPIXEL
  64. static Adafruit_NeoPixel adaneo2;
  65. #endif
  66. public:
  67. static pixel_index_t neoindex;
  68. static void init();
  69. static void set_color_startup(const uint32_t c);
  70. static void set_color(const uint32_t c);
  71. #ifdef NEOPIXEL_BKGD_INDEX_FIRST
  72. static void set_background_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
  73. static void reset_background_color();
  74. #endif
  75. static void begin() {
  76. adaneo1.begin();
  77. TERN_(CONJOINED_NEOPIXEL, adaneo2.begin());
  78. }
  79. static void set_pixel_color(const uint16_t n, const uint32_t c) {
  80. #if ENABLED(NEOPIXEL2_INSERIES)
  81. if (n >= NEOPIXEL_PIXELS) adaneo2.setPixelColor(n - (NEOPIXEL_PIXELS), c);
  82. else adaneo1.setPixelColor(n, c);
  83. #else
  84. adaneo1.setPixelColor(n, c);
  85. TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c));
  86. #endif
  87. }
  88. static void set_brightness(const uint8_t b) {
  89. adaneo1.setBrightness(b);
  90. TERN_(CONJOINED_NEOPIXEL, adaneo2.setBrightness(b));
  91. }
  92. static void show() {
  93. // Some platforms cannot maintain PWM output when NeoPixel disables interrupts for long durations.
  94. TERN_(HAS_PAUSE_SERVO_OUTPUT, PAUSE_SERVO_OUTPUT());
  95. adaneo1.show();
  96. #if PIN_EXISTS(NEOPIXEL2)
  97. #if CONJOINED_NEOPIXEL
  98. adaneo2.show();
  99. #else
  100. adaneo1.show();
  101. adaneo1.setPin(NEOPIXEL_PIN);
  102. #endif
  103. #endif
  104. TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT());
  105. }
  106. // Accessors
  107. static uint16_t pixels() { return adaneo1.numPixels() * TERN1(NEOPIXEL2_INSERIES, 2); }
  108. static uint8_t brightness() { return adaneo1.getBrightness(); }
  109. static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w)) {
  110. return adaneo1.Color(r, g, b OPTARG(HAS_WHITE_LED, w));
  111. }
  112. };
  113. extern Marlin_NeoPixel neo;
  114. // Neo pixel channel 2
  115. #if ENABLED(NEOPIXEL2_SEPARATE)
  116. #if _NEO_IS_RGB(NEOPIXEL2_TYPE)
  117. #define NEOPIXEL2_IS_RGB 1
  118. #define NEO2_WHITE 255, 255, 255
  119. #else
  120. #define NEOPIXEL2_IS_RGBW 1
  121. #define HAS_WHITE_LED2 1 // A white component can be passed for NEOPIXEL2
  122. #define NEO2_WHITE 0, 0, 0, 255
  123. #endif
  124. class Marlin_NeoPixel2 {
  125. private:
  126. static Adafruit_NeoPixel adaneo;
  127. public:
  128. static pixel_index_t neoindex;
  129. static void init();
  130. static void set_color_startup(const uint32_t c);
  131. static void set_color(const uint32_t c);
  132. static void begin() { adaneo.begin(); }
  133. static void set_pixel_color(const uint16_t n, const uint32_t c) { adaneo.setPixelColor(n, c); }
  134. static void set_brightness(const uint8_t b) { adaneo.setBrightness(b); }
  135. static void show() {
  136. adaneo.show();
  137. adaneo.setPin(NEOPIXEL2_PIN);
  138. }
  139. // Accessors
  140. static uint16_t pixels() { return adaneo.numPixels();}
  141. static uint8_t brightness() { return adaneo.getBrightness(); }
  142. static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED2, uint8_t w)) {
  143. return adaneo.Color(r, g, b OPTARG(HAS_WHITE_LED2, w));
  144. }
  145. };
  146. extern Marlin_NeoPixel2 neo2;
  147. #endif // NEOPIXEL2_SEPARATE
  148. #undef _NEO_IS_RGB