diff --git a/scripts/emulation/Dockerfile b/scripts/emulation/Dockerfile index 9439c9f2..bc348a46 100644 --- a/scripts/emulation/Dockerfile +++ b/scripts/emulation/Dockerfile @@ -3,21 +3,42 @@ FROM debian:12 WORKDIR /root ARG DEBIAN_FRONTEND=noninteractive +ARG ESP_IDF_VERSION=v5.5.2 +ARG ESP_QEMU_VERSION=esp-develop-9.2.2-20250817 # Update container RUN apt-get update && apt-get upgrade -y # Install dependencies -RUN apt-get install git wget flex bison gperf python3 python3-pip python3-setuptools python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 \ - libgcrypt20 libglib2.0-0 libpixman-1-0 libsdl2-2.0-0 libslirp0 -y +RUN apt-get install -y git wget flex bison gperf python3 python3-pip python3-setuptools python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 \ + libgcrypt20 libglib2.0-0 libpixman-1-0 libsdl2-2.0-0 libslirp0 \ + libglib2.0-dev libpixman-1-dev libgcrypt20-dev libslirp-dev libsdl2-dev # Install ESP-IDF ENV PATH="~/.local/bin:${PATH}" -RUN mkdir -p ~/esp && cd ~/esp && git clone --quiet --recursive https://github.com/espressif/esp-idf.git && ln -s /usr/bin/python3 /usr/bin/python +RUN mkdir -p ~/esp && \ + cd ~/esp && git clone --recursive https://github.com/espressif/esp-idf.git -b ${ESP_IDF_VERSION} --depth 1 -j $(nproc) && \ + ln -s /usr/bin/python3 /usr/bin/python RUN cd ~/esp/esp-idf && export IDF_GITHUB_ASSETS="dl.espressif.com/github_assets" && ./install.sh && /bin/bash -c "source ./export.sh" # Install qemu -RUN cd ~/esp/esp-idf && python tools/idf_tools.py install qemu-riscv32 +RUN cd ~/esp/esp-idf && python tools/idf_tools.py install qemu-riscv32 qemu-xtensa + +# Or, build qemu from source +# RUN git clone https://github.com/espressif/qemu.git -b ${ESP_QEMU_VERSION} --depth 1 \ +# && cd qemu \ +# && mkdir -p build \ +# && cd build \ +# && ../configure --target-list=riscv32-softmmu \ +# --enable-gcrypt \ +# --enable-slirp \ +# --enable-debug \ +# --enable-sdl \ +# --disable-strip --disable-user \ +# --disable-capstone --disable-vnc \ +# --disable-gtk \ +# && make -j $(nproc) vga=no \ +# && make install RUN echo "alias idf='source /root/esp/esp-idf/export.sh'" >> .bashrc diff --git a/scripts/emulation/server.py b/scripts/emulation/server.py index 737d6845..d0dd3dfe 100644 --- a/scripts/emulation/server.py +++ b/scripts/emulation/server.py @@ -380,7 +380,7 @@ async def spawn_qemu(): "-nographic", "-M", "esp32c3", "-drive", "file=flash.bin,if=mtd,format=raw", - "-global", "driver=timer.esp32c3.timg,property=wdt_disable,value=true", # got panic if we don't disable WDT, why? + # "-global", "driver=timer.esp32c3.timg,property=wdt_disable,value=true", # got panic if we don't disable WDT, why? ] # Get working directory from environment or use /tmp diff --git a/src/Battery.h b/src/Battery.h index dcfcbf79..4181f402 100644 --- a/src/Battery.h +++ b/src/Battery.h @@ -3,4 +3,16 @@ #define BAT_GPIO0 0 // Battery voltage -static BatteryMonitor battery(BAT_GPIO0); +class Battery { + public: + uint16_t readPercentage() const { +#if CROSSPOINT_EMULATED == 0 + static const BatteryMonitor hwBattery = BatteryMonitor(BAT_GPIO0); + return hwBattery.readPercentage(); +#else + return 100; +#endif + } +}; + +static Battery battery;