From 8dc30f15fbd5c16c5bfe2af18b7bab96d898f460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 7 Jul 2022 17:40:25 +0200 Subject: [PATCH] Implement first working version of DMX receiver. Might still be buggy --- firmware/dmx.c | 14 ++++++++++++-- firmware/include/ring-light/dmx.h | 2 +- firmware/main.c | 6 +++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/firmware/dmx.c b/firmware/dmx.c index 16636cc..82da070 100644 --- a/firmware/dmx.c +++ b/firmware/dmx.c @@ -3,11 +3,15 @@ static uint32_t dmx_base_channel; + enum dmx_rx_state_enum { DMX_RX_WAIT_FOR_BREAK = 0, DMX_RX_DATA, }; +static volatile enum dmx_rx_state_enum dmx_state; + + static volatile bool break_received; /** @@ -71,17 +75,22 @@ void USART1_IRQHandler(void) if (isr & USART_ISR_FE) { /* Frame error received. Start of DMX frame */ /* Flush RX data */ + USART1->CR3 &= ~USART_CR3_DMAR; USART1->RQR = USART_RQR_RXFRQ; - USART1->CR3 |= USART_CR3_DMAR; DMA1_Channel3->CCR &= ~DMA_CCR_EN; + while (DMA1_Channel3->CCR & DMA_CCR_EN); DMA1_Channel3->CMAR = (uint32_t)dmx_channel_data; DMA1_Channel3->CPAR = (uint32_t)&USART1->RDR; DMA1_Channel3->CNDTR = DMX_UNIVERSE_SIZE + 1; DMA1_Channel3->CCR |= DMA_CCR_EN; + USART1->RQR = USART_RQR_RXFRQ; USART1->CR3 |= USART_CR3_DMAR; break_received = true; + dmx_state = DMX_RX_DATA; } else if (isr & USART_ISR_RXNE) { - + if (dmx_state != DMX_RX_DATA) { + USART1->RQR = USART_RQR_RXFRQ; + } } __DSB(); @@ -97,6 +106,7 @@ void DMA_CH2_3_DMA2_CH1_2_IRQHandler(void) if (isr & DMA_ISR_TCIF3) { DMA1->ISR; + dmx_state = DMX_RX_WAIT_FOR_BREAK; } __DSB(); } diff --git a/firmware/include/ring-light/dmx.h b/firmware/include/ring-light/dmx.h index 68970db..6fdcbf1 100644 --- a/firmware/include/ring-light/dmx.h +++ b/firmware/include/ring-light/dmx.h @@ -6,7 +6,7 @@ #include #include -#define DMX_UNIVERSE_SIZE (255u) +#define DMX_UNIVERSE_SIZE (512u) #define DMX_USED_CHANNEL_COUNT (129u) /** diff --git a/firmware/main.c b/firmware/main.c index add76ee..34d978a 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -220,9 +220,9 @@ int main(void) last_led_val = led_val; } - - - wait_for_ticks(5); + /* Only wait in case of non-DMX mode */ + if (!(mode == RING_MODE_WAIT_DMX_BREAK || mode == RING_MODE_WAIT_DMX)) + wait_for_ticks(5); if((int16_t)TIM3->CNT > (int16_t)led_val) { led_val = 0u;