Merge branch 'master' into ESP32

This commit is contained in:
wilberforce 2017-04-26 15:13:34 +12:00
commit 897524388e
16 changed files with 151 additions and 37 deletions

View File

@ -1,3 +1,5 @@
1v93 : Ensure that specifying too many advertising UUIDs causes an exception, not a reboot
1v92 : nRF5x: Fix issue where Espruino could crash during save() if the flash got into a strange state
Added Pin.toggle() function
Fix implicit casting to bool/number on ArrayBuffers (fix #1030)

View File

@ -20,7 +20,7 @@ info = {
'default_console' : "EV_SERIAL1",
'default_console_baudrate' : "115200",
'variables' : 1600,
'binary_name' : 'espruino_%v_esp8266',
'binary_name' : 'espruino_%v_esp8266_4mb',
'build' : {
'libraries' : [
'NET',

View File

@ -78,9 +78,13 @@ espruino_#v##_microbit.hex
- Espruino for the BBC micro:bit - just copy this file onto the
flash drive that appears when you plug the micro:bit in.
espruino_#v##_ruuvitag.zip
- The firmware image for Ruuvitag Devices
See http://www.espruino.com/Ruuvitag for more information
ESP8266
-------
ESP8266 / ESP32
---------------
See http://www.espruino.com/EspruinoESP8266 for more info
@ -88,9 +92,20 @@ espruino_#v##_esp8266_combined_512.bin
- ESP8266 'combined' port for 512k devices like ESP01
Flash with: esptool.py write_flash 0 espruino_#v##_esp8266_combined_512.bin
espruino_#v##_esp8266_4mb_combined_4096.bin
- ESP8266 'combined' port for 4MB devices like ESP12
Flash with: esptool.py write_flash 0 espruino_#v##_esp8266_combined_4096.bin
espruino_#v##_esp8266
- ESP8266 port as separate files - see README in directory for more information
espruino_#v##_esp8266_4mb
- ESP8266 port for 4mb devices as separate files - see README in directory for more information
espruino_#v##_esp32.zip
- The firmware image for ESP32 Devices
See http://www.espruino.com/ESP32 for more information

View File

@ -539,17 +539,16 @@ void jswrap_nrf_bluetooth_setAdvertising(JsVar *data, JsVar *options) {
// raw data...
// Check if it's nested arrays - if so we alternate between advertising types
bleStatus &= ~(BLE_IS_ADVERTISING_MULTIPLE|BLE_ADVERTISING_MULTIPLE_MASK);
JsVar *item = 0;
if (jsvIsArray(data)) {
JsVar *item = jsvGetArrayItem(data, 0);
item = jsvGetArrayItem(data, 0);
if (jsvIsArray(item) || jsvIsArrayBuffer(item)) {
// nested - enable multiple advertising - start at index 0
bleStatus |= BLE_IS_ADVERTISING_MULTIPLE;
// start with the first element
jsvUnLock(data);
data = item;
item = 0;
} else
jsvUnLock(item);
}
}
JSV_GET_AS_CHAR_ARRAY(dPtr, dLen, data);
@ -564,7 +563,8 @@ void jswrap_nrf_bluetooth_setAdvertising(JsVar *data, JsVar *options) {
jsble_check_error(err_code);
if (bleChanged && isAdvertising)
jsble_advertising_start();
return; // we're done here now
jsvUnLock(item);
return; // we're done here now - don't mess with advertising any more
} else if (jsvIsObject(data)) {
ble_advdata_service_data_t *service_data = (ble_advdata_service_data_t*)alloca(jsvGetChildren(data)*sizeof(ble_advdata_service_data_t));
int n = 0;
@ -738,6 +738,15 @@ NRF.setServices({
}, { advertise: [ '180D' ] });
```
You may specify 128 bit UUIDs to advertise, however you may get a `DATA_SIZE`
exception because there is insufficient space in the Bluetooth LE advertising
packet for the 128 bit UART UUID as well as the UUID you specified. In this
case you can add `uart:false` after the `advertise` element to disable the
UART, however you then be unable to connect to Puck.js's console via Bluetooth.
If you absolutely require two or more 128 bit UUIDs then you will have to
specify your own raw advertising data packets with `NRF.setAdvertising`
*/
void jswrap_nrf_bluetooth_setServices(JsVar *data, JsVar *options) {
if (!(jsvIsObject(data) || jsvIsUndefined(data))) {
@ -1810,6 +1819,46 @@ JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryServices(JsVar *parent) {
#endif
}
/*JSON{
"type" : "method",
"class" : "BluetoothRemoteGATTServer",
"name" : "setRSSIHandler",
"generate" : "jswrap_BluetoothRemoteGATTServer_setRSSIHandler",
"params" : [
["callback","JsVar","The callback to call with the RSSI value, or undefined to stop"]
],
"ifdef" : "NRF52"
}
Start/stop listening for RSSI values on the active GATT connection
```
// Start listening for RSSI value updates
gattServer.setRSSIHandler(function(rssi) {
console.log(rssi); // prints -85 (or similar)
});
// Stop listening
gattServer.setRSSIHandler();
```
RSSI is the 'Received Signal Strength Indication' in dBm
**Note:** This is only available on some devices
*/
void jswrap_BluetoothRemoteGATTServer_setRSSIHandler(JsVar *parent, JsVar *callback) {
#if CENTRAL_LINK_COUNT>0
// set the callback event variable
if (!jsvIsFunction(callback)) callback=0;
jsvObjectSetChild(parent, BLE_RSSI_EVENT, callback);
// either start or stop scanning
uint32_t err_code = jsble_set_central_rssi_scan(callback != 0);
jsble_check_error(err_code);
#else
jsExceptionHere(JSET_ERROR, "Unimplemented");
return 0;
#endif
}
/*JSON{
"type" : "class",
"class" : "BluetoothRemoteGATTService",

View File

@ -84,6 +84,7 @@ JsVar *jswrap_nrf_BluetoothRemoteGATTServer_connect(JsVar *parent);
void jswrap_BluetoothRemoteGATTServer_disconnect(JsVar *parent);
JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryService(JsVar *parent, JsVar *service);
JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryServices(JsVar *parent);
void jswrap_BluetoothRemoteGATTServer_setRSSIHandler(JsVar *parent, JsVar *callback);
JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristic(JsVar *parent, JsVar *characteristic);
JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristics(JsVar *parent);
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_writeValue(JsVar *characteristic, JsVar *data);

View File

@ -593,14 +593,11 @@ Before first use the media needs to be formatted.
```
fs=require("fs");
if ( typeof(fs.readdirSync())==="undefined" ) {
console.log("Formatting FS");
E.flashFatFS({format:true});
}
fs.writeFileSync("bang.txt", "This is the way the world ends\nnot with a bang but a whimper.\n");
fs.readdirSync();
```

View File

@ -61,11 +61,12 @@ attached to the given pin.
```
// set just one pixel, red, green, blue
require("neopixel").write(B15, [255,0,0]);
```
```
// Produce an animated rainbow over 25 LEDs
var rgb = new Uint8ClampedArray(25*3);
var pos = 0;
function getPattern() {
pos++;
for (var i=0;i<rgb.length;) {
@ -75,7 +76,6 @@ function getPattern() {
}
return rgb;
}
setInterval(function() {
require("neopixel").write(B15, getPattern());
}, 100);

View File

@ -1565,7 +1565,7 @@ void jswrap_ESP32_wifi_setHostname(
/*JSON{
"type" : "staticmethod",
"class" : "ESP8266",
"class" : "ESP32",
"name" : "ping",
"generate" : "jswrap_ESP32_ping",
"params" : [

View File

@ -37,8 +37,7 @@ export PATH=$PATH:$DIR/xtensa-esp32-elf/bin/
echo ------------------------------------------------------
echo Building Version $VERSION
echo ------------------------------------------------------
for BOARDNAME in PICO_1V3_CC3000 PICO_1V3_WIZ ESPRUINO_1V3 ESPRUINO_1V3_WIZ ESPRUINOWIFI PUCKJS NUCLEOF401RE NUCLEOF411RE STM32VLDISCOVERY STM32F3DISCOVERY STM32F4DISCOVERY OLIMEXINO_STM32 HYSTM32_24 HYSTM32_28 HYSTM32_32 RASPBERRYPI MICROBIT ESP8266_BOARD RUUVITAG ESP32
for BOARDNAME in PICO_1V3_CC3000 PICO_1V3_WIZ ESPRUINO_1V3 ESPRUINO_1V3_WIZ ESPRUINOWIFI PUCKJS NUCLEOF401RE NUCLEOF411RE STM32VLDISCOVERY STM32F3DISCOVERY STM32F4DISCOVERY OLIMEXINO_STM32 HYSTM32_24 HYSTM32_28 HYSTM32_32 RASPBERRYPI MICROBIT ESP8266_BOARD ESP8266_4MB RUUVITAG ESP32
do
echo ------------------------------
echo $BOARDNAME
@ -98,9 +97,14 @@ do
# copy...
if [ "$BOARDNAME" == "ESP8266_BOARD" ]; then
tar -C $ZIPDIR -xzf ${ESP_BINARY_NAME}.tgz || { echo "Build of $BOARDNAME failed" ; exit 1; }
# Do some more ESP8266 build stuff
# build a combined image
bash -c "$EXTRADEFS RELEASE=1 BOARD=$BOARDNAME make combined" || { echo "Build of $BOARDNAME failed" ; exit 1; }
cp ${ESP_BINARY_NAME}_combined_512.bin $ZIPDIR || { echo "Build of $BOARDNAME failed" ; exit 1; }
elif [ "$BOARDNAME" == "ESP8266_4MB" ]; then
tar -C $ZIPDIR -xzf ${ESP_BINARY_NAME}.tgz || { echo "Build of $BOARDNAME failed" ; exit 1; }
# build a combined image
bash -c "$EXTRADEFS RELEASE=1 BOARD=$BOARDNAME make combined" || { echo "Build of $BOARDNAME failed" ; exit 1; }
cp ${ESP_BINARY_NAME}_combined_4096.bin $ZIPDIR || { echo "Build of $BOARDNAME failed" ; exit 1; }
else
echo Copying ${ESP_BINARY_NAME} to $ZIPDIR/$NEW_BINARY_NAME
cp ${ESP_BINARY_NAME} $ZIPDIR/$NEW_BINARY_NAME || { echo "Build of $BOARDNAME failed" ; exit 1; }

View File

@ -821,11 +821,12 @@ JsVar *jslNewFromLexer(JslCharPos *charFrom, size_t charTo) {
block->varData.str[blockChars++] = ch;
jsvStringIteratorNext(&it);
}
jsvStringIteratorFree(&it);
jsvSetCharactersInVar(block, blockChars);
jsvUnLock(block);
// Just make sure we only assert if there's a bug here. If we just ran out of memory it's ok
assert((l == jsvGetStringLength(var)) || (jsErrorFlags&JSERR_MEMORY));
// Just make sure we only assert if there's a bug here. If we just ran out of memory or at end of string it's ok
assert((l == jsvGetStringLength(var)) || (jsErrorFlags&JSERR_MEMORY) || !jsvStringIteratorHasChar(&it));
jsvStringIteratorFree(&it);
return var;
}

View File

@ -2512,6 +2512,7 @@ JsVarInt jsvGetLength(const JsVar *src) {
/** Count the amount of JsVars used. Mostly useful for debugging */
static size_t _jsvCountJsVarsUsedRecursive(JsVar *v, bool resetRecursionFlag) {
if (!v) return 0;
// Use IS_RECURSING flag to stop recursion
if (resetRecursionFlag) {
if (!(v->flags & JSV_IS_RECURSING))

View File

@ -93,7 +93,7 @@ CalendarDate getCalendarDate(int d) {
//Find the month
m=0;
while (mdays[m]<d+1) {
while (mdays[m]<d+1 && m<12) {
m++;
}
date.month=m-1;
@ -122,7 +122,7 @@ int fromCalenderDate(CalendarDate *date) {
if (yf>=2)
ydays=ydays+1;
return f*FDAY+YDAYS[yf]+mdays[date->month]+date->day-1;
return f*FDAY+YDAYS[yf]+mdays[date->month%12]+date->day-1;
};
@ -204,14 +204,14 @@ JsVar *jswrap_date_constructor(JsVar *args) {
} else {
CalendarDate date;
date.year = (int)jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 0));
date.month = (int)jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 1));
date.day = (int)jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 2));
date.month = (int)(jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 1)) % 12);
date.day = (int)(jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 2)) % 31);
TimeInDay td;
td.daysSinceEpoch = fromCalenderDate(&date);
td.hour = (int)jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 3));
td.min = (int)jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 4));
td.sec = (int)jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 5));
td.ms = (int)jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 6));
td.hour = (int)(jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 3)) % 24);
td.min = (int)(jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 4)) % 60);
td.sec = (int)(jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 5)) % 60);
td.ms = (int)(jsvGetIntegerAndUnLock(jsvGetArrayItem(args, 6)) % 1000);
td.zone = 0;
time = fromTimeInDay(&td);
}

