Skip to content

Commit

Permalink
Merge branch 'ESP32-v3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed May 14, 2018
2 parents 225c08f + 5223d4e commit 11ac45f
Show file tree
Hide file tree
Showing 23 changed files with 1,994 additions and 93 deletions.
5 changes: 3 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
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
ESP8266: rearange rf_cal_sector (fix #1294)
ESP8266: Wifi.scan() now return authmode as text
ESP32: update esp-idf to v3.0. BLE support - thanks to @jumjum. Erase flash before flashing. vars now 2500
ESP8266: rearange rf_cal_sector (fix #1294)
ESP8266: Wifi.scan() now return authmode as text

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -300,15 +306,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 @@ -648,9 +654,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 @@ -735,6 +744,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 @@ -758,6 +770,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 @@ -1928,7 +1945,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 @@ -2116,7 +2133,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 @@ -2228,7 +2245,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 @@ -2253,7 +2270,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 @@ -2307,7 +2324,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 @@ -2319,7 +2336,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 @@ -2335,7 +2352,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 @@ -2435,7 +2457,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 @@ -2467,7 +2489,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 @@ -2494,7 +2516,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 @@ -2528,7 +2550,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 @@ -2541,7 +2563,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 @@ -2573,7 +2595,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 @@ -2596,7 +2618,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 @@ -2654,11 +2676,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
Original file line number Diff line number Diff line change
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

0 comments on commit 11ac45f

Please sign in to comment.