diff --git a/docs/reference/serial.md b/docs/reference/serial.md index b1570e98..f93f1d52 100644 --- a/docs/reference/serial.md +++ b/docs/reference/serial.md @@ -17,6 +17,7 @@ serial.onDataReceived(",", () => {}) ```cards serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200); +serial.redirectToUSB(); serial.writeBuffer(pins.createBuffer(0)); serial.readBuffer(64); ``` @@ -26,4 +27,5 @@ serial.readBuffer(64); [writeLine](/reference/serial/write-line), [writeNumber](/reference/serial/write-number), [writeValue](/reference/serial/write-value), [writeString](/reference/serial/write-string), [readUntil](/reference/serial/read-until), [readLine](/reference/serial/read-line), [readString](/reference/serial/read-string), [onDataReceived](/reference/serial/on-data-received), -[redirect](/reference/serial/redirect-to), [writeBuffer](/reference/serial/write-buffer), [readBuffer](/reference/serial/read-buffer) +[redirect](/reference/serial/redirect-to), [writeBuffer](/reference/serial/write-buffer), [readBuffer](/reference/serial/read-buffer), +[redirectToUSB](/reference/serial/redirect-to-usb) diff --git a/docs/reference/serial/redirect-to-usb.md b/docs/reference/serial/redirect-to-usb.md new file mode 100644 index 00000000..0659f5b3 --- /dev/null +++ b/docs/reference/serial/redirect-to-usb.md @@ -0,0 +1,12 @@ +# Serial Redirect To USB + +Dynamically configure the serial instance to use ``USBTX`` and ``USBRX``. + +```sig +serial.redirectToUSB() +``` + +## See also + +[serial](/device/serial), +[redirect](/reference/serial/redirect-to) diff --git a/docs/reference/serial/redirect-to.md b/docs/reference/serial/redirect-to.md index ba4988b6..04d3c42e 100644 --- a/docs/reference/serial/redirect-to.md +++ b/docs/reference/serial/redirect-to.md @@ -27,5 +27,6 @@ input.onButtonPressed(Button.A, () => { ## See also -[serial](/device/serial) +[serial](/device/serial), +[redirectToUSB](/reference/serial/redirect-to-usb) diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index e4ec2d55..1dc551e6 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -419,6 +419,7 @@ "serial.readUntil": "Reads a line of text from the serial port and returns the buffer when the delimiter is met.", "serial.readUntil|param|delimiter": "text delimiter that separates each text chunk", "serial.redirect": "Dynamically configuring the serial instance to use pins other than USBTX and USBRX.", + "serial.redirectToUSB": "Redirects the serial instance to USBTX and USBRX.", "serial.redirect|param|rate": "the new baud rate. eg: 115200", "serial.redirect|param|rx": "the new reception pin, eg: SerialPin.P1", "serial.redirect|param|tx": "the new transmission pins, eg: SerialPin.P0", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 252a1b59..8c24f7dc 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -339,6 +339,7 @@ "serial.readLine|block": "serial|read line", "serial.readString|block": "serial|read string", "serial.readUntil|block": "serial|read until %delimiter=serial_delimiter_conv", + "serial.redirectToUSB|block": "serial|redirect to USB", "serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate", "serial.writeBuffer|block": "serial|write buffer %buffer", "serial.writeLine|block": "serial|write line %text", diff --git a/libs/core/serial.cpp b/libs/core/serial.cpp index ff8f3b80..7363a1ac 100644 --- a/libs/core/serial.cpp +++ b/libs/core/serial.cpp @@ -152,6 +152,7 @@ namespace serial { //% tx.fieldOptions.tooltips="false" //% rx.fieldEditor="gridpicker" rx.fieldOptions.columns=3 //% rx.fieldOptions.tooltips="false" + //% blockGap=8 void redirect(SerialPin tx, SerialPin rx, BaudRate rate) { MicroBitPin* txp = getPin(tx); if (!tx) return; MicroBitPin* rxp = getPin(rx); if (!rx) return; @@ -159,4 +160,14 @@ namespace serial { uBit.serial.redirect(txp->name, rxp->name); uBit.serial.baud((int)rate); } + + /** + * Redirects the serial instance to USBTX and USBRX. + */ + //% weight=9 help=serial/redirect-to-usb + //% blockId=serial_redirect_to_usb block="serial|redirect to USB" + void redirectToUSB() { + uBit.serial.redirect(USBTX, USBRX); + uBit.serial.baud(115200); + } } diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 7a92b5c7..4dff6d28 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -831,8 +831,16 @@ declare namespace serial { //% tx.fieldEditor="gridpicker" tx.fieldOptions.columns=3 //% tx.fieldOptions.tooltips="false" //% rx.fieldEditor="gridpicker" rx.fieldOptions.columns=3 - //% rx.fieldOptions.tooltips="false" shim=serial::redirect + //% rx.fieldOptions.tooltips="false" + //% blockGap=8 shim=serial::redirect function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void; + + /** + * Redirects the serial instance to USBTX and USBRX. + */ + //% weight=9 help=serial/redirect-to-usb + //% blockId=serial_redirect_to_usb block="serial|redirect to USB" shim=serial::redirectToUSB + function redirectToUSB(): void; } diff --git a/package.json b/package.json index b8098daa..59ec0d9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.13.55", + "version": "0.14.0", "description": "micro:bit target for Microsoft MakeCode (PXT)", "keywords": [ "JavaScript", diff --git a/sim/state/serial.ts b/sim/state/serial.ts index 3d957341..de7cdf6b 100644 --- a/sim/state/serial.ts +++ b/sim/state/serial.ts @@ -49,4 +49,8 @@ namespace pxsim.serial { export function redirect(tx: number, rx: number, rate: number) { // TODO? } + + export function redirectToUSB() { + // TODO + } } \ No newline at end of file