Add UART alternative pin setting methods

This commit is contained in:
Daniel Fekete 2017-04-17 11:06:24 +02:00
parent d77814ca9a
commit 73ef9cbf12
2 changed files with 18 additions and 1 deletions

View File

@ -94,7 +94,7 @@ void SerialUART::begin(const uint32_t baud) {
}
#endif
stm32_af_uart_init(instance, NULL, 0, NULL, 0);
stm32_af_uart_init(instance, rxPort, rxPin, txPort, txPin);
handle->Init.BaudRate = baud;
handle->Init.WordLength = UART_WORDLENGTH_8B;
@ -141,6 +141,16 @@ size_t SerialUART::write(const uint8_t c) {
return 1;
}
void SerialUART::stm32_set_rx(uint8_t rx) {
rxPort = port_pin_list[rx].port;
rxPin = port_pin_list[rx].pin_mask;
}
void SerialUART::stm32_set_tx(uint8_t tx) {
txPort = port_pin_list[tx].port;
txPin = port_pin_list[tx].pin_mask;
}
//// Interrupt
SerialUART *interruptUART;

View File

@ -19,6 +19,9 @@ class SerialUART : public Stream {
size_t write(const uint8_t c);
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool() { return true; }; // UART always active
void stm32_set_rx(uint8_t rx);
void stm32_set_tx(uint8_t tx);
USART_TypeDef *instance = NULL;
UART_HandleTypeDef *handle = NULL;
@ -33,6 +36,10 @@ class SerialUART : public Stream {
volatile uint8_t rxStart = 0;
volatile uint8_t rxEnd = 0;
GPIO_TypeDef *rxPort = NULL;
uint32_t rxPin = 0;
GPIO_TypeDef *txPort = NULL;
uint32_t txPin = 0;
};
#ifdef USART1