Skip to content

Commit c05459e

Browse files
authored
Merge pull request arduino-libraries#305 from facchinm/uno_r4_wifi
wip: add support for UNO R4 WiFi
2 parents 54d6317 + 742ba78 commit c05459e

File tree

6 files changed

+161
-4
lines changed

6 files changed

+161
-4
lines changed

.github/workflows/compile-examples.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- arduino:megaavr:uno2018:mode=on
1616
- arduino:mbed:nano33ble
1717
- arduino:mbed_nano:nanorp2040connect
18+
- arduino:renesas_uno:unor4wifi
1819

1920
steps:
2021
- uses: actions/checkout@v3

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
[![Compile Examples Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [![Spell Check Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check)
44

5-
Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE.
5+
Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Arduino Portenta H7, Arduino Giga R1 and Arduino UNO R4 WiFi.
66

77
This library supports creating a Bluetooth® Low Energy peripheral & central mode.
88

99
For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later.
1010

11+
For the Arduino UNO R4 WiFi, it requires the ESP32-S3 module to be running [firmware](https://github.com/arduino/uno-r4-wifi-usb-bridge) v0.2.0 or later.
12+
1113

1214
For more information about this library please visit us at:
1315
https://www.arduino.cc/en/Reference/ArduinoBLE

library.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name=ArduinoBLE
22
version=1.3.5
33
author=Arduino
44
maintainer=Arduino <[email protected]>
5-
sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME.
5+
sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi.
66
paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode.
77
category=Communication
88
url=https://www.arduino.cc/en/Reference/ArduinoBLE
9-
architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta
9+
architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta,renesas_uno
1010
includes=ArduinoBLE.h

src/utility/HCIUartTransport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) || defined(TARGET_NANO_RP2040_CONNECT)
20+
#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT)
2121

2222
#include "HCIUartTransport.h"
2323

src/utility/HCIVirtualTransportAT.cpp

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
This file is part of the ArduinoBLE library.
3+
Copyright (c) 2018 Arduino SA. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#if defined(ARDUINO_UNOR4_WIFI)
21+
22+
#include "HCIVirtualTransportAT.h"
23+
24+
extern ModemClass modem;
25+
26+
HCIVirtualTransportATClass::HCIVirtualTransportATClass()
27+
{
28+
}
29+
30+
HCIVirtualTransportATClass::~HCIVirtualTransportATClass()
31+
{
32+
}
33+
34+
static RingBufferN<258> buf;
35+
36+
int HCIVirtualTransportATClass::begin()
37+
{
38+
// TODO: add this helper
39+
//modem.debug(Serial);
40+
buf.clear();
41+
//modem.debug(true);
42+
std::string res = "";
43+
modem.begin();
44+
if (modem.write(std::string(PROMPT(_HCI_BEGIN)), res, CMD(_HCI_BEGIN))) {
45+
return 1;
46+
}
47+
return 0;
48+
}
49+
50+
void HCIVirtualTransportATClass::end()
51+
{
52+
}
53+
54+
void HCIVirtualTransportATClass::wait(unsigned long timeout)
55+
{
56+
std::string res = "";
57+
modem.write(std::string(PROMPT(_HCI_WAIT)), res, "%d\n\r", CMD_WRITE(_HCI_WAIT), timeout);
58+
}
59+
60+
int HCIVirtualTransportATClass::available()
61+
{
62+
std::string res = "";
63+
if (buf.available()) {
64+
return buf.available();
65+
}
66+
if (modem.write(std::string(PROMPT(_HCI_AVAILABLE)), res, CMD_READ(_HCI_AVAILABLE))) {
67+
return atoi(res.c_str());
68+
}
69+
70+
return 0;
71+
}
72+
73+
// never called
74+
int HCIVirtualTransportATClass::peek()
75+
{
76+
return -1;
77+
}
78+
79+
int HCIVirtualTransportATClass::read()
80+
{
81+
uint8_t c;
82+
std::string res = "";
83+
if (buf.available()) {
84+
return buf.read_char();
85+
}
86+
modem.avoid_trim_results();
87+
modem.read_using_size();
88+
if (modem.write(std::string(PROMPT(_HCI_READ)), res, CMD(_HCI_READ))) {
89+
for(int i = 0; i < res.size(); i++) {
90+
buf.store_char((uint8_t)res[i]);
91+
}
92+
return buf.read_char();
93+
}
94+
95+
return -1;
96+
}
97+
98+
size_t HCIVirtualTransportATClass::write(const uint8_t* data, size_t length)
99+
{
100+
std::string res = "";
101+
modem.write_nowait(std::string(PROMPT(_HCI_WRITE)), res, "%s%d\r\n" , CMD_WRITE(_HCI_WRITE), length);
102+
if(modem.passthrough(data, length)) {
103+
return length;
104+
}
105+
return 0;
106+
}
107+
108+
HCIVirtualTransportATClass HCIVirtualTransportAT;
109+
110+
HCITransportInterface& HCITransport = HCIVirtualTransportAT;
111+
112+
#endif

src/utility/HCIVirtualTransportAT.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
This file is part of the ArduinoBLE library.
3+
Copyright (c) 2018 Arduino SA. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include "HCITransport.h"
21+
#include <stdint.h>
22+
#include <stdio.h>
23+
#include <string.h>
24+
25+
#include "WiFiS3.h"
26+
27+
class HCIVirtualTransportATClass : public HCITransportInterface {
28+
public:
29+
HCIVirtualTransportATClass();
30+
virtual ~HCIVirtualTransportATClass();
31+
32+
virtual int begin();
33+
virtual void end();
34+
35+
virtual void wait(unsigned long timeout);
36+
37+
virtual int available();
38+
virtual int peek();
39+
virtual int read();
40+
41+
virtual size_t write(const uint8_t* data, size_t length);
42+
};

0 commit comments

Comments
 (0)