Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial esp-idf 3.0 build #1388

Merged
merged 15 commits into from May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions ChangeLog
@@ -1,4 +1,18 @@
Allow Crypto SHA1 without SHA256/512 (for Original & ESP8266 where flash is scarce)
Add better docs for the form of Wifi callback functions
Modify ESP8266/ESP32 callbacks to match the node.js style used elsewhere
nRF52: fix pin.toggle() on software-negated pins
Pixl.js: Reorder pins so 0..13 are also D0..13 for better Arduino compatibility
Fix dump() when used with code written using E.setBootCode(..), (fix #1398)
Allow parseInt/parseFloat to be used on very large strings if the number doesn't extend right to the end (fix #1397)
nRF5x: Fix memory leak on NRF.connect
Fix memory leak if an exception is thrown within a rejected promise
ESP8266: rewrite wifi.save and restore to use the storage lib (imp #1380)
ESP8266: Add missing option ssid_hidden for Wifi.startAP() (imp #1358)
Fixed double-connect issue for TCP sockets
Pixl.js: Ensure Pixl.menu changes to bitmap fonts
Pixl.js: tweaked bias/contrast to improve display quality
ESP32: update esp-idf to v3.0. BLE support - thanks to @jumjum. Erase flash before flashing. vars now 2500

1v97 : nRF52: fix NRF.on('connect',...) issue
STM32: Fix setDeviceClockCmd error for USB.setConsole()
Expand Down
11 changes: 6 additions & 5 deletions boards/ESP32.py
Expand Up @@ -19,7 +19,7 @@
'espruino_page_link' : 'ESP32',
'default_console' : "EV_SERIAL1",
'default_console_baudrate' : "115200",
'variables' : 5000,
'variables' : 2500,
'binary_name' : 'espruino_%v_esp32.bin',
'build' : {
'optimizeflags' : '-Og',
Expand All @@ -32,7 +32,8 @@
'TELNET',
'NEOPIXEL',
'FILESYSTEM',
'FLASHFS'
'FLASHFS',
'BLUETOOTH'
],
'makefile' : [
'DEFINES+=-DESP_PLATFORM -DESP32=1'
Expand All @@ -53,10 +54,10 @@
'adc' : 2,
'dac' : 0,
'saved_code' : {
'address' : 0x100000,
'address' : 0x2C0000,
'page_size' : 4096,
'pages' : 16,
'flash_available' : 960, # firmware can be up to this size
'pages' : 64,
'flash_available' : 1344, # firmware can be up to this size - see paritions_espruino.csv
},
};
devices = {
Expand Down
6 changes: 4 additions & 2 deletions libs/bluetooth/bluetooth.h
Expand Up @@ -23,7 +23,8 @@
#else
typedef struct {
uint16_t uuid;
uint8_t type;
uint8_t type; //see BLE_UUID_TYPE_... definitions
uint8_t uuid128[16]; //BLE knows 16/32/128 bit uuids. Espruino supports 16/128.
} PACKED_FLAGS ble_uuid_t;
typedef struct {
//uint8_t addr_id_peer;
Expand All @@ -44,10 +45,11 @@ typedef struct {
#define BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA 0xFF
#define BLE_UUID_TYPE_UNKNOWN (0)
#define BLE_UUID_TYPE_BLE (1)
#define BLE_UUID_TYPE_128 2
#define MSEC_TO_UNITS(MS,MEH) MS
#endif

#ifdef NRF52
#if defined(NRF52) || defined(ESP32)
// nRF52 gets the ability to connect to other
#define CENTRAL_LINK_COUNT 1 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings*/
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
Expand Down
23 changes: 19 additions & 4 deletions libs/bluetooth/bluetooth_utils.c
Expand Up @@ -24,7 +24,20 @@

/// Return true if two UUIDs are equal
bool bleUUIDEqual(ble_uuid_t a, ble_uuid_t b) {
return a.type==b.type && a.uuid==b.uuid;
#ifdef NRF5X
return a.type==b.type && a.uuid==b.uuid;
#else
switch(a.type){
case BLE_UUID_TYPE_UNKNOWN:
return a.type == b.type;
case BLE_UUID_TYPE_BLE:
return a.type == b.type && a.uuid == b.uuid;
case BLE_UUID_TYPE_128:
return a.type == b.type && a.uuid128 == b.uuid128;
default:
return false;
}
#endif
}

JsVar *bleUUID128ToStr(const uint8_t *data) {
Expand Down Expand Up @@ -52,8 +65,7 @@ JsVar *bleUUIDToStr(ble_uuid_t uuid) {
assert(dataLen==16); // it should always be 16 as we checked above
return bleUUID128ToStr(&data[0]);
#else
jsiConsolePrintf("FIXME\n");
return 0;
return bleUUID128ToStr(&uuid.uuid128);
#endif
}

Expand Down Expand Up @@ -163,7 +175,10 @@ const char *bleVarToUUID(ble_uuid_t *uuid, JsVar *v) {
}
return err_code ? "BLE device error adding UUID" : 0;
#else
jsiConsolePrintf("FIXME\n");
uuid->uuid = ((data[13]<<8) | data[12]);
for(int i = 0; i < 16; i++){
uuid->uuid128[i] = data[i];
}
return 0;
#endif
}
Expand Down
63 changes: 42 additions & 21 deletions libs/bluetooth/jswrap_bluetooth.c
Expand Up @@ -44,6 +44,12 @@
#endif
#endif

#ifdef ESP32
#include "BLE/esp32_gap_func.h"
#include "BLE/esp32_gatts_func.h"
#include "BLE/esp32_gattc_func.h"
#define BLE_CONN_HANDLE_INVALID -1
#endif

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -288,15 +294,15 @@ Called when a host device disconnects from Espruino.
"type" : "event",
"class" : "NRF",
"name" : "servicesDiscover",
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
Called with discovered services when discovery is finished
*/
/*JSON{
"type" : "event",
"class" : "NRF",
"name" : "characteristicsDiscover",
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
Called with discovered characteristics when discovery is finished
*/
Expand Down Expand Up @@ -644,9 +650,12 @@ void jswrap_nrf_bluetooth_setAdvertising(JsVar *data, JsVar *options) {
err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *)namePtr,
nameLen);
#else
err_code = 0xDEAD;
jsiConsolePrintf("FIXME\n");
//#else
// err_code = 0xDEAD;
// jsiConsolePrintf("FIXME\n");
#endif
#ifdef ESP32
bluetooth_setDeviceName(v);
#endif
jsble_check_error(err_code);
bleChanged = true;
Expand Down Expand Up @@ -731,6 +740,9 @@ void jswrap_nrf_bluetooth_setAdvertising(JsVar *data, JsVar *options) {
#else
err_code = 0xDEAD;
jsiConsolePrintf("FIXME\n");
#endif
#ifdef ESP32
err_code = bluetooth_gap_setAdvertizing(advArray);
#endif
jsvUnLock(initialArray);
jsble_check_error(err_code);
Expand All @@ -754,6 +766,11 @@ the data, it returns the packet that would be advertised as an array.
*/
JsVar *jswrap_nrf_bluetooth_getAdvertisingData(JsVar *data, JsVar *options) {
uint32_t err_code;
#ifdef ESP32
JsVar *r;
r = bluetooth_gap_getAdvertisingData(data,options);
return r;
#endif
#ifdef NRF5X
ble_advdata_t advdata;
jsble_setup_advdata(&advdata);
Expand Down Expand Up @@ -1922,7 +1939,7 @@ void jswrap_nrf_sendHIDReport(JsVar *data, JsVar *callback) {
"type" : "staticmethod",
"class" : "NRF",
"name" : "requestDevice",
"ifdef" : "NRF52",
"#if" : "defined(NRF52) || defined(ESP32)",
"generate" : "jswrap_nrf_bluetooth_requestDevice",
"params" : [
["options","JsVar","Options used to filter the device to use"]
Expand Down Expand Up @@ -2110,7 +2127,7 @@ JsVar *jswrap_nrf_bluetooth_requestDevice(JsVar *options) {
"type" : "staticmethod",
"class" : "NRF",
"name" : "connect",
"ifdef" : "NRF52",
"#if" : "defined(NRF52) || defined(ESP32)",
"generate" : "jswrap_nrf_bluetooth_connect",
"params" : [
["mac","JsVar","The MAC address to connect to"]
Expand Down Expand Up @@ -2213,7 +2230,7 @@ NRF.requestDevice({ filters: [{ name: 'Puck.js abcd' }] }).then(function(device)
"type" : "property",
"class" : "BluetoothDevice",
"name" : "gatt",
"ifdef" : "NRF52",
"#if" : "defined(NRF52) || defined(ESP32)",
"generate" : "jswrap_BluetoothDevice_gatt",
"return" : ["JsVar", "A `BluetoothRemoteGATTServer` for this device" ]
}
Expand All @@ -2238,7 +2255,7 @@ JsVar *jswrap_BluetoothDevice_gatt(JsVar *parent) {
"type" : "method",
"class" : "BluetoothRemoteGATTServer",
"name" : "connect",
"ifdef" : "NRF52",
"#if" : "defined(NRF52) || defined(ESP32)",
"generate" : "jswrap_nrf_BluetoothRemoteGATTServer_connect",
"return" : ["JsVar", "A Promise that is resolved (or rejected) when the connection is complete" ]
}
Expand Down Expand Up @@ -2292,7 +2309,7 @@ JsVar *jswrap_nrf_BluetoothRemoteGATTServer_connect(JsVar *parent) {
/*JSON{
"type" : "class",
"class" : "BluetoothRemoteGATTServer",
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
Web Bluetooth-style GATT server - get this using `NRF.connect(address)`
or `NRF.requestDevice(options)` and `response.gatt.connect`
Expand All @@ -2304,7 +2321,7 @@ or `NRF.requestDevice(options)` and `response.gatt.connect`
"class" : "BluetoothRemoteGATTServer",
"name" : "disconnect",
"generate" : "jswrap_BluetoothRemoteGATTServer_disconnect",
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
Disconnect from a previously connected BLE device connected with
`NRF.connect` - this does not disconnect from something that has
Expand All @@ -2320,7 +2337,12 @@ void jswrap_BluetoothRemoteGATTServer_disconnect(JsVar *parent) {
jsble_check_error(err_code);
} else {
// no connection - try and cancel the connect attempt (assume we have one)
#ifdef NRF52
err_code = sd_ble_gap_connect_cancel();
#endif
#ifdef ESP32
jsWarn("connect cancel not implemented yet\n");
#endif
// maybe we don't, in which case we don't care about the error code
}
#else
Expand Down Expand Up @@ -2420,7 +2442,7 @@ JsVar *jswrap_nrf_BluetoothRemoteGATTServer_getSecurityStatus(JsVar *parent) {
"generate" : "jswrap_BluetoothRemoteGATTServer_getPrimaryService",
"params" : [ ["service","JsVar","The service UUID"] ],
"return" : ["JsVar", "A Promise that is resolved (or rejected) when the primary service is found (the argument contains a `BluetoothRemoteGATTService`)" ],
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
See `NRF.connect` for usage examples.
*/
Expand Down Expand Up @@ -2452,7 +2474,7 @@ JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryService(JsVar *parent, JsVar *
"name" : "getPrimaryServices",
"generate" : "jswrap_BluetoothRemoteGATTServer_getPrimaryServices",
"return" : ["JsVar", "A Promise that is resolved (or rejected) when the primary services are found (the argument contains an array of `BluetoothRemoteGATTService`)" ],
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
*/
JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryServices(JsVar *parent) {
Expand All @@ -2479,7 +2501,7 @@ JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryServices(JsVar *parent) {
"params" : [
["callback","JsVar","The callback to call with the RSSI value, or undefined to stop"]
],
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}

Start/stop listening for RSSI values on the active GATT connection
Expand Down Expand Up @@ -2513,7 +2535,7 @@ void jswrap_BluetoothRemoteGATTServer_setRSSIHandler(JsVar *parent, JsVar *callb
/*JSON{
"type" : "class",
"class" : "BluetoothRemoteGATTService",
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
Web Bluetooth-style GATT service - get this using `BluetoothRemoteGATTServer.getPrimaryService(s)`

Expand All @@ -2526,7 +2548,7 @@ Web Bluetooth-style GATT service - get this using `BluetoothRemoteGATTServer.get
"generate" : "jswrap_BluetoothRemoteGATTService_getCharacteristic",
"params" : [ ["characteristic","JsVar","The characteristic UUID"] ],
"return" : ["JsVar", "A Promise that is resolved (or rejected) when the characteristic is found (the argument contains a `BluetoothRemoteGATTCharacteristic`)" ],
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
See `NRF.connect` for usage examples.
*/
Expand Down Expand Up @@ -2558,7 +2580,7 @@ JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristic(JsVar *parent, JsVar
"name" : "getCharacteristics",
"generate" : "jswrap_BluetoothRemoteGATTService_getCharacteristics",
"return" : ["JsVar", "A Promise that is resolved (or rejected) when the characteristic is found (the argument contains an array of `BluetoothRemoteGATTCharacteristic`)" ],
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
*/
JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristics(JsVar *parent) {
Expand All @@ -2581,7 +2603,7 @@ JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristics(JsVar *parent) {
/*JSON{
"type" : "class",
"class" : "BluetoothRemoteGATTCharacteristic",
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}
Web Bluetooth-style GATT characteristic - get this using `BluetoothRemoteGATTService.getCharacteristic(s)`

Expand Down Expand Up @@ -2639,11 +2661,10 @@ JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_writeValue(JsVar *characteri
"name" : "readValue",
"generate" : "jswrap_nrf_BluetoothRemoteGATTCharacteristic_readValue",
"return" : ["JsVar", "A Promise that is resolved (or rejected) with a `DataView` when the characteristic is read" ],
"ifdef" : "NRF52"
"#if" : "defined(NRF52) || defined(ESP32)"
}

Read a characteristic's value, return a promise containing a `DataView` with the data in it

Read a characteristic's value, return a promise containing a `DataView`

```
var device;
Expand Down
1 change: 1 addition & 0 deletions libs/bluetooth/jswrap_bluetooth.h
Expand Up @@ -33,6 +33,7 @@ typedef enum {
#define BLETASK_IS_CENTRAL(x) ((x)>=BLETASK_CENTRAL_START && ((x)<=BLETASK_CENTRAL_END))

extern JsVar *bleTaskInfo; // info related to the current task

bool bleInTask(BleTask task);
BleTask bleGetCurrentTask();
bool bleNewTask(BleTask task, JsVar *taskInfo);
Expand Down
2 changes: 0 additions & 2 deletions libs/network/network.c
Expand Up @@ -508,7 +508,6 @@ bool ssl_newSocketData(int sckt, JsVar *options) {
* Also see https://tls.mbed.org/kb/how-to/reduce-mbedtls-memory-and-storage-footprint
* */

assert(sckt>=0 && sckt<32);
// Create a new socketData using the variable
JsVar *ssl = jsvObjectGetChild(execInfo.root, "ssl", JSV_OBJECT);
if (!ssl) return false; // out of memory?
Expand Down Expand Up @@ -672,7 +671,6 @@ int netCreateSocket(JsNetwork *net, SocketType socketType, uint32_t host, unsign
if (sckt<0) return sckt;

#ifdef USE_TLS
assert(sckt>=0 && sckt<32);
if (socketType & ST_TLS) {
if (ssl_newSocketData(sckt, options)) {
} else {
Expand Down