From af93aba0daafebff4ed253d74f50f767297befb7 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Fri, 19 Aug 2022 10:32:47 +0100 Subject: [PATCH] aux_serial: Moved the transmit buffer swap function declaration into aux_serial.h and implemented a function to get the current buffer --- src/platforms/common/aux_serial.c | 5 +++++ src/platforms/common/aux_serial.h | 5 +++++ src/platforms/common/usb_serial.c | 2 +- src/platforms/common/usbuart.h | 1 - 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/platforms/common/aux_serial.c b/src/platforms/common/aux_serial.c index 7c0787f..5de17a1 100644 --- a/src/platforms/common/aux_serial.c +++ b/src/platforms/common/aux_serial.c @@ -93,4 +93,9 @@ void aux_serial_switch_transmit_buffers(void) buf_tx_act_sz = 0; buf_tx_act_idx ^= 1; } + +char *aux_serial_current_transmit_buffer(void) +{ + return buf_tx + (buf_tx_act_idx * TX_BUF_SIZE); +} #endif diff --git a/src/platforms/common/aux_serial.h b/src/platforms/common/aux_serial.h index 2638779..9302a4d 100644 --- a/src/platforms/common/aux_serial.h +++ b/src/platforms/common/aux_serial.h @@ -26,4 +26,9 @@ void aux_serial_init(void); void aux_serial_set_encoding(struct usb_cdc_line_coding *coding); +#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) +void aux_serial_switch_transmit_buffers(void); +char *aux_serial_current_transmit_buffer(void); +#endif + #endif /*AUX_SERIAL_H*/ diff --git a/src/platforms/common/usb_serial.c b/src/platforms/common/usb_serial.c index c263102..0037c94 100644 --- a/src/platforms/common/usb_serial.c +++ b/src/platforms/common/usb_serial.c @@ -317,7 +317,7 @@ static void debug_uart_receive_callback(usbd_device *dev, uint8_t ep) usbd_ep_nak_set(dev, CDCACM_UART_ENDPOINT, 1); /* Read new packet directly into TX buffer */ - char *const tx_buf_ptr = &buf_tx[buf_tx_act_idx * TX_BUF_SIZE]; + char *const tx_buf_ptr = aux_serial_current_transmit_buffer(); const uint16_t len = usbd_ep_read_packet(dev, CDCACM_UART_ENDPOINT, tx_buf_ptr + buf_tx_act_sz, CDCACM_PACKET_SIZE); #if defined(BLACKMAGIC) diff --git a/src/platforms/common/usbuart.h b/src/platforms/common/usbuart.h index bf40ae3..40214b0 100644 --- a/src/platforms/common/usbuart.h +++ b/src/platforms/common/usbuart.h @@ -23,7 +23,6 @@ #include "general.h" void usbuart_set_led_state(uint8_t ledn, bool state); -void aux_serial_switch_transmit_buffers(void); void debug_uart_run(void); #define TX_LED_ACT (1 << 0)