|
| 1 | +/* |
| 2 | + WiFi1010FirmwareUpdater - Firmware Updater for the |
| 3 | + Arduino MKR WiFi101, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. |
| 4 | + |
| 5 | + Copyright (C) 2018 Arduino AG (http://www.arduino.cc/) |
| 6 | +
|
| 7 | + This library is free software; you can redistribute it and/or |
| 8 | + modify it under the terms of the GNU Lesser General Public |
| 9 | + License as published by the Free Software Foundation; either |
| 10 | + version 2.1 of the License, or (at your option) any later version. |
| 11 | +
|
| 12 | + This library is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + Lesser General Public License for more details. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU Lesser General Public |
| 18 | + License along with this library; if not, write to the Free Software |
| 19 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | +*/ |
| 21 | + |
| 22 | +unsigned long baud = 115200; |
| 23 | + |
| 24 | +void setup() { |
| 25 | + SerialUSB.begin(baud); |
| 26 | + SerialNina.begin(baud); |
| 27 | + |
| 28 | + pinMode(NINA_GPIO0, OUTPUT); |
| 29 | + pinMode(NINA_RESETN, OUTPUT); |
| 30 | +} |
| 31 | + |
| 32 | +void loop() { |
| 33 | + digitalWrite(NINA_RESETN, SerialUSB.rts()); |
| 34 | + digitalWrite(NINA_GPIO0, (SerialUSB.dtr() == 0) ? HIGH : LOW); |
| 35 | + |
| 36 | + while (SerialUSB.available()) { |
| 37 | + uint8_t c = SerialUSB.read(); |
| 38 | + SerialNina.write(c); |
| 39 | + } |
| 40 | + |
| 41 | + while (SerialNina.available()) { |
| 42 | + uint8_t c = SerialNina.read(); |
| 43 | + SerialUSB.write(c); |
| 44 | + } |
| 45 | + |
| 46 | + // check if the USB virtual serial wants a new baud rate |
| 47 | + if (SerialUSB.baud() != baud) { |
| 48 | + baud = SerialUSB.baud(); |
| 49 | + SerialNina.begin(baud); |
| 50 | + } |
| 51 | +} |
0 commit comments