Skip to content

Commit

Permalink
Sync with local development
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Mar 30, 2024
1 parent 59c32a7 commit 7c7a47d
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 173 deletions.
17 changes: 4 additions & 13 deletions lib-displayudf/include/displayudf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file displayudf.h
*
*/
/* Copyright (C) 2019-2023 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2019-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 @@ -60,11 +60,7 @@
#endif

#if defined (RDM_RESPONDER)
# if defined (NODE_ARTNET)
# include "artnetrdmresponder.h"
# else
# include "rdmresponder.h"
# endif
# include "rdmdeviceresponder.h"
#endif

namespace displayudf {
Expand Down Expand Up @@ -219,13 +215,8 @@ class DisplayUdf final: public Display {

#if defined (RDM_RESPONDER)
void ShowDmxStartAddress() {
# if defined (NODE_ARTNET)
const auto nDmxStartAddress = ArtNetRdmResponder::Get()->GetDmxStartAddress();
const auto nDmxFootprint = ArtNetRdmResponder::Get()->GetDmxFootPrint();
# else
const auto nDmxStartAddress = RDMResponder::Get()->GetDmxStartAddress();
const auto nDmxFootprint = RDMResponder::Get()->GetDmxFootPrint();
# endif
const auto nDmxStartAddress = RDMDeviceResponder::Get()->GetDmxStartAddress();
const auto nDmxFootprint = RDMDeviceResponder::Get()->GetDmxFootPrint();
Printf(m_aLabels[static_cast<uint32_t>(displayudf::Labels::DMX_START_ADDRESS)], "DMX S:%3u F:%3u", nDmxStartAddress, nDmxFootprint);
}
#endif
Expand Down
24 changes: 0 additions & 24 deletions lib-dmx/src/gd32/dmx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,15 @@ static void irq_handler_dmx_rdm_input(const uint32_t uart, const uint32_t nPortI

if (RESET != (USART_REG_VAL(uart, USART_FLAG_FERR) & BIT(USART_BIT_POS(USART_FLAG_FERR)))) {
USART_REG_VAL(uart, USART_FLAG_FERR) &= ~BIT(USART_BIT_POS(USART_FLAG_FERR));
#if defined (GD32H7XX)
static_cast<void>(GET_BITS(USART_RDATA(uart), 0U, 8U));
#else
static_cast<void>(GET_BITS(USART_DATA(uart), 0U, 8U));
#endif
if (sv_RxBuffer[nPortIndex].State == TxRxState::IDLE) {
sv_RxBuffer[nPortIndex].Dmx.nSlotsInPacket = 0;
sv_RxBuffer[nPortIndex].State = TxRxState::BREAK;
}
return;
}

#if defined (GD32H7XX)
const auto data = static_cast<uint8_t>(GET_BITS(USART_RDATA(uart), 0U, 8U));
#else
const auto data = static_cast<uint8_t>(GET_BITS(USART_DATA(uart), 0U, 8U));
#endif

switch (sv_RxBuffer[nPortIndex].State) {
case TxRxState::IDLE:
Expand Down Expand Up @@ -2452,19 +2444,11 @@ void Dmx::RdmSendRaw(const uint32_t nPortIndex, const uint8_t* pRdmData, uint32_
for (uint32_t i = 0; i < nLength; i++) {
while (RESET == usart_flag_get(nUart, USART_FLAG_TBE))
;
#if defined (GD32H7XX)
USART_TDATA(nUart) = USART_TDATA_TDATA & pRdmData[i];
#else
USART_DATA(nUart) = (USART_DATA_DATA & pRdmData[i]);
#endif
}

while (SET != usart_flag_get(nUart, USART_FLAG_TC)) {
#if defined (GD32H7XX)
static_cast<void>(GET_BITS(USART_RDATA(nUart), 0U, 8U));
#else
static_cast<void>(GET_BITS(USART_DATA(nUart), 0U, 8U));
#endif
}

#if !defined (CONFIG_DMX_DISABLE_STATISTICS)
Expand All @@ -2487,19 +2471,11 @@ void Dmx::RdmSendDiscoveryRespondMessage(uint32_t nPortIndex, const uint8_t *pRd
for (uint32_t i = 0; i < nLength; i++) {
while (RESET == usart_flag_get(nUart, USART_FLAG_TBE))
;
#if defined (GD32H7XX)
USART_TDATA(nUart) = USART_TDATA_TDATA & pRdmData[i];
#else
USART_DATA(nUart) = (USART_DATA_DATA & pRdmData[i]);
#endif
}

while (SET != usart_flag_get(nUart, USART_FLAG_TC)) {
#if defined (GD32H7XX)
static_cast<void>(GET_BITS(USART_RDATA(nUart), 0U, 8U));
#else
static_cast<void>(GET_BITS(USART_DATA(nUart), 0U, 8U));
#endif
}

TIMER_CNT(TIMER5) = 0;
Expand Down
13 changes: 8 additions & 5 deletions lib-dmx/src/gd32/dmx_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ inline void _gpio_mode_af(const uint32_t gpio_periph, const uint32_t pin, const
# define DMA_INTERRUPT_FLAG_GET (DMA_INT_FLAG_FTF)
# define DMA_INTERRUPT_FLAG_CLEAR (DMA_INT_FLAG_FTF | DMA_INT_FLAG_TAE)
#else
// U(S)ART
# define USART_TDATA USART_DATA
# define USART_RDATA USART_DATA
# define USART_TDATA_TDATA USART_DATA_DATA
# define USART_RDATA_TDATA USART_DATA_DATA
// GPIO
inline void _gpio_mode_output(const uint32_t gpio_periph, const uint32_t pin) {
gpio_init(gpio_periph, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, pin);
Expand All @@ -199,4 +194,12 @@ inline void _gpio_mode_af(const uint32_t gpio_periph, const uint32_t pin, [[mayb
# define DMA_INTERRUPT_FLAG_CLEAR (DMA_INT_FLAG_FTF | DMA_INT_FLAG_G)
#endif

#if !defined (GD32H7XX)
// U(S)ART
# define USART_TDATA USART_DATA
# define USART_RDATA USART_DATA
# define USART_TDATA_TDATA USART_DATA_DATA
# define USART_RDATA_TDATA USART_DATA_DATA
#endif

#endif /* GD32_DMX_INTERNAL_H_ */
2 changes: 1 addition & 1 deletion lib-rdm/include/rdmconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct TRdmDiscoveryMsg {
}PACKED;

