From 4848a52479ccc3c04940d2cc013dbce1d4d23b4f Mon Sep 17 00:00:00 2001 From: Rei Vilo Date: Thu, 12 Dec 2024 17:28:11 +0100 Subject: [PATCH] Release 8.1.1 Added patch for ezWS2812gpio issue (see https://github.com/SiliconLabs/arduino/issues/106) --- examples/EXT4/EXT4_WS2813C/EXT4_WS2813C.ino | 10 +- examples/EXT4/EXT4_WS2813C/rawWS2813C.cpp | 143 ++++++++++++++++++ examples/EXT4/EXT4_WS2813C/rawWS2813C.h | 56 +++++++ .../EXT4_Matter_RGB/EXT4_Matter_RGB.ino | 10 +- .../EXT4_Matter_RGB/rawWS2813C.cpp | 143 ++++++++++++++++++ .../EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.h | 56 +++++++ library.properties | 2 +- src/hV_Documentation.h | 4 +- 8 files changed, 413 insertions(+), 11 deletions(-) create mode 100644 examples/EXT4/EXT4_WS2813C/rawWS2813C.cpp create mode 100644 examples/EXT4/EXT4_WS2813C/rawWS2813C.h create mode 100644 examples/EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.cpp create mode 100644 examples/EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.h diff --git a/examples/EXT4/EXT4_WS2813C/EXT4_WS2813C.ino b/examples/EXT4/EXT4_WS2813C/EXT4_WS2813C.ino index 56ed8a2..6f216c4 100644 --- a/examples/EXT4/EXT4_WS2813C/EXT4_WS2813C.ino +++ b/examples/EXT4/EXT4_WS2813C/EXT4_WS2813C.ino @@ -6,8 +6,8 @@ /// @n Based on highView technology /// /// @author Rei Vilo -/// @date 21 Nov 2024 -/// @version 810 +/// @date 12 Dec 2024 +/// @version 811 /// /// @copyright (c) Rei Vilo, 2010-2024 /// @copyright All rights reserved @@ -30,7 +30,8 @@ #include "Arduino.h" // WS2813C -#include "ezWS2812gpio.h" +// #include "ezWS2812gpio.h" +#include "rawWS2813C.h" // Set parameters @@ -42,7 +43,8 @@ const pins_t myBoard = boardArduinoNanoMatter; // WS2813 -ezWS2812gpio myRGB(1, myBoard.ledData); +// ezWS2812gpio myRGB(1, myBoard.ledData); +rawWS2813C myRGB(1, myBoard.ledData); // Prototypes diff --git a/examples/EXT4/EXT4_WS2813C/rawWS2813C.cpp b/examples/EXT4/EXT4_WS2813C/rawWS2813C.cpp new file mode 100644 index 0000000..57af417 --- /dev/null +++ b/examples/EXT4/EXT4_WS2813C/rawWS2813C.cpp @@ -0,0 +1,143 @@ +/// +/// @file rawWS2813C.cpp +/// +/// @brief Driver for WS2813C +/// @version 103 +/// @date 16 Feb 2024 +/// +/// @author Rei Vilo for Pervasive Displays https://www.pervasivedisplays.com +/// @copyright Copyright (c) 2010-2024 Rei Vilo for Pervasive Displays +/// @copyright License CC-BY-SA Creative Commons - Attribution - Share Alike +/// https://creativecommons.org/licenses/by-sa/4.0/deed.en +/// + +#include "rawWS2813C.h" + +#include +#include +#include +#include "em_common.h" +#include "em_gpio.h" +#include "sl_udelay.h" + +/// +/// @brief Define GPIO for WS2813C +/// @param port port, gpioPortA..gpioPortD +/// @param pin pin, O..16 according to port +/// +void wsDefine(uint8_t port, uint8_t pin); + +/// +/// @brief Set RGB values +/// @param red red component, 0..255 +/// @param green green component, 0..255 +/// @param blue blue component, 0..255 +/// +void wsWrite(uint8_t red, uint8_t green, uint8_t blue); + +uint8_t wsPort; +uint8_t wsBit; + +void wsDefine(uint8_t port, uint8_t pin) +{ + wsPort = port; + wsBit = pin; + + GPIO_PinModeSet(wsPort, wsBit, gpioModePushPull, 0); + wsWrite(0, 0, 0); +} + +void wsWrite(uint8_t red, uint8_t green, uint8_t blue) +{ + // uint32_t valueG70R70B70 = 0b111100001010101011001100; // 0xf0aacc + uint32_t valueG70R70B70 = (green << 16) | (red << 8) | blue; + uint32_t valueB07R07G07 = 0; + + for (uint8_t i = 0; i < 24; i += 1) + { + valueB07R07G07 <<= 1; + valueB07R07G07 |= (valueG70R70B70 & 1); + valueG70R70B70 >>= 1; + } + + for (uint8_t i = 0; i < 24; i += 1) + { + if (valueB07R07G07 & 1) + { + // 1 code = T1H T1L + // T1H 1-code, High-level time 580ns~1.6μs + // T1L 1-code, Low-level time 220ns~420ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns * 14 = 784 ns + + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns * 6 = 276 ns + } + else + { + // 0 code = T0H T0L + // T0H 0-code, High-level time 220ns~380ns + // T0L 0-code, Low-level time 580ns~1.6μs + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns * 5 = 280 ns + + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns * 15 = 690 ns + } + valueB07R07G07 >>= 1; + } +} + + +rawWS2813C::rawWS2813C(uint32_t num_leds, pin_size_t pin) +{ + wsPinArduino = pin; +} + +void rawWS2813C::begin() +{ + PinName wsName; + + wsName = pinToPinName(wsPinArduino); + wsPort = getSilabsPortFromArduinoPin(wsName); + wsBit = getSilabsPinFromArduinoPin(wsName); + + wsDefine(wsPort, wsBit); +} + +void rawWS2813C::set_all(uint8_t red, uint8_t green, uint8_t blue) +{ + wsWrite(red, green, blue); +}; diff --git a/examples/EXT4/EXT4_WS2813C/rawWS2813C.h b/examples/EXT4/EXT4_WS2813C/rawWS2813C.h new file mode 100644 index 0000000..b03ce57 --- /dev/null +++ b/examples/EXT4/EXT4_WS2813C/rawWS2813C.h @@ -0,0 +1,56 @@ +/// +/// @file rawWS2813C.h +/// @brief Driver for WS2813C +/// @version 103 +/// @date 16 Feb 2024 +/// +/// @author Rei Vilo for Pervasive Displays https://www.pervasivedisplays.com +/// @copyright Copyright (c) 2010-2024 Rei Vilo for Pervasive Displays +/// @copyright License CC-BY-SA Creative Commons - Attribution - Share Alike +/// https://creativecommons.org/licenses/by-sa/4.0/deed.en +/// +/// @see https://github.com/SiliconLabs/arduino/issues/106 +/// + +#ifndef rawWS2813C_RELEASE +#define rawWS2813C_RELEASE 103 + +#include "Arduino.h" + +/// +/// @class rawWS2813C +/// @details Minimal class for WS2813C +/// +class rawWS2813C +{ + public: + /// + /// @brief Construct WS2813C object + /// + /// @param num_leds 1, ignored + /// @param pin Arduino pin, name `D4` or number `4` + /// + rawWS2813C(uint32_t num_leds, pin_size_t pin); + + /// + /// @brief Initialise + /// + void begin(); + + /// + /// @brief Set RGB LED + /// + /// @param red red component, 0..255 + /// @param green green component, 0..255 + /// @param blue blue component, 0..255 + /// + void set_all(uint8_t red, uint8_t green, uint8_t blue); + + private: + uint8_t wsPinArduino; + uint32_t wsBit; + uint8_t wsPort; // enum GPIO_Port_TypeDef +}; + +#endif // rawWS2813C_RELEASE + diff --git a/examples/EXT4_Matter/EXT4_Matter_RGB/EXT4_Matter_RGB.ino b/examples/EXT4_Matter/EXT4_Matter_RGB/EXT4_Matter_RGB.ino index e372069..bd0385b 100755 --- a/examples/EXT4_Matter/EXT4_Matter_RGB/EXT4_Matter_RGB.ino +++ b/examples/EXT4_Matter/EXT4_Matter_RGB/EXT4_Matter_RGB.ino @@ -20,8 +20,8 @@ /// @author Tamas Jozsi (Silicon Labs) /// /// @author Rei Vilo -/// @date 21 Nov 2024 -/// @version 810 +/// @date 12 Dec 2024 +/// @version 811 /// /// @copyright (c) Rei Vilo, 2010-2024 /// * 2024-06-06 Rei Vilo (Pervasive Displays) @@ -45,7 +45,8 @@ MatterColorLightbulb myMatterRGB; // WS2813C -#include "ezWS2812gpio.h" +// #include "ezWS2812gpio.h" +#include "rawWS2813C.h" // PDLS #include "PDLS_EXT4_Basic_Matter.h" @@ -79,7 +80,8 @@ Screen_EPD_EXT4_Fast myScreen(eScreen_EPD_290_KS_0F, myBoard); #define MATTER_EXAMPLE_RELEASE 810 // WS2813 -ezWS2812gpio myRGB(1, myBoard.ledData); +// ezWS2812gpio myRGB(1, myBoard.ledData); +rawWS2813C myRGB(1, myBoard.ledData); static bool wsState = false; const uint8_t wsLimit = 64; // Limit for each RGB channel diff --git a/examples/EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.cpp b/examples/EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.cpp new file mode 100644 index 0000000..57af417 --- /dev/null +++ b/examples/EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.cpp @@ -0,0 +1,143 @@ +/// +/// @file rawWS2813C.cpp +/// +/// @brief Driver for WS2813C +/// @version 103 +/// @date 16 Feb 2024 +/// +/// @author Rei Vilo for Pervasive Displays https://www.pervasivedisplays.com +/// @copyright Copyright (c) 2010-2024 Rei Vilo for Pervasive Displays +/// @copyright License CC-BY-SA Creative Commons - Attribution - Share Alike +/// https://creativecommons.org/licenses/by-sa/4.0/deed.en +/// + +#include "rawWS2813C.h" + +#include +#include +#include +#include "em_common.h" +#include "em_gpio.h" +#include "sl_udelay.h" + +/// +/// @brief Define GPIO for WS2813C +/// @param port port, gpioPortA..gpioPortD +/// @param pin pin, O..16 according to port +/// +void wsDefine(uint8_t port, uint8_t pin); + +/// +/// @brief Set RGB values +/// @param red red component, 0..255 +/// @param green green component, 0..255 +/// @param blue blue component, 0..255 +/// +void wsWrite(uint8_t red, uint8_t green, uint8_t blue); + +uint8_t wsPort; +uint8_t wsBit; + +void wsDefine(uint8_t port, uint8_t pin) +{ + wsPort = port; + wsBit = pin; + + GPIO_PinModeSet(wsPort, wsBit, gpioModePushPull, 0); + wsWrite(0, 0, 0); +} + +void wsWrite(uint8_t red, uint8_t green, uint8_t blue) +{ + // uint32_t valueG70R70B70 = 0b111100001010101011001100; // 0xf0aacc + uint32_t valueG70R70B70 = (green << 16) | (red << 8) | blue; + uint32_t valueB07R07G07 = 0; + + for (uint8_t i = 0; i < 24; i += 1) + { + valueB07R07G07 <<= 1; + valueB07R07G07 |= (valueG70R70B70 & 1); + valueG70R70B70 >>= 1; + } + + for (uint8_t i = 0; i < 24; i += 1) + { + if (valueB07R07G07 & 1) + { + // 1 code = T1H T1L + // T1H 1-code, High-level time 580ns~1.6μs + // T1L 1-code, Low-level time 220ns~420ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns * 14 = 784 ns + + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns * 6 = 276 ns + } + else + { + // 0 code = T0H T0L + // T0H 0-code, High-level time 220ns~380ns + // T0L 0-code, Low-level time 580ns~1.6μs + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns + GPIO_PinOutSet(wsPort, wsBit); // 56 ns * 5 = 280 ns + + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns + GPIO_PinOutClear(wsPort, wsBit); // 46 ns * 15 = 690 ns + } + valueB07R07G07 >>= 1; + } +} + + +rawWS2813C::rawWS2813C(uint32_t num_leds, pin_size_t pin) +{ + wsPinArduino = pin; +} + +void rawWS2813C::begin() +{ + PinName wsName; + + wsName = pinToPinName(wsPinArduino); + wsPort = getSilabsPortFromArduinoPin(wsName); + wsBit = getSilabsPinFromArduinoPin(wsName); + + wsDefine(wsPort, wsBit); +} + +void rawWS2813C::set_all(uint8_t red, uint8_t green, uint8_t blue) +{ + wsWrite(red, green, blue); +}; diff --git a/examples/EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.h b/examples/EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.h new file mode 100644 index 0000000..b03ce57 --- /dev/null +++ b/examples/EXT4_Matter/EXT4_Matter_RGB/rawWS2813C.h @@ -0,0 +1,56 @@ +/// +/// @file rawWS2813C.h +/// @brief Driver for WS2813C +/// @version 103 +/// @date 16 Feb 2024 +/// +/// @author Rei Vilo for Pervasive Displays https://www.pervasivedisplays.com +/// @copyright Copyright (c) 2010-2024 Rei Vilo for Pervasive Displays +/// @copyright License CC-BY-SA Creative Commons - Attribution - Share Alike +/// https://creativecommons.org/licenses/by-sa/4.0/deed.en +/// +/// @see https://github.com/SiliconLabs/arduino/issues/106 +/// + +#ifndef rawWS2813C_RELEASE +#define rawWS2813C_RELEASE 103 + +#include "Arduino.h" + +/// +/// @class rawWS2813C +/// @details Minimal class for WS2813C +/// +class rawWS2813C +{ + public: + /// + /// @brief Construct WS2813C object + /// + /// @param num_leds 1, ignored + /// @param pin Arduino pin, name `D4` or number `4` + /// + rawWS2813C(uint32_t num_leds, pin_size_t pin); + + /// + /// @brief Initialise + /// + void begin(); + + /// + /// @brief Set RGB LED + /// + /// @param red red component, 0..255 + /// @param green green component, 0..255 + /// @param blue blue component, 0..255 + /// + void set_all(uint8_t red, uint8_t green, uint8_t blue); + + private: + uint8_t wsPinArduino; + uint32_t wsBit; + uint8_t wsPort; // enum GPIO_Port_TypeDef +}; + +#endif // rawWS2813C_RELEASE + diff --git a/library.properties b/library.properties index cc54ea7..23c811d 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PDLS_EXT4_Basic_Matter -version=8.1.0 +version=8.1.1 author=Rei Vilo for Pervasive Displays maintainer=Rei Vilo sentence=Library for Pervasive Displays EPDK-Matter EXT4 board and iTC 2.90-HD screen diff --git a/src/hV_Documentation.h b/src/hV_Documentation.h index 9b119a3..4da55e9 100755 --- a/src/hV_Documentation.h +++ b/src/hV_Documentation.h @@ -48,8 +48,8 @@ /// Additionally, the **[Wiki](https://docs.pervasivedisplays.com/)** provides a gradual introduction to the e-paper technology and how to use it. /// /// @author Rei Vilo -/// @date 21 Nov 2024 -/// @version 810 +/// @date 12 Dec 2024 +/// @version 811 /// /// @copyright © Rei Vilo, 2010-2024 /// @copyright All rights reserved