├── .editorconfig ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── all-other-issues.md │ ├── bug-report.md │ └── config.yml ├── auto-comment.yml ├── stale.yml └── workflows │ ├── ccpp.yml │ └── merge-to-dev.yml ├── .gitignore ├── .gitmodules ├── .vscode └── settings.json ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── LICENCE.txt ├── Makefile ├── README.md ├── clock ├── BatteryController.h ├── BatteryIcon.cpp ├── BatteryIcon.h ├── BleController.cpp ├── BleController.h ├── BleIcon.cpp ├── BleIcon.h ├── Clock.cpp ├── Clock.h ├── Clock2.cpp ├── ClockHelper.cpp ├── ClockHelper.h ├── DateTimeController.cpp ├── DateTimeController.h ├── DisplayApp.h ├── LittleVgl.cpp ├── LittleVgl.h ├── Screen.h ├── Symbols.h ├── date.h ├── jetbrains_mono_bold_20.c └── jetbrains_mono_extrabold_compressed.c ├── demo ├── lv_demo_widgets.c └── lv_demo_widgets.h ├── docs ├── CODE_OF_CONDUCT.md ├── CODING_STYLE.md ├── CONTRIBUTING.md ├── ROADMAP.md ├── index.md ├── lvgl.html ├── lvgl.js ├── lvgl.old.html ├── lvgl.txt ├── lvgl.wasm ├── lvgl2.html ├── lvgl2.js ├── lvgl2.wasm ├── rust.html ├── rust.js ├── rust.wasm ├── test.html ├── test.js ├── test.old.html ├── test.txt ├── test.wasm ├── test_rust.html ├── test_rust.js ├── test_rust.old.html ├── test_rust.txt └── test_rust.wasm ├── examples ├── arduino │ ├── ESP32_TFT_eSPI │ │ ├── ESP32_TFT_eSPI.ino │ │ └── README.md │ └── README.md └── porting │ ├── lv_port_disp_template.c │ ├── lv_port_disp_template.h │ ├── lv_port_fs_template.c │ ├── lv_port_fs_template.h │ ├── lv_port_indev_template.c │ └── lv_port_indev_template.h ├── library.json ├── library.properties ├── lv_conf.h ├── lv_conf_template.h ├── lvgl.h ├── lvgl.mk ├── rust ├── Cargo.toml ├── README.md ├── index.html ├── index.js ├── package-lock.json ├── package.json ├── src │ └── lib.rs ├── styles │ ├── normalize.css │ ├── skeleton.css │ └── style.css └── webpack.config.js ├── scripts ├── Doxyfile ├── built_in_font │ ├── DejaVuSans.ttf │ ├── FontAwesome5-Solid+Brands+Regular.woff │ ├── Montserrat-Medium.ttf │ ├── SimSun.woff │ ├── built_in_font_gen.py │ └── generate_all.py ├── code-format.cfg ├── code-format.sh ├── cppcheck_run.sh ├── infer_run.sh ├── lv_conf_checker.py └── release.py ├── src ├── lv_api_map.h ├── lv_conf_internal.h ├── lv_core │ ├── lv_core.mk │ ├── lv_disp.c │ ├── lv_disp.h │ ├── lv_group.c │ ├── lv_group.h │ ├── lv_indev.c │ ├── lv_indev.h │ ├── lv_obj.c │ ├── lv_obj.h │ ├── lv_obj_style_dec.h │ ├── lv_refr.c │ ├── lv_refr.h │ ├── lv_style.c │ └── lv_style.h ├── lv_draw │ ├── lv_draw.h │ ├── lv_draw.mk │ ├── lv_draw_arc.c │ ├── lv_draw_arc.h │ ├── lv_draw_blend.c │ ├── lv_draw_blend.h │ ├── lv_draw_img.c │ ├── lv_draw_img.h │ ├── lv_draw_label.c │ ├── lv_draw_label.h │ ├── lv_draw_line.c │ ├── lv_draw_line.h │ ├── lv_draw_mask.c │ ├── lv_draw_mask.h │ ├── lv_draw_rect.c │ ├── lv_draw_rect.h │ ├── lv_draw_triangle.c │ ├── lv_draw_triangle.h │ ├── lv_img_buf.c │ ├── lv_img_buf.h │ ├── lv_img_cache.c │ ├── lv_img_cache.h │ ├── lv_img_decoder.c │ └── lv_img_decoder.h ├── lv_font │ ├── lv_font.c │ ├── lv_font.h │ ├── lv_font.mk │ ├── lv_font_dejavu_16_persian_hebrew.c │ ├── lv_font_fmt_txt.c │ ├── lv_font_fmt_txt.h │ ├── lv_font_montserrat_12.c │ ├── lv_font_montserrat_12_subpx.c │ ├── lv_font_montserrat_14.c │ ├── lv_font_montserrat_16.c │ ├── lv_font_montserrat_18.c │ ├── lv_font_montserrat_20.c │ ├── lv_font_montserrat_22.c │ ├── lv_font_montserrat_24.c │ ├── lv_font_montserrat_26.c │ ├── lv_font_montserrat_28.c │ ├── lv_font_montserrat_28_compressed.c │ ├── lv_font_montserrat_30.c │ ├── lv_font_montserrat_32.c │ ├── lv_font_montserrat_34.c │ ├── lv_font_montserrat_36.c │ ├── lv_font_montserrat_38.c │ ├── lv_font_montserrat_40.c │ ├── lv_font_montserrat_42.c │ ├── lv_font_montserrat_44.c │ ├── lv_font_montserrat_46.c │ ├── lv_font_montserrat_48.c │ ├── lv_font_simsun_16_cjk.c │ ├── lv_font_unscii_8.c │ └── lv_symbol_def.h ├── lv_gpu │ ├── lv_gpu.mk │ ├── lv_gpu_stm32_dma2d.c │ └── lv_gpu_stm32_dma2d.h ├── lv_hal │ ├── lv_hal.h │ ├── lv_hal.mk │ ├── lv_hal_disp.c │ ├── lv_hal_disp.h │ ├── lv_hal_indev.c │ ├── lv_hal_indev.h │ ├── lv_hal_tick.c │ └── lv_hal_tick.h ├── lv_misc │ ├── lv_anim.c │ ├── lv_anim.h │ ├── lv_area.c │ ├── lv_area.h │ ├── lv_async.c │ ├── lv_async.h │ ├── lv_bidi.c │ ├── lv_bidi.h │ ├── lv_color.c │ ├── lv_color.h │ ├── lv_debug.c │ ├── lv_debug.h │ ├── lv_fs.c │ ├── lv_fs.h │ ├── lv_gc.c │ ├── lv_gc.h │ ├── lv_ll.c │ ├── lv_ll.h │ ├── lv_log.c │ ├── lv_log.h │ ├── lv_math.c │ ├── lv_math.h │ ├── lv_mem.c │ ├── lv_mem.h │ ├── lv_misc.mk │ ├── lv_printf.c │ ├── lv_printf.h │ ├── lv_task.c │ ├── lv_task.h │ ├── lv_templ.c │ ├── lv_templ.h │ ├── lv_txt.c │ ├── lv_txt.h │ ├── lv_txt_ap.c │ ├── lv_txt_ap.h │ ├── lv_types.h │ ├── lv_utils.c │ └── lv_utils.h ├── lv_themes │ ├── lv_theme.c │ ├── lv_theme.h │ ├── lv_theme_empty.c │ ├── lv_theme_empty.h │ ├── lv_theme_material.c │ ├── lv_theme_material.h │ ├── lv_theme_mono.c │ ├── lv_theme_mono.h │ ├── lv_theme_template.c │ ├── lv_theme_template.h │ └── lv_themes.mk ├── lv_widgets │ ├── lv_arc.c │ ├── lv_arc.h │ ├── lv_bar.c │ ├── lv_bar.h │ ├── lv_btn.c │ ├── lv_btn.h │ ├── lv_btnmatrix.c │ ├── lv_btnmatrix.h │ ├── lv_calendar.c │ ├── lv_calendar.h │ ├── lv_canvas.c │ ├── lv_canvas.h │ ├── lv_chart.c │ ├── lv_chart.h │ ├── lv_checkbox.c │ ├── lv_checkbox.h │ ├── lv_cont.c │ ├── lv_cont.h │ ├── lv_cpicker.c │ ├── lv_cpicker.h │ ├── lv_dropdown.c │ ├── lv_dropdown.h │ ├── lv_gauge.c │ ├── lv_gauge.h │ ├── lv_img.c │ ├── lv_img.h │ ├── lv_imgbtn.c │ ├── lv_imgbtn.h │ ├── lv_keyboard.c │ ├── lv_keyboard.h │ ├── lv_label.c │ ├── lv_label.h │ ├── lv_led.c │ ├── lv_led.h │ ├── lv_line.c │ ├── lv_line.h │ ├── lv_linemeter.c │ ├── lv_linemeter.h │ ├── lv_list.c │ ├── lv_list.h │ ├── lv_msgbox.c │ ├── lv_msgbox.h │ ├── lv_objmask.c │ ├── lv_objmask.h │ ├── lv_objx_templ.c │ ├── lv_objx_templ.h │ ├── lv_page.c │ ├── lv_page.h │ ├── lv_roller.c │ ├── lv_roller.h │ ├── lv_slider.c │ ├── lv_slider.h │ ├── lv_spinbox.c │ ├── lv_spinbox.h │ ├── lv_spinner.c │ ├── lv_spinner.h │ ├── lv_switch.c │ ├── lv_switch.h │ ├── lv_table.c │ ├── lv_table.h │ ├── lv_tabview.c │ ├── lv_tabview.h │ ├── lv_textarea.c │ ├── lv_textarea.h │ ├── lv_tileview.c │ ├── lv_tileview.h │ ├── lv_widgets.mk │ ├── lv_win.c │ └── lv_win.h └── lvgl.h ├── tests ├── Makefile ├── build.py ├── icon.png ├── icon2.png ├── lv_test_assert.c ├── lv_test_assert.h ├── lv_test_conf.h ├── lv_test_core │ ├── lv_test_core.c │ ├── lv_test_core.h │ ├── lv_test_obj.c │ ├── lv_test_obj.h │ ├── lv_test_style.c │ └── lv_test_style.h ├── lv_test_main.c ├── lv_test_objx │ ├── lv_test_cont.c │ └── lv_test_cont.h └── lv_test_ref_imgs │ └── lv_test_obj_1_1.png └── wasm ├── copy-wasm.sh ├── copy-wasm2.sh ├── lv_port_disp.c ├── lv_port_disp.h ├── lvgl.c ├── lvgl.sh ├── test.c └── test_rust.c /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{c,h}] 2 | indent_style = space 3 | indent_size = 4 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | 8 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ["https://paypal.me/littlevgl?locale.x=en_US"] 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/all-other-issues.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: All other issues 3 | about: Questions and enhancement requests should go to the forum. 4 | title: '' 5 | labels: not-template 6 | assignees: '' 7 | 8 | --- 9 | 10 | # All enhancement requests or questions should be directed to the Forum. 11 | 12 | 13 | We use GitHub issues for development related discussions. 14 | Please use the [forum](https://forum.littlevgl.com/) to ask questions. 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | > # Important: issues that don't use this template will be ignored/closed. 11 | 12 | **Describe the bug** 13 | 14 | A clear and concise description of what the bug is. 15 | 16 | **To Reproduce** 17 | 18 | Please provide a small, independent code sample that can be used to reproduce the issue. Ideally this should work in the PC simulator unless the problem is specific to one platform. 19 | 20 | **Expected behavior** 21 | 22 | A clear and concise description of what you expected to happen. 23 | 24 | **Screenshots** 25 | If applicable, add screenshots to help explain your problem. 26 | 27 | **Additional context** 28 | 29 | Add any other context about the problem here. 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Documentation 4 | url: https://docs.lvgl.io 5 | about: Be sure to read to documentation first 6 | - name: Forum 7 | url: https://forum.lvgl.io 8 | about: For how-to questions use the forum 9 | - name: CONTIBUTING.md 10 | url: https://github.com/lvgl/lvgl/blob/master/docs/CONTRIBUTING.md#faq-about-contributing 11 | about: The basic rules of contributing 12 | - name: CODING_STYLE.md 13 | url: https://github.com/lvgl/lvgl/blob/master/docs/CODING_STYLE.md 14 | about: Quick summary of LVGL's code style 15 | -------------------------------------------------------------------------------- /.github/auto-comment.yml: -------------------------------------------------------------------------------- 1 | # Comment to a new issue. 2 | pullRequestOpened: | 3 | Thank you for raising your pull request. 4 | 5 | To ensure that all licensing criteria is met all repositories of the LVGL project apply a process called DCO (Developer's Certificate of Origin). 6 | 7 | The text of DCO can be read here: https://developercertificate.org/ 8 | For a more detailed description see the [Documentation](https://docs.lvgl.io/latest/en/html/contributing/index.html#developer-certification-of-origin-dco) site. 9 | 10 | By contributing to any repositories of the LVGL project you state that your contribution corresponds with the DCO. 11 | 12 | No further action is required if your contribution fulfills the DCO. If you are not sure about it feel free to ask us in a comment. 13 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 21 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - architecture 8 | - pinned 9 | # Label to use when marking an issue as stale 10 | staleLabel: stale 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue or pull request has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when closing a stale issue. Set to `false` to disable 17 | closeComment: false 18 | -------------------------------------------------------------------------------- /.github/workflows/ccpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ master, dev ] 6 | pull_request: 7 | branches: [master, dev ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: Fetch cache for Rust Toolchain 18 | id: cache-rust 19 | uses: actions/cache@v2 20 | with: 21 | path: | 22 | ~/.cargo/registry 23 | ~/.cargo/git 24 | target 25 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 26 | 27 | - name: Install Rust Toolchain for emscripten 28 | run: | 29 | rustup default nightly 30 | rustup target add wasm32-unknown-emscripten 31 | 32 | - name: Check cache for emscripten 33 | id: cache-emsdk 34 | uses: actions/cache@v2 35 | env: 36 | cache-name: cache-emsdk 37 | with: 38 | path: /tmp/emsdk 39 | key: ${{ runner.os }}-build-${{ env.cache-name }} 40 | restore-keys: ${{ runner.os }}-build-${{ env.cache-name }} 41 | 42 | - name: Install emscripten 43 | if: steps.cache-emsdk.outputs.cache-hit != 'true' # Install emscripten if not found in cache 44 | run: | 45 | # Based on https://emscripten.org/docs/getting_started/downloads.html 46 | cd /tmp 47 | 48 | # Get the emsdk repo 49 | git clone https://github.com/emscripten-core/emsdk.git 50 | 51 | # Enter that directory 52 | cd emsdk 53 | 54 | # Download and install the latest SDK tools. 55 | ./emsdk install latest 56 | 57 | # Make the "latest" SDK "active" for the current user. (writes .emscripten file) 58 | ./emsdk activate latest 59 | 60 | # Activate PATH and other environment variables in the current terminal 61 | source ./emsdk_env.sh 62 | 63 | # Show version 64 | emcc --version 65 | emcc --version 66 | 67 | - name: Check cache for wabt 68 | id: cache-wabt 69 | uses: actions/cache@v2 70 | env: 71 | cache-name: cache-wabt 72 | with: 73 | path: /tmp/wabt 74 | key: ${{ runner.os }}-build-${{ env.cache-name }} 75 | restore-keys: ${{ runner.os }}-build-${{ env.cache-name }} 76 | 77 | - name: Install wabt 78 | if: steps.cache-wabt.outputs.cache-hit != 'true' # Install wabt if not found in cache 79 | run: | 80 | cd /tmp 81 | git clone --recursive https://github.com/WebAssembly/wabt 82 | cd wabt 83 | mkdir build 84 | cd build 85 | cmake .. 86 | cmake --build . 87 | 88 | - name: Build LVGL 89 | run: | 90 | # Add emscripten and wabt to the PATH 91 | source /tmp/emsdk/emsdk_env.sh 92 | export PATH=$PATH:/tmp/wabt/build 93 | 94 | # Build LVGL app: wasm/lvgl.html, lvgl.js, lvgl.wasm 95 | wasm/lvgl.sh 96 | 97 | - name: Show files 98 | run: set ; pwd ; ls -l 99 | 100 | - name: Upload Outputs 101 | uses: actions/upload-artifact@v2 102 | with: 103 | name: wasm 104 | path: | 105 | wasm/*.html 106 | wasm/*.js 107 | wasm/*.wasm 108 | wasm/*.txt 109 | 110 | #- name: Run tests 111 | # run: cd tests; python ./build.py -------------------------------------------------------------------------------- /.github/workflows/merge-to-dev.yml: -------------------------------------------------------------------------------- 1 | name: Merge master branch to dev 2 | on: 3 | push: 4 | branches: 5 | - 'master' 6 | jobs: 7 | merge-branch: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@master 11 | - name: Merge to dev branch 12 | uses: devmasx/merge-branch@v1.1.0 13 | with: 14 | type: now 15 | target_branch: 'dev' 16 | env: 17 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.o 2 | **/*bin 3 | **/*.swp 4 | **/*.swo 5 | **/*.o.tmp 6 | tags 7 | docs/api_doc 8 | scripts/cppcheck_res.txt 9 | scripts/built_in_font/lv_font_* 10 | target 11 | rust/node_modules 12 | wasm/lvgl.html 13 | wasm/lvgl.js 14 | wasm/lvgl.txt 15 | wasm/lvgl.wasm 16 | wasm/test.html 17 | wasm/test.js 18 | wasm/test.txt 19 | wasm/test.wasm 20 | wasm/test-rust.html 21 | wasm/test-rust.js 22 | wasm/test-rust.txt 23 | wasm/test-rust.wasm 24 | clock/ClockTmp.cpp 25 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/.gitmodules -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "limits": "cpp", 4 | "random": "cpp" 5 | } 6 | } -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "bumpalo" 5 | version = "3.4.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" 8 | 9 | [[package]] 10 | name = "cfg-if" 11 | version = "0.1.10" 12 | source = "registry+https://github.com/rust-lang/crates.io-index" 13 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 14 | 15 | [[package]] 16 | name = "js-sys" 17 | version = "0.3.44" 18 | source = "registry+https://github.com/rust-lang/crates.io-index" 19 | checksum = "85a7e2c92a4804dd459b86c339278d0fe87cf93757fae222c3fa3ae75458bc73" 20 | dependencies = [ 21 | "wasm-bindgen", 22 | ] 23 | 24 | [[package]] 25 | name = "lazy_static" 26 | version = "1.4.0" 27 | source = "registry+https://github.com/rust-lang/crates.io-index" 28 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 29 | 30 | [[package]] 31 | name = "log" 32 | version = "0.4.11" 33 | source = "registry+https://github.com/rust-lang/crates.io-index" 34 | checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" 35 | dependencies = [ 36 | "cfg-if", 37 | ] 38 | 39 | [[package]] 40 | name = "lvgl_wasm_rust" 41 | version = "0.1.0" 42 | dependencies = [ 43 | "wasm-bindgen", 44 | "web-sys", 45 | ] 46 | 47 | [[package]] 48 | name = "proc-macro2" 49 | version = "1.0.19" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" 52 | dependencies = [ 53 | "unicode-xid", 54 | ] 55 | 56 | [[package]] 57 | name = "quote" 58 | version = "1.0.7" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" 61 | dependencies = [ 62 | "proc-macro2", 63 | ] 64 | 65 | [[package]] 66 | name = "syn" 67 | version = "1.0.38" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" 70 | dependencies = [ 71 | "proc-macro2", 72 | "quote", 73 | "unicode-xid", 74 | ] 75 | 76 | [[package]] 77 | name = "unicode-xid" 78 | version = "0.2.1" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" 81 | 82 | [[package]] 83 | name = "wasm-bindgen" 84 | version = "0.2.67" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c" 87 | dependencies = [ 88 | "cfg-if", 89 | "wasm-bindgen-macro", 90 | ] 91 | 92 | [[package]] 93 | name = "wasm-bindgen-backend" 94 | version = "0.2.67" 95 | source = "registry+https://github.com/rust-lang/crates.io-index" 96 | checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0" 97 | dependencies = [ 98 | "bumpalo", 99 | "lazy_static", 100 | "log", 101 | "proc-macro2", 102 | "quote", 103 | "syn", 104 | "wasm-bindgen-shared", 105 | ] 106 | 107 | [[package]] 108 | name = "wasm-bindgen-macro" 109 | version = "0.2.67" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2" 112 | dependencies = [ 113 | "quote", 114 | "wasm-bindgen-macro-support", 115 | ] 116 | 117 | [[package]] 118 | name = "wasm-bindgen-macro-support" 119 | version = "0.2.67" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" 122 | dependencies = [ 123 | "proc-macro2", 124 | "quote", 125 | "syn", 126 | "wasm-bindgen-backend", 127 | "wasm-bindgen-shared", 128 | ] 129 | 130 | [[package]] 131 | name = "wasm-bindgen-shared" 132 | version = "0.2.67" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092" 135 | 136 | [[package]] 137 | name = "web-sys" 138 | version = "0.3.44" 139 | source = "registry+https://github.com/rust-lang/crates.io-index" 140 | checksum = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47" 141 | dependencies = [ 142 | "js-sys", 143 | "wasm-bindgen", 144 | ] 145 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | # Define the Rust workspace, which contains all Rust projects 2 | 3 | # All projects in the `rust` folder belong to this workspace 4 | [workspace] 5 | members = [ 6 | "rust" 7 | ] -------------------------------------------------------------------------------- /LICENCE.txt: -------------------------------------------------------------------------------- 1 | MIT licence 2 | Copyright (c) 2020 LVGL LLC 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Build LVGL for WebAssembly: wasm/lvgl.html, lvgl.js, lvgl.wasm 2 | 3 | ############################################################################### 4 | # Typical Compile to WebAssembly with emscripten 5 | # emcc hello.c -s WASM=1 -o hello.html 6 | 7 | # Define $(CSRCS) 8 | LVGL_DIR := . 9 | LVGL_DIR_NAME := . 10 | include lvgl.mk 11 | 12 | # WebAssembly C and C++ Source Files 13 | WASM_CSRCS := \ 14 | demo/lv_demo_widgets.c \ 15 | wasm/lv_port_disp.c \ 16 | clock/BatteryIcon.cpp \ 17 | clock/BleController.cpp \ 18 | clock/BleIcon.cpp \ 19 | clock/ClockTmp.cpp \ 20 | clock/ClockHelper.cpp \ 21 | clock/DateTimeController.cpp \ 22 | clock/LittleVgl.cpp \ 23 | clock/jetbrains_mono_bold_20.c \ 24 | clock/jetbrains_mono_extrabold_compressed.c 25 | 26 | # Build LVGL app: wasm/lvgl.html, lvgl.js, lvgl.wasm 27 | TARGETS:= wasm/lvgl 28 | 29 | DEPS := lv_conf.h 30 | 31 | # Use emscripten compiler 32 | CC := emcc 33 | CPP := em++ 34 | 35 | # Options for emscripten. We specify the C and Rust WebAssembly functions to be exported. 36 | CCFLAGS := \ 37 | -g \ 38 | -I src/lv_core \ 39 | -D LV_USE_DEMO_WIDGETS \ 40 | -s WASM=1 \ 41 | -s "EXPORTED_FUNCTIONS=[ '_main', '_get_display_buffer', '_get_display_width', '_get_display_height', '_test_display', '_init_display', '_render_display', '_render_widgets', '_create_clock', '_refresh_clock', '_update_clock' ]" 42 | 43 | LDFLAGS := 44 | 45 | MAINS := $(addsuffix .o, $(TARGETS) ) 46 | OBJ := \ 47 | $(MAINS) \ 48 | $(CSRCS:.c=.o) \ 49 | $(WASM_CSRCS:.c=.o) 50 | 51 | .PHONY: all clean 52 | 53 | all: $(TARGETS) 54 | 55 | clean: 56 | rm *.o || true 57 | rm clock/*.o || true 58 | rm clock/ClockTmp.* || true 59 | rm wasm/*.o || true 60 | rm wasm/*.wasm || true 61 | rm wasm/*.js || true 62 | rm wasm/*.txt || true 63 | rm -r $(HOME)/.emscripten_cache || true 64 | 65 | $(OBJ): %.o : %.c $(DEPS) 66 | $(CC) -c -o $@ $< $(CCFLAGS) 67 | 68 | # TODO: Build C++ files with em++ 69 | # $(OBJ): %.o : %.cpp $(DEPS) 70 | # $(CPP) -c -o $@ $< $(CCFLAGS) 71 | 72 | $(TARGETS): % : $(filter-out $(MAINS), $(OBJ)) %.o 73 | $(CC) -o $@.html \ 74 | -Wl,--start-group \ 75 | $(LIBS) \ 76 | $^ \ 77 | -Wl,--end-group \ 78 | $(CCFLAGS) \ 79 | $(LDFLAGS) 80 | -------------------------------------------------------------------------------- /clock/BatteryController.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | ////#include 3 | 4 | 5 | namespace Pinetime { 6 | namespace Controllers { 7 | class Battery { 8 | public: 9 | void Init(); 10 | void Update(); 11 | float PercentRemaining() const { return percentRemaining; } 12 | float Voltage() const { return voltage; } 13 | bool IsCharging() const { return isCharging; } 14 | bool IsPowerPresent() const { return isPowerPresent; } 15 | 16 | private: 17 | static constexpr uint32_t chargingPin = 12; 18 | static constexpr uint32_t powerPresentPin = 19; 19 | ////static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7; 20 | ////static void SaadcEventHandler(nrfx_saadc_evt_t const * p_event); 21 | float percentRemaining = 0.0f; 22 | float voltage = 0.0f; 23 | bool isCharging = false; 24 | bool isPowerPresent = false; 25 | }; 26 | } 27 | } -------------------------------------------------------------------------------- /clock/BatteryIcon.cpp: -------------------------------------------------------------------------------- 1 | #include "BatteryIcon.h" 2 | #include "Symbols.h" 3 | using namespace Pinetime::Applications::Screens; 4 | 5 | const char* BatteryIcon::GetBatteryIcon(float batteryPercent) { 6 | if(batteryPercent > 90.0f) return Symbols::batteryFull; 7 | if(batteryPercent > 75.0f) return Symbols::batteryThreeQuarter; 8 | if(batteryPercent > 50.0f) return Symbols::batteryHalf; 9 | if(batteryPercent > 25.0f) return Symbols::batteryOneQuarter; 10 | return Symbols::batteryEmpty; 11 | } 12 | 13 | const char* BatteryIcon::GetUnknownIcon() { 14 | return Symbols::batteryEmpty; 15 | } 16 | 17 | const char *BatteryIcon::GetPlugIcon(bool isCharging) { 18 | if(isCharging) 19 | return Symbols::plug; 20 | else return ""; 21 | } 22 | -------------------------------------------------------------------------------- /clock/BatteryIcon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../lv_draw/lv_img_decoder.h"////#include 4 | 5 | namespace Pinetime { 6 | namespace Applications { 7 | namespace Screens { 8 | class BatteryIcon { 9 | public: 10 | static const char* GetUnknownIcon(); 11 | static const char* GetBatteryIcon(float batteryPercent); 12 | static const char* GetPlugIcon(bool isCharging); 13 | }; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /clock/BleController.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "BleController.h" 4 | 5 | using namespace Pinetime::Controllers; 6 | 7 | void Ble::Connect() { 8 | isConnected = true; 9 | } 10 | 11 | void Ble::Disconnect() { 12 | isConnected = false; 13 | } 14 | 15 | void Ble::StartFirmwareUpdate() { 16 | isFirmwareUpdating = true; 17 | } 18 | 19 | void Ble::StopFirmwareUpdate() { 20 | isFirmwareUpdating = false; 21 | } 22 | 23 | void Ble::FirmwareUpdateTotalBytes(uint32_t totalBytes) { 24 | firmwareUpdateTotalBytes = totalBytes; 25 | } 26 | 27 | void Ble::FirmwareUpdateCurrentBytes(uint32_t currentBytes) { 28 | firmwareUpdateCurrentBytes = currentBytes; 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /clock/BleController.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | ////#include 4 | ////#include 5 | #include 6 | 7 | namespace Pinetime { 8 | namespace Controllers { 9 | class Ble { 10 | public: 11 | using BleAddress = std::array; 12 | enum class FirmwareUpdateStates {Idle, Running, Validated, Error}; 13 | enum class AddressTypes { Public, Random }; 14 | 15 | Ble() = default; 16 | bool IsConnected() const {return isConnected;} 17 | void Connect(); 18 | void Disconnect(); 19 | 20 | void StartFirmwareUpdate(); 21 | void StopFirmwareUpdate(); 22 | void FirmwareUpdateTotalBytes(uint32_t totalBytes); 23 | void FirmwareUpdateCurrentBytes(uint32_t currentBytes); 24 | void State(FirmwareUpdateStates state) { firmwareUpdateState = state; } 25 | 26 | bool IsFirmwareUpdating() const { return isFirmwareUpdating; } 27 | uint32_t FirmwareUpdateTotalBytes() const { return firmwareUpdateTotalBytes; } 28 | uint32_t FirmwareUpdateCurrentBytes() const { return firmwareUpdateCurrentBytes; } 29 | FirmwareUpdateStates State() const { return firmwareUpdateState; } 30 | 31 | void Address(BleAddress&& addr) { address = addr; } 32 | const BleAddress& Address() const { return address; } 33 | void AddressType(AddressTypes t) { addressType = t;} 34 | private: 35 | bool isConnected = false; 36 | bool isFirmwareUpdating = false; 37 | uint32_t firmwareUpdateTotalBytes = 0; 38 | uint32_t firmwareUpdateCurrentBytes = 0; 39 | FirmwareUpdateStates firmwareUpdateState = FirmwareUpdateStates::Idle; 40 | BleAddress address; 41 | AddressTypes addressType; 42 | 43 | }; 44 | } 45 | } -------------------------------------------------------------------------------- /clock/BleIcon.cpp: -------------------------------------------------------------------------------- 1 | #include "BleIcon.h" 2 | #include "Symbols.h" 3 | using namespace Pinetime::Applications::Screens; 4 | 5 | const char* BleIcon::GetIcon(bool isConnected) { 6 | if(isConnected) return Symbols::bluetooth; 7 | else return ""; 8 | } -------------------------------------------------------------------------------- /clock/BleIcon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Pinetime { 4 | namespace Applications { 5 | namespace Screens { 6 | class BleIcon { 7 | public: 8 | static const char* GetIcon(bool isConnected); 9 | }; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /clock/Clock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Screen.h" 6 | ////#include 7 | #include "lv_style.h" ////#include 8 | #include "lv_obj.h" ////#include 9 | #include "BatteryController.h" ////#include 10 | #include "BleController.h" ////#include 11 | 12 | namespace Pinetime { 13 | namespace Applications { 14 | namespace Screens { 15 | 16 | template 17 | class DirtyValue { 18 | public: 19 | explicit DirtyValue(T v) { value = v; } 20 | explicit DirtyValue(T& v) { value = v; } 21 | bool IsUpdated() const { return isUpdated; } 22 | T& Get() { this->isUpdated = false; return value; } 23 | 24 | DirtyValue& operator=(const T& other) { 25 | if (this->value != other) { 26 | this->value = other; 27 | this->isUpdated = true; 28 | } 29 | return *this; 30 | } 31 | private: 32 | T value; 33 | bool isUpdated = true; 34 | }; 35 | class Clock : public Screen{ 36 | public: 37 | Clock(DisplayApp* app, 38 | Controllers::DateTime& dateTimeController, 39 | Controllers::Battery& batteryController, 40 | Controllers::Ble& bleController); 41 | ~Clock(); //// override; 42 | 43 | bool Refresh(); //// override; 44 | bool OnButtonPushed(); //// override; 45 | 46 | void OnObjectEvent(lv_obj_t *pObj, lv_event_t i); 47 | private: 48 | static const char* MonthToString(Pinetime::Controllers::DateTime::Months month); 49 | static const char* DayOfWeekToString(Pinetime::Controllers::DateTime::Days dayOfWeek); 50 | static char const *DaysString[]; 51 | static char const *MonthsString[]; 52 | 53 | char displayedChar[5]; 54 | 55 | uint16_t currentYear = 1970; 56 | Pinetime::Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown; 57 | Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; 58 | uint8_t currentDay = 0; 59 | 60 | DirtyValue batteryPercentRemaining {0}; 61 | DirtyValue bleState {false}; 62 | DirtyValue> currentDateTime; 63 | DirtyValue stepCount {0}; 64 | DirtyValue heartbeat {0}; 65 | 66 | 67 | lv_obj_t* label_time; 68 | lv_obj_t* label_date; 69 | lv_obj_t* backgroundLabel; 70 | lv_obj_t * batteryIcon; 71 | lv_obj_t * bleIcon; 72 | lv_obj_t* batteryPlug; 73 | lv_obj_t* heartbeatIcon; 74 | lv_obj_t* heartbeatValue; 75 | lv_obj_t* heartbeatBpm; 76 | lv_obj_t* stepIcon; 77 | lv_obj_t* stepValue; 78 | 79 | Controllers::DateTime& dateTimeController; 80 | Controllers::Battery& batteryController; 81 | Controllers::Ble& bleController; 82 | 83 | bool running = true; 84 | 85 | }; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /clock/ClockHelper.cpp: -------------------------------------------------------------------------------- 1 | //// WebAssembly Helper 2 | #include 3 | #include 4 | #include "LittleVgl.h" 5 | #include "Clock.h" 6 | #include "ClockHelper.h" 7 | 8 | static Pinetime::Components::LittleVgl *littleVgl0 = nullptr; 9 | static Pinetime::Drivers::St7789 *lcd0 = nullptr; 10 | static Pinetime::Drivers::Cst816S *touchPanel0 = nullptr; 11 | static Pinetime::Applications::Screens::Clock *clock0 = nullptr; 12 | static DisplayApp *app0 = nullptr; 13 | static Pinetime::Controllers::DateTime *dateTimeController0 = nullptr; 14 | static Pinetime::Controllers::Battery *batteryController0 = nullptr; 15 | static Pinetime::Controllers::Ble *bleController0 = nullptr; 16 | extern lv_style_t* LabelBigStyle; 17 | 18 | /// Create an instance of the clock 19 | int create_clock(void) { 20 | puts("In C++: Creating clock..."); 21 | 22 | // Init LVGL styles 23 | lcd0 = new Pinetime::Drivers::St7789(); 24 | touchPanel0 = new Pinetime::Drivers::Cst816S(); 25 | littleVgl0 = new Pinetime::Components::LittleVgl( 26 | *lcd0, 27 | *touchPanel0 28 | ); 29 | assert(LabelBigStyle != nullptr); 30 | 31 | // Create clock 32 | app0 = new DisplayApp(); 33 | dateTimeController0 = new Pinetime::Controllers::DateTime(); 34 | batteryController0 = new Pinetime::Controllers::Battery(); 35 | bleController0 = new Pinetime::Controllers::Ble(); 36 | clock0 = new Pinetime::Applications::Screens::Clock( 37 | app0, 38 | *dateTimeController0, 39 | *batteryController0, 40 | *bleController0 41 | ); 42 | return 0; 43 | } 44 | 45 | /// Redraw the clock 46 | int refresh_clock(void) { 47 | puts("In C++: Refreshing clock..."); 48 | assert(clock0 != nullptr); 49 | clock0->Refresh(); 50 | return 0; 51 | } 52 | 53 | /// Update the clock time. Use generic "int" type to prevent JavaScript-WebAssembly interoperability problems. 54 | int update_clock(int year, int month, int day, 55 | int hour, int minute, int second) { 56 | puts("In C++: Updating clock..."); 57 | assert(dateTimeController0 != nullptr); 58 | dateTimeController0->SetTime( 59 | year, month, day, 60 | 0, // Auto compute day of week 61 | hour, minute, second, 62 | 0 // Offset for systick counter 63 | ); 64 | return 0; 65 | } -------------------------------------------------------------------------------- /clock/ClockHelper.h: -------------------------------------------------------------------------------- 1 | //// WebAssembly Helper 2 | #ifndef CLOCKHELPER_H 3 | #define CLOCKHELPER_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /// Create an instance of the clock 10 | int create_clock(void); 11 | 12 | /// Redraw the clock 13 | int refresh_clock(void); 14 | 15 | /// Update the clock time 16 | int update_clock(int year, int month, int day, 17 | int hour, int minute, int second); 18 | 19 | #ifdef __cplusplus 20 | } // extern "C" 21 | #endif 22 | 23 | #endif // CLOCKHELPER_H -------------------------------------------------------------------------------- /clock/DateTimeController.cpp: -------------------------------------------------------------------------------- 1 | #include "DateTimeController.h" 2 | #include "date.h" ////#include 3 | ////#include 4 | using namespace Pinetime::Controllers; 5 | 6 | #define NRF_LOG_INFO(...) //// 7 | 8 | void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, 9 | uint8_t second, uint32_t systickCounter) { 10 | std::tm tm = { /* .tm_sec = */ second, 11 | /* .tm_min = */ minute, 12 | /* .tm_hour = */ hour, 13 | /* .tm_mday = */ day, 14 | /* .tm_mon = */ month - 1, 15 | /* .tm_year = */ year - 1900, 16 | }; 17 | tm.tm_isdst = -1; // Use DST value from local time zone 18 | currentDateTime = std::chrono::system_clock::from_time_t(std::mktime(&tm)); 19 | 20 | NRF_LOG_INFO("%d %d %d ", day, month, year); 21 | NRF_LOG_INFO("%d %d %d ", hour, minute, second); 22 | previousSystickCounter = systickCounter; 23 | 24 | UpdateTime(systickCounter); 25 | NRF_LOG_INFO("* %d %d %d ", this->hour, this->minute, this->second); 26 | NRF_LOG_INFO("* %d %d %d ", this->day, this->month, this->year); 27 | } 28 | 29 | void DateTime::UpdateTime(uint32_t systickCounter) { 30 | // Handle systick counter overflow 31 | uint32_t systickDelta = 0; 32 | if(systickCounter < previousSystickCounter) { 33 | systickDelta = 0xffffff - previousSystickCounter; 34 | systickDelta += systickCounter + 1; 35 | } else { 36 | systickDelta = systickCounter - previousSystickCounter; 37 | } 38 | 39 | /* 40 | * 1000 ms = 1024 ticks 41 | */ 42 | auto correctedDelta = systickDelta / 1024; 43 | auto rest = (systickDelta - (correctedDelta*1024)); 44 | if(systickCounter >= rest) { 45 | previousSystickCounter = systickCounter - rest; 46 | } else { 47 | previousSystickCounter = 0xffffff - (rest - systickCounter); 48 | } 49 | 50 | currentDateTime += std::chrono::seconds(correctedDelta); 51 | uptime += std::chrono::seconds(correctedDelta); 52 | 53 | auto dp = date::floor(currentDateTime); 54 | auto time = date::make_time(currentDateTime-dp); 55 | auto yearMonthDay = date::year_month_day(dp); 56 | 57 | year = (int)yearMonthDay.year(); 58 | month = static_cast((unsigned)yearMonthDay.month()); 59 | day = (unsigned)yearMonthDay.day(); 60 | dayOfWeek = static_cast(date::weekday(yearMonthDay).iso_encoding()); 61 | 62 | hour = time.hours().count(); 63 | minute = time.minutes().count(); 64 | second = time.seconds().count(); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /clock/DateTimeController.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Pinetime { 7 | namespace Controllers { 8 | class DateTime { 9 | public: 10 | enum class Days : uint8_t {Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}; 11 | enum class Months : uint8_t {Unknown, January, February, March, April, May, June, July, August, September, October, November, December}; 12 | 13 | void SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter); 14 | void UpdateTime(uint32_t systickCounter); 15 | uint16_t Year() const { return year; } 16 | Months Month() const { return month; } 17 | uint8_t Day() const { return day; } 18 | Days DayOfWeek() const { return dayOfWeek; } 19 | uint8_t Hours() const { return hour; } 20 | uint8_t Minutes() const { return minute; } 21 | uint8_t Seconds() const { return second; } 22 | 23 | std::chrono::time_point CurrentDateTime() const { return currentDateTime; } 24 | std::chrono::seconds Uptime() const { return uptime; } 25 | private: 26 | uint16_t year = 0; 27 | Months month = Months::Unknown; 28 | uint8_t day = 0; 29 | Days dayOfWeek = Days::Unknown; 30 | uint8_t hour = 0; 31 | uint8_t minute = 0; 32 | uint8_t second = 0; 33 | 34 | uint32_t previousSystickCounter = 0; 35 | std::chrono::time_point currentDateTime; 36 | std::chrono::seconds uptime {0}; 37 | }; 38 | } 39 | } -------------------------------------------------------------------------------- /clock/DisplayApp.h: -------------------------------------------------------------------------------- 1 | //// Mock Class 2 | #ifndef DISPLAYAPP_H 3 | #define DISPLAYAPP_H 4 | 5 | /// Change LVGL v6 lv_label_set_style() to LVGL v7 lv_obj_reset_style_list() and lv_obj_add_style() 6 | #define lv_label_set_style(label, style_type, style) \ 7 | { \ 8 | lv_obj_reset_style_list(label, LV_LABEL_PART_MAIN); \ 9 | lv_obj_add_style(label, LV_LABEL_PART_MAIN, style); \ 10 | } 11 | 12 | /// Used by Clock.cpp 13 | namespace Pinetime { 14 | namespace Applications { 15 | namespace Screens { 16 | class Clock; 17 | static Clock *backgroundLabel_user_data = nullptr; 18 | } 19 | } 20 | } 21 | 22 | class DisplayApp {}; 23 | 24 | #endif // DISPLAYAPP_H 25 | -------------------------------------------------------------------------------- /clock/Screen.h: -------------------------------------------------------------------------------- 1 | //// Mock Class 2 | #ifndef SCREEN_H 3 | #define SCREEN_H 4 | 5 | #include "DisplayApp.h" 6 | #include "DateTimeController.h" 7 | 8 | class Screen {}; 9 | 10 | #endif // SCREEN_H -------------------------------------------------------------------------------- /clock/Symbols.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Pinetime { 4 | namespace Applications { 5 | namespace Screens { 6 | namespace Symbols { 7 | static constexpr char* batteryFull = "\xEF\x89\x80"; 8 | static constexpr char* batteryEmpty = "\xEF\x89\x84"; 9 | static constexpr char* batteryThreeQuarter = "\xEF\x89\x81"; 10 | static constexpr char* batteryHalf = "\xEF\x89\x82"; 11 | static constexpr char* batteryOneQuarter = "\xEF\x89\x83"; 12 | static constexpr char* heartBeat = "\xEF\x88\x9E"; 13 | static constexpr char* bluetoothFull = "\xEF\x8A\x93"; 14 | static constexpr char* bluetooth = "\xEF\x8A\x94"; 15 | static constexpr char* plug = "\xEF\x87\xA6"; 16 | static constexpr char* shoe = "\xEF\x95\x8B"; 17 | static constexpr char* clock = "\xEF\x80\x97"; 18 | static constexpr char* info = "\xEF\x84\xA9"; 19 | static constexpr char* list = "\xEF\x80\xBA"; 20 | static constexpr char* sun = "\xEF\x86\x85"; 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /demo/lv_demo_widgets.h: -------------------------------------------------------------------------------- 1 | // From https://github.com/lvgl/lv_examples/blob/master/src/lv_demo_widgets/lv_demo_widgets.h 2 | /** 3 | * @file lv_demo_widgets.h 4 | * 5 | */ 6 | 7 | #ifndef LV_DEMO_WIDGETS_H 8 | #define LV_DEMO_WIDGETS_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | void lv_demo_widgets(void); 30 | 31 | /********************** 32 | * MACROS 33 | **********************/ 34 | 35 | #ifdef __cplusplus 36 | } /* extern "C" */ 37 | #endif 38 | 39 | #endif /*LV_DEMO_WIDGETS_H*/ -------------------------------------------------------------------------------- /docs/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [atom@github.com](mailto:atom@github.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /docs/CODING_STYLE.md: -------------------------------------------------------------------------------- 1 | # Coding style 2 | 3 | ## File format 4 | Use [lv_misc/lv_templ.c](https://github.com/lvgl/lvgl/blob/master/src/lv_misc/lv_templ.c) and [lv_misc/lv_templ.h](https://github.com/lvgl/lvgl/blob/master/src/lv_misc/lv_templ.h) 5 | 6 | ## Naming conventions 7 | * Words are separated by '_' 8 | * In variable and function names use only lower case letters (e.g. *height_tmp*) 9 | * In enums and defines use only upper case letters (e.g. *e.g. MAX_LINE_NUM*) 10 | * Global names (API): 11 | * starts with *lv* 12 | * followed by module name: *btn*, *label*, *style* etc. 13 | * followed by the action (for functions): *set*, *get*, *refr* etc. 14 | * closed with the subject: *name*, *size*, *state* etc. 15 | * Typedefs 16 | * prefer `typedef struct` and `typedef enum` instead of `struct name` and `enum name` 17 | * always end `typedef struct` and `typedef enum` type names with `_t` 18 | * Abbreviations: 19 | * Only words longer or equal than 6 characters can be abbreviated. 20 | * Abbreviate only if it makes the word at least half as long 21 | * Use only very straightforward and well-known abbreviations (e.g. pos: position, def: default, btn: button) 22 | 23 | ## Coding guide 24 | * Functions: 25 | * Try to write function shorter than is 50 lines 26 | * Always shorter than 200 lines (except very straightforwards) 27 | * Variables: 28 | * One line, one declaration (BAD: char x, y;) 29 | * Use `` (*uint8_t*, *int32_t* etc) 30 | * Declare variables where needed (not all at function start) 31 | * Use the smallest required scope 32 | * Variables in a file (outside functions) are always *static* 33 | * Do not use global variables (use functions to set/get static variables) 34 | 35 | ## Comments 36 | Before every function have a comment like this: 37 | 38 | ```c 39 | /** 40 | * Return with the screen of an object 41 | * @param obj pointer to an object 42 | * @return pointer to a screen 43 | */ 44 | lv_obj_t * lv_obj_get_scr(lv_obj_t * obj); 45 | ``` 46 | 47 | Always use `/* Something */` format and NOT `//Something` 48 | 49 | Write readable code to avoid descriptive comments like: 50 | `x++; /* Add 1 to x */`. 51 | The code should show clearly what you are doing. 52 | 53 | You should write **why** have you done this: 54 | `x++; /*Because of closing '\0' of the string */` 55 | 56 | Short "code summaries" of a few lines are accepted. E.g. `/*Calculate the new coordinates*/` 57 | 58 | In comments use \` \` when referring to a variable. E.g. ``/*Update the value of `x_act`*/`` 59 | 60 | ### Formatting 61 | Here is example to show bracket placing and using of white spaces: 62 | ```c 63 | /** 64 | * Set a new text for a label. Memory will be allocated to store the text by the label. 65 | * @param label pointer to a label object 66 | * @param text '\0' terminated character string. NULL to refresh with the current text. 67 | */ 68 | void lv_label_set_text(lv_obj_t * label, const char * text) 69 | { /* Main brackets of functions in new line*/ 70 | 71 | if(label == NULL) return; /*No bracket only if the command is inline with the if statement*/ 72 | 73 | lv_obj_inv(label); 74 | 75 | lv_label_ext_t * ext = lv_obj_get_ext(label); 76 | 77 | /*Comment before a section */ 78 | if(text == ext->txt || text == NULL) { /*Bracket of statements start inline*/ 79 | lv_label_refr_text(label); 80 | return; 81 | } 82 | 83 | ... 84 | } 85 | ``` 86 | 87 | Use 4 spaces indentation instead of tab. 88 | 89 | You can use **astyle** to format the code. Run `code-formatter.sh` from the `scrips` folder. 90 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to LVGL 2 | 3 | Thank you for considering contributing to LVGL. 4 | 5 | For a detailed description of contribution opportunities, please visit the [Contributing](https://docs.lvgl.io/latest/en/html/contributing/index.html) section of the documentation. 6 | -------------------------------------------------------------------------------- /docs/ROADMAP.md: -------------------------------------------------------------------------------- 1 | # Roadmap 2 | 3 | This is a summary for thenew fatures of the major releases and a collection of ideas. 4 | 5 | This list indicates only the current intention and can be changed. 6 | 7 | ## v8 8 | Planned to September/October 2020 9 | - New scrolling: 10 | - See [feat/new-scroll](https://github.com/lvgl/lvgl/tree/feat/new-scroll) branch and [#1614](https://github.com/lvgl/lvgl/issues/1614)) issue. 11 | - Remove `lv_page` and support scrolling on `lv_obj` 12 | - Support "elastic" scrolling when scrolled in 13 | - Support scroll chaining among any objects types (not only `lv_pages`s) 14 | - Remove `lv_drag`. Similar effect can be achieved by setting the position in `LV_EVENT_PRESSING` 15 | - Add snapping? 16 | - Already working 17 | - New layouts: 18 | - See [#1615](https://github.com/lvgl/lvgl/issues/1615) issue 19 | - [CSS Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/)-like layout support 20 | - Besides setting width/height in `px` add support to `partent percentage` and `screen percentage`. 21 | - Work in progress 22 | - Simplified File system interface ([feat/new_fs_api](https://github.com/lvgl/lvgl/tree/feat/new-fs-api) branch) to make porting easier 23 | - Work in progress 24 | - Add new label alignment modes 25 | - See [#1656](https://github.com/lvgl/lvgl/issues/1656) 26 | - Remove the align parameter from `lv_canvas_draw_text` 27 | 28 | ## v9 29 | - Simplify `group`s. Discussion is [here](https://forum.lvgl.io/t/lv-group-tabindex/2927/3). 30 | 31 | ## Ideas 32 | - Unit testing (gtest?). See [#1658](https://github.com/lvgl/lvgl/issues/1658) 33 | - Benchmarking (gem5?). See [#1660](https://github.com/lvgl/lvgl/issues/1660) 34 | - CPP binding. See [Forum](https://forum.lvgl.io/t/is-it-possible-to-officially-support-optional-cpp-api/2736) 35 | - Optmize font decompression 36 | - Switch to RGBA colors in styles 37 | - Need coverage report for tests 38 | - Need static analize (via coverity.io or somehing else) 39 | - Support dot_begin and dot_middle long modes for labels 40 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | [PineTime Watch Face Simulator](lvgl.html) 2 | -------------------------------------------------------------------------------- /docs/lvgl.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/docs/lvgl.wasm -------------------------------------------------------------------------------- /docs/lvgl2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/docs/lvgl2.wasm -------------------------------------------------------------------------------- /docs/rust.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/docs/rust.wasm -------------------------------------------------------------------------------- /docs/test.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/docs/test.wasm -------------------------------------------------------------------------------- /docs/test_rust.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/docs/test_rust.wasm -------------------------------------------------------------------------------- /examples/arduino/ESP32_TFT_eSPI/ESP32_TFT_eSPI.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TFT_eSPI tft = TFT_eSPI(); /* TFT instance */ 5 | static lv_disp_buf_t disp_buf; 6 | static lv_color_t buf[LV_HOR_RES_MAX * 10]; 7 | 8 | #if USE_LV_LOG != 0 9 | /* Serial debugging */ 10 | void my_print(lv_log_level_t level, const char * file, uint32_t line, const char * dsc) 11 | { 12 | 13 | Serial.printf("%s@%d->%s\r\n", file, line, dsc); 14 | Serial.flush(); 15 | } 16 | #endif 17 | 18 | /* Display flushing */ 19 | void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) 20 | { 21 | uint32_t w = (area->x2 - area->x1 + 1); 22 | uint32_t h = (area->y2 - area->y1 + 1); 23 | 24 | tft.startWrite(); 25 | tft.setAddrWindow(area->x1, area->y1, w, h); 26 | tft.pushColors(&color_p->full, w * h, true); 27 | tft.endWrite(); 28 | 29 | lv_disp_flush_ready(disp); 30 | } 31 | 32 | /*Read the touchpad*/ 33 | bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) 34 | { 35 | uint16_t touchX, touchY; 36 | 37 | bool touched = tft.getTouch(&touchX, &touchY, 600); 38 | 39 | if(!touched) 40 | { 41 | data->state = LV_INDEV_STATE_REL; 42 | return false; 43 | } 44 | else 45 | { 46 | data->state = LV_INDEV_STATE_PR; 47 | } 48 | 49 | if(touchX>screenWidth || touchY > screenHeight) 50 | { 51 | Serial.println("Y or y outside of expected parameters.."); 52 | Serial.print("y:"); 53 | Serial.print(touchX); 54 | Serial.print(" x:"); 55 | Serial.print(touchY); 56 | } 57 | else 58 | { 59 | /*Set the coordinates*/ 60 | data->point.x = touchX; 61 | data->point.y = touchY; 62 | 63 | Serial.print("Data x"); 64 | Serial.println(touchX); 65 | 66 | Serial.print("Data y"); 67 | Serial.println(touchY); 68 | 69 | } 70 | 71 | return false; /*Return `false` because we are not buffering and no more data to read*/ 72 | } 73 | 74 | void setup() 75 | { 76 | Serial.begin(115200); /* prepare for possible serial debug */ 77 | 78 | lv_init(); 79 | 80 | #if USE_LV_LOG != 0 81 | lv_log_register_print_cb(my_print); /* register print function for debugging */ 82 | #endif 83 | 84 | tft.begin(); /* TFT init */ 85 | tft.setRotation(1); /* Landscape orientation */ 86 | 87 | uint16_t calData[5] = { 275, 3620, 264, 3532, 1 }; 88 | tft.setTouch(calData); 89 | 90 | lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); 91 | 92 | /*Initialize the display*/ 93 | lv_disp_drv_t disp_drv; 94 | lv_disp_drv_init(&disp_drv); 95 | disp_drv.hor_res = 320; 96 | disp_drv.ver_res = 240; 97 | disp_drv.flush_cb = my_disp_flush; 98 | disp_drv.buffer = &disp_buf; 99 | lv_disp_drv_register(&disp_drv); 100 | 101 | /*Initialize the (dummy) input device driver*/ 102 | lv_indev_drv_t indev_drv; 103 | lv_indev_drv_init(&indev_drv); 104 | indev_drv.type = LV_INDEV_TYPE_POINTER; 105 | indev_drv.read_cb = my_touchpad_read; 106 | lv_indev_drv_register(&indev_drv); 107 | 108 | /* Try an example from the lv_examples repository 109 | * https://github.com/lvgl/lv_examples*/ 110 | lv_ex_btn_1(); 111 | } 112 | 113 | 114 | void loop() 115 | { 116 | 117 | lv_task_handler(); /* let the GUI do its work */ 118 | delay(5); 119 | } 120 | -------------------------------------------------------------------------------- /examples/arduino/ESP32_TFT_eSPI/README.md: -------------------------------------------------------------------------------- 1 | # Example for lv_arduino using a slider 2 | 3 | This example has the screen set to 320x480 (ILI9488), change this by altering the following lines in the main ino file: 4 | 5 | ```C 6 | int screenWidth = 480; 7 | int screenHeight = 320; 8 | ``` 9 | 10 | ## Backlight 11 | 12 | Change pin 32 to your preferred backlight pin using a PNP transistor (2N3906) or remove the following code and connect directly to +ve: 13 | 14 | ```C 15 | ledcSetup(10, 5000/*freq*/, 10 /*resolution*/); 16 | ledcAttachPin(32, 10); 17 | analogReadResolution(10); 18 | ledcWrite(10,768); 19 | ``` 20 | 21 | ## Theme selection 22 | 23 | Change the following to change the theme: 24 | 25 | ```C 26 | lv_theme_t * th = lv_theme_night_init(210, NULL); //Set a HUE value and a Font for the Night Theme 27 | lv_theme_set_current(th); 28 | ``` 29 | 30 | ## Calibration 31 | 32 | This is using the bodmer tft_espi driver for touch. To correctly set the calibration load the calibration sketch and replace the following with your values: 33 | 34 | ```C 35 | uint16_t calData[5] = { 275, 3620, 264, 3532, 1 }; 36 | ``` 37 | 38 | ## Screen rotation 39 | 40 | Check the following if you need to alter your screen rotation: 41 | 42 | ```C 43 | tft.setRotation(3); 44 | ``` 45 | -------------------------------------------------------------------------------- /examples/arduino/README.md: -------------------------------------------------------------------------------- 1 | # LVGL Arduino examples 2 | 3 | LVGL can be installed via Arduino IDE Library Manager or as an .ZIP library. 4 | It will install [lv_exmaples](https://github.com/lvgl/lv_examples) which contains a lot of examples and demos to try LVGL. 5 | 6 | ## Example 7 | 8 | There are simple examples which use the [TFT_eSPI](https://github.com/Bodmer/TFT_eSPI) library as a TFT driver to simplify testing. 9 | To get all this to work you have to setup TFT_eSPI to work with your TFT display type via editing the `User_Setup.h` file in TFT_eSPI library folder, or by selecting your own configurtion in the `User_Setup_Select.h` file in TFT_eSPI library folder. 10 | 11 | LVGL library has its own configuration file called `lv_conf.h`. When LVGL is installed to followings needs to be done to configure it: 12 | 1. Go to directory of the installed Arduno libraries 13 | 2. Go to `lvgl` and copy `lv_conf_template.h` as `lvgl.h` next to the `lvgl` folder. 14 | 3. Open `lv_conf.h` and change the first `#if 0` to `#if 1` 15 | 4. Set the resolution of your display in `LV_HOR_RES_MAX` and `LV_VER_RES_MAX` 16 | 5. Set the color depth of you display in `LV_COLOR_DEPTH` 17 | 6. Set `LV_TICK_CUSTOM 1` 18 | 19 | ## Debugging 20 | 21 | In case of trouble there are debug informations inside LVGL. In the `ESP32_TFT_eSPI` example there is `my_print` method, which allow to send this debug informations to the serial interface. To enable this feature you have to edit `lv_conf.h` file and enable logging in section `log settings`: 22 | 23 | ```c 24 | /*Log settings*/ 25 | #define USE_LV_LOG 1 /*Enable/disable the log module*/ 26 | #if LV_USE_LOG 27 | /* How important log should be added: 28 | * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information 29 | * LV_LOG_LEVEL_INFO Log important events 30 | * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem 31 | * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail 32 | * LV_LOG_LEVEL_NONE Do not log anything 33 | */ 34 | # define LV_LOG_LEVEL LV_LOG_LEVEL_WARN 35 | ``` 36 | 37 | After enabling log module and setting LV_LOG_LEVEL accordingly the output log is sent to the `Serial` port @ 115200 Bd. 38 | -------------------------------------------------------------------------------- /examples/porting/lv_port_disp_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_port_disp_templ.h 3 | * 4 | */ 5 | 6 | /*Copy this file as "lv_port_disp.h" and set this value to "1" to enable content*/ 7 | #if 0 8 | 9 | #ifndef LV_PORT_DISP_TEMPL_H 10 | #define LV_PORT_DISP_TEMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /********************* 17 | * INCLUDES 18 | *********************/ 19 | #include "lvgl/lvgl.h" 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /********************** 30 | * GLOBAL PROTOTYPES 31 | **********************/ 32 | 33 | /********************** 34 | * MACROS 35 | **********************/ 36 | 37 | 38 | #ifdef __cplusplus 39 | } /* extern "C" */ 40 | #endif 41 | 42 | #endif /*LV_PORT_DISP_TEMPL_H*/ 43 | 44 | #endif /*Disable/Enable content*/ 45 | -------------------------------------------------------------------------------- /examples/porting/lv_port_fs_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_port_fs_templ.h 3 | * 4 | */ 5 | 6 | /*Copy this file as "lv_port_fs.h" and set this value to "1" to enable content*/ 7 | #if 0 8 | 9 | #ifndef LV_PORT_FS_TEMPL_H 10 | #define LV_PORT_FS_TEMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /********************* 17 | * INCLUDES 18 | *********************/ 19 | #include "lvgl/lvgl.h" 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /********************** 30 | * GLOBAL PROTOTYPES 31 | **********************/ 32 | 33 | /********************** 34 | * MACROS 35 | **********************/ 36 | 37 | 38 | #ifdef __cplusplus 39 | } /* extern "C" */ 40 | #endif 41 | 42 | #endif /*LV_PORT_FS_TEMPL_H*/ 43 | 44 | #endif /*Disable/Enable content*/ 45 | -------------------------------------------------------------------------------- /examples/porting/lv_port_indev_template.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file lv_port_indev_templ.h 4 | * 5 | */ 6 | 7 | /*Copy this file as "lv_port_indev.h" and set this value to "1" to enable content*/ 8 | #if 0 9 | 10 | #ifndef LV_PORT_INDEV_TEMPL_H 11 | #define LV_PORT_INDEV_TEMPL_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | /********************* 18 | * INCLUDES 19 | *********************/ 20 | #include "lvgl/lvgl.h" 21 | 22 | /********************* 23 | * DEFINES 24 | *********************/ 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | /********************** 31 | * GLOBAL PROTOTYPES 32 | **********************/ 33 | 34 | /********************** 35 | * MACROS 36 | **********************/ 37 | 38 | 39 | #ifdef __cplusplus 40 | } /* extern "C" */ 41 | #endif 42 | 43 | #endif /*LV_PORT_INDEV_TEMPL_H*/ 44 | 45 | #endif /*Disable/Enable content*/ 46 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lvgl", 3 | "version": "7.3.0", 4 | "keywords": "graphics, gui, embedded, tft, lvgl", 5 | "description": "Graphics library to create embedded GUI with easy-to-use graphical elements, beautiful visual effects and low memory footprint. It offers anti-aliasing, opacity, and animations using only one frame buffer.", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/lvgl/lvgl.git" 9 | }, 10 | "build": { 11 | "includeDir": "." 12 | }, 13 | "license": "MIT", 14 | "homepage": "https://lvgl.io", 15 | "frameworks": "*", 16 | "platforms": "*" 17 | } 18 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=lvgl 2 | version=7.3.0 3 | author=kisvegabor 4 | maintainer=kisvegabor,embeddedt,pete-pjb 5 | sentence=Full-featured Graphics Library for Embedded Systems 6 | paragraph=Powerful and easy-to-use embedded GUI with many widgets, advanced visual effects (opacity, antialiasing, animations) and low memory requirements (16K RAM, 64K Flash). 7 | category=Display 8 | url=https://lvgl.io 9 | architectures=* 10 | includes=lvgl.h 11 | -------------------------------------------------------------------------------- /lvgl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lvgl.h 3 | * Include all LittleV GL related headers 4 | */ 5 | 6 | #ifndef LVGL_H 7 | #define LVGL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #include "src/lv_misc/lv_log.h" 18 | #include "src/lv_misc/lv_task.h" 19 | #include "src/lv_misc/lv_math.h" 20 | #include "src/lv_misc/lv_async.h" 21 | 22 | #include "src/lv_hal/lv_hal.h" 23 | 24 | #include "src/lv_core/lv_obj.h" 25 | #include "src/lv_core/lv_group.h" 26 | #include "src/lv_core/lv_indev.h" 27 | 28 | #include "src/lv_core/lv_refr.h" 29 | #include "src/lv_core/lv_disp.h" 30 | 31 | #include "src/lv_themes/lv_theme.h" 32 | 33 | #include "src/lv_font/lv_font.h" 34 | #include "src/lv_font/lv_font_fmt_txt.h" 35 | #include "src/lv_misc/lv_printf.h" 36 | 37 | #include "src/lv_widgets/lv_btn.h" 38 | #include "src/lv_widgets/lv_imgbtn.h" 39 | #include "src/lv_widgets/lv_img.h" 40 | #include "src/lv_widgets/lv_label.h" 41 | #include "src/lv_widgets/lv_line.h" 42 | #include "src/lv_widgets/lv_page.h" 43 | #include "src/lv_widgets/lv_cont.h" 44 | #include "src/lv_widgets/lv_list.h" 45 | #include "src/lv_widgets/lv_chart.h" 46 | #include "src/lv_widgets/lv_table.h" 47 | #include "src/lv_widgets/lv_checkbox.h" 48 | #include "src/lv_widgets/lv_cpicker.h" 49 | #include "src/lv_widgets/lv_bar.h" 50 | #include "src/lv_widgets/lv_slider.h" 51 | #include "src/lv_widgets/lv_led.h" 52 | #include "src/lv_widgets/lv_btnmatrix.h" 53 | #include "src/lv_widgets/lv_keyboard.h" 54 | #include "src/lv_widgets/lv_dropdown.h" 55 | #include "src/lv_widgets/lv_roller.h" 56 | #include "src/lv_widgets/lv_textarea.h" 57 | #include "src/lv_widgets/lv_canvas.h" 58 | #include "src/lv_widgets/lv_win.h" 59 | #include "src/lv_widgets/lv_tabview.h" 60 | #include "src/lv_widgets/lv_tileview.h" 61 | #include "src/lv_widgets/lv_msgbox.h" 62 | #include "src/lv_widgets/lv_objmask.h" 63 | #include "src/lv_widgets/lv_gauge.h" 64 | #include "src/lv_widgets/lv_linemeter.h" 65 | #include "src/lv_widgets/lv_switch.h" 66 | #include "src/lv_widgets/lv_arc.h" 67 | #include "src/lv_widgets/lv_spinner.h" 68 | #include "src/lv_widgets/lv_calendar.h" 69 | #include "src/lv_widgets/lv_spinbox.h" 70 | 71 | #include "src/lv_draw/lv_img_cache.h" 72 | 73 | #include "src/lv_api_map.h" 74 | 75 | /********************* 76 | * DEFINES 77 | *********************/ 78 | /*Current version of LVGL*/ 79 | #define LVGL_VERSION_MAJOR 7 80 | #define LVGL_VERSION_MINOR 3 81 | #define LVGL_VERSION_PATCH 1 82 | #define LVGL_VERSION_INFO "dev" 83 | 84 | /********************** 85 | * TYPEDEFS 86 | **********************/ 87 | 88 | /********************** 89 | * GLOBAL PROTOTYPES 90 | **********************/ 91 | 92 | /********************** 93 | * MACROS 94 | **********************/ 95 | 96 | /** Gives 1 if the x.y.z version is supported in the current version 97 | * Usage: 98 | * 99 | * - Require v6 100 | * #if LV_VERSION_CHECK(6,0,0) 101 | * new_func_in_v6(); 102 | * #endif 103 | * 104 | * 105 | * - Require at least v5.3 106 | * #if LV_VERSION_CHECK(5,3,0) 107 | * new_feature_from_v5_3(); 108 | * #endif 109 | * 110 | * 111 | * - Require v5.3.2 bugfixes 112 | * #if LV_VERSION_CHECK(5,3,2) 113 | * bugfix_in_v5_3_2(); 114 | * #endif 115 | * 116 | * */ 117 | #define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) 118 | 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | #endif /*LVGL_H*/ 125 | -------------------------------------------------------------------------------- /lvgl.mk: -------------------------------------------------------------------------------- 1 | include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_core/lv_core.mk 2 | include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_hal/lv_hal.mk 3 | include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_widgets/lv_widgets.mk 4 | include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_font/lv_font.mk 5 | include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_misc/lv_misc.mk 6 | include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_themes/lv_themes.mk 7 | include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_draw/lv_draw.mk 8 | include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_gpu/lv_gpu.mk 9 | 10 | 11 | -------------------------------------------------------------------------------- /rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lvgl_wasm_rust" 3 | version = "0.1.0" 4 | authors = ["luppy@appkaki.com"] 5 | edition = "2018" 6 | 7 | [lib] 8 | crate-type = ["staticlib"] 9 | #crate-type = ["cdylib"] 10 | 11 | [dependencies] 12 | wasm-bindgen = "0.2.67" 13 | 14 | [dependencies.web-sys] 15 | version = "0.3.4" 16 | features = [ 17 | 'ImageData', 18 | 'CanvasRenderingContext2d', 19 | ] 20 | -------------------------------------------------------------------------------- /rust/README.md: -------------------------------------------------------------------------------- 1 | # Rust WebAssembly Modules for LVGL 2 | 3 | Based on... 4 | 5 | https://rustwasm.github.io/docs/book/reference/js-ffi.html 6 | 7 | https://kripken.github.io/blog/binaryen/2018/04/18/rust-emscripten.html 8 | 9 | -------------------------------------------------------------------------------- /rust/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 |
11 |

C =

12 |
13 | 14 | 15 |
16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 |
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /rust/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | Fails with error: 3 | lvgl_wasm_rust_bg.wasm:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "application/wasm". Strict MIME type checking is enforced for module scripts per HTML spec. 4 | TypeError: Failed to fetch dynamically imported module: https://appkaki.github.io/lvgl-wasm/rust/pkg/lvgl_wasm_rust.js 5 | Promise.catch (async) 6 | (anonymous) @ index.js:18 7 | */ 8 | import('./pkg/lvgl_wasm_rust.js') 9 | .then(wasm => { 10 | const canvas = document.getElementById('drawing'); 11 | const ctx = canvas.getContext('2d'); 12 | 13 | const realInput = document.getElementById('real'); 14 | const imaginaryInput = document.getElementById('imaginary'); 15 | const renderBtn = document.getElementById('render'); 16 | 17 | renderBtn.addEventListener('click', () => { 18 | const real = parseFloat(realInput.value) || 0; 19 | const imaginary = parseFloat(imaginaryInput.value) || 0; 20 | wasm.draw(ctx, 600, 600, real, imaginary); 21 | }); 22 | 23 | wasm.draw(ctx, 600, 600, -0.15, 0.65); 24 | }) 25 | .catch(console.error); 26 | -------------------------------------------------------------------------------- /rust/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "build": "webpack", 4 | "serve": "webpack-dev-server" 5 | }, 6 | "devDependencies": { 7 | "@wasm-tool/wasm-pack-plugin": "1.0.1", 8 | "text-encoding": "^0.7.0", 9 | "html-webpack-plugin": "^3.2.0", 10 | "webpack": "^4.29.4", 11 | "webpack-cli": "^3.1.1", 12 | "webpack-dev-server": "^3.1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* To build: 2 | rustup default nightly 3 | rustup target add wasm32-unknown-emscripten 4 | cargo build --target=wasm32-unknown-emscripten 5 | 6 | To dump: 7 | ~/PineTime/wabt/build/wasm-objdump -x docs/test_rust.wasm | more 8 | */ 9 | #![feature(libc)] 10 | // use std::ops::Add; 11 | // use wasm_bindgen::prelude::*; 12 | // use wasm_bindgen::Clamped; 13 | // use web_sys::{CanvasRenderingContext2d, ImageData}; 14 | 15 | extern "C" { 16 | static mut test_rust_buffer: [u8; 32]; 17 | fn test_c() -> i32; 18 | fn puts(fmt: *const u8) -> i32; 19 | // fn printf(fmt: *const u8, ...) -> i32; 20 | } 21 | 22 | #[no_mangle] 23 | pub extern fn test_rust() -> i32 { 24 | unsafe { puts(b"In Rust: test_rust()\0".as_ptr()); } 25 | 2205 26 | } 27 | 28 | #[no_mangle] 29 | pub extern fn test_rust2() -> i32 { 30 | unsafe { puts(b"In Rust: test_rust2()\0".as_ptr()); } 31 | 2306 32 | } 33 | 34 | #[no_mangle] 35 | pub extern fn test_rust3() -> i32 { 36 | unsafe { puts(b"In Rust: test_rust3()\0".as_ptr()); } 37 | let i = unsafe { test_c() }; 38 | i 39 | } 40 | 41 | #[no_mangle] 42 | pub extern fn test_rust_set_buffer() -> i32 { 43 | unsafe { puts(b"In Rust: test_rust_set_buffer()\0".as_ptr()); } 44 | let i = unsafe { test_rust_buffer[0] }; 45 | unsafe { test_rust_buffer[0] = 0x42; } // B 46 | i as i32 47 | } 48 | 49 | #[no_mangle] 50 | pub extern fn test_rust_get_buffer() -> i32 { 51 | unsafe { puts(b"In Rust: test_rust_get_buffer()\0".as_ptr()); } 52 | unsafe { test_rust_buffer[0] as i32 } 53 | } 54 | 55 | /* 56 | #[wasm_bindgen] 57 | pub fn draw( 58 | ctx: &CanvasRenderingContext2d, 59 | width: u32, 60 | height: u32, 61 | real: f64, 62 | imaginary: f64, 63 | ) -> Result<(), JsValue> { 64 | // The real workhorse of this algorithm, generating pixel data 65 | let c = Complex { real, imaginary }; 66 | let mut data = get_julia_set(width, height, c); 67 | let data = ImageData::new_with_u8_clamped_array_and_sh(Clamped(&mut data), width, height)?; 68 | ctx.put_image_data(&data, 0.0, 0.0) 69 | } 70 | 71 | fn get_julia_set(width: u32, height: u32, c: Complex) -> Vec { 72 | let mut data = Vec::new(); 73 | 74 | let param_i = 1.5; 75 | let param_r = 1.5; 76 | let scale = 0.005; 77 | 78 | for x in 0..width { 79 | for y in 0..height { 80 | let z = Complex { 81 | real: y as f64 * scale - param_r, 82 | imaginary: x as f64 * scale - param_i, 83 | }; 84 | let iter_index = get_iter_index(z, c); 85 | data.push((iter_index / 4) as u8); 86 | data.push((iter_index / 2) as u8); 87 | data.push(iter_index as u8); 88 | data.push(255); 89 | } 90 | } 91 | 92 | data 93 | } 94 | 95 | fn get_iter_index(z: Complex, c: Complex) -> u32 { 96 | let mut iter_index: u32 = 0; 97 | let mut z = z; 98 | while iter_index < 900 { 99 | if z.norm() > 2.0 { 100 | break; 101 | } 102 | z = z.square() + c; 103 | iter_index += 1; 104 | } 105 | iter_index 106 | } 107 | 108 | #[derive(Clone, Copy, Debug)] 109 | struct Complex { 110 | real: f64, 111 | imaginary: f64, 112 | } 113 | 114 | impl Complex { 115 | fn square(self) -> Complex { 116 | let real = (self.real * self.real) - (self.imaginary * self.imaginary); 117 | let imaginary = 2.0 * self.real * self.imaginary; 118 | Complex { real, imaginary } 119 | } 120 | 121 | fn norm(&self) -> f64 { 122 | (self.real * self.real) + (self.imaginary * self.imaginary) 123 | } 124 | } 125 | 126 | impl Add for Complex { 127 | type Output = Complex; 128 | 129 | fn add(self, rhs: Complex) -> Complex { 130 | Complex { 131 | real: self.real + rhs.real, 132 | imaginary: self.imaginary + rhs.imaginary, 133 | } 134 | } 135 | } 136 | */ -------------------------------------------------------------------------------- /rust/styles/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | display: flex; 3 | justify-content: center; 4 | } 5 | 6 | .controls { 7 | display: flex; 8 | align-items: flex-end; 9 | margin-bottom: 1em; 10 | } 11 | 12 | .controls h1 { 13 | margin: 0 .3em 0 0; 14 | font-style: italic; 15 | font-family: 'Times New Roman', Times, serif; 16 | } 17 | 18 | .controls > div { 19 | margin-right: 1em; 20 | } 21 | 22 | button, 23 | input[type="number"] { 24 | margin-bottom: 0; 25 | } 26 | -------------------------------------------------------------------------------- /rust/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 3 | const webpack = require('webpack'); 4 | const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); 5 | 6 | module.exports = { 7 | entry: './index.js', 8 | output: { 9 | path: path.resolve(__dirname, 'dist'), 10 | filename: 'index.js', 11 | }, 12 | plugins: [ 13 | new HtmlWebpackPlugin({ 14 | template: 'index.html' 15 | }), 16 | new WasmPackPlugin({ 17 | crateDirectory: path.resolve(__dirname, ".") 18 | }), 19 | // Have this example work in Edge which doesn't ship `TextEncoder` or 20 | // `TextDecoder` at this time. 21 | new webpack.ProvidePlugin({ 22 | TextDecoder: ['text-encoding', 'TextDecoder'], 23 | TextEncoder: ['text-encoding', 'TextEncoder'] 24 | }) 25 | ], 26 | mode: 'development' 27 | }; 28 | -------------------------------------------------------------------------------- /scripts/built_in_font/DejaVuSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/scripts/built_in_font/DejaVuSans.ttf -------------------------------------------------------------------------------- /scripts/built_in_font/FontAwesome5-Solid+Brands+Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/scripts/built_in_font/FontAwesome5-Solid+Brands+Regular.woff -------------------------------------------------------------------------------- /scripts/built_in_font/Montserrat-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/scripts/built_in_font/Montserrat-Medium.ttf -------------------------------------------------------------------------------- /scripts/built_in_font/SimSun.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/scripts/built_in_font/SimSun.woff -------------------------------------------------------------------------------- /scripts/built_in_font/built_in_font_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3.6 2 | 3 | import argparse 4 | from argparse import RawTextHelpFormatter 5 | import os 6 | import sys 7 | 8 | parser = argparse.ArgumentParser(description="""Create fonts for LittelvGL including the built-in symbols. lv_font_conv needs to be installed. See https://github.com/littlevgl/lv_font_conv 9 | Example: python built_in_font_gen.py --size 16 -o lv_font_roboto_16.c --bpp 4 -r 0x20-0x7F""", formatter_class=RawTextHelpFormatter) 10 | parser.add_argument('-s', '--size', 11 | type=int, 12 | metavar = 'px', 13 | nargs='?', 14 | help='Size of the font in px') 15 | parser.add_argument('--bpp', 16 | type=int, 17 | metavar = '1,2,4', 18 | nargs='?', 19 | help='Bit per pixel') 20 | parser.add_argument('-r', '--range', 21 | nargs='+', 22 | metavar = 'start-end', 23 | default=['0x20-0x7F,0xB0,0x2022'], 24 | help='Ranges and/or characters to include. Default is 0x20-7F (ASCII). E.g. -r 0x20-0x7F, 0x200, 324') 25 | parser.add_argument('--symbols', 26 | nargs='+', 27 | metavar = 'sym', 28 | default=[''], 29 | help=u'Symbols to include. E.g. -s ÁÉŐ'.encode('utf-8')) 30 | parser.add_argument('--font', 31 | metavar = 'file', 32 | nargs='?', 33 | default='Montserrat-Medium.ttf', 34 | help='A TTF or WOFF file') 35 | parser.add_argument('-o', '--output', 36 | nargs='?', 37 | metavar='file', 38 | help='Output file name. E.g. my_font_20.c') 39 | parser.add_argument('--compressed', action='store_true', 40 | help='Compress the bitmaps') 41 | parser.add_argument('--subpx', action='store_true', 42 | help='3 times wider letters for sub pixel rendering') 43 | 44 | args = parser.parse_args() 45 | 46 | if args.compressed == False: 47 | compr = "--no-compress --no-prefilter" 48 | else: 49 | compr = "" 50 | 51 | if len(args.symbols[0]) != 0: 52 | args.symbols[0] = "--symbols " + args.symbols[0] 53 | 54 | #Built in symbols 55 | syms = "61441,61448,61451,61452,61452,61453,61457,61459,61461,61465,61468,61473,61478,61479,61480,61502,61512,61515,61516,61517,61521,61522,61523,61524,61543,61544,61550,61552,61553,61556,61559,61560,61561,61563,61587,61589,61636,61637,61639,61671,61674,61683,61724,61732,61787,61931,62016,62017,62018,62019,62020,62087,62099,62212,62189,62810,63426,63650" 56 | 57 | #Run the command (Add degree and bbullet symbol) 58 | cmd = "lv_font_conv {} --bpp {} --size {} --font {} -r {} {} --font FontAwesome5-Solid+Brands+Regular.woff -r {} --format lvgl -o {} --force-fast-kern-format".format(compr, args.bpp, args.size, args.font, args.range[0], args.symbols[0], syms, args.output) 59 | os.system(cmd) 60 | -------------------------------------------------------------------------------- /scripts/code-format.cfg: -------------------------------------------------------------------------------- 1 | --style=kr 2 | --indent=spaces=4 3 | --indent-classes 4 | --indent-switches 5 | --indent-cases 6 | --indent-preproc-block 7 | --indent-preproc-define 8 | --indent-col1-comments 9 | --pad-oper 10 | --unpad-paren 11 | --align-pointer=middle 12 | --align-reference=middle 13 | --convert-tabs 14 | --max-code-length=120 15 | --break-after-logical 16 | --break-closing-braces 17 | --attach-closing-while 18 | --min-conditional-indent=0 19 | --max-continuation-indent=120 20 | --mode=c 21 | --lineend=linux 22 | --recursive 23 | --suffix=none 24 | --preserve-date 25 | --formatted 26 | --exclude=lv_conf_internal.h 27 | --exclude=../src/lv_font/lv_font_montserrat_12.c 28 | --exclude=../src/lv_font/lv_font_montserrat_14.c 29 | --exclude=../src/lv_font/lv_font_montserrat_16.c 30 | --exclude=../src/lv_font/lv_font_montserrat_18.c 31 | --exclude=../src/lv_font/lv_font_montserrat_20.c 32 | --exclude=../src/lv_font/lv_font_montserrat_22.c 33 | --exclude=../src/lv_font/lv_font_montserrat_24.c 34 | --exclude=../src/lv_font/lv_font_montserrat_26.c 35 | --exclude=../src/lv_font/lv_font_montserrat_28.c 36 | --exclude=../src/lv_font/lv_font_montserrat_30.c 37 | --exclude=../src/lv_font/lv_font_montserrat_32.c 38 | --exclude=../src/lv_font/lv_font_montserrat_34.c 39 | --exclude=../src/lv_font/lv_font_montserrat_36.c 40 | --exclude=../src/lv_font/lv_font_montserrat_38.c 41 | --exclude=../src/lv_font/lv_font_montserrat_40.c 42 | --exclude=../src/lv_font/lv_font_montserrat_42.c 43 | --exclude=../src/lv_font/lv_font_montserrat_44.c 44 | --exclude=../src/lv_font/lv_font_montserrat_46.c 45 | --exclude=../src/lv_font/lv_font_montserrat_48.c 46 | --exclude=../src/lv_font/lv_font_montserrat_12_subpx.c 47 | --exclude=../src/lv_font/lv_font_montserrat_28_compressed.c 48 | --exclude=../src/lv_font/lv_font_simsun_16_cjk.c 49 | --exclude=../src/lv_font/lv_font_dejavu_16_persian_hebrew.c 50 | 51 | -------------------------------------------------------------------------------- /scripts/code-format.sh: -------------------------------------------------------------------------------- 1 | astyle --options=code-format.cfg "../src/*.c,*.h" 2 | -------------------------------------------------------------------------------- /scripts/cppcheck_run.sh: -------------------------------------------------------------------------------- 1 | cppcheck -j8 --template="{severity}\t{file}:{line}\t{id}: {message}" --enable=all ../src/ --output-file=cppcheck_res.txt --suppress=unusedFunction --suppress=preprocessorErrorDirective --force 2 | 3 | -------------------------------------------------------------------------------- /scripts/infer_run.sh: -------------------------------------------------------------------------------- 1 | # https://github.com/facebook/infer 2 | # 3 | # Install: 4 | # VERSION=0.17.0; \ 5 | # curl -sSL "https://github.com/facebook/infer/releases/download/v$VERSION/infer-linux64-v$VERSION.tar.xz" \ 6 | # | sudo tar -C /opt -xJ && \ 7 | # sudoln -s "/opt/infer-linux64-v$VERSION/bin/infer" /usr/local/bin/infer 8 | 9 | 10 | infer run -- make -j8 11 | -------------------------------------------------------------------------------- /scripts/lv_conf_checker.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | Generates a checker file for lv_conf.h from lv_conf_templ.h define all the not defined values 5 | ''' 6 | 7 | 8 | import sys 9 | import re 10 | 11 | if sys.version_info < (3,6,0): 12 | print("Python >=3.6 is required", file=sys.stderr) 13 | exit(1) 14 | 15 | fin = open("../lv_conf_template.h", "r") 16 | fout = open("../src/lv_conf_internal.h", "w") 17 | 18 | 19 | fout.write( 20 | '''/** 21 | * GENERATED FILE, DO NOT EDIT IT! 22 | * @file lv_conf_internal.h 23 | * Make sure all the defines of lv_conf.h have a default value 24 | **/ 25 | 26 | #ifndef LV_CONF_INTERNAL_H 27 | #define LV_CONF_INTERNAL_H 28 | /* clang-format off */ 29 | 30 | #include 31 | 32 | #if defined(LV_CONF_PATH) 33 | #define __LV_TO_STR_AUX(x) #x 34 | #define __LV_TO_STR(x) __LV_TO_STR_AUX(x) 35 | #include __LV_TO_STR(LV_CONF_PATH) 36 | #undef __LV_TO_STR_AUX 37 | #undef __LV_TO_STR 38 | #elif defined(LV_CONF_INCLUDE_SIMPLE) 39 | #include "lv_conf.h" 40 | #else 41 | #include "../../lv_conf.h" 42 | #endif 43 | 44 | ''' 45 | ) 46 | 47 | started = 0 48 | 49 | for i in fin.read().splitlines(): 50 | if not started: 51 | if '#define LV_CONF_H' in i: 52 | started = 1 53 | continue 54 | else: 55 | continue 56 | 57 | if '/*--END OF LV_CONF_H--*/' in i: break 58 | 59 | r = re.search(r'^ *# *define ([^\s]+).*$', i) 60 | 61 | if r: 62 | line = re.sub('\(.*?\)', '', r[1], 1) #remove parentheses from macros 63 | fout.write( 64 | f'#ifndef {line}\n' 65 | f'{i}\n' 66 | '#endif\n' 67 | ) 68 | elif re.search('^ *typedef .*;.*$', i): 69 | continue #ignore typedefs to avoide redeclaration 70 | else: 71 | fout.write(f'{i}\n') 72 | 73 | 74 | fout.write( 75 | ''' 76 | #endif /*LV_CONF_CHECKER_H*/ 77 | ''' 78 | ) 79 | 80 | fin.close() 81 | fout.close() 82 | -------------------------------------------------------------------------------- /src/lv_core/lv_core.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_group.c 2 | CSRCS += lv_indev.c 3 | CSRCS += lv_disp.c 4 | CSRCS += lv_obj.c 5 | CSRCS += lv_refr.c 6 | CSRCS += lv_style.c 7 | 8 | DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_core 9 | VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_core 10 | 11 | CFLAGS += "-I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_core" 12 | -------------------------------------------------------------------------------- /src/lv_core/lv_refr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_refr.h 3 | * 4 | */ 5 | 6 | #ifndef LV_REFR_H 7 | #define LV_REFR_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_obj.h" 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | 23 | #define LV_REFR_TASK_PRIO LV_TASK_PRIO_MID 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /********************** 30 | * STATIC PROTOTYPES 31 | **********************/ 32 | 33 | /********************** 34 | * STATIC VARIABLES 35 | **********************/ 36 | 37 | /********************** 38 | * MACROS 39 | **********************/ 40 | 41 | /********************** 42 | * GLOBAL FUNCTIONS 43 | **********************/ 44 | 45 | /** 46 | * Initialize the screen refresh subsystem 47 | */ 48 | void _lv_refr_init(void); 49 | 50 | /** 51 | * Redraw the invalidated areas now. 52 | * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process 53 | * can prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process 54 | * (e.g. progress bar) this function can be called when the screen should be updated. 55 | * @param disp pointer to display to refresh. NULL to refresh all displays. 56 | */ 57 | void lv_refr_now(lv_disp_t * disp); 58 | 59 | /** 60 | * Invalidate an area on display to redraw it 61 | * @param area_p pointer to area which should be invalidated (NULL: delete the invalidated areas) 62 | * @param disp pointer to display where the area should be invalidated (NULL can be used if there is 63 | * only one display) 64 | */ 65 | void _lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p); 66 | 67 | /** 68 | * Get the display which is being refreshed 69 | * @return the display being refreshed 70 | */ 71 | lv_disp_t * _lv_refr_get_disp_refreshing(void); 72 | 73 | /** 74 | * Set the display which is being refreshed. 75 | * It shouldn't be used directly by the user. 76 | * It can be used to trick the drawing functions about there is an active display. 77 | * @param the display being refreshed 78 | */ 79 | void _lv_refr_set_disp_refreshing(lv_disp_t * disp); 80 | 81 | /** 82 | * Called periodically to handle the refreshing 83 | * @param task pointer to the task itself 84 | */ 85 | void _lv_disp_refr_task(lv_task_t * task); 86 | 87 | /********************** 88 | * STATIC FUNCTIONS 89 | **********************/ 90 | 91 | #ifdef __cplusplus 92 | } /* extern "C" */ 93 | #endif 94 | 95 | #endif /*LV_REFR_H*/ 96 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_H 7 | #define LV_DRAW_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #include "../lv_core/lv_style.h" 19 | #include "../lv_misc/lv_txt.h" 20 | #include "lv_img_decoder.h" 21 | 22 | #include "lv_draw_rect.h" 23 | #include "lv_draw_label.h" 24 | #include "lv_draw_img.h" 25 | #include "lv_draw_line.h" 26 | #include "lv_draw_triangle.h" 27 | #include "lv_draw_arc.h" 28 | #include "lv_draw_blend.h" 29 | #include "lv_draw_mask.h" 30 | 31 | /********************* 32 | * DEFINES 33 | *********************/ 34 | 35 | /********************** 36 | * TYPEDEFS 37 | **********************/ 38 | 39 | /********************** 40 | * GLOBAL PROTOTYPES 41 | **********************/ 42 | 43 | /********************** 44 | * GLOBAL VARIABLES 45 | **********************/ 46 | 47 | /********************** 48 | * MACROS 49 | **********************/ 50 | 51 | /********************** 52 | * POST INCLUDES 53 | *********************/ 54 | 55 | #ifdef __cplusplus 56 | } /* extern "C" */ 57 | #endif 58 | 59 | #endif /*LV_DRAW_H*/ 60 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_draw_mask.c 2 | CSRCS += lv_draw_blend.c 3 | CSRCS += lv_draw_rect.c 4 | CSRCS += lv_draw_label.c 5 | CSRCS += lv_draw_line.c 6 | CSRCS += lv_draw_img.c 7 | CSRCS += lv_draw_arc.c 8 | CSRCS += lv_draw_triangle.c 9 | CSRCS += lv_img_decoder.c 10 | CSRCS += lv_img_cache.c 11 | CSRCS += lv_img_buf.c 12 | 13 | DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_draw 14 | VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_draw 15 | 16 | CFLAGS += "-I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_draw" 17 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw_arc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_arc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_ARC_H 7 | #define LV_DRAW_ARC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw_line.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Draw an arc. (Can draw pie too with great thickness.) 32 | * @param center_x the x coordinate of the center of the arc 33 | * @param center_y the y coordinate of the center of the arc 34 | * @param radius the radius of the arc 35 | * @param mask the arc will be drawn only in this mask 36 | * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) 37 | * @param end_angle the end angle of the arc 38 | * @param clip_area the arc will be drawn only in this area 39 | * @param dsc pointer to an initialized `lv_draw_line_dsc_t` variable 40 | */ 41 | void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, 42 | const lv_area_t * clip_area, const lv_draw_line_dsc_t * dsc); 43 | 44 | /********************** 45 | * MACROS 46 | **********************/ 47 | 48 | #ifdef __cplusplus 49 | } /* extern "C" */ 50 | #endif 51 | 52 | #endif /*LV_DRAW_ARC*/ 53 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw_blend.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_blend.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_BLEND_H 7 | #define LV_DRAW_BLEND_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_misc/lv_color.h" 17 | #include "../lv_misc/lv_area.h" 18 | #include "lv_draw_mask.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | enum { 28 | LV_BLEND_MODE_NORMAL, 29 | #if LV_USE_BLEND_MODES 30 | LV_BLEND_MODE_ADDITIVE, 31 | LV_BLEND_MODE_SUBTRACTIVE, 32 | #endif 33 | }; 34 | 35 | typedef uint8_t lv_blend_mode_t; 36 | 37 | /********************** 38 | * GLOBAL PROTOTYPES 39 | **********************/ 40 | 41 | //! @cond Doxygen_Suppress 42 | LV_ATTRIBUTE_FAST_MEM void _lv_blend_fill(const lv_area_t * clip_area, const lv_area_t * fill_area, lv_color_t color, 43 | lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_opa_t opa, lv_blend_mode_t mode); 44 | 45 | 46 | LV_ATTRIBUTE_FAST_MEM void _lv_blend_map(const lv_area_t * clip_area, const lv_area_t * map_area, 47 | const lv_color_t * map_buf, 48 | lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_opa_t opa, lv_blend_mode_t mode); 49 | 50 | //! @endcond 51 | /********************** 52 | * MACROS 53 | **********************/ 54 | 55 | #ifdef __cplusplus 56 | } /* extern "C" */ 57 | #endif 58 | 59 | #endif /*LV_DRAW_BLEND_H*/ 60 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw_img.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_img.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_IMG_H 7 | #define LV_DRAW_IMG_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_img_decoder.h" 17 | #include "lv_img_buf.h" 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | 23 | /********************** 24 | * MACROS 25 | **********************/ 26 | 27 | /********************** 28 | * TYPEDEFS 29 | **********************/ 30 | 31 | typedef struct { 32 | lv_opa_t opa; 33 | 34 | uint16_t angle; 35 | lv_point_t pivot; 36 | uint16_t zoom; 37 | 38 | lv_opa_t recolor_opa; 39 | lv_color_t recolor; 40 | 41 | lv_blend_mode_t blend_mode; 42 | 43 | uint8_t antialias : 1; 44 | } lv_draw_img_dsc_t; 45 | 46 | /********************** 47 | * GLOBAL PROTOTYPES 48 | **********************/ 49 | 50 | void lv_draw_img_dsc_init(lv_draw_img_dsc_t * dsc); 51 | /** 52 | * Draw an image 53 | * @param coords the coordinates of the image 54 | * @param mask the image will be drawn only in this area 55 | * @param src pointer to a lv_color_t array which contains the pixels of the image 56 | * @param dsc pointer to an initialized `lv_draw_img_dsc_t` variable 57 | */ 58 | void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask, const void * src, const lv_draw_img_dsc_t * dsc); 59 | 60 | /** 61 | * Get the type of an image source 62 | * @param src pointer to an image source: 63 | * - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code) 64 | * - a path to a file (e.g. "S:/folder/image.bin") 65 | * - or a symbol (e.g. LV_SYMBOL_CLOSE) 66 | * @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKNOWN 67 | */ 68 | lv_img_src_t lv_img_src_get_type(const void * src); 69 | 70 | /** 71 | * Get the pixel size of a color format in bits 72 | * @param cf a color format (`LV_IMG_CF_...`) 73 | * @return the pixel size in bits 74 | */ 75 | uint8_t lv_img_cf_get_px_size(lv_img_cf_t cf); 76 | 77 | /** 78 | * Check if a color format is chroma keyed or not 79 | * @param cf a color format (`LV_IMG_CF_...`) 80 | * @return true: chroma keyed; false: not chroma keyed 81 | */ 82 | bool lv_img_cf_is_chroma_keyed(lv_img_cf_t cf); 83 | 84 | /** 85 | * Check if a color format has alpha channel or not 86 | * @param cf a color format (`LV_IMG_CF_...`) 87 | * @return true: has alpha channel; false: doesn't have alpha channel 88 | */ 89 | bool lv_img_cf_has_alpha(lv_img_cf_t cf); 90 | 91 | 92 | #ifdef __cplusplus 93 | } /* extern "C" */ 94 | #endif 95 | 96 | #endif /*LV_TEMPL_H*/ 97 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw_label.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_label.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_LABEL_H 7 | #define LV_DRAW_LABEL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_misc/lv_bidi.h" 17 | #include "../lv_misc/lv_txt.h" 18 | #include "../lv_core/lv_style.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | #define LV_DRAW_LABEL_NO_TXT_SEL (0xFFFF) 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | typedef struct { 30 | lv_color_t color; 31 | lv_color_t sel_color; 32 | const lv_font_t * font; 33 | lv_opa_t opa; 34 | lv_style_int_t line_space; 35 | lv_style_int_t letter_space; 36 | uint32_t sel_start; 37 | uint32_t sel_end; 38 | lv_coord_t ofs_x; 39 | lv_coord_t ofs_y; 40 | lv_bidi_dir_t bidi_dir; 41 | lv_txt_flag_t flag; 42 | lv_text_decor_t decor; 43 | lv_blend_mode_t blend_mode; 44 | } lv_draw_label_dsc_t; 45 | 46 | /** Store some info to speed up drawing of very large texts 47 | * It takes a lot of time to get the first visible character because 48 | * all the previous characters needs to be checked to calculate the positions. 49 | * This structure stores an earlier (e.g. at -1000 px) coordinate and the index of that line. 50 | * Therefore the calculations can start from here.*/ 51 | typedef struct { 52 | /** Index of the line at `y` coordinate*/ 53 | int32_t line_start; 54 | 55 | /** Give the `y` coordinate of the first letter at `line start` index. Relative to the label's coordinates*/ 56 | int32_t y; 57 | 58 | /** The 'y1' coordinate of the label when the hint was saved. 59 | * Used to invalidate the hint if the label has moved too much. */ 60 | int32_t coord_y; 61 | } lv_draw_label_hint_t; 62 | 63 | /********************** 64 | * GLOBAL PROTOTYPES 65 | **********************/ 66 | 67 | //! @cond Doxygen_Suppress 68 | 69 | LV_ATTRIBUTE_FAST_MEM void lv_draw_label_dsc_init(lv_draw_label_dsc_t * dsc); 70 | 71 | /** 72 | * Write a text 73 | * @param coords coordinates of the label 74 | * @param mask the label will be drawn only in this area 75 | * @param dsc pointer to draw descriptor 76 | * @param txt `\0` terminated text to write 77 | * @param hint pointer to a `lv_draw_label_hint_t` variable. 78 | * It is managed by the drawer to speed up the drawing of very long texts (thousands of lines). 79 | */ 80 | LV_ATTRIBUTE_FAST_MEM void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, 81 | const lv_draw_label_dsc_t * dsc, 82 | const char * txt, lv_draw_label_hint_t * hint); 83 | 84 | //! @endcond 85 | /*********************** 86 | * GLOBAL VARIABLES 87 | ***********************/ 88 | extern const uint8_t _lv_bpp2_opa_table[]; 89 | extern const uint8_t _lv_bpp3_opa_table[]; 90 | extern const uint8_t _lv_bpp1_opa_table[]; 91 | extern const uint8_t _lv_bpp4_opa_table[]; 92 | extern const uint8_t _lv_bpp8_opa_table[]; 93 | 94 | /********************** 95 | * MACROS 96 | **********************/ 97 | 98 | #ifdef __cplusplus 99 | } /* extern "C" */ 100 | #endif 101 | 102 | #endif /*LV_DRAW_LABEL_H*/ 103 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw_line.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_line.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_LINE_H 7 | #define LV_DRAW_LINE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_core/lv_style.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | typedef struct { 26 | lv_color_t color; 27 | lv_style_int_t width; 28 | lv_style_int_t dash_width; 29 | lv_style_int_t dash_gap; 30 | lv_opa_t opa; 31 | lv_blend_mode_t blend_mode : 2; 32 | uint8_t round_start : 1; 33 | uint8_t round_end : 1; 34 | uint8_t raw_end : 1; /*Do not bother with perpendicular line ending is it's not visible for any reason*/ 35 | } lv_draw_line_dsc_t; 36 | 37 | /********************** 38 | * GLOBAL PROTOTYPES 39 | **********************/ 40 | 41 | //! @cond Doxygen_Suppress 42 | /** 43 | * Draw a line 44 | * @param point1 first point of the line 45 | * @param point2 second point of the line 46 | * @param clip the line will be drawn only in this area 47 | * @param dsc pointer to an initialized `lv_draw_line_dsc_t` variable 48 | */ 49 | LV_ATTRIBUTE_FAST_MEM void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, 50 | const lv_draw_line_dsc_t * dsc); 51 | 52 | LV_ATTRIBUTE_FAST_MEM void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc); 53 | 54 | 55 | //! @endcond 56 | 57 | /********************** 58 | * MACROS 59 | **********************/ 60 | 61 | #ifdef __cplusplus 62 | } /* extern "C" */ 63 | #endif 64 | 65 | #endif /*LV_DRAW_LINE_H*/ 66 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw_rect.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_rect.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_RECT_H 7 | #define LV_DRAW_RECT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_core/lv_style.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | typedef struct { 27 | lv_style_int_t radius; 28 | 29 | /*Background*/ 30 | lv_color_t bg_color; 31 | lv_color_t bg_grad_color; 32 | lv_grad_dir_t bg_grad_dir; 33 | lv_style_int_t bg_main_color_stop; 34 | lv_style_int_t bg_grad_color_stop; 35 | lv_opa_t bg_opa; 36 | lv_blend_mode_t bg_blend_mode; 37 | 38 | /*Border*/ 39 | lv_color_t border_color; 40 | lv_style_int_t border_width; 41 | lv_style_int_t border_side; 42 | lv_opa_t border_opa; 43 | lv_blend_mode_t border_blend_mode; 44 | 45 | /*Outline*/ 46 | lv_color_t outline_color; 47 | lv_style_int_t outline_width; 48 | lv_style_int_t outline_pad; 49 | lv_opa_t outline_opa; 50 | lv_blend_mode_t outline_blend_mode; 51 | 52 | /*Shadow*/ 53 | lv_color_t shadow_color; 54 | lv_style_int_t shadow_width; 55 | lv_style_int_t shadow_ofs_x; 56 | lv_style_int_t shadow_ofs_y; 57 | lv_style_int_t shadow_spread; 58 | lv_opa_t shadow_opa; 59 | lv_blend_mode_t shadow_blend_mode; 60 | 61 | /*Pattern*/ 62 | const void * pattern_image; 63 | const lv_font_t * pattern_font; 64 | lv_color_t pattern_recolor; 65 | lv_opa_t pattern_opa; 66 | lv_opa_t pattern_recolor_opa; 67 | uint8_t pattern_repeat : 1; 68 | lv_blend_mode_t pattern_blend_mode; 69 | 70 | /*Value*/ 71 | const char * value_str; 72 | const lv_font_t * value_font; 73 | lv_opa_t value_opa; 74 | lv_color_t value_color; 75 | lv_style_int_t value_ofs_x; 76 | lv_style_int_t value_ofs_y; 77 | lv_style_int_t value_letter_space; 78 | lv_style_int_t value_line_space; 79 | lv_align_t value_align; 80 | lv_blend_mode_t value_blend_mode; 81 | } lv_draw_rect_dsc_t; 82 | 83 | /********************** 84 | * GLOBAL PROTOTYPES 85 | **********************/ 86 | 87 | LV_ATTRIBUTE_FAST_MEM void lv_draw_rect_dsc_init(lv_draw_rect_dsc_t * dsc); 88 | 89 | //! @endcond 90 | 91 | /** 92 | * Draw a rectangle 93 | * @param coords the coordinates of the rectangle 94 | * @param mask the rectangle will be drawn only in this mask 95 | * @param dsc pointer to an initialized `lv_draw_rect_dsc_t` variable 96 | */ 97 | void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_draw_rect_dsc_t * dsc); 98 | 99 | /** 100 | * Draw a pixel 101 | * @param point the coordinates of the point to draw 102 | * @param mask the pixel will be drawn only in this mask 103 | * @param style pointer to a style 104 | */ 105 | void lv_draw_px(const lv_point_t * point, const lv_area_t * clip_area, const lv_style_t * style); 106 | 107 | /********************** 108 | * MACROS 109 | **********************/ 110 | 111 | #ifdef __cplusplus 112 | } /* extern "C" */ 113 | #endif 114 | 115 | #endif /*LV_DRAW_RECT_H*/ 116 | -------------------------------------------------------------------------------- /src/lv_draw/lv_draw_triangle.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_triangle.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_TRIANGLE_H 7 | #define LV_DRAW_TRIANGLE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw_rect.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Draw a triangle 32 | * @param points pointer to an array with 3 points 33 | * @param clip_area the triangle will be drawn only in this area 34 | * @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable 35 | */ 36 | void lv_draw_triangle(const lv_point_t points[], const lv_area_t * clip, const lv_draw_rect_dsc_t * draw_dsc); 37 | 38 | /** 39 | * Draw a polygon. Only convex polygons are supported. 40 | * @param points an array of points 41 | * @param point_cnt number of points 42 | * @param clip_area polygon will be drawn only in this area 43 | * @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable 44 | */ 45 | void lv_draw_polygon(const lv_point_t points[], uint16_t point_cnt, const lv_area_t * mask, 46 | const lv_draw_rect_dsc_t * draw_dsc); 47 | 48 | /********************** 49 | * MACROS 50 | **********************/ 51 | 52 | #ifdef __cplusplus 53 | } /* extern "C" */ 54 | #endif 55 | 56 | #endif /*LV_DRAW_TRIANGLE_H*/ 57 | -------------------------------------------------------------------------------- /src/lv_draw/lv_img_cache.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_img_cache.h 3 | * 4 | */ 5 | 6 | #ifndef LV_IMG_CACHE_H 7 | #define LV_IMG_CACHE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_img_decoder.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /** 27 | * When loading images from the network it can take a long time to download and decode the image. 28 | * 29 | * To avoid repeating this heavy load images can be cached. 30 | */ 31 | typedef struct { 32 | lv_img_decoder_dsc_t dec_dsc; /**< Image information */ 33 | 34 | /** Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used. 35 | * Decrement all lifes by one every in every ::lv_img_cache_open. 36 | * If life == 0 the entry can be reused */ 37 | int32_t life; 38 | } lv_img_cache_entry_t; 39 | 40 | /********************** 41 | * GLOBAL PROTOTYPES 42 | **********************/ 43 | 44 | /** 45 | * Open an image using the image decoder interface and cache it. 46 | * The image will be left open meaning if the image decoder open callback allocated memory then it will remain. 47 | * The image is closed if a new image is opened and the new image takes its place in the cache. 48 | * @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable 49 | * @param color The color of the image with `LV_IMG_CF_ALPHA_...` 50 | * @return pointer to the cache entry or NULL if can open the image 51 | */ 52 | lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color); 53 | 54 | /** 55 | * Set the number of images to be cached. 56 | * More cached images mean more opened image at same time which might mean more memory usage. 57 | * E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache. 58 | * @param new_entry_cnt number of image to cache 59 | */ 60 | void lv_img_cache_set_size(uint16_t new_slot_num); 61 | 62 | /** 63 | * Invalidate an image source in the cache. 64 | * Useful if the image source is updated therefore it needs to be cached again. 65 | * @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable. 66 | */ 67 | void lv_img_cache_invalidate_src(const void * src); 68 | 69 | /********************** 70 | * MACROS 71 | **********************/ 72 | 73 | #ifdef __cplusplus 74 | } /* extern "C" */ 75 | #endif 76 | 77 | #endif /*LV_IMG_CACHE_H*/ 78 | -------------------------------------------------------------------------------- /src/lv_font/lv_font.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_font.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | 10 | #include "lv_font.h" 11 | #include "../lv_misc/lv_utils.h" 12 | #include "../lv_misc/lv_log.h" 13 | 14 | /********************* 15 | * DEFINES 16 | *********************/ 17 | 18 | /********************** 19 | * TYPEDEFS 20 | **********************/ 21 | 22 | /********************** 23 | * STATIC PROTOTYPES 24 | **********************/ 25 | 26 | /********************** 27 | * STATIC VARIABLES 28 | **********************/ 29 | 30 | /********************** 31 | * GLOBAL PROTOTYPES 32 | **********************/ 33 | 34 | /********************** 35 | * MACROS 36 | **********************/ 37 | 38 | /********************** 39 | * GLOBAL FUNCTIONS 40 | **********************/ 41 | 42 | /** 43 | * Return with the bitmap of a font. 44 | * @param font_p pointer to a font 45 | * @param letter an UNICODE character code 46 | * @return pointer to the bitmap of the letter 47 | */ 48 | const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter) 49 | { 50 | return font_p->get_glyph_bitmap(font_p, letter); 51 | } 52 | 53 | /** 54 | * Get the descriptor of a glyph 55 | * @param font_p pointer to font 56 | * @param dsc_out store the result descriptor here 57 | * @param letter an UNICODE letter code 58 | * @return true: descriptor is successfully loaded into `dsc_out`. 59 | * false: the letter was not found, no data is loaded to `dsc_out` 60 | */ 61 | bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, 62 | uint32_t letter_next) 63 | { 64 | return font_p->get_glyph_dsc(font_p, dsc_out, letter, letter_next); 65 | } 66 | 67 | /** 68 | * Get the width of a glyph with kerning 69 | * @param font pointer to a font 70 | * @param letter an UNICODE letter 71 | * @param letter_next the next letter after `letter`. Used for kerning 72 | * @return the width of the glyph 73 | */ 74 | uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next) 75 | { 76 | lv_font_glyph_dsc_t g; 77 | bool ret; 78 | ret = lv_font_get_glyph_dsc(font, &g, letter, letter_next); 79 | if(ret) return g.adv_w; 80 | else return 0; 81 | } 82 | 83 | /********************** 84 | * STATIC FUNCTIONS 85 | **********************/ 86 | -------------------------------------------------------------------------------- /src/lv_font/lv_font.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_font.c 2 | CSRCS += lv_font_fmt_txt.c 3 | CSRCS += lv_font_montserrat_12.c 4 | CSRCS += lv_font_montserrat_14.c 5 | CSRCS += lv_font_montserrat_16.c 6 | CSRCS += lv_font_montserrat_18.c 7 | CSRCS += lv_font_montserrat_20.c 8 | CSRCS += lv_font_montserrat_22.c 9 | CSRCS += lv_font_montserrat_24.c 10 | CSRCS += lv_font_montserrat_26.c 11 | CSRCS += lv_font_montserrat_28.c 12 | CSRCS += lv_font_montserrat_30.c 13 | CSRCS += lv_font_montserrat_32.c 14 | CSRCS += lv_font_montserrat_34.c 15 | CSRCS += lv_font_montserrat_36.c 16 | CSRCS += lv_font_montserrat_38.c 17 | CSRCS += lv_font_montserrat_40.c 18 | CSRCS += lv_font_montserrat_42.c 19 | CSRCS += lv_font_montserrat_44.c 20 | CSRCS += lv_font_montserrat_46.c 21 | CSRCS += lv_font_montserrat_48.c 22 | CSRCS += lv_font_montserrat_12_subpx.c 23 | CSRCS += lv_font_montserrat_28_compressed.c 24 | CSRCS += lv_font_unscii_8.c 25 | CSRCS += lv_font_dejavu_16_persian_hebrew.c 26 | 27 | DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_font 28 | VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_font 29 | 30 | CFLAGS += "-I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_font" 31 | -------------------------------------------------------------------------------- /src/lv_gpu/lv_gpu.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_gpu_stm32_dma2d.c 2 | 3 | DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_gpu 4 | VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_gpu 5 | 6 | CFLAGS += "-I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_gpu" 7 | -------------------------------------------------------------------------------- /src/lv_gpu/lv_gpu_stm32_dma2d.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_gpu_stm32_dma2d.h 3 | * 4 | */ 5 | 6 | #ifndef LV_GPU_STM32_DMA2D_H 7 | #define LV_GPU_STM32_DMA2D_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_misc/lv_area.h" 17 | #include "../lv_misc/lv_color.h" 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | 23 | #define LV_DMA2D_ARGB8888 0 24 | #define LV_DMA2D_RGB888 1 25 | #define LV_DMA2D_RGB565 2 26 | #define LV_DMA2D_ARGB1555 3 27 | #define LV_DMA2D_ARGB4444 4 28 | 29 | /********************** 30 | * TYPEDEFS 31 | **********************/ 32 | 33 | /********************** 34 | * GLOBAL PROTOTYPES 35 | **********************/ 36 | 37 | /** 38 | * Turn on the peripheral and set output color mode, this only needs to be done once 39 | */ 40 | void lv_gpu_stm32_dma2d_init(void); 41 | 42 | /** 43 | * Fill an area in the buffer with a color 44 | * @param buf a buffer which should be filled 45 | * @param buf_w width of the buffer in pixels 46 | * @param color fill color 47 | * @param fill_w width to fill in pixels (<= buf_w) 48 | * @param fill_h height to fill in pixels 49 | * @note `buf_w - fill_w` is offset to the next line after fill 50 | */ 51 | void lv_gpu_stm32_dma2d_fill(lv_color_t * buf, lv_coord_t buf_w, lv_color_t color, lv_coord_t fill_w, 52 | lv_coord_t fill_h); 53 | 54 | 55 | /** 56 | * Fill an area in the buffer with a color but take into account a mask which describes the opacity of each pixel 57 | * @param buf a buffer which should be filled using a mask 58 | * @param buf_w width of the buffer in pixels 59 | * @param color fill color 60 | * @param mask 0..255 values describing the opacity of the corresponding pixel. It's width is `fill_w` 61 | * @param opa overall opacity. 255 in `mask` should mean this opacity. 62 | * @param fill_w width to fill in pixels (<= buf_w) 63 | * @param fill_h height to fill in pixels 64 | * @note `buf_w - fill_w` is offset to the next line after fill 65 | */ 66 | void lv_gpu_stm32_dma2d_fill_mask(lv_color_t * buf, lv_coord_t buf_w, lv_color_t color, const lv_opa_t * mask, 67 | lv_opa_t opa, lv_coord_t fill_w, lv_coord_t fill_h); 68 | 69 | /** 70 | * Copy a map (typically RGB image) to a buffer 71 | * @param buf a buffer where map should be copied 72 | * @param buf_w width of the buffer in pixels 73 | * @param map an "image" to copy 74 | * @param map_w width of the map in pixels 75 | * @param copy_w width of the area to copy in pixels (<= buf_w) 76 | * @param copy_h height of the area to copy in pixels 77 | * @note `map_w - fill_w` is offset to the next line after copy 78 | */ 79 | void lv_gpu_stm32_dma2d_copy(lv_color_t * buf, lv_coord_t buf_w, const lv_color_t * map, lv_coord_t map_w, 80 | lv_coord_t copy_w, lv_coord_t copy_h); 81 | /** 82 | * Blend a map (e.g. ARGB image or RGB image with opacity) to a buffer 83 | * @param buf a buffer where `map` should be copied 84 | * @param buf_w width of the buffer in pixels 85 | * @param map an "image" to copy 86 | * @param opa opacity of `map` 87 | * @param map_w width of the map in pixels 88 | * @param copy_w width of the area to copy in pixels (<= buf_w) 89 | * @param copy_h height of the area to copy in pixels 90 | * @note `map_w - fill_w` is offset to the next line after copy 91 | */ 92 | void lv_gpu_stm32_dma2d_blend(lv_color_t * buf, lv_coord_t buf_w, const lv_color_t * map, lv_opa_t opa, 93 | lv_coord_t map_w, lv_coord_t copy_w, lv_coord_t copy_h); 94 | /********************** 95 | * MACROS 96 | **********************/ 97 | 98 | #ifdef __cplusplus 99 | } /* extern "C" */ 100 | #endif 101 | 102 | #endif /*LV_GPU_STM32_DMA2D_H*/ 103 | -------------------------------------------------------------------------------- /src/lv_hal/lv_hal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_hal.h 3 | * 4 | */ 5 | 6 | #ifndef LV_HAL_H 7 | #define LV_HAL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_hal_disp.h" 17 | #include "lv_hal_indev.h" 18 | #include "lv_hal_tick.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | #ifdef __cplusplus 37 | } /* extern "C" */ 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/lv_hal/lv_hal.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_hal_disp.c 2 | CSRCS += lv_hal_indev.c 3 | CSRCS += lv_hal_tick.c 4 | 5 | DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_hal 6 | VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_hal 7 | 8 | CFLAGS += "-I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_hal" 9 | -------------------------------------------------------------------------------- /src/lv_hal/lv_hal_tick.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file systick.c 3 | * Provide access to the system tick with 1 millisecond resolution 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "lv_hal_tick.h" 10 | #include 11 | 12 | #if LV_TICK_CUSTOM == 1 13 | #include LV_TICK_CUSTOM_INCLUDE 14 | #endif 15 | 16 | /********************* 17 | * DEFINES 18 | *********************/ 19 | 20 | /********************** 21 | * TYPEDEFS 22 | **********************/ 23 | 24 | /********************** 25 | * STATIC PROTOTYPES 26 | **********************/ 27 | 28 | /********************** 29 | * STATIC VARIABLES 30 | **********************/ 31 | static uint32_t sys_time = 0; 32 | static volatile uint8_t tick_irq_flag; 33 | 34 | /********************** 35 | * MACROS 36 | **********************/ 37 | 38 | /********************** 39 | * GLOBAL FUNCTIONS 40 | **********************/ 41 | 42 | /** 43 | * You have to call this function periodically 44 | * @param tick_period the call period of this function in milliseconds 45 | */ 46 | LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period) 47 | { 48 | tick_irq_flag = 0; 49 | sys_time += tick_period; 50 | } 51 | 52 | /** 53 | * Get the elapsed milliseconds since start up 54 | * @return the elapsed milliseconds 55 | */ 56 | uint32_t lv_tick_get(void) 57 | { 58 | #if LV_TICK_CUSTOM == 0 59 | 60 | /* If `lv_tick_inc` is called from an interrupt while `sys_time` is read 61 | * the result might be corrupted. 62 | * This loop detects if `lv_tick_inc` was called while reading `sys_time`. 63 | * If `tick_irq_flag` was cleared in `lv_tick_inc` try to read again 64 | * until `tick_irq_flag` remains `1`. */ 65 | uint32_t result; 66 | do { 67 | tick_irq_flag = 1; 68 | result = sys_time; 69 | } while(!tick_irq_flag); /*Continue until see a non interrupted cycle */ 70 | 71 | return result; 72 | #else 73 | return LV_TICK_CUSTOM_SYS_TIME_EXPR; 74 | #endif 75 | } 76 | 77 | /** 78 | * Get the elapsed milliseconds since a previous time stamp 79 | * @param prev_tick a previous time stamp (return value of systick_get() ) 80 | * @return the elapsed milliseconds since 'prev_tick' 81 | */ 82 | uint32_t lv_tick_elaps(uint32_t prev_tick) 83 | { 84 | uint32_t act_time = lv_tick_get(); 85 | 86 | /*If there is no overflow in sys_time simple subtract*/ 87 | if(act_time >= prev_tick) { 88 | prev_tick = act_time - prev_tick; 89 | } 90 | else { 91 | prev_tick = UINT32_MAX - prev_tick + 1; 92 | prev_tick += act_time; 93 | } 94 | 95 | return prev_tick; 96 | } 97 | 98 | /********************** 99 | * STATIC FUNCTIONS 100 | **********************/ 101 | -------------------------------------------------------------------------------- /src/lv_hal/lv_hal_tick.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_hal_tick.h 3 | * Provide access to the system tick with 1 millisecond resolution 4 | */ 5 | 6 | #ifndef LV_HAL_TICK_H 7 | #define LV_HAL_TICK_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #include 19 | #include 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | #ifndef LV_ATTRIBUTE_TICK_INC 25 | #define LV_ATTRIBUTE_TICK_INC 26 | #endif 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | //! @cond Doxygen_Suppress 37 | 38 | /** 39 | * You have to call this function periodically 40 | * @param tick_period the call period of this function in milliseconds 41 | */ 42 | LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period); 43 | 44 | //! @endcond 45 | 46 | /** 47 | * Get the elapsed milliseconds since start up 48 | * @return the elapsed milliseconds 49 | */ 50 | uint32_t lv_tick_get(void); 51 | 52 | /** 53 | * Get the elapsed milliseconds since a previous time stamp 54 | * @param prev_tick a previous time stamp (return value of systick_get() ) 55 | * @return the elapsed milliseconds since 'prev_tick' 56 | */ 57 | uint32_t lv_tick_elaps(uint32_t prev_tick); 58 | 59 | /********************** 60 | * MACROS 61 | **********************/ 62 | 63 | #ifdef __cplusplus 64 | } /* extern "C" */ 65 | #endif 66 | 67 | #endif /*LV_HAL_TICK_H*/ 68 | -------------------------------------------------------------------------------- /src/lv_misc/lv_async.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_async.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | 10 | #include "lv_async.h" 11 | 12 | /********************* 13 | * DEFINES 14 | *********************/ 15 | 16 | /********************** 17 | * TYPEDEFS 18 | **********************/ 19 | 20 | /********************** 21 | * STATIC PROTOTYPES 22 | **********************/ 23 | 24 | static void lv_async_task_cb(lv_task_t * task); 25 | 26 | /********************** 27 | * STATIC VARIABLES 28 | **********************/ 29 | 30 | /********************** 31 | * MACROS 32 | **********************/ 33 | 34 | /********************** 35 | * GLOBAL FUNCTIONS 36 | **********************/ 37 | 38 | lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) 39 | { 40 | /*Allocate an info structure */ 41 | lv_async_info_t * info = lv_mem_alloc(sizeof(lv_async_info_t)); 42 | 43 | if(info == NULL) 44 | return LV_RES_INV; 45 | 46 | /* Create a new task */ 47 | /* Use highest priority so that it will run before a refresh */ 48 | lv_task_t * task = lv_task_create(lv_async_task_cb, 0, LV_TASK_PRIO_HIGHEST, info); 49 | 50 | if(task == NULL) { 51 | lv_mem_free(info); 52 | return LV_RES_INV; 53 | } 54 | 55 | info->cb = async_xcb; 56 | info->user_data = user_data; 57 | 58 | /* Set the task's user data */ 59 | task->user_data = info; 60 | lv_task_set_repeat_count(task, 1); 61 | return LV_RES_OK; 62 | } 63 | 64 | /********************** 65 | * STATIC FUNCTIONS 66 | **********************/ 67 | 68 | static void lv_async_task_cb(lv_task_t * task) 69 | { 70 | lv_async_info_t * info = (lv_async_info_t *)task->user_data; 71 | 72 | info->cb(info->user_data); 73 | 74 | lv_mem_free(info); 75 | } 76 | -------------------------------------------------------------------------------- /src/lv_misc/lv_async.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_async.h 3 | * 4 | */ 5 | 6 | #ifndef LV_ASYNC_H 7 | #define LV_ASYNC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #include "lv_task.h" 18 | #include "lv_types.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /** 29 | * Type for async callback. 30 | */ 31 | typedef void (*lv_async_cb_t)(void *); 32 | 33 | typedef struct _lv_async_info_t { 34 | lv_async_cb_t cb; 35 | void * user_data; 36 | } lv_async_info_t; 37 | 38 | struct _lv_obj_t; 39 | 40 | /********************** 41 | * GLOBAL PROTOTYPES 42 | **********************/ 43 | 44 | /** 45 | * Call an asynchronous function the next time lv_task_handler() is run. This function is likely to return 46 | * **before** the call actually happens! 47 | * @param async_xcb a callback which is the task itself. 48 | * (the 'x' in the argument name indicates that its not a fully generic function because it not follows 49 | * the `func_name(object, callback, ...)` convention) 50 | * @param user_data custom parameter 51 | */ 52 | lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data); 53 | 54 | /********************** 55 | * MACROS 56 | **********************/ 57 | 58 | #ifdef __cplusplus 59 | } /* extern "C" */ 60 | #endif 61 | 62 | #endif /*LV_TEMPL_H*/ 63 | -------------------------------------------------------------------------------- /src/lv_misc/lv_bidi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_bifi.h 3 | * 4 | */ 5 | 6 | #ifndef LV_BIDI_H 7 | #define LV_BIDI_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #include 19 | #include 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | /* Special non printable strong characters. 25 | * They can be inserted to texts to affect the run's direction*/ 26 | #define LV_BIDI_LRO "\xE2\x80\xAD" /*U+202D*/ 27 | #define LV_BIDI_RLO "\xE2\x80\xAE" /*U+202E*/ 28 | 29 | /********************** 30 | * TYPEDEFS 31 | **********************/ 32 | enum { 33 | /*The first 4 values are stored in `lv_obj_t` on 2 bits*/ 34 | LV_BIDI_DIR_LTR = 0x00, 35 | LV_BIDI_DIR_RTL = 0x01, 36 | LV_BIDI_DIR_AUTO = 0x02, 37 | LV_BIDI_DIR_INHERIT = 0x03, 38 | 39 | LV_BIDI_DIR_NEUTRAL = 0x20, 40 | LV_BIDI_DIR_WEAK = 0x21, 41 | }; 42 | 43 | typedef uint8_t lv_bidi_dir_t; 44 | 45 | /********************** 46 | * GLOBAL PROTOTYPES 47 | **********************/ 48 | #if LV_USE_BIDI 49 | 50 | /** 51 | * Convert a text to get the characters in the correct visual order according to 52 | * Unicode Bidirectional Algorithm 53 | * @param str_in the text to process 54 | * @param str_out store the result here. Has the be `strlen(str_in)` length 55 | * @param base_dir `LV_BIDI_DIR_LTR` or `LV_BIDI_DIR_RTL` 56 | */ 57 | void _lv_bidi_process(const char * str_in, char * str_out, lv_bidi_dir_t base_dir); 58 | 59 | /** 60 | * Auto-detect the direction of a text based on the first strong character 61 | * @param txt the text to process 62 | * @return `LV_BIDI_DIR_LTR` or `LV_BIDI_DIR_RTL` 63 | */ 64 | lv_bidi_dir_t _lv_bidi_detect_base_dir(const char * txt); 65 | 66 | /** 67 | * Get the logical position of a character in a line 68 | * @param str_in the input string. Can be only one line. 69 | * @param bidi_txt internally the text is bidi processed which buffer can be get here. 70 | * If not required anymore has to freed with `lv_mem_free()` 71 | * Can be `NULL` is unused 72 | * @param len length of the line in character count 73 | * @param base_dir base direction of the text: `LV_BIDI_DIR_LTR` or `LV_BIDI_DIR_RTL` 74 | * @param visual_pos the visual character position which logical position should be get 75 | * @param is_rtl tell the the char at `visual_pos` is RTL or LTR context 76 | * @return the logical character position 77 | */ 78 | uint16_t _lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, 79 | uint32_t visual_pos, bool * is_rtl); 80 | 81 | /** 82 | * Get the visual position of a character in a line 83 | * @param str_in the input string. Can be only one line. 84 | * @param bidi_txt internally the text is bidi processed which buffer can be get here. 85 | * If not required anymore has to freed with `lv_mem_free()` 86 | * Can be `NULL` is unused 87 | * @param len length of the line in character count 88 | * @param base_dir base direction of the text: `LV_BIDI_DIR_LTR` or `LV_BIDI_DIR_RTL` 89 | * @param logical_pos the logical character position which visual position should be get 90 | * @param is_rtl tell the the char at `logical_pos` is RTL or LTR context 91 | * @return the visual character position 92 | */ 93 | uint16_t _lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_bidi_dir_t base_dir, 94 | uint32_t logical_pos, bool * is_rtl); 95 | 96 | /** 97 | * Bidi process a paragraph of text 98 | * @param str_in the string to process 99 | * @param str_out store the result here 100 | * @param len length of the text 101 | * @param base_dir base dir of the text 102 | * @param pos_conv_out an `uint16_t` array to store the related logical position of the character. 103 | * Can be `NULL` is unused 104 | * @param pos_conv_len length of `pos_conv_out` in element count 105 | */ 106 | void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, 107 | uint16_t * pos_conv_out, uint16_t pos_conv_len); 108 | 109 | /********************** 110 | * MACROS 111 | **********************/ 112 | 113 | #endif /*LV_USE_BIDI*/ 114 | 115 | #ifdef __cplusplus 116 | } /* extern "C" */ 117 | #endif 118 | 119 | #endif /*LV_BIDI_H*/ 120 | -------------------------------------------------------------------------------- /src/lv_misc/lv_debug.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_debug.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "lv_debug.h" 10 | 11 | #if LV_USE_DEBUG 12 | 13 | #include "lv_mem.h" 14 | #include 15 | 16 | /********************* 17 | * DEFINES 18 | *********************/ 19 | #ifndef LV_DEBUG_STR_MAX_LENGTH 20 | #define LV_DEBUG_STR_MAX_LENGTH (1024 * 8) 21 | #endif 22 | 23 | #ifndef LV_DEBUG_STR_MAX_REPEAT 24 | #define LV_DEBUG_STR_MAX_REPEAT 8 25 | #endif 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | /********************** 31 | * STATIC PROTOTYPES 32 | **********************/ 33 | 34 | /********************** 35 | * STATIC VARIABLES 36 | **********************/ 37 | 38 | /********************** 39 | * MACROS 40 | **********************/ 41 | 42 | /********************** 43 | * GLOBAL FUNCTIONS 44 | **********************/ 45 | 46 | bool lv_debug_check_null(const void * p) 47 | { 48 | if(p) return true; 49 | 50 | return false; 51 | } 52 | 53 | bool lv_debug_check_mem_integrity(void) 54 | { 55 | return lv_mem_test() == LV_RES_OK ? true : false; 56 | } 57 | 58 | bool lv_debug_check_str(const void * str) 59 | { 60 | const uint8_t * s = (const uint8_t *)str; 61 | uint8_t last_byte = 0; 62 | uint32_t rep = 0; 63 | uint32_t i; 64 | 65 | for(i = 0; i < LV_DEBUG_STR_MAX_LENGTH && s[i] != '\0'; i++) { 66 | if(s[i] != last_byte) { 67 | last_byte = s[i]; 68 | rep = 1; 69 | } 70 | else if(s[i] > 0x7F) { 71 | rep++; 72 | if(rep > LV_DEBUG_STR_MAX_REPEAT) { 73 | LV_LOG_WARN("lv_debug_check_str: a non-ASCII char has repeated more than LV_DEBUG_STR_MAX_REPEAT times)"); 74 | return false; 75 | } 76 | } 77 | 78 | if(s[i] < 10) { 79 | LV_LOG_WARN("lv_debug_check_str: invalid char in the string (< 10 value)"); 80 | return false; /*Shouldn't occur in strings*/ 81 | } 82 | } 83 | 84 | if(s[i] == '\0') return true; 85 | 86 | LV_LOG_WARN("lv_debug_check_str: string is longer than LV_DEBUG_STR_MAX_LENGTH"); 87 | return false; 88 | } 89 | 90 | void lv_debug_log_error(const char * msg, uint64_t value) 91 | { 92 | static const char hex[] = "0123456789ABCDEF"; 93 | 94 | size_t msg_len = strlen(msg); 95 | uint32_t value_len = sizeof(unsigned long int); 96 | 97 | if(msg_len < 230) { 98 | char buf[255]; 99 | char * bufp = buf; 100 | 101 | /*Add the function name*/ 102 | _lv_memcpy(bufp, msg, msg_len); 103 | bufp += msg_len; 104 | 105 | /*Add value in hey*/ 106 | *bufp = ' '; 107 | bufp ++; 108 | *bufp = '('; 109 | bufp ++; 110 | *bufp = '0'; 111 | bufp ++; 112 | *bufp = 'x'; 113 | bufp ++; 114 | 115 | int8_t i; 116 | for(i = value_len * 2 - 1; i >= 0; i--) { 117 | uint8_t x = (unsigned long int)((unsigned long int)value >> (i * 4)) & 0xF; 118 | 119 | *bufp = hex[x]; 120 | bufp++; 121 | } 122 | 123 | *bufp = ')'; 124 | bufp ++; 125 | 126 | *bufp = '\0'; 127 | LV_LOG_ERROR(buf); 128 | } 129 | else { 130 | LV_LOG_ERROR(msg); 131 | } 132 | } 133 | 134 | /********************** 135 | * STATIC FUNCTIONS 136 | **********************/ 137 | 138 | 139 | #endif /*LV_USE_DEBUG*/ 140 | 141 | -------------------------------------------------------------------------------- /src/lv_misc/lv_debug.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_debug.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DEBUG_H 7 | #define LV_DEBUG_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_DEBUG 19 | #include 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /********************** 30 | * GLOBAL PROTOTYPES 31 | **********************/ 32 | bool lv_debug_check_null(const void * p); 33 | 34 | bool lv_debug_check_mem_integrity(void); 35 | 36 | bool lv_debug_check_str(const void * str); 37 | 38 | void lv_debug_log_error(const char * msg, uint64_t value); 39 | 40 | /********************** 41 | * MACROS 42 | **********************/ 43 | 44 | #ifndef LV_DEBUG_ASSERT 45 | #define LV_DEBUG_ASSERT(expr, msg, value) \ 46 | do { \ 47 | if(!(expr)) { \ 48 | LV_LOG_ERROR(__func__); \ 49 | lv_debug_log_error(msg, (uint64_t)((uintptr_t)value)); \ 50 | while(1); \ 51 | } \ 52 | } while(0) 53 | #endif 54 | 55 | /*---------------- 56 | * CHECKS 57 | *----------------*/ 58 | 59 | #ifndef LV_DEBUG_IS_NULL 60 | #define LV_DEBUG_IS_NULL(p) (lv_debug_check_null(p)) 61 | #endif 62 | 63 | 64 | #ifndef LV_DEBUG_CHECK_MEM_INTEGRITY 65 | #define LV_DEBUG_CHECK_MEM_INTEGRITY() (lv_debug_check_mem_integrity()) 66 | #endif 67 | 68 | #ifndef LV_DEBUG_IS_STR 69 | #define LV_DEBUG_IS_STR(str) (lv_debug_check_null(str) && \ 70 | lv_debug_check_str(str)) 71 | #endif 72 | 73 | /*----------------- 74 | * ASSERTS 75 | *-----------------*/ 76 | 77 | /*clang-format off*/ 78 | 79 | #if LV_USE_ASSERT_NULL 80 | # ifndef LV_ASSERT_NULL 81 | # define LV_ASSERT_NULL(p) LV_DEBUG_ASSERT(LV_DEBUG_IS_NULL(p), "NULL pointer", p); 82 | # endif 83 | #else 84 | # define LV_ASSERT_NULL(p) true 85 | #endif 86 | 87 | #if LV_USE_ASSERT_MEM 88 | # ifndef LV_ASSERT_MEM 89 | # define LV_ASSERT_MEM(p) LV_DEBUG_ASSERT(LV_DEBUG_IS_NULL(p), "Out of memory", p); 90 | # endif 91 | #else 92 | # define LV_ASSERT_MEM(p) true 93 | #endif 94 | 95 | #if LV_USE_ASSERT_MEM_INTEGRITY 96 | # ifndef LV_ASSERT_MEM_INTEGRITY 97 | # define LV_ASSERT_MEM_INTEGRITY() LV_DEBUG_ASSERT(LV_DEBUG_CHECK_MEM_INTEGRITY(), "Memory integrity error", 0); 98 | # endif 99 | #else 100 | # define LV_ASSERT_MEM_INTEGRITY() true 101 | #endif 102 | 103 | #if LV_USE_ASSERT_STR 104 | # ifndef LV_ASSERT_STR 105 | # define LV_ASSERT_STR(str) LV_DEBUG_ASSERT(LV_DEBUG_IS_STR(str), "Strange or invalid string", str); 106 | # endif 107 | #else /* LV_USE_ASSERT_OBJ == 0 */ 108 | # if LV_USE_ASSERT_NULL /*Use at least LV_ASSERT_NULL if enabled*/ 109 | # define LV_ASSERT_STR(str) LV_ASSERT_NULL(str) 110 | # else 111 | # define LV_ASSERT_STR(str) true 112 | # endif 113 | #endif 114 | 115 | 116 | #else /* LV_USE_DEBUG == 0 */ 117 | 118 | #define LV_DEBUG_ASSERT(expr, msg, value) do{}while(0) 119 | 120 | #define LV_ASSERT_NULL(p) true 121 | #define LV_ASSERT_MEM(p) true 122 | #define LV_ASSERT_MEM_INTEGRITY() true 123 | #define LV_ASSERT_STR(p) true 124 | #define LV_ASSERT_OBJ(obj, obj_type) true 125 | 126 | #endif /* LV_USE_DEBUG */ 127 | /*clang-format on*/ 128 | 129 | #ifdef __cplusplus 130 | } /* extern "C" */ 131 | #endif 132 | 133 | #endif /*LV_DEBUG_H*/ 134 | -------------------------------------------------------------------------------- /src/lv_misc/lv_gc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_gc.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | 10 | #include "lv_gc.h" 11 | #include "string.h" 12 | 13 | #if defined(LV_GC_INCLUDE) 14 | #include LV_GC_INCLUDE 15 | #endif /* LV_ENABLE_GC */ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * STATIC PROTOTYPES 27 | **********************/ 28 | 29 | /********************** 30 | * STATIC VARIABLES 31 | **********************/ 32 | 33 | #if(!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0 34 | LV_ROOTS 35 | #endif /* LV_ENABLE_GC */ 36 | 37 | /********************** 38 | * MACROS 39 | **********************/ 40 | 41 | /********************** 42 | * GLOBAL FUNCTIONS 43 | **********************/ 44 | 45 | void _lv_gc_clear_roots(void) 46 | { 47 | #define LV_CLEAR_ROOT(root_type, root_name) _lv_memset_00(&LV_GC_ROOT(root_name), sizeof(LV_GC_ROOT(root_name))); 48 | LV_ITERATE_ROOTS(LV_CLEAR_ROOT) 49 | } 50 | 51 | /********************** 52 | * STATIC FUNCTIONS 53 | **********************/ 54 | -------------------------------------------------------------------------------- /src/lv_misc/lv_gc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_gc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_GC_H 7 | #define LV_GC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | #include 18 | #include "lv_mem.h" 19 | #include "lv_ll.h" 20 | #include "lv_task.h" 21 | #include "../lv_draw/lv_img_cache.h" 22 | #include "../lv_draw/lv_draw_mask.h" 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | #define LV_ITERATE_ROOTS(f) \ 29 | f(lv_ll_t, _lv_task_ll) /*Linked list to store the lv_tasks*/ \ 30 | f(lv_ll_t, _lv_disp_ll) /*Linked list of screens*/ \ 31 | f(lv_ll_t, _lv_indev_ll) /*Linked list of screens*/ \ 32 | f(lv_ll_t, _lv_drv_ll) \ 33 | f(lv_ll_t, _lv_file_ll) \ 34 | f(lv_ll_t, _lv_anim_ll) \ 35 | f(lv_ll_t, _lv_group_ll) \ 36 | f(lv_ll_t, _lv_img_defoder_ll) \ 37 | f(lv_ll_t, _lv_obj_style_trans_ll) \ 38 | f(lv_img_cache_entry_t*, _lv_img_cache_array) \ 39 | f(lv_task_t*, _lv_task_act) \ 40 | f(lv_mem_buf_arr_t , _lv_mem_buf) \ 41 | f(_lv_draw_mask_saved_arr_t , _lv_draw_mask_list) \ 42 | f(void * , _lv_theme_material_styles) \ 43 | f(void * , _lv_theme_template_styles) \ 44 | f(void * , _lv_theme_mono_styles) \ 45 | f(void * , _lv_theme_empty_styles) \ 46 | 47 | #define LV_DEFINE_ROOT(root_type, root_name) root_type root_name; 48 | #define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT) 49 | 50 | #if LV_ENABLE_GC == 1 51 | #if LV_MEM_CUSTOM != 1 52 | #error "GC requires CUSTOM_MEM" 53 | #endif /* LV_MEM_CUSTOM */ 54 | #else /* LV_ENABLE_GC */ 55 | #define LV_GC_ROOT(x) x 56 | #define LV_EXTERN_ROOT(root_type, root_name) extern root_type root_name; 57 | LV_ITERATE_ROOTS(LV_EXTERN_ROOT) 58 | #endif /* LV_ENABLE_GC */ 59 | 60 | /********************** 61 | * TYPEDEFS 62 | **********************/ 63 | 64 | /********************** 65 | * GLOBAL PROTOTYPES 66 | **********************/ 67 | 68 | void _lv_gc_clear_roots(void); 69 | 70 | /********************** 71 | * MACROS 72 | **********************/ 73 | 74 | #ifdef __cplusplus 75 | } /* extern "C" */ 76 | #endif 77 | 78 | #endif /*LV_GC_H*/ 79 | -------------------------------------------------------------------------------- /src/lv_misc/lv_log.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_log.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "lv_log.h" 10 | #if LV_USE_LOG 11 | 12 | #include 13 | #include 14 | #include "lv_printf.h" 15 | 16 | #if LV_LOG_PRINTF 17 | #include 18 | #endif 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * STATIC PROTOTYPES 30 | **********************/ 31 | 32 | /********************** 33 | * STATIC VARIABLES 34 | **********************/ 35 | static lv_log_print_g_cb_t custom_print_cb; 36 | 37 | /********************** 38 | * MACROS 39 | **********************/ 40 | 41 | /********************** 42 | * GLOBAL FUNCTIONS 43 | **********************/ 44 | 45 | /** 46 | * Register custom print/write function to call when a log is added. 47 | * It can format its "File path", "Line number" and "Description" as required 48 | * and send the formatted log message to a console or serial port. 49 | * @param print_cb a function pointer to print a log 50 | */ 51 | void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb) 52 | { 53 | custom_print_cb = print_cb; 54 | } 55 | 56 | 57 | /** 58 | * Add a log 59 | * @param level the level of log. (From `lv_log_level_t` enum) 60 | * @param file name of the file when the log added 61 | * @param line line number in the source code where the log added 62 | * @param func name of the function when the log added 63 | * @param format printf-like format string 64 | * @param ... parameters for `format` 65 | */ 66 | void _lv_log_add(lv_log_level_t level, const char * file, int line, const char * func, const char * format, ...) 67 | { 68 | if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/ 69 | 70 | if(level >= LV_LOG_LEVEL) { 71 | va_list args; 72 | va_start(args, format); 73 | char buf[256]; 74 | lv_vsnprintf(buf, sizeof(buf), format, args); 75 | va_end(args); 76 | 77 | #if LV_LOG_PRINTF 78 | /*Use only the file name not the path*/ 79 | size_t p; 80 | for(p = strlen(file); p > 0; p--) { 81 | if(file[p] == '/' || file[p] == '\\') { 82 | p++; /*Skip the slash*/ 83 | break; 84 | } 85 | } 86 | 87 | static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error", "User"}; 88 | printf("%s: %s \t(%s #%d %s())\n", lvl_prefix[level], buf, &file[p], line, func); 89 | #else 90 | if(custom_print_cb) custom_print_cb(level, file, line, func, buf); 91 | #endif 92 | } 93 | } 94 | 95 | /********************** 96 | * STATIC FUNCTIONS 97 | **********************/ 98 | 99 | #endif /*LV_USE_LOG*/ 100 | -------------------------------------------------------------------------------- /src/lv_misc/lv_math.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file math_base.h 3 | * 4 | */ 5 | 6 | #ifndef LV_MATH_H 7 | #define LV_MATH_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | #define LV_MATH_MIN(a, b) ((a) < (b) ? (a) : (b)) 23 | #define LV_MATH_MIN3(a, b, c) (LV_MATH_MIN(LV_MATH_MIN(a,b), c)) 24 | #define LV_MATH_MIN4(a, b, c, d) (LV_MATH_MIN(LV_MATH_MIN(a,b), LV_MATH_MIN(c,d))) 25 | 26 | #define LV_MATH_MAX(a, b) ((a) > (b) ? (a) : (b)) 27 | #define LV_MATH_MAX3(a, b, c) (LV_MATH_MAX(LV_MATH_MAX(a,b), c)) 28 | #define LV_MATH_MAX4(a, b, c, d) (LV_MATH_MAX(LV_MATH_MAX(a,b), LV_MATH_MAX(c,d))) 29 | 30 | #define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x))) 31 | 32 | #define LV_MATH_UDIV255(x) ((uint32_t)((uint32_t) (x) * 0x8081) >> 0x17) 33 | 34 | #define LV_IS_SIGNED(t) (((t)(-1)) < ((t) 0)) 35 | #define LV_UMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0xFULL << ((sizeof(t) * 8ULL) - 4ULL))) 36 | #define LV_SMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0x7ULL << ((sizeof(t) * 8ULL) - 4ULL))) 37 | #define LV_MAX_OF(t) ((unsigned long) (LV_IS_SIGNED(t) ? LV_SMAX_OF(t) : LV_UMAX_OF(t))) 38 | 39 | #define LV_TRIGO_SIN_MAX 32767 40 | #define LV_TRIGO_SHIFT 15 /**< >> LV_TRIGO_SHIFT to normalize*/ 41 | 42 | #define LV_BEZIER_VAL_MAX 1024 /**< Max time in Bezier functions (not [0..1] to use integers) */ 43 | #define LV_BEZIER_VAL_SHIFT 10 /**< log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ 44 | 45 | 46 | 47 | /********************** 48 | * TYPEDEFS 49 | **********************/ 50 | 51 | typedef struct { 52 | uint16_t i; 53 | uint16_t f; 54 | } lv_sqrt_res_t; 55 | 56 | 57 | /********************** 58 | * GLOBAL PROTOTYPES 59 | **********************/ 60 | 61 | //! @cond Doxygen_Suppress 62 | /** 63 | * Return with sinus of an angle 64 | * @param angle 65 | * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 66 | */ 67 | LV_ATTRIBUTE_FAST_MEM int16_t _lv_trigo_sin(int16_t angle); 68 | 69 | //! @endcond 70 | 71 | /** 72 | * Calculate a value of a Cubic Bezier function. 73 | * @param t time in range of [0..LV_BEZIER_VAL_MAX] 74 | * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] 75 | * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] 76 | * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] 77 | * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] 78 | * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] 79 | */ 80 | int32_t _lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3); 81 | 82 | /** 83 | * Calculate the atan2 of a vector. 84 | * @param x 85 | * @param y 86 | * @return the angle in degree calculated from the given parameters in range of [0..360] 87 | */ 88 | uint16_t _lv_atan2(int x, int y); 89 | 90 | 91 | //! @cond Doxygen_Suppress 92 | 93 | /** 94 | * Get the square root of a number 95 | * @param x integer which square root should be calculated 96 | * @param q store the result here. q->i: integer part, q->f: fractional part in 1/256 unit 97 | * @param mask: optional to skip some iterations if the magnitude of the root is known. 98 | * Set to 0x8000 by default. 99 | * If root < 16: mask = 0x80 100 | * If root < 256: mask = 0x800 101 | * Else: mask = 0x8000 102 | */ 103 | LV_ATTRIBUTE_FAST_MEM void _lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask); 104 | 105 | //! @endcond 106 | 107 | /** 108 | * Calculate the integer exponents. 109 | * @param base 110 | * @param power 111 | * @return base raised to the power exponent 112 | */ 113 | int64_t _lv_pow(int64_t base, int8_t exp); 114 | 115 | /********************** 116 | * MACROS 117 | **********************/ 118 | 119 | #ifdef __cplusplus 120 | } /* extern "C" */ 121 | #endif 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /src/lv_misc/lv_misc.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_area.c 2 | CSRCS += lv_task.c 3 | CSRCS += lv_fs.c 4 | CSRCS += lv_anim.c 5 | CSRCS += lv_mem.c 6 | CSRCS += lv_ll.c 7 | CSRCS += lv_color.c 8 | CSRCS += lv_txt.c 9 | CSRCS += lv_txt_ap.c 10 | CSRCS += lv_math.c 11 | CSRCS += lv_log.c 12 | CSRCS += lv_gc.c 13 | CSRCS += lv_utils.c 14 | CSRCS += lv_async.c 15 | CSRCS += lv_printf.c 16 | CSRCS += lv_bidi.c 17 | CSRCS += lv_debug.c 18 | 19 | DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_misc 20 | VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_misc 21 | 22 | CFLAGS += "-I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_misc" 23 | -------------------------------------------------------------------------------- /src/lv_misc/lv_printf.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // \author (c) Marco Paland (info@paland.com) 3 | // 2014-2019, PALANDesign Hannover, Germany 4 | // 5 | // \license The MIT License (MIT) 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on 26 | // embedded systems with a very limited resources. 27 | // Use this instead of bloated standard/newlib printf. 28 | // These routines are thread safe and reentrant. 29 | // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef _LV_PRINTF_H_ 33 | #define _LV_PRINTF_H_ 34 | 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #include "../lv_conf_internal.h" 41 | 42 | #if LV_SPRINTF_CUSTOM == 0 43 | 44 | #include 45 | #include 46 | 47 | /** 48 | * Tiny snprintf/vsnprintf implementation 49 | * \param buffer A pointer to the buffer where to store the formatted string 50 | * \param count The maximum number of characters to store in the buffer, including a terminating null character 51 | * \param format A string that specifies the format of the output 52 | * \param va A value identifying a variable arguments list 53 | * \return The number of characters that COULD have been written into the buffer, not counting the terminating 54 | * null character. A value equal or larger than count indicates truncation. Only when the returned value 55 | * is non-negative and less than count, the string has been completely written. 56 | */ 57 | int lv_snprintf(char * buffer, size_t count, const char * format, ...); 58 | int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va); 59 | 60 | #else 61 | #include LV_SPRINTF_INCLUDE 62 | #endif 63 | 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | 70 | #endif // _PRINTF_H_ 71 | -------------------------------------------------------------------------------- /src/lv_misc/lv_templ.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | 10 | /********************* 11 | * DEFINES 12 | *********************/ 13 | 14 | /********************** 15 | * TYPEDEFS 16 | **********************/ 17 | 18 | /* This typedef exists purely to keep -Wpedantic happy when the file is empty. */ 19 | /* It can be removed. */ 20 | typedef int _keep_pedantic_happy; 21 | 22 | /********************** 23 | * STATIC PROTOTYPES 24 | **********************/ 25 | 26 | /********************** 27 | * STATIC VARIABLES 28 | **********************/ 29 | 30 | /********************** 31 | * MACROS 32 | **********************/ 33 | 34 | /********************** 35 | * GLOBAL FUNCTIONS 36 | **********************/ 37 | 38 | /********************** 39 | * STATIC FUNCTIONS 40 | **********************/ 41 | -------------------------------------------------------------------------------- /src/lv_misc/lv_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEMPL_H 7 | #define LV_TEMPL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | 29 | /********************** 30 | * MACROS 31 | **********************/ 32 | 33 | #ifdef __cplusplus 34 | } /* extern "C" */ 35 | #endif 36 | 37 | #endif /*LV_TEMPL_H*/ 38 | -------------------------------------------------------------------------------- /src/lv_misc/lv_txt_ap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_txt_ap.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TXT_AP_H 7 | #define LV_TXT_AP_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | #include "lv_txt.h" 18 | #include "../lv_draw/lv_draw.h" 19 | 20 | #if LV_USE_ARABIC_PERSIAN_CHARS == 1 21 | 22 | /********************* 23 | * DEFINES 24 | *********************/ 25 | 26 | #define LV_UNDEF_ARABIC_PERSIAN_CHARS (UINT32_MAX) 27 | #define LV_AP_ALPHABET_BASE_CODE 0x0622 28 | #define LV_AP_END_CHARS_LIST {0,0,0,0,0,{0,0}} 29 | /********************** 30 | * TYPEDEFS 31 | **********************/ 32 | typedef struct { 33 | uint8_t char_offset; 34 | uint16_t char_end_form; 35 | int8_t char_begining_form_offset; 36 | int8_t char_middle_form_offset; 37 | int8_t char_isolated_form_offset; 38 | struct { 39 | uint8_t conj_to_previous; 40 | uint8_t conj_to_next; 41 | } ap_chars_conjunction; 42 | } ap_chars_map_t; 43 | 44 | /********************** 45 | * GLOBAL PROTOTYPES 46 | **********************/ 47 | uint32_t _lv_txt_ap_calc_bytes_cnt(const char * txt); 48 | void _lv_txt_ap_proc(const char * txt, char * txt_out); 49 | 50 | /********************** 51 | * MACROS 52 | **********************/ 53 | 54 | #endif // LV_USE_ARABIC_PERSIAN_CHARS 55 | 56 | #ifdef __cplusplus 57 | } /* extern "C" */ 58 | #endif 59 | 60 | #endif /*LV_TXT_AP_H*/ 61 | -------------------------------------------------------------------------------- /src/lv_misc/lv_types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_types.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TYPES_H 7 | #define LV_TYPES_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | #if __STDC_VERSION__ >= 199901L // If c99 or newer, use stdint.h to determine arch size 22 | #include 23 | #endif 24 | 25 | 26 | // If __UINTPTR_MAX__ or UINTPTR_MAX are available, use them to determine arch size 27 | #if defined(__UINTPTR_MAX__) && __UINTPTR_MAX__ > 0xFFFFFFFF 28 | #define LV_ARCH_64 29 | 30 | #elif defined(UINTPTR_MAX) && UINTPTR_MAX > 0xFFFFFFFF 31 | #define LV_ARCH_64 32 | 33 | // Otherwise use compiler-dependent means to determine arch size 34 | #elif defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) || defined (__aarch64__) 35 | #define LV_ARCH_64 36 | 37 | #endif 38 | 39 | 40 | /********************** 41 | * TYPEDEFS 42 | **********************/ 43 | 44 | /** 45 | * LVGL error codes. 46 | */ 47 | enum { 48 | LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action 49 | function or an operation was failed*/ 50 | LV_RES_OK, /*The object is valid (no deleted) after the action*/ 51 | }; 52 | typedef uint8_t lv_res_t; 53 | 54 | 55 | 56 | #if __STDC_VERSION__ >= 199901L 57 | // If c99 or newer, use the definition of uintptr_t directly from 58 | typedef uintptr_t lv_uintptr_t; 59 | 60 | #else 61 | 62 | // Otherwise, use the arch size determination 63 | #ifdef LV_ARCH_64 64 | typedef uint64_t lv_uintptr_t; 65 | #else 66 | typedef uint32_t lv_uintptr_t; 67 | #endif 68 | 69 | #endif 70 | 71 | 72 | /********************** 73 | * GLOBAL PROTOTYPES 74 | **********************/ 75 | 76 | /********************** 77 | * MACROS 78 | **********************/ 79 | 80 | #define LV_UNUSED(x) ((void) x) 81 | 82 | #ifdef __cplusplus 83 | } /* extern "C" */ 84 | #endif 85 | 86 | #endif /*LV_TYPES_H*/ 87 | 88 | -------------------------------------------------------------------------------- /src/lv_misc/lv_utils.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_utils.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include 10 | 11 | #include "lv_utils.h" 12 | #include "lv_math.h" 13 | #include "lv_printf.h" 14 | #include "lv_txt.h" 15 | 16 | /********************* 17 | * DEFINES 18 | *********************/ 19 | 20 | /********************** 21 | * TYPEDEFS 22 | **********************/ 23 | 24 | /********************** 25 | * STATIC PROTOTYPES 26 | **********************/ 27 | 28 | /********************** 29 | * STATIC VARIABLES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL FUNCTIONS 38 | **********************/ 39 | 40 | /** 41 | * Convert a number to string 42 | * @param num a number 43 | * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) 44 | * @return same as `buf` (just for convenience) 45 | */ 46 | char * _lv_utils_num_to_str(int32_t num, char * buf) 47 | { 48 | if(num == 0) { 49 | buf[0] = '0'; 50 | buf[1] = '\0'; 51 | return buf; 52 | } 53 | int8_t digitCount = 0; 54 | int8_t i = 0; 55 | if(num < 0) { 56 | buf[digitCount++] = '-'; 57 | num = LV_MATH_ABS(num); 58 | ++i; 59 | } 60 | while(num) { 61 | char digit = num % 10; 62 | buf[digitCount++] = digit + 48; 63 | num /= 10; 64 | } 65 | buf[digitCount] = '\0'; 66 | digitCount--; 67 | while(digitCount > i) { 68 | char temp = buf[i]; 69 | buf[i] = buf[digitCount]; 70 | buf[digitCount] = temp; 71 | digitCount--; 72 | i++; 73 | } 74 | return buf; 75 | } 76 | 77 | /** Searches base[0] to base[n - 1] for an item that matches *key. 78 | * 79 | * @note The function cmp must return negative if its first 80 | * argument (the search key) is less that its second (a table entry), 81 | * zero if equal, and positive if greater. 82 | * 83 | * @note Items in the array must be in ascending order. 84 | * 85 | * @param key Pointer to item being searched for 86 | * @param base Pointer to first element to search 87 | * @param n Number of elements 88 | * @param size Size of each element 89 | * @param cmp Pointer to comparison function (see #lv_font_codeCompare as a comparison function 90 | * example) 91 | * 92 | * @return a pointer to a matching item, or NULL if none exists. 93 | */ 94 | void * _lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size, 95 | int32_t (*cmp)(const void * pRef, const void * pElement)) 96 | { 97 | const char * middle; 98 | int32_t c; 99 | 100 | for(middle = base; n != 0;) { 101 | middle += (n / 2) * size; 102 | if((c = (*cmp)(key, middle)) > 0) { 103 | n = (n / 2) - ((n & 1) == 0); 104 | base = (middle += size); 105 | } 106 | else if(c < 0) { 107 | n /= 2; 108 | middle = base; 109 | } 110 | else { 111 | return (char *)middle; 112 | } 113 | } 114 | return NULL; 115 | } 116 | 117 | /********************** 118 | * STATIC FUNCTIONS 119 | **********************/ 120 | -------------------------------------------------------------------------------- /src/lv_misc/lv_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_utils.h 3 | * 4 | */ 5 | 6 | #ifndef LV_UTILS_H 7 | #define LV_UTILS_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | 23 | /********************** 24 | * TYPEDEFS 25 | **********************/ 26 | 27 | /********************** 28 | * GLOBAL PROTOTYPES 29 | **********************/ 30 | /** 31 | * Convert a number to string 32 | * @param num a number 33 | * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) 34 | * @return same as `buf` (just for convenience) 35 | */ 36 | char * _lv_utils_num_to_str(int32_t num, char * buf); 37 | 38 | /** Searches base[0] to base[n - 1] for an item that matches *key. 39 | * 40 | * @note The function cmp must return negative if its first 41 | * argument (the search key) is less that its second (a table entry), 42 | * zero if equal, and positive if greater. 43 | * 44 | * @note Items in the array must be in ascending order. 45 | * 46 | * @param key Pointer to item being searched for 47 | * @param base Pointer to first element to search 48 | * @param n Number of elements 49 | * @param size Size of each element 50 | * @param cmp Pointer to comparison function (see #lv_font_codeCompare as a comparison function 51 | * example) 52 | * 53 | * @return a pointer to a matching item, or NULL if none exists. 54 | */ 55 | void * _lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size, 56 | int32_t (*cmp)(const void * pRef, const void * pElement)); 57 | 58 | /********************** 59 | * MACROS 60 | **********************/ 61 | 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/lv_themes/lv_theme_empty.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_empty.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include 10 | #include "../../lvgl.h" /*To see all the widgets*/ 11 | 12 | #if LV_USE_THEME_EMPTY 13 | 14 | #include "../lv_misc/lv_gc.h" 15 | 16 | #if defined(LV_GC_INCLUDE) 17 | #include LV_GC_INCLUDE 18 | #endif /* LV_ENABLE_GC */ 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | typedef struct { 28 | lv_style_t opa_cover; 29 | } theme_styles_t; 30 | 31 | /********************** 32 | * STATIC PROTOTYPES 33 | **********************/ 34 | static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name); 35 | static void style_init_reset(lv_style_t * style); 36 | 37 | /********************** 38 | * STATIC VARIABLES 39 | **********************/ 40 | static lv_theme_t theme; 41 | static theme_styles_t * styles; 42 | 43 | static bool inited; 44 | 45 | /********************** 46 | * MACROS 47 | **********************/ 48 | 49 | /********************** 50 | * STATIC FUNCTIONS 51 | **********************/ 52 | 53 | /********************** 54 | * GLOBAL FUNCTIONS 55 | **********************/ 56 | 57 | /** 58 | * Initialize the default 59 | * @param color_primary the primary color of the theme 60 | * @param color_secondary the secondary color for the theme 61 | * @param flags ORed flags starting with `LV_THEME_DEF_FLAG_...` 62 | * @param font_small pointer to a small font 63 | * @param font_normal pointer to a normal font 64 | * @param font_subtitle pointer to a large font 65 | * @param font_title pointer to a extra large font 66 | * @return a pointer to reference this theme later 67 | */ 68 | lv_theme_t * lv_theme_empty_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, 69 | const lv_font_t * font_small, const lv_font_t * font_normal, const lv_font_t * font_subtitle, 70 | const lv_font_t * font_title) 71 | { 72 | /* This trick is required only to avoid the garbage collection of 73 | * styles' data if LVGL is used in a binding (e.g. Micropython) 74 | * In a general case styles could be simple `static lv_style_t my style` variables*/ 75 | if(!inited) { 76 | LV_GC_ROOT(_lv_theme_empty_styles) = lv_mem_alloc(sizeof(theme_styles_t)); 77 | styles = (theme_styles_t *)LV_GC_ROOT(_lv_theme_empty_styles); 78 | } 79 | 80 | 81 | theme.color_primary = color_primary; 82 | theme.color_secondary = color_secondary; 83 | theme.font_small = font_small; 84 | theme.font_normal = font_normal; 85 | theme.font_subtitle = font_subtitle; 86 | theme.font_title = font_title; 87 | theme.flags = flags; 88 | 89 | style_init_reset(&styles->opa_cover); 90 | lv_style_set_bg_opa(&styles->opa_cover, LV_STATE_DEFAULT, LV_OPA_COVER); 91 | 92 | theme.apply_xcb = NULL; 93 | theme.apply_cb = theme_apply; 94 | return &theme; 95 | } 96 | 97 | 98 | static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) 99 | { 100 | LV_UNUSED(th); 101 | if(name == LV_THEME_SCR) { 102 | lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); 103 | lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &styles->opa_cover); 104 | } 105 | } 106 | 107 | /********************** 108 | * STATIC FUNCTIONS 109 | **********************/ 110 | 111 | static void style_init_reset(lv_style_t * style) 112 | { 113 | if(inited) lv_style_reset(style); 114 | else lv_style_init(style); 115 | } 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /src/lv_themes/lv_theme_empty.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_material.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_EMPTY_H 7 | #define LV_THEME_EMPTY_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_THEME_EMPTY 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | 33 | /** 34 | * Initialize the default 35 | * @param color_primary the primary color of the theme 36 | * @param color_secondary the secondary color for the theme 37 | * @param flags ORed flags starting with `LV_THEME_DEF_FLAG_...` 38 | * @param font_small pointer to a small font 39 | * @param font_normal pointer to a normal font 40 | * @param font_subtitle pointer to a large font 41 | * @param font_title pointer to a extra large font 42 | * @return a pointer to reference this theme later 43 | */ 44 | lv_theme_t * lv_theme_empty_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, 45 | const lv_font_t * font_small, const lv_font_t * font_normal, const lv_font_t * font_subtitle, 46 | const lv_font_t * font_title); 47 | /********************** 48 | * MACROS 49 | **********************/ 50 | 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } /* extern "C" */ 55 | #endif 56 | 57 | #endif /*LV_THEME_ALIEN_H*/ 58 | -------------------------------------------------------------------------------- /src/lv_themes/lv_theme_material.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_material.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_MATERIAL_H 7 | #define LV_THEME_MATERIAL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_THEME_MATERIAL 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | typedef enum { 24 | LV_THEME_MATERIAL_FLAG_DARK = 0x01, 25 | LV_THEME_MATERIAL_FLAG_LIGHT = 0x02, 26 | LV_THEME_MATERIAL_FLAG_NO_TRANSITION = 0x10, 27 | LV_THEME_MATERIAL_FLAG_NO_FOCUS = 0x20, 28 | } lv_theme_material_flag_t; 29 | 30 | /********************** 31 | * TYPEDEFS 32 | **********************/ 33 | 34 | /********************** 35 | * GLOBAL PROTOTYPES 36 | **********************/ 37 | 38 | /** 39 | * Initialize the default 40 | * @param color_primary the primary color of the theme 41 | * @param color_secondary the secondary color for the theme 42 | * @param flags ORed flags starting with `LV_THEME_DEF_FLAG_...` 43 | * @param font_small pointer to a small font 44 | * @param font_normal pointer to a normal font 45 | * @param font_subtitle pointer to a large font 46 | * @param font_title pointer to a extra large font 47 | * @return a pointer to reference this theme later 48 | */ 49 | lv_theme_t * lv_theme_material_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, 50 | const lv_font_t * font_small, const lv_font_t * font_normal, const lv_font_t * font_subtitle, 51 | const lv_font_t * font_title); 52 | /********************** 53 | * MACROS 54 | **********************/ 55 | 56 | #endif 57 | 58 | #ifdef __cplusplus 59 | } /* extern "C" */ 60 | #endif 61 | 62 | #endif /*LV_THEME_MATERIAL_H*/ 63 | -------------------------------------------------------------------------------- /src/lv_themes/lv_theme_mono.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_mono.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_MONO_H 7 | #define LV_THEME_MONO_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_THEME_MONO 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | 33 | /** 34 | * Initialize the mono theme. 35 | * @param color_primary the primary color of the theme 36 | * @param color_secondary the secondary color for the theme 37 | * @param flags ORed flags starting with `LV_THEME_DEF_FLAG_...` 38 | * @param font_small pointer to a small font 39 | * @param font_normal pointer to a normal font 40 | * @param font_subtitle pointer to a large font 41 | * @param font_title pointer to a extra large font 42 | * @return a pointer to reference this theme later 43 | */ 44 | lv_theme_t * lv_theme_mono_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, 45 | const lv_font_t * font_small, const lv_font_t * font_normal, const lv_font_t * font_subtitle, 46 | const lv_font_t * font_title); 47 | /********************** 48 | * MACROS 49 | **********************/ 50 | 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } /* extern "C" */ 55 | #endif 56 | 57 | #endif /*LV_THEME_TEMPLATE_H*/ 58 | -------------------------------------------------------------------------------- /src/lv_themes/lv_theme_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_template.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_TEMPLATE_H 7 | #define LV_THEME_TEMPLATE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_THEME_TEMPLATE 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | 33 | /** 34 | * Initialize the default 35 | * @param color_primary the primary color of the theme 36 | * @param color_secondary the secondary color for the theme 37 | * @param flags ORed flags starting with `LV_THEME_DEF_FLAG_...` 38 | * @param font_small pointer to a small font 39 | * @param font_normal pointer to a normal font 40 | * @param font_subtitle pointer to a large font 41 | * @param font_title pointer to a extra large font 42 | * @return a pointer to reference this theme later 43 | */ 44 | lv_theme_t * lv_theme_template_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, 45 | const lv_font_t * font_small, const lv_font_t * font_normal, const lv_font_t * font_subtitle, 46 | const lv_font_t * font_title); 47 | /********************** 48 | * MACROS 49 | **********************/ 50 | 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } /* extern "C" */ 55 | #endif 56 | 57 | #endif /*LV_THEME_TEMPLATE_H*/ 58 | -------------------------------------------------------------------------------- /src/lv_themes/lv_themes.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_theme.c 2 | CSRCS += lv_theme_material.c 3 | CSRCS += lv_theme_mono.c 4 | CSRCS += lv_theme_empty.c 5 | CSRCS += lv_theme_template.c 6 | 7 | DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_themes 8 | VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_themes 9 | 10 | CFLAGS += "-I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_themes" 11 | -------------------------------------------------------------------------------- /src/lv_widgets/lv_arc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_arc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_ARC_H 7 | #define LV_ARC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_ARC != 0 19 | 20 | #include "../lv_core/lv_obj.h" 21 | 22 | /********************* 23 | * DEFINES 24 | *********************/ 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | /*Data of arc*/ 30 | typedef struct { 31 | /*New data for this type */ 32 | uint16_t rotation_angle; 33 | uint16_t arc_angle_start; 34 | uint16_t arc_angle_end; 35 | uint16_t bg_angle_start; 36 | uint16_t bg_angle_end; 37 | lv_style_list_t style_arc; 38 | } lv_arc_ext_t; 39 | 40 | /*Parts of the arc*/ 41 | enum { 42 | LV_ARC_PART_BG = LV_OBJ_PART_MAIN, 43 | LV_ARC_PART_INDIC, 44 | _LV_ARC_PART_VIRTUAL_LAST, 45 | 46 | _LV_ARC_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST, 47 | }; 48 | typedef uint8_t lv_arc_part_t; 49 | 50 | /********************** 51 | * GLOBAL PROTOTYPES 52 | **********************/ 53 | 54 | /** 55 | * Create a arc objects 56 | * @param par pointer to an object, it will be the parent of the new arc 57 | * @param copy pointer to a arc object, if not NULL then the new object will be copied from it 58 | * @return pointer to the created arc 59 | */ 60 | lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy); 61 | 62 | /*====================== 63 | * Add/remove functions 64 | *=====================*/ 65 | 66 | /*===================== 67 | * Setter functions 68 | *====================*/ 69 | 70 | /** 71 | * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. 72 | * @param arc pointer to an arc object 73 | * @param start the start angle 74 | */ 75 | void lv_arc_set_start_angle(lv_obj_t * arc, uint16_t start); 76 | 77 | /** 78 | * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. 79 | * @param arc pointer to an arc object 80 | * @param end the end angle 81 | */ 82 | void lv_arc_set_end_angle(lv_obj_t * arc, uint16_t end); 83 | 84 | /** 85 | * Set the start and end angles 86 | * @param arc pointer to an arc object 87 | * @param start the start angle 88 | * @param end the end angle 89 | */ 90 | void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end); 91 | 92 | /** 93 | * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc. 94 | * @param arc pointer to an arc object 95 | * @param start the start angle 96 | */ 97 | void lv_arc_set_bg_start_angle(lv_obj_t * arc, uint16_t start); 98 | 99 | /** 100 | * Set the start angle of an arc background. 0 deg: right, 90 bottom etc. 101 | * @param arc pointer to an arc object 102 | * @param end the end angle 103 | */ 104 | void lv_arc_set_bg_end_angle(lv_obj_t * arc, uint16_t end); 105 | 106 | /** 107 | * Set the start and end angles of the arc background 108 | * @param arc pointer to an arc object 109 | * @param start the start angle 110 | * @param end the end angle 111 | */ 112 | void lv_arc_set_bg_angles(lv_obj_t * arc, uint16_t start, uint16_t end); 113 | 114 | /** 115 | * Set the rotation for the whole arc 116 | * @param arc pointer to an arc object 117 | * @param rotation_angle rotation angle 118 | */ 119 | void lv_arc_set_rotation(lv_obj_t * arc, uint16_t rotation_angle); 120 | 121 | /*===================== 122 | * Getter functions 123 | *====================*/ 124 | 125 | /** 126 | * Get the start angle of an arc. 127 | * @param arc pointer to an arc object 128 | * @return the start angle [0..360] 129 | */ 130 | uint16_t lv_arc_get_angle_start(lv_obj_t * arc); 131 | 132 | /** 133 | * Get the end angle of an arc. 134 | * @param arc pointer to an arc object 135 | * @return the end angle [0..360] 136 | */ 137 | uint16_t lv_arc_get_angle_end(lv_obj_t * arc); 138 | 139 | /** 140 | * Get the start angle of an arc background. 141 | * @param arc pointer to an arc object 142 | * @return the start angle [0..360] 143 | */ 144 | uint16_t lv_arc_get_bg_angle_start(lv_obj_t * arc); 145 | 146 | /** 147 | * Get the end angle of an arc background. 148 | * @param arc pointer to an arc object 149 | * @return the end angle [0..360] 150 | */ 151 | uint16_t lv_arc_get_bg_angle_end(lv_obj_t * arc); 152 | 153 | /*===================== 154 | * Other functions 155 | *====================*/ 156 | 157 | /********************** 158 | * MACROS 159 | **********************/ 160 | 161 | #endif /*LV_USE_ARC*/ 162 | 163 | #ifdef __cplusplus 164 | } /* extern "C" */ 165 | #endif 166 | 167 | #endif /*LV_ARC_H*/ 168 | -------------------------------------------------------------------------------- /src/lv_widgets/lv_led.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_led.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LED_H 7 | #define LV_LED_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_LED != 0 19 | 20 | #include "../lv_core/lv_obj.h" 21 | 22 | /********************* 23 | * DEFINES 24 | *********************/ 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | /*Data of led*/ 31 | typedef struct { 32 | /*No inherited ext.*/ 33 | /*New data for this type */ 34 | uint8_t bright; /*Current brightness of the LED (0..255)*/ 35 | } lv_led_ext_t; 36 | 37 | /*Parts of LED*/ 38 | enum { 39 | LV_LED_PART_MAIN = LV_OBJ_PART_MAIN, 40 | }; 41 | typedef uint8_t lv_led_part_t; 42 | 43 | /********************** 44 | * GLOBAL PROTOTYPES 45 | **********************/ 46 | 47 | /** 48 | * Create a led objects 49 | * @param par pointer to an object, it will be the parent of the new led 50 | * @param copy pointer to a led object, if not NULL then the new object will be copied from it 51 | * @return pointer to the created led 52 | */ 53 | lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy); 54 | 55 | /** 56 | * Set the brightness of a LED object 57 | * @param led pointer to a LED object 58 | * @param bright LV_LED_BRIGHT_MIN (max. dark) ... LV_LED_BRIGHT_MAX (max. light) 59 | */ 60 | void lv_led_set_bright(lv_obj_t * led, uint8_t bright); 61 | 62 | /** 63 | * Light on a LED 64 | * @param led pointer to a LED object 65 | */ 66 | void lv_led_on(lv_obj_t * led); 67 | 68 | /** 69 | * Light off a LED 70 | * @param led pointer to a LED object 71 | */ 72 | void lv_led_off(lv_obj_t * led); 73 | 74 | /** 75 | * Toggle the state of a LED 76 | * @param led pointer to a LED object 77 | */ 78 | void lv_led_toggle(lv_obj_t * led); 79 | 80 | /** 81 | * Get the brightness of a LEd object 82 | * @param led pointer to LED object 83 | * @return bright 0 (max. dark) ... 255 (max. light) 84 | */ 85 | uint8_t lv_led_get_bright(const lv_obj_t * led); 86 | 87 | /********************** 88 | * MACROS 89 | **********************/ 90 | 91 | #endif /*LV_USE_LED*/ 92 | 93 | #ifdef __cplusplus 94 | } /* extern "C" */ 95 | #endif 96 | 97 | #endif /*LV_LED_H*/ 98 | -------------------------------------------------------------------------------- /src/lv_widgets/lv_line.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_line.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LINE_H 7 | #define LV_LINE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_LINE != 0 19 | 20 | #include "../lv_core/lv_obj.h" 21 | 22 | /********************* 23 | * DEFINES 24 | *********************/ 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | /*Data of line*/ 31 | typedef struct { 32 | /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ 33 | const lv_point_t * point_array; /*Pointer to an array with the points of the line*/ 34 | uint16_t point_num; /*Number of points in 'point_array' */ 35 | uint8_t auto_size : 1; /*1: set obj. width to x max and obj. height to y max */ 36 | uint8_t y_inv : 1; /*1: y == 0 will be on the bottom*/ 37 | } lv_line_ext_t; 38 | 39 | /*Styles*/ 40 | enum { 41 | LV_LINE_PART_MAIN, 42 | }; 43 | typedef uint8_t lv_line_style_t; 44 | 45 | /********************** 46 | * GLOBAL PROTOTYPES 47 | **********************/ 48 | 49 | /** 50 | * Create a line objects 51 | * @param par pointer to an object, it will be the parent of the new line 52 | * @return pointer to the created line 53 | */ 54 | lv_obj_t * lv_line_create(lv_obj_t * par, const lv_obj_t * copy); 55 | 56 | /*===================== 57 | * Setter functions 58 | *====================*/ 59 | 60 | /** 61 | * Set an array of points. The line object will connect these points. 62 | * @param line pointer to a line object 63 | * @param point_a an array of points. Only the address is saved, 64 | * so the array can NOT be a local variable which will be destroyed 65 | * @param point_num number of points in 'point_a' 66 | */ 67 | void lv_line_set_points(lv_obj_t * line, const lv_point_t point_a[], uint16_t point_num); 68 | 69 | /** 70 | * Enable (or disable) the auto-size option. The size of the object will fit to its points. 71 | * (set width to x max and height to y max) 72 | * @param line pointer to a line object 73 | * @param en true: auto size is enabled, false: auto size is disabled 74 | */ 75 | void lv_line_set_auto_size(lv_obj_t * line, bool en); 76 | 77 | /** 78 | * Enable (or disable) the y coordinate inversion. 79 | * If enabled then y will be subtracted from the height of the object, 80 | * therefore the y=0 coordinate will be on the bottom. 81 | * @param line pointer to a line object 82 | * @param en true: enable the y inversion, false:disable the y inversion 83 | */ 84 | void lv_line_set_y_invert(lv_obj_t * line, bool en); 85 | 86 | #define lv_line_set_y_inv \ 87 | lv_line_set_y_invert /*The name was inconsistent. In v.6.0 only `lv_line_set_y_invert`will \ 88 | work */ 89 | 90 | 91 | /*===================== 92 | * Getter functions 93 | *====================*/ 94 | 95 | /** 96 | * Get the auto size attribute 97 | * @param line pointer to a line object 98 | * @return true: auto size is enabled, false: disabled 99 | */ 100 | bool lv_line_get_auto_size(const lv_obj_t * line); 101 | 102 | /** 103 | * Get the y inversion attribute 104 | * @param line pointer to a line object 105 | * @return true: y inversion is enabled, false: disabled 106 | */ 107 | bool lv_line_get_y_invert(const lv_obj_t * line); 108 | 109 | /********************** 110 | * MACROS 111 | **********************/ 112 | 113 | #endif /*LV_USE_LINE*/ 114 | 115 | #ifdef __cplusplus 116 | } /* extern "C" */ 117 | #endif 118 | 119 | #endif /*LV_LINE_H*/ 120 | -------------------------------------------------------------------------------- /src/lv_widgets/lv_objmask.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_objmask.h 3 | * 4 | */ 5 | 6 | #ifndef LV_OBJMASK_H 7 | #define LV_OBJMASK_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_OBJMASK != 0 19 | 20 | #include "../lv_core/lv_obj.h" 21 | #include "../lv_widgets/lv_cont.h" 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /********************** 28 | * TYPEDEFS 29 | **********************/ 30 | 31 | typedef struct { 32 | void * param; 33 | } lv_objmask_mask_t; 34 | 35 | /*Data of object mask*/ 36 | typedef struct { 37 | lv_cont_ext_t cont; /*Ext. of ancestor*/ 38 | /*New data for this type */ 39 | lv_ll_t mask_ll; /*Store the created masks*/ 40 | 41 | } lv_objmask_ext_t; 42 | 43 | /*Parts of the object*/ 44 | enum { 45 | LV_OBJMASK_PART_MAIN, 46 | }; 47 | typedef uint8_t lv_objmask_part_t; 48 | 49 | /********************** 50 | * GLOBAL PROTOTYPES 51 | **********************/ 52 | 53 | /** 54 | * Create a object mask objects 55 | * @param par pointer to an object, it will be the parent of the new object mask 56 | * @param copy pointer to a object mask object, if not NULL then the new object will be copied from it 57 | * @return pointer to the created object mask 58 | */ 59 | lv_obj_t * lv_objmask_create(lv_obj_t * par, const lv_obj_t * copy); 60 | 61 | /*====================== 62 | * Add/remove functions 63 | *=====================*/ 64 | 65 | /** 66 | * Add a mask 67 | * @param objmask pointer to an Object mask object 68 | * @param param an initialized mask parameter 69 | * @return pointer to the added mask 70 | */ 71 | lv_objmask_mask_t * lv_objmask_add_mask(lv_obj_t * objmask, void * param); 72 | 73 | /** 74 | * Update an already created mask 75 | * @param objmask pointer to an Object mask object 76 | * @param mask pointer to created mask (returned by `lv_objmask_add_mask`) 77 | * @param param an initialized mask parameter (initialized by `lv_draw_mask_line/angle/.../_init`) 78 | */ 79 | void lv_objmask_update_mask(lv_obj_t * objmask, lv_objmask_mask_t * mask, void * param); 80 | 81 | /** 82 | * Remove a mask 83 | * @param objmask pointer to an Object mask object 84 | * @param mask pointer to created mask (returned by `lv_objmask_add_mask`) 85 | * If `NULL` passed all masks will be deleted. 86 | */ 87 | void lv_objmask_remove_mask(lv_obj_t * objmask, lv_objmask_mask_t * mask); 88 | 89 | /*===================== 90 | * Setter functions 91 | *====================*/ 92 | 93 | /*===================== 94 | * Getter functions 95 | *====================*/ 96 | 97 | /*===================== 98 | * Other functions 99 | *====================*/ 100 | 101 | /********************** 102 | * MACROS 103 | **********************/ 104 | 105 | #endif /*LV_USE_OBJMASK*/ 106 | 107 | #ifdef __cplusplus 108 | } /* extern "C" */ 109 | #endif 110 | 111 | #endif /*LV_OBJMASK_H*/ 112 | -------------------------------------------------------------------------------- /src/lv_widgets/lv_objx_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | /* TODO Remove these instructions 7 | * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) 8 | * templ -> object short name with lower case(e.g. btn, label etc) 9 | * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) 10 | * 11 | */ 12 | 13 | #ifndef LV_TEMPL_H 14 | #define LV_TEMPL_H 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /********************* 21 | * INCLUDES 22 | *********************/ 23 | #include "../lv_conf_internal.h" 24 | 25 | #if LV_USE_TEMPL != 0 26 | 27 | #include "../lv_core/lv_obj.h" 28 | 29 | /********************* 30 | * DEFINES 31 | *********************/ 32 | 33 | /********************** 34 | * TYPEDEFS 35 | **********************/ 36 | /*Data of template*/ 37 | typedef struct { 38 | lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ 39 | /*New data for this type */ 40 | } lv_templ_ext_t; 41 | 42 | /*Styles*/ 43 | enum { 44 | LV_TEMPL_STYLE_X, 45 | LV_TEMPL_STYLE_Y, 46 | }; 47 | typedef uint8_t lv_templ_style_t; 48 | 49 | /********************** 50 | * GLOBAL PROTOTYPES 51 | **********************/ 52 | 53 | /** 54 | * Create a template objects 55 | * @param par pointer to an object, it will be the parent of the new template 56 | * @param copy pointer to a template object, if not NULL then the new object will be copied from it 57 | * @return pointer to the created template 58 | */ 59 | lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy); 60 | 61 | /*====================== 62 | * Add/remove functions 63 | *=====================*/ 64 | 65 | /*===================== 66 | * Setter functions 67 | *====================*/ 68 | 69 | /** 70 | * Set a style of a template. 71 | * @param templ pointer to template object 72 | * @param type which style should be set 73 | * @param style pointer to a style 74 | */ 75 | void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, const lv_style_t * style); 76 | 77 | /*===================== 78 | * Getter functions 79 | *====================*/ 80 | 81 | /** 82 | * Get style of a template. 83 | * @param templ pointer to template object 84 | * @param type which style should be get 85 | * @return style pointer to the style 86 | */ 87 | lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type); 88 | 89 | /*===================== 90 | * Other functions 91 | *====================*/ 92 | 93 | /********************** 94 | * MACROS 95 | **********************/ 96 | 97 | #endif /*LV_USE_TEMPL*/ 98 | 99 | #ifdef __cplusplus 100 | } /* extern "C" */ 101 | #endif 102 | 103 | #endif /*LV_TEMPL_H*/ 104 | -------------------------------------------------------------------------------- /src/lv_widgets/lv_switch.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_sw.h 3 | * 4 | */ 5 | 6 | #ifndef LV_SWITCH_H 7 | #define LV_SWITCH_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "../lv_conf_internal.h" 17 | 18 | #if LV_USE_SWITCH != 0 19 | 20 | /*Testing of dependencies*/ 21 | #if LV_USE_SLIDER == 0 22 | #error "lv_sw: lv_slider is required. Enable it in lv_conf.h (LV_USE_SLIDER 1)" 23 | #endif 24 | 25 | #include "../lv_core/lv_obj.h" 26 | #include "lv_bar.h" 27 | 28 | /********************* 29 | * DEFINES 30 | *********************/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | /*Data of switch*/ 36 | typedef struct { 37 | lv_bar_ext_t bar; /*Ext. of ancestor*/ 38 | /*New data for this type */ 39 | lv_style_list_t style_knob; /*Style of the knob*/ 40 | uint8_t state : 1; /*The current state*/ 41 | } lv_switch_ext_t; 42 | 43 | /** 44 | * Switch parts. 45 | */ 46 | enum { 47 | LV_SWITCH_PART_BG = LV_BAR_PART_BG, /**< Switch background. */ 48 | LV_SWITCH_PART_INDIC = LV_BAR_PART_INDIC, /**< Switch fill area. */ 49 | LV_SWITCH_PART_KNOB = _LV_BAR_PART_VIRTUAL_LAST, /**< Switch knob. */ 50 | _LV_SWITCH_PART_VIRTUAL_LAST 51 | }; 52 | 53 | typedef uint8_t lv_switch_part_t; 54 | 55 | /********************** 56 | * GLOBAL PROTOTYPES 57 | **********************/ 58 | 59 | /** 60 | * Create a switch objects 61 | * @param par pointer to an object, it will be the parent of the new switch 62 | * @param copy pointer to a switch object, if not NULL then the new object will be copied from it 63 | * @return pointer to the created switch 64 | */ 65 | lv_obj_t * lv_switch_create(lv_obj_t * par, const lv_obj_t * copy); 66 | 67 | /*===================== 68 | * Setter functions 69 | *====================*/ 70 | 71 | /** 72 | * Turn ON the switch 73 | * @param sw pointer to a switch object 74 | * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately 75 | */ 76 | void lv_switch_on(lv_obj_t * sw, lv_anim_enable_t anim); 77 | 78 | /** 79 | * Turn OFF the switch 80 | * @param sw pointer to a switch object 81 | * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately 82 | */ 83 | void lv_switch_off(lv_obj_t * sw, lv_anim_enable_t anim); 84 | 85 | /** 86 | * Toggle the position of the switch 87 | * @param sw pointer to a switch object 88 | * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately 89 | * @return resulting state of the switch. 90 | */ 91 | bool lv_switch_toggle(lv_obj_t * sw, lv_anim_enable_t anim); 92 | 93 | /** 94 | * Set the animation time of the switch 95 | * @param sw pointer to a switch object 96 | * @param anim_time animation time 97 | * @return style pointer to a style 98 | */ 99 | static inline void lv_switch_set_anim_time(lv_obj_t * sw, uint16_t anim_time) 100 | { 101 | lv_bar_set_anim_time(sw, anim_time); 102 | } 103 | 104 | /*===================== 105 | * Getter functions 106 | *====================*/ 107 | 108 | /** 109 | * Get the state of a switch 110 | * @param sw pointer to a switch object 111 | * @return false: OFF; true: ON 112 | */ 113 | static inline bool lv_switch_get_state(const lv_obj_t * sw) 114 | { 115 | lv_switch_ext_t * ext = (lv_switch_ext_t *)lv_obj_get_ext_attr(sw); 116 | return ext->state ? true : false; 117 | } 118 | 119 | /** 120 | * Get the animation time of the switch 121 | * @param sw pointer to a switch object 122 | * @return style pointer to a style 123 | */ 124 | static inline uint16_t lv_switch_get_anim_time(const lv_obj_t * sw) 125 | { 126 | return lv_bar_get_anim_time(sw); 127 | } 128 | 129 | /********************** 130 | * MACROS 131 | **********************/ 132 | 133 | #endif /*LV_USE_SWITCH*/ 134 | 135 | #ifdef __cplusplus 136 | } /* extern "C" */ 137 | #endif 138 | 139 | #endif /*LV_SWITCH_H*/ 140 | -------------------------------------------------------------------------------- /src/lv_widgets/lv_widgets.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_arc.c 2 | CSRCS += lv_bar.c 3 | CSRCS += lv_checkbox.c 4 | CSRCS += lv_cpicker.c 5 | CSRCS += lv_dropdown.c 6 | CSRCS += lv_keyboard.c 7 | CSRCS += lv_line.c 8 | CSRCS += lv_msgbox.c 9 | CSRCS += lv_spinner.c 10 | CSRCS += lv_roller.c 11 | CSRCS += lv_table.c 12 | CSRCS += lv_tabview.c 13 | CSRCS += lv_tileview.c 14 | CSRCS += lv_btn.c 15 | CSRCS += lv_calendar.c 16 | CSRCS += lv_chart.c 17 | CSRCS += lv_canvas.c 18 | CSRCS += lv_gauge.c 19 | CSRCS += lv_label.c 20 | CSRCS += lv_list.c 21 | CSRCS += lv_slider.c 22 | CSRCS += lv_textarea.c 23 | CSRCS += lv_spinbox.c 24 | CSRCS += lv_btnmatrix.c 25 | CSRCS += lv_cont.c 26 | CSRCS += lv_img.c 27 | CSRCS += lv_imgbtn.c 28 | CSRCS += lv_led.c 29 | CSRCS += lv_linemeter.c 30 | CSRCS += lv_page.c 31 | CSRCS += lv_switch.c 32 | CSRCS += lv_win.c 33 | CSRCS += lv_objmask.c 34 | 35 | DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_widgets 36 | VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_widgets 37 | 38 | CFLAGS += "-I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/lv_widgets" 39 | -------------------------------------------------------------------------------- /src/lvgl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lvgl.h 3 | * This file exists only to be compatible with Arduino's library structure 4 | */ 5 | 6 | #ifndef LVGL_SRC_H 7 | #define LVGL_SRC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #include "../lvgl.h" 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | 23 | /********************** 24 | * TYPEDEFS 25 | **********************/ 26 | 27 | /********************** 28 | * GLOBAL PROTOTYPES 29 | **********************/ 30 | 31 | /********************** 32 | * MACROS 33 | **********************/ 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /*LVGL_SRC_H*/ 40 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile 3 | # 4 | CC ?= gcc 5 | LVGL_DIR ?= ${shell pwd}/../.. 6 | LVGL_DIR_NAME ?= lvgl 7 | 8 | WARNINGS = -Werror -Wall -Wextra \ 9 | -Wshadow -Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wpointer-arith -Wuninitialized \ 10 | -Wunreachable-code -Wreturn-type -Wmultichar -Wformat-security -Wdouble-promotion -Wclobbered -Wdeprecated \ 11 | -Wempty-body -Wshift-negative-value -Wstack-usage=2048 \ 12 | -Wtype-limits -Wsizeof-pointer-memaccess 13 | 14 | #-Wno-unused-value -Wno-unused-parameter 15 | OPTIMIZATION ?= -O3 -g0 16 | 17 | 18 | CFLAGS ?= -I$(LVGL_DIR)/ $(DEFINES) $(WARNINGS) $(OPTIMIZATION) -I$(LVGL_DIR) -I. 19 | 20 | LDFLAGS ?= -lpng 21 | BIN ?= demo 22 | 23 | 24 | #Collect the files to compile 25 | MAINSRC = ./lv_test_main.c 26 | 27 | include ../lvgl.mk 28 | 29 | CSRCS += lv_test_assert.c 30 | CSRCS += lv_test_core/lv_test_core.c 31 | CSRCS += lv_test_core/lv_test_obj.c 32 | CSRCS += lv_test_core/lv_test_style.c 33 | 34 | OBJEXT ?= .o 35 | 36 | AOBJS = $(ASRCS:.S=$(OBJEXT)) 37 | COBJS = $(CSRCS:.c=$(OBJEXT)) 38 | 39 | MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) 40 | 41 | SRCS = $(ASRCS) $(CSRCS) $(MAINSRC) 42 | OBJS = $(AOBJS) $(COBJS) 43 | 44 | ## MAINOBJ -> OBJFILES 45 | 46 | all: default 47 | 48 | %.o: %.c 49 | @$(CC) $(CFLAGS) -c $< -o $@ 50 | @echo "CC $<" 51 | 52 | default: $(AOBJS) $(COBJS) $(MAINOBJ) 53 | $(CC) -o $(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS) 54 | 55 | clean: 56 | rm -f $(BIN) $(AOBJS) $(COBJS) $(MAINOBJ) 57 | 58 | -------------------------------------------------------------------------------- /tests/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/tests/icon.png -------------------------------------------------------------------------------- /tests/icon2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/tests/icon2.png -------------------------------------------------------------------------------- /tests/lv_test_assert.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_assert.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEST_ASSERT_H 7 | #define LV_TEST_ASSERT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | #include 18 | #include "../lvgl.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | void lv_test_print(const char * s, ...); 33 | void lv_test_exit(const char * s, ...); 34 | void lv_test_error(const char * s, ...); 35 | void lv_test_assert_int_eq(int32_t n1, int32_t n2, const char * s); 36 | void lv_test_assert_int_gt(int32_t n_ref, int32_t n_act, const char * s); 37 | void lv_test_assert_int_lt(int32_t n_ref, int32_t n_act, const char * s); 38 | void lv_test_assert_str_eq(const char * str1, const char * str2, const char * s); 39 | void lv_test_assert_ptr_eq(const void * p_ref, const void * p_act, const char * s); 40 | void lv_test_assert_color_eq(lv_color_t c_ref, lv_color_t c_act, const char * s); 41 | void lv_test_assert_img_eq(const char * ref_img_fn, const char * s); 42 | 43 | /********************** 44 | * MACROS 45 | **********************/ 46 | 47 | #ifdef __cplusplus 48 | } /* extern "C" */ 49 | #endif 50 | 51 | #endif /*LV_TEST_ASSERT_H*/ 52 | -------------------------------------------------------------------------------- /tests/lv_test_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_conf.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEST_CONF_H 7 | #define LV_TEST_CONF_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | uint32_t custom_tick_get(void); 26 | #define LV_TICK_CUSTOM_SYS_TIME_EXPR custom_tick_get() 27 | 28 | typedef int16_t lv_coord_t; 29 | typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ 30 | typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/ 31 | typedef void * lv_font_user_data_t; 32 | typedef void * lv_obj_user_data_t; 33 | typedef void * lv_anim_user_data_t; 34 | typedef void * lv_group_user_data_t; 35 | typedef void * lv_fs_drv_user_data_t; 36 | typedef void * lv_img_decoder_user_data_t; 37 | 38 | /********************** 39 | * GLOBAL PROTOTYPES 40 | **********************/ 41 | 42 | /********************** 43 | * MACROS 44 | **********************/ 45 | 46 | #ifdef __cplusplus 47 | } /* extern "C" */ 48 | #endif 49 | 50 | #endif /*LV_TEST_CONF_H*/ 51 | -------------------------------------------------------------------------------- /tests/lv_test_core/lv_test_core.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_core.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "../lv_test_assert.h" 10 | 11 | #if LV_BUILD_TEST 12 | #include "lv_test_core.h" 13 | #include "lv_test_obj.h" 14 | #include "lv_test_style.h" 15 | 16 | /********************* 17 | * DEFINES 18 | *********************/ 19 | 20 | /********************** 21 | * TYPEDEFS 22 | **********************/ 23 | 24 | /********************** 25 | * STATIC PROTOTYPES 26 | **********************/ 27 | 28 | /********************** 29 | * STATIC VARIABLES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL FUNCTIONS 38 | **********************/ 39 | 40 | void lv_test_core(void) 41 | { 42 | lv_test_print(""); 43 | lv_test_print("*******************"); 44 | lv_test_print("Start lv_core tests"); 45 | lv_test_print("*******************"); 46 | 47 | lv_test_obj(); 48 | lv_test_style(); 49 | } 50 | 51 | 52 | /********************** 53 | * STATIC FUNCTIONS 54 | **********************/ 55 | #endif 56 | -------------------------------------------------------------------------------- /tests/lv_test_core/lv_test_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_core.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEST_CORE_H 7 | #define LV_TEST_CORE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | void lv_test_core(void); 29 | 30 | /********************** 31 | * MACROS 32 | **********************/ 33 | 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif 37 | 38 | #endif /*LV_TEST_CORE_H*/ 39 | -------------------------------------------------------------------------------- /tests/lv_test_core/lv_test_obj.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_obj.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "../../lvgl.h" 10 | #include "../lv_test_assert.h" 11 | #include "lv_test_obj.h" 12 | 13 | #if LV_BUILD_TEST 14 | 15 | /********************* 16 | * DEFINES 17 | *********************/ 18 | 19 | /********************** 20 | * TYPEDEFS 21 | **********************/ 22 | 23 | /********************** 24 | * STATIC PROTOTYPES 25 | **********************/ 26 | static void create_delete_change_parent(void); 27 | 28 | /********************** 29 | * STATIC VARIABLES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL FUNCTIONS 38 | **********************/ 39 | 40 | void lv_test_obj(void) 41 | { 42 | lv_test_print(""); 43 | lv_test_print("=================="); 44 | lv_test_print("Start lv_obj tests"); 45 | lv_test_print("=================="); 46 | 47 | create_delete_change_parent(); 48 | } 49 | 50 | 51 | /********************** 52 | * STATIC FUNCTIONS 53 | **********************/ 54 | 55 | static void create_delete_change_parent(void) 56 | { 57 | 58 | lv_test_print(""); 59 | lv_test_print("Create, delete, change parent of a simple object:"); 60 | lv_test_print("-------------------------------------------------"); 61 | 62 | 63 | lv_test_print("Create an object on the default screen"); 64 | lv_test_assert_int_eq(0, lv_obj_count_children(lv_scr_act()), "Screen's children count before creation"); 65 | 66 | lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL); 67 | lv_test_assert_int_eq(1, lv_obj_count_children(lv_scr_act()), "Screen's children count after creation"); 68 | lv_test_assert_int_eq(0, lv_obj_count_children(obj), "New object's children count after creation"); 69 | 70 | lv_test_print("Delete the created object"); 71 | lv_obj_del(obj); 72 | obj = NULL; 73 | lv_test_assert_int_eq(0, lv_obj_count_children(lv_scr_act()), "Screen's children count after delete"); 74 | 75 | lv_test_print("Create two objects"); 76 | lv_obj_t * obj_parent = lv_obj_create(lv_scr_act(), NULL); 77 | lv_obj_t * obj_child = lv_obj_create(lv_scr_act(), NULL); 78 | lv_test_assert_int_eq(2, lv_obj_count_children(lv_scr_act()), "Screen's children count after creation"); 79 | 80 | lv_test_print("Change the parent of the second object to the first"); 81 | lv_obj_set_parent(obj_child, obj_parent); 82 | lv_test_assert_int_eq(1, lv_obj_count_children(lv_scr_act()), "Screen's children count after parent change"); 83 | lv_test_assert_int_eq(1, lv_obj_count_children(obj_parent), "Parent object's children count after parent change"); 84 | lv_test_assert_int_eq(0, lv_obj_count_children(obj_child), "Child object's children count after parent change"); 85 | 86 | lv_test_print("Remove the parent object"); 87 | lv_obj_del(obj_parent); 88 | lv_test_assert_int_eq(0, lv_obj_count_children(lv_scr_act()), "Screen's children count after delete"); 89 | } 90 | #endif 91 | -------------------------------------------------------------------------------- /tests/lv_test_core/lv_test_obj.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_obj.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEST_OBJ_H 7 | #define LV_TEST_OBJ_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | void lv_test_obj(void); 29 | 30 | /********************** 31 | * MACROS 32 | **********************/ 33 | 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif 37 | 38 | #endif /*LV_TEST_OBJ_H*/ 39 | -------------------------------------------------------------------------------- /tests/lv_test_core/lv_test_style.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_style.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEST_STYLE_H 7 | #define LV_TEST_STYLE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | void lv_test_style(void); 29 | 30 | /********************** 31 | * MACROS 32 | **********************/ 33 | 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif 37 | 38 | #endif /*LV_TEST_STYLE_H*/ 39 | -------------------------------------------------------------------------------- /tests/lv_test_main.c: -------------------------------------------------------------------------------- 1 | #include "../lvgl.h" 2 | #include 3 | #include 4 | #include 5 | #include "lv_test_core/lv_test_core.h" 6 | 7 | #if LV_BUILD_TEST 8 | 9 | static void hal_init(void); 10 | static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); 11 | 12 | int main(void) 13 | { 14 | printf("Call lv_init...\n"); 15 | lv_init(); 16 | 17 | hal_init(); 18 | 19 | lv_test_core(); 20 | 21 | printf("Exit with success!\n"); 22 | return 0; 23 | } 24 | 25 | 26 | static void hal_init(void) 27 | { 28 | static lv_disp_buf_t disp_buf; 29 | lv_color_t * disp_buf1 = (lv_color_t *)malloc(LV_HOR_RES * LV_VER_RES * sizeof(lv_color_t)); 30 | 31 | lv_disp_buf_init(&disp_buf, disp_buf1, NULL, LV_HOR_RES* LV_VER_RES); 32 | 33 | lv_disp_drv_t disp_drv; 34 | lv_disp_drv_init(&disp_drv); 35 | disp_drv.buffer = &disp_buf; 36 | disp_drv.flush_cb = dummy_flush_cb; 37 | lv_disp_drv_register(&disp_drv); 38 | } 39 | 40 | 41 | static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) 42 | { 43 | LV_UNUSED(area); 44 | LV_UNUSED(color_p); 45 | lv_disp_flush_ready(disp_drv); 46 | } 47 | 48 | uint32_t custom_tick_get(void) 49 | { 50 | static uint64_t start_ms = 0; 51 | if(start_ms == 0) { 52 | struct timeval tv_start; 53 | gettimeofday(&tv_start, NULL); 54 | start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000; 55 | } 56 | 57 | struct timeval tv_now; 58 | gettimeofday(&tv_now, NULL); 59 | uint64_t now_ms; 60 | now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000; 61 | 62 | uint32_t time_ms = now_ms - start_ms; 63 | return time_ms; 64 | } 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /tests/lv_test_objx/lv_test_cont.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_cont.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "../../lvgl.h" 10 | #include "../lv_test_assert.h" 11 | 12 | #if LV_BUILD_TEST 13 | 14 | 15 | /********************* 16 | * DEFINES 17 | *********************/ 18 | 19 | /********************** 20 | * TYPEDEFS 21 | **********************/ 22 | 23 | /********************** 24 | * STATIC PROTOTYPES 25 | **********************/ 26 | static void create_copy(void); 27 | 28 | /********************** 29 | * STATIC VARIABLES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL FUNCTIONS 38 | **********************/ 39 | 40 | void lv_test_cont(void) 41 | { 42 | lv_test_print(""); 43 | lv_test_print("==================="); 44 | lv_test_print("Start lv_cont tests"); 45 | lv_test_print("==================="); 46 | 47 | create_copy(); 48 | } 49 | 50 | 51 | /********************** 52 | * STATIC FUNCTIONS 53 | **********************/ 54 | 55 | static void create_copy(void) 56 | { 57 | lv_test_print(""); 58 | lv_test_print("Create and copy a container"); 59 | lv_test_print("---------------------------"); 60 | 61 | lv_test_print("Create a container"); 62 | lv_test_assert_int_eq(0, lv_obj_count_children(lv_scr_act()), "Screen's children count before creation"); 63 | 64 | lv_obj_t * obj = lv_cont_create(lv_scr_act(), NULL); 65 | lv_test_assert_int_eq(1, lv_obj_count_children(lv_scr_act()), "Screen's children count after creation"); 66 | 67 | lv_test_print("Test the default values"); 68 | lv_test_assert_int_eq(LV_FIT_NONE, lv_cont_get_fit_left(obj), "Default left fit"); 69 | lv_test_assert_int_eq(LV_FIT_NONE, lv_cont_get_fit_right(obj), "Default right fit"); 70 | lv_test_assert_int_eq(LV_FIT_NONE, lv_cont_get_fit_top(obj), "Default top fit"); 71 | lv_test_assert_int_eq(LV_FIT_NONE, lv_cont_get_fit_bottom(obj), "Default bottom fit"); 72 | lv_test_assert_int_eq(LV_LAYOUT_OFF, lv_cont_get_layout(obj), "Default layout"); 73 | 74 | lv_test_print("Delete the container"); 75 | lv_obj_del(obj); 76 | obj = NULL; 77 | lv_test_assert_int_eq(0, lv_obj_count_children(lv_scr_act()), "Screen's children count after delete"); 78 | 79 | } 80 | #endif 81 | -------------------------------------------------------------------------------- /tests/lv_test_objx/lv_test_cont.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_test_obj.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEST_CONT_H 7 | #define LV_TEST_CONT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | void lv_test_cont(void); 29 | 30 | /********************** 31 | * MACROS 32 | **********************/ 33 | 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif 37 | 38 | #endif /*LV_TEST_CONT_H*/ 39 | -------------------------------------------------------------------------------- /tests/lv_test_ref_imgs/lv_test_obj_1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rajssss/lvgl-wasm/ed44d86d83af5af6e38267a0cbf85f005f8d965c/tests/lv_test_ref_imgs/lv_test_obj_1_1.png -------------------------------------------------------------------------------- /wasm/copy-wasm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copy outputs to docs/lvgl.js, lvgl.wasm 3 | 4 | # Stop the script on error, echo all commands 5 | set -e -x 6 | 7 | cp wasm/lvgl.wasm docs/lvgl.wasm 8 | cp wasm/lvgl.js docs/lvgl.js 9 | -------------------------------------------------------------------------------- /wasm/copy-wasm2.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copy outputs to docs/lvgl2.js, lvgl2.wasm 3 | 4 | # Stop the script on error, echo all commands 5 | set -e -x 6 | 7 | cp wasm/lvgl.wasm docs/lvgl2.wasm 8 | 9 | # Change lvgl.wasm to lvgl2.wasm 10 | cat wasm/lvgl.js \ 11 | | sed 's/lvgl.wasm/lvgl2.wasm/' \ 12 | >docs/lvgl2.js 13 | -------------------------------------------------------------------------------- /wasm/lv_port_disp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_port_disp_templ.h 3 | * 4 | */ 5 | 6 | /*Copy this file as "lv_port_disp.h" and set this value to "1" to enable content*/ 7 | #if 1 8 | 9 | #ifndef LV_PORT_DISP_TEMPL_H 10 | #define LV_PORT_DISP_TEMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /********************* 17 | * INCLUDES 18 | *********************/ 19 | #include "../lvgl.h" 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /********************** 30 | * GLOBAL PROTOTYPES 31 | **********************/ 32 | 33 | void lv_port_disp_init(void); 34 | 35 | // Defined in lvgl.c 36 | void put_display_px(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a); 37 | 38 | /********************** 39 | * MACROS 40 | **********************/ 41 | 42 | 43 | #ifdef __cplusplus 44 | } /* extern "C" */ 45 | #endif 46 | 47 | #endif /*LV_PORT_DISP_TEMPL_H*/ 48 | 49 | #endif /*Disable/Enable content*/ 50 | -------------------------------------------------------------------------------- /wasm/lvgl.c: -------------------------------------------------------------------------------- 1 | // Simple port of LVGL to WebAssembly. 2 | // Renders UI controls to HTML Canvas but touch input not handled yet. 3 | // To build see lvgl.sh 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "../lvgl.h" 9 | #include "../demo/lv_demo_widgets.h" 10 | #include "lv_port_disp.h" 11 | 12 | //////////////////////////////////////////////////////////////////// 13 | // Device and Display Buffers 14 | 15 | /// RGBA WebAssembly Display Buffer that will be rendered to HTML Canvas 16 | #define DISPLAY_BYTES_PER_PIXEL 4 17 | uint8_t display_buffer[LV_HOR_RES_MAX * LV_VER_RES_MAX * DISPLAY_BYTES_PER_PIXEL]; 18 | 19 | /// Plot a pixel on the WebAssembly Display Buffer 20 | void put_display_px(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { 21 | assert(x >= 0); assert(x < LV_HOR_RES_MAX); 22 | assert(y >= 0); assert(y < LV_VER_RES_MAX); 23 | // TODO: Map RGB565 to RGBA 24 | int i = (y * LV_HOR_RES_MAX * DISPLAY_BYTES_PER_PIXEL) + (x * DISPLAY_BYTES_PER_PIXEL); 25 | display_buffer[i++] = r; // Red 26 | display_buffer[i++] = g; // Green 27 | display_buffer[i++] = b; // Blue 28 | display_buffer[i++] = a; // Alpha 29 | } 30 | 31 | /// Return the WebAssembly Address of the WebAssembly Display Buffer 32 | unsigned get_display_buffer(void) { 33 | uint8_t *p = &display_buffer[0]; 34 | return (unsigned) p; 35 | } 36 | 37 | /// Return the width of the WebAssembly Display Buffer 38 | unsigned get_display_width(void) { return LV_HOR_RES_MAX; } 39 | 40 | /// Return the height of the WebAssembly Display Buffer 41 | unsigned get_display_height(void) { return LV_VER_RES_MAX; } 42 | 43 | /// Render a colour box to the WebAssembly Display Buffer 44 | int test_display(void) { 45 | puts("In C: Testing display..."); 46 | for (uint16_t x = 0; x < LV_HOR_RES_MAX; x++) { 47 | for (uint16_t y = 0; y < LV_VER_RES_MAX; y++) { 48 | uint8_t r = (x * 256 / 20) & 0xff; 49 | uint8_t g = (y * 256 / 20) & 0xff; 50 | uint8_t b = ((x + y) * 256 / 40) & 0xff; 51 | uint8_t a = 0xff; 52 | put_display_px(x, y, r, g, b, a); 53 | } 54 | } 55 | return 0; 56 | } 57 | 58 | //////////////////////////////////////////////////////////////////// 59 | // Render LVGL 60 | 61 | /// Init the LVGL display 62 | void init_display(void) { 63 | puts("In C: Init display..."); 64 | 65 | // Init the LVGL display 66 | lv_init(); 67 | lv_port_disp_init(); 68 | } 69 | 70 | /// Render a Button Widget and a Label Widget 71 | void render_widgets(void) { 72 | puts("In C: Rendering widgets..."); 73 | lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); // Add a button to the current screen 74 | lv_obj_set_pos(btn, 10, 10); // Set its position 75 | lv_obj_set_size(btn, 120, 50); // Set its size 76 | 77 | lv_obj_t * label = lv_label_create(btn, NULL); // Add a label to the button 78 | lv_label_set_text(label, "Button"); // Set the label's text 79 | } 80 | 81 | /// Render the LVGL display 82 | void render_display(void) { 83 | puts("In C: Rendering display..."); 84 | // Must tick at least 100 milliseconds to force LVGL to update display 85 | lv_tick_inc(100); 86 | // LVGL will flush our display driver 87 | lv_task_handler(); 88 | } 89 | 90 | //////////////////////////////////////////////////////////////////// 91 | // Main 92 | 93 | /// Do nothing 94 | int main(int argc, char **argv) { 95 | puts("In C: main()"); 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /wasm/lvgl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Build LVGL for WebAssembly 3 | 4 | # Stop the script on error, echo all commands 5 | set -e -x 6 | 7 | # Rewrite Clock.cpp to build with WebAssembly: 8 | # Change 9 | # To "date.h" 10 | # Change 11 | # To "DateTimeController.h" 12 | # Change 13 | # To "../lvgl.h" 14 | # Change "../DisplayApp.h" 15 | # To "DisplayApp.h" 16 | # Change obj->user_data 17 | # To backgroundLabel_user_data 18 | # Change backgroundLabel->user_data 19 | # To backgroundLabel_user_data 20 | # Remove Screen(app), 21 | cat clock/Clock.cpp \ 22 | | sed 's//"date.h"/' \ 23 | | sed 's//"DateTimeController.h"/' \ 24 | | sed 's//"..\/lvgl.h"/' \ 25 | | sed 's/"..\/DisplayApp.h"/"DisplayApp.h"/' \ 26 | | sed 's/obj->user_data/backgroundLabel_user_data/' \ 27 | | sed 's/backgroundLabel->user_data/backgroundLabel_user_data/' \ 28 | | sed 's/Screen(app),//' \ 29 | >clock/ClockTmp.cpp 30 | 31 | # Build LVGL app: wasm/lvgl.html, lvgl.js, lvgl.wasm 32 | make -j 33 | 34 | # Build Rust modules with emscripten compatibility 35 | # cargo build --target=wasm32-unknown-emscripten 36 | 37 | # Build sample Rust app: wasm/test_rust.html, test_rust.js, test_rust.wasm 38 | # emcc \ 39 | # -g \ 40 | # wasm/test_rust.c \ 41 | # -s WASM=1 \ 42 | # -s "EXPORTED_FUNCTIONS=[ '_main', '_get_display_buffer', '_get_display_width', '_get_display_height', '_test_display', '_test_c', '_test_c_set_buffer', '_test_c_get_buffer', '_test_c_buffer_address', '_test_rust', '_test_rust2', '_test_rust3', '_test_rust_set_buffer', '_test_rust_get_buffer' ]" \ 43 | # -o wasm/test_rust.html \ 44 | # -I src/lv_core \ 45 | # target/wasm32-unknown-emscripten/debug/liblvgl_wasm_rust.a 46 | 47 | # Build sample app: wasm/test.html, test.js, test.wasm 48 | # emcc \ 49 | # -g \ 50 | # wasm/test.c \ 51 | # -s WASM=1 \ 52 | # -o wasm/test.html 53 | 54 | # Dump the WebAssembly modules 55 | wasm-objdump -x wasm/lvgl.wasm >wasm/lvgl.txt 56 | # wasm-objdump -x wasm/test.wasm >wasm/test.txt 57 | # wasm-objdump -x wasm/test_rust.wasm >wasm/test_rust.txt 58 | 59 | # Rename the HTML files so we don't overwrite the updates 60 | mv wasm/lvgl.html wasm/lvgl.old.html 61 | # mv wasm/test.html wasm/test.old.html 62 | # mv wasm/test_rust.html wasm/test_rust.old.html 63 | -------------------------------------------------------------------------------- /wasm/test.c: -------------------------------------------------------------------------------- 1 | /* Sample App: 2 | emcc wasm/test.c -s WASM=1 -o wasm/test.html 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | //////////////////////////////////////////////////////////////////// 10 | // Main 11 | 12 | int main(int argc, char **argv) { 13 | puts("Hello world"); 14 | return 0; 15 | } 16 | 17 | #ifdef NOTUSED 18 | [luppy@pinebook lvgl-wasm]$ emcc wasm/test.c -s WASM=1 -o wasm/test.html 19 | shared:INFO: EM_IGNORE_SANITY set, ignoring sanity checks 20 | cache:INFO: generating system asset: generated_struct_info.json... (this will be cached in "/home/luppy/.emscripten_cache/wasm/generated_struct_info.json" for subsequent builds) 21 | Fatal: Module::addExport: stackSave already exists 22 | emcc: error: '/usr/bin/wasm-emscripten-finalize --detect-features --global-base=1024 --check-stack-overflow /tmp/emscripten_temp_ss2n_af6/tmpyakvy0aa.wasm -o /tmp/emscripten_temp_ss2n_af6/tmpyakvy0aa.wasm.o.wasm' failed (1) 23 | FAIL: Compilation failed!: ['/usr/lib/emscripten/emcc', '-D_GNU_SOURCE', '-o', '/tmp/tmpyakvy0aa.js', '/tmp/tmphcwy4r4h.c', '-O0', '--js-opts', '0', '--memory-init-file', '0', '-Werror', '-Wno-format', '-s', 'BOOTSTRAPPING_STRUCT_INFO=1', '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0', '-s', 'STRICT=1', '-s', 'SINGLE_FILE=1'] 24 | #endif 25 | -------------------------------------------------------------------------------- /wasm/test_rust.c: -------------------------------------------------------------------------------- 1 | /* Sample app to test C and Rust WebAssembly Interoperability 2 | Build sample Rust app: wasm/test_rust.html, test_rust.js, test_rust.wasm 3 | emcc \ 4 | -g \ 5 | wasm/test_rust.c \ 6 | -s WASM=1 \ 7 | -s "EXPORTED_FUNCTIONS=[ '_main', '_test_c', '_test_c_set_buffer', '_test_c_get_buffer', '_test_c_buffer_address', '_test_rust', '_test_rust2', '_test_rust3', '_test_rust_set_buffer', '_test_rust_get_buffer' ]" \ 8 | -o wasm/test_rust.html \ 9 | target/wasm32-unknown-emscripten/debug/liblvgl_wasm_rust.a 10 | */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "../lvgl.h" 17 | 18 | //////////////////////////////////////////////////////////////////// 19 | // Device and Display Buffers 20 | 21 | /// RGBA WebAssembly Display Buffer that will be rendered to HTML Canvas 22 | #define DISPLAY_BYTES_PER_PIXEL 4 23 | uint8_t display_buffer[LV_HOR_RES_MAX * LV_VER_RES_MAX * DISPLAY_BYTES_PER_PIXEL]; 24 | 25 | /// Plot a pixel on the WebAssembly Display Buffer 26 | void put_display_px(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { 27 | assert(x >= 0); assert(x < LV_HOR_RES_MAX); 28 | assert(y >= 0); assert(y < LV_VER_RES_MAX); 29 | // TODO: Map RGB565 to RGBA 30 | int i = (y * LV_HOR_RES_MAX * DISPLAY_BYTES_PER_PIXEL) + (x * DISPLAY_BYTES_PER_PIXEL); 31 | display_buffer[i++] = r; // Red 32 | display_buffer[i++] = g; // Green 33 | display_buffer[i++] = b; // Blue 34 | display_buffer[i++] = a; // Alpha 35 | } 36 | 37 | /// Return the WebAssembly Address of the WebAssembly Display Buffer 38 | unsigned get_display_buffer(void) { 39 | uint8_t *p = &display_buffer[0]; 40 | return (unsigned) p; 41 | } 42 | 43 | /// Return the width of the WebAssembly Display Buffer 44 | unsigned get_display_width(void) { return LV_HOR_RES_MAX; } 45 | 46 | /// Return the height of the WebAssembly Display Buffer 47 | unsigned get_display_height(void) { return LV_VER_RES_MAX; } 48 | 49 | /// Render a colour box to the WebAssembly Display Buffer 50 | int test_display(void) { 51 | puts("In C: test_display()"); 52 | for (uint16_t x = 0; x < LV_HOR_RES_MAX; x++) { 53 | for (uint16_t y = 0; y < LV_VER_RES_MAX; y++) { 54 | uint8_t r = (x * 256 / 20) & 0xff; 55 | uint8_t g = (y * 256 / 20) & 0xff; 56 | uint8_t b = ((x + y) * 256 / 40) & 0xff; 57 | uint8_t a = 0xff; 58 | put_display_px(x, y, r, g, b, a); 59 | } 60 | } 61 | return 0; 62 | } 63 | 64 | /* 65 | /// RGB565 Device Buffer for PineTime 66 | #define DEVICE_BYTES_PER_PIXEL 3 // TODO: Switch to RGB565 67 | uint8_t device_buffer[LV_HOR_RES_MAX * LV_VER_RES_MAX * DEVICE_BYTES_PER_PIXEL]; 68 | 69 | /// Plot a pixel on the PineTime Device Buffer 70 | void put_display_px(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { 71 | assert(x >= 0); assert(x < LV_HOR_RES_MAX); 72 | assert(y >= 0); assert(y < LV_VER_RES_MAX); 73 | int i = (y * LV_HOR_RES_MAX * DEVICE_BYTES_PER_PIXEL) + (x * DEVICE_BYTES_PER_PIXEL); 74 | // TODO: Switch to RGB565 75 | device_buffer[i++] = r; // Red 76 | device_buffer[i++] = g; // Green 77 | device_buffer[i++] = b; // Blue 78 | } 79 | */ 80 | 81 | //////////////////////////////////////////////////////////////////// 82 | // Test 83 | 84 | // Defined in rust/src/lib.rs 85 | int test_rust(void); 86 | 87 | // Export memory buffer 88 | uint8_t test_rust_buffer[32] = "Test Rust Buffer"; 89 | 90 | //////////////////////////////////////////////////////////////////// 91 | // Main 92 | 93 | int main(int argc, char **argv) { 94 | puts("In C: main()"); 95 | int i = test_rust(); 96 | printf("In C: test_rust() returned %d\n", i); 97 | uint8_t *p = &test_rust_buffer[0]; 98 | printf("In C: test_rust_buffer is 0x%x\n", (unsigned) p); 99 | return 0; 100 | } 101 | 102 | int test_c(void) { 103 | puts("In C: test_c()"); 104 | return 2407; 105 | } 106 | 107 | int test_c_set_buffer(void) { 108 | int i = test_rust_buffer[0]; 109 | test_rust_buffer[0] = 'A'; 110 | return i; 111 | } 112 | 113 | int test_c_get_buffer(void) { 114 | return test_rust_buffer[0]; 115 | } 116 | 117 | unsigned test_c_buffer_address(void) { 118 | uint8_t *p = &test_rust_buffer[0]; 119 | return (unsigned) p; 120 | } --------------------------------------------------------------------------------