// Unique identifier (UID) which consists of a 2 byte ESTA manufacturer ID, and a 4 byte device ID.
static const uint8_t UID_ALL[RDM_UID_SIZE] __attribute__((aligned(4))) = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
static constexpr uint8_t UID_ALL[RDM_UID_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

struct RDMConst {
static const char MANUFACTURER_NAME[];
Expand Down
7 changes: 4 additions & 3 deletions lib-rdm/include/rdmhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define RDMHANDLER_H_

#include <cstdint>
#include <cstring>

#if defined (NODE_RDMNET_LLRP_ONLY)
# if defined (CONFIG_RDM_ENABLE_MANUFACTURER_PIDS)
Expand All @@ -49,10 +50,10 @@ class RDMHandler {
void HandleData(const uint8_t *pRdmDataIn, uint8_t *pRdmDataOut);

private:
void CreateRespondMessage(uint8_t nResponseType, uint16_t nReason = 0);
void CreateRespondMessage(const uint8_t nResponseType, const uint16_t nReason);
void RespondMessageAck();
void RespondMessageNack(uint16_t nReason);
void HandleString(const char *pString, uint32_t nLength);
void RespondMessageNack(const uint16_t nReason);
void HandleString(const char *pString, const uint32_t nLength);
void Handlers(bool bIsBroadcast, uint8_t nCommandClass, uint16_t nParamId, uint8_t nParamDataLength, uint16_t nSubDevice);

// Get
Expand Down
115 changes: 94 additions & 21 deletions lib-rdm/include/rdmresponder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file rdmresponder.h
*
*/
/* Copyright (C) 2018-2023 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2018-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 All @@ -27,34 +27,42 @@
#define RDMRESPONDER_H_

#include <cstdint>
#include <cstring>
#include <cassert>

#include "dmxreceiver.h"

#include "rdm.h"
#include "rdmhandler.h"
#include "rdmdeviceresponder.h"
#include "rdmpersonality.h"

#include "dmxreceiver.h"

#include "lightset.h"

#include "debug.h"

#if defined (NODE_RDMNET_LLRP_ONLY)
# error "Cannot be both RDMNet Device and RDM Responder"
#endif

namespace rdm {
namespace responder {
static constexpr auto NO_DATA = 0;
static constexpr auto DISCOVERY_RESPONSE = -1;
static constexpr auto INVALID_DATA_RECEIVED = -2;
static constexpr auto INVALID_RESPONSE = -3;
static constexpr int NO_DATA = 0;
static constexpr int DISCOVERY_RESPONSE = -1;
static constexpr int INVALID_DATA_RECEIVED = -2;
static constexpr int INVALID_RESPONSE = -3;
} // namespace responder
} // namespace rdm

namespace configstore {
void delay();
} // namespace configstore

class RDMResponder final : DMXReceiver, public RDMDeviceResponder, RDMHandler {
public:
RDMResponder(RDMPersonality **pRDMPersonalities, uint32_t nPersonalityCount, const uint32_t nCurrentPersonality = rdm::device::responder::DEFAULT_CURRENT_PERSONALITY) :
DMXReceiver(pRDMPersonalities[nCurrentPersonality - 1]->GetLightSet()),
RDMDeviceResponder(pRDMPersonalities, nPersonalityCount, nCurrentPersonality)
DMXReceiver(pRDMPersonalities[nCurrentPersonality - 1]->GetLightSet()),
RDMDeviceResponder(pRDMPersonalities, nPersonalityCount, nCurrentPersonality)
{
assert(s_pThis == nullptr);
s_pThis = this;
Expand All @@ -67,7 +75,60 @@ class RDMResponder final : DMXReceiver, public RDMDeviceResponder, RDMHandler {
// There is no DMXReceiver::Init()
}

int Run();
int Run() {
int16_t nLength;

#if !defined (CONFIG_RDM_ENABLE_SUBDEVICES)
DMXReceiver::Run(nLength);
#else
const auto *pDmxDataIn = DMXReceiver::Run(nLength);

if (RDMSubDevices::Get()->GetCount() != 0) {
if (nLength == -1) {
if (m_IsSubDeviceActive) {
RDMSubDevices::Get()->Stop();
m_IsSubDeviceActive = false;
}
} else if (pDmxDataIn != nullptr) {
RDMSubDevices::Get()->SetData(pDmxDataIn, static_cast<uint16_t>(nLength));
if (!m_IsSubDeviceActive) {
RDMSubDevices::Get()->Start();
m_IsSubDeviceActive = true;
}
}
}
#endif

const auto *pRdmDataIn = Rdm::Receive(0);

if (pRdmDataIn == nullptr) {
return rdm::responder::NO_DATA;
}

#ifndef NDEBUG
rdm::message_print(pRdmDataIn);
#endif

if (pRdmDataIn[0] == E120_SC_RDM) {
const auto *pRdmCommand = reinterpret_cast<const struct TRdmMessage*>(pRdmDataIn);

switch (pRdmCommand->command_class) {
case E120_DISCOVERY_COMMAND:
case E120_GET_COMMAND:
case E120_SET_COMMAND:
HandleData(&pRdmDataIn[1], reinterpret_cast<uint8_t*>(&s_RdmCommand));
return HandleResponse(reinterpret_cast<uint8_t*>(&s_RdmCommand));
break;
default:
DEBUG_PUTS("RDM_RESPONDER_INVALID_DATA_RECEIVED");
return rdm::responder::INVALID_DATA_RECEIVED;
break;
}
}

DEBUG_PUTS("RDM_RESPONDER_DISCOVERY_RESPONSE");
return rdm::responder::DISCOVERY_RESPONSE;
}

void Print() {
RDMDeviceResponder::Print();
Expand All @@ -79,27 +140,39 @@ class RDMResponder final : DMXReceiver, public RDMDeviceResponder, RDMHandler {
DMXReceiver::Start();
}

void DmxDisableOutput(bool bDisable) {
void DmxDisableOutput(const bool bDisable) {
DMXReceiver::SetDisableOutput(bDisable);
}

uint16_t GetDmxStartAddress(uint16_t nSubDevice = RDM_ROOT_DEVICE) {
return RDMDeviceResponder::GetDmxStartAddress(nSubDevice);
}

uint16_t GetDmxFootPrint(uint16_t nSubDevice = RDM_ROOT_DEVICE) {
return RDMDeviceResponder::GetDmxFootPrint(nSubDevice);
}

static RDMResponder* Get() {
static RDMResponder *Get() {
return s_pThis;
}

void PersonalityUpdate(uint32_t nPersonality) __attribute__((weak));
void DmxStartAddressUpdate(uint16_t nDmxStartAddress) __attribute__((weak));

private:
int HandleResponse(uint8_t *pResponse);
int HandleResponse(const uint8_t *pResponse) {
auto nLength = rdm::responder::INVALID_RESPONSE;

if (pResponse[0] == E120_SC_RDM) {
const auto *p = reinterpret_cast<const struct TRdmMessage*>(pResponse);
nLength = static_cast<int>(p->message_length + RDM_MESSAGE_CHECKSUM_SIZE);
Rdm::SendRawRespondMessage(0, pResponse, static_cast<uint16_t>(nLength));
} else if (pResponse[0] == 0xFE) {
nLength = sizeof(struct TRdmDiscoveryMsg);
Rdm::SendDiscoveryRespondMessage(0, pResponse, static_cast<uint16_t>(nLength));
}

#ifndef NDEBUG
if (nLength != INVALID_RESPONSE) {
rdm::message_print(pResponse);
}
#endif

configstore::delay();
return nLength;
}

void PersonalityUpdate(LightSet *pLightSet) override {
DMXReceiver::SetLightSet(pLightSet);
Expand Down
23 changes: 8 additions & 15 deletions lib-rdm/src/rdmhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ RDMHandler::RDMHandler(bool bIsRdm): m_bIsRDM(bIsRdm) {
DEBUG_EXIT
}

void RDMHandler::HandleString(const char *pString, uint32_t nLength) {
void RDMHandler::HandleString(const char *pString, const uint32_t nLength) {
auto *RdmMessage = reinterpret_cast<struct TRdmMessage *>(m_pRdmDataOut);

RdmMessage->param_data_length = static_cast<uint8_t>(nLength);
Expand All @@ -166,9 +166,7 @@ void RDMHandler::HandleString(const char *pString, uint32_t nLength) {
}
}

void RDMHandler::CreateRespondMessage(uint8_t nResponseType, uint16_t nReason) {
unsigned i;

void RDMHandler::CreateRespondMessage(const uint8_t nResponseType, const uint16_t nReason) {
auto *pRdmDataIn = reinterpret_cast<struct TRdmMessageNoSc *>(m_pRdmDataIn);
auto *pRdmDataOut = reinterpret_cast<struct TRdmMessage *>(m_pRdmDataOut);

Expand Down Expand Up @@ -203,12 +201,13 @@ void RDMHandler::CreateRespondMessage(uint8_t nResponseType, uint16_t nReason) {

const auto *pUID = RDMDeviceResponder::Get()->GetUID();

for (i = 0; i < RDM_UID_SIZE; i++) {
for (uint32_t i = 0; i < RDM_UID_SIZE; i++) {
pRdmDataOut->destination_uid[i] = pRdmDataIn->source_uid[i];
pRdmDataOut->source_uid[i] = pUID[i];
}

uint16_t rdm_checksum = 0;
uint32_t i;

for (i = 0; i < pRdmDataOut->message_length; i++) {
rdm_checksum = static_cast<uint16_t>(rdm_checksum + m_pRdmDataOut[i]);
Expand All @@ -219,16 +218,10 @@ void RDMHandler::CreateRespondMessage(uint8_t nResponseType, uint16_t nReason) {
}

void RDMHandler::RespondMessageAck() {
auto *pRdmDataIn = reinterpret_cast<struct TRdmMessageNoSc *>(m_pRdmDataIn);

if(pRdmDataIn->param_data_length == 0) {
pRdmDataIn->message_length = RDM_MESSAGE_MINIMUM_SIZE;
}

CreateRespondMessage(E120_RESPONSE_TYPE_ACK);
CreateRespondMessage(E120_RESPONSE_TYPE_ACK, 0);
}

void RDMHandler::RespondMessageNack(uint16_t nReason) {
void RDMHandler::RespondMessageNack(const uint16_t nReason) {
CreateRespondMessage(E120_RESPONSE_TYPE_NACK_REASON, nReason);
}

Expand Down Expand Up @@ -493,10 +486,10 @@ void RDMHandler::GetSupportedParameters(uint16_t nSubDevice) {
uint32_t nTableSize = 0;

if (nSubDevice != 0) {
pPidDefinitions = const_cast<PidDefinition*>(&PID_DEFINITIONS_SUB_DEVICES[0]);
pPidDefinitions = const_cast<PidDefinition *>(&PID_DEFINITIONS_SUB_DEVICES[0]);
nTableSize = sizeof(PID_DEFINITIONS_SUB_DEVICES) / sizeof(PID_DEFINITIONS_SUB_DEVICES[0]);
} else {
pPidDefinitions = const_cast<PidDefinition*>(&PID_DEFINITIONS[0]);
pPidDefinitions = const_cast<PidDefinition *>(&PID_DEFINITIONS[0]);
nTableSize = sizeof(PID_DEFINITIONS) / sizeof(PID_DEFINITIONS[0]);
}

Expand Down
Loading

0 comments on commit 7c7a47d

Please sign in to comment.