Skip to content

Commit d9229d3

Browse files
author
Antti Kauppila
committed
Added mbed_lib.json based default constructor
1 parent 229964d commit d9229d3

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
lines changed

ESP8266Interface.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
// Firmware version
2525
#define ESP8266_VERSION 2
2626

27+
ESP8266Interface::ESP8266Interface()
28+
: _esp(MBED_CONF_ESP8266_TX, MBED_CONF_ESP8266_RX, MBED_CONF_ESP8266_DEBUG),
29+
_initialized(false),
30+
_started(false)
31+
{
32+
memset(_ids, 0, sizeof(_ids));
33+
memset(_cbs, 0, sizeof(_cbs));
34+
memset(ap_ssid, 0, sizeof(ap_ssid));
35+
memset(ap_pass, 0, sizeof(ap_pass));
36+
memset(_local_ports, 0, sizeof(_local_ports));
37+
ap_sec = NSAPI_SECURITY_UNKNOWN;
38+
39+
_esp.sigio(this, &ESP8266Interface::event);
40+
_esp.setTimeout();
41+
}
42+
2743
// ESP8266Interface implementation
2844
ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug)
2945
: _esp(tx, rx, debug),
@@ -271,24 +287,24 @@ int ESP8266Interface::socket_open(void **handle, nsapi_protocol_t proto)
271287
{
272288
// Look for an unused socket
273289
int id = -1;
274-
290+
275291
for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) {
276292
if (!_ids[i]) {
277293
id = i;
278294
_ids[i] = true;
279295
break;
280296
}
281297
}
282-
298+
283299
if (id == -1) {
284300
return NSAPI_ERROR_NO_SOCKET;
285301
}
286-
302+
287303
struct esp8266_socket *socket = new struct esp8266_socket;
288304
if (!socket) {
289305
return NSAPI_ERROR_NO_SOCKET;
290306
}
291-
307+
292308
socket->id = id;
293309
socket->proto = proto;
294310
socket->connected = false;
@@ -305,7 +321,7 @@ int ESP8266Interface::socket_close(void *handle)
305321
if (!socket) {
306322
return NSAPI_ERROR_NO_SOCKET;
307323
}
308-
324+
309325
if (socket->connected && !_esp.close(socket->id)) {
310326
err = NSAPI_ERROR_DEVICE_ERROR;
311327
}
@@ -372,7 +388,7 @@ int ESP8266Interface::socket_connect(void *handle, const SocketAddress &addr)
372388
socket->connected = true;
373389
return 0;
374390
}
375-
391+
376392
int ESP8266Interface::socket_accept(void *server, void **socket, SocketAddress *addr)
377393
{
378394
return NSAPI_ERROR_UNSUPPORTED;
@@ -386,7 +402,7 @@ int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size)
386402
if (!socket) {
387403
return NSAPI_ERROR_NO_SOCKET;
388404
}
389-
405+
390406
status = _esp.send(socket->id, data, size);
391407

392408
return status != NSAPI_ERROR_OK ? status : size;
@@ -395,7 +411,7 @@ int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size)
395411
int ESP8266Interface::socket_recv(void *handle, void *data, unsigned size)
396412
{
397413
struct esp8266_socket *socket = (struct esp8266_socket *)handle;
398-
414+
399415
if (!socket) {
400416
return NSAPI_ERROR_NO_SOCKET;
401417
}
@@ -409,7 +425,7 @@ int ESP8266Interface::socket_recv(void *handle, void *data, unsigned size)
409425
} else {
410426
recv = _esp.recv_udp(socket->id, data, size);
411427
}
412-
428+
413429
return recv;
414430
}
415431

@@ -439,7 +455,7 @@ int ESP8266Interface::socket_sendto(void *handle, const SocketAddress &addr, con
439455
}
440456
socket->addr = addr;
441457
}
442-
458+
443459
return socket_send(socket, data, size);
444460
}
445461

ESP8266Interface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
class ESP8266Interface : public NetworkStack, public WiFiInterface
3030
{
3131
public:
32+
/**
33+
* @brief ESP8266Interface default constructor
34+
* Will use values defined in mbed_lib.json
35+
*/
36+
ESP8266Interface();
37+
3238
/** ESP8266Interface lifetime
3339
* @param tx TX pin
3440
* @param rx RX pin

mbed_lib.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "esp8266",
3+
"config": {
4+
"tx": {
5+
"help": "TX pin for serial connection",
6+
"value": "D1"
7+
},
8+
"rx": {
9+
"help": "RX pin for serial connection",
10+
"value": "D0"
11+
},
12+
"debug": {
13+
"help": "Enable debug logs",
14+
"value": false
15+
}
16+
},
17+
"target_overrides": {
18+
"HEXIWEAR": {
19+
"tx": "PTD3",
20+
"rx": "PTD2"
21+
},
22+
"NUCLEO_F401RE": {
23+
"tx": "D8",
24+
"rx": "D2"
25+
},
26+
"NUCLEO_F411RE": {
27+
"tx": "D8",
28+
"rx": "D2"
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)