From 56dc85e6ff62d2ca64ef1ae9c26dacfc52cdcd23 Mon Sep 17 00:00:00 2001 From: thinkberg Date: Sun, 12 Feb 2017 10:26:32 +0100 Subject: [PATCH] picked serial redirection fix from pxt-microbit (issue #961) --- libs/core/serial.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/core/serial.cpp b/libs/core/serial.cpp index 614423fe..daeb813b 100644 --- a/libs/core/serial.cpp +++ b/libs/core/serial.cpp @@ -83,16 +83,19 @@ namespace serial { /** * Dynamically configuring the serial instance to use pins other than USBTX and USBRX. - * @param tx the new transmission pins - * @param rx the new reception pin - * @param baud the new baud rate. eg: 115200 + * @param tx the new transmission pins, eg: SerialPin.P0 + * @param rx the new reception pin, eg: SerialPin.P1 + * @param rate the new baud rate. eg: 115200 */ //% weight=10 //% help=serial/redirect-to //% blockId=serial_redirect block="serial|redirect to|TX %tx|RX %rx|at baud rate %rate" //% blockExternalInputs=1 void redirect(SerialPin tx, SerialPin rx, BaudRate rate) { - uBit.serial.redirect((PinName)tx, (PinName)rx); + MicroBitPin* txp = getPin(tx); if (!tx) return; + MicroBitPin* rxp = getPin(rx); if (!rx) return; + + uBit.serial.redirect(txp->name, rxp->name); uBit.serial.baud((int)rate); } }