diff --git a/src/drv_softserial.c b/src/drv_softserial.c index 6a137e14d..6fe1e432d 100644 --- a/src/drv_softserial.c +++ b/src/drv_softserial.c @@ -87,6 +87,7 @@ void setupSoftSerial1(uint32_t baud) int portIndex = 0; softSerial_t *softSerial = &(softSerialPorts[portIndex]); + softSerial->port.vTable = softSerialVTable; softSerial->port.mode = MODE_RXTX; softSerial->port.baudRate = baud; @@ -289,19 +290,22 @@ uint8_t serialReadByte(softSerial_t *softSerial) moveHeadToNextByte(softSerial); return b; } -void serialWriteByte(softSerial_t *softSerial, uint8_t ch) -{ - serialPort_t *s = &(softSerial->port); +void serialWriteByte(serialPort_t *s, uint8_t ch) +{ s->txBuffer[s->txBufferHead] = ch; s->txBufferHead = (s->txBufferHead + 1) % s->txBufferSize; } +const struct serialPortVTable softSerialVTable[] = { + { serialWriteByte } +}; + void serialPrint(softSerial_t *softSerial, const char *str) { uint8_t ch; while ((ch = *(str++))) { - serialWriteByte(softSerial, ch); + serialWrite((serialPort_t *)softSerial, ch); } } diff --git a/src/drv_softserial.h b/src/drv_softserial.h index fb7d55bf5..387be7fb0 100644 --- a/src/drv_softserial.h +++ b/src/drv_softserial.h @@ -30,12 +30,15 @@ typedef struct softSerial_s { uint16_t internalTxBuffer; // includes start and stop bits } softSerial_t; + +extern const struct serialPortVTable softSerialVTable[]; + void setupSoftSerial1(uint32_t baud); uint8_t serialReadByte(softSerial_t *softSerial); uint8_t serialAvailable(softSerial_t *softSerial); -void serialWriteByte(softSerial_t *softSerial, uint8_t ch); +void softSerialWriteByte(serialPort_t *instance, uint8_t ch); void serialPrint(softSerial_t *softSerial, const char *str); extern timerHardware_t* serialTimerHardware; diff --git a/src/drv_uart.c b/src/drv_uart.c index 852c7a9c7..2e72baea6 100755 --- a/src/drv_uart.c +++ b/src/drv_uart.c @@ -17,7 +17,7 @@ uartPort_t *serialUSART1(uint32_t baudRate, portMode_t mode) NVIC_InitTypeDef NVIC_InitStructure; s = &uartPort1; - s->port.vTable = UART; + s->port.vTable = uartVTable; s->port.baudRate = baudRate; @@ -62,7 +62,7 @@ uartPort_t *serialUSART2(uint32_t baudRate, portMode_t mode) NVIC_InitTypeDef NVIC_InitStructure; s = &uartPort2; - s->port.vTable = UART; + s->port.vTable = uartVTable; s->port.baudRate = baudRate; @@ -257,7 +257,7 @@ void uartWrite(serialPort_t *instance, uint8_t ch) } } -const struct serialPortVTable UART[] = { +const struct serialPortVTable uartVTable[] = { { uartWrite } }; diff --git a/src/drv_uart.h b/src/drv_uart.h index ef370ed5e..5f43d3d16 100755 --- a/src/drv_uart.h +++ b/src/drv_uart.h @@ -26,7 +26,7 @@ typedef struct { USART_TypeDef *USARTx; } uartPort_t; -extern const struct serialPortVTable UART[]; +extern const struct serialPortVTable uartVTable[]; serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode); void uartChangeBaud(uartPort_t *s, uint32_t baudRate); diff --git a/src/main.c b/src/main.c index b5d77316b..15acdfa03 100755 --- a/src/main.c +++ b/src/main.c @@ -149,7 +149,7 @@ int main(void) while (serialAvailable(&softSerialPorts[0])) { uint8_t b = serialReadByte(&softSerialPorts[0]); - serialWriteByte(&softSerialPorts[0], b); + serialWrite((serialPort_t*)&softSerialPorts[0], b); //uartWrite(core.mainport, b); }; #endif