serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallbackPtr callback, uint32_t baud, portOptions_t options) { softSerial_t *softSerial = &(softSerialPorts[portIndex]); #ifdef USE_SOFTSERIAL1 if (portIndex == SOFTSERIAL1) { softSerial->rxTimerHardware = &(timerHardware[SOFTSERIAL_1_TIMER_RX_HARDWARE]); softSerial->txTimerHardware = &(timerHardware[SOFTSERIAL_1_TIMER_TX_HARDWARE]); } #endif #ifdef USE_SOFTSERIAL2 if (portIndex == SOFTSERIAL2) { softSerial->rxTimerHardware = &(timerHardware[SOFTSERIAL_2_TIMER_RX_HARDWARE]); softSerial->txTimerHardware = &(timerHardware[SOFTSERIAL_2_TIMER_TX_HARDWARE]); } #endif softSerial->port.vTable = softSerialVTable; softSerial->port.baudRate = baud; softSerial->port.mode = MODE_RXTX; softSerial->port.options = options; softSerial->port.callback = callback; resetBuffers(softSerial); softSerial->isTransmittingData = false; softSerial->isSearchingForStartBit = true; softSerial->rxBitIndex = 0; softSerial->transmissionErrors = 0; softSerial->receiveErrors = 0; softSerial->softSerialPortIndex = portIndex; softSerial->txIO = IOGetByTag(softSerial->txTimerHardware->tag); serialOutputPortConfig(softSerial->txTimerHardware->tag, portIndex); softSerial->rxIO = IOGetByTag(softSerial->rxTimerHardware->tag); serialInputPortConfig(softSerial->rxTimerHardware->tag, portIndex); setTxSignal(softSerial, ENABLE); delay(50); serialTimerTxConfig(softSerial->txTimerHardware, portIndex, baud); serialTimerRxConfig(softSerial->rxTimerHardware, portIndex, options); return &softSerial->port; }
serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallbackPtr callback, uint32_t baud, serialInversion_e inversion) { softSerial_t *softSerial = &(softSerialPorts[portIndex]); if (portIndex == SOFTSERIAL1) { softSerial->rxTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_RX_HARDWARE]); softSerial->txTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_TX_HARDWARE]); } if (portIndex == SOFTSERIAL2) { softSerial->rxTimerHardware = &(timerHardware[SOFT_SERIAL_2_TIMER_RX_HARDWARE]); softSerial->txTimerHardware = &(timerHardware[SOFT_SERIAL_2_TIMER_TX_HARDWARE]); } softSerial->port.vTable = softSerialVTable; softSerial->port.baudRate = baud; softSerial->port.mode = MODE_RXTX; softSerial->port.inversion = inversion; softSerial->port.callback = callback; resetBuffers(softSerial); softSerial->isTransmittingData = false; softSerial->isSearchingForStartBit = true; softSerial->rxBitIndex = 0; softSerial->transmissionErrors = 0; softSerial->receiveErrors = 0; softSerial->softSerialPortIndex = portIndex; serialOutputPortConfig(softSerial->txTimerHardware); serialInputPortConfig(softSerial->rxTimerHardware); setTxSignal(softSerial, ENABLE); delay(50); serialTimerTxConfig(softSerial->txTimerHardware, portIndex, baud); serialTimerRxConfig(softSerial->rxTimerHardware, portIndex, inversion); return &softSerial->port; }
serialPort_t *openEscSerial(escSerialPortIndex_e portIndex, serialReceiveCallbackPtr callback, uint16_t output, uint32_t baud, portOptions_t options, uint8_t mode) { escSerial_t *escSerial = &(escSerialPorts[portIndex]); escSerial->rxTimerHardware = &(timerHardware[output]); escSerial->txTimerHardware = &(timerHardware[ESCSERIAL_TIMER_TX_HARDWARE]); escSerial->port.vTable = escSerialVTable; escSerial->port.baudRate = baud; escSerial->port.mode = MODE_RXTX; escSerial->port.options = options; escSerial->port.callback = callback; resetBuffers(escSerial); escSerial->isTransmittingData = false; escSerial->isSearchingForStartBit = true; escSerial->rxBitIndex = 0; escSerial->transmissionErrors = 0; escSerial->receiveErrors = 0; escSerial->receiveTimeout = 0; escSerial->escSerialPortIndex = portIndex; serialInputPortConfig(escSerial->rxTimerHardware); setTxSignal(escSerial, ENABLE); delay(50); if(mode==0){ serialTimerTxConfig(escSerial->txTimerHardware, portIndex); serialTimerRxConfig(escSerial->rxTimerHardware, portIndex); } if(mode==1){ serialTimerTxConfigBL(escSerial->txTimerHardware, portIndex, baud); serialTimerRxConfigBL(escSerial->rxTimerHardware, portIndex, options); } return &escSerial->port; }
void setupSoftSerial1(uint32_t baud, uint8_t inverted) { int portIndex = 0; softSerial_t *softSerial = &(softSerialPorts[portIndex]); softSerial->port.vTable = softSerialVTable; softSerial->port.mode = MODE_RXTX; softSerial->port.baudRate = baud; softSerial->isInverted = inverted; //softSerial->rxTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_RX_HARDWARE]); //softSerial->txTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_TX_HARDWARE]); softSerial->port.rxBufferSize = SOFT_SERIAL_BUFFER_SIZE; softSerial->port.rxBuffer = softSerial->rxBuffer; softSerial->port.rxBufferTail = 0; softSerial->port.rxBufferHead = 0; softSerial->port.txBuffer = softSerial->txBuffer; softSerial->port.txBufferSize = SOFT_SERIAL_BUFFER_SIZE, softSerial->port.txBufferTail = 0; softSerial->port.txBufferHead = 0; softSerial->isTransmittingData = false; softSerial->isSearchingForStartBit = true; softSerial->isSearchingForStopBit = false; softSerial->timerRxCounter = 1; serialInputPortConfig(softSerial->rxTimerHardware); serialOutputPortConfig(softSerial->txTimerHardware); setTxSignal(softSerial, 1); delay(50); serialTimerConfig(softSerial->rxTimerHardware, baud, portIndex, onSerialTimer); }