3535#include < algorithm>
3636#include < cassert>
3737
38- #include " dmx.h"
38+ #include " dmx.h" // IWYU pragma: keep
3939#include " dmxconst.h"
4040#include " rdm.h"
4141#include " rdm_e120.h"
4242#include " gd32.h"
4343#include " gd32_dma.h"
4444#include " gd32_uart.h"
45+ #include " gd32_gpio.h"
4546#include " dmx_internal.h"
4647#include " dmx/dmx_config.h"
4748#include " gd32/dmx_assert.h"
48- #include " gd32/dmx_dma_check.h" // Do not reorder/move
49+ #include " gd32/dmx_dma_check.h" // IWYU pragma: keep // Do not reorder/move
4950#if defined(LOGIC_ANALYZER)
5051#include " logic_analyzer.h"
5152#endif
@@ -69,7 +70,7 @@ enum class TxRxState {
6970enum class PortState { kIdle , kTx , kRx };
7071
7172struct TxDmxDataPacket {
72- uint8_t data[dmx::buffer::SIZE ]; // multiple of uint32_t
73+ uint8_t data[dmx::buffer::kSize ]; // multiple of uint32_t
7374 uint32_t length;
7475};
7576
@@ -99,7 +100,7 @@ struct RxDmxPackets {
99100};
100101
101102struct RxDmxData {
102- uint8_t data[dmx::buffer::SIZE ] ALIGNED ; // multiple of uint32_t
103+ uint8_t data[dmx::buffer::kSize ] ALIGNED ; // multiple of uint32_t
103104 uint32_t slots_in_packet;
104105};
105106
@@ -146,26 +147,26 @@ static constexpr dmx::DirGpio kDirGpio[DMX_MAX_PORTS] = {
146147#endif
147148};
148149
149- static volatile dmx::PortState sv_port_state[dmx::config::max::PORTS ] ALIGNED ;
150+ static volatile dmx::PortState sv_port_state[dmx::config::max::kPorts ] ALIGNED ;
150151
151152#if !defined(CONFIG_DMX_DISABLE_STATISTICS)
152- static volatile dmx::TotalStatistics sv_total_statistics[dmx::config::max::PORTS ] ALIGNED ;
153+ static volatile dmx::TotalStatistics sv_total_statistics[dmx::config::max::kPorts ] ALIGNED ;
153154#endif
154155
155156// DMX RX
156157
157- static volatile dmx::RxDmxPackets sv_rx_dmx_packets[dmx::config::max::PORTS ] ALIGNED ;
158+ static volatile dmx::RxDmxPackets sv_rx_dmx_packets[dmx::config::max::kPorts ] ALIGNED ;
158159
159160// RDM RX
160161volatile uint32_t gsv_RdmDataReceiveEnd;
161162
162163// DMX RDM RX
163164
164- static volatile dmx::RxData sv_rx_buffer[dmx::config::max::PORTS ] ALIGNED ;
165+ static volatile dmx::RxData sv_rx_buffer[dmx::config::max::kPorts ] ALIGNED ;
165166
166167// DMX TX
167168
168- static dmx::TxData s_TxBuffer[dmx::config::max::PORTS ] ALIGNED SECTION_DMA_BUFFER ;
169+ static dmx::TxData s_TxBuffer[dmx::config::max::kPorts ] ALIGNED SECTION_DMA_BUFFER ;
169170static dmx::DmxTransmit s_dmx_transmit;
170171
171172template <uint32_t uart, uint32_t port_index> void IrqHandlerDmxRdmInput () {
@@ -1390,11 +1391,11 @@ void Dmx::SetPortDirection(uint32_t port_index, dmx::PortDirection port_directio
13901391}
13911392
13921393void Dmx::ClearData (uint32_t port_index) {
1393- assert (port_index < dmx::config::max::PORTS );
1394+ assert (port_index < dmx::config::max::kPorts );
13941395
13951396 auto * p = &s_TxBuffer[port_index].dmx .data [0 ];
13961397 p->length = 513 ; // Including START Code
1397- __builtin_memset (p->data , 0 , dmx::buffer::SIZE );
1398+ __builtin_memset (p->data , 0 , dmx::buffer::kSize );
13981399}
13991400
14001401#if !defined(CONFIG_DMX_DISABLE_STATISTICS)
@@ -1499,13 +1500,13 @@ template <uint32_t port_index, uint32_t nUart> static void StartDmxOutput() {
14991500}
15001501
15011502template <uint32_t portIndex> static void StartDmxOutputPort () {
1502- if constexpr (portIndex < dmx::config::max::PORTS ) {
1503+ if constexpr (portIndex < dmx::config::max::kPorts ) {
15031504 StartDmxOutput<portIndex, DmxPortToUart (portIndex)>();
15041505 }
15051506}
15061507
15071508void Dmx::StartDmxOutput (uint32_t port_index) {
1508- assert (port_index < dmx::config::max::PORTS );
1509+ assert (port_index < dmx::config::max::kPorts );
15091510
15101511 switch (port_index) {
15111512 case 0 :
@@ -1649,7 +1650,7 @@ void Dmx::FullOn() {
16491650 auto * __restrict__ p = &s_TxBuffer[port_index].dmx .data [0 ];
16501651 auto * p32 = reinterpret_cast <uint32_t *>(p->data );
16511652
1652- for (auto i = 0 ; i < dmx::buffer::SIZE / 4 ; i++) {
1653+ for (auto i = 0 ; i < dmx::buffer::kSize / 4 ; i++) {
16531654 *p32++ = UINT32_MAX ;
16541655 }
16551656
@@ -1672,7 +1673,7 @@ void Dmx::StartOutput(uint32_t port_index) {
16721673}
16731674
16741675void Dmx::Sync () {
1675- for (uint32_t port_index = 0 ; port_index < dmx::config::max::PORTS ; port_index++) {
1676+ for (uint32_t port_index = 0 ; port_index < dmx::config::max::kPorts ; port_index++) {
16761677 auto & tx_buffer = s_TxBuffer[port_index];
16771678
16781679 if (!tx_buffer.dmx .data_pending ) {
@@ -1737,7 +1738,7 @@ const uint8_t* Dmx::GetDmxChanged(uint32_t port_index) {
17371738 if (sv_rx_buffer[port_index].dmx .current .slots_in_packet != sv_rx_buffer[port_index].dmx .previous .slots_in_packet ) {
17381739 sv_rx_buffer[port_index].dmx .previous .slots_in_packet = sv_rx_buffer[port_index].dmx .current .slots_in_packet ;
17391740
1740- for (size_t i = 0 ; i < dmx::buffer::SIZE / 4 ; ++i) {
1741+ for (size_t i = 0 ; i < dmx::buffer::kSize / 4 ; ++i) {
17411742 dst32[i] = src32[i];
17421743 }
17431744
@@ -1746,7 +1747,7 @@ const uint8_t* Dmx::GetDmxChanged(uint32_t port_index) {
17461747
17471748 bool is_changed = false ;
17481749
1749- for (size_t i = 0 ; i < dmx::buffer::SIZE / 4 ; ++i) {
1750+ for (size_t i = 0 ; i < dmx::buffer::kSize / 4 ; ++i) {
17501751 const auto kSrcValue = src32[i];
17511752 auto dst_value = dst32[i];
17521753
@@ -2168,7 +2169,7 @@ void Dmx::SetDmxPeriodTime(uint32_t period) {
21682169
21692170 auto length_max = s_TxBuffer[0 ].dmx .data [0 ].length ;
21702171
2171- for (uint32_t port_index = 1 ; port_index < dmx::config::max::PORTS ; port_index++) {
2172+ for (uint32_t port_index = 1 ; port_index < dmx::config::max::kPorts ; port_index++) {
21722173 const auto kLength = s_TxBuffer[port_index].dmx .data [0 ].length ;
21732174 if (kLength > length_max) {
21742175 length_max = kLength ;
@@ -2207,7 +2208,7 @@ void Dmx::SetDmxSlots(uint16_t slots) {
22072208 if ((slots >= 2 ) && (slots <= dmx::kChannelsMax )) {
22082209 m_nDmxTransmitSlots = slots;
22092210
2210- for (uint32_t i = 0 ; i < dmx::config::max::PORTS ; i++) {
2211+ for (uint32_t i = 0 ; i < dmx::config::max::kPorts ; i++) {
22112212 m_nDmxTransmissionLength[i] = static_cast <uint32_t >(slots);
22122213 }
22132214
@@ -2230,20 +2231,20 @@ void Dmx::SetOutputStyle(uint32_t port_index, dmx::OutputStyle output_style) {
22302231 return ;
22312232 }
22322233
2233- for (uint32_t index = 0 ; index < dmx::config::max::PORTS ; index++) {
2234+ for (uint32_t index = 0 ; index < dmx::config::max::kPorts ; index++) {
22342235 if ((s_TxBuffer[index].output_style == dmx::OutputStyle::kConstant ) && (m_dmxPortDirection[index] == dmx::PortDirection::kOutput )) {
22352236 StopData (index);
22362237 }
22372238 }
22382239
2239- for (uint32_t index = 0 ; index < dmx::config::max::PORTS ; index++) {
2240+ for (uint32_t index = 0 ; index < dmx::config::max::kPorts ; index++) {
22402241 if ((s_TxBuffer[index].output_style == dmx::OutputStyle::kConstant ) && (m_dmxPortDirection[index] == dmx::PortDirection::kOutput )) {
22412242 StartDmxOutput (index);
22422243 }
22432244 }
22442245 } else {
22452246 m_bHasContinuosOutput = false ;
2246- for (uint32_t index = 0 ; index < dmx::config::max::PORTS ; index++) {
2247+ for (uint32_t index = 0 ; index < dmx::config::max::kPorts ; index++) {
22472248 if (s_TxBuffer[index].output_style == dmx::OutputStyle::kConstant ) {
22482249 m_bHasContinuosOutput = true ;
22492250 return ;
@@ -2273,20 +2274,15 @@ Dmx::Dmx() {
22732274 s_dmx_transmit.inter_time = dmx::transmit::kPeriodDefault - s_dmx_transmit.break_time - s_dmx_transmit.mab_time - (dmx::kChannelsMax * 44 ) - 44 ;
22742275
22752276 for (auto port_index = 0 ; port_index < DMX_MAX_PORTS ; port_index++) {
2276- #if defined(GPIO_INIT)
2277- gpio_init (kDirGpio [port_index].port , GPIO_MODE_OUT_PP , GPIO_OSPEED_50MHZ , kDirGpio [port_index].pin );
2278- #else
2279- gpio_mode_set (kDirGpio [port_index].port , GPIO_MODE_OUTPUT , GPIO_PUPD_PULLDOWN , kDirGpio [port_index].pin );
2280- gpio_output_options_set (kDirGpio [port_index].port , GPIO_OTYPE_PP , GPIO_OSPEED , kDirGpio [port_index].pin );
2281- #endif
2277+ Gd32GpioFsel (kDirGpio [port_index].port , kDirGpio [port_index].pin , GPIO_FSEL_OUTPUT );
22822278 m_nDmxTransmissionLength[port_index] = dmx::kChannelsMax ;
22832279 sv_rx_buffer[port_index].state = dmx::TxRxState::kIdle ;
22842280 s_TxBuffer[port_index].state = dmx::TxRxState::kIdle ;
22852281 SetPortDirection (port_index, dmx::PortDirection::kInput , false );
22862282 SetOutputStyle (port_index, dmx::OutputStyle::kDelta );
22872283 ClearData (port_index);
22882284 }
2289-
2285+
22902286 SetDmxBreakTime (dmx::transmit::kBreakTimeTypical );
22912287 SetDmxMabTime (dmx::transmit::kMabTimeMin );
22922288 SetDmxSlots (dmx::kChannelsMax );
0 commit comments