Skip to content

Commit 45d024f

Browse files
committed
Initial support for Uno WiFi rev2
Need to add a patch to Arduino_ConnectionHandler: diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 195ab13..8d80f2e 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -29,7 +29,8 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_AVR_UNO_WIFI_REV2) #include <WiFiNINA.h> #include <WiFiUdp.h>
1 parent aff9ebd commit 45d024f

File tree

10 files changed

+283
-3
lines changed

10 files changed

+283
-3
lines changed

src/AIoTC_Config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
#define HAS_TCP
8080
#endif
8181

82-
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
82+
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \
83+
defined(ARDUINO_AVR_UNO_WIFI_REV2)
8384
#define BOARD_HAS_OFFLOADED_ECCX08
8485
#define HAS_TCP
8586
#undef OTA_ENABLED

src/cbor/CBORDecoder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
/******************************************************************************
2222
INCLUDE
2323
******************************************************************************/
24+
#ifdef __AVR__
25+
#include <Arduino.h>
26+
#include <ArduinoSTL.h>
27+
#endif
2428

2529
#undef max
2630
#undef min

src/cbor/CBOREncoder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
* INCLUDE
2323
******************************************************************************/
2424

25+
#ifdef __AVR__
26+
#include <Arduino.h>
27+
#include <ArduinoSTL.h>
28+
#endif
29+
2530
#include "../property/PropertyContainer.h"
2631

2732
/******************************************************************************

src/cbor/lib/tinycbor/src/cbor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#ifndef CBOR_H
2626
#define CBOR_H
2727

28+
#ifdef __AVR__
29+
#define FP_NAN NAN
30+
#define FP_INFINITE INFINITY
31+
#endif
32+
2833
#ifndef assert
2934
#include <assert.h>
3035
#endif

src/cbor/lib/tinycbor/src/cborpretty.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
# define __STDC_LIMIT_MACROS 1
2929
#endif
3030

31+
#ifndef __AVR__
32+
3133
#include "cbor.h"
3234
#include "cborinternal_p.h"
3335
#include "compilersupport_p.h"
@@ -580,4 +582,6 @@ CborError cbor_value_to_pretty_stream(CborStreamFunction streamFunction, void *t
580582

581583
#pragma GCC diagnostic pop
582584

585+
#endif // __AVR__
586+
583587
/** @} */

src/cbor/lib/tinycbor/src/cbortojson.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
# define __STDC_LIMIT_MACROS 1
3131
#endif
3232

33+
#ifndef __AVR__
34+
3335
#include "cbor.h"
3436
#include "cborjson.h"
3537
#include "cborinternal_p.h"
@@ -701,4 +703,6 @@ CborError cbor_value_to_json_advance(FILE *out, CborValue *value, int flags)
701703

702704
#pragma GCC diagnostic pop
703705

706+
#endif // __AVR__
707+
704708
/** @} */

src/cbor/lib/tinycbor/src/open_memstream.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434

3535
#include <unistd.h>
3636

37+
#ifdef __AVR__
38+
typedef size_t ssize_t;
39+
#endif
40+
3741
typedef ssize_t RetType;
3842
typedef size_t LenType;
3943

