From 879615dcc1fec1d7e6f725ce3116c87c8b0b4987 Mon Sep 17 00:00:00 2001 From: "Matthias L. Jugel" Date: Thu, 17 Aug 2017 18:25:55 +0200 Subject: [PATCH] add function to reset the UART back to USB --- README.md | 6 ++++++ libs/core/_locales/core-jsdoc-strings.json | 1 + libs/core/_locales/core-strings.json | 1 + libs/core/serial.cpp | 12 ++++++++++++ libs/core/shims.d.ts | 9 +++++++++ pxtarget.json | 5 ++++- 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de290ad2..fdbde24c 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ This target allow to program a [Calliope](http://calliope.cc/) using PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt)). +### BUILD COMMENTS + +- build libs/core/dal.d.ts new requires some meddling, as the `#define` parser does not parse `#ifdef` and thus +has some conflicts with double defines constants + + [![Build Status](https://travis-ci.org/Microsoft/pxt-calliope.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-calliope) ![](http://calliope.cc/content/1-ueber-mini/mini_board.png) diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 7bbd1f39..bec480c9 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -253,6 +253,7 @@ "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", + "serial.reset": "Reset the serial instance to use the USBTX and USBRX at the default baud rate.", "serial.writeLine": "Prints a line of text to the serial", "serial.writeNumber": "Prints a numeric value to the serial", "serial.writeString": "Sends a piece of text through Serial connection.", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 87793130..e350853c 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -233,6 +233,7 @@ "serial.readString|block": "serial|read string", "serial.readUntil|block": "serial|read until %delimiter=serial_delimiter_conv", "serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate", + "serial.reset|block": "serial pin reset", "serial.writeLine|block": "serial|write line %text", "serial.writeNumber|block": "serial|write number %value", "serial.writeString|block": "serial|write string %text", diff --git a/libs/core/serial.cpp b/libs/core/serial.cpp index 512f3912..1c0897bc 100644 --- a/libs/core/serial.cpp +++ b/libs/core/serial.cpp @@ -100,4 +100,16 @@ namespace serial { uBit.serial.redirect(txp->name, rxp->name); uBit.serial.baud((int)rate); } + + /** + * Reset the serial instance to use the USBTX and USBRX at the default baud rate. + */ + //% weight=10 + //% help=serial/reset + //% blockId=serial_reset block="serial pin reset" + //% blockExternalInputs=1 + void reset() { + uBit.serial.redirect(USBTX, USBRX); + uBit.serial.baud(MICROBIT_SERIAL_DEFAULT_BAUD_RATE); + } } diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 0ba88887..7cd61794 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -760,6 +760,15 @@ declare namespace serial { //% blockId=serial_redirect block="serial|redirect to|TX %tx|RX %rx|at baud rate %rate" //% blockExternalInputs=1 shim=serial::redirect function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void; + + /** + * Reset the serial instance to use the USBTX and USBRX at the default baud rate. + */ + //% weight=10 + //% help=serial/reset + //% blockId=serial_reset block="serial pin reset" + //% blockExternalInputs=1 shim=serial::reset + function reset(): void; } diff --git a/pxtarget.json b/pxtarget.json index dd51cbe0..27918552 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -9,7 +9,10 @@ "libs/core", "libs/radio", "libs/devices", - "libs/bluetooth" + "libs/bluetooth", + "libs/pxt-calliope-bc95", + "libs/pxt-calliope-bunt", + "libs/pxt-isl29125" ], "cloud": { "workspace": false,