Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO-L072CZ-LRWAN1_LoRa_PingPong
Fork of SX1276GenericLib by
Revision 75:7330dd86cdea, committed 2017-07-26
- Comitter:
- Helmut Tschemernjak
- Date:
- Wed Jul 26 15:18:35 2017 +0200
- Parent:
- 74:66223d437a25
- Child:
- 76:79f8ca9c8025
- Commit message:
- Added a default Serial configuration which allows to switch
between Serial and SerialUSB via a single simple define.
Changed in this revision
--- a/Arduino-mbed-APIs/arduino-mbed.cpp Sun Jul 23 18:04:39 2017 +0200
+++ b/Arduino-mbed-APIs/arduino-mbed.cpp Wed Jul 26 15:18:35 2017 +0200
@@ -9,7 +9,12 @@
using namespace std;
#include "arduino-mbed.h"
+#include "arduino-util.h"
+Stream *ser;
+void InitSerial(Stream *serial) {
+ ser = serial;
+}
static void pinInt00(void);
static void pinInt01(void);
@@ -343,7 +348,7 @@
*/
if (t->INTFLAG.bit.OVF == 1) { // A overflow caused the interrupt
t->INTFLAG.bit.OVF = 1; // writing a one clears the flag ovf flag
- // Serial.println("T_OVF");
+ // ser->println("T_OVF");
/*
* reading the count once is needed, otherwise
@@ -358,7 +363,7 @@
}
if (t->INTFLAG.bit.MC0 == 1) { // A compare to cc0 caused the interrupt
t->INTFLAG.bit.MC0 = 1; // writing a one clears the MCO (match capture) flag
- // Serial.println("T_MC0");
+ // ser->println("T_MC0");
}
}
@@ -500,9 +505,9 @@
t->CTRLA.reg |= TCC_CTRLA_ENABLE ; // Enable TC
while (t->SYNCBUSY.bit.ENABLE == 1); // wait for sync
#if 0
- Serial.print(ms_getTicker(), DEC);
- Serial.print(" startTimer: nCounts=");
- Serial.println(nCounts, DEC);
+ ser->print(ms_getTicker(), DEC);
+ ser->print(" startTimer: nCounts=");
+ ser->println(nCounts, DEC);
#endif
}
@@ -527,7 +532,7 @@
}
if (t->INTFLAG.bit.MC0 == 1) { // A compare to cc0 caused the interrupt
- //Serial.print("MC0\r\n");
+ //ser->print("MC0\r\n");
t->INTFLAG.bit.MC0 = 1; // writing a one clears the MCO (match capture) flag
}
@@ -622,6 +627,21 @@
void sleep(void)
{
+ /*
+ * If we use the native USB port our Serial is SerialUSB
+ * and if the SerialUSB and connected we should
+ * not enter into sleep mode because this kills the Arduino USB emulation
+ */
+#if 0
+ if (ser && ser == (Stream *)&SerialUSB) {
+ if (1) {
+ __WFI();
+ return;
+ }
+ USB->CTRLA.bit.ENABLE = 0;
+ }
+#endif
+
#if 1 // (SAMD20 || SAMD21)
/* Errata: Make sure that the Flash does not power all the way down
* when in sleep mode. */
--- a/Arduino-mbed-APIs/arduino-mbed.h Sun Jul 23 18:04:39 2017 +0200
+++ b/Arduino-mbed-APIs/arduino-mbed.h Wed Jul 26 15:18:35 2017 +0200
@@ -28,6 +28,9 @@
#define MYdigitalPinToInterrupt(x) (x)
#endif
+void InitSerial(Stream *serial);
+extern Stream *ser;
+
enum PinMode {
PullUp = 1,
Binary file Arduino-mbed-APIs/arduino-util.cpp has changed
--- a/Arduino-mbed-APIs/arduino-util.h Sun Jul 23 18:04:39 2017 +0200 +++ b/Arduino-mbed-APIs/arduino-util.h Wed Jul 26 15:18:35 2017 +0200 @@ -1,13 +1,14 @@ -#ifdef ARDUINO -#ifndef __ARDUINO_UTIL_H__ -#define __ARDUINO_UTIL_H__ - /* * The file is Licensed under the Apache License, Version 2.0 * (c) 2017 Helmut Tschemernjak * 30826 Garbsen (Hannover) Germany */ +#ifdef ARDUINO +#ifndef __ARDUINO_UTIL_H__ +#define __ARDUINO_UTIL_H__ + + extern void dprintf(const char *format, ...); extern void dump(const char *title, const void *data, int len);
--- a/Arduino-mbed-APIs/examples/TimerTest/TimerTest.ino Sun Jul 23 18:04:39 2017 +0200
+++ b/Arduino-mbed-APIs/examples/TimerTest/TimerTest.ino Wed Jul 26 15:18:35 2017 +0200
@@ -8,8 +8,10 @@
void SwitchInput(void);
#define SW0 3 // switch needs pullup
+#define LED LED_BUILTIN
+#define MYSERIAL Serial
-DigitalOut led(LED_BUILTIN);
+DigitalOut led(LED);
InterruptIn intr(SW0);
Timeout tp;
Timeout tp2;
@@ -17,9 +19,10 @@
Timeout tp4;
void setup() {
- Serial.begin(230400);
+ MYSERIAL.begin(230400);
+ InitSerial(&MYSERIAL);
- Serial.println("TimerTest");
+ ser->println("TimerTest");
tp.attach(callback(&TestTimeoutFunc), 1000);
tp2.attach(callback(&TestTimeoutFunc55), 5500);
@@ -41,21 +44,21 @@
void TestTimeoutFunc(void) {
tp.attach(callback(&TestTimeoutFunc), 1000);
led = !led;
- Serial.print(ms_getTicker(), DEC);
- Serial.println(" TestTimeoutFunc 1 sec");
+ ser->print(ms_getTicker(), DEC);
+ ser->println(" TestTimeoutFunc 1 sec");
}
void TestTimeoutFunc55(void) {
tp2.attach(callback(&TestTimeoutFunc55), 5500);
- Serial.print(ms_getTicker(), DEC);
- Serial.println(" TestTimeoutFunc 5.5 sec");
+ ser->print(ms_getTicker(), DEC);
+ ser->println(" TestTimeoutFunc 5.5 sec");
}
void TestTimeoutFunc10(void) {
tp3.attach(callback(&TestTimeoutFunc10), 10000);
- Serial.print(ms_getTicker(), DEC);
- Serial.println(" TestTimeoutFunc 10 sec");
+ ser->print(ms_getTicker(), DEC);
+ ser->println(" TestTimeoutFunc 10 sec");
}
@@ -64,7 +67,7 @@
}
void SwitchInput(void) {
- Serial.print(ms_getTicker(), DEC);
- Serial.println(" SwitchInput");
+ ser->print(ms_getTicker(), DEC);
+ ser->println(" SwitchInput");
led = !led;
}
--- a/Arduino-mbed-APIs/library.properties Sun Jul 23 18:04:39 2017 +0200 +++ b/Arduino-mbed-APIs/library.properties Wed Jul 26 15:18:35 2017 +0200 @@ -4,6 +4,6 @@ maintainer=Helmut Tschemernjak <helmut2009@me.com> sentence=Arduino-mbed-APIs to support mbed like APIs including Timer, Timeout, SPI, InterruptIn, DigialIn, DigitalOut, DigitalInOut, sleep, deepsleep, it also includes a SAMD TCC based Timer implementation for correct timestamps and timeouts. paragraph= -category=Kernel +category=Other url=http://https://TODO architectures=samd