src/nonstd/nonstd.h

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
#pragma once
2+
#ifdef __AVR__
3+
#include <Arduino.h>
4+
extern void * operator new(size_t size, void * ptr);
5+
namespace nonstd{
6+
7+
template<class T>struct tag{using type=T;};
8+
template<class Tag>using type_t=typename Tag::type;
9+
10+
using size_t=decltype(sizeof(int));
11+
12+
//move
13+
14+
template<class T>
15+
T&& move(T&t){return static_cast<T&&>(t);}
16+
17+
//forward
18+
19+
template<class T>
20+
struct remove_reference:tag<T>{};
21+
template<class T>
22+
struct remove_reference<T&>:tag<T>{};
23+
template<class T>using remove_reference_t=type_t<remove_reference<T>>;
24+
25+
template<class T>
26+
T&& forward( remove_reference_t<T>& t ) {
27+
return static_cast<T&&>(t);
28+
}
29+
template<class T>
30+
T&& forward( remove_reference_t<T>&& t ) {
31+
return static_cast<T&&>(t);
32+
}
33+
34+
//decay
35+
36+
template<class T>
37+
struct remove_const:tag<T>{};
38+
template<class T>
39+
struct remove_const<T const>:tag<T>{};
40+
41+
template<class T>
42+
struct remove_volatile:tag<T>{};
43+
template<class T>
44+
struct remove_volatile<T volatile>:tag<T>{};
45+
46+
template<class T>
47+
struct remove_cv:remove_const<type_t<remove_volatile<T>>>{};
48+
49+
50+
template<class T>
51+
struct decay3:remove_cv<T>{};
52+
template<class R, class...Args>
53+
struct decay3<R(Args...)>:tag<R(*)(Args...)>{};
54+
template<class T>
55+
struct decay2:decay3<T>{};
56+
template<class T, size_t N>
57+
struct decay2<T[N]>:tag<T*>{};
58+
59+
template<class T>
60+
struct decay:decay2<remove_reference_t<T>>{};
61+
62+
template<class T>
63+
using decay_t=type_t<decay<T>>;
64+
65+
//is_convertible
66+
67+
template<class T>
68+
T declval(); // no implementation
69+
70+
template<class T, T t>
71+
struct integral_constant{
72+
static constexpr T value=t;
73+
constexpr integral_constant() {};
74+
constexpr operator T()const{ return value; }
75+
constexpr T operator()()const{ return value; }
76+
};
77+
template<bool b>
78+
using bool_t=integral_constant<bool, b>;
79+
using true_type=bool_t<true>;
80+
using false_type=bool_t<false>;
81+
82+
template<class...>struct voider:tag<void>{};
83+
template<class...Ts>using void_t=type_t<voider<Ts...>>;
84+
85+
namespace details {
86+
template<template<class...>class Z, class, class...Ts>
87+
struct can_apply:false_type{};
88+
template<template<class...>class Z, class...Ts>
89+
struct can_apply<Z, void_t<Z<Ts...>>, Ts...>:true_type{};
90+
}
91+
template<template<class...>class Z, class...Ts>
92+
using can_apply = details::can_apply<Z, void, Ts...>;
93+
94+
namespace details {
95+
template<class From, class To>
96+
using try_convert = decltype( To{declval<From>()} );
97+
}
98+
template<class From, class To>
99+
struct is_convertible : can_apply< details::try_convert, From, To > {};
100+
template<>
101+
struct is_convertible<void,void>:true_type{};
102+
103+
//enable_if
104+
105+
template<bool, class=void>
106+
struct enable_if {};
107+
template<class T>
108+
struct enable_if<true, T>:tag<T>{};
109+
template<bool b, class T=void>
110+
using enable_if_t=type_t<enable_if<b,T>>;
111+
112+
//res_of
113+
114+
namespace details {
115+
template<class G, class...Args>
116+
using invoke_t = decltype( declval<G>()(declval<Args>()...) );
117+
118+
template<class Sig,class=void>
119+
struct res_of {};
120+
template<class G, class...Args>
121+
struct res_of<G(Args...), void_t<invoke_t<G, Args...>>>:
122+
tag<invoke_t<G, Args...>>
123+
{};
124+
}
125+
template<class Sig>
126+
using res_of = details::res_of<Sig>;
127+
template<class Sig>
128+
using res_of_t=type_t<res_of<Sig>>;
129+
130+
//aligned_storage
131+
132+
template<size_t size, size_t align>
133+
struct alignas(align) aligned_storage_t {
134+
char buff[size];
135+
};
136+
137+
//is_same
138+
139+
template<class A, class B>
140+
struct is_same:false_type{};
141+
template<class A>
142+
struct is_same<A,A>:true_type{};
143+
144+
template<class Sig, size_t sz, size_t algn>
145+
struct small_task;
146+
147+
template<class R, class...Args, size_t sz, size_t algn>
148+
struct small_task<R(Args...), sz, algn>{
149+
struct vtable_t {
150+
void(*mover)(void* src, void* dest);
151+
void(*destroyer)(void*);
152+
R(*invoke)(void const* t, Args&&...args);
153+
template<class T>
154+
static vtable_t const* get() {
155+
static const vtable_t table = {
156+
[](void* src, void*dest) {
157+
new(dest) T(move(*static_cast<T*>(src)));
158+
},
159+
[](void* t){ static_cast<T*>(t)->~T(); },
160+
[](void const* t, Args&&...args)->R {
161+
return (*static_cast<T const*>(t))(forward<Args>(args)...);
162+
}
163+
};
164+
return &table;
165+
}
166+
};
167+
vtable_t const* table = nullptr;
168+
aligned_storage_t<sz, algn> data;
169+
template<class F,
170+
class dF=decay_t<F>,
171+
enable_if_t<!is_same<dF, small_task>{}>* = nullptr,
172+
enable_if_t<is_convertible< res_of_t<dF&(Args...)>, R >{}>* = nullptr
173+
>
174+
small_task( F&& f ):
175+
table( vtable_t::template get<dF>() )
176+
{
177+
static_assert( sizeof(dF) <= sz, "object too large" );
178+
static_assert( alignof(dF) <= algn, "object too aligned" );
179+
new(&data) dF(forward<F>(f));
180+
}
181+
~small_task() {
182+
if (table)
183+
table->destroyer(&data);
184+
}
185+
small_task(const small_task& o):
186+
table(o.table)
187+
{
188+
data = o.data;
189+
}
190+
small_task(small_task&& o):
191+
table(o.table)
192+
{
193+
if (table)
194+
table->mover(&o.data, &data);
195+
}
196+
small_task(){}
197+
small_task& operator=(const small_task& o){
198+
this->~small_task();
199+
new(this) small_task( move(o) );
200+
return *this;
201+
}
202+
small_task& operator=(small_task&& o){
203+
this->~small_task();
204+
new(this) small_task( move(o) );
205+
return *this;
206+
}
207+
explicit operator bool()const{return table;}
208+
R operator()(Args...args)const{
209+
return table->invoke(&data, forward<Args>(args)...);
210+
}
211+
};
212+
213+
template<class R, class...Args, size_t sz, size_t algn>
214+
inline bool operator==(const small_task<R(Args...), sz, algn>& __f, nullptr_t)
215+
{ return !static_cast<bool>(__f); }
216+
217+
/// @overload
218+
template<class R, class...Args, size_t sz, size_t algn>
219+
inline bool operator==(nullptr_t, const small_task<R(Args...), sz, algn>& __f)
220+
{ return !static_cast<bool>(__f); }
221+
222+
template<class R, class...Args, size_t sz, size_t algn>
223+
inline bool operator!=(const small_task<R(Args...), sz, algn>& __f, nullptr_t)
224+
{ return static_cast<bool>(__f); }
225+
226+
/// @overload
227+
template<class R, class...Args, size_t sz, size_t algn>
228+
inline bool operator!=(nullptr_t, const small_task<R(Args...), sz, algn>& __f)
229+
{ return static_cast<bool>(__f); }
230+
231+
template<class Sig>
232+
using function = small_task<Sig, sizeof(void*)*4, alignof(void*) >;
233+
}
234+
235+
#endif

