Replacing calls to serialWriteByte(softSerial_t*, char) with calls to serialWrite(serialPort_t*, char). This completes the proof of concept for polymorphic serial port implementations (uartPort and softSerialPort).
This commit is contained in:
parent
6425877b2c
commit
97f54561f0
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 }
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue