ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputWS2811.hpp
Go to the documentation of this file.
1#pragma once
2/*
3* OutputWS2811.h - WS2811 driver code for ESPixelStick
4*
5* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
6* Copyright (c) 2015, 2024 Shelby Merrick
7* http://www.forkineye.com
8*
9* This program is provided free for you to use in any way that you wish,
10* subject to the laws and regulations where you are using it. Due diligence
11* is strongly suggested before using this code. Please give credit where due.
12*
13* The Author makes no warranty of any kind, express or implied, with regard
14* to this program or the documentation contained in this document. The
15* Author shall not be liable in any event for incidental or consequential
16* damages in connection with, or arising out of, the furnishing, performance
17* or use of these programs.
18*
19* This is a derived class that converts data in the output buffer into
20* pixel intensities and then transmits them through the configured serial
21* interface.
22*
23*/
24
25#include "OutputPixel.hpp"
26#if defined(SUPPORT_OutputProtocol_WS2811)
27
28#ifdef ARDUINO_ARCH_ESP32
29# include <driver/uart.h>
30#endif
31
32class c_OutputWS2811 : public c_OutputPixel
33{
34public:
35 // These functions are inherited from c_OutputCommon
36 c_OutputWS2811 (OM_OutputPortDefinition_t & OutputPortDefinition,
38 virtual ~c_OutputWS2811 ();
39
40 // functions to be provided by the derived class
41 virtual void Begin ();
42 virtual bool SetConfig (ArduinoJson::JsonObject & jsonConfig);
43 virtual void GetConfig (ArduinoJson::JsonObject & jsonConfig);
44 virtual void GetStatus (ArduinoJson::JsonObject & jsonStatus);
45 void GetDriverName (String & sDriverName) { sDriverName = CN_WS2811; }
46
47protected:
48
49#define WS2811_PIXEL_DATA_RATE 800000.0 // 800Khz
50#define WS2811_PIXEL_NS_BIT_TOTAL ( (1.0 / WS2811_PIXEL_DATA_RATE) * NanoSecondsInASecond)
51#ifdef ARDUINO_ARCH_ESP32
52 // values have been adjusted to work with seed pixels.
53// #define WS2811_PIXEL_NS_BIT_0_HIGH 312.0 // = 312 on logic analyzer 220ns - 380ns per datasheet
54// #define WS2811_PIXEL_NS_BIT_0_LOW 945.0 // = 937 on logic analyzer 580ns - 1.6us per datasheet
55// #define WS2811_PIXEL_NS_BIT_1_HIGH 975.0 // = 937 on logic analyzer 580ns - 1.6us per datasheet
56// #define WS2811_PIXEL_NS_BIT_1_LOW 300.0 // = 312 on logic analyzer 220ns - 380ns per datasheet
57 #define WS2811_PIXEL_NS_BIT_0_HIGH 300.0 // 220ns - 380ns per datasheet
58 #define WS2811_PIXEL_NS_BIT_0_LOW (WS2811_PIXEL_NS_BIT_TOTAL - WS2811_PIXEL_NS_BIT_0_HIGH)
59 #define WS2811_PIXEL_NS_BIT_1_HIGH WS2811_PIXEL_NS_BIT_0_LOW
60 #define WS2811_PIXEL_NS_BIT_1_LOW WS2811_PIXEL_NS_BIT_0_HIGH
61#else
62 #define WS2811_PIXEL_NS_BIT_0_HIGH 312.0 // 220ns - 380ns per datasheet
63 #define WS2811_PIXEL_NS_BIT_0_LOW (WS2811_PIXEL_NS_BIT_TOTAL - WS2811_PIXEL_NS_BIT_0_HIGH)
64 #define WS2811_PIXEL_NS_BIT_1_HIGH 975.0 // 580ns - 1.6us per datasheet
65 #define WS2811_PIXEL_NS_BIT_1_LOW (WS2811_PIXEL_NS_BIT_TOTAL - WS2811_PIXEL_NS_BIT_1_HIGH)
66#endif // ARDUINO_ARCH_ESP32
67
68#define WS2811_PIXEL_IDLE_TIME_US 350.0 // 350us per datasheet
69#define WS2811_PIXEL_IDLE_TIME_NS WS2811_PIXEL_IDLE_TIME_US * NanoSecondsInAMicroSecond
70
71#define WS2811_PIXEL_BITS_PER_INTENSITY 8
72
73}; // c_OutputWS2811
74
75#endif // defined(SUPPORT_OutputProtocol_WS2811)
const CN_PROGMEM char CN_WS2811[]
Definition ConstNames.cpp:256
virtual void GetDriverName(String &sDriverName)=0
get the name for the instantiated driver
virtual void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputCommon.hpp:41
e_OutputProtocolType
Definition OutputMgr.hpp:78
Definition OutputPixel.hpp:28
virtual void GetStatus(ArduinoJson::JsonObject &jsonStatus)
Definition OutputPixel.cpp:76
virtual bool SetConfig(ArduinoJson::JsonObject &jsonConfig)
Set a new config in the driver.
Definition OutputPixel.cpp:177
virtual void GetConfig(ArduinoJson::JsonObject &jsonConfig)
Get the current config used by the driver.
Definition OutputPixel.cpp:50
Definition OutputMgrPortDefs.hpp:90