src/property/Property.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ CborError Property::appendAttributeReal(String value, String attributeName, Cbor
189189
}, encoder);
190190
}
191191

192-
CborError Property::appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder) {
192+
#ifdef __AVR__
193+
CborError Property::appendAttributeName(String attributeName, nonstd::function<CborError (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder)
194+
#else
195+
CborError Property::appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder)
196+
#endif
197+
{
193198
if (attributeName != "") {
194199
// when the attribute name string is not empty, the attribute identifier is incremented in order to be encoded in the message if the _lightPayload flag is set
195200
_attributeIdentifier++;
@@ -271,7 +276,11 @@ void Property::setAttributeReal(String& value, String attributeName) {
271276
});
272277
}
273278

279+
#ifdef __AVR__
280+
void Property::setAttributeReal(String attributeName, nonstd::function<void (CborMapData & md)>setValue)
281+
#else
274282
void Property::setAttributeReal(String attributeName, std::function<void (CborMapData & md)>setValue)
283+
#endif
275284
{
276285
if (attributeName != "") {
277286
_attributeIdentifier++;

src/property/Property.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ typedef void(*OnSyncCallbackFunc)(Property &);
133133
CLASS DECLARATION
134134
******************************************************************************/
135135

136+
#ifdef __AVR__
137+
#include "nonstd/nonstd.h"
138+
#endif
139+
136140
class Property
137141
{
138142
public:
@@ -177,13 +181,18 @@ class Property
177181
CborError appendAttributeReal(int value, String attributeName = "", CborEncoder *encoder = nullptr);
178182
CborError appendAttributeReal(float value, String attributeName = "", CborEncoder *encoder = nullptr);
179183
CborError appendAttributeReal(String value, String attributeName = "", CborEncoder *encoder = nullptr);
184+
#ifndef __AVR__
180185
CborError appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>f, CborEncoder *encoder);
186+
void setAttributeReal(String attributeName, std::function<void (CborMapData & md)>setValue);
187+
#else
188+
CborError appendAttributeName(String attributeName, nonstd::function<CborError (CborEncoder& mapEncoder)>f, CborEncoder *encoder);
189+
void setAttributeReal(String attributeName, nonstd::function<void (CborMapData & md)>setValue);
190+
#endif
181191
void setAttributesFromCloud(std::list<CborMapData> * map_data_list);
182192
void setAttributeReal(bool& value, String attributeName = "");
183193
void setAttributeReal(int& value, String attributeName = "");
184194
void setAttributeReal(float& value, String attributeName = "");
185195
void setAttributeReal(String& value, String attributeName = "");
186-
void setAttributeReal(String attributeName, std::function<void (CborMapData & md)>setValue);
187196
String getAttributeName(String propertyName, char separator);
188197

189198
virtual bool isDifferentFromCloud() = 0;

0 commit comments

Comments
 (0)