Prusa MINI Firmware overview
neopixel.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
20  *
21  */
22 #pragma once
23 
24 /**
25  * Neopixel support
26  */
27 
28 // ------------------------
29 // Includes
30 // ------------------------
31 
32 #include "../../inc/MarlinConfig.h"
33 
34 #include <Adafruit_NeoPixel.h>
35 #include <stdint.h>
36 
37 // ------------------------
38 // Defines
39 // ------------------------
40 
41 #define MULTIPLE_NEOPIXEL_TYPES (defined(NEOPIXEL2_TYPE) && (NEOPIXEL2_TYPE != NEOPIXEL_TYPE))
42 
43 #define NEOPIXEL_IS_RGB (NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR)
44 #define NEOPIXEL_IS_RGBW !NEOPIXEL_IS_RGB
45 
46 #if NEOPIXEL_IS_RGB
47  #define NEO_WHITE 255, 255, 255, 0
48 #else
49  #define NEO_WHITE 0, 0, 0, 255
50 #endif
51 
52 // ------------------------
53 // Function prototypes
54 // ------------------------
55 
57 private:
58  static Adafruit_NeoPixel adaneo1
59  #if MULTIPLE_NEOPIXEL_TYPES
60  , adaneo2
61  #endif
62  ;
63 
64 public:
65  static void init();
66  static void set_color_startup(const uint32_t c);
67 
68  static void set_color(const uint32_t c);
69 
70  #ifdef NEOPIXEL_BKGD_LED_INDEX
71  static void set_color_background();
72  #endif
73 
74  static inline void begin() {
75  adaneo1.begin();
76  #if MULTIPLE_NEOPIXEL_TYPES
77  adaneo2.begin();
78  #endif
79  }
80 
81  static inline void set_pixel_color(const uint16_t n, const uint32_t c) {
82  adaneo1.setPixelColor(n, c);
83  #if MULTIPLE_NEOPIXEL_TYPES
84  adaneo2.setPixelColor(n, c);
85  #endif
86  }
87 
88  static inline void set_brightness(const uint8_t b) {
89  adaneo1.setBrightness(b);
90  #if MULTIPLE_NEOPIXEL_TYPES
91  adaneo2.setBrightness(b);
92  #endif
93  }
94 
95  static inline void show() {
96  adaneo1.show();
97  #if PIN_EXISTS(NEOPIXEL2)
98  #if MULTIPLE_NEOPIXEL_TYPES
99  adaneo2.show();
100  #else
101  adaneo1.setPin(NEOPIXEL2_PIN);
102  adaneo1.show();
103  adaneo1.setPin(NEOPIXEL_PIN);
104  #endif
105  #endif
106  }
107 
108  #if 0
109  bool set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
110  #endif
111 
112  // Accessors
113  static inline uint16_t pixels() { return adaneo1.numPixels(); }
114  static inline uint8_t brightness() { return adaneo1.getBrightness(); }
115  static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
116  return adaneo1.Color(r, g, b, w);
117  }
118 };
119 
120 extern Marlin_NeoPixel neo;
Marlin_NeoPixel::init
static void init()
Marlin_NeoPixel::Color
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Definition: neopixel.h:115
Marlin_NeoPixel::set_brightness
static void set_brightness(const uint8_t b)
Definition: neopixel.h:88
Marlin_NeoPixel::begin
static void begin()
Definition: neopixel.h:74
Marlin_NeoPixel::set_color_startup
static void set_color_startup(const uint32_t c)
Marlin_NeoPixel::set_pixel_color
static void set_pixel_color(const uint16_t n, const uint32_t c)
Definition: neopixel.h:81
i
uint8_t i
Definition: screen_test_graph.c:72
Marlin_NeoPixel::pixels
static uint16_t pixels()
Definition: neopixel.h:113
SET_OUTPUT
#define SET_OUTPUT(IO)
Definition: fastio.h:101
Marlin_NeoPixel
Definition: neopixel.h:56
neo
Marlin_NeoPixel neo
Marlin_NeoPixel::brightness
static uint8_t brightness()
Definition: neopixel.h:114
Marlin_NeoPixel::show
static void show()
Definition: neopixel.h:95
uint8_t
const uint8_t[]
Definition: 404_html.c:3
neopixel.h
safe_delay
void safe_delay(millis_t ms)
Definition: utility.cpp:28
background_color
png_structrp png_const_color_16p background_color
Definition: png.h:1302
createSpeedLookupTable.b
list b
Definition: createSpeedLookupTable.py:30
Marlin_NeoPixel::set_color
static void set_color(const uint32_t c)
NEOPIXEL_PIN
#define NEOPIXEL_PIN
Definition: pins_BTT_SKR_MINI_E3_V1_2.h:124