Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 054337e

Browse files
committed
wip: add support for UNO R4 WiFi
Needs UNOR4USBBridge firmware >= 0.2.0
1 parent 726a6c8 commit 054337e

File tree

3 files changed

+155
-1
lines changed

3 files changed

+155
-1
lines changed

‎src/utility/HCIUartTransport.cpp‎

Lines changed: 1 addition & 1 deletion
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

Lines changed: 112 additions & 0 deletions
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‎

Lines changed: 42 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /