From 631c699a54f1d439bcb2cae59a7125a31a646fc3 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Sat, 17 Nov 2018 00:07:36 +0100 Subject: [PATCH 1/2] Allow emulated startup of launcher and installer Restructured some bits to make it easier to fill in the blanks. With these changes the emulator can successfully start the launcher and the installer, though actually interacting with them is not yet supported. Additional benefit is that this allows moving some of the emulation code out of the micropython repo, keeping that repo more in sync with upstream. Merge https://github.com/HackerHotel/micropython-esp32/pull/1 and update the submodule in this PR before merging this PR. --- README.md | 3 +-- emulator/badge.py | 14 ++++++++++++++ emulator/emulate.py | 23 +++++++++++++++++++++++ emulator/esp.py | 1 + emulator/machine.py | 14 ++++++++++++++ micropython | 2 +- 6 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 emulator/badge.py create mode 100755 emulator/emulate.py create mode 100644 emulator/esp.py create mode 100644 emulator/machine.py diff --git a/README.md b/README.md index b70dc9c..1e12b57 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,5 @@ Badge Emulator -------------- ``` make -C micropython/unix -cd micropython/unix -./micropython ../../examples/Game\ of\ Life/game_of_life.py +./emulator/emulate.py examples/Game\ of\ Life/game_of_life.py ``` diff --git a/emulator/badge.py b/emulator/badge.py new file mode 100644 index 0000000..7f2c6a0 --- /dev/null +++ b/emulator/badge.py @@ -0,0 +1,14 @@ +# Emulating the badge module +# +# The badge module is a C module with Python bindings +# on the real badge, but for the emulator it's just a +# plain python module. + +def nvs_get_u16(namespace, key, value): + return value + +def eink_init(): + "ok" + +def safe_mode(): + return False diff --git a/emulator/emulate.py b/emulator/emulate.py new file mode 100755 index 0000000..cb95ef5 --- /dev/null +++ b/emulator/emulate.py @@ -0,0 +1,23 @@ +#!./micropython/unix/micropython + +# 'Emulator' to run badge micropython scripts on linux. +# +# Usage: './emulator/emulate.py micropython/esp32/modules/launcher.py' +# +# Needs this wrapper python script so the python module loader prefers the +# emulated module implementations in './emulator' over the 'real' +# implementations next to the to-be-emulated application. + +import sys,os + +print('Running',sys.argv[1],'in badge emulator') + +dir = '/'.join(sys.argv[1].split('/')[:-1]) +file = sys.argv[1].split('/')[-1] + +sys.path.append(dir) + +print('looking for',file,'in sys.path:',sys.path) + +__import__(file) +print('yolo') diff --git a/emulator/esp.py b/emulator/esp.py new file mode 100644 index 0000000..11a2462 --- /dev/null +++ b/emulator/esp.py @@ -0,0 +1 @@ +# Emulating the ESP API: diff --git a/emulator/machine.py b/emulator/machine.py new file mode 100644 index 0000000..8427a36 --- /dev/null +++ b/emulator/machine.py @@ -0,0 +1,14 @@ +# Emulating the machine API + +class Pin: + """"tee hee""" + +class RTC: + def wake_on_ext0(self, pin, level): + "ok" + +class Timer: + PERIODIC=1 + + def init(self, mode, period, callback): + "TODO" diff --git a/micropython b/micropython index 5dbf3e7..9527cca 160000 --- a/micropython +++ b/micropython @@ -1 +1 @@ -Subproject commit 5dbf3e7e6af454fc0a26ff2a281718c4b353d49a +Subproject commit 9527ccad30e4213307269de672af94adf4452988 From ab3205e539849632c54e7b9e30d30cbeaa4136dd Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Sat, 17 Nov 2018 00:29:11 +0100 Subject: [PATCH 2/2] Get micropython-esp32 submodule from HackerHotel --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 20a4449..198620c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,7 +4,7 @@ branch = master [submodule "micropython"] path = micropython - url = https://github.com/SHA2017-badge/micropython-esp32.git + url = https://github.com/HackerHotel/micropython-esp32.git branch = master [submodule "ugfx"] path = ugfx