Skip to content

Commit

Permalink
Release 8.1.1
Browse files Browse the repository at this point in the history
Added patch for ezWS2812gpio issue (see SiliconLabs/arduino#106)
  • Loading branch information
rei-vilo committed Dec 12, 2024
1 parent 43eae09 commit 4848a52
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 11 deletions.
10 changes: 6 additions & 4 deletions examples/EXT4/EXT4_WS2813C/EXT4_WS2813C.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +30,8 @@
#include "Arduino.h"

// WS2813C
#include "ezWS2812gpio.h"
// #include "ezWS2812gpio.h"
#include "rawWS2813C.h"

// Set parameters

Expand All @@ -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

Expand Down
143 changes: 143 additions & 0 deletions examples/EXT4/EXT4_WS2813C/rawWS2813C.cpp
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#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);
};
56 changes: 56 additions & 0 deletions examples/EXT4/EXT4_WS2813C/rawWS2813C.h
Original file line number Diff line number Diff line change
@@ -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

10 changes: 6 additions & 4 deletions examples/EXT4_Matter/EXT4_Matter_RGB/EXT4_Matter_RGB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -45,7 +45,8 @@
MatterColorLightbulb myMatterRGB;

// WS2813C
#include "ezWS2812gpio.h"
// #include "ezWS2812gpio.h"
#include "rawWS2813C.h"

// PDLS
#include "PDLS_EXT4_Basic_Matter.h"
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4848a52

Please sign in to comment.