From 652d9adba8add2aa33412965dc4169c38ba8caf7 Mon Sep 17 00:00:00 2001 From: jflyper Date: Thu, 31 Aug 2017 03:44:49 +0900 Subject: [PATCH 1/3] Avoid using N-Channel for RX function --- src/main/drivers/serial_softserial.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/drivers/serial_softserial.c b/src/main/drivers/serial_softserial.c index aaf0b2a212..201a3742f4 100644 --- a/src/main/drivers/serial_softserial.c +++ b/src/main/drivers/serial_softserial.c @@ -254,8 +254,8 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb if (options & SERIAL_BIDIR) { // If RX and TX pins are both assigned, we CAN use either with a timer. // However, for consistency with hardware UARTs, we only use TX pin, - // and this pin must have a timer. - if (!timerTx) + // and this pin must have a timer, and it should not be N-Channel. + if (!(timerTx && !(timerTx->output & TIMER_OUTPUT_N_CHANNEL))) return NULL; softSerial->timerHardware = timerTx; @@ -264,8 +264,8 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb IOInit(txIO, OWNER_SERIAL_TX, RESOURCE_INDEX(portIndex + RESOURCE_SOFT_OFFSET)); } else { if (mode & MODE_RX) { - // Need a pin & a timer on RX - if (!(tagRx && timerRx)) + // Need a pin & a timer on RX. Channel should not be N-Channel. + if (!(timerRx && !(timerRx->output & TIMER_OUTPUT_N_CHANNEL))) return NULL; softSerial->rxIO = rxIO; From 5715bda90622e21c2076509f2c125c977e693416 Mon Sep 17 00:00:00 2001 From: jflyper Date: Thu, 31 Aug 2017 14:48:00 +0900 Subject: [PATCH 2/3] Tidy --- src/main/drivers/serial_softserial.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/serial_softserial.c b/src/main/drivers/serial_softserial.c index 201a3742f4..389596ec97 100644 --- a/src/main/drivers/serial_softserial.c +++ b/src/main/drivers/serial_softserial.c @@ -255,8 +255,9 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb // If RX and TX pins are both assigned, we CAN use either with a timer. // However, for consistency with hardware UARTs, we only use TX pin, // and this pin must have a timer, and it should not be N-Channel. - if (!(timerTx && !(timerTx->output & TIMER_OUTPUT_N_CHANNEL))) + if (!(timerTx && !(timerTx->output & TIMER_OUTPUT_N_CHANNEL))) { return NULL; + } softSerial->timerHardware = timerTx; softSerial->txIO = txIO; @@ -265,8 +266,9 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb } else { if (mode & MODE_RX) { // Need a pin & a timer on RX. Channel should not be N-Channel. - if (!(timerRx && !(timerRx->output & TIMER_OUTPUT_N_CHANNEL))) + if (!(timerRx && !(timerRx->output & TIMER_OUTPUT_N_CHANNEL))) { return NULL; + } softSerial->rxIO = rxIO; softSerial->timerHardware = timerRx; From b5ddae4672a61d4ea25296f47396bc7814baf81f Mon Sep 17 00:00:00 2001 From: jflyper Date: Thu, 31 Aug 2017 15:02:21 +0900 Subject: [PATCH 3/3] For readability --- src/main/drivers/serial_softserial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/serial_softserial.c b/src/main/drivers/serial_softserial.c index 389596ec97..6789d70ce1 100644 --- a/src/main/drivers/serial_softserial.c +++ b/src/main/drivers/serial_softserial.c @@ -255,7 +255,7 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb // If RX and TX pins are both assigned, we CAN use either with a timer. // However, for consistency with hardware UARTs, we only use TX pin, // and this pin must have a timer, and it should not be N-Channel. - if (!(timerTx && !(timerTx->output & TIMER_OUTPUT_N_CHANNEL))) { + if (!timerTx || (timerTx->output & TIMER_OUTPUT_N_CHANNEL)) { return NULL; } @@ -266,7 +266,7 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb } else { if (mode & MODE_RX) { // Need a pin & a timer on RX. Channel should not be N-Channel. - if (!(timerRx && !(timerRx->output & TIMER_OUTPUT_N_CHANNEL))) { + if (!timerRx || (timerRx->output & TIMER_OUTPUT_N_CHANNEL)) { return NULL; }