-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
36 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
DEFINES=USE_SPI_DMA | ||
#DEFINES+=NDEBUG | ||
#DEFINES=NDEBUG | ||
|
||
EXTRA_INCLUDES= | ||
|
||
EXTRA_SRCDIR=src/patterns src/pixel src/gd32/gpio src/gd32/i2s | ||
EXTRA_SRCDIR=src/patterns src/pixel | ||
|
||
ifneq ($(MAKE_FLAGS),) | ||
ifeq ($(findstring OUTPUT_DMX_PIXEL_MULTI,$(MAKE_FLAGS)), OUTPUT_DMX_PIXEL_MULTI) | ||
EXTRA_SRCDIR+=src/gd32/gpio | ||
else | ||
EXTRA_SRCDIR+=src/gd32/i2s | ||
endif | ||
else | ||
EXTRA_SRCDIR+=src/gd32/gpio src/gd32/i2s | ||
endif | ||
|
||
include ../firmware-template-gd32/lib/Rules.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* @file ws28xx.h | ||
* | ||
*/ | ||
/* Copyright (C) 2017-2023 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2017-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -30,9 +30,7 @@ | |
|
||
#include "pixelconfiguration.h" | ||
|
||
#if defined (USE_SPI_DMA) | ||
# include "hal_spi.h" | ||
#endif | ||
#include "hal_spi.h" | ||
|
||
class WS28xx { | ||
public: | ||
|
@@ -42,15 +40,15 @@ class WS28xx { | |
void SetPixel(uint32_t nIndex, uint8_t nRed, uint8_t nGreen, uint8_t nBlue); | ||
void SetPixel(uint32_t nIndex, uint8_t nRed, uint8_t nGreen, uint8_t nBlue, uint8_t nWhite); | ||
|
||
#if defined ( USE_SPI_DMA ) | ||
bool IsUpdating () { | ||
return FUNC_PREFIX (spi_dma_tx_is_active()); | ||
} | ||
#if defined (GD32) | ||
return i2s::gd32_spi_dma_tx_is_active(); | ||
#elif defined (H3) | ||
return h3_spi_dma_tx_is_active(); | ||
#else | ||
bool IsUpdating() const { | ||
return false; | ||
} | ||
#endif | ||
} | ||
|
||
void Update(); | ||
void Blackout(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* @file ws28xx.cpp | ||
* | ||
*/ | ||
/* Copyright (C) 2022 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2022-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -30,12 +30,10 @@ | |
#include "ws28xx.h" | ||
#include "pixelconfiguration.h" | ||
|
||
#include "hal_spi.h" | ||
#include "gd32_spi.h" | ||
|
||
#include "debug.h" | ||
|
||
using namespace pixel; | ||
|
||
static uint32_t s_tmp; | ||
|
||
WS28xx *WS28xx::s_pThis; | ||
|
@@ -63,15 +61,15 @@ WS28xx::WS28xx(PixelConfiguration& pixelConfiguration) { | |
|
||
const auto type = m_PixelConfiguration.GetType(); | ||
|
||
if ((type == Type::APA102) || (type == Type::SK9822) || (type == Type::P9813)) { | ||
if ((type == pixel::Type::APA102) || (type == pixel::Type::SK9822) || (type == pixel::Type::P9813)) { | ||
m_nBufSize += nCount; | ||
m_nBufSize += 8; | ||
} | ||
|
||
SetupBuffers(); | ||
|
||
FUNC_PREFIX(spi_dma_begin()); | ||
FUNC_PREFIX(spi_dma_set_speed_hz(pixelConfiguration.GetClockSpeedHz())); | ||
i2s::gd32_spi_dma_begin(); | ||
i2s::gd32_spi_dma_set_speed_hz(pixelConfiguration.GetClockSpeedHz()); | ||
|
||
DEBUG_EXIT | ||
} | ||
|
@@ -87,7 +85,7 @@ void WS28xx::SetupBuffers() { | |
|
||
uint32_t nSize; | ||
|
||
m_pBuffer = const_cast<uint8_t*>(FUNC_PREFIX (spi_dma_tx_prepare(&nSize))); | ||
m_pBuffer = const_cast<uint8_t *>(i2s::gd32_spi_dma_tx_prepare(&nSize)); | ||
assert(m_pBuffer != nullptr); | ||
|
||
const auto nSizeHalf = nSize / 2; | ||
|
@@ -118,7 +116,7 @@ void WS28xx::Update() { | |
pDst[i] = __builtin_bswap16(pSrc[i]); | ||
} | ||
|
||
FUNC_PREFIX(spi_dma_tx_start(m_pBlackoutBuffer, m_nBufSize)); | ||
i2s::gd32_spi_dma_tx_start(m_pBlackoutBuffer, m_nBufSize); | ||
} | ||
|
||
void WS28xx::Blackout() { | ||
|
@@ -127,37 +125,37 @@ void WS28xx::Blackout() { | |
// A blackout can be called any time. Make sure the previous transmit is ended. | ||
do { | ||
__ISB(); | ||
} while (FUNC_PREFIX(spi_dma_tx_is_active())); | ||
} while (i2s::gd32_spi_dma_tx_is_active()); | ||
|
||
auto *pBuffer = m_pBuffer; | ||
m_pBuffer = m_pBlackoutBuffer; | ||
|
||
const auto type = m_PixelConfiguration.GetType(); | ||
const auto nCount = m_PixelConfiguration.GetCount(); | ||
|
||
if ((type == Type::APA102) || (type == Type::SK9822) || (type == Type::P9813)) { | ||
if ((type == pixel::Type::APA102) || (type == pixel::Type::SK9822) || (type == pixel::Type::P9813)) { | ||
memset(m_pBuffer, 0, 4); | ||
|
||
for (uint32_t nPixelIndex = 0; nPixelIndex < nCount; nPixelIndex++) { | ||
SetPixel(nPixelIndex, 0, 0, 0); | ||
} | ||
|
||
if ((type == Type::APA102) || (type == Type::SK9822)) { | ||
if ((type == pixel::Type::APA102) || (type == pixel::Type::SK9822)) { | ||
memset(&m_pBuffer[m_nBufSize - 4], 0xFF, 4); | ||
} else { | ||
memset(&m_pBuffer[m_nBufSize - 4], 0, 4); | ||
} | ||
} else { | ||
m_pBuffer[0] = 0x00; | ||
memset(&m_pBuffer[1], type == Type::WS2801 ? 0 : m_PixelConfiguration.GetLowCode(), m_nBufSize); | ||
memset(&m_pBuffer[1], type == pixel::Type::WS2801 ? 0 : m_PixelConfiguration.GetLowCode(), m_nBufSize); | ||
} | ||
|
||
Update(); | ||
|
||
// A blackout may not be interrupted. | ||
do { | ||
__ISB(); | ||
} while (FUNC_PREFIX(spi_dma_tx_is_active())); | ||
} while (i2s::gd32_spi_dma_tx_is_active()); | ||
|
||
m_pBuffer = pBuffer; | ||
|
||
|
@@ -170,37 +168,37 @@ void WS28xx::FullOn() { | |
// Can be called any time. Make sure the previous transmit is ended. | ||
do { | ||
__ISB(); | ||
} while (FUNC_PREFIX(spi_dma_tx_is_active())); | ||
} while (i2s::gd32_spi_dma_tx_is_active()); | ||
|
||
auto *pBuffer = m_pBuffer; | ||
m_pBuffer = m_pBlackoutBuffer; | ||
|
||
const auto type = m_PixelConfiguration.GetType(); | ||
const auto nCount = m_PixelConfiguration.GetCount(); | ||
|
||
if ((type == Type::APA102) || (type == Type::SK9822) || (type == Type::P9813)) { | ||
if ((type == pixel::Type::APA102) || (type == pixel::Type::SK9822) || (type == pixel::Type::P9813)) { | ||
memset(m_pBuffer, 0, 4); | ||
|
||
for (uint32_t nPixelIndex = 0; nPixelIndex < nCount; nPixelIndex++) { | ||
SetPixel(nPixelIndex, 0xFF, 0xFF, 0xFF); | ||
} | ||
|
||
if ((type == Type::APA102) || (type == Type::SK9822)) { | ||
if ((type == pixel::Type::APA102) || (type == pixel::Type::SK9822)) { | ||
memset(&m_pBuffer[m_nBufSize - 4], 0xFF, 4); | ||
} else { | ||
memset(&m_pBuffer[m_nBufSize - 4], 0, 4); | ||
} | ||
} else { | ||
m_pBuffer[0] = 0x00; | ||
memset(&m_pBuffer[1], type == Type::WS2801 ? 0xFF : m_PixelConfiguration.GetHighCode(), m_nBufSize); | ||
memset(&m_pBuffer[1], type == pixel::Type::WS2801 ? 0xFF : m_PixelConfiguration.GetHighCode(), m_nBufSize); | ||
} | ||
|
||
Update(); | ||
|
||
// May not be interrupted. | ||
do { | ||
__ISB(); | ||
} while (FUNC_PREFIX(spi_dma_tx_is_active())); | ||
} while (i2s::gd32_spi_dma_tx_is_active()); | ||
|
||
m_pBuffer = pBuffer; | ||
|
||
|