Skip to content

Commit 343e9d3

Browse files
authored
Merge pull request #1 from espruino/master
merge from Dordon
2 parents 31c49c9 + bc384d8 commit 343e9d3

31 files changed

+970
-200
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ env:
4949
- BOARD=EFM32GGSTK
5050
- BOARD=NUCLEOL476RG
5151
- BOARD=RUUVITAG DFU_UPDATE_BUILD=1
52+
- BOARD=WIO_LTE DFU_UPDATE_BUILD=1
5253

5354
script: make
5455

ChangeLog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
- Do not garbage collect inside an IRQ
77
On nRF52 devices, allow button press at boot to clear out peer manager data
88
Work out length of typed array with offset correctly (fix #1204)
9+
nRF5x: Add Watchdog timer handling
10+
Allow IRQs during STM32 neopixel send
11+
nRF52: start new connections on idle to ease memory allocation conflicts between code execution & IRQs
12+
nRF52: Ignore INVALID_STATE from CONN_PARAM_UPDATE_REQUEST (it can happen if we disconnect and then SD requests an update)
13+
Fix Date.toString for dates before 1970
14+
STM32: Fix handling of months when setting the internal RTC
15+
Move to a faster jsvNewFlatStringOfLength which avoids blocking memory allocation
16+
nRF5x: If a task is in progress, report the task ID (BleTask enum)
17+
nRF52: Report central mode promise errors correctly if returned by softdevice
18+
Remove 'out of memory' warning messages (it's stored as a flag anyway)
19+
nRF5x: Don't disable IRQs completely for some things - only disable Espruino ones
20+
Fix tab complete for Pins (fix #1213)
21+
ESP8266: Fix load() causes endless loops (fix #1037)
22+
ESP8266: Wifi library doesn't handle {password: null} (fix #753)
23+
ESP8266: make topstrings and topreadonly work on Mac OS X (fix #1210)
24+
Change order of execution for init - E.on('init',...) now executed before onInit
25+
Added Error flag to show if a UART overflow has occurred
926

1027
1v93 : Ensure that specifying too many advertising UUIDs causes an exception, not a reboot
1128
nRF5x: Fix for time jump caused by reentrancy in jshGetSystemTime

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,23 @@ ifdef USE_NFC
601601
endif
602602

603603
ifdef USE_NUCLEO
604-
WRAPPERSOURCES += targets/nucleo/jswrap_nucleo.c
604+
WRAPPERSOURCES += targets/nucleo/jswrap_nucleo.c
605605
endif
606606

607+
ifdef USE_HEXBADGE
608+
INCLUDE += -I$(ROOT)/libs/hexbadge
609+
WRAPPERSOURCES += libs/hexbadge/jswrap_hexbadge.c
610+
endif
611+
612+
ifdef USE_WIO_LTE
613+
INCLUDE += -I$(ROOT)/libs/wio_lte
614+
WRAPPERSOURCES += libs/wio_lte/jswrap_wio_lte.c
615+
SOURCES += targets/stm32/stm32_ws2812b_driver.c
616+
endif
617+
618+
607619
ifdef WICED
608-
WRAPPERSOURCES += targets/emw3165/jswrap_emw3165.c
620+
WRAPPERSOURCES += targets/emw3165/jswrap_emw3165.c
609621
endif
610622

611623
endif # BOOTLOADER ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DON'T USE STUFF ABOVE IN BOOTLOADER

boards/HEXBADGE.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/false
2+
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
3+
#
4+
# Copyright (C) 2013 Gordon Williams <[email protected]>
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
#
10+
# ----------------------------------------------------------------------------------------
11+
# This file contains information for a specific board - the available pins, and where LEDs,
12+
# Buttons, and other in-built peripherals are. It is used to build documentation as well
13+
# as various source and header files for Espruino.
14+
# ----------------------------------------------------------------------------------------
15+
16+
import pinutils;
17+
18+
info = {
19+
'name' : "Hexagonal Espruino Badge",
20+
'link' : [ "" ],
21+
'default_console' : "EV_SERIAL1",
22+
'default_console_tx' : "D7",
23+
'default_console_rx' : "D8",
24+
'default_console_baudrate' : "9600",
25+
# Number of variables can be WAY higher on this board
26+
'variables' : 2000, # How many variables are allocated for Espruino to use. RAM will be overflowed if this number is too high and code won't compile.
27+
'bootloader' : 1,
28+
'binary_name' : 'espruino_%v_hexbadge.bin',
29+
'build' : {
30+
'optimizeflags' : '-Os',
31+
'libraries' : [
32+
'BLUETOOTH',
33+
'NET',
34+
'GRAPHICS',
35+
'NFC',
36+
'NEOPIXEL',
37+
'HEXBADGE'
38+
],
39+
'makefile' : [
40+
'DEFINES+=-DHAL_NFC_ENGINEERING_BC_FTPAN_WORKAROUND=1', # Looks like proper production nRF52s had this issue
41+
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
42+
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C'
43+
]
44+
}
45+
};
46+
47+
48+
chip = {
49+
'part' : "NRF52832",
50+
'family' : "NRF52",
51+
'package' : "QFN48",
52+
'ram' : 64,
53+
'flash' : 512,
54+
'speed' : 64,
55+
'usart' : 1,
56+
'spi' : 3,
57+
'i2c' : 2,
58+
'adc' : 1,
59+
'dac' : 0,
60+
'saved_code' : {
61+
'address' : ((118 - 3) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
62+
'page_size' : 4096,
63+
'pages' : 3,
64+
'flash_available' : 512 - ((31 + 8 + 1 + 3)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 1, code 3. Each page is 4 kb.
65+
},
66+
};
67+
68+
devices = {
69+
'LED1' : { 'pin' : 'D25' },
70+
'LED2' : { 'pin' : 'D26' },
71+
'LED3' : { 'pin' : 'D27' },
72+
'LED4' : { 'pin' : 'D28' },
73+
'LED5' : { 'pin' : 'D29' },
74+
'LED6' : { 'pin' : 'D30' },
75+
'BTN1' : { 'pin' : 'D19', 'pinstate' : 'IN_PULLDOWN' },
76+
'BTN2' : { 'pin' : 'D20', 'pinstate' : 'IN_PULLDOWN' },
77+
'BTN3' : { 'pin' : 'D31', 'pinstate' : 'IN_PULLDOWN' },
78+
'BTN4' : { 'pin' : 'D16', 'pinstate' : 'IN_PULLDOWN' },
79+
'BTN5' : { 'pin' : 'D17', 'pinstate' : 'IN_PULLDOWN' },
80+
'BTN6' : { 'pin' : 'D18', 'pinstate' : 'IN_PULLDOWN' },
81+
# Pin D22 is used for clock when driving neopixels - as not specifying a pin seems to break things
82+
};
83+
84+
# left-right, or top-bottom order
85+
board = {
86+
};
87+
board["_css"] = """
88+
""";
89+
90+
def get_pins():
91+
pins = pinutils.generate_pins(0,31) # 32 General Purpose I/O Pins.
92+
pinutils.findpin(pins, "PD0", True)["functions"]["XL1"]=0;
93+
pinutils.findpin(pins, "PD1", True)["functions"]["XL2"]=0;
94+
pinutils.findpin(pins, "PD5", True)["functions"]["RTS"]=0;
95+
pinutils.findpin(pins, "PD6", True)["functions"]["TXD"]=0;
96+
pinutils.findpin(pins, "PD7", True)["functions"]["CTS"]=0;
97+
pinutils.findpin(pins, "PD8", True)["functions"]["RXD"]=0;
98+
pinutils.findpin(pins, "PD9", True)["functions"]["NFC1"]=0;
99+
pinutils.findpin(pins, "PD10", True)["functions"]["NFC2"]=0;
100+
pinutils.findpin(pins, "PD2", True)["functions"]["ADC1_IN0"]=0;
101+
pinutils.findpin(pins, "PD3", True)["functions"]["ADC1_IN1"]=0;
102+
pinutils.findpin(pins, "PD4", True)["functions"]["ADC1_IN2"]=0;
103+
pinutils.findpin(pins, "PD5", True)["functions"]["ADC1_IN3"]=0;
104+
pinutils.findpin(pins, "PD28", True)["functions"]["ADC1_IN4"]=0;
105+
pinutils.findpin(pins, "PD29", True)["functions"]["ADC1_IN5"]=0;
106+
pinutils.findpin(pins, "PD30", True)["functions"]["ADC1_IN6"]=0;
107+
pinutils.findpin(pins, "PD31", True)["functions"]["ADC1_IN7"]=0;
108+
# everything is non-5v tolerant
109+
for pin in pins:
110+
pin["functions"]["3.3"]=0;
111+
#The boot/reset button will function as a reset button in normal operation. Pin reset on PD21 needs to be enabled on the nRF52832 device for this to work.
112+
return pins

boards/WIO_LTE.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
'NET',
2828
'NEOPIXEL',
2929
'FILESYSTEM', # Add FILESYSTEM will force javascript module to load from SD card, remain to be seen.
30+
'WIO_LTE'
3031
],
3132
'makefile' : [
3233
'DEFINES+=-DUSE_USB_OTG_FS=1',
3334
'DEFINES+=-DWIO_LTE',
35+
'USE_DFU=1',
3436
'STLIB=STM32F405xx',
3537
'PRECOMPILED_OBJS+=$(ROOT)/targetlibs/stm32f4/lib/startup_stm32f40_41xxx.o'
3638
]
@@ -91,7 +93,7 @@
9193
width: 680px;
9294
height: 1020px;
9395
left: 200px;
94-
background-image: url(img/STM32F4DISCOVERY.jpg);
96+
background-image: url(img/WIO_LTE.jpg);
9597
}
9698
#boardcontainer {
9799
height: 1020px;

libs/bluetooth/jswrap_bluetooth.c

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ BleTask bleGetCurrentTask() {
5858

5959
bool bleNewTask(BleTask task, JsVar *taskInfo) {
6060
if (bleTask) {
61-
jsExceptionHere(JSET_ERROR, "BLE task is already in progress");
61+
jsExceptionHere(JSET_ERROR, "BLE task %d is already in progress", (int)bleTask);
6262
return false;
6363
}
6464
assert(!blePromise && !bleTaskInfo);
@@ -390,8 +390,6 @@ This makes Puck.js undiscoverable, so it can't be connected to.
390390
Use `NRF.wake()` to wake up and make Puck.js connectable again.
391391
*/
392392
void jswrap_nrf_bluetooth_sleep() {
393-
uint32_t err_code;
394-
395393
// set as sleeping
396394
bleStatus |= BLE_IS_SLEEPING;
397395
// stop advertising
@@ -1174,16 +1172,33 @@ Start/stop listening for BLE advertising packets within range. Returns a
11741172
packets=10;
11751173
NRF.setScan(function(d) {
11761174
packets--;
1177-
console.log(d); // print packet info
11781175
if (packets<=0)
11791176
NRF.setScan(); // stop scanning
1177+
else
1178+
console.log(d); // print packet info
11801179
});
11811180
```
11821181
1182+
Each `BluetoothDevice` will look a bit like:
1183+
1184+
```
1185+
BluetoothDevice {
1186+
"id": "aa:bb:cc:dd:ee:ff", // address
1187+
"rssi": -89, // signal strength
1188+
"services": [ "128bit-uuid", ... ], // zero or more service UUIDs
1189+
"data": new Uint8Array([ ... ]).buffer, // ArrayBuffer of returned data
1190+
"name": "DeviceName" // the advertised device name
1191+
}
1192+
```
1193+
11831194
**Note:** BLE advertising packets can arrive quickly - faster than you'll
11841195
be able to print them to the console. It's best only to print a few, or
11851196
to use a function like `NRF.findDevices(..)` which will collate a list
11861197
of available devices.
1198+
1199+
**Note:** Using setScan turns the radio's receive mode on constantly. This
1200+
can draw a *lot* of power (12mA or so), so you should use it sparingly or
1201+
you can run your battery down quickly.
11871202
*/
11881203
void jswrap_nrf_bluetooth_setScan_cb(JsVar *callback, JsVar *adv) {
11891204
/* This is called when we get data - do some processing here in the main loop
@@ -1295,6 +1310,9 @@ the device returned, to make a connection.
12951310
12961311
You can also use [`NRF.connect(...)`](/Reference#l_NRF_connect) on just the `id` string returned, which
12971312
may be useful if you always want to connect to a specific device.
1313+
1314+
**Note:** Using findDevices turns the radio's receive mode on for 2000ms (or however long you specify). This
1315+
can draw a *lot* of power (12mA or so), so you should use it sparingly or you can run your battery down quickly.
12981316
*/
12991317
void jswrap_nrf_bluetooth_findDevices_found_cb(JsVar *device) {
13001318
JsVar *arr = jsvObjectGetChild(execInfo.hiddenRoot, "BLEADV", JSV_ARRAY);
@@ -1645,7 +1663,7 @@ NRF.requestDevice({ filters: [{ namePrefix: 'Puck.js' }] }).then(function(device
16451663
}).then(function(service) {
16461664
return service.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
16471665
}).then(function(characteristic) {
1648-
characteristic.writeValue("LED1.set()\n");
1666+
return characteristic.writeValue("LED1.set()\n");
16491667
}).then(function() {
16501668
gatt.disconnect();
16511669
console.log("Done!");
@@ -1821,7 +1839,7 @@ NRF.connect("aa:bb:cc:dd:ee").then(function(g) {
18211839
}).then(function(service) {
18221840
return service.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
18231841
}).then(function(characteristic) {
1824-
characteristic.writeValue("LED1.set()\n");
1842+
return characteristic.writeValue("LED1.set()\n");
18251843
}).then(function() {
18261844
gatt.disconnect();
18271845
console.log("Done!");
@@ -1919,6 +1937,17 @@ See [`NRF.requestDevice`](/Reference#l_NRF_requestDevice) for usage examples.
19191937
19201938
**Note:** This is only available on some devices
19211939
*/
1940+
#if CENTRAL_LINK_COUNT>0
1941+
static void _jswrap_nrf_bluetooth_central_connect(JsVar *addr) {
1942+
// this function gets called on idle - just to make it less
1943+
// likely we get connected while in the middle of executing stuff
1944+
ble_gap_addr_t peer_addr;
1945+
// this should be ok since we checked in jswrap_nrf_BluetoothRemoteGATTServer_connect
1946+
if (!bleVarToAddr(addr, &peer_addr)) return;
1947+
jsble_central_connect(peer_addr);
1948+
}
1949+
#endif
1950+
19221951
JsVar *jswrap_nrf_BluetoothRemoteGATTServer_connect(JsVar *parent) {
19231952
#if CENTRAL_LINK_COUNT>0
19241953

@@ -1931,14 +1960,19 @@ JsVar *jswrap_nrf_BluetoothRemoteGATTServer_connect(JsVar *parent) {
19311960
jsExceptionHere(JSET_TYPEERROR, "Expecting a device with a mac address of the form aa:bb:cc:dd:ee:ff");
19321961
return 0;
19331962
}
1934-
jsvUnLock2(device, addr);
1963+
jsvUnLock(device);
19351964

1965+
JsVar *promise = 0;
19361966
if (bleNewTask(BLETASK_CONNECT, parent/*BluetoothRemoteGATTServer*/)) {
1937-
JsVar *promise = jsvLockAgainSafe(blePromise);
1938-
jsble_central_connect(peer_addr);
1939-
return promise;
1967+
JsVar *fn = jsvNewNativeFunction((void (*)(void))_jswrap_nrf_bluetooth_central_connect, JSWAT_VOID|(JSWAT_JSVAR<<JSWAT_BITS));
1968+
if (fn) {
1969+
jsiQueueEvents(0, fn, &addr, 1);
1970+
jsvUnLock(fn);
1971+
promise = jsvLockAgainSafe(blePromise);
1972+
}
19401973
}
1941-
return 0;
1974+
jsvUnLock(addr);
1975+
return promise;
19421976
#else
19431977
jsExceptionHere(JSET_ERROR, "Unimplemented");
19441978
return 0;

0 commit comments

Comments
 (0)