Let's build a simple Simulator for #BL602 ... With #uLisp, #WebAssembly and #Blockly
We stub out the GPIO Functions in #uLisp #WebAssembly ... They shall be simulated with JavaScript in our #BL602 Simulator
https://github.com/lupyuen/ulisp-bl602/blob/wasm/src/ulisp.c#L48-L57
#uLisp Interpreter runs in #WebAssembly ... Thanks to #Emscripten yay!
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1297-L1326
#uLisp in #WebAssembly ... Try it here: https://lupyuen.github.io/ulisp-bl602/ulisp.html
#BL602 Simulator is super helpful ... For catching, fixing and testing tricky firmware bugs like this
https://github.com/lupyuen/ulisp-bl602/blob/wasm/src/ulisp.c#L5346-L5373
#uLisp #WebAssembly shall send #BL602 Simulator a JSON Stream of Simulation Events ... Looks like a MIDI Stream 🤔
Here's the JSON Stream of #BL602 Simulation Events in #WebAssembly ... When #uLisp sets the GPIO Output, a Simulation Event gets added to the JSON Stream
https://github.com/lupyuen/ulisp-bl602/blob/wasm/wasm/wasm.c#L7-L32
Here's how #uLisp #WebAssembly adds a Simulation Event to the JSON Stream ... For #BL602 GPIO Output
https://github.com/lupyuen/ulisp-bl602/blob/wasm/wasm/wasm.c#L54-L71
#uLisp #WebAssembly generates this JSON Stream of #BL602 Simulation Events ... Now we interpret the Simulation Events and blink the Simulated #BL602 LED
How we return a String from #WebAssembly to JavaScript ... In our #BL602 Simulator
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1339-L1379
Our #BL602 Simulator needs a board pic ... Let's use this wriggly sketch for now 😬
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/pinecone.png
How we render our #BL602 Simulator pic to the HTML Canvas 🎨
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1334-L1358
How we handle the #BL602 Simulation Events generated by #uLisp #WebAssembly
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1407-L1454
Simulating #uLisp Loops ... We can't allow uLisp to emit an Infinite List of #BL602 Simulation Events ... So we stop uLisp Loops before the Event List gets too long
https://github.com/lupyuen/ulisp-bl602/blob/wasm/wasm/wasm.c#L34-L46
Let's add our #BL602 Simulator to #Blockly for uLisp ... So that we can preview Blockly Apps in the Web Browser!
https://github.com/AppKaki/blockly-ulisp/blob/wasm/demos/simulator/index.html
#BL602 #WebAssembly Simulator now works with #uLisp #Blockly Apps yay! 🎉
Try it here: https://appkaki.github.io/blockly-ulisp/demos/simulator/
Simulating #BL602 in a Web Browser ... With #WebAssembly, uLisp and Blockly ... All shall be explained here
How we compile #BL602 uLisp to #WebAssembly ... And call it from a Web Browser
https://lupyuen.github.io/articles/wasm?2#emscripten-and-webassembly
Here's how we built the #uLisp REPL in #WebAssembly
https://lupyuen.github.io/articles/wasm?3#repl-in-a-web-browser
Rendering our #BL602 Simulator in a Web Browser
https://lupyuen.github.io/articles/wasm?4#render-the-bl602-simulator
#uLisp sends a stream of Simulation Events to our #BL602 Simulator ... Here's how it works
https://lupyuen.github.io/articles/wasm?5#simulate-bl602-hardware
How #uLisp adds a #BL602 Simulation Event
https://lupyuen.github.io/articles/wasm?8#add-a-simulation-event
How uLisp #WebAssembly passes Simulation Events to the #BL602 Simulator
https://lupyuen.github.io/articles/wasm?10#get-the-simulation-events
Here's how we flip the Simulated LED on #BL602 Simulator
https://lupyuen.github.io/articles/wasm?11#flip-the-simulated-led
Drag-n-drop #Blockly (Scratch) programs ... And run them with #BL602 Simulator! Try it here
https://lupyuen.github.io/articles/wasm?16#add-simulator-to-blockly
Here's how we added #BL602 Simulator to #Blockly ... To simulate our drag-n-drop programs
https://lupyuen.github.io/articles/wasm?18#simulate-blockly-programs
Will our #BL602 Simulator run Actual BL602 Firmware in #WebAssembly? It might be possible!
https://lupyuen.github.io/articles/wasm?19#can-we-simulate-any-bl602-firmware
@lupyuen No more mysterious pins to chase down now?
@AmpBenzScientist I asked the Pine64 folks to chase down the pins thanks 🙂
To blink the Simulated #BL602 LED ... We need to Simulate the Delays too ... Here's how
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1467-L1472