Skip to content

Commit 32148e3

Browse files
author
Seppo Takalo
authored
Merge pull request #75 from ARMmbed/mbed_lib_added
Added mbed_lib.json based default constructor
2 parents 229964d + 1a06292 commit 32148e3

File tree

3 files changed

+79
-10
lines changed

3 files changed

+79
-10
lines changed

ESP8266Interface.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,41 @@
2121
#include "nsapi_types.h"
2222

2323

24+
#ifndef MBED_CONF_ESP8266_TX
25+
#ifdef TARGET_FF_ARDUINO
26+
#define MBED_CONF_ESP8266_TX D1
27+
#else
28+
#define MBED_CONF_ESP8266_TX NC
29+
#endif
30+
#endif
31+
32+
#ifndef MBED_CONF_ESP8266_RX
33+
#ifdef TARGET_FF_ARDUINO
34+
#define MBED_CONF_ESP8266_RX D0
35+
#else
36+
#define MBED_CONF_ESP8266_RX NC
37+
#endif
38+
#endif
39+
2440
// Firmware version
2541
#define ESP8266_VERSION 2
2642

43+
ESP8266Interface::ESP8266Interface()
44+
: _esp(MBED_CONF_ESP8266_TX, MBED_CONF_ESP8266_RX, MBED_CONF_ESP8266_DEBUG),
45+
_initialized(false),
46+
_started(false)
47+
{
48+
memset(_ids, 0, sizeof(_ids));
49+
memset(_cbs, 0, sizeof(_cbs));
50+
memset(ap_ssid, 0, sizeof(ap_ssid));
51+
memset(ap_pass, 0, sizeof(ap_pass));
52+
memset(_local_ports, 0, sizeof(_local_ports));
53+
ap_sec = NSAPI_SECURITY_UNKNOWN;
54+
55+
_esp.sigio(this, &ESP8266Interface::event);
56+
_esp.setTimeout();
57+
}
58+
2759
// ESP8266Interface implementation
2860
ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug)
2961
: _esp(tx, rx, debug),
@@ -271,24 +303,24 @@ int ESP8266Interface::socket_open(void **handle, nsapi_protocol_t proto)
271303
{
272304
// Look for an unused socket
273305
int id = -1;
274-
306+
275307
for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) {
276308
if (!_ids[i]) {
277309
id = i;
278310
_ids[i] = true;
279311
break;
280312
}
281313
}
282-
314+
283315
if (id == -1) {
284316
return NSAPI_ERROR_NO_SOCKET;
285317
}
286-
318+
287319
struct esp8266_socket *socket = new struct esp8266_socket;
288320
if (!socket) {
289321
return NSAPI_ERROR_NO_SOCKET;
290322
}
291-
323+
292324
socket->id = id;
293325
socket->proto = proto;
294326
socket->connected = false;
@@ -305,7 +337,7 @@ int ESP8266Interface::socket_close(void *handle)
305337
if (!socket) {
306338
return NSAPI_ERROR_NO_SOCKET;
307339
}
308-
340+
309341
if (socket->connected && !_esp.close(socket->id)) {
310342
err = NSAPI_ERROR_DEVICE_ERROR;
311343
}
@@ -372,7 +404,7 @@ int ESP8266Interface::socket_connect(void *handle, const SocketAddress &addr)
372404
socket->connected = true;
373405
return 0;
374406
}
375-
407+
376408
int ESP8266Interface::socket_accept(void *server, void **socket, SocketAddress *addr)
377409
{
378410
return NSAPI_ERROR_UNSUPPORTED;
@@ -386,7 +418,7 @@ int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size)
386418
if (!socket) {
387419
return NSAPI_ERROR_NO_SOCKET;
388420
}
389-
421+
390422
status = _esp.send(socket->id, data, size);
391423

392424
return status != NSAPI_ERROR_OK ? status : size;
@@ -395,7 +427,7 @@ int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size)
395427
int ESP8266Interface::socket_recv(void *handle, void *data, unsigned size)
396428
{
397429
struct esp8266_socket *socket = (struct esp8266_socket *)handle;
398-
430+
399431
if (!socket) {
400432
return NSAPI_ERROR_NO_SOCKET;
401433
}
@@ -409,7 +441,7 @@ int ESP8266Interface::socket_recv(void *handle, void *data, unsigned size)
409441
} else {
410442
recv = _esp.recv_udp(socket->id, data, size);
411443
}
412-
444+
413445
return recv;
414446
}
415447

@@ -439,7 +471,7 @@ int ESP8266Interface::socket_sendto(void *handle, const SocketAddress &addr, con
439471
}
440472
socket->addr = addr;
441473
}
442-
474+
443475
return socket_send(socket, data, size);
444476
}
445477

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": null
7+
},
8+
"rx": {
9+
"help": "RX pin for serial connection",
10+
"value": null
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)