Skip to content

Commit

Permalink
Removed #define USE_SPI_DMA
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Mar 11, 2024
1 parent 4ef9921 commit 2c04c14
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
15 changes: 12 additions & 3 deletions lib-ws28xx/Makefile.GD32
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
16 changes: 7 additions & 9 deletions lib-ws28xx/include/ws28xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -30,9 +30,7 @@

#include "pixelconfiguration.h"

#if defined (USE_SPI_DMA)
# include "hal_spi.h"
#endif
#include "hal_spi.h"

class WS28xx {
public:
Expand All @@ -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();
Expand Down
36 changes: 17 additions & 19 deletions lib-ws28xx/src/gd32/i2s/ws28xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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;

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

Expand Down

0 comments on commit 2c04c14

Please sign in to comment.