Added first demo
This commit is contained in:
parent
5ced01aed7
commit
41013d4c9d
5 changed files with 399 additions and 0 deletions
74
wasmFPGALoader.html
Normal file
74
wasmFPGALoader.html
Normal file
|
@ -0,0 +1,74 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>wasmFPGAloader -- FPGAOL-CE</title>
|
||||
</head>
|
||||
<body>
|
||||
<button id="connectBtn">Connect</button>
|
||||
<button id="testBtn">openFPGAloader --detect</button>
|
||||
<p id="status0"></p>
|
||||
<input type="file" id="upload" onchange="uploadFile()">
|
||||
<button id="testBtn2">Blast</button>
|
||||
<script>
|
||||
const connectBtn = document.getElementById('connectBtn');
|
||||
connectBtn.addEventListener('click', connect_a_device);
|
||||
async function connect_a_device() {
|
||||
console.log('connect_a_device')
|
||||
await navigator.usb.requestDevice({ filters: [] });
|
||||
}
|
||||
const testBtn = document.getElementById('testBtn');
|
||||
testBtn.addEventListener('click', ofl_detect);
|
||||
async function ofl_detect() {
|
||||
console.log('openFPGAloader detect')
|
||||
try{
|
||||
await Module.callMain(["--detect"]);
|
||||
}
|
||||
catch (err) {
|
||||
console.log("Detecting JTAG downloader error: " + err.message)
|
||||
}
|
||||
}
|
||||
const testBtn2 = document.getElementById('testBtn2');
|
||||
testBtn2.addEventListener('click', test_usb_2);
|
||||
async function test_usb_2() {
|
||||
console.log('test_usb_2')
|
||||
await Module.callMain(["-b", "tangnano9k", "" + document.getElementById('upload').files[0].name]);
|
||||
//await Module.ccall('myMain', null, null, null);
|
||||
}
|
||||
var Module = {
|
||||
onRuntimeInitialized: function() {
|
||||
console.log('wasm loaded');
|
||||
},
|
||||
print: function(text) {
|
||||
console.log(text);
|
||||
},
|
||||
printErr: function(text) {
|
||||
console.log('Err: ' + text);
|
||||
}
|
||||
};
|
||||
|
||||
function uploadFile() {
|
||||
var fileInput = document.getElementById('upload');
|
||||
var file = fileInput.files[0];
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function() {
|
||||
// Create a Uint8Array from file content
|
||||
var data = new Uint8Array(reader.result);
|
||||
|
||||
// Use Emscripten's FS API to write the file to the virtual filesystem
|
||||
FS.writeFile('' + file.name, data);
|
||||
|
||||
console.log('File writen to WASM file system: ' + file.name);
|
||||
|
||||
// Optionally, call a function defined in your WebAssembly module that needs access to the file
|
||||
// For example, if your module has a function that takes the file path as argument
|
||||
// Module.ccall('yourFunctionName', 'returnType', ['param1Type'], ['/working/' + file.name]);
|
||||
};
|
||||
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
</script>
|
||||
<script src="./wasmFPGALoader.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue