Browse Source

usbuart: Moved usbuart_set_line_coding() out into a new file

fix/newlib-file-io-hooks
dragonmux 2 years ago
parent
commit
3faf4221e3
No known key found for this signature in database GPG Key ID: 64861EA89B35507A
  1. 1
      src/platforms/common/Makefile.inc
  2. 73
      src/platforms/common/aux_serial.c
  3. 36
      src/platforms/stm32/usbuart.c
  4. 26
      src/platforms/tm4c/usbuart.c

1
src/platforms/common/Makefile.inc

@ -27,3 +27,4 @@ SRC += \
usb.c \
usb_serial.c \
usb_dfu_stub.c \
aux_serial.c

73
src/platforms/common/aux_serial.c

@ -0,0 +1,73 @@
/*
* This file is part of the Black Magic Debug project.
*
* Copyright (C) 2022 1BitSquared <info@1bitsquared.com>
* Written by Rachel Mant <git@dragonmux.network>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4)
#include <libopencm3/stm32/usart.h>
#elif defined(LM4F)
#include <libopencm3/lm4f/uart.h>
#else
#error "Unknown processor target"
#endif
#include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/cdc.h>
#include "general.h"
#include "usbuart.h"
#include "usb.h"
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
{
usart_set_baudrate(USBUSART, coding->dwDTERate);
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4)
if (coding->bParityType)
usart_set_databits(USBUSART, (coding->bDataBits + 1 <= 8 ? 8 : 9));
else
usart_set_databits(USBUSART, (coding->bDataBits <= 8 ? 8 : 9));
#elif defined(LM4F)
uart_set_databits(USBUART, coding->bDataBits);
#endif
switch(coding->bCharFormat) {
case 0:
usart_set_stopbits(USBUSART, USART_STOPBITS_1);
break;
case 1:
usart_set_stopbits(USBUSART, USART_STOPBITS_1_5);
break;
case 2:
default:
usart_set_stopbits(USBUSART, USART_STOPBITS_2);
break;
}
switch(coding->bParityType) {
case 0:
usart_set_parity(USBUSART, USART_PARITY_NONE);
break;
case 1:
usart_set_parity(USBUSART, USART_PARITY_ODD);
break;
case 2:
default:
usart_set_parity(USBUSART, USART_PARITY_EVEN);
break;
}
}

36
src/platforms/stm32/usbuart.c

@ -192,42 +192,6 @@ void aux_serial_init(void)
usart_enable_rx_dma(USBUSART);
}
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
{
usart_set_baudrate(USBUSART, coding->dwDTERate);
if (coding->bParityType)
usart_set_databits(USBUSART, (coding->bDataBits + 1 <= 8 ? 8 : 9));
else
usart_set_databits(USBUSART, (coding->bDataBits <= 8 ? 8 : 9));
switch(coding->bCharFormat) {
case 0:
usart_set_stopbits(USBUSART, USART_STOPBITS_1);
break;
case 1:
usart_set_stopbits(USBUSART, USART_STOPBITS_1_5);
break;
case 2:
default:
usart_set_stopbits(USBUSART, USART_STOPBITS_2);
break;
}
switch(coding->bParityType) {
case 0:
usart_set_parity(USBUSART, USART_PARITY_NONE);
break;
case 1:
usart_set_parity(USBUSART, USART_PARITY_ODD);
break;
case 2:
default:
usart_set_parity(USBUSART, USART_PARITY_EVEN);
break;
}
}
/*
* Copy data from fifo into continuous buffer. Return copied length.
*/

26
src/platforms/tm4c/usbuart.c

@ -76,32 +76,6 @@ void aux_serial_init(void)
nvic_enable_irq(USBUART_IRQ);
}
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
{
uart_set_baudrate(USBUART, coding->dwDTERate);
uart_set_databits(USBUART, coding->bDataBits);
switch(coding->bCharFormat) {
case 0:
case 1:
uart_set_stopbits(USBUART, 1);
break;
case 2:
uart_set_stopbits(USBUART, 2);
break;
}
switch(coding->bParityType) {
case 0:
uart_set_parity(USBUART, UART_PARITY_NONE);
break;
case 1:
uart_set_parity(USBUART, UART_PARITY_ODD);
break;
case 2:
uart_set_parity(USBUART, UART_PARITY_EVEN);
break;
}
}
#ifndef ENABLE_RTT
void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
{

Loading…
Cancel
Save