Skip to content

Commit fa8d921

Browse files
committed
Introduce new web examples
1 parent 55f5403 commit fa8d921

File tree

4 files changed

+121
-4
lines changed

4 files changed

+121
-4
lines changed

examples/daplink-serial/web.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!--
2+
DAPjs
3+
Copyright Arm Limited 2018
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18+
SOFTWARE.
19+
-->
20+
21+
<!DOCTYPE html>
22+
<html>
23+
<body>
24+
<button id="connect">Connect</button>
25+
<div id="results" style="white-space: pre;" />
26+
27+
<script type="text/javascript" src="../../dist/dap.umd.js"></script>
28+
<script>
29+
30+
// Listen to serial output from the device
31+
const listen = async (device, resultsEl) => {
32+
const transport = new DAPjs.WebUSB(device);
33+
const target = new DAPjs.DAPLink(transport);
34+
35+
target.on(DAPjs.DAPLink.EVENT_SERIAL_DATA, data => {
36+
resultsEl.innerHTML += `${data}`;
37+
});
38+
39+
await target.connect();
40+
const baud = await target.getSerialBaudrate();
41+
target.startSerialRead();
42+
resultsEl.innerHTML = `Listening at ${baud} baud...\n`;
43+
};
44+
45+
document.getElementById("connect").onclick = async () => {
46+
const resultsEl = document.getElementById("results");
47+
const device = await navigator.usb.requestDevice({
48+
filters: [{vendorId: 0xD28}]
49+
});
50+
51+
listen(device, resultsEl);
52+
};
53+
</script>
54+
</body>
55+
</html>

examples/read-registers/common.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ function readRegisters(transport) {
5555
registers.forEach((register, index) => {
5656
console.log(`R${index}: ${("00000000" + register.toString(16)).slice(-8)}`);
5757
});
58-
return processor.reconnect();
59-
})
60-
.then(() => {
6158
return processor.resume();
6259
})
6360
.then(() => {

examples/read-registers/web.html

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<!--
2+
DAPjs
3+
Copyright Arm Limited 2018
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18+
SOFTWARE.
19+
-->
20+
21+
<!DOCTYPE html>
22+
<html>
23+
<body>
24+
<button id="read">Read Registers</button>
25+
26+
<script type="text/javascript" src="../../dist/dap.umd.js"></script>
27+
<script>
28+
const count = 16;
29+
30+
const readRegisters = async (device, count) => {
31+
const transport = new DAPjs.WebUSB(device);
32+
const processor = new DAPjs.CortexM(transport);
33+
34+
await processor.connect();
35+
await processor.halt();
36+
37+
const registers = Array.from({ length: count }, (_, index) => index);
38+
const values = await processor.readCoreRegisters(registers);
39+
40+
await processor.resume();
41+
await processor.disconnect();
42+
43+
const result = values.map(register => ("00000000" + register.toString(16)).slice(-8));
44+
return result;
45+
};
46+
47+
document.getElementById("read").onclick = async () => {
48+
const device = await navigator.usb.requestDevice({
49+
filters: [{vendorId: 0xD28}]
50+
});
51+
const values = await readRegisters(device, count);
52+
values.forEach((value, index) => {
53+
const registerEl = document.getElementById(`r${index}`);
54+
registerEl.innerHTML = `Register ${index}: ${value}`;
55+
});
56+
};
57+
58+
for (let index = 0; index < count; index++) {
59+
const registerEl = document.createElement("div");
60+
registerEl.id = `r${index}`;
61+
registerEl.innerHTML = `Register ${index}: None`;
62+
document.body.appendChild(registerEl);
63+
}
64+
</script>
65+
</body>
66+
</html>

examples/typescript/registers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export class Registers {
4545
const registers = Array.from({ length: count }, (_, index) => index);
4646
const values = await processor.readCoreRegisters(registers);
4747

48-
await processor.reconnect();
4948
await processor.resume();
5049
await processor.disconnect();
5150

0 commit comments

Comments
 (0)