-
Notifications
You must be signed in to change notification settings - Fork 0
/
firmware_tool.html
158 lines (132 loc) · 4.72 KB
/
firmware_tool.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Little Red Rover</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.min.css">
<style>
body {
overflow: hidden;
}
#terminal {
width: 100%;
overflow: wrap;
}
@font-face {
font-family: 'Randomn4yy';
src: url('./_fonts/Randomn4yy-Regular.ttf');
}
@font-face {
font-family: 'Manrope';
src: url('./_fonts/Manrope-VariableFont_wght.ttf');
}
</style>
<script src="https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/crypto-js.js"></script>
<script type="module">
import {Terminal} from 'https://cdn.jsdelivr.net/npm/xterm@5.3.0/+esm'
import {FitAddon} from 'https://cdn.jsdelivr.net/npm/@xterm/addon-fit@0.10.0/+esm'
import {ESPLoader, Transport} from "https://unpkg.com/esptool-js/bundle.js";
var term = new Terminal();
const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
term.open(document.getElementById('terminal'));
fitAddon.fit();
let transport;
let esploader;
let device = null;
let chip = null;
const espLoaderTerminal = {
clean() {
term.clear();
},
writeLine(data) {
term.writeln(data);
},
write(data) {
term.write(data);
},
};
let isConsoleClosed = false;
async function reset() {
if (transport) {
await transport.setDTR(false);
await new Promise((resolve) => setTimeout(resolve, 100));
await transport.setDTR(true);
}
}
async function startConsole() {
if (transport) {
await transport.disconnect();
await transport.waitForUnlock(1500);
}
if (device === null) {
device = await navigator.serial.requestPort({});
transport = new Transport(device, true);
}
await transport.connect(115200);
isConsoleClosed = false;
reset();
while (true && !isConsoleClosed) {
const val = await transport.rawRead();
if (typeof val !== "undefined") {
term.write(val);
} else {
break;
}
}
isConsoleClosed = true;
console.log("quitting console");
};
function loadBinaryResource(url) {
const req = new XMLHttpRequest();
req.open("GET", url, false);
req.overrideMimeType("text/plain; charset=x-user-defined");
req.send(null);
return req.status === 200 ? req.responseText : "";
}
async function program() {
if (transport) {
await transport.disconnect();
await transport.waitForUnlock(1500);
}
if (device === null) {
device = await navigator.serial.requestPort({});
transport = new Transport(device, true);
}
try {
let flashOptions = {
transport,
baudrate: 921600,
terminal: espLoaderTerminal,
};
esploader = new ESPLoader(flashOptions);
chip = await esploader.main();
flashOptions = {
fileArray: [{data: loadBinaryResource("./_binaries/lrr-firmware.bin"), address: 0x0}],
flashSize: "keep",
eraseAll: false,
compress: true,
calculateMD5Hash: (image) => CryptoJS.MD5(CryptoJS.enc.Latin1.parse(image)),
};
await esploader.writeFlash(flashOptions);
} catch (e) {
console.error(e);
term.writeln(`Error: ${e.message}`);
}
startConsole();
};
consoleStartButton.onclick = startConsole;
resetButton.onclick = reset;
programButton.onclick = program;
</script>
</head>
<body>
<input type="button" id="programButton" value="Program" />
<input type="button" id="consoleStartButton" value="Open Console" />
<input type="button" id="resetButton" value="Reset" />
<div id="terminal"></div>
</body>
</html>