View File

@ -482,10 +482,14 @@ for example:
```
// shift out to single clk+data
shiftOut(A0, { clk : A1 }, [1,0,1,0]);
```
```
// shift out a whole byte (like software SPI)
shiftOut(A0, { clk : A1, repeat: 8 }, [1,2,3,4]);
```
```
// shift out via 4 data pins
shiftOut([A3,A2,A1,A0], { clk : A4 }, [1,2,3,4]);
```

View File

@ -308,7 +308,10 @@ JsVar *jswrap_ESP8266_crc32(JsVar *jsData) {
["pin", "pin", "Pin for output signal."],
["arrayOfData", "JsVar", "Array of LED data."]
]
}*/
}
**This function is deprecated.** Please use `require("neopixel").write(pin, data)` instead
*/
void jswrap_ESP8266_neopixelWrite(Pin pin, JsVar *jsArrayOfData) {
jswrap_neopixel_write(pin, jsArrayOfData);
}

View File

@ -391,12 +391,29 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
break;
case BLE_GAP_EVT_RSSI_CHANGED: {
JsVar *evt = jsvNewFromInteger(p_ble_evt->evt.gap_evt.params.rssi_changed.rssi);
if (evt) jsiQueueObjectCallbacks(execInfo.root, BLE_RSSI_EVENT, &evt, 1);
jsvUnLock(evt);
jshHadEvent();
} break;
case BLE_GAP_EVT_RSSI_CHANGED:
#if CENTRAL_LINK_COUNT>0
if (m_central_conn_handle == p_ble_evt->evt.gap_evt.conn_handle) {
JsVar *gattServer = bleGetActiveBluetoothGattServer();
if (gattServer) {
JsVar *rssi = jsvNewFromInteger(p_ble_evt->evt.gap_evt.params.rssi_changed.rssi);
JsVar *bluetoothDevice = jsvObjectGetChild(gattServer, "device", 0);
if (bluetoothDevice) {
jsvObjectSetChild(bluetoothDevice, "rssi", rssi);
}
jsiQueueObjectCallbacks(gattServer, BLE_RSSI_EVENT, &rssi, 1);
jshHadEvent();
jsvUnLock3(rssi, gattServer, bluetoothDevice);
}
} else
#endif
{
JsVar *evt = jsvNewFromInteger(p_ble_evt->evt.gap_evt.params.rssi_changed.rssi);
if (evt) jsiQueueObjectCallbacks(execInfo.root, BLE_RSSI_EVENT, &evt, 1);
jsvUnLock(evt);
jshHadEvent();
}
break;
#if PEER_MANAGER_ENABLED==0
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:{
@ -1177,7 +1194,7 @@ static void peer_manager_init(bool erase_bonds) {
if (FLASH_MAGIC == *magicWord) {
int i;
for (i=1;i<=FDS_PHY_PAGES;i++)
jshFlashErasePage(FS_PAGE_END_ADDR - i*FS_PAGE_SIZE);
jshFlashErasePage(((uint32_t)FS_PAGE_END_ADDR) - i*FS_PAGE_SIZE);
}
@ -1469,7 +1486,7 @@ static void advertising_init() {
options.ble_adv_fast_timeout = APP_ADV_TIMEOUT_IN_SECONDS;
err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
APP_ERROR_CHECK(err_code);
jsble_check_error(err_code);
}
// -----------------------------------------------------------------------------------
@ -1631,6 +1648,23 @@ uint32_t jsble_set_rssi_scan(bool enabled) {
return err_code;
}
uint32_t jsble_set_central_rssi_scan(bool enabled) {
uint32_t err_code = 0;
if (enabled) {
if (jsble_has_central_connection())
err_code = sd_ble_gap_rssi_start(m_central_conn_handle, 0, 0);
} else {
if (jsble_has_central_connection())
err_code = sd_ble_gap_rssi_stop(m_central_conn_handle);
}
if (err_code == NRF_ERROR_INVALID_STATE) {
// We either tried to start when already started, or stop when
// already stopped, so we can simply ignore this condition.
err_code = 0;
}
return err_code;
}
/** Actually set the services defined in the 'data' object. Note: we can
* only do this *once* - so to change it we must reset the softdevice and
* then call this again */

View File

@ -98,6 +98,9 @@ uint32_t jsble_set_scanning(bool enabled);
/// returning RSSI values for current connection
uint32_t jsble_set_rssi_scan(bool enabled);
/// RSSI monitoring in central mode
uint32_t jsble_set_central_rssi_scan(bool enabled);
/** Actually set the services defined in the 'data' object. Note: we can
* only do this *once* - so to change it we must reset the softdevice and
* then call this again */