├── .github └── workflows │ └── build.yml ├── .gitignore ├── Bootloader.cmake ├── CMakeLists.txt ├── LICENSE ├── README.md ├── apps ├── calculator │ ├── CMakeLists.txt │ ├── main │ │ ├── CMakeLists.txt │ │ ├── calculator.c │ │ └── idf_component.yml │ ├── sdkconfig.defaults │ ├── sdkconfig.defaults.esp-box │ ├── sdkconfig.defaults.esp-box-3 │ ├── sdkconfig.defaults.esp32_p4_function_ev_board │ └── sdkconfig.defaults.m5stack_core_s3 ├── game_of_life │ ├── CMakeLists.txt │ ├── main │ │ ├── CMakeLists.txt │ │ ├── game_of_life.c │ │ └── idf_component.yml │ ├── sdkconfig.defaults │ ├── sdkconfig.defaults.esp-box │ ├── sdkconfig.defaults.esp-box-3 │ ├── sdkconfig.defaults.esp32_p4_function_ev_board │ └── sdkconfig.defaults.m5stack_core_s3 ├── synth_piano │ ├── CMakeLists.txt │ ├── main │ │ ├── CMakeLists.txt │ │ ├── idf_component.yml │ │ └── synth_piano.c │ ├── sdkconfig.defaults │ ├── sdkconfig.defaults.esp-box │ ├── sdkconfig.defaults.esp-box-3 │ ├── sdkconfig.defaults.esp32_p4_function_ev_board │ └── sdkconfig.defaults.m5stack_core_s3 ├── tic_tac_toe │ ├── CMakeLists.txt │ ├── diagram.json │ ├── main │ │ ├── CMakeLists.txt │ │ ├── idf_component.yml │ │ └── tic_tac_toe.c │ ├── sdkconfig.defaults │ ├── sdkconfig.defaults.esp-box │ ├── sdkconfig.defaults.esp-box-3 │ ├── sdkconfig.defaults.esp32_p4_function_ev_board │ ├── sdkconfig.defaults.m5stack_core_s3 │ └── wokwi.toml └── wifi_list │ ├── CMakeLists.txt │ ├── main │ ├── CMakeLists.txt │ ├── idf_component.yml │ └── wifi_list.c │ ├── partitions.csv │ ├── sdkconfig.defaults │ ├── sdkconfig.defaults.esp-box │ ├── sdkconfig.defaults.esp-box-3 │ ├── sdkconfig.defaults.esp32_p4_function_ev_board │ └── sdkconfig.defaults.m5stack_core_s3 ├── boards ├── esp-box-3.cfg ├── esp-box.cfg ├── esp32_p4_function_ev_board.cfg └── m5stack_core_s3.cfg ├── diagram.json ├── doc └── esp32-s3-box-3-graphical-bootloader.webp ├── esp-launchpad.toml ├── main ├── CMakeLists.txt ├── bootloader_ui.c ├── graphical_bootloader_main.c └── idf_component.yml ├── partitions.csv ├── resources └── images │ ├── icon_calculator.png │ ├── icon_game_of_life.png │ ├── icon_synth_piano.png │ ├── icon_tic_tac_toe.png │ └── icon_wifi_list.png ├── sdkconfig.defaults ├── sdkconfig.defaults.esp-box ├── sdkconfig.defaults.esp-box-3 ├── sdkconfig.defaults.esp32_p4_function_ev_board ├── sdkconfig.defaults.m5stack_core_s3 └── wokwi.toml /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build and Release Graphical Bootloader 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*.*' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | create-release: 11 | runs-on: ubuntu-22.04 12 | outputs: 13 | upload_url: ${{ steps.create_release.outputs.upload_url }} 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v3 17 | 18 | - name: Extract Tag Name 19 | id: extract_tag_name 20 | run: echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT 21 | 22 | - name: Create Draft Release 23 | id: create_release 24 | run: | 25 | gh release create ${{ steps.extract_tag_name.outputs.tag_name }} --title "Release ${{ steps.extract_tag_name.outputs.tag_name }}" --notes "Release notes for ${{ steps.extract_tag_name.outputs.tag_name }}" --draft 26 | env: 27 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 28 | 29 | build-and-upload: 30 | needs: create-release 31 | strategy: 32 | matrix: 33 | board: 34 | - { name: "esp32-s3-box-3", sdkconfig: "sdkconfig.defaults.esp-box-3" } 35 | - { name: "esp32-s3-box", sdkconfig: "sdkconfig.defaults.esp-box" } 36 | #- { name: "esp32-p4", sdkconfig: "sdkconfig.defaults.esp32_p4_function_ev_board" } 37 | - { name: "m5stack-cores3", sdkconfig: "sdkconfig.defaults.m5stack_core_s3" } 38 | runs-on: ubuntu-22.04 39 | container: espressif/idf:release-v5.3 40 | 41 | steps: 42 | - uses: actions/checkout@v3 43 | with: 44 | submodules: 'recursive' 45 | 46 | - name: Set SDKCONFIG_DEFAULTS 47 | run: echo "SDKCONFIG_DEFAULTS=${{ matrix.board.sdkconfig }}" >> $GITHUB_ENV 48 | 49 | - name: Build the main application and sub-applications 50 | run: | 51 | . /opt/esp/idf/export.sh 52 | cmake -Daction=select_board -P Bootloader.cmake 53 | cmake -Daction=build_all_apps -P Bootloader.cmake 54 | 55 | - name: Merge binaries into a single image 56 | run: | 57 | . /opt/esp/idf/export.sh 58 | cmake -Daction=merge_binaries -P Bootloader.cmake 59 | mv build/combined.bin build/graphical-bootloader-${{ matrix.board.name }}.bin 60 | 61 | 62 | - name: Upload artifact 63 | uses: actions/upload-artifact@v4 64 | with: 65 | name: graphical-bootloader-${{ matrix.board.name }}.bin 66 | path: build/graphical-bootloader-${{ matrix.board.name }}.bin 67 | 68 | - name: Merge binaries into a uf2 image 69 | run: | 70 | . /opt/esp/idf/export.sh 71 | cmake -Daction=merge_binaries_uf2 -P Bootloader.cmake 72 | mv build/uf2.bin build/graphical-bootloader-${{ matrix.board.name }}.uf2 73 | 74 | - name: Upload UF2 artifact 75 | uses: actions/upload-artifact@v4 76 | with: 77 | name: graphical-bootloader-${{ matrix.board.name }}.uf2 78 | path: build/graphical-bootloader-${{ matrix.board.name }}.uf2 79 | 80 | upload-release-assets: 81 | needs: build-and-upload 82 | runs-on: ubuntu-22.04 83 | steps: 84 | - name: Checkout 85 | uses: actions/checkout@v3 86 | 87 | - name: Download Artifacts 88 | uses: actions/download-artifact@v4 89 | with: 90 | path: ./artifacts 91 | merge-multiple: true 92 | 93 | - name: Extract Tag Name 94 | id: extract_tag_name 95 | run: echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT 96 | 97 | - name: Rename and Upload Release Assets 98 | run: | 99 | ls -l ./artifacts 100 | for file in ./artifacts/*.bin ./artifacts/*.uf2; do 101 | gh release upload ${{ steps.extract_tag_name.outputs.tag_name }} "${file}" --clobber 102 | done 103 | env: 104 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 105 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # ESP-IDF 55 | build/ 56 | build.*/ 57 | managed_components/ 58 | dependencies.lock 59 | 60 | sdkconfig 61 | sdkconfig.old 62 | sdkconfig.*.vscode 63 | 64 | main/images/ 65 | 66 | .DS_Store 67 | .vscode/ 68 | 69 | -------------------------------------------------------------------------------- /Bootloader.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(NOT DEFINED BUILD_BOARD) 4 | message(FATAL_ERROR "BUILD_BOARD CMake variable is not set") 5 | endif() 6 | 7 | # Function to build all applications 8 | function(build_all_apps) 9 | # Build main app 10 | message(STATUS "Building main application") 11 | execute_process( 12 | COMMAND idf.py @boards/${BUILD_BOARD}.cfg build 13 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 14 | RESULT_VARIABLE build_main_result 15 | ) 16 | if(NOT build_main_result EQUAL 0) 17 | message(FATAL_ERROR "Failed to build main application") 18 | endif() 19 | 20 | # List of sub-applications 21 | set(SUB_APPS tic_tac_toe wifi_list calculator synth_piano game_of_life) 22 | 23 | # Function to build each sub-application 24 | function(build_app APP) 25 | message(STATUS "Building ${APP}") 26 | execute_process( 27 | COMMAND idf.py @../../boards/${BUILD_BOARD}.cfg build 28 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/apps/${APP} 29 | RESULT_VARIABLE build_result 30 | ) 31 | if(NOT build_result EQUAL 0) 32 | message(FATAL_ERROR "Failed to build ${APP}") 33 | endif() 34 | endfunction() 35 | 36 | # Build each sub-application 37 | foreach(APP ${SUB_APPS}) 38 | build_app(${APP}) 39 | endforeach() 40 | endfunction() 41 | 42 | # Function to merge all binaries into a single .bin file 43 | function(merge_binaries) 44 | # Paths to binaries 45 | set(BOOTLOADER_BIN "${CMAKE_SOURCE_DIR}/build/bootloader/bootloader.bin") 46 | set(PARTITION_TABLE_BIN "${CMAKE_SOURCE_DIR}/build/partition_table/partition-table.bin") 47 | set(MAIN_APP_BIN "${CMAKE_SOURCE_DIR}/build/esp32-graphical-bootloader.bin") 48 | set(OTA_DATA_INITIAL_BIN "${CMAKE_SOURCE_DIR}/build/ota_data_initial.bin") 49 | 50 | # List of sub-applications and corresponding flash addresses 51 | set(SUB_APP_NAMES 52 | tic_tac_toe 53 | wifi_list 54 | calculator 55 | synth_piano 56 | game_of_life 57 | ) 58 | 59 | set(SUB_APP_ADDRS 60 | 0x220000 61 | 0x4E0000 62 | 0x7A0000 63 | 0xA60000 64 | 0xD20000 65 | ) 66 | 67 | # Build command for esptool.py merge_bin 68 | set(MERGE_CMD esptool.py --chip esp32s3 merge_bin -o ${CMAKE_SOURCE_DIR}/build/combined.bin 69 | --flash_mode dio --flash_size 16MB 70 | 0x0 ${BOOTLOADER_BIN} 71 | 0x8000 ${PARTITION_TABLE_BIN} 72 | 0xf000 ${OTA_DATA_INITIAL_BIN} 73 | 0x20000 ${MAIN_APP_BIN} 74 | ) 75 | 76 | # Append sub-application binaries and addresses 77 | list(LENGTH SUB_APP_NAMES LENGTH_SUB_APP_NAMES) 78 | math(EXPR LAST_IDX "${LENGTH_SUB_APP_NAMES} - 1") 79 | foreach(APP_IDX RANGE 0 ${LAST_IDX}) 80 | list(GET SUB_APP_NAMES ${APP_IDX} APP) 81 | list(GET SUB_APP_ADDRS ${APP_IDX} ADDR) 82 | list(APPEND MERGE_CMD ${ADDR} ${CMAKE_SOURCE_DIR}/apps/${APP}/build/${APP}.bin) 83 | endforeach() 84 | 85 | # Execute merge command 86 | message(STATUS "Merging binaries into combined.bin...") 87 | execute_process( 88 | COMMAND ${MERGE_CMD} 89 | RESULT_VARIABLE merge_result 90 | ) 91 | if(NOT merge_result EQUAL 0) 92 | message(FATAL_ERROR "Failed to merge binaries") 93 | endif() 94 | endfunction() 95 | 96 | # Function to merge all binaries into a single UF2 file 97 | function(merge_binaries_uf2) 98 | # Paths to binaries 99 | set(BOOTLOADER_BIN "${CMAKE_SOURCE_DIR}/build/bootloader/bootloader.bin") 100 | set(PARTITION_TABLE_BIN "${CMAKE_SOURCE_DIR}/build/partition_table/partition-table.bin") 101 | set(MAIN_APP_BIN "${CMAKE_SOURCE_DIR}/build/esp32-graphical-bootloader.bin") 102 | set(OTA_DATA_INITIAL_BIN "${CMAKE_SOURCE_DIR}/build/ota_data_initial.bin") 103 | 104 | # List of sub-applications and corresponding flash addresses 105 | set(SUB_APP_NAMES 106 | tic_tac_toe 107 | wifi_list 108 | calculator 109 | synth_piano 110 | game_of_life 111 | ) 112 | 113 | set(SUB_APP_ADDRS 114 | 0x220000 115 | 0x4E0000 116 | 0x7A0000 117 | 0xA60000 118 | 0xD20000 119 | ) 120 | 121 | # Build command for esptool.py merge_bin with UF2 format 122 | set(MERGE_CMD esptool.py --chip esp32s3 merge_bin --format uf2 -o ${CMAKE_SOURCE_DIR}/build/uf2.bin 123 | --flash_mode dio --flash_size 16MB 124 | 0x0 ${BOOTLOADER_BIN} 125 | 0x8000 ${PARTITION_TABLE_BIN} 126 | 0xf000 ${OTA_DATA_INITIAL_BIN} 127 | 0x20000 ${MAIN_APP_BIN} 128 | ) 129 | 130 | # Append sub-application binaries and addresses 131 | list(LENGTH SUB_APP_NAMES LENGTH_SUB_APP_NAMES) 132 | math(EXPR LAST_IDX "${LENGTH_SUB_APP_NAMES} - 1") 133 | foreach(APP_IDX RANGE 0 ${LAST_IDX}) 134 | list(GET SUB_APP_NAMES ${APP_IDX} APP) 135 | list(GET SUB_APP_ADDRS ${APP_IDX} ADDR) 136 | list(APPEND MERGE_CMD ${ADDR} ${CMAKE_SOURCE_DIR}/apps/${APP}/build/${APP}.bin) 137 | endforeach() 138 | 139 | # Execute merge command 140 | message(STATUS "Merging binaries into uf2.bin...") 141 | execute_process( 142 | COMMAND ${MERGE_CMD} 143 | RESULT_VARIABLE merge_result 144 | ) 145 | if(NOT merge_result EQUAL 0) 146 | message(FATAL_ERROR "Failed to merge binaries into UF2") 147 | endif() 148 | endfunction() 149 | 150 | # Function to run all steps 151 | function(build_all) 152 | select_board() 153 | build_all_apps() 154 | merge_binaries() 155 | endfunction() 156 | 157 | # Entry point 158 | if(DEFINED action) 159 | message(STATUS "Action specified: ${action}") 160 | if(action STREQUAL "select_board") 161 | select_board() 162 | elseif(action STREQUAL "build_all_apps") 163 | build_all_apps() 164 | elseif(action STREQUAL "merge_binaries") 165 | merge_binaries() 166 | elseif(action STREQUAL "merge_binaries_uf2") 167 | merge_binaries_uf2() 168 | elseif(action STREQUAL "build_all") 169 | build_all() 170 | else() 171 | message(FATAL_ERROR "Unknown action: ${action}") 172 | endif() 173 | else() 174 | message(FATAL_ERROR "No action specified") 175 | endif() 176 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about build system see 2 | # https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html 3 | # The following five lines of boilerplate have to be in your project's 4 | # CMakeLists in this exact order for cmake to work correctly 5 | cmake_minimum_required(VERSION 3.5) 6 | 7 | # Select board configuration based on -DBUILD_BOARD 8 | if(NOT DEFINED BUILD_BOARD) 9 | message(FATAL_ERROR "BUILD_BOARD CMake variable is not set") 10 | endif() 11 | 12 | set(ENV{USE_ESP_BOX} "0") 13 | set(ENV{USE_ESP_BOX_3} "0") 14 | set(ENV{USE_M5STACK_CORE_S3} "0") 15 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "0") 16 | 17 | if (BUILD_BOARD STREQUAL "esp-box") 18 | set(ENV{USE_ESP_BOX} "esp32s3") 19 | elseif (BUILD_BOARD STREQUAL "esp-box-3") 20 | set(ENV{USE_ESP_BOX_3} "esp32s3") 21 | elseif (BUILD_BOARD STREQUAL "m5stack_core_s3") 22 | set(ENV{USE_M5STACK_CORE_S3} "esp32s3") 23 | elseif (BUILD_BOARD STREQUAL "esp32_p4_function_ev_board") 24 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "esp32p4") 25 | endif() 26 | 27 | set(COMPONENTS main) # "Trim" the build. Include the minimal set of components; main and anything it depends on. 28 | 29 | # Each configuration's sdkconfig will be in the build directory 30 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 31 | 32 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 33 | project(esp32-graphical-bootloader) 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP32 Graphical Bootloader 2 | 3 | 3rd stage graphical bootloader which lets you pick applications stored in OTA partitions. 4 | 5 | 6 | ## How it works 7 | 8 | The bootloader allows user to select an application from graphical menu. After the selection the partition is selected and the chip rebooted. The bootloader switches to the newly selected application. During the start of the application there is a code which switches bootloader back to the first application with the bootloader. After another restart the original application with the bootloader is visible again. 9 | 10 | ### Test on-line 11 | 12 | [![ESP32-S3-Box-3 Graphical Bootloader](doc/esp32-s3-box-3-graphical-bootloader.webp)](https://wokwi.com/experimental/viewer?diagram=https://gist.githubusercontent.com/urish/c3d58ddaa0817465605ecad5dc171396/raw/ab1abfa902835a9503d412d55a97ee2b7e0a6b96/diagram.json&firmware=https://github.com/georgik/esp32-graphical-bootloader/releases/latest/download/graphical-bootloader-esp32-s3-box.uf2 13 | ) 14 | 15 | [Run on-line in Wokwi Simulator](https://wokwi.com/experimental/viewer?diagram=https://gist.githubusercontent.com/urish/c3d58ddaa0817465605ecad5dc171396/raw/ab1abfa902835a9503d412d55a97ee2b7e0a6b96/diagram.json&firmware=https://github.com/georgik/esp32-graphical-bootloader/releases/latest/download/graphical-bootloader-esp32-s3-box.uf2) 16 | 17 | ## Selected board 18 | 19 | The project is by default configured for ESP32-S3-BOX-3. Build configuration for the available boards are stored in `boards` directory. 20 | If you need a different board please run one of following exports and then CMake command: 21 | 22 | - ESP32-S3-BOX-3 23 | ```shell 24 | idf.py @boards/esp-box-3.cfg reconfigure 25 | ``` 26 | 27 | - ESP32-S3-BOX (prior Dec. 2023) 28 | ```shell 29 | idf.py @boards/esp-box.cfg reconfigure 30 | ``` 31 | 32 | - ESP32-P4 33 | ```shell 34 | idf.py @boards/esp32_p4_function_ev_board.cfg reconfigure 35 | ``` 36 | 37 | - M5Stack-CoreS3 38 | ```shell 39 | idf.py @boards/m5stack_core_s3.cfg reconfigure 40 | ``` 41 | 42 | ## Quick start 43 | 44 | Build and flash all applications at once: 45 | 46 | ```shell 47 | cmake -DBUILD_BOARD=esp-box-3 -Daction=build_all_apps -P Bootloader.cmake 48 | ``` 49 | 50 | ## Build applications one by one 51 | 52 | Applications are stored in ota_0 - ota_4 with the following offset: 53 | - ota_0 - 0x220000 54 | - ota_1 - 0x4E0000 55 | - ota_2 - 0x7A0000 56 | - ota_3 - 0xA60000 57 | - ota_4 - 0xD20000 58 | 59 | Commands to build and flash appplications: 60 | ```shell 61 | idf.py @boards/esp-box-3.cfg build 62 | pushd apps/tic_tac_toe 63 | idf.py @../../boards/esp-box-3.cfg build 64 | esptool.py --before default_reset --after hard_reset write_flash 0x220000 build.esp-box-3/tic_tac_toe.bin 65 | popd 66 | pushd apps/wifi_list 67 | idf.py @../../boards/esp-box-3.cfg build 68 | esptool.py --before default_reset --after hard_reset write_flash 0x4E0000 build.esp-box-3/wifi_list.bin 69 | popd 70 | pushd apps/calculator 71 | idf.py @../../boards/esp-box-3.cfg build 72 | esptool.py --before default_reset --after hard_reset write_flash 0x7A0000 build.esp-box-3/calculator.bin 73 | popd 74 | pushd apps/synth_piano 75 | idf.py @../../boards/esp-box-3.cfg build 76 | esptool.py --before default_reset --after hard_reset write_flash 0xA60000 build.esp-box-3/synth_piano.bin 77 | popd 78 | pushd apps/game_of_life 79 | idf.py @../../boards/esp-box-3.cfg build 80 | esptool.py --before default_reset --after hard_reset write_flash 0xD20000 build.esp-box-3/game_of_life.bin 81 | popd 82 | ``` 83 | 84 | Alternatively you can use [espflash](https://github.com/esp-rs/espflash/blob/main/espflash/README.md#installation): 85 | ``` 86 | espflash write-bin 0xD20000 .\build.esp-box-3\app.bin 87 | ``` 88 | 89 | ### Merging all applications 90 | 91 | The following command merges all applications into binary image format: 92 | ```shell 93 | esptool.py --chip esp32s3 merge_bin -o build.esp-box-3/combined.bin --flash_mode dio --flash_size 16MB \ 94 | 0x0 build.esp-box-3/bootloader/bootloader.bin \ 95 | 0x8000 build.esp-box-3/partition_table/partition-table.bin \ 96 | 0xf000 build.esp-box-3/ota_data_initial.bin \ 97 | 0x20000 build.esp-box-3/esp32-graphical-bootloader.bin \ 98 | 0x220000 apps/tic_tac_toe/build.esp-box-3/tic_tac_toe.bin \ 99 | 0x4E0000 apps/wifi_list/build.esp-box-3/wifi_list.bin \ 100 | 0x7A0000 apps/calculator/build.esp-box-3/calculator.bin \ 101 | 0xA60000 apps/synth_piano/build.esp-box-3/synth_piano.bin \ 102 | 0xD20000 apps/game_of_life/build.esp-box-3/game_of_life.bin 103 | ``` 104 | 105 | The single binary can be flashed by command: 106 | 107 | ```shell 108 | esptool.py --chip esp32s3 --baud 921600 write_flash 0x0000 build.esp-box-3/combined.bin 109 | ``` 110 | 111 | ## Create custom app 112 | 113 | You can use ESP-IDF app, just you need to make sure that application has fallback mechanism to factory app. This can be achieving by following code. 114 | 115 | ## Updating apps to fallback to bootloader 116 | 117 | The bootloader is using OTA mechanism. It's necessary to add following code to the application 118 | in order to reboot to bootloader. 119 | 120 | Put the following code to main, before starting the rest of the application: 121 | ```c 122 | #include "esp_ota_ops.h" 123 | 124 | const esp_partition_t* factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); 125 | if (factory_partition != NULL) { 126 | esp_ota_set_boot_partition(factory_partition); 127 | } 128 | ``` 129 | 130 | More elaborate version which can be put somwhere into application, like reaction on back button: 131 | 132 | ```c 133 | #include "esp_ota_ops.h" 134 | 135 | // Get the partition structure for the factory partition 136 | const esp_partition_t *factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); 137 | if (factory_partition != NULL) { 138 | if (esp_ota_set_boot_partition(factory_partition) == ESP_OK) { 139 | printf("Set boot partition to factory.\n"); 140 | } else { 141 | printf("Failed to set boot partition to factory.\n"); 142 | } 143 | } else { 144 | printf("Factory partition not found.\n"); 145 | } 146 | 147 | fflush(stdout); 148 | printf("Restarting now.\n"); 149 | esp_restart(); 150 | ``` 151 | 152 | If the project is using explicit list of components, you need to add `app_update` into `main/CMakeLists.txt`, so it looks like this: 153 | ``` 154 | idf_component_register( 155 | SRCS "main.cpp" 156 | INCLUDE_DIRS "." 157 | REQUIRES app_update 158 | ) 159 | ``` 160 | -------------------------------------------------------------------------------- /apps/calculator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following five lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.16) 4 | 5 | # Select board configuration based on -DBUILD_BOARD 6 | if(NOT DEFINED BUILD_BOARD) 7 | message(FATAL_ERROR "BUILD_BOARD CMake variable is not set") 8 | endif() 9 | 10 | set(ENV{USE_ESP_BOX} "0") 11 | set(ENV{USE_ESP_BOX_3} "0") 12 | set(ENV{USE_M5STACK_CORE_S3} "0") 13 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "0") 14 | 15 | if (BUILD_BOARD STREQUAL "esp-box") 16 | set(ENV{USE_ESP_BOX} "esp32s3") 17 | elseif (BUILD_BOARD STREQUAL "esp-box-3") 18 | set(ENV{USE_ESP_BOX_3} "esp32s3") 19 | elseif (BUILD_BOARD STREQUAL "m5stack_core_s3") 20 | set(ENV{USE_M5STACK_CORE_S3} "esp32s3") 21 | elseif (BUILD_BOARD STREQUAL "esp32_p4_function_ev_board") 22 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "esp32p4") 23 | endif() 24 | 25 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 26 | project(calculator) 27 | -------------------------------------------------------------------------------- /apps/calculator/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "calculator.c" 2 | INCLUDE_DIRS "." 3 | REQUIRES app_update) 4 | -------------------------------------------------------------------------------- /apps/calculator/main/calculator.c: -------------------------------------------------------------------------------- 1 | #include "freertos/FreeRTOS.h" 2 | #include "freertos/task.h" 3 | #include "esp_system.h" 4 | #include "esp_log.h" 5 | #include "lvgl.h" 6 | #include "bsp/esp-bsp.h" 7 | #include "esp_timer.h" 8 | #include "esp_ota_ops.h" 9 | 10 | #define TAG "Calculator" 11 | 12 | static lv_obj_t *display_label; 13 | static char current_input[64] = ""; 14 | static double stored_value = 0; 15 | static char current_operator = 0; 16 | static bool clear_next = false; 17 | static int64_t last_press_time = 0; 18 | 19 | static void update_display() { 20 | bsp_display_lock(0); 21 | lv_label_set_text(display_label, current_input); 22 | bsp_display_unlock(); 23 | } 24 | 25 | static void clear_input() { 26 | current_input[0] = '\0'; 27 | update_display(); 28 | } 29 | 30 | static void append_input(const char *text) { 31 | if (clear_next) { 32 | clear_input(); 33 | clear_next = false; 34 | } 35 | if (strlen(current_input) < sizeof(current_input) - 1) { 36 | strcat(current_input, text); 37 | } 38 | update_display(); 39 | } 40 | 41 | static void handle_operator(char operator) { 42 | if (current_operator != 0 && !clear_next) { 43 | double current_value = atof(current_input); 44 | switch (current_operator) { 45 | case '+': stored_value += current_value; break; 46 | case '-': stored_value -= current_value; break; 47 | case '*': stored_value *= current_value; break; 48 | case '/': if (current_value != 0) stored_value /= current_value; break; 49 | } 50 | snprintf(current_input, sizeof(current_input), "%g", stored_value); 51 | update_display(); 52 | } else { 53 | stored_value = atof(current_input); 54 | } 55 | current_operator = operator; 56 | clear_next = true; 57 | } 58 | 59 | static void btn_event_cb(lv_event_t *e) { 60 | int64_t now = esp_timer_get_time(); 61 | if (now - last_press_time < 500000) { // 500 ms debounce time 62 | return; 63 | } 64 | last_press_time = now; 65 | 66 | lv_obj_t *btn = lv_event_get_target(e); 67 | const char *txt = lv_btnmatrix_get_btn_text(btn, lv_btnmatrix_get_selected_btn(btn)); 68 | 69 | if (strcmp(txt, "C") == 0) { 70 | clear_input(); 71 | stored_value = 0; 72 | current_operator = 0; 73 | } else if (strcmp(txt, "=") == 0) { 74 | handle_operator(0); 75 | current_operator = 0; 76 | clear_next = true; 77 | } else if (strchr("+-*/", txt[0]) != NULL) { 78 | handle_operator(txt[0]); 79 | } else { 80 | append_input(txt); 81 | } 82 | } 83 | 84 | void reset_to_factory_app() { 85 | // Get the partition structure for the factory partition 86 | const esp_partition_t *factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); 87 | if (factory_partition != NULL) { 88 | if (esp_ota_set_boot_partition(factory_partition) == ESP_OK) { 89 | printf("Set boot partition to factory.\n"); 90 | } else { 91 | printf("Failed to set boot partition to factory.\n"); 92 | } 93 | } else { 94 | printf("Factory partition not found.\n"); 95 | } 96 | 97 | fflush(stdout); 98 | } 99 | 100 | void app_main(void) { 101 | // Reset to factory app for the next boot. 102 | // It should return to graphical bootloader. 103 | reset_to_factory_app(); 104 | 105 | // Initialize the BSP 106 | bsp_i2c_init(); 107 | bsp_display_start(); 108 | lv_init(); 109 | 110 | // Create a label for the display 111 | display_label = lv_label_create(lv_scr_act()); 112 | lv_obj_set_size(display_label, 300, 30); 113 | lv_obj_align(display_label, LV_ALIGN_TOP_MID, 0, 10); 114 | lv_label_set_text(display_label, "0"); 115 | 116 | // Create a button matrix for the calculator 117 | static const char *btn_map[] = { 118 | "7", "8", "9", "C", "\n", 119 | "4", "5", "6", "*", "\n", 120 | "1", "2", "3", "-", "\n", 121 | "0", ".", "/", "+", "\n", 122 | "=", "" 123 | }; 124 | 125 | lv_obj_t *btnm = lv_btnmatrix_create(lv_scr_act()); 126 | lv_btnmatrix_set_map(btnm, btn_map); 127 | lv_obj_set_size(btnm, 320, 180); 128 | lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 30); 129 | lv_obj_add_event_cb(btnm, btn_event_cb, LV_EVENT_VALUE_CHANGED, NULL); 130 | 131 | bsp_display_backlight_on(); 132 | 133 | while (1) { 134 | vTaskDelay(pdMS_TO_TICKS(1000)); // Add a small delay to prevent watchdog issues 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /apps/calculator/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | espressif/esp-box-3: 4 | version: "^1.2.0" 5 | rules: 6 | - if: "target == ${USE_ESP_BOX_3}" 7 | espressif/esp-box: 8 | version: "3.1.0" 9 | rules: 10 | - if: "target == ${USE_ESP_BOX}" 11 | espressif/m5stack_core_s3: 12 | version: "1.1.1" 13 | rules: 14 | - if: "target == ${USE_M5STACK_CORE_S3}" 15 | espressif/esp32_p4_function_ev_board: 16 | version: "2.0.0" 17 | rules: 18 | - if: "target == ${USE_ESP32_P4_FUNCTION_EV_BOARD}" 19 | # Workaround for i2c: CONFLICT! driver_ng is not allowed to be used with this old driver 20 | esp_codec_dev: 21 | public: true 22 | version: "==1.1.0" 23 | ## Required IDF version 24 | idf: 25 | version: ">=5.0.0" -------------------------------------------------------------------------------- /apps/calculator/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/calculator/sdkconfig.defaults.esp-box: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/calculator/sdkconfig.defaults.esp-box-3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/calculator/sdkconfig.defaults.esp32_p4_function_ev_board: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32p4" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | #CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | 9 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 11 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 12 | CONFIG_SPIRAM=y 13 | CONFIG_SPIRAM_MODE_OCT=y 14 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y 15 | CONFIG_SPIRAM_RODATA=y 16 | CONFIG_SPIRAM_SPEED_80M=y 17 | CONFIG_FREERTOS_HZ=1000 18 | CONFIG_BSP_LCD_RGB_BUFFER_NUMS=2 19 | CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y 20 | CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR=y 21 | CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y 22 | CONFIG_SPIRAM_MODE_HEX=y 23 | CONFIG_SPIRAM_SPEED_200M=y 24 | CONFIG_IDF_EXPERIMENTAL_FEATURES=y 25 | 26 | ## LVGL9 ## 27 | CONFIG_LV_CONF_SKIP=y 28 | 29 | #CLIB default 30 | CONFIG_LV_USE_CLIB_MALLOC=y 31 | CONFIG_LV_USE_CLIB_SPRINTF=y 32 | CONFIG_LV_USE_CLIB_STRING=y 33 | 34 | -------------------------------------------------------------------------------- /apps/calculator/sdkconfig.defaults.m5stack_core_s3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_SPIRAM_MODE_QUAD=y 7 | -------------------------------------------------------------------------------- /apps/game_of_life/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following five lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.16) 4 | 5 | # Select board configuration based on -DBUILD_BOARD 6 | if(NOT DEFINED BUILD_BOARD) 7 | message(FATAL_ERROR "BUILD_BOARD CMake variable is not set") 8 | endif() 9 | 10 | set(ENV{USE_ESP_BOX} "0") 11 | set(ENV{USE_ESP_BOX_3} "0") 12 | set(ENV{USE_M5STACK_CORE_S3} "0") 13 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "0") 14 | 15 | if (BUILD_BOARD STREQUAL "esp-box") 16 | set(ENV{USE_ESP_BOX} "esp32s3") 17 | elseif (BUILD_BOARD STREQUAL "esp-box-3") 18 | set(ENV{USE_ESP_BOX_3} "esp32s3") 19 | elseif (BUILD_BOARD STREQUAL "m5stack_core_s3") 20 | set(ENV{USE_M5STACK_CORE_S3} "esp32s3") 21 | elseif (BUILD_BOARD STREQUAL "esp32_p4_function_ev_board") 22 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "esp32p4") 23 | endif() 24 | 25 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 26 | project(game_of_life) 27 | -------------------------------------------------------------------------------- /apps/game_of_life/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "game_of_life.c" 2 | INCLUDE_DIRS "." 3 | REQUIRES app_update) 4 | -------------------------------------------------------------------------------- /apps/game_of_life/main/game_of_life.c: -------------------------------------------------------------------------------- 1 | #include 2 | // Conway's Game of Life for ESP32 using LVGL 3 | #include 4 | #include 5 | #include 6 | #include "freertos/FreeRTOS.h" 7 | #include "freertos/task.h" 8 | #include "esp_log.h" 9 | #include "esp_system.h" 10 | #include "lvgl.h" 11 | #include "bsp/esp-bsp.h" 12 | #include "esp_ota_ops.h" 13 | 14 | #define TAG "GameOfLife" 15 | #define GRID_SIZE 20 16 | #define CELL_SIZE 10 17 | #define CANVAS_WIDTH (GRID_SIZE * CELL_SIZE) 18 | #define CANVAS_HEIGHT (GRID_SIZE * CELL_SIZE) 19 | 20 | static bool grid[GRID_SIZE][GRID_SIZE]; 21 | static bool temp_grid[GRID_SIZE][GRID_SIZE]; 22 | static lv_obj_t *canvas; 23 | lv_layer_t layer; 24 | 25 | static void draw_grid(); 26 | static void update_grid(); 27 | 28 | static void randomize_grid() { 29 | for (int row = 0; row < GRID_SIZE; ++row) { 30 | for (int col = 0; col < GRID_SIZE; ++col) { 31 | grid[row][col] = rand() % 2; 32 | } 33 | } 34 | } 35 | 36 | static void reset_btn_event_cb(lv_event_t *e) { 37 | lv_event_code_t code = lv_event_get_code(e); 38 | if (code == LV_EVENT_CLICKED) { 39 | randomize_grid(); 40 | } 41 | } 42 | 43 | static void draw_grid() { 44 | bsp_display_lock(0); 45 | 46 | lv_draw_rect_dsc_t rect_dsc; 47 | lv_draw_rect_dsc_init(&rect_dsc); 48 | 49 | for (int row = 0; row < GRID_SIZE; ++row) { 50 | for (int col = 0; col < GRID_SIZE; ++col) { 51 | lv_area_t area; 52 | area.x1 = col * CELL_SIZE; 53 | area.y1 = row * CELL_SIZE; 54 | area.x2 = area.x1 + CELL_SIZE - 1; 55 | area.y2 = area.y1 + CELL_SIZE - 1; 56 | rect_dsc.bg_color = grid[row][col] ? lv_palette_main(LV_PALETTE_BLUE) : lv_color_white(); 57 | lv_draw_rect(&layer, &rect_dsc, &area); 58 | } 59 | } 60 | 61 | lv_canvas_finish_layer(canvas, &layer); 62 | lv_obj_invalidate(canvas); 63 | bsp_display_unlock(); 64 | } 65 | 66 | static void update_grid() { 67 | for (int row = 0; row < GRID_SIZE; ++row) { 68 | for (int col = 0; col < GRID_SIZE; ++col) { 69 | int live_neighbors = 0; 70 | for (int i = -1; i <= 1; ++i) { 71 | for (int j = -1; j <= 1; ++j) { 72 | if (i == 0 && j == 0) continue; 73 | int r = row + i; 74 | int c = col + j; 75 | if (r >= 0 && r < GRID_SIZE && c >= 0 && c < GRID_SIZE) { 76 | live_neighbors += grid[r][c]; 77 | } 78 | } 79 | } 80 | 81 | if (grid[row][col]) { 82 | temp_grid[row][col] = live_neighbors == 2 || live_neighbors == 3; 83 | } else { 84 | temp_grid[row][col] = live_neighbors == 3; 85 | } 86 | } 87 | } 88 | 89 | for (int row = 0; row < GRID_SIZE; ++row) { 90 | for (int col = 0; col < GRID_SIZE; ++col) { 91 | grid[row][col] = temp_grid[row][col]; 92 | } 93 | } 94 | } 95 | 96 | static void life_task(void *param) { 97 | while (1) { 98 | vTaskDelay(pdMS_TO_TICKS(100)); 99 | update_grid(); 100 | draw_grid(); 101 | } 102 | } 103 | 104 | void reset_to_factory_app() { 105 | // Get the partition structure for the factory partition 106 | const esp_partition_t *factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); 107 | if (factory_partition != NULL) { 108 | if (esp_ota_set_boot_partition(factory_partition) == ESP_OK) { 109 | printf("Set boot partition to factory.\n"); 110 | } else { 111 | printf("Failed to set boot partition to factory.\n"); 112 | } 113 | } else { 114 | printf("Factory partition not found.\n"); 115 | } 116 | 117 | fflush(stdout); 118 | } 119 | 120 | void app_main(void) { 121 | // Reset to factory app for the next boot. 122 | // It should return to graphical bootloader. 123 | reset_to_factory_app(); 124 | 125 | // Initialize the BSP 126 | bsp_i2c_init(); 127 | bsp_display_start(); 128 | lv_init(); 129 | srand(time(NULL)); 130 | 131 | bsp_display_lock(0); 132 | 133 | LV_DRAW_BUF_DEFINE(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_RGB565); 134 | 135 | canvas = lv_canvas_create(lv_scr_act()); 136 | lv_canvas_set_draw_buf(canvas, &draw_buf); 137 | lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER); 138 | lv_obj_center(canvas); 139 | 140 | lv_canvas_init_layer(canvas, &layer); 141 | 142 | // Create a reset button 143 | lv_obj_t *reset_btn = lv_btn_create(lv_scr_act()); 144 | lv_obj_t *label = lv_label_create(reset_btn); 145 | lv_label_set_text(label, "Reset"); 146 | lv_obj_align(reset_btn, LV_ALIGN_BOTTOM_RIGHT, 0, -10); 147 | lv_obj_add_event_cb(reset_btn, reset_btn_event_cb, LV_EVENT_CLICKED, NULL); 148 | 149 | bsp_display_backlight_on(); 150 | bsp_display_unlock(); 151 | 152 | // Initialize grid 153 | randomize_grid(); 154 | printf("Grid initialized\n"); 155 | draw_grid(); 156 | printf("Grid drawn\n"); 157 | 158 | // Create the life task 159 | xTaskCreate(life_task, "life_task", 32768, NULL, 5, NULL); 160 | 161 | while (1) { 162 | vTaskDelay(pdMS_TO_TICKS(1000)); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /apps/game_of_life/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | espressif/esp-box-3: 4 | version: "^1.2.0" 5 | rules: 6 | - if: "target == ${USE_ESP_BOX_3}" 7 | espressif/esp-box: 8 | version: "3.1.0" 9 | rules: 10 | - if: "target == ${USE_ESP_BOX}" 11 | espressif/m5stack_core_s3: 12 | version: "1.1.1" 13 | rules: 14 | - if: "target == ${USE_M5STACK_CORE_S3}" 15 | espressif/esp32_p4_function_ev_board: 16 | version: "2.0.0" 17 | rules: 18 | - if: "target == ${USE_ESP32_P4_FUNCTION_EV_BOARD}" 19 | # Workaround for i2c: CONFLICT! driver_ng is not allowed to be used with this old driver 20 | esp_codec_dev: 21 | public: true 22 | version: "==1.1.0" 23 | ## Required IDF version 24 | idf: 25 | version: ">=5.0.0" -------------------------------------------------------------------------------- /apps/game_of_life/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/game_of_life/sdkconfig.defaults.esp-box: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/game_of_life/sdkconfig.defaults.esp-box-3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/game_of_life/sdkconfig.defaults.esp32_p4_function_ev_board: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32p4" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | #CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | 9 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 11 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 12 | CONFIG_SPIRAM=y 13 | CONFIG_SPIRAM_MODE_OCT=y 14 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y 15 | CONFIG_SPIRAM_RODATA=y 16 | CONFIG_SPIRAM_SPEED_80M=y 17 | CONFIG_FREERTOS_HZ=1000 18 | CONFIG_BSP_LCD_RGB_BUFFER_NUMS=2 19 | CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y 20 | CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR=y 21 | CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y 22 | CONFIG_SPIRAM_MODE_HEX=y 23 | CONFIG_SPIRAM_SPEED_200M=y 24 | CONFIG_IDF_EXPERIMENTAL_FEATURES=y 25 | 26 | ## LVGL9 ## 27 | CONFIG_LV_CONF_SKIP=y 28 | 29 | #CLIB default 30 | CONFIG_LV_USE_CLIB_MALLOC=y 31 | CONFIG_LV_USE_CLIB_SPRINTF=y 32 | CONFIG_LV_USE_CLIB_STRING=y 33 | 34 | -------------------------------------------------------------------------------- /apps/game_of_life/sdkconfig.defaults.m5stack_core_s3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_SPIRAM_MODE_QUAD=y 7 | -------------------------------------------------------------------------------- /apps/synth_piano/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following five lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.16) 4 | 5 | # Select board configuration based on -DBUILD_BOARD 6 | if(NOT DEFINED BUILD_BOARD) 7 | message(FATAL_ERROR "BUILD_BOARD CMake variable is not set") 8 | endif() 9 | 10 | set(ENV{USE_ESP_BOX} "0") 11 | set(ENV{USE_ESP_BOX_3} "0") 12 | set(ENV{USE_M5STACK_CORE_S3} "0") 13 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "0") 14 | 15 | if (BUILD_BOARD STREQUAL "esp-box") 16 | set(ENV{USE_ESP_BOX} "esp32s3") 17 | elseif (BUILD_BOARD STREQUAL "esp-box-3") 18 | set(ENV{USE_ESP_BOX_3} "esp32s3") 19 | elseif (BUILD_BOARD STREQUAL "m5stack_core_s3") 20 | set(ENV{USE_M5STACK_CORE_S3} "esp32s3") 21 | elseif (BUILD_BOARD STREQUAL "esp32_p4_function_ev_board") 22 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "esp32p4") 23 | endif() 24 | 25 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 26 | project(synth_piano) 27 | -------------------------------------------------------------------------------- /apps/synth_piano/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "synth_piano.c" 2 | INCLUDE_DIRS "." 3 | REQUIRES app_update) 4 | -------------------------------------------------------------------------------- /apps/synth_piano/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | espressif/esp-box-3: 4 | version: "^1.2.0" 5 | rules: 6 | - if: "target == ${USE_ESP_BOX_3}" 7 | espressif/esp-box: 8 | version: "3.1.0" 9 | rules: 10 | - if: "target == ${USE_ESP_BOX}" 11 | espressif/m5stack_core_s3: 12 | version: "1.1.1" 13 | rules: 14 | - if: "target == ${USE_M5STACK_CORE_S3}" 15 | espressif/esp32_p4_function_ev_board: 16 | version: "2.0.0" 17 | rules: 18 | - if: "target == ${USE_ESP32_P4_FUNCTION_EV_BOARD}" 19 | # Workaround for i2c: CONFLICT! driver_ng is not allowed to be used with this old driver 20 | esp_codec_dev: 21 | public: true 22 | version: "==1.1.0" 23 | ## Required IDF version 24 | idf: 25 | version: ">=5.0.0" -------------------------------------------------------------------------------- /apps/synth_piano/main/synth_piano.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "freertos/FreeRTOS.h" 4 | #include "freertos/task.h" 5 | #include "esp_log.h" 6 | #include "esp_system.h" 7 | #include "lvgl.h" 8 | #include "bsp/esp-bsp.h" 9 | #include "esp_timer.h" 10 | #include "driver/i2s.h" 11 | #include "esp_ota_ops.h" 12 | 13 | #define TAG "SynthPiano" 14 | #define SAMPLE_RATE 44100 15 | #define DEFAULT_VOLUME 90 16 | 17 | static lv_obj_t *octave_label; 18 | static int current_octave = 4; 19 | static int last_note_index = -1; 20 | static int last_octave_event = -1; 21 | static esp_codec_dev_handle_t spk_codec_dev = NULL; 22 | static QueueHandle_t tone_queue; 23 | 24 | typedef struct { 25 | float frequency; 26 | int duration_ms; 27 | } tone_t; 28 | 29 | static void update_display() { 30 | char buffer[16]; 31 | snprintf(buffer, sizeof(buffer), "Octave: %d", current_octave); 32 | bsp_display_lock(0); 33 | lv_label_set_text(octave_label, buffer); 34 | bsp_display_unlock(); 35 | } 36 | 37 | static void play_tone(float frequency, int duration_ms) { 38 | const int sample_rate = SAMPLE_RATE; 39 | const int num_samples = (sample_rate * duration_ms) / 1000; 40 | const float amplitude = 1.0; 41 | 42 | int16_t *samples = malloc(num_samples * sizeof(int16_t)); 43 | if (!samples) { 44 | ESP_LOGE(TAG, "Failed to allocate memory for samples"); 45 | return; 46 | } 47 | 48 | for (int i = 0; i < num_samples; ++i) { 49 | samples[i] = (int16_t)(amplitude * INT16_MAX * sinf(2.0f * M_PI * frequency * i / sample_rate)); 50 | } 51 | 52 | esp_codec_dev_write(spk_codec_dev, samples, num_samples * sizeof(int16_t)); 53 | vTaskDelay(pdMS_TO_TICKS(duration_ms)); // Ensure the tone plays for the specified duration 54 | 55 | free(samples); 56 | } 57 | 58 | static void tone_task(void *param) { 59 | tone_t tone; 60 | while (1) { 61 | if (xQueueReceive(tone_queue, &tone, portMAX_DELAY)) { 62 | play_tone(tone.frequency, tone.duration_ms); 63 | } 64 | } 65 | } 66 | 67 | static void note_event_cb(lv_event_t *e) { 68 | lv_obj_t *btn = lv_event_get_target(e); 69 | const char *txt = lv_btnmatrix_get_btn_text(btn, lv_btnmatrix_get_selected_btn(btn)); 70 | 71 | float frequencies[12] = { 72 | 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.00, 415.30, 440.00, 466.16, 493.88 73 | }; 74 | int note_index = atoi(txt); 75 | if (note_index == last_note_index) { 76 | return; // Ignore repeated events for the same note 77 | } 78 | last_note_index = note_index; 79 | 80 | if (note_index >= 0 && note_index < 12) { 81 | float frequency = frequencies[note_index] * powf(2.0f, current_octave - 4); 82 | tone_t tone = { .frequency = frequency, .duration_ms = 250 }; 83 | xQueueSend(tone_queue, &tone, portMAX_DELAY); // Send tone to queue 84 | } 85 | } 86 | 87 | static void octave_event_cb(lv_event_t *e) { 88 | lv_obj_t *btn = lv_event_get_target(e); 89 | const char *txt = lv_btnmatrix_get_btn_text(btn, lv_btnmatrix_get_selected_btn(btn)); 90 | 91 | if ((last_octave_event == 0 && strcmp(txt, "Up") == 0) || (last_octave_event == 1 && strcmp(txt, "Down") == 0)) { 92 | return; // Ignore repeated events for the same octave button 93 | } 94 | 95 | if (strcmp(txt, "Up") == 0) { 96 | last_octave_event = 0; 97 | current_octave = (current_octave < 8) ? current_octave + 1 : current_octave; 98 | } else if (strcmp(txt, "Down") == 0) { 99 | last_octave_event = 1; 100 | current_octave = (current_octave > 0) ? current_octave - 1 : current_octave; 101 | } 102 | update_display(); 103 | } 104 | 105 | void app_audio_init(void) 106 | { 107 | /* Initialize speaker */ 108 | spk_codec_dev = bsp_audio_codec_speaker_init(); 109 | assert(spk_codec_dev); 110 | /* Speaker output volume */ 111 | esp_codec_dev_set_out_vol(spk_codec_dev, DEFAULT_VOLUME); 112 | 113 | esp_codec_dev_open(spk_codec_dev, &(esp_codec_dev_sample_info_t){ 114 | .sample_rate = SAMPLE_RATE, 115 | .channel = 1, 116 | .bits_per_sample = 16, 117 | }); 118 | } 119 | 120 | void reset_to_factory_app() { 121 | // Get the partition structure for the factory partition 122 | const esp_partition_t *factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); 123 | if (factory_partition != NULL) { 124 | if (esp_ota_set_boot_partition(factory_partition) == ESP_OK) { 125 | printf("Set boot partition to factory.\n"); 126 | } else { 127 | printf("Failed to set boot partition to factory.\n"); 128 | } 129 | } else { 130 | printf("Factory partition not found.\n"); 131 | } 132 | 133 | fflush(stdout); 134 | } 135 | 136 | void app_main(void) { 137 | // Reset to factory app for the next boot. 138 | // It should return to graphical bootloader. 139 | reset_to_factory_app(); 140 | 141 | // Initialize the BSP 142 | bsp_i2c_init(); 143 | bsp_display_start(); 144 | lv_init(); 145 | app_audio_init(); 146 | 147 | // Create a label for the octave 148 | octave_label = lv_label_create(lv_scr_act()); 149 | lv_label_set_text(octave_label, "Octave: 4"); 150 | lv_obj_align(octave_label, LV_ALIGN_TOP_LEFT, 0, 10); 151 | 152 | // Create a button matrix for the octave control 153 | static const char *octave_map[] = { 154 | "Up", "\n", 155 | "Down", "" 156 | }; 157 | 158 | lv_obj_t *octave_btnm = lv_btnmatrix_create(lv_scr_act()); 159 | lv_btnmatrix_set_map(octave_btnm, octave_map); 160 | lv_obj_set_size(octave_btnm, 150, 60); 161 | lv_obj_align(octave_btnm, LV_ALIGN_TOP_RIGHT, 0, 0); 162 | lv_obj_add_event_cb(octave_btnm, octave_event_cb, LV_EVENT_VALUE_CHANGED, NULL); 163 | 164 | // Create a button matrix for the notes 165 | static const char *note_map[] = { 166 | "0", "1", "2", "3", "\n", 167 | "4", "5", "6", "7", "\n", 168 | "8", "9", "10", "11", "" 169 | }; 170 | 171 | lv_obj_t *note_btnm = lv_btnmatrix_create(lv_scr_act()); 172 | lv_btnmatrix_set_map(note_btnm, note_map); 173 | lv_obj_set_size(note_btnm, 320, 150); 174 | lv_obj_align(note_btnm, LV_ALIGN_CENTER, 0, 30); 175 | lv_obj_add_event_cb(note_btnm, note_event_cb, LV_EVENT_VALUE_CHANGED, NULL); 176 | 177 | // Create the tone queue 178 | tone_queue = xQueueCreate(10, sizeof(tone_t)); 179 | assert(tone_queue != NULL); 180 | 181 | // Create the tone task 182 | xTaskCreate(tone_task, "tone_task", 2048, NULL, 5, NULL); 183 | 184 | bsp_display_backlight_on(); 185 | 186 | while (1) { 187 | vTaskDelay(pdMS_TO_TICKS(1000)); 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /apps/synth_piano/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/synth_piano/sdkconfig.defaults.esp-box: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/synth_piano/sdkconfig.defaults.esp-box-3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/synth_piano/sdkconfig.defaults.esp32_p4_function_ev_board: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32p4" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | #CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | 9 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 11 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 12 | CONFIG_SPIRAM=y 13 | CONFIG_SPIRAM_MODE_OCT=y 14 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y 15 | CONFIG_SPIRAM_RODATA=y 16 | CONFIG_SPIRAM_SPEED_80M=y 17 | CONFIG_FREERTOS_HZ=1000 18 | CONFIG_BSP_LCD_RGB_BUFFER_NUMS=2 19 | CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y 20 | CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR=y 21 | CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y 22 | CONFIG_SPIRAM_MODE_HEX=y 23 | CONFIG_SPIRAM_SPEED_200M=y 24 | CONFIG_IDF_EXPERIMENTAL_FEATURES=y 25 | 26 | ## LVGL9 ## 27 | CONFIG_LV_CONF_SKIP=y 28 | 29 | #CLIB default 30 | CONFIG_LV_USE_CLIB_MALLOC=y 31 | CONFIG_LV_USE_CLIB_SPRINTF=y 32 | CONFIG_LV_USE_CLIB_STRING=y 33 | 34 | -------------------------------------------------------------------------------- /apps/synth_piano/sdkconfig.defaults.m5stack_core_s3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_SPIRAM_MODE_QUAD=y 7 | -------------------------------------------------------------------------------- /apps/tic_tac_toe/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following five lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.16) 4 | 5 | # Select board configuration based on -DBUILD_BOARD 6 | if(NOT DEFINED BUILD_BOARD) 7 | message(FATAL_ERROR "BUILD_BOARD CMake variable is not set") 8 | endif() 9 | 10 | set(ENV{USE_ESP_BOX} "0") 11 | set(ENV{USE_ESP_BOX_3} "0") 12 | set(ENV{USE_M5STACK_CORE_S3} "0") 13 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "0") 14 | 15 | if (BUILD_BOARD STREQUAL "esp-box") 16 | set(ENV{USE_ESP_BOX} "esp32s3") 17 | elseif (BUILD_BOARD STREQUAL "esp-box-3") 18 | set(ENV{USE_ESP_BOX_3} "esp32s3") 19 | elseif (BUILD_BOARD STREQUAL "m5stack_core_s3") 20 | set(ENV{USE_M5STACK_CORE_S3} "esp32s3") 21 | elseif (BUILD_BOARD STREQUAL "esp32_p4_function_ev_board") 22 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "esp32p4") 23 | endif() 24 | 25 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 26 | project(tic_tac_toe) 27 | -------------------------------------------------------------------------------- /apps/tic_tac_toe/diagram.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "author": "Uri Shaked", 4 | "editor": "wokwi", 5 | "parts": [ 6 | { 7 | "type": "board-esp32-s3-box-3", 8 | "id": "esp32", 9 | "top": -24.91, 10 | "left": -388.54, 11 | "attrs": { "psramSize": "16", "flashSize": "16" } 12 | } 13 | ], 14 | "connections": [ [ "$serialMonitor:RX", "esp32:G43", "", [] ], [ "$serialMonitor:TX", "esp32:G44", "", [] ] ], 15 | "dependencies": {} 16 | } -------------------------------------------------------------------------------- /apps/tic_tac_toe/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "tic_tac_toe.c" 2 | INCLUDE_DIRS "." 3 | REQUIRES app_update) 4 | -------------------------------------------------------------------------------- /apps/tic_tac_toe/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | espressif/esp-box-3: 4 | version: "^1.2.0" 5 | rules: 6 | - if: "target == ${USE_ESP_BOX_3}" 7 | espressif/esp-box: 8 | version: "3.1.0" 9 | rules: 10 | - if: "target == ${USE_ESP_BOX}" 11 | espressif/m5stack_core_s3: 12 | version: "1.1.1" 13 | rules: 14 | - if: "target == ${USE_M5STACK_CORE_S3}" 15 | espressif/esp32_p4_function_ev_board: 16 | version: "2.0.0" 17 | rules: 18 | - if: "target == ${USE_ESP32_P4_FUNCTION_EV_BOARD}" 19 | # Workaround for i2c: CONFLICT! driver_ng is not allowed to be used with this old driver 20 | esp_codec_dev: 21 | public: true 22 | version: "==1.1.0" 23 | ## Required IDF version 24 | idf: 25 | version: ">=5.0.0" -------------------------------------------------------------------------------- /apps/tic_tac_toe/main/tic_tac_toe.c: -------------------------------------------------------------------------------- 1 | #include "freertos/FreeRTOS.h" 2 | #include "freertos/task.h" 3 | #include "freertos/semphr.h" 4 | #include "esp_system.h" 5 | #include "esp_log.h" 6 | #include "lvgl.h" 7 | #include "bsp/esp-bsp.h" 8 | #include "esp_ota_ops.h" 9 | 10 | #define TAG "TicTacToe" 11 | 12 | static lv_obj_t *btn_grid[3][3]; 13 | static char board[3][3]; 14 | static bool player_turn = true; // true for 'X', false for 'O' 15 | 16 | static void reset_game() { 17 | bsp_display_lock(0); 18 | memset(board, 0, sizeof(board)); 19 | for (int row = 0; row < 3; ++row) { 20 | for (int col = 0; col < 3; ++col) { 21 | lv_obj_t *btn = btn_grid[row][col]; 22 | lv_label_set_text(lv_obj_get_child(btn, 0), ""); 23 | lv_obj_clear_state(btn, LV_STATE_DISABLED); 24 | } 25 | } 26 | player_turn = true; 27 | bsp_display_unlock(); 28 | } 29 | 30 | static void close_message_box(lv_timer_t *timer) { 31 | lv_obj_t *msg_box = (lv_obj_t *)lv_timer_get_user_data(timer); 32 | bsp_display_lock(0); 33 | lv_msgbox_close(msg_box); 34 | lv_timer_delete(timer); 35 | bsp_display_unlock(); 36 | reset_game(); 37 | } 38 | 39 | static void show_message(const char *text) { 40 | ESP_LOGI(TAG, "%s", text); 41 | bsp_display_lock(0); 42 | lv_obj_t *msg_box = lv_msgbox_create(NULL); 43 | lv_msgbox_add_text(msg_box, text); 44 | lv_obj_center(msg_box); 45 | lv_timer_create(close_message_box, 2000, msg_box); 46 | bsp_display_unlock(); 47 | } 48 | 49 | static bool check_winner(char player) { 50 | for (int i = 0; i < 3; ++i) { 51 | // Check rows 52 | if (board[i][0] == player && board[i][1] == player && board[i][2] == player) 53 | return true; 54 | // Check columns 55 | if (board[0][i] == player && board[1][i] == player && board[2][i] == player) 56 | return true; 57 | } 58 | // Check diagonals 59 | if (board[0][0] == player && board[1][1] == player && board[2][2] == player) 60 | return true; 61 | if (board[0][2] == player && board[1][1] == player && board[2][0] == player) 62 | return true; 63 | return false; 64 | } 65 | 66 | static void event_handler(lv_event_t *e) { 67 | lv_event_code_t code = lv_event_get_code(e); 68 | lv_obj_t *btn = lv_event_get_target(e); 69 | 70 | if (code == LV_EVENT_CLICKED) { 71 | bsp_display_lock(0); 72 | uint32_t id = (uint32_t)lv_event_get_user_data(e); 73 | uint8_t row = id / 3; 74 | uint8_t col = id % 3; 75 | if (board[row][col] == 0) { 76 | board[row][col] = player_turn ? 'X' : 'O'; 77 | lv_label_set_text(lv_obj_get_child(btn, 0), player_turn ? "X" : "O"); 78 | lv_obj_add_state(btn, LV_STATE_DISABLED); // Disable the button after being clicked 79 | 80 | if (check_winner(player_turn ? 'X' : 'O')) { 81 | show_message(player_turn ? "Player X wins!" : "Player O wins!"); 82 | } else if (memchr(board, 0, sizeof(board)) == NULL) { 83 | show_message("It's a draw!"); 84 | } else { 85 | player_turn = !player_turn; 86 | } 87 | } 88 | bsp_display_unlock(); 89 | } 90 | } 91 | 92 | void reset_to_factory_app() { 93 | // Get the partition structure for the factory partition 94 | const esp_partition_t *factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); 95 | if (factory_partition != NULL) { 96 | if (esp_ota_set_boot_partition(factory_partition) == ESP_OK) { 97 | printf("Set boot partition to factory.\n"); 98 | } else { 99 | printf("Failed to set boot partition to factory.\n"); 100 | } 101 | } else { 102 | printf("Factory partition not found.\n"); 103 | } 104 | 105 | fflush(stdout); 106 | } 107 | 108 | void app_main(void) { 109 | // Reset to factory app for the next boot. 110 | // It should return to graphical bootloader. 111 | reset_to_factory_app(); 112 | 113 | // Initialize the BSP 114 | bsp_i2c_init(); 115 | bsp_display_start(); 116 | 117 | bsp_display_lock(0); 118 | // Create a grid for buttons 119 | lv_obj_t *grid = lv_obj_create(lv_scr_act()); 120 | static lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; 121 | static lv_coord_t row_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; 122 | lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc); 123 | lv_obj_set_size(grid, 240, 240); 124 | lv_obj_align(grid, LV_ALIGN_CENTER, 0, 0); 125 | 126 | for (int row = 0; row < 3; ++row) { 127 | for (int col = 0; col < 3; ++col) { 128 | lv_obj_t *btn = lv_btn_create(grid); 129 | lv_obj_set_grid_cell(btn, LV_GRID_ALIGN_STRETCH, col, 1, LV_GRID_ALIGN_STRETCH, row, 1); 130 | lv_obj_t *label = lv_label_create(btn); 131 | lv_label_set_text(label, ""); 132 | lv_obj_center(label); 133 | lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, (void *)(row * 3 + col)); 134 | btn_grid[row][col] = btn; 135 | } 136 | } 137 | bsp_display_unlock(); 138 | 139 | bsp_display_backlight_on(); 140 | 141 | reset_game(); 142 | 143 | while (1) { 144 | vTaskDelay(pdMS_TO_TICKS(1000)); // Add a small delay to prevent watchdog issues 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /apps/tic_tac_toe/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/tic_tac_toe/sdkconfig.defaults.esp-box: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/tic_tac_toe/sdkconfig.defaults.esp-box-3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | -------------------------------------------------------------------------------- /apps/tic_tac_toe/sdkconfig.defaults.esp32_p4_function_ev_board: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32p4" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | #CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | 9 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 11 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 12 | CONFIG_SPIRAM=y 13 | CONFIG_SPIRAM_MODE_OCT=y 14 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y 15 | CONFIG_SPIRAM_RODATA=y 16 | CONFIG_SPIRAM_SPEED_80M=y 17 | CONFIG_FREERTOS_HZ=1000 18 | CONFIG_BSP_LCD_RGB_BUFFER_NUMS=2 19 | CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y 20 | CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR=y 21 | CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y 22 | CONFIG_SPIRAM_MODE_HEX=y 23 | CONFIG_SPIRAM_SPEED_200M=y 24 | CONFIG_IDF_EXPERIMENTAL_FEATURES=y 25 | 26 | ## LVGL9 ## 27 | CONFIG_LV_CONF_SKIP=y 28 | 29 | #CLIB default 30 | CONFIG_LV_USE_CLIB_MALLOC=y 31 | CONFIG_LV_USE_CLIB_SPRINTF=y 32 | CONFIG_LV_USE_CLIB_STRING=y 33 | 34 | -------------------------------------------------------------------------------- /apps/tic_tac_toe/sdkconfig.defaults.m5stack_core_s3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_SPIRAM_MODE_QUAD=y -------------------------------------------------------------------------------- /apps/tic_tac_toe/wokwi.toml: -------------------------------------------------------------------------------- 1 | [wokwi] 2 | version = 1 3 | elf = "build/uf2.bin" 4 | firmware = "build/uf2.bin" 5 | 6 | -------------------------------------------------------------------------------- /apps/wifi_list/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following five lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.16) 4 | 5 | # Select board configuration based on -DBUILD_BOARD 6 | if(NOT DEFINED BUILD_BOARD) 7 | message(FATAL_ERROR "BUILD_BOARD CMake variable is not set") 8 | endif() 9 | 10 | set(ENV{USE_ESP_BOX} "0") 11 | set(ENV{USE_ESP_BOX_3} "0") 12 | set(ENV{USE_M5STACK_CORE_S3} "0") 13 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "0") 14 | 15 | if (BUILD_BOARD STREQUAL "esp-box") 16 | set(ENV{USE_ESP_BOX} "esp32s3") 17 | elseif (BUILD_BOARD STREQUAL "esp-box-3") 18 | set(ENV{USE_ESP_BOX_3} "esp32s3") 19 | elseif (BUILD_BOARD STREQUAL "m5stack_core_s3") 20 | set(ENV{USE_M5STACK_CORE_S3} "esp32s3") 21 | elseif (BUILD_BOARD STREQUAL "esp32_p4_function_ev_board") 22 | set(ENV{USE_ESP32_P4_FUNCTION_EV_BOARD} "esp32p4") 23 | endif() 24 | 25 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 26 | project(wifi_list) 27 | -------------------------------------------------------------------------------- /apps/wifi_list/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "wifi_list.c" 2 | INCLUDE_DIRS "." 3 | REQUIRES app_update esp_wifi nvs_flash) 4 | -------------------------------------------------------------------------------- /apps/wifi_list/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | espressif/esp-box-3: 4 | version: "^1.2.0" 5 | rules: 6 | - if: "target == ${USE_ESP_BOX_3}" 7 | espressif/esp-box: 8 | version: "3.1.0" 9 | rules: 10 | - if: "target == ${USE_ESP_BOX}" 11 | espressif/m5stack_core_s3: 12 | version: "1.1.1" 13 | rules: 14 | - if: "target == ${USE_M5STACK_CORE_S3}" 15 | espressif/esp32_p4_function_ev_board: 16 | version: "2.0.0" 17 | rules: 18 | - if: "target == ${USE_ESP32_P4_FUNCTION_EV_BOARD}" 19 | # Workaround for i2c: CONFLICT! driver_ng is not allowed to be used with this old driver 20 | esp_codec_dev: 21 | public: true 22 | version: "==1.1.0" 23 | ## Required IDF version 24 | idf: 25 | version: ">=5.0.0" -------------------------------------------------------------------------------- /apps/wifi_list/main/wifi_list.c: -------------------------------------------------------------------------------- 1 | #include "freertos/FreeRTOS.h" 2 | #include "freertos/task.h" 3 | #include "freertos/semphr.h" 4 | #include "esp_system.h" 5 | #include "esp_log.h" 6 | #include "lvgl.h" 7 | #include "bsp/esp-bsp.h" 8 | #include "esp_wifi.h" 9 | #include "esp_event.h" 10 | #include "nvs_flash.h" 11 | #include "esp_ota_ops.h" 12 | 13 | #define TAG "WiFiList" 14 | #define DEFAULT_SCAN_LIST_SIZE 32 15 | 16 | static lv_obj_t *list; 17 | static bool scan_in_progress = false; 18 | static lv_obj_t *search_msg_box = NULL; 19 | 20 | static void list_wifi(); 21 | static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data); 22 | 23 | static void close_message_box() { 24 | if (search_msg_box) { 25 | bsp_display_lock(0); 26 | lv_msgbox_close(search_msg_box); 27 | bsp_display_unlock(); 28 | search_msg_box = NULL; 29 | } 30 | } 31 | 32 | static void show_message(const char *text) { 33 | ESP_LOGI(TAG, "%s", text); 34 | bsp_display_lock(0); 35 | search_msg_box = lv_msgbox_create(NULL); 36 | lv_msgbox_add_text(search_msg_box, text); 37 | lv_obj_center(search_msg_box); 38 | bsp_display_unlock(); 39 | } 40 | 41 | void list_wifi() { 42 | if (scan_in_progress) { 43 | ESP_LOGW(TAG, "Scan already in progress"); 44 | return; 45 | } 46 | 47 | wifi_scan_config_t scan_config = { 48 | .ssid = NULL, 49 | .bssid = NULL, 50 | .channel = 0, 51 | .show_hidden = false, // Disable hidden networks 52 | .scan_type = WIFI_SCAN_TYPE_ACTIVE, 53 | .scan_time = { .active = { .min = 500, .max = 1500 } } // Increased scan times 54 | }; 55 | 56 | esp_err_t err = esp_wifi_scan_start(&scan_config, false); 57 | if (err != ESP_OK) { 58 | ESP_LOGE(TAG, "Failed to start WiFi scan: %s", esp_err_to_name(err)); 59 | return; 60 | } 61 | 62 | scan_in_progress = true; 63 | } 64 | 65 | void handle_scan_done() { 66 | uint16_t ap_count = 0; 67 | 68 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count)); 69 | printf("Found %d access points\n", ap_count); 70 | 71 | wifi_ap_record_t *ap_records = (wifi_ap_record_t *)malloc(sizeof(wifi_ap_record_t) * ap_count); 72 | if (ap_records == NULL) { 73 | ESP_LOGE(TAG, "Failed to allocate memory for AP records"); 74 | scan_in_progress = false; 75 | return; 76 | } 77 | 78 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_count, ap_records)); 79 | printf("Scan done\n"); 80 | 81 | bsp_display_lock(0); 82 | // Clear the current list items 83 | while (lv_obj_get_child_cnt(list) > 0) { 84 | lv_obj_del(lv_obj_get_child(list, 0)); 85 | } 86 | 87 | // Add new list items 88 | for (int i = 0; i < ap_count; i++) { 89 | char buffer[128]; 90 | snprintf(buffer, sizeof(buffer), "%s (%d)", ap_records[i].ssid, ap_records[i].rssi); 91 | lv_list_add_text(list, buffer); 92 | } 93 | bsp_display_unlock(); 94 | 95 | free(ap_records); 96 | scan_in_progress = false; 97 | 98 | close_message_box(); // Close the "Searching..." message box after scan is done 99 | } 100 | 101 | void reset_to_factory_app() { 102 | // Get the partition structure for the factory partition 103 | const esp_partition_t *factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); 104 | if (factory_partition != NULL) { 105 | if (esp_ota_set_boot_partition(factory_partition) == ESP_OK) { 106 | printf("Set boot partition to factory.\n"); 107 | } else { 108 | printf("Failed to set boot partition to factory.\n"); 109 | } 110 | } else { 111 | printf("Factory partition not found.\n"); 112 | } 113 | 114 | fflush(stdout); 115 | } 116 | 117 | void app_main(void) { 118 | // Reset to factory app for the next boot. 119 | // It should return to graphical bootloader. 120 | reset_to_factory_app(); 121 | 122 | // Initialize the BSP 123 | bsp_i2c_init(); 124 | bsp_display_start(); 125 | lv_init(); 126 | 127 | // Initialize NVS 128 | esp_err_t ret = nvs_flash_init(); 129 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { 130 | ESP_ERROR_CHECK(nvs_flash_erase()); 131 | ret = nvs_flash_init(); 132 | } 133 | ESP_ERROR_CHECK(ret); 134 | 135 | // Initialize the network interface 136 | ESP_ERROR_CHECK(esp_netif_init()); 137 | 138 | // Initialize the event loop 139 | ESP_ERROR_CHECK(esp_event_loop_create_default()); 140 | 141 | // Initialize WiFi 142 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); 143 | ESP_ERROR_CHECK(esp_wifi_init(&cfg)); 144 | 145 | ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_SCAN_DONE, &wifi_event_handler, NULL)); 146 | ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); 147 | ESP_ERROR_CHECK(esp_wifi_start()); 148 | 149 | // Create a label for WiFi list title 150 | bsp_display_lock(0); 151 | lv_obj_t *label = lv_label_create(lv_scr_act()); 152 | lv_label_set_text(label, "List of Wi-Fi networks"); 153 | lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 10); 154 | 155 | // Create a list for WiFi networks 156 | list = lv_list_create(lv_scr_act()); 157 | lv_obj_set_size(list, 300, 180); // Adjust height to leave space for the label 158 | lv_obj_align(list, LV_ALIGN_CENTER, 0, 20); 159 | bsp_display_unlock(); 160 | 161 | bsp_display_backlight_on(); 162 | 163 | show_message("Searching..."); // Show the "Searching..." message at the start 164 | 165 | while (1) { 166 | list_wifi(); 167 | vTaskDelay(pdMS_TO_TICKS(60000)); // Refresh every 60 seconds 168 | } 169 | } 170 | 171 | static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { 172 | if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE) { 173 | handle_scan_done(); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /apps/wifi_list/partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, Subtype, Offset, Size, Flags 2 | nvs, data, nvs, 0x9000, 24K, 3 | otadata, data, ota, , 8K, 4 | phy_init, data, phy, , 4K, 5 | factory, app, factory, , 2M, 6 | 7 | -------------------------------------------------------------------------------- /apps/wifi_list/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_SPIRAM=y 8 | CONFIG_SPIRAM_MODE_OCT=y 9 | CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=42 10 | CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=16384 11 | CONFIG_ESP_MAIN_TASK_STACK_SIZE=16384 12 | -------------------------------------------------------------------------------- /apps/wifi_list/sdkconfig.defaults.esp-box: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_SPIRAM=y 8 | CONFIG_SPIRAM_MODE_OCT=y 9 | CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=42 10 | CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=16384 11 | CONFIG_ESP_MAIN_TASK_STACK_SIZE=16384 12 | -------------------------------------------------------------------------------- /apps/wifi_list/sdkconfig.defaults.esp-box-3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_SPIRAM=y 8 | CONFIG_SPIRAM_MODE_OCT=y 9 | CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=42 10 | CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=16384 11 | CONFIG_ESP_MAIN_TASK_STACK_SIZE=16384 12 | -------------------------------------------------------------------------------- /apps/wifi_list/sdkconfig.defaults.esp32_p4_function_ev_board: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32p4" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | 9 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 11 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 12 | CONFIG_SPIRAM=y 13 | CONFIG_SPIRAM_MODE_OCT=y 14 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y 15 | CONFIG_SPIRAM_RODATA=y 16 | CONFIG_SPIRAM_SPEED_80M=y 17 | CONFIG_FREERTOS_HZ=1000 18 | CONFIG_BSP_LCD_RGB_BUFFER_NUMS=2 19 | CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y 20 | CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR=y 21 | CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y 22 | CONFIG_SPIRAM_MODE_HEX=y 23 | CONFIG_SPIRAM_SPEED_200M=y 24 | CONFIG_IDF_EXPERIMENTAL_FEATURES=y 25 | 26 | ## LVGL9 ## 27 | CONFIG_LV_CONF_SKIP=y 28 | 29 | #CLIB default 30 | CONFIG_LV_USE_CLIB_MALLOC=y 31 | CONFIG_LV_USE_CLIB_SPRINTF=y 32 | CONFIG_LV_USE_CLIB_STRING=y 33 | 34 | -------------------------------------------------------------------------------- /apps/wifi_list/sdkconfig.defaults.m5stack_core_s3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM= 7 | CONFIG_SPIRAM_MODE_QUAD=y 8 | -------------------------------------------------------------------------------- /boards/esp-box-3.cfg: -------------------------------------------------------------------------------- 1 | -DSDKCONFIG_DEFAULTS="sdkconfig.defaults.esp-box-3;sdkconfig.defaults" -DBUILD_BOARD="esp-box-3" -B build.esp-box-3 2 | -------------------------------------------------------------------------------- /boards/esp-box.cfg: -------------------------------------------------------------------------------- 1 | -DSDKCONFIG_DEFAULTS="sdkconfig.defaults.esp-box;sdkconfig.defaults" -DBUILD_BOARD="esp-box" -B build.esp-box 2 | -------------------------------------------------------------------------------- /boards/esp32_p4_function_ev_board.cfg: -------------------------------------------------------------------------------- 1 | -DSDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32_p4_function_ev_board;sdkconfig.defaults" -DBUILD_BOARD="esp32_p4_function_ev_board" -B build.esp32_p4_function_ev_board 2 | -------------------------------------------------------------------------------- /boards/m5stack_core_s3.cfg: -------------------------------------------------------------------------------- 1 | -DSDKCONFIG_DEFAULTS="sdkconfig.defaults.m5stack_core_s3;sdkconfig.defaults" -DBUILD_BOARD="m5stack_core_s3" -B build.m5stack_core_s3 2 | -------------------------------------------------------------------------------- /diagram.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "author": "Uri Shaked", 4 | "editor": "wokwi", 5 | "parts": [ 6 | { 7 | "type": "board-esp32-s3-box-3", 8 | "id": "esp32", 9 | "top": -24.91, 10 | "left": -388.54, 11 | "attrs": { "psramSize": "16", "flashSize": "16" } 12 | } 13 | ], 14 | "connections": [ [ "$serialMonitor:RX", "esp32:G43", "", [] ], [ "$serialMonitor:TX", "esp32:G44", "", [] ] ], 15 | "dependencies": {} 16 | } 17 | -------------------------------------------------------------------------------- /doc/esp32-s3-box-3-graphical-bootloader.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/georgik/esp32-graphical-bootloader/993df0fa6c498fcb3dfc463c13ccd4c1395f1e72/doc/esp32-s3-box-3-graphical-bootloader.webp -------------------------------------------------------------------------------- /esp-launchpad.toml: -------------------------------------------------------------------------------- 1 | esp_toml_version = 1.0 2 | firmware_images_url = "https://github.com/georgik/esp32-graphical-bootloader/releases/download/v0.3/" 3 | supported_apps = ["esp32-graphical-bootloader-esp32-box"] 4 | 5 | [esp32-graphical-bootloader-esp32-box] 6 | image.esp32s3 = "graphical-bootloader-esp32-box.bin" 7 | android_app_url = "" 8 | ios_app_url = "" 9 | chipsets = ["esp32s3"] 10 | -------------------------------------------------------------------------------- /main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS 2 | "bootloader_ui.c" 3 | "graphical_bootloader_main.c" 4 | 5 | INCLUDE_DIRS 6 | ".") 7 | 8 | lvgl_port_create_c_image("../resources/images/icon_tic_tac_toe.png" "images/gen/" "ARGB8888" "NONE") 9 | lvgl_port_create_c_image("../resources/images/icon_wifi_list.png" "images/gen/" "ARGB8888" "NONE") 10 | lvgl_port_create_c_image("../resources/images/icon_calculator.png" "images/gen/" "ARGB8888" "NONE") 11 | lvgl_port_create_c_image("../resources/images/icon_synth_piano.png" "images/gen/" "ARGB8888" "NONE") 12 | lvgl_port_create_c_image("../resources/images/icon_game_of_life.png" "images/gen/" "ARGB8888" "NONE") 13 | 14 | lvgl_port_add_images(${COMPONENT_LIB} "images/gen/") 15 | -------------------------------------------------------------------------------- /main/bootloader_ui.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "lvgl.h" 4 | #include "esp_log.h" 5 | #include "esp_ota_ops.h" 6 | #include "esp_system.h" 7 | #include "bsp/esp-bsp.h" 8 | #include "esp_timer.h" 9 | 10 | typedef struct { 11 | lv_obj_t *scr; 12 | int count_val; 13 | } my_timer_context_t; 14 | 15 | typedef struct { 16 | lv_style_t style; 17 | lv_style_t style_focus_no_outline; 18 | lv_style_t style_focus; 19 | lv_style_t style_pr; 20 | } button_style_t; 21 | 22 | typedef struct { 23 | char *name; 24 | void *img_src; 25 | void (*start_fn)(void (*fn)(void)); 26 | void (*end_fn)(void); 27 | } item_desc_t; 28 | 29 | static const char *TAG = "bootloader_ui"; 30 | 31 | LV_FONT_DECLARE(font_icon_16); 32 | 33 | static int g_item_index = 0; 34 | static lv_group_t *g_btn_op_group = NULL; 35 | static button_style_t g_btn_styles; 36 | static lv_obj_t *g_page_menu = NULL; 37 | static int64_t last_btn_press_time = 0; 38 | 39 | static lv_obj_t *g_focus_last_obj = NULL; 40 | static lv_obj_t *g_group_list[3] = {0}; 41 | 42 | LV_IMG_DECLARE(icon_tic_tac_toe) 43 | LV_IMG_DECLARE(icon_wifi_list) 44 | LV_IMG_DECLARE(icon_calculator) 45 | LV_IMG_DECLARE(icon_synth_piano) 46 | LV_IMG_DECLARE(icon_game_of_life) 47 | 48 | void ui_app1_start(void (*fn)(void)); 49 | void ui_app2_start(void (*fn)(void)); 50 | void ui_app3_start(void (*fn)(void)); 51 | void ui_app4_start(void (*fn)(void)); 52 | void ui_app5_start(void (*fn)(void)); 53 | 54 | static item_desc_t item[] = { 55 | { "Tic-Tac-Toe", (void *) &icon_tic_tac_toe, ui_app1_start, NULL}, 56 | { "Wi-Fi List", (void *) &icon_wifi_list, ui_app2_start, NULL}, 57 | { "Calculator", (void *) &icon_calculator, ui_app3_start, NULL}, 58 | { "Piano", (void *) &icon_synth_piano, ui_app4_start, NULL}, 59 | { "Game of Life", (void *) &icon_game_of_life, ui_app5_start, NULL}, 60 | }; 61 | 62 | static lv_obj_t *g_img_btn, *g_img_item = NULL; 63 | static lv_obj_t *g_lab_item = NULL; 64 | static lv_obj_t *g_led_item[5]; 65 | static size_t g_item_size = sizeof(item) / sizeof(item[0]); 66 | static lv_obj_t *g_status_bar = NULL; 67 | 68 | static uint32_t menu_get_num_offset(uint32_t focus, int32_t max, int32_t offset) 69 | { 70 | if (focus >= max) { 71 | ESP_LOGI(TAG, "[ERROR] focus should less than max"); 72 | return focus; 73 | } 74 | 75 | uint32_t i; 76 | if (offset >= 0) { 77 | i = (focus + offset) % max; 78 | } else { 79 | offset = max + (offset % max); 80 | i = (focus + offset) % max; 81 | } 82 | return i; 83 | } 84 | 85 | 86 | lv_obj_t *ui_main_get_status_bar(void) 87 | { 88 | return g_status_bar; 89 | } 90 | 91 | button_style_t *ui_button_styles(void) 92 | { 93 | return &g_btn_styles; 94 | } 95 | 96 | lv_group_t *ui_get_btn_op_group(void) 97 | { 98 | return g_btn_op_group; 99 | } 100 | 101 | static void ui_button_style_init(void) 102 | { 103 | /*Init the style for the default state*/ 104 | 105 | lv_style_init(&g_btn_styles.style); 106 | 107 | lv_style_set_radius(&g_btn_styles.style, 5); 108 | 109 | lv_style_set_bg_color(&g_btn_styles.style, lv_color_make(255, 255, 255)); 110 | 111 | lv_style_set_border_opa(&g_btn_styles.style, LV_OPA_30); 112 | lv_style_set_border_width(&g_btn_styles.style, 2); 113 | lv_style_set_border_color(&g_btn_styles.style, lv_palette_main(LV_PALETTE_GREY)); 114 | 115 | lv_style_set_shadow_width(&g_btn_styles.style, 7); 116 | lv_style_set_shadow_color(&g_btn_styles.style, lv_color_make(0, 0, 0)); 117 | lv_style_set_shadow_ofs_x(&g_btn_styles.style, 0); 118 | lv_style_set_shadow_ofs_y(&g_btn_styles.style, 0); 119 | 120 | /*Init the pressed style*/ 121 | 122 | lv_style_init(&g_btn_styles.style_pr); 123 | 124 | lv_style_set_border_opa(&g_btn_styles.style_pr, LV_OPA_40); 125 | lv_style_set_border_width(&g_btn_styles.style_pr, 2); 126 | lv_style_set_border_color(&g_btn_styles.style_pr, lv_palette_main(LV_PALETTE_GREY)); 127 | 128 | 129 | lv_style_init(&g_btn_styles.style_focus); 130 | lv_style_set_outline_color(&g_btn_styles.style_focus, lv_color_make(255, 0, 0)); 131 | 132 | lv_style_init(&g_btn_styles.style_focus_no_outline); 133 | lv_style_set_outline_width(&g_btn_styles.style_focus_no_outline, 0); 134 | } 135 | 136 | static int8_t menu_direct_probe(lv_obj_t *focus_obj) 137 | { 138 | int8_t direct; 139 | uint32_t index_max_sz, index_focus, index_prev; 140 | 141 | index_focus = 0; 142 | index_prev = 0; 143 | index_max_sz = sizeof(g_group_list) / sizeof(g_group_list[0]); 144 | 145 | for (int i = 0; i < index_max_sz; i++) { 146 | if (focus_obj == g_group_list[i]) { 147 | index_focus = i; 148 | } 149 | if (g_focus_last_obj == g_group_list[i]) { 150 | index_prev = i; 151 | } 152 | } 153 | 154 | if (NULL == g_focus_last_obj) { 155 | direct = 0; 156 | } else if (index_focus == menu_get_num_offset(index_prev, index_max_sz, 1)) { 157 | direct = 1; 158 | } else if (index_focus == menu_get_num_offset(index_prev, index_max_sz, -1)) { 159 | direct = -1; 160 | } else { 161 | direct = 0; 162 | } 163 | 164 | g_focus_last_obj = focus_obj; 165 | return direct; 166 | } 167 | 168 | static void menu_prev_cb(lv_event_t *e) 169 | { 170 | bsp_display_lock(0); 171 | lv_event_code_t code = lv_event_get_code(e); 172 | 173 | if (LV_EVENT_RELEASED == code) { 174 | int64_t now = esp_timer_get_time(); 175 | if (now - last_btn_press_time < 500000) { // 500 ms debounce time 176 | bsp_display_unlock(); 177 | return; 178 | } 179 | last_btn_press_time = now; 180 | 181 | lv_led_off(g_led_item[g_item_index]); 182 | if (0 == g_item_index) { 183 | g_item_index = g_item_size; 184 | } 185 | g_item_index--; 186 | lv_led_on(g_led_item[g_item_index]); 187 | lv_img_set_src(g_img_item, item[g_item_index].img_src); 188 | lv_label_set_text_static(g_lab_item, item[g_item_index].name); 189 | } 190 | bsp_display_unlock(); 191 | } 192 | 193 | static void menu_next_cb(lv_event_t *e) 194 | { 195 | bsp_display_lock(0); 196 | lv_event_code_t code = lv_event_get_code(e); 197 | 198 | if (LV_EVENT_RELEASED == code) { 199 | int64_t now = esp_timer_get_time(); 200 | if (now - last_btn_press_time < 500000) { // 500 ms debounce time 201 | bsp_display_unlock(); 202 | return; 203 | } 204 | last_btn_press_time = now; 205 | 206 | lv_led_off(g_led_item[g_item_index]); 207 | g_item_index++; 208 | if (g_item_index >= g_item_size) { 209 | g_item_index = 0; 210 | } 211 | lv_led_on(g_led_item[g_item_index]); 212 | lv_img_set_src(g_img_item, item[g_item_index].img_src); 213 | lv_label_set_text_static(g_lab_item, item[g_item_index].name); 214 | } 215 | bsp_display_unlock(); 216 | } 217 | 218 | static void ui_led_set_visible(bool visible) 219 | { 220 | bsp_display_lock(0); 221 | for (size_t i = 0; i < sizeof(g_led_item) / sizeof(g_led_item[0]); i++) { 222 | if (NULL != g_led_item[i]) { 223 | if (visible) { 224 | lv_obj_clear_flag(g_led_item[i], LV_OBJ_FLAG_HIDDEN); 225 | } else { 226 | lv_obj_add_flag(g_led_item[i], LV_OBJ_FLAG_HIDDEN); 227 | } 228 | } 229 | } 230 | bsp_display_unlock(); 231 | } 232 | 233 | 234 | void menu_new_item_select(lv_obj_t *obj) 235 | { 236 | bsp_display_lock(0); 237 | int8_t direct = menu_direct_probe(obj); 238 | g_item_index = menu_get_num_offset(g_item_index, g_item_size, direct); 239 | 240 | lv_led_on(g_led_item[g_item_index]); 241 | lv_img_set_src(g_img_item, item[g_item_index].img_src); 242 | lv_label_set_text_static(g_lab_item, item[g_item_index].name); 243 | bsp_display_unlock(); 244 | } 245 | 246 | static void menu_enter_cb(lv_event_t *e) 247 | { 248 | bsp_display_lock(0); 249 | lv_event_code_t code = lv_event_get_code(e); 250 | lv_obj_t *obj = lv_event_get_user_data(e); 251 | 252 | if (LV_EVENT_FOCUSED == code) { 253 | lv_led_off(g_led_item[g_item_index]); 254 | menu_new_item_select(obj); 255 | } else if (LV_EVENT_CLICKED == code) { 256 | lv_obj_t *menu_btn_parent = lv_obj_get_parent(obj); 257 | ESP_LOGI(TAG, "menu click, item index = %d", g_item_index); 258 | if (ui_get_btn_op_group()) { 259 | lv_group_remove_all_objs(ui_get_btn_op_group()); 260 | } 261 | // #if !CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite 262 | // bsp_btn_rm_all_callback(BSP_BUTTON_MAIN); 263 | // #endif 264 | ui_led_set_visible(false); 265 | lv_obj_del(menu_btn_parent); 266 | g_focus_last_obj = NULL; 267 | 268 | item[g_item_index].start_fn(item[g_item_index].end_fn); 269 | } 270 | bsp_display_unlock(); 271 | } 272 | 273 | static void ui_main_menu(int32_t index_id) 274 | { 275 | if (!g_page_menu) { 276 | g_page_menu = lv_obj_create(lv_scr_act()); 277 | lv_obj_set_size(g_page_menu, lv_obj_get_width(lv_obj_get_parent(g_page_menu)), lv_obj_get_height(lv_obj_get_parent(g_page_menu)) - lv_obj_get_height(ui_main_get_status_bar())); 278 | lv_obj_set_style_border_width(g_page_menu, 0, LV_PART_MAIN); 279 | lv_obj_set_style_bg_color(g_page_menu, lv_obj_get_style_bg_color(lv_scr_act(), LV_STATE_DEFAULT), LV_PART_MAIN); 280 | lv_obj_clear_flag(g_page_menu, LV_OBJ_FLAG_SCROLLABLE); 281 | lv_obj_align_to(g_page_menu, ui_main_get_status_bar(), LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); 282 | } 283 | 284 | lv_obj_t *obj = lv_obj_create(g_page_menu); 285 | lv_obj_set_size(obj, 290, 174); 286 | lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); 287 | lv_obj_set_style_radius(obj, 15, LV_STATE_DEFAULT); 288 | lv_obj_set_style_border_width(obj, 0, LV_STATE_DEFAULT); 289 | lv_obj_set_style_shadow_width(obj, 20, LV_PART_MAIN); 290 | lv_obj_set_style_shadow_opa(obj, LV_OPA_30, LV_PART_MAIN); 291 | lv_obj_align(obj, LV_ALIGN_TOP_MID, 0, -10); 292 | 293 | g_img_btn = lv_btn_create(obj); 294 | lv_obj_set_size(g_img_btn, 108, 108); 295 | lv_obj_add_style(g_img_btn, &ui_button_styles()->style_pr, LV_STATE_PRESSED); 296 | lv_obj_add_style(g_img_btn, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY); 297 | lv_obj_add_style(g_img_btn, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED); 298 | lv_obj_set_style_bg_color(g_img_btn, lv_color_white(), LV_PART_MAIN); 299 | lv_obj_set_style_shadow_color(g_img_btn, lv_color_make(0, 0, 0), LV_PART_MAIN); 300 | lv_obj_set_style_shadow_width(g_img_btn, 15, LV_PART_MAIN); 301 | lv_obj_set_style_shadow_ofs_x(g_img_btn, 0, LV_PART_MAIN); 302 | lv_obj_set_style_shadow_ofs_y(g_img_btn, 0, LV_PART_MAIN); 303 | lv_obj_set_style_shadow_opa(g_img_btn, LV_OPA_50, LV_PART_MAIN); 304 | lv_obj_set_style_radius(g_img_btn, 40, LV_PART_MAIN); 305 | lv_obj_align(g_img_btn, LV_ALIGN_CENTER, 0, -20); 306 | lv_obj_add_event_cb(g_img_btn, menu_enter_cb, LV_EVENT_ALL, g_img_btn); 307 | 308 | g_img_item = lv_img_create(g_img_btn); 309 | lv_img_set_src(g_img_item, item[index_id].img_src); 310 | lv_obj_center(g_img_item); 311 | 312 | g_lab_item = lv_label_create(obj); 313 | lv_label_set_text_static(g_lab_item, item[index_id].name); 314 | lv_obj_set_style_text_font(g_lab_item, &lv_font_montserrat_32, LV_PART_MAIN); 315 | lv_obj_align(g_lab_item, LV_ALIGN_CENTER, 0, 60); 316 | 317 | for (size_t i = 0; i < sizeof(g_led_item) / sizeof(g_led_item[0]); i++) { 318 | int gap = 10; 319 | if (NULL == g_led_item[i]) { 320 | g_led_item[i] = lv_led_create(g_page_menu); 321 | } else { 322 | lv_obj_clear_flag(g_led_item[i], LV_OBJ_FLAG_HIDDEN); 323 | } 324 | lv_led_off(g_led_item[i]); 325 | lv_obj_set_size(g_led_item[i], 5, 5); 326 | lv_obj_align_to(g_led_item[i], g_page_menu, LV_ALIGN_BOTTOM_MID, 2 * gap * i - (g_item_size - 1) * gap, 0); 327 | } 328 | lv_led_on(g_led_item[index_id]); 329 | 330 | lv_obj_t *btn_prev = lv_btn_create(obj); 331 | lv_obj_add_style(btn_prev, &ui_button_styles()->style_pr, LV_STATE_PRESSED); 332 | lv_obj_add_style(btn_prev, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY); 333 | lv_obj_add_style(btn_prev, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED); 334 | 335 | lv_obj_set_size(btn_prev, 40, 40); 336 | lv_obj_set_style_bg_color(btn_prev, lv_color_white(), LV_PART_MAIN); 337 | lv_obj_set_style_shadow_color(btn_prev, lv_color_make(0, 0, 0), LV_PART_MAIN); 338 | lv_obj_set_style_shadow_width(btn_prev, 15, LV_PART_MAIN); 339 | lv_obj_set_style_shadow_opa(btn_prev, LV_OPA_50, LV_PART_MAIN); 340 | lv_obj_set_style_shadow_ofs_x(btn_prev, 0, LV_PART_MAIN); 341 | lv_obj_set_style_shadow_ofs_y(btn_prev, 0, LV_PART_MAIN); 342 | lv_obj_set_style_radius(btn_prev, 20, LV_PART_MAIN); 343 | lv_obj_align_to(btn_prev, obj, LV_ALIGN_LEFT_MID, 0, 0); 344 | lv_obj_t *label = lv_label_create(btn_prev); 345 | lv_label_set_text_static(label, LV_SYMBOL_LEFT); 346 | lv_obj_set_style_text_color(label, lv_color_make(5, 5, 5), LV_PART_MAIN); 347 | lv_obj_center(label); 348 | lv_obj_add_event_cb(btn_prev, menu_prev_cb, LV_EVENT_ALL, btn_prev); 349 | 350 | 351 | lv_obj_t *btn_next = lv_btn_create(obj); 352 | lv_obj_add_style(btn_next, &ui_button_styles()->style_pr, LV_STATE_PRESSED); 353 | lv_obj_add_style(btn_next, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY); 354 | lv_obj_add_style(btn_next, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED); 355 | 356 | lv_obj_set_size(btn_next, 40, 40); 357 | lv_obj_set_style_bg_color(btn_next, lv_color_white(), LV_PART_MAIN); 358 | lv_obj_set_style_shadow_color(btn_next, lv_color_make(0, 0, 0), LV_PART_MAIN); 359 | lv_obj_set_style_shadow_width(btn_next, 15, LV_PART_MAIN); 360 | lv_obj_set_style_shadow_opa(btn_next, LV_OPA_50, LV_PART_MAIN); 361 | lv_obj_set_style_shadow_ofs_x(btn_next, 0, LV_PART_MAIN); 362 | lv_obj_set_style_shadow_ofs_y(btn_next, 0, LV_PART_MAIN); 363 | lv_obj_set_style_radius(btn_next, 20, LV_PART_MAIN); 364 | lv_obj_align_to(btn_next, obj, LV_ALIGN_RIGHT_MID, 0, 0); 365 | label = lv_label_create(btn_next); 366 | lv_label_set_text_static(label, LV_SYMBOL_RIGHT); 367 | lv_obj_set_style_text_color(label, lv_color_make(5, 5, 5), LV_PART_MAIN); 368 | lv_obj_center(label); 369 | lv_obj_add_event_cb(btn_next, menu_next_cb, LV_EVENT_ALL, btn_next); 370 | } 371 | 372 | 373 | static void ota_swich_to_app(int app_index) { 374 | // Initially assume the first OTA partition, which is typically 'ota_0' 375 | const esp_partition_t *next_partition = esp_ota_get_next_update_partition(NULL); 376 | 377 | // Iterate to find the correct OTA partition only if button ID is greater than 1 378 | if (app_index > 0 && app_index <= 5) { 379 | for (int i = 0; i < app_index; i++) { 380 | next_partition = esp_ota_get_next_update_partition(next_partition); 381 | if (!next_partition) break; // If no next partition, break from the loop 382 | } 383 | } 384 | 385 | // For button 1, next_partition will not change, thus pointing to 'ota_0' 386 | if (next_partition && esp_ota_set_boot_partition(next_partition) == ESP_OK) { 387 | printf("Setting boot partition to %s\n", next_partition->label); 388 | esp_restart(); // Restart to boot from the new partition 389 | } else { 390 | printf("Failed to set boot partition\n"); 391 | } 392 | } 393 | 394 | 395 | 396 | void ui_app1_start(void (*fn)(void)) 397 | { 398 | ESP_LOGI(TAG, "App1 start"); 399 | ota_swich_to_app(0); 400 | } 401 | 402 | void ui_app2_start(void (*fn)(void)) 403 | { 404 | ESP_LOGI(TAG, "App2 start"); 405 | ota_swich_to_app(1); 406 | } 407 | 408 | void ui_app3_start(void (*fn)(void)) 409 | { 410 | ESP_LOGI(TAG, "App3 start"); 411 | ota_swich_to_app(2); 412 | } 413 | 414 | void ui_app4_start(void (*fn)(void)) 415 | { 416 | ESP_LOGI(TAG, "App4 start"); 417 | ota_swich_to_app(3); 418 | } 419 | 420 | void ui_app5_start(void (*fn)(void)) 421 | { 422 | ESP_LOGI(TAG, "App5 start"); 423 | ota_swich_to_app(4); 424 | } 425 | 426 | void bootloader_ui(lv_obj_t *scr) { 427 | lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(237, 238, 239), LV_STATE_DEFAULT); 428 | ui_button_style_init(); 429 | 430 | lv_indev_t *indev = lv_indev_get_next(NULL); 431 | 432 | if ((lv_indev_get_type(indev) == LV_INDEV_TYPE_KEYPAD) || \ 433 | lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) { 434 | ESP_LOGI(TAG, "Input device type is keypad"); 435 | g_btn_op_group = lv_group_create(); 436 | lv_indev_set_group(indev, g_btn_op_group); 437 | } else if (lv_indev_get_type(indev) == LV_INDEV_TYPE_BUTTON) { 438 | ESP_LOGI(TAG, "Input device type have button"); 439 | } else if (lv_indev_get_type(indev) == LV_INDEV_TYPE_POINTER) { 440 | ESP_LOGI(TAG, "Input device type have pointer"); 441 | } 442 | 443 | // Create status bar 444 | g_status_bar = lv_obj_create(lv_scr_act()); 445 | lv_obj_set_size(g_status_bar, lv_obj_get_width(lv_obj_get_parent(g_status_bar)), 0); 446 | lv_obj_clear_flag(g_status_bar, LV_OBJ_FLAG_SCROLLABLE); 447 | lv_obj_set_style_radius(g_status_bar, 0, LV_STATE_DEFAULT); 448 | lv_obj_set_style_bg_color(g_status_bar, lv_obj_get_style_bg_color(lv_scr_act(), LV_STATE_DEFAULT), LV_PART_MAIN); 449 | lv_obj_set_style_border_width(g_status_bar, 0, LV_PART_MAIN); 450 | lv_obj_set_style_shadow_width(g_status_bar, 0, LV_PART_MAIN); 451 | lv_obj_align(g_status_bar, LV_ALIGN_TOP_MID, 0, 0); 452 | 453 | ui_main_menu(g_item_index); 454 | } 455 | -------------------------------------------------------------------------------- /main/graphical_bootloader_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: CC0-1.0 5 | */ 6 | 7 | #include 8 | #include "bsp/esp-bsp.h" 9 | #include "lvgl.h" 10 | #include "esp_log.h" 11 | 12 | extern void bootloader_ui(lv_obj_t *scr); 13 | 14 | void app_main(void) 15 | { 16 | ESP_LOGI("bootloader", "Starting 3rd stage bootloader..."); 17 | 18 | bsp_display_start(); 19 | 20 | bsp_display_lock(0); 21 | lv_obj_t *scr = lv_disp_get_scr_act(NULL); 22 | bootloader_ui(scr); 23 | 24 | bsp_display_unlock(); 25 | bsp_display_backlight_on(); 26 | // Enter the main loop to process LVGL tasks 27 | while (1) { 28 | vTaskDelay(pdMS_TO_TICKS(1000)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | espressif/esp-box-3: 4 | version: "^1.2.0" 5 | rules: 6 | - if: "target == ${USE_ESP_BOX_3}" 7 | espressif/esp-box: 8 | version: "3.1.0" 9 | rules: 10 | - if: "target == ${USE_ESP_BOX}" 11 | espressif/m5stack_core_s3: 12 | version: "1.1.1" 13 | rules: 14 | - if: "target == ${USE_M5STACK_CORE_S3}" 15 | espressif/esp32_p4_function_ev_board: 16 | version: "2.0.0" 17 | rules: 18 | - if: "target == ${USE_ESP32_P4_FUNCTION_EV_BOARD}" 19 | # Workaround for i2c: CONFLICT! driver_ng is not allowed to be used with this old driver 20 | esp_codec_dev: 21 | public: true 22 | version: "==1.1.0" 23 | ## Required IDF version 24 | idf: 25 | version: ">=5.0.0" -------------------------------------------------------------------------------- /partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, Subtype, Offset, Size, Flags 2 | nvs, data, nvs, 0x9000, 24K, 3 | otadata, data, ota, , 8K, 4 | phy_init, data, phy, , 4K, 5 | factory, app, factory, , 2M, 6 | ota_0, app, ota_0, , 2816K, 7 | ota_1, app, ota_1, , 2816K, 8 | ota_2, app, ota_2, , 2816K, 9 | ota_3, app, ota_3, , 2816K, 10 | ota_4, app, ota_4, , 2816K, 11 | 12 | -------------------------------------------------------------------------------- /resources/images/icon_calculator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/georgik/esp32-graphical-bootloader/993df0fa6c498fcb3dfc463c13ccd4c1395f1e72/resources/images/icon_calculator.png -------------------------------------------------------------------------------- /resources/images/icon_game_of_life.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/georgik/esp32-graphical-bootloader/993df0fa6c498fcb3dfc463c13ccd4c1395f1e72/resources/images/icon_game_of_life.png -------------------------------------------------------------------------------- /resources/images/icon_synth_piano.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/georgik/esp32-graphical-bootloader/993df0fa6c498fcb3dfc463c13ccd4c1395f1e72/resources/images/icon_synth_piano.png -------------------------------------------------------------------------------- /resources/images/icon_tic_tac_toe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/georgik/esp32-graphical-bootloader/993df0fa6c498fcb3dfc463c13ccd4c1395f1e72/resources/images/icon_tic_tac_toe.png -------------------------------------------------------------------------------- /resources/images/icon_wifi_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/georgik/esp32-graphical-bootloader/993df0fa6c498fcb3dfc463c13ccd4c1395f1e72/resources/images/icon_wifi_list.png -------------------------------------------------------------------------------- /sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | -------------------------------------------------------------------------------- /sdkconfig.defaults.esp-box: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | -------------------------------------------------------------------------------- /sdkconfig.defaults.esp-box-3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | -------------------------------------------------------------------------------- /sdkconfig.defaults.esp32_p4_function_ev_board: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32p4" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | 9 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 11 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 12 | CONFIG_SPIRAM=y 13 | CONFIG_SPIRAM_MODE_OCT=y 14 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y 15 | CONFIG_SPIRAM_RODATA=y 16 | CONFIG_SPIRAM_SPEED_80M=y 17 | CONFIG_FREERTOS_HZ=1000 18 | CONFIG_BSP_LCD_RGB_BUFFER_NUMS=2 19 | CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y 20 | CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR=y 21 | CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y 22 | CONFIG_SPIRAM_MODE_HEX=y 23 | CONFIG_SPIRAM_SPEED_200M=y 24 | CONFIG_IDF_EXPERIMENTAL_FEATURES=y 25 | 26 | ## LVGL9 ## 27 | CONFIG_LV_CONF_SKIP=y 28 | 29 | #CLIB default 30 | CONFIG_LV_USE_CLIB_MALLOC=y 31 | CONFIG_LV_USE_CLIB_SPRINTF=y 32 | CONFIG_LV_USE_CLIB_STRING=y 33 | 34 | -------------------------------------------------------------------------------- /sdkconfig.defaults.m5stack_core_s3: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s3" 5 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 6 | CONFIG_PARTITION_TABLE_CUSTOM=y 7 | CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32=y 8 | CONFIG_SPIRAM_MODE_QUAD=y 9 | 10 | -------------------------------------------------------------------------------- /wokwi.toml: -------------------------------------------------------------------------------- 1 | [wokwi] 2 | version = 1 3 | elf = "build/uf2.bin" 4 | firmware = "build/uf2.bin" 5 | 6 | --------------------------------------------------------------------------------