From c41f98039c0c7328c10a56958956bbc0a5626ee7 Mon Sep 17 00:00:00 2001 From: "ctcaer@gmail.com" Date: Sun, 30 Jun 2019 04:03:00 +0300 Subject: [PATCH] [Nyx] Introducing hekate GUI, named Nyx! Version 0.8.0. Expect dragons! --- Makefile | 8 +- nyx/Makefile | 117 + nyx/README_RES.md | 12 + nyx/nyx_gui/config/config.c | 165 + nyx/nyx_gui/config/config.h | 52 + nyx/nyx_gui/config/ini.c | 259 + nyx/nyx_gui/config/ini.h | 53 + nyx/nyx_gui/frontend/fe_emmc_tools.c | 1442 ++++ nyx/nyx_gui/frontend/fe_emmc_tools.h | 35 + nyx/nyx_gui/frontend/fe_emummc_tools.c | 703 ++ nyx/nyx_gui/frontend/fe_emummc_tools.h | 27 + nyx/nyx_gui/frontend/gui.c | 2107 +++++ nyx/nyx_gui/frontend/gui.h | 63 + nyx/nyx_gui/frontend/gui_emmc_tools.c | 458 ++ nyx/nyx_gui/frontend/gui_emmc_tools.h | 24 + nyx/nyx_gui/frontend/gui_emummc_tools.c | 1183 +++ nyx/nyx_gui/frontend/gui_emummc_tools.h | 24 + nyx/nyx_gui/frontend/gui_info.c | 1179 +++ nyx/nyx_gui/frontend/gui_info.h | 24 + nyx/nyx_gui/frontend/gui_tools.c | 902 +++ nyx/nyx_gui/frontend/gui_tools.h | 25 + nyx/nyx_gui/gfx/di.c | 281 + nyx/nyx_gui/gfx/di.h | 370 + nyx/nyx_gui/gfx/di.inl | 601 ++ nyx/nyx_gui/gfx/gfx.c | 628 ++ nyx/nyx_gui/gfx/gfx.h | 61 + nyx/nyx_gui/gfx/logos-gui.h | 29 + nyx/nyx_gui/hos/hos.c | 211 + nyx/nyx_gui/hos/hos.h | 70 + nyx/nyx_gui/hos/pkg1.c | 95 + nyx/nyx_gui/hos/pkg1.h | 49 + nyx/nyx_gui/hos/pkg2.c | 104 + nyx/nyx_gui/hos/pkg2.h | 94 + nyx/nyx_gui/hos/sept.c | 220 + nyx/nyx_gui/hos/sept.h | 25 + nyx/nyx_gui/ianos/ianos.c | 131 + nyx/nyx_gui/ianos/ianos.h | 34 + nyx/nyx_gui/input/als.c | 118 + nyx/nyx_gui/input/als.h | 65 + nyx/nyx_gui/input/touch.c | 206 + nyx/nyx_gui/input/touch.h | 115 + nyx/nyx_gui/libs/compr/blz.c | 98 + nyx/nyx_gui/libs/compr/blz.h | 36 + nyx/nyx_gui/libs/compr/lz.c | 179 + nyx/nyx_gui/libs/compr/lz.h | 52 + nyx/nyx_gui/libs/elfload/elf.h | 589 ++ nyx/nyx_gui/libs/elfload/elfarch.h | 49 + nyx/nyx_gui/libs/elfload/elfload.c | 329 + nyx/nyx_gui/libs/elfload/elfload.h | 127 + nyx/nyx_gui/libs/elfload/elfreloc_aarch64.c | 84 + nyx/nyx_gui/libs/elfload/elfreloc_arm.c | 66 + nyx/nyx_gui/libs/fatfs/diskio.c | 89 + nyx/nyx_gui/libs/fatfs/diskio.h | 79 + nyx/nyx_gui/libs/fatfs/ff.c | 6866 +++++++++++++++++ nyx/nyx_gui/libs/fatfs/ff.h | 391 + nyx/nyx_gui/libs/fatfs/ffconf.h | 293 + nyx/nyx_gui/libs/fatfs/ffsystem.c | 39 + nyx/nyx_gui/libs/fatfs/ffunicode.c | 632 ++ nyx/nyx_gui/libs/lv_conf.h | 376 + nyx/nyx_gui/libs/lvgl/docs/CODE_OF_CONDUCT.md | 46 + nyx/nyx_gui/libs/lvgl/docs/CONTRIBUTING.md | 103 + nyx/nyx_gui/libs/lvgl/docs/astyle_c | 1 + nyx/nyx_gui/libs/lvgl/docs/astyle_h | 1 + nyx/nyx_gui/libs/lvgl/licence.txt | 8 + nyx/nyx_gui/libs/lvgl/lv_core/lv_core.mk | 12 + nyx/nyx_gui/libs/lvgl/lv_core/lv_group.c | 554 ++ nyx/nyx_gui/libs/lvgl/lv_core/lv_group.h | 247 + nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.c | 965 +++ nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.h | 157 + nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.c | 117 + nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.h | 74 + nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.c | 1986 +++++ nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.h | 840 ++ nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.c | 614 ++ nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.h | 94 + nyx/nyx_gui/libs/lvgl/lv_core/lv_style.c | 357 + nyx/nyx_gui/libs/lvgl/lv_core/lv_style.h | 198 + nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.c | 207 + nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.h | 119 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.c | 163 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.h | 115 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.mk | 14 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.c | 264 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.h | 53 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.c | 759 ++ nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.h | 167 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.c | 264 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.h | 53 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.c | 607 ++ nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.h | 49 + .../libs/lvgl/lv_draw/lv_draw_rbasic.c | 269 + .../libs/lvgl/lv_draw/lv_draw_rbasic.h | 96 + nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.c | 1435 ++++ nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.h | 48 + .../libs/lvgl/lv_draw/lv_draw_triangle.c | 168 + .../libs/lvgl/lv_draw/lv_draw_triangle.h | 51 + .../libs/lvgl/lv_draw/lv_draw_vbasic.c | 691 ++ .../libs/lvgl/lv_draw/lv_draw_vbasic.h | 89 + .../libs/lvgl/lv_fonts/hekate_symbol_120.c | 56 + .../libs/lvgl/lv_fonts/hekate_symbol_20.c | 157 + .../libs/lvgl/lv_fonts/hekate_symbol_30.c | 157 + nyx/nyx_gui/libs/lvgl/lv_fonts/interui_20.c | 246 + nyx/nyx_gui/libs/lvgl/lv_fonts/interui_30.c | 246 + .../libs/lvgl/lv_fonts/lv_font_builtin.c | 100 + .../libs/lvgl/lv_fonts/lv_font_builtin.h | 95 + nyx/nyx_gui/libs/lvgl/lv_fonts/lv_fonts.mk | 14 + nyx/nyx_gui/libs/lvgl/lv_fonts/ubuntu_mono.c | 246 + nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.h | 40 + nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.mk | 8 + nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.c | 242 + nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.h | 173 + nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.c | 135 + nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.h | 166 + nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.c | 100 + nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.h | 65 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.c | 445 ++ nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.h | 176 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.c | 200 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.h | 168 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.c | 79 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.h | 80 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.c | 143 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.h | 448 ++ nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.c | 269 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.h | 191 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.c | 627 ++ nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.h | 276 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.c | 40 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.h | 76 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.c | 376 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.h | 145 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.c | 82 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.h | 86 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.c | 165 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.h | 73 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.c | 464 ++ nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.h | 127 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_misc.mk | 19 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_symbol_def.h | 223 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.c | 332 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.h | 148 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.c | 36 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.h | 38 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.c | 793 ++ nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.h | 197 + nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.c | 516 ++ nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.h | 213 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.c | 310 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.h | 127 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.c | 429 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.h | 160 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.c | 763 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.h | 280 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.c | 881 +++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.h | 197 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.c | 1038 +++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.h | 246 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.c | 593 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.h | 229 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.c | 347 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.h | 174 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.c | 824 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.h | 262 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.c | 642 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.h | 163 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.c | 981 +++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.h | 286 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.c | 466 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.h | 222 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.c | 408 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.h | 195 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.c | 391 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.h | 249 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.c | 465 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.h | 199 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.c | 987 +++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.h | 295 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.c | 244 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.h | 116 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.c | 301 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.h | 158 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.c | 1052 +++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.h | 336 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.c | 382 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.h | 153 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.c | 532 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.h | 221 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx.mk | 36 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.c | 231 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.h | 111 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.c | 1205 +++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.h | 402 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.c | 411 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.h | 168 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.c | 582 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.h | 224 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.c | 520 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.h | 202 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.c | 471 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.h | 201 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.c | 445 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.h | 194 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.c | 1365 ++++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.h | 390 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.c | 855 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.h | 261 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.c | 909 +++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.h | 252 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.c | 578 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.h | 163 + nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.c | 590 ++ nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.h | 298 + nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.c | 112 + nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.h | 343 + .../libs/lvgl/lv_themes/lv_theme_hekate.c | 905 +++ .../libs/lvgl/lv_themes/lv_theme_hekate.h | 71 + nyx/nyx_gui/libs/lvgl/lv_themes/lv_themes.mk | 9 + nyx/nyx_gui/libs/lvgl/lv_version.h | 66 + nyx/nyx_gui/libs/lvgl/lvgl.h | 85 + nyx/nyx_gui/libs/lvgl/lvgl.mk | 8 + ...95300-57B4628D2267231D57E0FC1078C0596D.jpg | Bin 0 -> 67711 bytes ...95900-57B4628D2267231D57E0FC1078C0596D.jpg | Bin 0 -> 106882 bytes ...01400-57B4628D2267231D57E0FC1078C0596D.jpg | Bin 0 -> 75176 bytes ...34300-57B4628D2267231D57E0FC1078C0596D.jpg | Bin 0 -> 65199 bytes ...11300-57B4628D2267231D57E0FC1078C0596D.jpg | Bin 0 -> 78744 bytes nyx/nyx_gui/link.ld | 23 + nyx/nyx_gui/mem/emc.h | 667 ++ nyx/nyx_gui/mem/heap.c | 129 + nyx/nyx_gui/mem/heap.h | 28 + nyx/nyx_gui/mem/mc.c | 143 + nyx/nyx_gui/mem/mc.h | 14 + nyx/nyx_gui/mem/mc_t210.h | 466 ++ nyx/nyx_gui/mem/minerva.c | 99 + nyx/nyx_gui/mem/minerva.h | 61 + nyx/nyx_gui/mem/mtc_table.h | 560 ++ nyx/nyx_gui/mem/sdram.c | 565 ++ nyx/nyx_gui/mem/sdram.h | 27 + nyx/nyx_gui/mem/sdram_config.inl | 1152 +++ nyx/nyx_gui/mem/sdram_config_lz.inl | 124 + nyx/nyx_gui/mem/sdram_lp0.c | 1126 +++ nyx/nyx_gui/mem/sdram_lp0_param_t210.h | 964 +++ nyx/nyx_gui/mem/sdram_param_t210.h | 931 +++ nyx/nyx_gui/nyx.c | 427 + nyx/nyx_gui/power/bq24193.c | 162 + nyx/nyx_gui/power/bq24193.h | 119 + nyx/nyx_gui/power/max17050.c | 266 + nyx/nyx_gui/power/max17050.h | 127 + nyx/nyx_gui/power/max77620.h | 331 + nyx/nyx_gui/power/max7762x.c | 165 + nyx/nyx_gui/power/max7762x.h | 116 + nyx/nyx_gui/rtc/max77620-rtc.c | 77 + nyx/nyx_gui/rtc/max77620-rtc.h | 75 + nyx/nyx_gui/sec/se.c | 298 + nyx/nyx_gui/sec/se.h | 31 + nyx/nyx_gui/sec/se_t210.h | 357 + nyx/nyx_gui/sec/tsec.c | 285 + nyx/nyx_gui/sec/tsec.h | 34 + nyx/nyx_gui/sec/tsec_t210.h | 50 + nyx/nyx_gui/soc/bpmp.c | 217 + nyx/nyx_gui/soc/bpmp.h | 51 + nyx/nyx_gui/soc/clock.c | 529 ++ nyx/nyx_gui/soc/clock.h | 172 + nyx/nyx_gui/soc/cluster.c | 133 + nyx/nyx_gui/soc/cluster.h | 37 + nyx/nyx_gui/soc/fuse.c | 349 + nyx/nyx_gui/soc/fuse.h | 83 + nyx/nyx_gui/soc/gpio.c | 94 + nyx/nyx_gui/soc/gpio.h | 77 + nyx/nyx_gui/soc/hw_init.c | 73 + nyx/nyx_gui/soc/hw_init.h | 24 + nyx/nyx_gui/soc/i2c.c | 143 + nyx/nyx_gui/soc/i2c.h | 46 + nyx/nyx_gui/soc/kfuse.c | 42 + nyx/nyx_gui/soc/kfuse.h | 41 + nyx/nyx_gui/soc/pinmux.c | 32 + nyx/nyx_gui/soc/pinmux.h | 103 + nyx/nyx_gui/soc/pmc.h | 71 + nyx/nyx_gui/soc/pmc_lp0_t210.h | 564 ++ nyx/nyx_gui/soc/smmu.c | 171 + nyx/nyx_gui/soc/smmu.h | 82 + nyx/nyx_gui/soc/t210.h | 191 + nyx/nyx_gui/soc/uart.c | 83 + nyx/nyx_gui/soc/uart.h | 69 + nyx/nyx_gui/start.S | 77 + nyx/nyx_gui/storage/mmc.h | 432 ++ nyx/nyx_gui/storage/nx_emmc.c | 77 + nyx/nyx_gui/storage/nx_emmc.h | 72 + nyx/nyx_gui/storage/sd.h | 124 + nyx/nyx_gui/storage/sdmmc.c | 1201 +++ nyx/nyx_gui/storage/sdmmc.h | 113 + nyx/nyx_gui/storage/sdmmc_driver.c | 1128 +++ nyx/nyx_gui/storage/sdmmc_driver.h | 126 + nyx/nyx_gui/storage/sdmmc_t210.h | 132 + nyx/nyx_gui/thermal/fan.c | 101 + nyx/nyx_gui/thermal/fan.h | 29 + nyx/nyx_gui/thermal/tmp451.c | 52 + nyx/nyx_gui/thermal/tmp451.h | 37 + nyx/nyx_gui/utils/aarch64_util.h | 35 + nyx/nyx_gui/utils/btn.c | 76 + nyx/nyx_gui/utils/btn.h | 31 + nyx/nyx_gui/utils/dirlist.c | 100 + nyx/nyx_gui/utils/dirlist.h | 19 + nyx/nyx_gui/utils/list.h | 95 + nyx/nyx_gui/utils/sprintf.c | 149 + nyx/nyx_gui/utils/sprintf.h | 24 + nyx/nyx_gui/utils/types.h | 90 + nyx/nyx_gui/utils/util.c | 109 + nyx/nyx_gui/utils/util.h | 57 + 308 files changed, 91222 insertions(+), 2 deletions(-) create mode 100644 nyx/Makefile create mode 100644 nyx/README_RES.md create mode 100644 nyx/nyx_gui/config/config.c create mode 100644 nyx/nyx_gui/config/config.h create mode 100644 nyx/nyx_gui/config/ini.c create mode 100644 nyx/nyx_gui/config/ini.h create mode 100644 nyx/nyx_gui/frontend/fe_emmc_tools.c create mode 100644 nyx/nyx_gui/frontend/fe_emmc_tools.h create mode 100644 nyx/nyx_gui/frontend/fe_emummc_tools.c create mode 100644 nyx/nyx_gui/frontend/fe_emummc_tools.h create mode 100644 nyx/nyx_gui/frontend/gui.c create mode 100644 nyx/nyx_gui/frontend/gui.h create mode 100644 nyx/nyx_gui/frontend/gui_emmc_tools.c create mode 100644 nyx/nyx_gui/frontend/gui_emmc_tools.h create mode 100644 nyx/nyx_gui/frontend/gui_emummc_tools.c create mode 100644 nyx/nyx_gui/frontend/gui_emummc_tools.h create mode 100644 nyx/nyx_gui/frontend/gui_info.c create mode 100644 nyx/nyx_gui/frontend/gui_info.h create mode 100644 nyx/nyx_gui/frontend/gui_tools.c create mode 100644 nyx/nyx_gui/frontend/gui_tools.h create mode 100644 nyx/nyx_gui/gfx/di.c create mode 100644 nyx/nyx_gui/gfx/di.h create mode 100644 nyx/nyx_gui/gfx/di.inl create mode 100644 nyx/nyx_gui/gfx/gfx.c create mode 100644 nyx/nyx_gui/gfx/gfx.h create mode 100644 nyx/nyx_gui/gfx/logos-gui.h create mode 100644 nyx/nyx_gui/hos/hos.c create mode 100644 nyx/nyx_gui/hos/hos.h create mode 100644 nyx/nyx_gui/hos/pkg1.c create mode 100644 nyx/nyx_gui/hos/pkg1.h create mode 100644 nyx/nyx_gui/hos/pkg2.c create mode 100644 nyx/nyx_gui/hos/pkg2.h create mode 100644 nyx/nyx_gui/hos/sept.c create mode 100644 nyx/nyx_gui/hos/sept.h create mode 100644 nyx/nyx_gui/ianos/ianos.c create mode 100644 nyx/nyx_gui/ianos/ianos.h create mode 100644 nyx/nyx_gui/input/als.c create mode 100644 nyx/nyx_gui/input/als.h create mode 100644 nyx/nyx_gui/input/touch.c create mode 100644 nyx/nyx_gui/input/touch.h create mode 100644 nyx/nyx_gui/libs/compr/blz.c create mode 100644 nyx/nyx_gui/libs/compr/blz.h create mode 100644 nyx/nyx_gui/libs/compr/lz.c create mode 100644 nyx/nyx_gui/libs/compr/lz.h create mode 100644 nyx/nyx_gui/libs/elfload/elf.h create mode 100644 nyx/nyx_gui/libs/elfload/elfarch.h create mode 100644 nyx/nyx_gui/libs/elfload/elfload.c create mode 100644 nyx/nyx_gui/libs/elfload/elfload.h create mode 100644 nyx/nyx_gui/libs/elfload/elfreloc_aarch64.c create mode 100644 nyx/nyx_gui/libs/elfload/elfreloc_arm.c create mode 100644 nyx/nyx_gui/libs/fatfs/diskio.c create mode 100644 nyx/nyx_gui/libs/fatfs/diskio.h create mode 100644 nyx/nyx_gui/libs/fatfs/ff.c create mode 100644 nyx/nyx_gui/libs/fatfs/ff.h create mode 100644 nyx/nyx_gui/libs/fatfs/ffconf.h create mode 100644 nyx/nyx_gui/libs/fatfs/ffsystem.c create mode 100644 nyx/nyx_gui/libs/fatfs/ffunicode.c create mode 100644 nyx/nyx_gui/libs/lv_conf.h create mode 100644 nyx/nyx_gui/libs/lvgl/docs/CODE_OF_CONDUCT.md create mode 100644 nyx/nyx_gui/libs/lvgl/docs/CONTRIBUTING.md create mode 100644 nyx/nyx_gui/libs/lvgl/docs/astyle_c create mode 100644 nyx/nyx_gui/libs/lvgl/docs/astyle_h create mode 100644 nyx/nyx_gui/libs/lvgl/licence.txt create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_core.mk create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_group.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_group.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_style.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_style.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.mk create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rbasic.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rbasic.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_triangle.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_triangle.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_vbasic.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_vbasic.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_120.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_20.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_30.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/interui_20.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/interui_30.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/lv_font_builtin.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/lv_font_builtin.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/lv_fonts.mk create mode 100644 nyx/nyx_gui/libs/lvgl/lv_fonts/ubuntu_mono.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.mk create mode 100644 nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_misc.mk create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_symbol_def.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx.mk create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme_hekate.c create mode 100644 nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme_hekate.h create mode 100644 nyx/nyx_gui/libs/lvgl/lv_themes/lv_themes.mk create mode 100644 nyx/nyx_gui/libs/lvgl/lv_version.h create mode 100644 nyx/nyx_gui/libs/lvgl/lvgl.h create mode 100644 nyx/nyx_gui/libs/lvgl/lvgl.mk create mode 100644 nyx/nyx_gui/libs/lvgl/ref/2017031823595300-57B4628D2267231D57E0FC1078C0596D.jpg create mode 100644 nyx/nyx_gui/libs/lvgl/ref/2017031823595900-57B4628D2267231D57E0FC1078C0596D.jpg create mode 100644 nyx/nyx_gui/libs/lvgl/ref/2017031900001400-57B4628D2267231D57E0FC1078C0596D.jpg create mode 100644 nyx/nyx_gui/libs/lvgl/ref/2017091517134300-57B4628D2267231D57E0FC1078C0596D.jpg create mode 100644 nyx/nyx_gui/libs/lvgl/ref/2017091903111300-57B4628D2267231D57E0FC1078C0596D.jpg create mode 100644 nyx/nyx_gui/link.ld create mode 100644 nyx/nyx_gui/mem/emc.h create mode 100644 nyx/nyx_gui/mem/heap.c create mode 100644 nyx/nyx_gui/mem/heap.h create mode 100644 nyx/nyx_gui/mem/mc.c create mode 100644 nyx/nyx_gui/mem/mc.h create mode 100644 nyx/nyx_gui/mem/mc_t210.h create mode 100644 nyx/nyx_gui/mem/minerva.c create mode 100644 nyx/nyx_gui/mem/minerva.h create mode 100644 nyx/nyx_gui/mem/mtc_table.h create mode 100644 nyx/nyx_gui/mem/sdram.c create mode 100644 nyx/nyx_gui/mem/sdram.h create mode 100644 nyx/nyx_gui/mem/sdram_config.inl create mode 100644 nyx/nyx_gui/mem/sdram_config_lz.inl create mode 100644 nyx/nyx_gui/mem/sdram_lp0.c create mode 100644 nyx/nyx_gui/mem/sdram_lp0_param_t210.h create mode 100644 nyx/nyx_gui/mem/sdram_param_t210.h create mode 100644 nyx/nyx_gui/nyx.c create mode 100644 nyx/nyx_gui/power/bq24193.c create mode 100644 nyx/nyx_gui/power/bq24193.h create mode 100644 nyx/nyx_gui/power/max17050.c create mode 100644 nyx/nyx_gui/power/max17050.h create mode 100644 nyx/nyx_gui/power/max77620.h create mode 100644 nyx/nyx_gui/power/max7762x.c create mode 100644 nyx/nyx_gui/power/max7762x.h create mode 100644 nyx/nyx_gui/rtc/max77620-rtc.c create mode 100644 nyx/nyx_gui/rtc/max77620-rtc.h create mode 100644 nyx/nyx_gui/sec/se.c create mode 100644 nyx/nyx_gui/sec/se.h create mode 100644 nyx/nyx_gui/sec/se_t210.h create mode 100644 nyx/nyx_gui/sec/tsec.c create mode 100644 nyx/nyx_gui/sec/tsec.h create mode 100644 nyx/nyx_gui/sec/tsec_t210.h create mode 100644 nyx/nyx_gui/soc/bpmp.c create mode 100644 nyx/nyx_gui/soc/bpmp.h create mode 100644 nyx/nyx_gui/soc/clock.c create mode 100644 nyx/nyx_gui/soc/clock.h create mode 100644 nyx/nyx_gui/soc/cluster.c create mode 100644 nyx/nyx_gui/soc/cluster.h create mode 100644 nyx/nyx_gui/soc/fuse.c create mode 100644 nyx/nyx_gui/soc/fuse.h create mode 100644 nyx/nyx_gui/soc/gpio.c create mode 100644 nyx/nyx_gui/soc/gpio.h create mode 100644 nyx/nyx_gui/soc/hw_init.c create mode 100644 nyx/nyx_gui/soc/hw_init.h create mode 100644 nyx/nyx_gui/soc/i2c.c create mode 100644 nyx/nyx_gui/soc/i2c.h create mode 100644 nyx/nyx_gui/soc/kfuse.c create mode 100644 nyx/nyx_gui/soc/kfuse.h create mode 100644 nyx/nyx_gui/soc/pinmux.c create mode 100644 nyx/nyx_gui/soc/pinmux.h create mode 100644 nyx/nyx_gui/soc/pmc.h create mode 100644 nyx/nyx_gui/soc/pmc_lp0_t210.h create mode 100644 nyx/nyx_gui/soc/smmu.c create mode 100644 nyx/nyx_gui/soc/smmu.h create mode 100644 nyx/nyx_gui/soc/t210.h create mode 100644 nyx/nyx_gui/soc/uart.c create mode 100644 nyx/nyx_gui/soc/uart.h create mode 100644 nyx/nyx_gui/start.S create mode 100644 nyx/nyx_gui/storage/mmc.h create mode 100644 nyx/nyx_gui/storage/nx_emmc.c create mode 100644 nyx/nyx_gui/storage/nx_emmc.h create mode 100644 nyx/nyx_gui/storage/sd.h create mode 100644 nyx/nyx_gui/storage/sdmmc.c create mode 100644 nyx/nyx_gui/storage/sdmmc.h create mode 100644 nyx/nyx_gui/storage/sdmmc_driver.c create mode 100644 nyx/nyx_gui/storage/sdmmc_driver.h create mode 100644 nyx/nyx_gui/storage/sdmmc_t210.h create mode 100644 nyx/nyx_gui/thermal/fan.c create mode 100644 nyx/nyx_gui/thermal/fan.h create mode 100644 nyx/nyx_gui/thermal/tmp451.c create mode 100644 nyx/nyx_gui/thermal/tmp451.h create mode 100644 nyx/nyx_gui/utils/aarch64_util.h create mode 100644 nyx/nyx_gui/utils/btn.c create mode 100644 nyx/nyx_gui/utils/btn.h create mode 100644 nyx/nyx_gui/utils/dirlist.c create mode 100644 nyx/nyx_gui/utils/dirlist.h create mode 100644 nyx/nyx_gui/utils/list.h create mode 100644 nyx/nyx_gui/utils/sprintf.c create mode 100644 nyx/nyx_gui/utils/sprintf.h create mode 100644 nyx/nyx_gui/utils/types.h create mode 100644 nyx/nyx_gui/utils/util.c create mode 100644 nyx/nyx_gui/utils/util.h diff --git a/Makefile b/Makefile index a1ff2a9..5fead3c 100755 --- a/Makefile +++ b/Makefile @@ -74,10 +74,11 @@ CFLAGS = $(ARCH) -O2 -nostdlib -ffunction-sections -fdata-sections -fomit-frame- LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections -Xlinker --defsym=IPL_LOAD_ADDR=$(IPL_LOAD_ADDR) MODULEDIRS := $(wildcard modules/*) +NYXDIR := $(wildcard nyx) ################################################################################ -.PHONY: all clean $(MODULEDIRS) +.PHONY: all clean $(MODULEDIRS) $(NYXDIR) all: $(TARGET).bin @echo -n "Payload size is " @@ -92,7 +93,10 @@ clean: $(MODULEDIRS): $(MAKE) -C $@ $(MAKECMDGOALS)$(MAKEFLAGS) -$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf $(MODULEDIRS) +$(NYXDIR): + $(MAKE) -C $@ $(MAKECMDGOALS)$(MAKEFLAGS) + +$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf $(MODULEDIRS) $(NYXDIR) $(OBJCOPY) -S -O binary $< $(OUTPUTDIR)/$@ @printf ICTC49 >> $(OUTPUTDIR)/$@ diff --git a/nyx/Makefile b/nyx/Makefile new file mode 100644 index 0000000..6b09763 --- /dev/null +++ b/nyx/Makefile @@ -0,0 +1,117 @@ +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") +endif + +include $(DEVKITARM)/base_rules + +################################################################################ + +NYX_LOAD_ADDR := 0x40003000 +NYX_RES_ADDR := 0xEE000000 +NYX_STORAGE_ADDR := 0xED000000 +NYX_MAGIC := 0x43544347 #"GCTC" +BLVERSION_MAJOR := 0 +BLVERSION_MINOR := 8 +BLVERSION_HOTFX := 0 + +BL_RESERVED := 0 + +################################################################################ + +TARGET := nyx +BUILDDIR := ./../build +OUTPUTDIR := ./../output +SOURCEDIR = nyx_gui +VPATH = $(dir $(wildcard ./$(SOURCEDIR)/*/)) $(dir $(wildcard ./$(SOURCEDIR)/*/*/)) +VPATH += $(dir $(wildcard ./$(SOURCEDIR)/*/*/*/)) $(dir $(wildcard ./$(SOURCEDIR)/*/*/*/*/)) + +# Main and graphics. +OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \ + start.o \ + nyx.o heap.o \ + gfx.o \ + gui.o gui_info.o gui_tools.o gui_emmc_tools.o gui_emummc_tools.o \ + fe_emummc_tools.o fe_emmc_tools.o \ +) + +# Hardware. +OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ + bpmp.o clock.o cluster.o di.o gpio.o i2c.o mc.o sdram.o pinmux.o se.o smmu.o tsec.o uart.o \ + fuse.o kfuse.o minerva.o \ + sdmmc.o sdmmc_driver.o \ + bq24193.o max17050.o max7762x.o max77620-rtc.o \ + touch.o tmp451.o fan.o \ + hw_init.o \ +) + +# Utilities. +OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ + btn.o dirlist.o ianos.o util.o \ + config.o ini.o \ + sprintf.o \ +) + +# Horizon. +OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ + nx_emmc.o \ + hos.o pkg1.o pkg2.o sept.o \ +) + +# Libraries. +OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ + diskio.o ff.o ffunicode.o ffsystem.o \ + elfload.o elfreloc_arm.o \ + lv_group.o lv_indev.o lv_obj.o lv_refr.o lv_style.o lv_vdb.o \ + lv_draw.o lv_draw_rbasic.o lv_draw_vbasic.o lv_draw_arc.o lv_draw_img.o \ + lv_draw_label.o lv_draw_line.o lv_draw_rect.o lv_draw_triangle.o \ + lv_hal_disp.o lv_hal_indev.o lv_hal_tick.o \ + interui_20.o interui_30.o ubuntu_mono.o hekate_symbol_20.o hekate_symbol_30.o hekate_symbol_120.o lv_font_builtin.o \ + lv_anim.o lv_area.o lv_circ.o lv_color.o lv_font.o lv_ll.o lv_math.o lv_mem.o lv_task.o lv_txt.o lv_gc.o \ + lv_bar.o lv_btn.o lv_btnm.o lv_cb.o lv_cont.o lv_ddlist.o lv_img.o lv_kb.o lv_label.o lv_line.o lv_list.o lv_lmeter.o lv_mbox.o \ + lv_page.o lv_roller.o lv_slider.o lv_sw.o lv_tabview.o lv_ta.o lv_win.o lv_log.o lv_imgbtn.o \ + lv_theme.o lv_theme_hekate.o \ +) + +################################################################################ + +CUSTOMDEFINES := -DNYX_RES_ADDR=$(NYX_RES_ADDR) -DNYX_STORAGE_ADDR=$(NYX_STORAGE_ADDR) +CUSTOMDEFINES += -DNYX_LOAD_ADDR=$(NYX_LOAD_ADDR) -DBL_MAGIC=$(NYX_MAGIC) +CUSTOMDEFINES += -DBL_VER_MJ=$(BLVERSION_MAJOR) -DBL_VER_MN=$(BLVERSION_MINOR) -DBL_VER_HF=$(BLVERSION_HOTFX) -DBL_RESERVED=$(BL_RESERVED) + +# 0: UART_A, 1: UART_B. +#CUSTOMDEFINES += -DDEBUG_UART_PORT=1 + +#CUSTOMDEFINES += -DDEBUG + +ARCH := -march=armv4t -mtune=arm7tdmi -mthumb-interwork +CFLAGS = $(ARCH) -O2 -nostdlib -ffunction-sections -fdata-sections -flto -fomit-frame-pointer -fno-inline -fno-strict-aliasing -std=gnu11 -Wall $(CUSTOMDEFINES) +CFLAGS += -g +LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections -Xlinker --defsym=NYX_LOAD_ADDR=$(NYX_LOAD_ADDR) + +################################################################################ + +.PHONY: all clean + +all: $(TARGET).bin + @echo -n "Nyx size is " + @wc -c < $(OUTPUTDIR)/$(TARGET).bin + +clean: + @rm -rf $(OBJS) + @rm -rf $(BUILDDIR) + @rm -rf $(OUTPUTDIR) + +$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf + $(OBJCOPY) -S -O binary $< $(OUTPUTDIR)/$@ + +$(BUILDDIR)/$(TARGET)/$(TARGET).elf: $(OBJS) + $(CC) $(LDFLAGS) -T $(SOURCEDIR)/link.ld $^ -o $@ + +$(BUILDDIR)/$(TARGET)/%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +$(BUILDDIR)/$(TARGET)/%.o: %.S + @mkdir -p "$(BUILDDIR)" + @mkdir -p "$(BUILDDIR)/$(TARGET)" + @mkdir -p "$(OUTPUTDIR)" + $(CC) $(CFLAGS) -c $< -o $@ diff --git a/nyx/README_RES.md b/nyx/README_RES.md new file mode 100644 index 0000000..ada08fe --- /dev/null +++ b/nyx/README_RES.md @@ -0,0 +1,12 @@ +# Nyx - Background - Icons + +The background for Nyx, must be a 1280 x 720 32-bit BMP. Alpha blending is taken into account. For that reason, if a solid background is required, that value must be 0xFF. There are sites that can produce the correct bmp. + +The icons supported are 192 x 192 32-bit BMP. You can utilize transparency at will and make nice mixes with the button background. + + +## How to configure + +The background must go to /bootloader/res/background.bmp + +The icons can be utilized either via `[boot entries names]` -> `boot entries names.bmp` or by using `icon={sd path}`, which should point at a bmp. diff --git a/nyx/nyx_gui/config/config.c b/nyx/nyx_gui/config/config.c new file mode 100644 index 0000000..882a3ab --- /dev/null +++ b/nyx/nyx_gui/config/config.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "config.h" +#include "ini.h" +#include "../gfx/gfx.h" +#include "../libs/fatfs/ff.h" +#include "../soc/fuse.h" +#include "../soc/t210.h" +#include "../utils/btn.h" +#include "../utils/list.h" +#include "../utils/util.h" + +extern hekate_config h_cfg; +extern bool sd_mount(); +extern void sd_unmount(bool deinit); + +void set_default_configuration() +{ + h_cfg.autoboot = 0; + h_cfg.autoboot_list = 0; + h_cfg.bootwait = 3; + h_cfg.verification = 1; + h_cfg.se_keygen_done = 0; + h_cfg.sbar_time_keeping = 0; + h_cfg.backlight = 100; + h_cfg.autohosoff = 0; + h_cfg.errors = 0; + h_cfg.autonogc = 1; + h_cfg.sept_run = EMC(EMC_SCRATCH0) & EMC_SEPT_RUN; + h_cfg.rcm_patched = fuse_check_patched_rcm(); + h_cfg.sd_timeoff = 0; +} + +int create_config_entry() +{ + if (!sd_mount()) + return 1; + + char lbuf[16]; + FIL fp; + bool mainIniFound = false; + + LIST_INIT(ini_sections); + + if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) + mainIniFound = true; + else + { + u8 res = f_open(&fp, "bootloader/hekate_ipl.ini", FA_READ); + if (res == FR_NO_FILE || res == FR_NO_PATH) + { + f_mkdir("bootloader"); + f_mkdir("bootloader/ini"); + f_mkdir("bootloader/payloads"); + f_mkdir("bootloader/sys"); + } + else + { + if (!res) + f_close(&fp); + return 1; + } + } + + if (f_open(&fp, "bootloader/hekate_ipl.ini", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) + return 1; + // Add config entry. + f_puts("[config]\nautoboot=", &fp); + itoa(h_cfg.autoboot, lbuf, 10); + f_puts(lbuf, &fp); + f_puts("\nautoboot_list=", &fp); + itoa(h_cfg.autoboot_list, lbuf, 10); + f_puts(lbuf, &fp); + f_puts("\nbootwait=", &fp); + itoa(h_cfg.bootwait, lbuf, 10); + f_puts(lbuf, &fp); + f_puts("\nverification=", &fp); + itoa(h_cfg.verification, lbuf, 10); + f_puts(lbuf, &fp); + f_puts("\nbacklight=", &fp); + itoa(h_cfg.backlight, lbuf, 10); + f_puts(lbuf, &fp); + f_puts("\nautohosoff=", &fp); + itoa(h_cfg.autohosoff, lbuf, 10); + f_puts(lbuf, &fp); + f_puts("\nautonogc=", &fp); + itoa(h_cfg.autonogc, lbuf, 10); + f_puts(lbuf, &fp); + if (h_cfg.brand) + { + f_puts("\nbrand=", &fp); + f_puts(h_cfg.brand, &fp); + } + if (h_cfg.tagline) + { + f_puts("\ntagline=", &fp); + f_puts(h_cfg.tagline, &fp); + } + f_puts("\n", &fp); + + if (mainIniFound) + { + // Re-construct existing entries. + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) + { + if (!strcmp(ini_sec->name, "config")) + continue; + + switch (ini_sec->type) + { + case INI_CHOICE: // Re-construct Boot entry [ ]. + f_puts("[", &fp); + f_puts(ini_sec->name, &fp); + f_puts("]\n", &fp); + // Re-construct boot entry's config. + LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) + { + f_puts(kv->key, &fp); + f_puts("=", &fp); + f_puts(kv->val, &fp); + f_puts("\n", &fp); + } + break; + case INI_CAPTION: // Re-construct caption entry { }. + f_puts("{", &fp); + f_puts(ini_sec->name, &fp); + f_puts("}\n", &fp); + break; + case INI_NEWLINE: // Re-construct cosmetic newline \n. + f_puts("\n", &fp); + break; + case INI_COMMENT: // Re-construct comment entry #. + f_puts("#", &fp); + f_puts(ini_sec->name, &fp); + f_puts("\n", &fp); + break; + } + } + } + + f_close(&fp); + sd_unmount(false); + + if (mainIniFound) + ini_free(&ini_sections); + + return 0; +} diff --git a/nyx/nyx_gui/config/config.h b/nyx/nyx_gui/config/config.h new file mode 100644 index 0000000..a0719c4 --- /dev/null +++ b/nyx/nyx_gui/config/config.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +#include "../utils/types.h" + +typedef struct _hekate_config +{ + // Non-volatile config. + u32 autoboot; + u32 autoboot_list; + u32 bootwait; + u32 verification; + u32 backlight; + u32 autohosoff; + u32 autonogc; + char *brand; + char *tagline; + // Global temporary config. + bool se_keygen_done; + u32 sbar_time_keeping; + u32 errors; + int sept_run; + bool rcm_patched; + u32 sd_timeoff; + bool emummc_force_disable; +} hekate_config; + +typedef enum +{ + ERR_LIBSYS_LP0 = (1 << 0), +} hsysmodule_t; + +void set_default_configuration(); +int create_config_entry(); + +#endif /* _CONFIG_H_ */ diff --git a/nyx/nyx_gui/config/ini.c b/nyx/nyx_gui/config/ini.c new file mode 100644 index 0000000..4e5450b --- /dev/null +++ b/nyx/nyx_gui/config/ini.c @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "ini.h" +#include "../libs/fatfs/ff.h" +#include "../mem/heap.h" +#include "../utils/dirlist.h" + +static char *_strdup(char *str) +{ + if (!str) + return NULL; + + // Remove starting space. + if (str[0] == ' ' && strlen(str)) + str++; + + char *res = (char *)malloc(strlen(str) + 1); + strcpy(res, str); + + // Remove trailing space. + if (res[strlen(res) - 1] == ' ' && strlen(res)) + res[strlen(res) - 1] = 0; + + return res; +} + +u32 _find_section_name(char *lbuf, u32 lblen, char schar) +{ + u32 i; + for (i = 0; i < lblen && lbuf[i] != schar && lbuf[i] != '\n' && lbuf[i] != '\r'; i++) + ; + lbuf[i] = 0; + + return i; +} + +ini_sec_t *_ini_create_section(link_t *dst, ini_sec_t *csec, char *name, u8 type) +{ + if (csec) + { + list_append(dst, &csec->link); + csec = NULL; + } + + csec = (ini_sec_t *)malloc(sizeof(ini_sec_t)); + csec->name = _strdup(name); + csec->type = type; + + return csec; +} + +int ini_parse(link_t *dst, char *ini_path, bool is_dir) +{ + u32 lblen; + u32 pathlen = strlen(ini_path); + u32 k = 0; + char lbuf[512]; + char *filelist = NULL; + FIL fp; + ini_sec_t *csec = NULL; + + char *filename = (char *)malloc(256); + + memcpy(filename, ini_path, pathlen + 1); + + // Get all ini filenames. + if (is_dir) + { + filelist = dirlist(filename, "*.ini", false, false); + if (!filelist) + { + free(filename); + return 0; + } + memcpy(filename + pathlen, "/", 2); + pathlen++; + } + + do + { + // Copy ini filename in path string. + if (is_dir) + { + if (filelist[k * 256]) + { + memcpy(filename + pathlen, &filelist[k * 256], strlen(&filelist[k * 256]) + 1); + k++; + } + else + break; + } + + // Open ini. + if (f_open(&fp, filename, FA_READ) != FR_OK) + { + free(filelist); + free(filename); + + return 0; + } + + do + { + // Fetch one line. + lbuf[0] = 0; + f_gets(lbuf, 512, &fp); + lblen = strlen(lbuf); + + // Remove trailing newline. + if (lbuf[lblen - 1] == '\n' || lbuf[lblen - 1] == '\r') + lbuf[lblen - 1] = 0; + + if (lblen > 2 && lbuf[0] == '[') // Create new section. + { + _find_section_name(lbuf, lblen, ']'); + + csec = _ini_create_section(dst, csec, &lbuf[1], INI_CHOICE); + list_init(&csec->kvs); + } + else if (lblen > 2 && lbuf[0] == '{') //Create new caption. + { + _find_section_name(lbuf, lblen, '}'); + + csec = _ini_create_section(dst, csec, &lbuf[1], INI_CAPTION); + csec->color = 0xFF0AB9E6; + } + else if (lblen > 2 && lbuf[0] == '#') //Create empty lines and comments. + { + _find_section_name(lbuf, lblen, '\0'); + + csec = _ini_create_section(dst, csec, &lbuf[1], INI_COMMENT); + } + else if (lblen < 2) + { + csec = _ini_create_section(dst, csec, NULL, INI_NEWLINE); + } + else if (csec && csec->type == INI_CHOICE) //Extract key/value. + { + u32 i = _find_section_name(lbuf, lblen, '='); + + ini_kv_t *kv = (ini_kv_t *)malloc(sizeof(ini_kv_t)); + kv->key = _strdup(&lbuf[0]); + kv->val = _strdup(&lbuf[i + 1]); + list_append(&csec->kvs, &kv->link); + } + } while (!f_eof(&fp)); + + f_close(&fp); + + if (csec) + { + list_append(dst, &csec->link); + if (is_dir) + csec = NULL; + } + } while (is_dir); + + free(filename); + free(filelist); + + return 1; +} + +void ini_free(link_t *dst) +{ + if (!dst->prev || !dst->next) + return; + + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, dst, link) + { + if (ini_sec->type == INI_CHOICE) + { + LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) + { + free(kv->key); + free(kv->val); + //free(kv); + } + } + free(ini_sec->name); + //free(ini_sec); + } + + list_init(dst); +} + +ini_sec_t *ini_clone_section(ini_sec_t *cfg) +{ + if (cfg == NULL) + return NULL; + + ini_sec_t *csec = (ini_sec_t *)malloc(sizeof(ini_sec_t)); + list_init(&csec->kvs); + + LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link) + { + ini_kv_t *kvcfg = (ini_kv_t *)malloc(sizeof(ini_kv_t)); + kvcfg->key = _strdup(kv->key); + kvcfg->val = _strdup(kv->val); + list_append(&csec->kvs, &kvcfg->link); + } + + return csec; +} + +void ini_free_section(ini_sec_t *cfg) +{ + if (cfg == NULL) + return; + + LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link) + { + free(kv->key); + free(kv->val); + //free(kv); + } + //free(cfg); + + cfg = NULL; +} + +char *ini_check_payload_section(ini_sec_t *cfg) +{ + char *path = NULL; + + if (cfg == NULL) + return NULL; + + LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link) + { + if (!strcmp("payload", kv->key)) + { + if (!path) + path = _strdup(kv->val); + } + } + + if (path) + return path; + else + return NULL; +} diff --git a/nyx/nyx_gui/config/ini.h b/nyx/nyx_gui/config/ini.h new file mode 100644 index 0000000..7f1d2c2 --- /dev/null +++ b/nyx/nyx_gui/config/ini.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _INI_H_ +#define _INI_H_ + +#include "../utils/types.h" +#include "../utils/list.h" + +#define INI_CHOICE 3 +#define INI_CAPTION 5 +#define INI_CHGLINE 6 +#define INI_NEWLINE 0xFE +#define INI_COMMENT 0xFF + +typedef struct _ini_kv_t +{ + char *key; + char *val; + link_t link; +} ini_kv_t; + +typedef struct _ini_sec_t +{ + char *name; + link_t kvs; + link_t link; + u32 type; + u32 color; +} ini_sec_t; + +int ini_parse(link_t *dst, char *ini_path, bool is_dir); +void ini_free(link_t *dst); +ini_sec_t *ini_clone_section(ini_sec_t *cfg); +void ini_free_section(ini_sec_t *cfg); +char *ini_check_payload_section(ini_sec_t *cfg); + +#endif + diff --git a/nyx/nyx_gui/frontend/fe_emmc_tools.c b/nyx/nyx_gui/frontend/fe_emmc_tools.c new file mode 100644 index 0000000..4020642 --- /dev/null +++ b/nyx/nyx_gui/frontend/fe_emmc_tools.c @@ -0,0 +1,1442 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 Rajko Stojadinovic + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +//! fix the dram stuff and the pop ups + +#include +#include + +#include "gui.h" +#include "fe_emmc_tools.h" +#include "fe_emummc_tools.h" +#include "../config/config.h" +#include "../libs/fatfs/ff.h" +#include "../mem/heap.h" +#include "../sec/se.h" +#include "../storage/nx_emmc.h" +#include "../storage/sdmmc.h" +#include "../utils/btn.h" +#include "../utils/sprintf.h" +#include "../utils/util.h" + +#define EMMC_BUF_ALIGNED 0xB5000000 +#define SDXC_BUF_ALIGNED 0xB6000000 +#define MIXD_BUF_ALIGNED 0xB7000000 + +#define NUM_SECTORS_PER_ITER 8192 // 4MB Cache. +#define OUT_FILENAME_SZ 128 +#define HASH_FILENAME_SZ (OUT_FILENAME_SZ + 11) // 11 == strlen(".sha256sums") +#define SHA256_SZ 0x20 + +extern sdmmc_t sd_sdmmc; +extern sdmmc_storage_t sd_storage; +extern FATFS sd_fs; +extern hekate_config h_cfg; + +extern bool sd_mount(); +extern void sd_unmount(bool deinit); +extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); + +#pragma GCC push_options +#pragma GCC target ("thumb") + +static void get_valid_partition(u32 *sector_start, u32 *sector_size, u32 *part_idx, bool backup) +{ + sd_mount(); + u8 *mbr = (u8 *)malloc(0x200); + sdmmc_storage_read(&sd_storage, 0, 1, mbr); + + memcpy(mbr, mbr + 0x1BE, 0x40); + + *part_idx = 0; + int i = 0; + u32 curr_part_size = 0; + for (i = 1; i < 4; i++) + { + curr_part_size = *(u32 *)&mbr[0x0C + (0x10 * i)]; + *sector_start = *(u32 *)&mbr[0x08 + (0x10 * i)]; + u8 type = mbr[0x04 + (0x10 * i)]; + if ((curr_part_size >= *sector_size) && *sector_start && type != 0x83 && (!backup || type == 0xEE)) + break; + } + if (i < 4) + *part_idx = i; + else + { + *sector_start = 0; + *sector_size = 0; + *part_idx = 0; + goto out; + } + + if (!backup) + *sector_start = *sector_start + 0x8000; + else + { + *sector_size = curr_part_size; + sdmmc_storage_read(&sd_storage, *sector_start + 0xC001, 1, mbr); + if (!memcmp(mbr, "EFI PART", 8)) + { + *sector_start = *sector_start + 0x8000; + goto out; + } + sdmmc_storage_read(&sd_storage, *sector_start + 0x4001, 1, mbr); + if (!memcmp(mbr, "EFI PART", 8)) + goto out; + + sdmmc_storage_read(&sd_storage, *sector_start + 0x4003, 1, mbr); + if (!memcmp(mbr, "EFI PART", 8)) + { + *sector_start = *sector_start + 2; + goto out; + } + } + +out: + free(mbr); +} + +static lv_obj_t *create_mbox_text(char *text, bool button_ok) +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\211", "\222OK", "\211", "" }; + lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES / 9 * 6); + + lv_mbox_set_text(mbox, text); + if (button_ok) + lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + return dark_bg; +} + +static int _dump_emmc_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage, u32 lba_curr, char *outFilename, emmc_part_t *part) +{ + FIL fp; + FIL hashFp; + u8 sparseShouldVerify = 4; + u32 btn = 0; + u32 prevPct = 200; + u32 sdFileSector = 0; + int res = 0; + const char hexa[] = "0123456789abcdef"; + DWORD *clmt = NULL; + + u8 hashEm[SHA256_SZ]; + u8 hashSd[SHA256_SZ]; + + if (f_open(&fp, outFilename, FA_READ) == FR_OK) + { + if (h_cfg.verification == 3) + { + char hashFilename[HASH_FILENAME_SZ]; + strncpy(hashFilename, outFilename, OUT_FILENAME_SZ - 1); + strcat(hashFilename, ".sha256sums"); + + res = f_open(&hashFp, hashFilename, FA_CREATE_ALWAYS | FA_WRITE); + if (res) + { + f_close(&fp); + + s_printf(gui->txt_buf, + "#FF0000 Hash file could not be written (error %d)!#\n" + "#FF0000 Aborting..#\n", res); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 1; + } + + char chunkSizeAscii[10]; + itoa(NUM_SECTORS_PER_ITER * NX_EMMC_BLOCKSIZE, chunkSizeAscii, 10); + chunkSizeAscii[9] = '\0'; + + f_puts("# chunksize: ", &hashFp); + f_puts(chunkSizeAscii, &hashFp); + f_puts("\n", &hashFp); + } + + u32 totalSectorsVer = (u32)((u64)f_size(&fp) >> (u64)9); + + u8 *bufEm = (u8 *)EMMC_BUF_ALIGNED; + u8 *bufSd = (u8 *)SDXC_BUF_ALIGNED; + + u32 pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); + lv_bar_set_value(gui->bar, pct); + lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, gui->bar_teal_bg); + lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, lv_theme_get_current()->bar.indic); + s_printf(gui->txt_buf, " "SYMBOL_DOT" %d%%", pct); + lv_label_set_text(gui->label_pct, gui->txt_buf); + manual_system_maintenance(true); + + clmt = f_expand_cltbl(&fp, 0x400000, 0); + + u32 num = 0; + while (totalSectorsVer > 0) + { + num = MIN(totalSectorsVer, NUM_SECTORS_PER_ITER); + + // Check every time or every 4. + // Every 4 protects from fake sd, sector corruption and frequent I/O corruption. + // Full provides all that, plus protection from extremely rare I/O corruption. + if ((h_cfg.verification >= 2) || !(sparseShouldVerify % 4)) + { + if (!sdmmc_storage_read(storage, lba_curr, num, bufEm)) + { + s_printf(gui->txt_buf, + "#FF0000 Failed to read %d blocks (@LBA %08X),#\n" + "#FF0000 from eMMC! Verification failed..#\n", + num, lba_curr); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + free(clmt); + f_close(&fp); + if (h_cfg.verification == 3) + f_close(&hashFp); + + return 1; + } + f_lseek(&fp, (u64)sdFileSector << (u64)9); + if (f_read_fast(&fp, bufSd, num << 9)) + { + s_printf(gui->txt_buf, + "#FF0000 Failed to read %d blocks (@LBA %08X),#\n" + "#FF0000 from SD card! Verification failed..#\n", + num, lba_curr); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + free(clmt); + f_close(&fp); + if (h_cfg.verification == 3) + f_close(&hashFp); + + return 1; + } + + se_calc_sha256(hashEm, bufEm, num << 9); + se_calc_sha256(hashSd, bufSd, num << 9); + res = memcmp(hashEm, hashSd, 0x10); + + if (res) + { + s_printf(gui->txt_buf, + "#FF0000 SD & eMMC data (@LBA %08X) do not match!#\n" + "#FF0000 \nVerification failed..#\n", + lba_curr); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + free(clmt); + f_close(&fp); + if (h_cfg.verification == 3) + f_close(&hashFp); + + return 1; + } + + if (h_cfg.verification == 3) + { + // Transform computed hash to readable hexadecimal + char hashStr[SHA256_SZ * 2 + 1]; + char *hashStrPtr = hashStr; + for (int i = 0; i < SHA256_SZ; i++) + { + *(hashStrPtr++) = hexa[hashSd[i] >> 4]; + *(hashStrPtr++) = hexa[hashSd[i] & 0x0F]; + } + hashStr[SHA256_SZ * 2] = '\0'; + + f_puts(hashStr, &hashFp); + f_puts("\n", &hashFp); + } + } + + pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); + if (pct != prevPct) + { + lv_bar_set_value(gui->bar, pct); + s_printf(gui->txt_buf, " "SYMBOL_DOT" %d%%", pct); + lv_label_set_text(gui->label_pct, gui->txt_buf); + manual_system_maintenance(true); + prevPct = pct; + } + + lba_curr += num; + totalSectorsVer -= num; + sdFileSector += num; + sparseShouldVerify++; + + btn = btn_wait_timeout(0, BTN_VOL_DOWN | BTN_VOL_UP); + if ((btn & BTN_VOL_DOWN) && (btn & BTN_VOL_UP)) + { + s_printf(gui->txt_buf, "#FFDD00 Verification was cancelled!#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + msleep(1000); + + free(clmt); + f_close(&fp); + f_close(&hashFp); + + return 0; + } + } + free(clmt); + f_close(&fp); + f_close(&hashFp); + + lv_bar_set_value(gui->bar, pct); + s_printf(gui->txt_buf, " "SYMBOL_DOT" %d%%", pct); + lv_label_set_text(gui->label_pct, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + else + { + s_printf(gui->txt_buf, "#FFDD00 File not found or could not be loaded!#\n#FFDD00 Verification failed..#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 1; + } +} + +static void _update_filename(char *outFilename, u32 sdPathLen, u32 numSplitParts, u32 currPartIdx) +{ + if (numSplitParts >= 10 && currPartIdx < 10) + { + outFilename[sdPathLen] = '0'; + itoa(currPartIdx, &outFilename[sdPathLen + 1], 10); + } + else + itoa(currPartIdx, &outFilename[sdPathLen], 10); +} + +#pragma GCC pop_options + +bool partial_sd_full_unmount = false; + +static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part) +{ + const u32 FAT32_FILESIZE_LIMIT = 0xFFFFFFFF; + const u32 SECTORS_TO_MIB_COEFF = 11; + + partial_sd_full_unmount = false; + + u32 multipartSplitSize = (1u << 31); + u32 totalSectors = part->lba_end - part->lba_start + 1; + u32 currPartIdx = 0; + u32 numSplitParts = 0; + u32 maxSplitParts = 0; + u32 btn = 0; + bool isSmallSdCard = false; + bool partialDumpInProgress = false; + int res = 0; + char *outFilename = sd_path; + u32 sdPathLen = strlen(sd_path); + + FIL partialIdxFp; + char partialIdxFilename[12]; + memcpy(partialIdxFilename, "partial.idx", 12); + + s_printf(gui->txt_buf, "#96FF00 SD Card free space:# %d MiB\n#96FF00 Total backup size:# %d MiB\n\n", + sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF, + totalSectors >> SECTORS_TO_MIB_COEFF); + lv_label_ins_text(gui->label_info, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + lv_bar_set_value(gui->bar, 0); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 0%"); + lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, lv_theme_get_current()->bar.bg); + lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, gui->bar_white_ind); + manual_system_maintenance(true); + + // 1GB parts for sd cards 8GB and less. + if ((sd_storage.csd.capacity >> (20 - sd_storage.csd.read_blkbits)) <= 8192) + multipartSplitSize = (1u << 30); + // Maximum parts fitting the free space available. + maxSplitParts = (sd_fs.free_clst * sd_fs.csize) / (multipartSplitSize / NX_EMMC_BLOCKSIZE); + + // Check if the USER partition or the RAW eMMC fits the sd card free space. + if (totalSectors > (sd_fs.free_clst * sd_fs.csize)) + { + isSmallSdCard = true; + + s_printf(gui->txt_buf, "\n#FFBA00 Free space is smaller than backup size.#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + if (!maxSplitParts) + { + s_printf(gui->txt_buf, "#FFDD00 Not enough free space for Partial Backup!#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + } + // Check if we are continuing a previous raw eMMC or USER partition backup in progress. + if (f_open(&partialIdxFp, partialIdxFilename, FA_READ) == FR_OK && totalSectors > (FAT32_FILESIZE_LIMIT / NX_EMMC_BLOCKSIZE)) + { + s_printf(gui->txt_buf, "\n#AEFD14 Partial Backup in progress. Continuing...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + partialDumpInProgress = true; + // Force partial dumping, even if the card is larger. + isSmallSdCard = true; + + f_read(&partialIdxFp, &currPartIdx, 4, NULL); + f_close(&partialIdxFp); + + if (!maxSplitParts) + { + s_printf(gui->txt_buf, "#FFDD00 Not enough free space for Partial Backup!#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + + // Increase maxSplitParts to accommodate previously backed up parts. + maxSplitParts += currPartIdx; + } + else if (isSmallSdCard) + { + s_printf(gui->txt_buf, "\n#FFBA00 Partial Backup enabled (%d MiB parts)...#\n", multipartSplitSize >> 20); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + + // Check if filesystem is FAT32 or the free space is smaller and backup in parts. + if (((sd_fs.fs_type != FS_EXFAT) && totalSectors > (FAT32_FILESIZE_LIMIT / NX_EMMC_BLOCKSIZE)) || isSmallSdCard) + { + u32 multipartSplitSectors = multipartSplitSize / NX_EMMC_BLOCKSIZE; + numSplitParts = (totalSectors + multipartSplitSectors - 1) / multipartSplitSectors; + + outFilename[sdPathLen++] = '.'; + + // Continue from where we left, if Partial Backup in progress. + _update_filename(outFilename, sdPathLen, numSplitParts, partialDumpInProgress ? currPartIdx : 0); + } + + FIL fp; + if (!f_open(&fp, outFilename, FA_READ)) + { + f_close(&fp); + + lv_obj_t *warn_mbox_bg = create_mbox_text( + "#FFDD00 An existing backup has been detected!#\n\n" + "Press #FF8000 POWER# to Continue.\nPress #FF8000 VOL# to abort.", false); + manual_system_maintenance(true); + + if (!(btn_wait() & BTN_POWER)) + { + lv_obj_del(warn_mbox_bg); + return 0; + } + lv_obj_del(warn_mbox_bg); + } + + s_printf(gui->txt_buf, "#96FF00 Filepath:#\n%s\n#96FF00 Filename:# #FF8000 %s#", + gui->base_path, outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + res = f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE); + if (res) + { + s_printf(gui->txt_buf, "\n#FF0000 Error (%d) while creating#\n#FFDD00 %s#\n", res, outFilename); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + + u8 *buf = (u8 *)MIXD_BUF_ALIGNED; + + u32 lba_curr = part->lba_start; + u32 lbaStartPart = part->lba_start; + u32 bytesWritten = 0; + u32 prevPct = 200; + int retryCount = 0; + DWORD *clmt = NULL; + + // Continue from where we left, if Partial Backup in progress. + if (partialDumpInProgress) + { + lba_curr += currPartIdx * (multipartSplitSize / NX_EMMC_BLOCKSIZE); + totalSectors -= currPartIdx * (multipartSplitSize / NX_EMMC_BLOCKSIZE); + lbaStartPart = lba_curr; // Update the start LBA for verification. + } + u64 totalSize = (u64)((u64)totalSectors << 9); + if (!isSmallSdCard && (sd_fs.fs_type == FS_EXFAT || totalSize <= FAT32_FILESIZE_LIMIT)) + clmt = f_expand_cltbl(&fp, 0x400000, totalSize); + else + clmt = f_expand_cltbl(&fp, 0x400000, MIN(totalSize, multipartSplitSize)); + + u32 num = 0; + u32 pct = 0; + + lv_obj_set_opa_scale(gui->bar, LV_OPA_COVER); + lv_obj_set_opa_scale(gui->label_pct, LV_OPA_COVER); + while (totalSectors > 0) + { + if (numSplitParts != 0 && bytesWritten >= multipartSplitSize) + { + f_close(&fp); + free(clmt); + memset(&fp, 0, sizeof(fp)); + currPartIdx++; + + if (h_cfg.verification) + { + // Verify part. + if (_dump_emmc_verify(gui, storage, lbaStartPart, outFilename, part)) + { + s_printf(gui->txt_buf, "#FFDD00 Please try again...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, lv_theme_get_current()->bar.bg); + lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, gui->bar_white_ind); + } + + _update_filename(outFilename, sdPathLen, numSplitParts, currPartIdx); + + // Always create partial.idx before next part, in case a fatal error occurs. + if (isSmallSdCard) + { + // Create partial backup index file. + if (f_open(&partialIdxFp, partialIdxFilename, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) + { + f_write(&partialIdxFp, &currPartIdx, 4, NULL); + f_close(&partialIdxFp); + } + else + { + s_printf(gui->txt_buf, "#FF0000 Error creating partial.idx file!#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + + // More parts to backup that do not currently fit the sd card free space or fatal error. + if (currPartIdx >= maxSplitParts) + { + create_mbox_text( + "#96FF00 Partial Backup in progress!#\n\n" + "#96FF00 1.# Press OK to unmount SD Card.\n" + "#96FF00 2.# Remove SD Card and move files to free space.\n" + "#FFDD00 Don\'t move the partial.idx file!#\n" + "#96FF00 3.# Re-insert SD Card.\n" + "#96FF00 4.# Select the SAME option again to continue.", true); + + partial_sd_full_unmount = true; + + return 1; + } + } + + // Create next part. + s_printf(gui->txt_buf, "%s#", outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, + strlen(lv_label_get_text(gui->label_info)) - strlen(outFilename + strlen(gui->base_path) - 1), + gui->txt_buf); + lv_label_cut_text(gui->label_info, + strlen(lv_label_get_text(gui->label_info)) - strlen(outFilename + strlen(gui->base_path) - 1), + strlen(outFilename + strlen(gui->base_path)) + 1); + manual_system_maintenance(true); + lbaStartPart = lba_curr; + res = f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE); + if (res) + { + s_printf(gui->txt_buf, "#FF0000 Error (%d) while creating#\n#FFDD00 %s#\n", res, outFilename); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + + bytesWritten = 0; + + totalSize = (u64)((u64)totalSectors << 9); + clmt = f_expand_cltbl(&fp, 0x400000, MIN(totalSize, multipartSplitSize)); + } + + retryCount = 0; + num = MIN(totalSectors, NUM_SECTORS_PER_ITER); + while (!sdmmc_storage_read(storage, lba_curr, num, buf)) + { + s_printf(gui->txt_buf, + "#FFDD00 Error reading %d blocks @ LBA %08X,#\n" + "#FFDD00 from eMMC (try %d). #", + num, lba_curr, ++retryCount); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + msleep(150); + if (retryCount >= 3) + { + s_printf(gui->txt_buf, "#FF0000 Aborting...#\nPlease try again...\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + f_close(&fp); + free(clmt); + f_unlink(outFilename); + + return 0; + } + else + { + s_printf(gui->txt_buf, "#FFDD00 Retrying...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + } + + res = f_write_fast(&fp, buf, NX_EMMC_BLOCKSIZE * num); + + if (res) + { + s_printf(gui->txt_buf, "#FF0000 Fatal error (%d) when writing to SD Card#\nPlease try again...\n", res); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + f_close(&fp); + free(clmt); + f_unlink(outFilename); + + return 0; + } + pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); + if (pct != prevPct) + { + lv_bar_set_value(gui->bar, pct); + s_printf(gui->txt_buf, " "SYMBOL_DOT" %d%%", pct); + lv_label_set_text(gui->label_pct, gui->txt_buf); + manual_system_maintenance(true); + + prevPct = pct; + } + + lba_curr += num; + totalSectors -= num; + bytesWritten += num * NX_EMMC_BLOCKSIZE; + + // Force a flush after a lot of data if not splitting. + if (numSplitParts == 0 && bytesWritten >= multipartSplitSize) + { + f_sync(&fp); + bytesWritten = 0; + } + + btn = btn_wait_timeout(0, BTN_VOL_DOWN | BTN_VOL_UP); + if ((btn & BTN_VOL_DOWN) && (btn & BTN_VOL_UP)) + { + s_printf(gui->txt_buf, "\n#FFDD00 The backup was cancelled!\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + msleep(1500); + + f_close(&fp); + free(clmt); + f_unlink(outFilename); + + return 0; + } + } + lv_bar_set_value(gui->bar, 100); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%"); + manual_system_maintenance(true); + + // Backup operation ended successfully. + f_close(&fp); + free(clmt); + + if (h_cfg.verification) + { + // Verify last part or single file backup. + if (_dump_emmc_verify(gui, storage, lbaStartPart, outFilename, part)) + { + s_printf(gui->txt_buf, "\n#FFDD00 Please try again...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + lv_bar_set_value(gui->bar, 100); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%"); + manual_system_maintenance(true); + } + + // Remove partial backup index file if no fatal errors occurred. + if (isSmallSdCard) + { + f_unlink(partialIdxFilename); + + create_mbox_text( + "#96FF00 Partial Backup done!#\n\n" + "You can now join the files if needed\nand get the complete eMMC RAW GPP backup.", true); + + partial_sd_full_unmount = true; + } + + return 1; +} + +void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui) +{ + int res = 0; + u32 timer = 0; + //! TODO switch to 800MHz + manual_system_maintenance(true); + + char *txt_buf = (char *)malloc(0x1000); + gui->txt_buf = txt_buf; + s_printf(txt_buf, ""); + lv_label_set_array_text(gui->label_log, txt_buf, 0x1000); + + if (!sd_mount()) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Failed to init SD!#"); + goto out; + } + + lv_label_set_static_text(gui->label_info, "Checking for available free space..."); + manual_system_maintenance(true); + + // Get SD Card free space for Partial Backup. + f_getfree("", &sd_fs.free_clst, NULL); + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + if (!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4)) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Failed to init eMMC!#"); + goto out; + } + + int i = 0; + char sdPath[OUT_FILENAME_SZ]; + // Create Restore folders, if they do not exist. + emmcsn_path_impl(sdPath, "/restore", "", &storage); + emmcsn_path_impl(sdPath, "/restore/partitions", "", &storage); + emmcsn_path_impl(sdPath, "", "", &storage); + gui->base_path = (char *)malloc(strlen(sdPath) + 1); + strcpy(gui->base_path, sdPath); + + timer = get_tmr_s(); + if (dumpType & PART_BOOT) + { + const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17; + + emmc_part_t bootPart; + memset(&bootPart, 0, sizeof(bootPart)); + bootPart.lba_start = 0; + bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; + for (i = 0; i < 2; i++) + { + memcpy(bootPart.name, "BOOT", 5); + bootPart.name[4] = (u8)('0' + i); + bootPart.name[5] = 0; + + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n", + i, bootPart.name, bootPart.lba_start, bootPart.lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, bootPart.name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + sdmmc_storage_set_mmc_partition(&storage, i + 1); + + emmcsn_path_impl(sdPath, "", bootPart.name, &storage); + res = _dump_emmc_part(gui, sdPath, &storage, &bootPart); + + if (!res) + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + } + } + + if ((dumpType & PART_SYSTEM) || (dumpType & PART_USER) || (dumpType & PART_RAW)) + { + sdmmc_storage_set_mmc_partition(&storage, 0); + + if ((dumpType & PART_SYSTEM) || (dumpType & PART_USER)) + { + emmcsn_path_impl(sdPath, "/partitions", "", &storage); + gui->base_path = (char *)malloc(strlen(sdPath) + 1); + strcpy(gui->base_path, sdPath); + + LIST_INIT(gpt); + nx_emmc_gpt_parse(&gpt, &storage); + LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link) + { + if ((dumpType & PART_USER) == 0 && !strcmp(part->name, "USER")) + continue; + if ((dumpType & PART_SYSTEM) == 0 && strcmp(part->name, "USER")) + continue; + + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n", + i, part->name, part->lba_start, part->lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, part->name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + i++; + + emmcsn_path_impl(sdPath, "/partitions", part->name, &storage); + res = _dump_emmc_part(gui, sdPath, &storage, part); + // If a part failed, don't continue. + if (!res) + { + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + break; + } + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + } + nx_emmc_gpt_free(&gpt); + } + + if (dumpType & PART_RAW) + { + // Get GP partition size dynamically. + const u32 RAW_AREA_NUM_SECTORS = storage.sec_cnt; + + emmc_part_t rawPart; + memset(&rawPart, 0, sizeof(rawPart)); + rawPart.lba_start = 0; + rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1; + strcpy(rawPart.name, "rawnand.bin"); + { + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n", + i, rawPart.name, rawPart.lba_start, rawPart.lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, rawPart.name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + i++; + + emmcsn_path_impl(sdPath, "", rawPart.name, &storage); + res = _dump_emmc_part(gui, sdPath, &storage, &rawPart); + + if (!res) + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + } + } + } + + timer = get_tmr_s() - timer; + sdmmc_storage_end(&storage); + + if (res && h_cfg.verification) + s_printf(txt_buf, "Time taken: %dm %ds.\n#96FF00 Finished and verified!#", timer / 60, timer % 60); + else if (res) + s_printf(txt_buf, "Time taken: %dm %ds.\nFinished!", timer / 60, timer % 60); + else + s_printf(txt_buf, "Time taken: %dm %ds.", timer / 60, timer % 60); + + lv_label_set_array_text(gui->label_finish, txt_buf, 0x1000); + +out: + free(txt_buf); + free(gui->base_path); + if (!partial_sd_full_unmount) + sd_unmount(false); + else + sd_unmount(true); +} + +static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, sdmmc_storage_t *storage, emmc_part_t *part, bool allow_multi_part) +{ + const u32 SECTORS_TO_MIB_COEFF = 11; + //! TODO switch to 800MHz + u32 totalSectors = part->lba_end - part->lba_start + 1; + u32 currPartIdx = 0; + u32 numSplitParts = 0; + u32 lbaStartPart = part->lba_start; + int res = 0; + char *outFilename = sd_path; + u32 sdPathLen = strlen(sd_path); + u64 fileSize = 0; + u64 totalCheckFileSize = 0; + + FIL fp; + FILINFO fno; + + lv_bar_set_value(gui->bar, 0); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 0%"); + lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, lv_theme_get_current()->bar.bg); + lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, gui->bar_white_ind); + manual_system_maintenance(true); + + bool use_multipart = false; + + if (allow_multi_part) + { + // Check to see if there is a combined file and if so then use that. + if (f_stat(outFilename, &fno)) + { + // If not, check if there are partial files and the total size matches. + s_printf(gui->txt_buf, "\nNo single file, checking for part files...\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + outFilename[sdPathLen++] = '.'; + + _update_filename(outFilename, sdPathLen, 99, numSplitParts); + + s_printf(gui->txt_buf, "#96FF00 Filepath:#\n%s\n#96FF00 Filename:# #FF8000 %s#", + gui->base_path, outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, LV_LABEL_POS_LAST, gui->txt_buf); + + // Stat total size of the part files. + while ((u32)((u64)totalCheckFileSize >> (u64)9) != totalSectors) + { + _update_filename(outFilename, sdPathLen, 99, numSplitParts); + + s_printf(gui->txt_buf, "%s#", outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, + strlen(lv_label_get_text(gui->label_info)) - strlen(outFilename + strlen(gui->base_path)) - 1, + gui->txt_buf); + lv_label_cut_text(gui->label_info, + strlen(lv_label_get_text(gui->label_info)) - strlen(outFilename + strlen(gui->base_path)) - 1, + strlen(outFilename + strlen(gui->base_path)) + 1); + manual_system_maintenance(true); + + if (f_stat(outFilename, &fno) && !gui->raw_emummc) + { + s_printf(gui->txt_buf, "#FFDD00 Error (%d) file not found '%s'. Aborting...#\n", res, outFilename); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + else if (f_stat(outFilename, &fno) && gui->raw_emummc) + { + totalSectors = (u32)((u64)totalCheckFileSize >> (u64)9); + } + else + totalCheckFileSize += (u64)fno.fsize; + + numSplitParts++; + } + + s_printf(gui->txt_buf, "%X sectors total.\n", (u32)((u64)totalCheckFileSize >> (u64)9)); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + if ((u32)((u64)totalCheckFileSize >> (u64)9) != totalSectors) + { + s_printf(gui->txt_buf, "#FF0000 Size of SD Card split backup does not match,#\n#FF0000 eMMC's selected part size!#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + else + { + use_multipart = true; + _update_filename(outFilename, sdPathLen, numSplitParts, 0); + } + } + } + + res = f_open(&fp, outFilename, FA_READ); + if (use_multipart) + { + s_printf(gui->txt_buf, "%s#", outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, + strlen(lv_label_get_text(gui->label_info)) - strlen(outFilename + strlen(gui->base_path)) - 1, + gui->txt_buf); + lv_label_cut_text(gui->label_info, + strlen(lv_label_get_text(gui->label_info)) - strlen(outFilename + strlen(gui->base_path)) - 1, + strlen(outFilename + strlen(gui->base_path)) + 1); + manual_system_maintenance(true); + } + else + { + s_printf(gui->txt_buf, "#96FF00 Filepath:#\n%s\n#96FF00 Filename:# #FF8000 %s#", + gui->base_path, outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, LV_LABEL_POS_LAST, gui->txt_buf); + } + manual_system_maintenance(true); + if (res) + { + if (res != FR_NO_FILE) + { + s_printf(gui->txt_buf, "\n#FF0000 Error (%d) while opening file. Continuing...#\n", res); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + else + { + s_printf(gui->txt_buf, "\n#FFDD00 Error (%d) file not found. Continuing...#\n", res); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + + return 0; + } + else if (!use_multipart && (((u32)((u64)f_size(&fp) >> (u64)9)) != totalSectors)) // Check total restore size vs emmc size. + { + if (!gui->raw_emummc) + { + s_printf(gui->txt_buf, "\n#FF0000 Size of the SD Card backup does not match,#\n#FF0000 eMMC's selected part size.#\n", res); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + f_close(&fp); + + return 0; + } + else + totalSectors = (u32)((u64)f_size(&fp) >> (u64)9); + } + else + { + fileSize = (u64)f_size(&fp); + s_printf(gui->txt_buf, "\nTotal restore size: %d MiB.\n", + (u32)((use_multipart ? (u64)totalCheckFileSize : fileSize) >> (u64)9) >> SECTORS_TO_MIB_COEFF); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + + u8 *buf = (u8 *)MIXD_BUF_ALIGNED; + + u32 lba_curr = part->lba_start; + u32 bytesWritten = 0; + u32 prevPct = 200; + int retryCount = 0; + + u32 num = 0; + u32 pct = 0; + + DWORD *clmt = f_expand_cltbl(&fp, 0x400000, 0); + + u32 sector_start = 0, part_idx = 0; + u32 sector_size = totalSectors; + u32 sd_sector_off = 0; + + if (gui->raw_emummc) + { + get_valid_partition(§or_start, §or_size, &part_idx, false); + if (!part_idx) + { + s_printf(gui->txt_buf, "#FFDD00 Failed to find a partition...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + sd_sector_off = sector_start + (0x2000 * active_part); + } + + lv_obj_set_opa_scale(gui->bar, LV_OPA_COVER); + lv_obj_set_opa_scale(gui->label_pct, LV_OPA_COVER); + while (totalSectors > 0) + { + // If we have more than one part, check the size for the split parts and make sure that the bytes written is not more than that. + if (numSplitParts != 0 && bytesWritten >= fileSize) + { + // If we have more bytes written then close the file pointer and increase the part index we are using + f_close(&fp); + free(clmt); + memset(&fp, 0, sizeof(fp)); + currPartIdx++; + + if (h_cfg.verification && !gui->raw_emummc) + { + // Verify part. + if (_dump_emmc_verify(gui, storage, lbaStartPart, outFilename, part)) + { + s_printf(gui->txt_buf, "#FFDD00 Please try again...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + } + + _update_filename(outFilename, sdPathLen, numSplitParts, currPartIdx); + + // Read from next part. + s_printf(gui->txt_buf, "%s#", outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, + strlen(lv_label_get_text(gui->label_info)) - strlen(outFilename + strlen(gui->base_path)) - 1, + gui->txt_buf); + lv_label_cut_text(gui->label_info, + strlen(lv_label_get_text(gui->label_info)) - strlen(outFilename + strlen(gui->base_path)) - 1, + strlen(outFilename + strlen(gui->base_path)) + 1); + manual_system_maintenance(true); + + lbaStartPart = lba_curr; + + // Try to open the next file part + res = f_open(&fp, outFilename, FA_READ); + if (res) + { + s_printf(gui->txt_buf, "#FF0000 Error (%d) while opening file#\n#FFDD00 %s!#\n", res, outFilename); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + fileSize = (u64)f_size(&fp); + bytesWritten = 0; + clmt = f_expand_cltbl(&fp, 0x400000, 0); + } + + retryCount = 0; + num = MIN(totalSectors, NUM_SECTORS_PER_ITER); + + res = f_read_fast(&fp, buf, num << 9); + + if (res) + { + s_printf(gui->txt_buf, + "\n#FF0000 Fatal error (%d) when reading from SD!#\n" + "#FF0000 Your device may be in an inoperative state!#\n" + "#FFDD00 Please try again now!#\n", res); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + f_close(&fp); + free(clmt); + return 0; + } + if (!gui->raw_emummc) + res = !sdmmc_storage_write(storage, lba_curr, num, buf); + else + res = !sdmmc_storage_write(&sd_storage, lba_curr + sd_sector_off, num, buf); + while (res) + { + s_printf(gui->txt_buf, + "#FFDD00 Error reading %d blocks @ LBA %08X,#\n" + "#FFDD00 from eMMC (try %d). #", + num, lba_curr, ++retryCount); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + msleep(150); + if (retryCount >= 3) + { + s_printf(gui->txt_buf, "#FF0000 Aborting...#\n" + "#FF0000 Your device may be in an inoperative state!#\n" + "#FFDD00 Please try again now!#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + f_close(&fp); + free(clmt); + return 0; + } + else + { + s_printf(gui->txt_buf, "#FFDD00 Retrying...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + if (!gui->raw_emummc) + res = !sdmmc_storage_write(storage, lba_curr, num, buf); + else + res = !sdmmc_storage_write(&sd_storage, lba_curr + sd_sector_off, num, buf); + } + pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); + if (pct != prevPct) + {; + lv_bar_set_value(gui->bar, pct); + s_printf(gui->txt_buf, " "SYMBOL_DOT" %d%%", pct); + lv_label_set_text(gui->label_pct, gui->txt_buf); + manual_system_maintenance(true); + prevPct = pct; + } + + lba_curr += num; + totalSectors -= num; + bytesWritten += num * NX_EMMC_BLOCKSIZE; + } + lv_bar_set_value(gui->bar, 100); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%"); + manual_system_maintenance(true); + + // Restore operation ended successfully. + f_close(&fp); + free(clmt); + + if (h_cfg.verification && !gui->raw_emummc) + { + // Verify restored data. + if (_dump_emmc_verify(gui, storage, lbaStartPart, outFilename, part)) + { + s_printf(gui->txt_buf, "#FFDD00 Please try again...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + lv_bar_set_value(gui->bar, 100); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%"); + manual_system_maintenance(true); + } + + if (gui->raw_emummc) + { + char sdPath[OUT_FILENAME_SZ]; + // Create Restore folders, if they do not exist. + f_mkdir("emuMMC"); + s_printf(sdPath, "emuMMC/RAW%d", part_idx); + f_mkdir(sdPath); + strcat(sdPath, "/raw_based"); + FIL fp_raw; + f_open(&fp_raw, sdPath, FA_CREATE_ALWAYS | FA_WRITE); + f_write(&fp_raw, §or_start, 4, NULL); + f_close(&fp_raw); + + s_printf(sdPath, "emuMMC/RAW%d", part_idx); + save_emummc_cfg(part_idx, sector_start, sdPath); + } + + return 1; +} + +void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui) +{ + int res = 0; + u32 timer = 0; + + //! TODO switch to 800MHz + manual_system_maintenance(true); + + char *txt_buf = (char *)malloc(0x1000); + gui->txt_buf = txt_buf; + s_printf(txt_buf, ""); + lv_label_set_array_text(gui->label_log, txt_buf, 0x1000); + + s_printf(txt_buf, + "#FFDD00 This may render your device inoperative!#\n\n" + "#FFDD00 Are you really sure?#"); + if ((restoreType & PART_BOOT) || (restoreType & PART_GP_ALL)) + { + s_printf(txt_buf + strlen(txt_buf), + "\n\nThe mode you selected will only restore\nthe partitions that it can find.\n" + "If it is not found, it will be skipped\nand continue with the next."); + } + + u32 orig_msg_len = strlen(txt_buf); + + lv_obj_t *warn_mbox_bg = create_mbox_text(txt_buf, false); + lv_obj_t *warn_mbox = lv_obj_get_child(warn_mbox_bg, NULL); + + u8 failsafe_wait = 6; + while (failsafe_wait > 0) + { + s_printf(txt_buf + orig_msg_len, "\n\n#888888 Wait... (%ds)#", failsafe_wait); + lv_mbox_set_text(warn_mbox, txt_buf); + msleep(1000); + manual_system_maintenance(true); + failsafe_wait--; + } + + s_printf(txt_buf + orig_msg_len, "\n\nPress #FF8000 POWER# to Continue.\nPress #FF8000 VOL# to abort."); + lv_mbox_set_text(warn_mbox, txt_buf); + manual_system_maintenance(true); + + u32 btn = btn_wait(); + if (!(btn & BTN_POWER)) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Restore operation was aborted!#"); + lv_obj_del(warn_mbox_bg); + goto out; + } + lv_obj_del(warn_mbox_bg); + manual_system_maintenance(true); + + if (!sd_mount()) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Failed to init SD!#"); + goto out; + } + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + if (!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4)) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Failed to init eMMC!#"); + goto out; + } + + int i = 0; + char sdPath[OUT_FILENAME_SZ]; + + emmcsn_path_impl(sdPath, "/restore", "", &storage); + gui->base_path = (char *)malloc(strlen(sdPath) + 1); + strcpy(gui->base_path, sdPath); + + timer = get_tmr_s(); + if (restoreType & PART_BOOT) + { + const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17; + + emmc_part_t bootPart; + memset(&bootPart, 0, sizeof(bootPart)); + bootPart.lba_start = 0; + bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; + for (i = 0; i < 2; i++) + { + memcpy(bootPart.name, "BOOT", 4); + bootPart.name[4] = (u8)('0' + i); + bootPart.name[5] = 0; + + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n\n\n\n", + i, bootPart.name, bootPart.lba_start, bootPart.lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, bootPart.name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + sdmmc_storage_set_mmc_partition(&storage, i + 1); + + emmcsn_path_impl(sdPath, "/restore", bootPart.name, &storage); + res = _restore_emmc_part(gui, sdPath, i, &storage, &bootPart, false); + + if (!res) + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + } + } + + if (restoreType & PART_GP_ALL) + { + emmcsn_path_impl(sdPath, "/restore/partitions", "", &storage); + gui->base_path = (char *)malloc(strlen(sdPath) + 1); + strcpy(gui->base_path, sdPath); + + sdmmc_storage_set_mmc_partition(&storage, 0); + + LIST_INIT(gpt); + nx_emmc_gpt_parse(&gpt, &storage); + LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link) + { + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n\n\n\n", + i, part->name, part->lba_start, part->lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, part->name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + i++; + + emmcsn_path_impl(sdPath, "/restore/partitions", part->name, &storage); + res = _restore_emmc_part(gui, sdPath, 0, &storage, part, false); + + if (!res) + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + } + nx_emmc_gpt_free(&gpt); + } + + if (restoreType & PART_RAW) + { + // Get GP partition size dynamically. + const u32 RAW_AREA_NUM_SECTORS = storage.sec_cnt; + + emmc_part_t rawPart; + memset(&rawPart, 0, sizeof(rawPart)); + rawPart.lba_start = 0; + rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1; + strcpy(rawPart.name, "rawnand.bin"); + { + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n\n\n\n", + i, rawPart.name, rawPart.lba_start, rawPart.lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, rawPart.name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + i++; + + emmcsn_path_impl(sdPath, "/restore", rawPart.name, &storage); + res = _restore_emmc_part(gui, sdPath, 2, &storage, &rawPart, true); + + if (!res) + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + } + } + + timer = get_tmr_s() - timer; + sdmmc_storage_end(&storage); + + if (res && h_cfg.verification) + s_printf(txt_buf, "Time taken: %dm %ds.\n#96FF00 Finished and verified!#", timer / 60, timer % 60); + else if (res) + s_printf(txt_buf, "Time taken: %dm %ds.\nFinished!", timer / 60, timer % 60); + else + s_printf(txt_buf, "Time taken: %dm %ds.", timer / 60, timer % 60); + + lv_label_set_array_text(gui->label_finish, txt_buf, 0x1000); + +out: + free(txt_buf); + free(gui->base_path); + sd_unmount(false); +} diff --git a/nyx/nyx_gui/frontend/fe_emmc_tools.h b/nyx/nyx_gui/frontend/fe_emmc_tools.h new file mode 100644 index 0000000..146472d --- /dev/null +++ b/nyx/nyx_gui/frontend/fe_emmc_tools.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018 Rajko Stojadinovic + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _FE_EMMC_TOOLS_H_ +#define _FE_EMMC_TOOLS_H_ + +#include "gui.h" + +typedef enum +{ + PART_BOOT = (1 << 0), + PART_SYSTEM = (1 << 1), + PART_USER = (1 << 2), + PART_RAW = (1 << 3), + PART_GP_ALL = (1 << 7) +} emmcPartType_t; + +void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui); +void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui); + +#endif diff --git a/nyx/nyx_gui/frontend/fe_emummc_tools.c b/nyx/nyx_gui/frontend/fe_emummc_tools.c new file mode 100644 index 0000000..f83fa14 --- /dev/null +++ b/nyx/nyx_gui/frontend/fe_emummc_tools.c @@ -0,0 +1,703 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 Rajko Stojadinovic + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +//! fix the dram stuff and the pop ups + +#include +#include + +#include "gui.h" +#include "fe_emummc_tools.h" +#include "../config/config.h" +#include "../libs/fatfs/ff.h" +#include "../mem/heap.h" +#include "../sec/se.h" +#include "../storage/nx_emmc.h" +#include "../storage/sdmmc.h" +#include "../utils/sprintf.h" +#include "../utils/util.h" + +#define EMMC_BUF_ALIGNED 0xB5000000 +#define SDXC_BUF_ALIGNED 0xB6000000 +#define MIXD_BUF_ALIGNED 0xB7000000 + +#define NUM_SECTORS_PER_ITER 8192 // 4MB Cache. +#define OUT_FILENAME_SZ 128 +#define SHA256_SZ 0x20 + +#define MBR_1ST_PART_TYPE_OFF 0x1C2 + +extern sdmmc_t sd_sdmmc; +extern sdmmc_storage_t sd_storage; +extern FATFS sd_fs; +extern hekate_config h_cfg; + +extern bool sd_mount(); +extern void sd_unmount(bool deinit); + +void save_emummc_cfg(u32 part_idx, u32 sector_start, const char *path) +{ + sd_mount(); + + char lbuf[16]; + FIL fp; + + if (f_open(&fp, "emuMMC/emummc.ini", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) + return; + + // Add config entry. + f_puts("[emummc]\nenabled=", &fp); + if (part_idx && sector_start) + { + itoa(part_idx, lbuf, 10); + f_puts(lbuf, &fp); + } + else if(path) + f_puts("1", &fp); + else + f_puts("0", &fp); + + if (!sector_start) + f_puts("\nsector=0x0", &fp); + else + { + f_puts("\nsector=0x", &fp); + itoa(sector_start, lbuf, 16); + f_puts(lbuf, &fp); + } + if (path) + { + f_puts("\npath=", &fp); + f_puts(path, &fp); + } + f_puts("\nid=0x0000", &fp); + f_puts("\nnintendo_path=", &fp); + if (path) + { + f_puts(path, &fp); + f_puts("/Nintendo\n", &fp); + } + else + f_puts("\n", &fp); + + f_close(&fp); +} + +static void _update_emummc_base_folder(char *outFilename, u32 sdPathLen, u32 currPartIdx) +{ + if (currPartIdx < 10) + { + outFilename[sdPathLen] = '0'; + itoa(currPartIdx, &outFilename[sdPathLen + 1], 10); + } + else + itoa(currPartIdx, &outFilename[sdPathLen], 10); +} + +static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part) +{ + static const u32 FAT32_FILESIZE_LIMIT = 0xFFFFFFFF; + static const u32 SECTORS_TO_MIB_COEFF = 11; + + u32 multipartSplitSize = 0xFE000000; + u32 totalSectors = part->lba_end - part->lba_start + 1; + u32 currPartIdx = 0; + u32 numSplitParts = 0; + int res = 0; + char *outFilename = sd_path; + u32 sdPathLen = strlen(sd_path); + + s_printf(gui->txt_buf, "#96FF00 SD Card free space:# %d MiB\n#96FF00 Total backup size:# %d MiB\n\n", + sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF, + totalSectors >> SECTORS_TO_MIB_COEFF); + lv_label_ins_text(gui->label_info, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + lv_bar_set_value(gui->bar, 0); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 0%"); + manual_system_maintenance(true); + + // Check if the USER partition or the RAW eMMC fits the sd card free space. + if (totalSectors > (sd_fs.free_clst * sd_fs.csize)) + { + s_printf(gui->txt_buf, "\n#FFDD00 Not enough free space for Partial Backup!#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + + // Check if filesystem is FAT32 or the free space is smaller and backup in parts. + if (totalSectors > (FAT32_FILESIZE_LIMIT / NX_EMMC_BLOCKSIZE)) + { + u32 multipartSplitSectors = multipartSplitSize / NX_EMMC_BLOCKSIZE; + numSplitParts = (totalSectors + multipartSplitSectors - 1) / multipartSplitSectors; + + // Continue from where we left, if Partial Backup in progress. + _update_emummc_base_folder(outFilename, sdPathLen, 0); + } + + FIL fp; + s_printf(gui->txt_buf, "#96FF00 Filepath:#\n%s\n#96FF00 Filename:# #FF8000 %s#", + gui->base_path, outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + res = f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE); + if (res) + { + s_printf(gui->txt_buf, "\n#FF0000 Error (%d) while creating#\n#FFDD00 %s#\n", res, outFilename); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + + u8 *buf = (u8 *)MIXD_BUF_ALIGNED; + + u32 lba_curr = part->lba_start; + u32 bytesWritten = 0; + u32 prevPct = 200; + int retryCount = 0; + DWORD *clmt = NULL; + + u64 totalSize = (u64)((u64)totalSectors << 9); + if (totalSize <= FAT32_FILESIZE_LIMIT) + clmt = f_expand_cltbl(&fp, 0x400000, totalSize); + else + clmt = f_expand_cltbl(&fp, 0x400000, MIN(totalSize, multipartSplitSize)); + + u32 num = 0; + u32 pct = 0; + + lv_obj_set_opa_scale(gui->bar, LV_OPA_COVER); + lv_obj_set_opa_scale(gui->label_pct, LV_OPA_COVER); + while (totalSectors > 0) + { + if (numSplitParts != 0 && bytesWritten >= multipartSplitSize) + { + f_close(&fp); + free(clmt); + memset(&fp, 0, sizeof(fp)); + currPartIdx++; + + _update_emummc_base_folder(outFilename, sdPathLen, currPartIdx); + + // Create next part. + s_printf(gui->txt_buf, "%s#", outFilename + strlen(gui->base_path)); + lv_label_ins_text(gui->label_info, strlen(lv_label_get_text(gui->label_info)) - 3, gui->txt_buf); + lv_label_cut_text(gui->label_info, strlen(lv_label_get_text(gui->label_info)) - 3, 3); + manual_system_maintenance(true); + + res = f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE); + if (res) + { + s_printf(gui->txt_buf, "#FF0000 Error (%d) while creating#\n#FFDD00 %s#\n", res, outFilename); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + + bytesWritten = 0; + + totalSize = (u64)((u64)totalSectors << 9); + clmt = f_expand_cltbl(&fp, 0x400000, MIN(totalSize, multipartSplitSize)); + } + + retryCount = 0; + num = MIN(totalSectors, NUM_SECTORS_PER_ITER); + while (!sdmmc_storage_read(storage, lba_curr, num, buf)) + { + s_printf(gui->txt_buf, + "#FFDD00 Error reading %d blocks @ LBA %08X,#\n" + "#FFDD00 from eMMC (try %d). #", + num, lba_curr, ++retryCount); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + msleep(150); + if (retryCount >= 3) + { + s_printf(gui->txt_buf, "#FF0000 Aborting...#\nPlease try again...\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + f_close(&fp); + free(clmt); + f_unlink(outFilename); + + return 0; + } + else + { + s_printf(gui->txt_buf, "#FFDD00 Retrying...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + } + res = f_write_fast(&fp, buf, NX_EMMC_BLOCKSIZE * num); + + if (res) + { + s_printf(gui->txt_buf, "#FF0000 Fatal error (%d) when writing to SD Card#\nPlease try again...\n", res); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + f_close(&fp); + free(clmt); + f_unlink(outFilename); + + return 0; + } + pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); + if (pct != prevPct) + { + lv_bar_set_value(gui->bar, pct); + s_printf(gui->txt_buf, " "SYMBOL_DOT" %d%%", pct); + lv_label_set_text(gui->label_pct, gui->txt_buf); + manual_system_maintenance(true); + + prevPct = pct; + } + + lba_curr += num; + totalSectors -= num; + bytesWritten += num * NX_EMMC_BLOCKSIZE; + + // Force a flush after a lot of data if not splitting. + if (numSplitParts == 0 && bytesWritten >= multipartSplitSize) + { + f_sync(&fp); + bytesWritten = 0; + } + } + lv_bar_set_value(gui->bar, 100); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%"); + manual_system_maintenance(true); + + // Backup operation ended successfully. + f_close(&fp); + free(clmt); + + return 1; +} + +void dump_emummc_file(emmc_tool_gui_t *gui) +{ + FILINFO fno; + int res = 0; + int base_len = 0; + u32 timer = 0; + //! TODO switch to 800MHz + manual_system_maintenance(true); + + char *txt_buf = (char *)malloc(0x1000); + gui->txt_buf = txt_buf; + s_printf(txt_buf, ""); + lv_label_set_array_text(gui->label_log, txt_buf, 0x1000); + + if (!sd_mount()) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Failed to init SD!#"); + goto out; + } + + lv_label_set_static_text(gui->label_info, "Checking for available free space..."); + manual_system_maintenance(true); + + // Get SD Card free space for Partial Backup. + f_getfree("", &sd_fs.free_clst, NULL); + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + if (!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4)) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Failed to init eMMC!#"); + goto out; + } + + int i = 0; + char sdPath[OUT_FILENAME_SZ]; + // Create Restore folders, if they do not exist. + f_mkdir("emuMMC"); + strcpy(sdPath, "emuMMC/SD"); + base_len = strlen(sdPath); + gui->base_path = (char *)malloc(OUT_FILENAME_SZ); + + for (int j = 0; j < 100; j++) + { + _update_emummc_base_folder(sdPath, base_len, j); + if(f_stat(sdPath, &fno) == FR_NO_FILE) + break; + } + + f_mkdir(sdPath); + strcat(sdPath, "/eMMC"); + f_mkdir(sdPath); + strcat(sdPath, "/"); + strcpy(gui->base_path, sdPath); + + timer = get_tmr_s(); + const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17; + + emmc_part_t bootPart; + memset(&bootPart, 0, sizeof(bootPart)); + bootPart.lba_start = 0; + bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; + for (i = 0; i < 2; i++) + { + memcpy(bootPart.name, "BOOT", 5); + bootPart.name[4] = (u8)('0' + i); + bootPart.name[5] = 0; + + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n", + i, bootPart.name, bootPart.lba_start, bootPart.lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, bootPart.name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + sdmmc_storage_set_mmc_partition(&storage, i + 1); + + strcat(sdPath, bootPart.name); + res = _dump_emummc_file_part(gui, sdPath, &storage, &bootPart); + + if (!res) + { + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + goto out_failed; + } + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + strcpy(sdPath, gui->base_path); + } + + // Get GP partition size dynamically. + sdmmc_storage_set_mmc_partition(&storage, 0); + + // Get GP partition size dynamically. + const u32 RAW_AREA_NUM_SECTORS = storage.sec_cnt; + + emmc_part_t rawPart; + memset(&rawPart, 0, sizeof(rawPart)); + rawPart.lba_start = 0; + rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1; + strcpy(rawPart.name, "GPP"); + { + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n", + i, rawPart.name, rawPart.lba_start, rawPart.lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, rawPart.name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + res = _dump_emummc_file_part(gui, sdPath, &storage, &rawPart); + + if (!res) + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + } + +out_failed: + timer = get_tmr_s() - timer; + sdmmc_storage_end(&storage); + + if (res) + { + s_printf(txt_buf, "Time taken: %dm %ds.\nFinished!", timer / 60, timer % 60); + gui->base_path[strlen(gui->base_path) - 5] = '\0'; + strcpy(sdPath, gui->base_path); + strcat(sdPath, "file_based"); + FIL fp; + f_open(&fp, sdPath, FA_CREATE_ALWAYS | FA_WRITE); + f_close(&fp); + + gui->base_path[strlen(gui->base_path) - 1] = 0; + save_emummc_cfg(0, 0, gui->base_path); + } + else + s_printf(txt_buf, "Time taken: %dm %ds.", timer / 60, timer % 60); + + lv_label_set_array_text(gui->label_finish, txt_buf, 0x1000); + +out: + free(txt_buf); + free(gui->base_path); + sd_unmount(false); +} + +static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part_idx, u32 sd_part_off, sdmmc_storage_t *storage, emmc_part_t *part) +{ + u32 totalSectors = part->lba_end - part->lba_start + 1; + + s_printf(gui->txt_buf, "\n\n\n"); + lv_label_ins_text(gui->label_info, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + lv_bar_set_value(gui->bar, 0); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 0%"); + manual_system_maintenance(true); + + + s_printf(gui->txt_buf, "#96FF00 Base folder:#\n%s\n#96FF00 Partition offset:# #FF8000 0x%08X#", + gui->base_path, sd_part_off); + lv_label_ins_text(gui->label_info, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + u8 *buf = (u8 *)MIXD_BUF_ALIGNED; + u32 sd_sector_off = sd_part_off + (0x2000 * active_part); + u32 lba_curr = part->lba_start; + u32 prevPct = 200; + int retryCount = 0; + + u32 num = 0; + u32 pct = 0; + + lv_obj_set_opa_scale(gui->bar, LV_OPA_COVER); + lv_obj_set_opa_scale(gui->label_pct, LV_OPA_COVER); + + while (totalSectors > 0) + { + retryCount = 0; + num = MIN(totalSectors, NUM_SECTORS_PER_ITER); + + // Read data from eMMC. + while (!sdmmc_storage_read(storage, lba_curr, num, buf)) + { + s_printf(gui->txt_buf, + "#FFDD00 Error reading %d blocks @LBA %08X,#\n" + "#FFDD00 from eMMC (try %d). #", + num, lba_curr, ++retryCount); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + msleep(150); + if (retryCount >= 3) + { + s_printf(gui->txt_buf, "#FF0000 Aborting...#\nPlease try again...\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + else + { + s_printf(gui->txt_buf, "#FFDD00 Retrying...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + } + retryCount = 0; + + // Write data to SD card. + while (!sdmmc_storage_write(&sd_storage, sd_sector_off + lba_curr, num, buf)) + { + s_printf(gui->txt_buf, + "#FFDD00 Error writing %d blocks @LBA %08X,#\n" + "#FFDD00 to SD (try %d). #", + num, lba_curr, ++retryCount); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + msleep(150); + if (retryCount >= 3) + { + s_printf(gui->txt_buf, "#FF0000 Aborting...#\nPlease try again...\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + + return 0; + } + else + { + s_printf(gui->txt_buf, "#FFDD00 Retrying...#\n"); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); + manual_system_maintenance(true); + } + } + pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); + if (pct != prevPct) + { + lv_bar_set_value(gui->bar, pct); + s_printf(gui->txt_buf, " "SYMBOL_DOT" %d%%", pct); + lv_label_set_text(gui->label_pct, gui->txt_buf); + manual_system_maintenance(true); + + prevPct = pct; + } + + lba_curr += num; + totalSectors -= num; + } + lv_bar_set_value(gui->bar, 100); + lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%"); + manual_system_maintenance(true); + + // Hide the partition. + if (active_part == 2) + { + u8 *mbr = (u8 *)malloc(0x200); + sdmmc_storage_read(&sd_storage, 0, 1, mbr); + mbr[MBR_1ST_PART_TYPE_OFF + (0x10 * part_idx)] = 0xEE; + sdmmc_storage_write(&sd_storage, 0, 1, mbr); + free(mbr); + } + + return 1; +} + +void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start) +{ + int res = 0; + u32 timer = 0; + //! TODO switch to 800MHz + manual_system_maintenance(true); + + char *txt_buf = (char *)malloc(0x1000); + gui->txt_buf = txt_buf; + s_printf(txt_buf, ""); + lv_label_set_array_text(gui->label_log, txt_buf, 0x1000); + + if (!sd_mount()) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Failed to init SD!#"); + goto out; + } + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + if (!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4)) + { + lv_label_set_static_text(gui->label_info, "#FFDD00 Failed to init eMMC!#"); + goto out; + } + + int i = 0; + char sdPath[OUT_FILENAME_SZ]; + // Create Restore folders, if they do not exist. + f_mkdir("emuMMC"); + s_printf(sdPath, "emuMMC/RAW%d", part_idx); + gui->base_path = (char *)malloc(OUT_FILENAME_SZ); + f_mkdir(sdPath); + strcat(sdPath, "/"); + strcpy(gui->base_path, sdPath); + + timer = get_tmr_s(); + const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17; + + emmc_part_t bootPart; + memset(&bootPart, 0, sizeof(bootPart)); + bootPart.lba_start = 0; + bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; + for (i = 0; i < 2; i++) + { + memcpy(bootPart.name, "BOOT", 5); + bootPart.name[4] = (u8)('0' + i); + bootPart.name[5] = 0; + + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n", + i, bootPart.name, bootPart.lba_start, bootPart.lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, bootPart.name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + sdmmc_storage_set_mmc_partition(&storage, i + 1); + + strcat(sdPath, bootPart.name); + res = _dump_emummc_raw_part(gui, i, part_idx, sector_start, &storage, &bootPart); + + if (!res) + { + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + goto out_failed; + } + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + strcpy(sdPath, gui->base_path); + } + + sdmmc_storage_set_mmc_partition(&storage, 0); + + // Get GP partition size dynamically. + const u32 RAW_AREA_NUM_SECTORS = storage.sec_cnt; + + emmc_part_t rawPart; + memset(&rawPart, 0, sizeof(rawPart)); + rawPart.lba_start = 0; + rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1; + strcpy(rawPart.name, "GPP"); + { + s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n", + i, rawPart.name, rawPart.lba_start, rawPart.lba_end); + lv_label_set_array_text(gui->label_info, txt_buf, 0x1000); + s_printf(txt_buf, "%02d: %s... ", i, rawPart.name); + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + + res = _dump_emummc_raw_part(gui, 2, part_idx, sector_start, &storage, &rawPart); + + if (!res) + s_printf(txt_buf, "#FFDD00 Failed!#\n"); + else + s_printf(txt_buf, "Done!\n"); + + lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); + manual_system_maintenance(true); + } + +out_failed: + timer = get_tmr_s() - timer; + sdmmc_storage_end(&storage); + + if (res) + { + s_printf(txt_buf, "Time taken: %dm %ds.\nFinished!", timer / 60, timer % 60); + strcpy(sdPath, gui->base_path); + strcat(sdPath, "raw_based"); + FIL fp; + f_open(&fp, sdPath, FA_CREATE_ALWAYS | FA_WRITE); + f_write(&fp, §or_start, 4, NULL); + f_close(&fp); + + gui->base_path[strlen(gui->base_path) - 1] = 0; + save_emummc_cfg(part_idx, sector_start, gui->base_path); + } + else + s_printf(txt_buf, "Time taken: %dm %ds.", timer / 60, timer % 60); + + lv_label_set_array_text(gui->label_finish, txt_buf, 0x1000); + +out: + free(txt_buf); + free(gui->base_path); + sd_unmount(false); +} diff --git a/nyx/nyx_gui/frontend/fe_emummc_tools.h b/nyx/nyx_gui/frontend/fe_emummc_tools.h new file mode 100644 index 0000000..1685a42 --- /dev/null +++ b/nyx/nyx_gui/frontend/fe_emummc_tools.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018 Rajko Stojadinovic + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _FE_EMUMMC_TOOLS_H_ +#define _FE_EMUMMC_TOOLS_H_ + +#include "gui.h" + +void save_emummc_cfg(u32 part_idx, u32 sector_start, const char *path); +void dump_emummc_file(emmc_tool_gui_t *gui); +void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start); + +#endif diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c new file mode 100644 index 0000000..995082d --- /dev/null +++ b/nyx/nyx_gui/frontend/gui.c @@ -0,0 +1,2107 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "gui.h" +#include "gui_emummc_tools.h" +#include "gui_tools.h" +#include "gui_info.h" +#include "../libs/lvgl/lv_themes/lv_theme_hekate.h" +#include "../libs/lvgl/lvgl.h" +#include "../gfx/logos-gui.h" + +#include "../config/config.h" +#include "../config/ini.h" +#include "../gfx/di.h" +#include "../gfx/gfx.h" +#include "../input/touch.h" +#include "../libs/fatfs/ff.h" +#include "../mem/minerva.h" +#include "../power/bq24193.h" +#include "../power/max17050.h" +#include "../rtc/max77620-rtc.h" +#include "../soc/bpmp.h" +#include "../soc/hw_init.h" +#include "../soc/t210.h" +#include "../thermal/tmp451.h" +#include "../utils/dirlist.h" +#include "../utils/sprintf.h" +#include "../utils/types.h" +#include "../utils/util.h" + +extern hekate_config h_cfg; +extern volatile nyx_storage_t *nyx_str; +extern volatile boot_cfg_t *b_cfg; + +extern lv_res_t launch_payload(lv_obj_t *list); +extern bool get_sd_card_removed(); +extern bool sd_mount(); +extern void sd_unmount(bool deinit); +void *sd_file_read(const char *path, u32 *fsize); +int sd_save_to_file(void *buf, u32 size, const char *filename); + +static bool disp_init_done = false; + +typedef struct _gui_status_bar_ctx +{ + lv_obj_t *mid; + lv_obj_t *time_temp; + lv_obj_t *temp_symbol; + lv_obj_t *temp_degrees; + lv_obj_t *battery; + lv_obj_t *battery_more; +} gui_status_bar_ctx; + +static gui_status_bar_ctx status_bar; + +static void _nyx_disp_init() +{ + display_backlight_brightness(0, 1000); + display_init_framebuffer(); + display_backlight_brightness(h_cfg.backlight - 20, 1000); +} + +static void _save_fb_to_bmp() +{ + const u32 file_size = 0x384000 + 0x36; + u8 *bitmap = malloc(file_size); + u32 *fb = malloc(0x384000); + u32 *fb_ptr = gfx_ctxt.fb; + + // Reconstruct FB for bottom-top, landscape bmp. + for (u32 x = 0; x < 1280; x++) + { + for (int y = 719; y > -1; y--) + fb[y * 1280 + x] = *fb_ptr++; + } + + // Create notification box. + lv_obj_t * mbox = lv_mbox_create(lv_layer_top(), NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_mbox_set_text(mbox, SYMBOL_CAMERA" #FFDD00 Saving screenshot...#"); + lv_obj_set_width(mbox, LV_DPI * 4); + lv_obj_set_top(mbox, true); + lv_obj_align(mbox, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + manual_system_maintenance(true); + + memcpy(bitmap + 0x36, fb, 0x384000); + + typedef struct _bmp_t + { + u16 magic; + u32 size; + u32 rsvd; + u32 data_off; + u32 hdr_size; + u32 width; + u32 height; + u16 planes; + u16 pxl_bits; + u32 comp; + u32 img_size; + u32 res_h; + u32 res_v; + u64 rsvd2; + } __attribute__((packed)) bmp_t; + + bmp_t *bmp = (bmp_t *)bitmap; + + bmp->magic = 0x4D42; + bmp->size = file_size; + bmp->rsvd = 0; + bmp->data_off = 0x36; + bmp->hdr_size = 40; + bmp->width = 1280; + bmp->height = 720; + bmp->planes = 1; + bmp->pxl_bits = 32; + bmp->comp = 0; + bmp->img_size = 0x384000; + bmp->res_h = 2834; + bmp->res_v = 2834; + bmp->rsvd2 = 0; + + sd_mount(); + + char path[0x80]; + + strcpy(path, "bootloader/screenshots"); + f_mkdir(path); + s_printf(path + strlen(path), "/screen_%08X.bmp", get_tmr_us()); + sd_save_to_file(bitmap, file_size, path); + sd_unmount(false); + + free(bitmap); + free(fb); + + lv_mbox_set_text(mbox, SYMBOL_CAMERA" #96FF00 Screenshot saved!#"); + manual_system_maintenance(true); + lv_mbox_start_auto_close(mbox, 4000); +} + +static void _disp_fb_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t *color_p) +{ + // Draw to framebuffer. + gfx_set_rect_land_pitch(gfx_ctxt.fb, (u32 *)color_p, x1, y1, x2, y2); //pitch + + // Check if display init was done. If it's the first big draw, init. + if (!disp_init_done && ((x2 - x1 + 1) > 600)) + { + disp_init_done = true; + _nyx_disp_init(); + } + + lv_flush_ready(); +} + +touch_event touchpad; + +static bool _fts_touch_read(lv_indev_data_t *data) +{ + touch_poll(&touchpad); + + if (touchpad.fingers > 2) + _save_fb_to_bmp(); + + switch (touchpad.type & STMFTS_MASK_EVENT_ID) + { + case STMFTS_EV_MULTI_TOUCH_ENTER: + case STMFTS_EV_MULTI_TOUCH_MOTION: + data->state = LV_INDEV_STATE_PR; + data->point.x = touchpad.x; + data->point.y = touchpad.y; + break; + case STMFTS_EV_MULTI_TOUCH_LEAVE: + data->state = LV_INDEV_STATE_REL; + data->point.x = touchpad.x; + data->point.y = touchpad.y; + break; + case STMFTS_EV_NO_EVENT: + default: + if (touchpad.touch) + { + data->state = LV_INDEV_STATE_PR; + } + else + { + data->point.x = touchpad.x; + data->point.y = touchpad.y; + data->state = LV_INDEV_STATE_REL; + //return true; + } + break; + } + + return false; // No buffering so no more data read. +} + +typedef struct _system_maintenance_tasks_t +{ + union + { + lv_task_t *tasks[2]; + struct + { + lv_task_t *status_bar; + lv_task_t *dram_periodic_comp; + } task; + }; +} system_maintenance_tasks_t; + +static system_maintenance_tasks_t system_tasks; + +void manual_system_maintenance(bool refresh) +{ + for (u32 task_idx = 0; task_idx < (sizeof(system_maintenance_tasks_t) / sizeof(lv_task_t *)); task_idx++) + { + lv_task_t *task = system_tasks.tasks[task_idx]; + if(task && (lv_tick_elaps(task->last_run) >= task->period)) + { + task->last_run = lv_tick_get(); + task->task(task->param); + } + } + if (refresh) + lv_refr_now(); +} + +lv_img_dsc_t *bmp_to_lvimg_obj(const char *path) +{ + u8 *bitmap = sd_file_read(path, NULL); + if (!bitmap) + return NULL; + + struct _bmp_data + { + u32 size; + u32 size_x; + u32 size_y; + u32 offset; + }; + + struct _bmp_data bmpData; + + // Get values manually to avoid unaligned access. + bmpData.size = bitmap[2] | bitmap[3] << 8 | + bitmap[4] << 16 | bitmap[5] << 24; + bmpData.offset = bitmap[10] | bitmap[11] << 8 | + bitmap[12] << 16 | bitmap[13] << 24; + bmpData.size_x = bitmap[18] | bitmap[19] << 8 | + bitmap[20] << 16 | bitmap[21] << 24; + bmpData.size_y = bitmap[22] | bitmap[23] << 8 | + bitmap[24] << 16 | bitmap[25] << 24; + // Sanity check. + if (bitmap[0] == 'B' && + bitmap[1] == 'M' && + bitmap[28] == 32) // Only 32 bit BMPs allowed. + { + // Check if non-default Bottom-Top. + bool flipped = false; + if (bmpData.size_y & 0x80000000) + { + bmpData.size_y = ~(bmpData.size_y) + 1; + flipped = true; + } + + lv_img_dsc_t *img_desc = (lv_img_dsc_t *)bitmap; + u32 offset_copy = ALIGN((u32)bitmap + sizeof(lv_img_dsc_t), 0x10); + + img_desc->header.always_zero = 0; + img_desc->header.w = bmpData.size_x; + img_desc->header.h = bmpData.size_y; + img_desc->header.cf = (bitmap[28] == 32) ? LV_IMG_CF_TRUE_COLOR_ALPHA : LV_IMG_CF_TRUE_COLOR; + img_desc->data_size = bmpData.size - bmpData.offset; + img_desc->data = (u8 *)offset_copy; + + u32 *tmp = malloc(bmpData.size); + u32 *tmp2 = (u32 *)offset_copy; + + // Copy the unaligned data to an aligned buffer. + memcpy((u8 *)tmp, bitmap + bmpData.offset, img_desc->data_size); + u32 j = 0; + + if (!flipped) + { + for (u32 y = 0; y < bmpData.size_y; y++) + { + for (u32 x = 0; x < bmpData.size_x; x++) + tmp2[j++] = tmp[(bmpData.size_y - 1 - y ) * bmpData.size_x + x]; + } + } + else + { + for (u32 y = 0; y < bmpData.size_y; y++) + { + for (u32 x = 0; x < bmpData.size_x; x++) + tmp2[j++] = tmp[y * bmpData.size_x + x]; + } + } + + free(tmp); + } + else + { + free(bitmap); + return NULL; + } + + return (lv_img_dsc_t *)bitmap; +} + +#pragma GCC push_options +#pragma GCC target ("thumb") + +lv_res_t nyx_generic_onoff_toggle(lv_obj_t *btn) +{ + lv_obj_t *label_btn = lv_obj_get_child(btn, NULL); + lv_obj_t *label_btn2 = lv_obj_get_child(btn, label_btn); + + char label_text[64]; + if (!label_btn2) + { + strcpy(label_text, lv_label_get_text(label_btn)); + label_text[strlen(label_text) - 15] = 0; + + if (!(lv_btn_get_state(btn) & LV_BTN_STATE_TGL_REL)) + { + strcat(label_text, "#D0D0D0 OFF#"); + lv_label_set_array_text(label_btn, label_text, 64); + } + else + { + strcat(label_text, "#00FFC9 ON #"); + lv_label_set_array_text(label_btn, label_text, 64); + } + } + else + { + if (!(lv_btn_get_state(btn) & LV_BTN_STATE_TGL_REL)) + lv_label_set_static_text(label_btn, "#D0D0D0 OFF#"); + else + lv_label_set_static_text(label_btn, "#00FFC9 ON #"); + } + + return LV_RES_OK; +} + +static lv_res_t auto_hos_poweroff_toggle(lv_obj_t *btn) +{ + h_cfg.autohosoff = !h_cfg.autohosoff; + + if (!h_cfg.autohosoff) + lv_btn_set_state(btn, LV_BTN_STATE_REL); + else + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + + nyx_generic_onoff_toggle(btn); + + return LV_RES_OK; +} + +static lv_res_t auto_nogc_toggle(lv_obj_t *btn) +{ + h_cfg.autonogc = !h_cfg.autonogc; + + if (!h_cfg.autonogc) + lv_btn_set_state(btn, LV_BTN_STATE_REL); + else + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + + nyx_generic_onoff_toggle(btn); + + return LV_RES_OK; +} + +lv_res_t mbox_action(lv_obj_t *btns, const char *txt) +{ + lv_obj_t *mbox = lv_mbox_get_from_btn(btns); + lv_obj_t *dark_bg = lv_obj_get_parent(mbox); + + lv_obj_del(dark_bg); // Deletes children also (mbox). + + return LV_RES_INV; +} + +void nyx_window_toggle_buttons(lv_obj_t *win, bool disable) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + lv_obj_t * hbtn; + + hbtn = lv_obj_get_child_back(ext->header, NULL); + hbtn = lv_obj_get_child_back(ext->header, hbtn); // Skip the title. + + if (disable) + { + while (hbtn != NULL) + { + lv_obj_set_opa_scale(hbtn, LV_OPA_40); + lv_obj_set_opa_scale_enable(hbtn, true); + lv_obj_set_click(hbtn, false); + hbtn = lv_obj_get_child_back(ext->header, hbtn); + } + } + else + { + while (hbtn != NULL) + { + lv_obj_set_opa_scale(hbtn, LV_OPA_COVER); + lv_obj_set_click(hbtn, true); + hbtn = lv_obj_get_child_back(ext->header, hbtn); + } + } +} + + +lv_obj_t *nyx_create_standard_window(const char *win_title) +{ + static lv_style_t win_bg_style; + + lv_style_copy(&win_bg_style, &lv_style_plain); + win_bg_style.body.main_color = LV_COLOR_HEX(0x2D2D2D);// TODO: COLOR_HOS_BG + win_bg_style.body.grad_color = win_bg_style.body.main_color; + + lv_obj_t *win = lv_win_create(lv_scr_act(), NULL); + lv_win_set_title(win, win_title); + lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style); + lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES); + + lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", lv_win_close_action); + + return win; +} + +static void _launch_hos(u8 autoboot, u8 autoboot_list) +{ + b_cfg->boot_cfg = BOOT_CFG_AUTOBOOT_EN; + b_cfg->autoboot = autoboot; + b_cfg->autoboot_list = autoboot_list; + + void (*main_ptr)() = (void *)nyx_str->hekate; + + sd_unmount(true); + + reconfig_hw_workaround(false, 0); + + (*main_ptr)(); +} + +static lv_res_t _slider_brightness_action(lv_obj_t * slider) +{ + display_backlight_brightness(lv_slider_get_value(slider) - 20, 0); + h_cfg.backlight = lv_slider_get_value(slider); + + return LV_RES_OK; +} + +struct autoboot_obj +{ + lv_obj_t *obj0; + lv_obj_t *obj1; + lv_obj_t *obj2; +}; + +static struct autoboot_obj autoboot_obj; + +static bool autoboot_first_time = true; + +static lv_res_t _win_autoboot_close_action(lv_obj_t * btn) +{ + if (!h_cfg.autoboot) + { + lv_obj_set_opa_scale_enable(autoboot_obj.obj1, true); + lv_obj_set_click(autoboot_obj.obj2, false); + lv_btn_set_state(autoboot_obj.obj0, LV_BTN_STATE_REL); + } + else + { + lv_obj_set_opa_scale_enable(autoboot_obj.obj1, false); + lv_obj_set_click(autoboot_obj.obj2, true); + lv_btn_set_state(autoboot_obj.obj0, LV_BTN_STATE_TGL_REL); + } + + nyx_generic_onoff_toggle(autoboot_obj.obj0); + + lv_obj_t * win = lv_win_get_from_btn(btn); + + lv_obj_del(win); + + return LV_RES_INV; +} + +lv_obj_t *create_window_autoboot(const char *win_title) +{ + static lv_style_t win_bg_style; + + lv_style_copy(&win_bg_style, &lv_style_plain); + win_bg_style.body.main_color = LV_COLOR_HEX(0x2D2D2D);// TODO: COLOR_HOS_BG + win_bg_style.body.grad_color = win_bg_style.body.main_color; + + lv_obj_t *win = lv_win_create(lv_scr_act(), NULL); + lv_win_set_title(win, win_title); + lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style); + lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES); + + lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", _win_autoboot_close_action); + + return win; +} + +// TODO: instant update of button for these. +static lv_res_t _autoboot_disable_action(lv_obj_t *btn) +{ + h_cfg.autoboot = 0; + h_cfg.autoboot_list = 0; + + lv_obj_set_opa_scale_enable(autoboot_obj.obj1, true); + lv_obj_set_click(autoboot_obj.obj2, false); + lv_btn_set_state(autoboot_obj.obj0, LV_BTN_STATE_REL); + nyx_generic_onoff_toggle(autoboot_obj.obj0); + + lv_obj_t * win = lv_win_get_from_btn(btn); + + lv_obj_del(win); + + return LV_RES_OK; +} + +lv_obj_t *auto_main_list; +lv_obj_t *auto_more_list; +static lv_res_t _autoboot_enable_main_action(lv_obj_t *btn) +{ + h_cfg.autoboot = lv_list_get_btn_index(auto_main_list, btn) + 1; + h_cfg.autoboot_list = 0; + + lv_obj_set_opa_scale_enable(autoboot_obj.obj1, false); + lv_obj_set_click(autoboot_obj.obj2, true); + lv_btn_set_state(autoboot_obj.obj0, LV_BTN_STATE_TGL_REL); + nyx_generic_onoff_toggle(autoboot_obj.obj0); + + lv_obj_t *obj = lv_obj_get_parent(btn); + for (int i = 0; i < 5; i++) + obj = lv_obj_get_parent(obj); + lv_obj_del(obj); + + return LV_RES_INV; +} + +static lv_res_t _autoboot_enable_more_action(lv_obj_t *btn) +{ + h_cfg.autoboot = lv_list_get_btn_index(auto_more_list, btn) + 1; + h_cfg.autoboot_list = 1; + + lv_obj_set_opa_scale_enable(autoboot_obj.obj1, false); + lv_obj_set_click(autoboot_obj.obj2, true); + lv_btn_set_state(autoboot_obj.obj0, LV_BTN_STATE_TGL_REL); + nyx_generic_onoff_toggle(autoboot_obj.obj0); + + lv_obj_t *obj = lv_obj_get_parent(btn); + for (int i = 0; i < 5; i++) + obj = lv_obj_get_parent(obj); + lv_obj_del(obj); + + return LV_RES_INV; +} + +static void _create_autoboot_window() +{ + lv_obj_t *win = create_window_autoboot(SYMBOL_GPS" Auto Boot"); + lv_win_add_btn(win, NULL, SYMBOL_POWER" Disable", _autoboot_disable_action); + + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = 0; + h_style.body.padding.hor = LV_DPI - (LV_DPI / 4); + h_style.body.padding.ver = LV_DPI / 6; + + // Main configurations container. + lv_obj_t *h1 = lv_cont_create(win, NULL); + lv_cont_set_style(h1, &h_style); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt = lv_label_create(h1, NULL); + lv_label_set_static_text(label_txt, "Main configurations"); + lv_obj_set_style(label_txt, lv_theme_get_current()->label.prim); + lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -(LV_DPI / 4)); + + lv_obj_t *line_sep = lv_line_create(h1, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, lv_theme_get_current()->line.decor); + lv_obj_align(line_sep, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create list and populate it with Main boot entries. + lv_obj_t *list_main = lv_list_create(h1, NULL); + auto_main_list = list_main; + lv_obj_align(list_main, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + + lv_obj_set_size(list_main, LV_HOR_RES * 4 / 10, LV_VER_RES * 4 / 7); + lv_list_set_single_mode(list_main, true); + + sd_mount(); + + LIST_INIT(ini_sections); + if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) + { + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) + { + if (!strcmp(ini_sec->name, "config") || (ini_sec->type != INI_CHOICE)) + continue; + + lv_list_add(list_main, NULL, ini_sec->name, _autoboot_enable_main_action); + } + } + + // More configuration container. + lv_obj_t *h2 = lv_cont_create(win, NULL); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, true); + lv_obj_set_width(h2, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h2, false); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI * 17 / 29, 0); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt3 = lv_label_create(h2, NULL); + lv_label_set_static_text(label_txt3, "Ini folder configurations"); + lv_obj_set_style(label_txt3, lv_theme_get_current()->label.prim); + lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI / 11); + + line_sep = lv_line_create(h2, line_sep); + lv_obj_align(line_sep, label_txt3, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 2), LV_DPI / 8); + lv_line_set_style(line_sep, lv_theme_get_current()->line.decor); + + // Create list and populate it with more cfg boot entries. + lv_obj_t *list_more_cfg = lv_list_create(h2, NULL); + auto_more_list = list_more_cfg; + lv_obj_align(list_more_cfg, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 2, LV_DPI / 4); + + lv_obj_set_size(list_more_cfg, LV_HOR_RES * 4 / 10, LV_VER_RES * 4 / 7); + lv_list_set_single_mode(list_more_cfg, true); + + LIST_INIT(ini_list_sections); + if (ini_parse(&ini_list_sections, "bootloader/ini", true)) + { + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) + { + if (!strcmp(ini_sec->name, "config") || (ini_sec->type != INI_CHOICE)) + continue; + + lv_list_add(list_more_cfg, NULL, ini_sec->name, _autoboot_enable_more_action); + } + } + + sd_unmount(false); +} + +static lv_res_t _autoboot_hide_delay_action(lv_obj_t *btn) +{ + lv_obj_set_opa_scale(autoboot_obj.obj1, LV_OPA_40); + + if (!autoboot_first_time) + _create_autoboot_window(); + + if (!h_cfg.autoboot && autoboot_first_time) + { + lv_obj_set_opa_scale_enable(autoboot_obj.obj1, true); + lv_obj_set_click(autoboot_obj.obj2, false); + lv_btn_set_state(btn, LV_BTN_STATE_REL); + } + else + { + lv_obj_set_opa_scale_enable(autoboot_obj.obj1, false); + lv_obj_set_click(autoboot_obj.obj2, true); + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } + autoboot_first_time = false; + + nyx_generic_onoff_toggle(btn); + + return LV_RES_INV; +} + +static lv_res_t _autoboot_delay_action(lv_obj_t *ddlist) +{ + h_cfg.bootwait = lv_ddlist_get_selected(ddlist); + + return LV_RES_OK; +} + +static lv_res_t _data_verification_action(lv_obj_t *ddlist) +{ + h_cfg.verification = lv_ddlist_get_selected(ddlist); + + return LV_RES_OK; +} + +static void _reload_nyx() +{ + b_cfg->boot_cfg = BOOT_CFG_AUTOBOOT_EN; + b_cfg->autoboot = 0; + b_cfg->autoboot_list = 0; + b_cfg->extra_cfg = 0; + + void (*main_ptr)() = (void *)nyx_str->hekate; + + sd_unmount(true); + + reconfig_hw_workaround(false, 0); + + (*main_ptr)(); +} + +static lv_res_t reload_action(lv_obj_t *btns, const char *txt) +{ + if (!lv_btnm_get_pressed(btns)) + _reload_nyx(); + + return mbox_action(btns, txt); +} + +static bool do_reload = false; + +static void _check_sd_card_removed(void *params) +{ + // The following checks if sdmmc_1 is initialized. + // If yes and card was removed, shows a message box, + // that will reload Nyx, when the card is inserted again. + if (!do_reload && get_sd_card_removed()) + { + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES * 4 / 9); + + lv_mbox_set_text(mbox, "\n#FF8000 SD card was removed!#\n\n#96FF00 Nyx will reload after inserting it.#\n"); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + do_reload = true; + } + + // If in reload state and card was inserted, reload nyx. + if (do_reload && !get_sd_card_removed()) + _reload_nyx(); +} + +static lv_res_t _reboot_action(lv_obj_t *btns, const char *txt) +{ + u32 btnidx = lv_btnm_get_pressed(btns); + + switch (btnidx) + { + case 0: + reboot_normal(); + break; + case 1: + reboot_rcm(); + break; + } + + return mbox_action(btns, txt); +} + +static lv_res_t _poweroff_action(lv_obj_t *btns, const char *txt) +{ + if (!lv_btnm_get_pressed(btns)) + power_off(); + + return mbox_action(btns, txt); +} + +static lv_res_t _create_mbox_reload(lv_obj_t *btn) +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\221Reload", "\221Cancel", "" }; + lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES * 4 / 10); + + lv_mbox_set_text(mbox, "#FF8000 Do you really want#\n#FF8000 to reload hekate?#"); + + lv_mbox_add_btns(mbox, mbox_btn_map, reload_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + return LV_RES_OK; +} + +static lv_res_t _create_mbox_reboot(lv_obj_t *btn) +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\221OFW", "\221RCM", "\221Cancel", "" }; + lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES / 2); + + lv_mbox_set_text(mbox, "#FF8000 Choose where to reboot:#"); + + lv_mbox_add_btns(mbox, mbox_btn_map, _reboot_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + return LV_RES_OK; +} + +static lv_res_t _create_mbox_poweroff(lv_obj_t *btn) +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\221Power Off", "\221Cancel", "" }; + lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES * 4 / 10); + + lv_mbox_set_text(mbox, "#FF8000 Do you really want#\n#FF8000 to power off?#"); + + lv_mbox_add_btns(mbox, mbox_btn_map, _poweroff_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + return LV_RES_OK; +} + +void nyx_create_onoff_button(lv_theme_t *th, lv_obj_t *parent, lv_obj_t *btn, const char *btn_name, lv_action_t action, bool transparent) +{ + // Create buttons that are flat and text, plus On/Off switch. + static lv_style_t btn_onoff_rel_hos_style, btn_onoff_pr_hos_style; + lv_style_copy(&btn_onoff_rel_hos_style, th->btn.rel); + btn_onoff_rel_hos_style.body.shadow.width = 0; + btn_onoff_rel_hos_style.body.border.width = 0; + btn_onoff_rel_hos_style.body.padding.hor = 0; + btn_onoff_rel_hos_style.body.radius = 0; + btn_onoff_rel_hos_style.body.empty = 1; + + lv_style_copy(&btn_onoff_pr_hos_style, &btn_onoff_rel_hos_style); + if (transparent) + { + btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(0xFFFFFF); + btn_onoff_pr_hos_style.body.opa = 35; + } + else + btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(0x3D3D3D); + btn_onoff_pr_hos_style.body.grad_color = btn_onoff_pr_hos_style.body.main_color; + btn_onoff_pr_hos_style.text.color = th->btn.pr->text.color; + btn_onoff_pr_hos_style.body.empty = 0; + + lv_obj_t *label_btn = lv_label_create(btn, NULL); + lv_obj_t *label_btnsw = NULL; + + lv_label_set_recolor(label_btn, true); + label_btnsw = lv_label_create(btn, NULL); + lv_label_set_recolor(label_btnsw, true); + lv_btn_set_layout(btn, LV_LAYOUT_OFF); + + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_onoff_rel_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_onoff_pr_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, &btn_onoff_rel_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, &btn_onoff_pr_hos_style); + + lv_btn_set_fit(btn, false, true); + lv_obj_set_width(btn, lv_obj_get_width(parent)); + lv_btn_set_toggle(btn, true); + + + lv_label_set_text(label_btn, btn_name); + + lv_label_set_static_text(label_btnsw, "#00ffc9 OFF#"); + lv_obj_align(label_btn, btn, LV_ALIGN_IN_LEFT_MID, LV_DPI / 4, 0); + lv_obj_align(label_btnsw, btn, LV_ALIGN_IN_RIGHT_MID, -LV_DPI / 4, -LV_DPI / 10); + + if (action) + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, action); +} + +static void _create_text_button(lv_theme_t *th, lv_obj_t *parent, lv_obj_t *btn, const char *btn_name, lv_action_t action) +{ + // Create buttons that are flat and only have a text label. + static lv_style_t btn_onoff_rel_hos_style, btn_onoff_pr_hos_style; + lv_style_copy(&btn_onoff_rel_hos_style, th->btn.rel); + btn_onoff_rel_hos_style.body.shadow.width = 0; + btn_onoff_rel_hos_style.body.border.width = 0; + btn_onoff_rel_hos_style.body.radius = 0; + btn_onoff_rel_hos_style.body.padding.hor = LV_DPI / 4; + btn_onoff_rel_hos_style.body.empty = 1; + + lv_style_copy(&btn_onoff_pr_hos_style, &btn_onoff_rel_hos_style); + if (hekate_bg) + { + btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(0xFFFFFF); + btn_onoff_pr_hos_style.body.opa = 35; + } + else + btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(0x3D3D3D); + btn_onoff_pr_hos_style.body.grad_color = btn_onoff_pr_hos_style.body.main_color; + btn_onoff_pr_hos_style.text.color = th->btn.pr->text.color; + btn_onoff_pr_hos_style.body.empty = 0; + + lv_obj_t *label_btn = lv_label_create(btn, NULL); + + lv_label_set_recolor(label_btn, true); + + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_onoff_rel_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_onoff_pr_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, &btn_onoff_rel_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, &btn_onoff_pr_hos_style); + + lv_btn_set_fit(btn, true, true); + + lv_label_set_text(label_btn, btn_name); + + if (action) + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, action); +} + +static void _create_tab_options(lv_theme_t *th, lv_obj_t *parent) +{ + lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY); + + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = 0; + h_style.body.padding.hor = LV_DPI - (LV_DPI / 4); + h_style.body.padding.ver = LV_DPI / 6; + + // Create containers to keep content inside. + lv_obj_t * sw_h2 = lv_cont_create(parent, NULL); + lv_cont_set_style(sw_h2, &h_style); + lv_cont_set_fit(sw_h2, false, true); + lv_obj_set_width(sw_h2, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(sw_h2, false); + lv_cont_set_layout(sw_h2, LV_LAYOUT_OFF); + + lv_obj_t * sw_h3 = lv_cont_create(parent, NULL); + lv_cont_set_style(sw_h3, &h_style); + lv_cont_set_fit(sw_h3, false, true); + lv_obj_set_width(sw_h3, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(sw_h3, false); + lv_cont_set_layout(sw_h3, LV_LAYOUT_OFF); + + lv_obj_t * l_cont = lv_cont_create(sw_h2, NULL); + lv_cont_set_style(l_cont, &lv_style_transp_tight); + lv_cont_set_fit(l_cont, true, true); + lv_obj_set_click(l_cont, false); + lv_cont_set_layout(l_cont, LV_LAYOUT_OFF); + lv_obj_set_opa_scale(l_cont, LV_OPA_40); + autoboot_obj.obj1 = l_cont; + + lv_obj_t *label_sep = lv_label_create(sw_h2, NULL); + lv_label_set_static_text(label_sep, ""); + + // Create Auto Boot button. + lv_obj_t *btn = lv_btn_create(sw_h2, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_transp_pr); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, &btn_transp_tgl_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, &btn_transp_tgl_pr); + } + lv_btn_set_layout(btn, LV_LAYOUT_OFF); + lv_obj_t *label_btn = lv_label_create(btn, NULL); + lv_label_set_recolor(label_btn, true); + lv_btn_set_fit(btn, true, true); + lv_btn_set_toggle(btn, true); + lv_label_set_static_text(label_btn, SYMBOL_GPS" Auto Boot #00ffc9 ON #"); + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, _autoboot_hide_delay_action); + lv_obj_align(btn, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI / 18 + 6); + lv_btn_set_fit(btn, false, false); + autoboot_obj.obj0 = btn; + + lv_obj_t *label_txt2 = lv_label_create(sw_h2, NULL); + lv_label_set_static_text(label_txt2, "Choose which boot entry or payload to automatically boot\nwhen injecting."); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3 - 4); + + lv_obj_t *line_sep = lv_line_create(sw_h2, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, th->line.decor); + lv_obj_align(line_sep, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 4); + + // Create Boot time delay list. + lv_obj_t *label_txt = lv_label_create(l_cont, NULL); + lv_label_set_static_text(label_txt, SYMBOL_CLOCK" Boot Time Delay "); + lv_obj_set_style(label_txt, th->label.prim); + lv_obj_align(label_txt, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + + lv_obj_t *ddlist = lv_ddlist_create(l_cont, NULL); + lv_obj_set_top(ddlist, true); + lv_ddlist_set_draw_arrow(ddlist, true); + lv_ddlist_set_options(ddlist, + "No bootlogo \n" + "1 second\n" + "2 seconds\n" + "3 seconds\n" + "4 seconds\n" + "5 seconds\n" + "6 seconds"); + lv_ddlist_set_selected(ddlist, 3); + //lv_ddlist_set_align(ddlist, LV_LABEL_ALIGN_RIGHT); + lv_obj_align(ddlist, label_txt, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 4, 0); + lv_ddlist_set_action(ddlist, _autoboot_delay_action); + lv_ddlist_set_selected(ddlist, h_cfg.bootwait); + autoboot_obj.obj2 = ddlist; + + if (hekate_bg) + { + lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_BG, &ddlist_transp_bg); + lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_BGO, &ddlist_transp_bg); + lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_PR, &ddlist_transp_sel); + lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_SEL, &ddlist_transp_sel); + } + + label_txt2 = lv_label_create(l_cont, NULL); + lv_label_set_recolor(label_txt2, true); + lv_label_set_static_text(label_txt2, + "Set how long to show bootlogo when autoboot is enabled.\n" + "#C7EA46 You can press# #FF8000 VOL-# #C7EA46 during that time to enter hekate's menu.#\n"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 4); + + line_sep = lv_line_create(sw_h2, line_sep); + lv_obj_align(line_sep, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 4); + + // Create Auto NoGC button. + lv_obj_t *btn2 = lv_btn_create(sw_h2, NULL); + nyx_create_onoff_button(th, sw_h2, btn2, SYMBOL_SHRK" Auto NoGC", auto_nogc_toggle, true); + + lv_obj_align(btn2, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 10); + + label_txt2 = lv_label_create(sw_h2, NULL); + lv_label_set_recolor(label_txt2, true); + lv_label_set_static_text(label_txt2, + "It checks fuses and applies the patch automatically\n" + "if higher firmware. It is now a global config and\n" + "set on auto by default. (ON: Auto)\n\n\n"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn2, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 12); + + label_sep = lv_label_create(sw_h3, NULL); + lv_label_set_static_text(label_sep, ""); + + // Create Auto HOS Power Off button. + lv_obj_t *btn3 = lv_btn_create(sw_h3, NULL); + nyx_create_onoff_button(th, sw_h3, btn3, SYMBOL_POWER" Auto HOS Power Off", auto_hos_poweroff_toggle, true); + lv_obj_align(btn3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + + label_txt2 = lv_label_create(sw_h3, NULL); + lv_label_set_static_text(label_txt2, + "When Shutdown is used from HOS, the device wakes up after\n" + "15s. Enable this to automatically power off on the next\npayload injection."); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn3, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 12); + + line_sep = lv_line_create(sw_h3, line_sep); + lv_obj_align(line_sep, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 4); + + // Create Backlight slider. + label_txt = lv_label_create(sw_h3, NULL); + lv_label_set_static_text(label_txt, SYMBOL_BRIGHTNESS" Backlight"); + lv_obj_set_style(label_txt, th->label.prim); + lv_obj_align(label_txt, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + + lv_obj_t * slider = lv_slider_create(sw_h3, NULL); + lv_obj_set_width(slider, LV_DPI * 80 / 34); + //lv_obj_set_height(slider, LV_DPI * 4 / 10); + lv_bar_set_range(slider, 30, 220); + lv_bar_set_value(slider, h_cfg.backlight); + lv_slider_set_action(slider, _slider_brightness_action); + lv_obj_align(slider, label_txt, LV_ALIGN_OUT_RIGHT_MID, LV_DPI * 20 / 15, 0); + + label_txt2 = lv_label_create(sw_h3, NULL); + lv_label_set_static_text(label_txt2, "Set backlight brightness.\n\n"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 4); + + line_sep = lv_line_create(sw_h3, line_sep); + lv_obj_align(line_sep, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 4); + + // Create Backup/Restore Verification list. + label_txt = lv_label_create(sw_h3, NULL); + lv_label_set_static_text(label_txt, SYMBOL_MODULES_ALT" Data Verification"); + lv_obj_set_style(label_txt, th->label.prim); + lv_obj_align(label_txt, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + + lv_obj_t *ddlist2 = lv_ddlist_create(sw_h3, NULL); + lv_obj_set_top(ddlist2, true); + lv_ddlist_set_draw_arrow(ddlist2, true); + lv_ddlist_set_options(ddlist2, + "Off (Fastest)\n" + "Sparse (Fast) \n" + "Full (Slow)\n" + "Full (Hashes)"); + lv_ddlist_set_selected(ddlist2, h_cfg.verification); + lv_obj_align(ddlist2, label_txt, LV_ALIGN_OUT_RIGHT_MID, LV_DPI * 3 / 8, 0); + lv_ddlist_set_action(ddlist2, _data_verification_action); + + if (hekate_bg) + { + lv_ddlist_set_style(ddlist2, LV_DDLIST_STYLE_BG, &ddlist_transp_bg); + lv_ddlist_set_style(ddlist2, LV_DDLIST_STYLE_BGO, &ddlist_transp_bg); + lv_ddlist_set_style(ddlist2, LV_DDLIST_STYLE_PR, &ddlist_transp_sel); + lv_ddlist_set_style(ddlist2, LV_DDLIST_STYLE_SEL, &ddlist_transp_sel); + } + + label_txt2 = lv_label_create(sw_h3, NULL); + lv_label_set_static_text(label_txt2, "Set the type of data verification done for backup and restore.\n" + "Can be canceled without losing the backup/restore.\n\n\n\n"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 4); + + // Set default loaded states. + if (h_cfg.autohosoff) + lv_btn_set_state(btn3, LV_BTN_STATE_TGL_REL); + if (h_cfg.autonogc) + lv_btn_set_state(btn2, LV_BTN_STATE_TGL_REL); + + nyx_generic_onoff_toggle(btn2); + nyx_generic_onoff_toggle(btn3); + _autoboot_hide_delay_action(btn); + + lv_obj_set_top(l_cont, true); // Set the ddlist container at top. + lv_obj_set_parent(ddlist, l_cont); // Reorder ddlist. + lv_obj_set_top(ddlist, true); + lv_obj_set_top(ddlist2, true); +} + +static void _create_tab_about(lv_theme_t * th, lv_obj_t * parent) +{ + lv_obj_t * lbl_credits = lv_label_create(parent, NULL); + + lv_obj_align(lbl_credits, NULL, LV_ALIGN_IN_TOP_LEFT, LV_DPI / 2, LV_DPI / 2); + lv_ta_set_style(lbl_credits, LV_TA_STYLE_BG, &monospace_text); + lv_label_set_recolor(lbl_credits, true); + lv_label_set_static_text(lbl_credits, + "hekate (c) 2018 naehrwert, st4rk\n\n" + "CTCaer mod (c) 2018 CTCaer\n" + "\n" + "Thanks to: #00CCFF derrek, nedwill, plutoo, #\n" + " #00CCFF shuffle2, smea, thexyz, yellows8 #\n" + "\n" + "Greetings to: fincs, hexkyz, SciresM,\n" + " Shiny Quagsire, WinterMute\n" + "\n" + "Open source and free packages used:\n\n" + " - FatFs R0.13c,\n" + " Copyright (c) 2018, ChaN\n\n" + " - bcl-1.2.0,\n" + " Copyright (c) 2003-2006, Marcus Geelnard\n\n" + " - Atmosphere (SE sha256, process id patches),\n" + " Copyright (c) 2018, Atmosphere-NX\n\n" + " - elfload,\n" + " Copyright (c) 2014, Owen Shepherd\n" + " Copyright (c) 2018, M4xw\n\n" + " - Littlev Graphics Library,\n" + " Copyright (c) 2016 Gabor Kiss-Vamosi" + ); + + + lv_obj_t * lbl_octopus = lv_label_create(parent, NULL); + lv_obj_align(lbl_octopus, lbl_credits, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI, 0); + lv_ta_set_style(lbl_octopus, LV_TA_STYLE_BG, &monospace_text); + lv_label_set_recolor(lbl_octopus, true); + + lv_label_set_static_text(lbl_octopus, + "\n#00CCFF ___#\n" + "#00CCFF .-' `'.#\n" + "#00CCFF / \\#\n" + "#00CCFF | ;#\n" + "#00CCFF | | ___.--,#\n" + "#00CCFF _.._ |0) = (0) | _.---'`__.-( (_.#\n" + "#00CCFF __.--'`_.. '.__.\\ '--. \\_.-' ,.--'` `\"\"`#\n" + "#00CCFF ( ,.--'` ',__ /./; ;, '.__.'` __#\n" + "#00CCFF _`) ) .---.__.' / | |\\ \\__..--\"\" \"\"\"--.,_#\n" + "#00CCFF `---' .'.''-._.-'`_./ /\\ '. \\ _.--''````'''--._`-.__.'#\n" + "#00CCFF | | .' _.-' | | \\ \\ '. `----`#\n" + "#00CCFF \\ \\/ .' \\ \\ '. '-._)#\n" + "#00CCFF \\/ / \\ \\ `=.__`'-.#\n" + "#00CCFF / /\\ `) ) / / `\"\".`\\#\n" + "#00CCFF , _.-'.'\\ \\ / / ( ( / /#\n" + "#00CCFF `--'` ) ) .-'.' '.'. | (#\n" + "#00CCFF (/` ( (` ) ) '-; ##00FFCC [switchbrew]#\n" + "#00CCFF ` '-; (-'#" + ); + + lv_obj_t *hekate_img = lv_img_create(parent, NULL); + lv_img_set_src(hekate_img, &hekate_logo); + lv_obj_align(hekate_img, lbl_octopus, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 2 / 3); + + lv_obj_t *ctcaer_img = lv_img_create(parent, NULL); + lv_img_set_src(ctcaer_img, &ctcaer_logo); + lv_obj_align(ctcaer_img, lbl_octopus, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, LV_DPI * 2 / 3); + + char version[32]; + s_printf(version, "Nyx v%d.%d.%d", BL_VER_MJ, BL_VER_MN, BL_VER_HF); + lv_obj_t * lbl_ver = lv_label_create(parent, NULL); + lv_obj_align(lbl_ver, ctcaer_img, LV_ALIGN_OUT_BOTTOM_RIGHT, -LV_DPI / 20, LV_DPI / 4); + lv_ta_set_style(lbl_ver, LV_TA_STYLE_BG, &monospace_text); + lv_label_set_text(lbl_ver, version); +} + +#pragma GCC pop_options + +static void _update_status_bar(void *params) +{ + char *label = (char *)malloc(64); + + u16 soc_temp; + u32 batt_percent; + int charge_status; + int batt_volt; + int batt_curr; + rtc_time_t time; + + // Get sensor data. + max77620_rtc_get_time(&time); + soc_temp = tmp451_get_soc_temp(false); + bq24193_get_property(BQ24193_ChargeStatus, &charge_status); + max17050_get_property(MAX17050_RepSOC, (int *)&batt_percent); + max17050_get_property(MAX17050_VCELL, &batt_volt); + max17050_get_property(MAX17050_Current, &batt_curr); + + //! TODO: Parse time and use offset. + // Set time and SoC temperature. + s_printf(label, "%02d:%02d "SYMBOL_DOT" "SYMBOL_TEMPERATURE" %02d.%d", + time.hour, time.min, soc_temp >> 8, (soc_temp & 0xFF) / 10); + + lv_label_set_array_text(status_bar.time_temp, label, 64); + + lv_obj_realign(status_bar.temp_symbol); + lv_obj_realign(status_bar.temp_degrees); + + // Set battery percent and charging symbol. + s_printf(label, " "SYMBOL_DOT" %d.%d%% ", (batt_percent >> 8) & 0xFF, (batt_percent & 0xFF) / 26); + + u8 batt_level = (batt_percent >> 8) & 0xFF; + if (batt_level > 80) + s_printf(label + strlen(label), SYMBOL_BATTERY_FULL); + else if (batt_level > 60) + s_printf(label + strlen(label), SYMBOL_BATTERY_3); + else if (batt_level > 40) + s_printf(label + strlen(label), SYMBOL_BATTERY_2); + else if (batt_level > 15) + s_printf(label + strlen(label), SYMBOL_BATTERY_1); + else + s_printf(label + strlen(label), "#FF3C28 "SYMBOL_BATTERY_EMPTY"#"); + + if (charge_status) + s_printf(label + strlen(label), " #FFDD00 "SYMBOL_CHARGE"#"); + + lv_label_set_array_text(status_bar.battery, label, 64); + lv_obj_realign(status_bar.battery); + + // Set battery current draw and voltage. + if (batt_curr >= 0) + s_printf(label, "#96FF00 +%d", batt_curr / 1000); + else + s_printf(label, "#FF3C28 -%d", (~batt_curr + 1) / 1000); + + s_printf(label + strlen(label), " mA# (%d mV)", batt_volt); + + lv_label_set_array_text(status_bar.battery_more, label, 64); + lv_obj_realign(status_bar.battery_more); + + free(label); +} + +static lv_res_t _create_mbox_payloads(lv_obj_t *btn) +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\211", "\222Cancel", "\211", "" }; + lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES * 5 / 9); + + lv_mbox_set_text(mbox, "Select a payload to launch:"); + + // Create a list with all found payloads. + //! TODO: SHould that be tabs with buttons? + Icon support? + lv_obj_t *list = lv_list_create(mbox, NULL); + payload_list = list; + lv_obj_set_size(list, LV_HOR_RES * 3 / 7, LV_VER_RES * 3 / 7); + lv_list_set_single_mode(list, true); + + if (!sd_mount()) + { + lv_mbox_set_text(mbox, "#FFDD00 Failed to init SD!#"); + + goto out_end; + } + + char *dir = (char *)malloc(256); + strcpy(dir, "bootloader/payloads"); + + char *filelist = dirlist(dir, NULL, false, false); + sd_unmount(false); + + u32 i = 0; + + if (filelist) + { + while (true) + { + if (!filelist[i * 256]) + break; + lv_list_add(list, NULL, &filelist[i * 256], launch_payload); + i++; + } + } + +out_end: + lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + return LV_RES_OK; +} + +static lv_obj_t *launch_ctxt[16]; + +static lv_res_t _launch_more_cfg_action(lv_obj_t *btn) +{ + lv_btn_ext_t *ext = lv_obj_get_ext_attr(btn); + + _launch_hos(ext->idx, 1); + + return LV_RES_OK; +} + +static lv_res_t _win_launch_close_action(lv_obj_t * btn) +{ + // Cleanup icons. + lv_btn_ext_t *ext; + lv_obj_t *btn_tmp; + for (u32 i = 0; i < 16; i += 2) + { + btn_tmp = launch_ctxt[i]; + ext = lv_obj_get_ext_attr(btn_tmp); + if (ext->idx) + { + btn_tmp = lv_obj_get_child(btn_tmp, NULL); + lv_img_dsc_t *tmp = (lv_img_dsc_t *)lv_img_get_src(btn_tmp); + + // Avoid freeing base icons. + if ((tmp != icon_switch) && (tmp != icon_payload) && (tmp != icon_lakka)) + free(tmp); + } + } + + lv_obj_t * win = lv_win_get_from_btn(btn); + + lv_obj_del(win); + + return LV_RES_INV; +} + +lv_obj_t *create_window_launch(const char *win_title) +{ + static lv_style_t win_bg_style; + + lv_style_copy(&win_bg_style, &lv_style_plain); + win_bg_style.body.main_color = LV_COLOR_HEX(0x2D2D2D);// TODO: COLOR_HOS_BG + win_bg_style.body.grad_color = win_bg_style.body.main_color; + + lv_obj_t *win = lv_win_create(lv_scr_act(), NULL); + lv_win_set_title(win, win_title); + lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style); + lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES); + + lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", _win_launch_close_action); + + return win; +} + +static lv_res_t _launch_action(lv_obj_t *btn) +{ + lv_btn_ext_t *ext = lv_obj_get_ext_attr(btn); + + _launch_hos(ext->idx, 0); + + return LV_RES_OK; +} + +static lv_res_t _create_window_home_launch(lv_obj_t *btn) +{ + char *icon_path; + + static lv_style_t btn_home_transp_rel; + lv_style_copy(&btn_home_transp_rel, lv_theme_get_current()->btn.rel); + btn_home_transp_rel.body.opa = LV_OPA_0; + + static lv_style_t btn_home_transp_pr; + lv_style_copy(&btn_home_transp_pr, lv_theme_get_current()->btn.pr); + btn_home_transp_pr.body.main_color = LV_COLOR_HEX(0xFFFFFF); + btn_home_transp_pr.body.grad_color = btn_home_transp_pr.body.main_color; + btn_home_transp_pr.body.opa = LV_OPA_30; + + lv_obj_t *win; + + bool more_cfg = false; + if (strcmp(lv_label_get_text(lv_obj_get_child(btn, NULL)),"#00EDBA Launch#")) + more_cfg = true; + + if (!more_cfg) + win = create_window_launch(SYMBOL_GPS" Launch"); + else + win = create_window_launch(SYMBOL_GPS" More Configurations"); + + lv_cont_set_fit(lv_page_get_scrl(lv_win_get_content(win)), false, false); + lv_page_set_scrl_height(lv_win_get_content(win), 572); + + lv_obj_t *btn_boot_entry; + lv_obj_t *boot_entry_lbl_cont; + lv_obj_t *boot_entry_label; + bool no_boot_entries = false; + + u32 max_entries = 8; + lv_btn_ext_t * ext; + + //! TODO: Use an array/loop for the initialization. + // Create CFW buttons. + btn_boot_entry = lv_btn_create(win, NULL); + launch_ctxt[0] = btn_boot_entry; + + + // Buttons are 200 x 200 with 4 pixel borders. + // Icons must be <= 192 x 192. + // Button 0. + lv_obj_set_size(btn_boot_entry, 200, 200); + lv_obj_set_pos(btn_boot_entry, 19, 36); + lv_obj_set_opa_scale(btn_boot_entry, LV_OPA_0); + lv_obj_set_opa_scale_enable(btn_boot_entry, true); + lv_btn_set_layout(btn_boot_entry, LV_LAYOUT_OFF); + + boot_entry_lbl_cont = lv_cont_create(win, NULL); + boot_entry_label = lv_label_create(boot_entry_lbl_cont, NULL); + lv_obj_set_style(boot_entry_label, &hint_small_style_white); + lv_label_set_static_text(boot_entry_label, ""); + launch_ctxt[1] = boot_entry_label; + + lv_cont_set_fit(boot_entry_lbl_cont, false, false); + lv_cont_set_layout(boot_entry_lbl_cont, LV_LAYOUT_CENTER); + lv_obj_set_size(boot_entry_lbl_cont, 238, 20); + lv_obj_set_pos(boot_entry_lbl_cont, 0, 245); + + // Button 1. + btn_boot_entry = lv_btn_create(win, btn_boot_entry); + launch_ctxt[2] = btn_boot_entry; + lv_obj_set_pos(btn_boot_entry, 340, 36); + + boot_entry_lbl_cont = lv_cont_create(win, boot_entry_lbl_cont); + boot_entry_label = lv_label_create(boot_entry_lbl_cont, boot_entry_label); + lv_obj_set_pos(boot_entry_lbl_cont, 321, 245); + launch_ctxt[3] = boot_entry_label; + + // Button 2. + btn_boot_entry = lv_btn_create(win, btn_boot_entry); + launch_ctxt[4] = btn_boot_entry; + lv_obj_set_pos(btn_boot_entry, 661, 36); + + boot_entry_lbl_cont = lv_cont_create(win, boot_entry_lbl_cont); + boot_entry_label = lv_label_create(boot_entry_lbl_cont, boot_entry_label); + lv_obj_set_pos(boot_entry_lbl_cont, 642, 245); + launch_ctxt[5] = boot_entry_label; + + // Button 3. + btn_boot_entry = lv_btn_create(win, btn_boot_entry); + launch_ctxt[6] = btn_boot_entry; + lv_obj_set_pos(btn_boot_entry, 982, 36); + + boot_entry_lbl_cont = lv_cont_create(win, boot_entry_lbl_cont); + boot_entry_label = lv_label_create(boot_entry_lbl_cont, boot_entry_label); + lv_obj_set_pos(boot_entry_lbl_cont, 963, 245); + launch_ctxt[7] = boot_entry_label; + + // Button 4. + btn_boot_entry = lv_btn_create(win, btn_boot_entry); + launch_ctxt[8] = btn_boot_entry; + lv_obj_set_pos(btn_boot_entry, 19, 313); + + boot_entry_lbl_cont = lv_cont_create(win, boot_entry_lbl_cont); + boot_entry_label = lv_label_create(boot_entry_lbl_cont, boot_entry_label); + lv_obj_set_pos(boot_entry_lbl_cont, 0, 522); + launch_ctxt[9] = boot_entry_label; + + // Button 5. + btn_boot_entry = lv_btn_create(win, btn_boot_entry); + launch_ctxt[10] = btn_boot_entry; + lv_obj_set_pos(btn_boot_entry, 340, 313); + + boot_entry_lbl_cont = lv_cont_create(win, boot_entry_lbl_cont); + boot_entry_label = lv_label_create(boot_entry_lbl_cont, boot_entry_label); + lv_obj_set_pos(boot_entry_lbl_cont, 321, 522); + launch_ctxt[11] = boot_entry_label; + + // Button 6. + btn_boot_entry = lv_btn_create(win, btn_boot_entry); + launch_ctxt[12] = btn_boot_entry; + lv_obj_set_pos(btn_boot_entry, 661, 313); + + boot_entry_lbl_cont = lv_cont_create(win, boot_entry_lbl_cont); + boot_entry_label = lv_label_create(boot_entry_lbl_cont, boot_entry_label); + lv_obj_set_pos(boot_entry_lbl_cont, 642, 522); + launch_ctxt[13] = boot_entry_label; + + // Button 7. + btn_boot_entry = lv_btn_create(win, btn_boot_entry); + launch_ctxt[14] = btn_boot_entry; + lv_obj_set_pos(btn_boot_entry, 982, 313); + + boot_entry_lbl_cont = lv_cont_create(win, boot_entry_lbl_cont); + boot_entry_label = lv_label_create(boot_entry_lbl_cont, boot_entry_label); + lv_obj_set_pos(boot_entry_lbl_cont, 963, 522); + launch_ctxt[15] = boot_entry_label; + + // Parse ini boot entries and set buttons/icons. + char *tmp_path = calloc(0x80, 1); + LIST_INIT(ini_sections); + if (sd_mount()) + { + // Choose what to parse. + bool ini_parse_success = false; + if (!more_cfg) + ini_parse_success = ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false); + else + ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true); + + if (ini_parse_success) + { + // Iterate to all boot entries and load icons. + u32 i = 1, x = 0; + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) + { + if (!strcmp(ini_sec->name, "config") || (ini_sec->type != INI_CHOICE)) + continue; + + icon_path = NULL; + bool payload = false; + lv_img_dsc_t *bmp = NULL; + + // Check for icons. + LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) + { + if (!strcmp("icon", kv->key)) + { + icon_path = kv->val; + break; + } + else if (!strcmp("payload", kv->key)) + { + payload = true; + break; + } + } + + // If icon not found, check res folder for section_name.bmp. + // If not, use defaults. + if (!icon_path) + { + s_printf(tmp_path, "bootloader/res/%s.bmp", ini_sec->name); + bmp = bmp_to_lvimg_obj(tmp_path); + if (!bmp) + { + if (!strcmp(ini_sec->name, "Lakka")) + bmp = icon_lakka; + else if (payload) + bmp = icon_payload; + } + } + else + bmp = bmp_to_lvimg_obj(icon_path); + + // Enable button. + ext = lv_obj_get_ext_attr(launch_ctxt[x]); + ext->idx = i; + lv_obj_set_opa_scale(launch_ctxt[x], LV_OPA_COVER); + + // Default to switch logo if no icon found at all. + if (!bmp) + bmp = icon_switch; + + //Set icon and border/radius mask. + if (bmp) + { + lv_obj_t *img = lv_img_create(launch_ctxt[x], NULL); + lv_img_set_src(img, bmp); + lv_obj_t *btn = lv_btn_create(launch_ctxt[x], NULL); + lv_obj_set_size(btn, 200, 200); + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_home_transp_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_home_transp_pr); + lv_obj_align(img, NULL, LV_ALIGN_CENTER, 0, 0); + ext = lv_obj_get_ext_attr(btn); + ext->idx = i; + + if (!more_cfg) + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, _launch_action); + else + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, _launch_more_cfg_action); + } + + // Set button's label text. + lv_label_set_array_text(launch_ctxt[x + 1], ini_sec->name, strlen(ini_sec->name)); + lv_obj_set_opa_scale(launch_ctxt[x + 1], LV_OPA_COVER); + + //! TODO: Check strlen and decide on rolling text + //lv_label_set_long_mode(boot_entry_label, LV_LABEL_LONG_ROLL); + + i++; + x += 2; + + if (i > max_entries) + break; + } + if (i < 2) + no_boot_entries = true; + } + else + no_boot_entries = true; + } + else + no_boot_entries = true; + sd_unmount(false); + + free(tmp_path); + + // No boot entries found. + if (no_boot_entries) + { + lv_obj_t *label_error = lv_label_create(win, NULL); + lv_label_set_recolor(label_error, true); + if (!more_cfg) + { + lv_label_set_static_text(label_error, + "#FFDD00 No main boot entries found...\n" + "You can use the following entry to boot stock,\n" + "or use #C7EA46 More configs# button for more boot entries."); + } + else + { + lv_label_set_static_text(label_error, + "#FFDD00 No .ini or boot entries found...\n" + "Check that a .ini file exists in #96FF00 /bootloader/ini/#,\n" + "and that it contains at least one entry."); + } + + lv_obj_set_pos(label_error, 19, 0); + } + + return LV_RES_OK; +} + +#pragma GCC push_options +#pragma GCC target ("thumb") + +static void _create_tab_home(lv_theme_t *th, lv_obj_t *parent) +{ + lv_page_set_scrl_layout(parent, LV_LAYOUT_OFF); + lv_page_set_scrl_fit(parent, false, false); + lv_page_set_scrl_height(parent, 592); + + // Set brand label. + lv_obj_t *label_brand = lv_label_create(parent, NULL); + lv_label_set_recolor(label_brand, true); + lv_label_set_static_text(label_brand, "#00EDBA hekate"); + lv_obj_set_pos(label_brand, 50, 48); + + // Set tagline label. + lv_obj_t *label_tagline = lv_label_create(parent, NULL); + lv_obj_set_style(label_tagline, &hint_small_style_white); + lv_label_set_static_text(label_tagline, "THE ALL IN ONE BOOTLOADER FOR ALL YOUR NEEDS"); + lv_obj_set_pos(label_tagline, 50, 82); + + static lv_style_t icons; + lv_style_copy(&icons, th->label.prim); + icons.text.font = &hekate_symbol_120; + + // Launch button. + lv_obj_t *btn_launch = lv_btn_create(parent, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn_launch, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn_launch, LV_BTN_STYLE_PR, &btn_transp_pr); + } + lv_obj_t *label_btn = lv_label_create(btn_launch, NULL); + lv_label_set_recolor(label_btn, true); + lv_obj_set_style(label_btn, &icons); + lv_label_set_static_text(label_btn, "#00EDBA "SYMBOL_DOT"#"); + lv_btn_set_action(btn_launch, LV_BTN_ACTION_CLICK, _create_window_home_launch); + lv_obj_set_size(btn_launch, 256, 256); + lv_obj_set_pos(btn_launch, 50, 160); + lv_btn_set_layout(btn_launch, LV_LAYOUT_OFF); + lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28); + lv_obj_t *label_btn2 = lv_label_create(btn_launch, NULL); + lv_label_set_recolor(label_btn2, true); + lv_label_set_static_text(label_btn2, "#00EDBA Launch#"); + lv_obj_align(label_btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 174); + + // More Configs button. + lv_obj_t *btn_more_cfg = lv_btn_create(parent, btn_launch); + label_btn = lv_label_create(btn_more_cfg, label_btn); + lv_label_set_static_text(label_btn, "#00EDBA "SYMBOL_CLOCK"#"); + lv_btn_set_action(btn_more_cfg, LV_BTN_ACTION_CLICK, _create_window_home_launch); + lv_btn_set_layout(btn_more_cfg, LV_LAYOUT_OFF); + lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28); + label_btn2 = lv_label_create(btn_more_cfg, label_btn2); + lv_label_set_static_text(label_btn2, "#00EDBA More Configs#"); + lv_obj_set_pos(btn_more_cfg, 341, 160); + lv_obj_align(label_btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 174); + + // Quick Launch button. + // lv_obj_t *btn_quick_launch = lv_btn_create(parent, NULL); + // label_btn = lv_label_create(btn_quick_launch, label_btn); + // lv_label_set_static_text(label_btn, SYMBOL_EDIT" Quick Launch"); + // lv_obj_set_width(btn_quick_launch, 256); + // lv_obj_set_pos(btn_quick_launch, 343, 448); + // lv_btn_set_action(btn_quick_launch, LV_BTN_ACTION_CLICK, NULL); + + // Payloads button. + lv_obj_t *btn_payloads = lv_btn_create(parent, btn_launch); + label_btn = lv_label_create(btn_payloads, label_btn); + lv_label_set_static_text(label_btn, "#00EDBA "SYMBOL_OK"#"); + lv_btn_set_action(btn_payloads, LV_BTN_ACTION_CLICK, _create_mbox_payloads); + lv_btn_set_layout(btn_payloads, LV_LAYOUT_OFF); + lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28); + label_btn2 = lv_label_create(btn_payloads, label_btn2); + lv_label_set_static_text(label_btn2, "#00EDBA Payloads#"); + lv_obj_set_pos(btn_payloads, 632, 160); + lv_obj_align(label_btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 174); + + lv_obj_t *line_sep = lv_line_create(parent, NULL); + static const lv_point_t line_pp[] = { {0, 0}, {0, LV_DPI * 3} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, th->line.decor); + lv_obj_align(line_sep, btn_payloads, LV_ALIGN_OUT_RIGHT_MID, 35, 0); + + // emuMMC manage button. + lv_obj_t *btn_emummc = lv_btn_create(parent, btn_launch); + label_btn = lv_label_create(btn_emummc, label_btn); + lv_label_set_static_text(label_btn, "#00EDBA "SYMBOL_LIST"#"); + lv_btn_set_action(btn_emummc, LV_BTN_ACTION_CLICK,create_win_emummc_tools); + lv_btn_set_layout(btn_emummc, LV_LAYOUT_OFF); + lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28); + lv_obj_set_pos(btn_emummc, 959, 160); + label_btn2 = lv_label_create(btn_emummc, label_btn2); + lv_label_set_static_text(label_btn2, "#00EDBA emuMMC#"); + lv_obj_align(label_btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 174); + + // Create bottom right power buttons. + lv_obj_t *btn_reboot = lv_btn_create(parent, NULL); + lv_obj_t *btn_power_off = lv_btn_create(parent, NULL); + lv_obj_t *btn_reload = lv_btn_create(parent, NULL); + + _create_text_button(th, NULL, btn_power_off, SYMBOL_POWER" Power Off", _create_mbox_poweroff); + lv_obj_align(btn_power_off, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -LV_DPI / 4, -LV_DPI / 12); + + _create_text_button(th, NULL, btn_reboot, SYMBOL_REBOOT" Reboot", _create_mbox_reboot); + lv_obj_align(btn_reboot, btn_power_off, LV_ALIGN_OUT_LEFT_MID, 0, 0); + + _create_text_button(th, NULL, btn_reload, SYMBOL_REFRESH" Reload", _create_mbox_reload); + lv_obj_align(btn_reload, btn_reboot, LV_ALIGN_OUT_LEFT_MID, 0, 0); +} + +static lv_res_t _save_options_action(lv_obj_t *btn) +{ + static const char * mbox_btn_map[] = {"\211", "\222OK!", "\211", ""}; + lv_obj_t * mbox = lv_mbox_create(lv_scr_act(), NULL); + lv_mbox_set_recolor_text(mbox, true); + + int res = !create_config_entry(); + + if (res) + lv_mbox_set_text(mbox, "#FF8000 hekate Configuration#\n\n#96FF00 The configuration was saved to sd card!#"); + else + lv_mbox_set_text(mbox, "#FF8000 hekate Configuration#\n\n#FFDD00 Failed to save the configuration#\n#FFDD00 to sd card!#"); + lv_mbox_add_btns(mbox, mbox_btn_map, NULL); + lv_obj_set_top(mbox, true); + + return LV_RES_OK; +} + +static void _create_status_bar(lv_theme_t * th) +{ + static lv_obj_t *status_bar_bg; + status_bar_bg = lv_cont_create(lv_layer_top(), NULL); + + static lv_style_t status_bar_style; + lv_style_copy(&status_bar_style, &lv_style_plain_color); + status_bar_style.body.opa = LV_OPA_0; + status_bar_style.body.shadow.width = 0; + + lv_obj_set_style(status_bar_bg, &status_bar_style); + lv_obj_set_size(status_bar_bg, LV_HOR_RES, LV_DPI * 9 / 14); + lv_obj_align(status_bar_bg, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + + // Battery percentages. + lv_obj_t *lbl_battery = lv_label_create(status_bar_bg, NULL); + lv_label_set_recolor(lbl_battery, true); + lv_label_set_static_text(lbl_battery, " "SYMBOL_DOT" 00.0% "SYMBOL_BATTERY_1" #FFDD00 "SYMBOL_CHARGE"#"); + lv_obj_align(lbl_battery, NULL, LV_ALIGN_IN_RIGHT_MID, -LV_DPI * 6 / 11, 0); + status_bar.battery = lbl_battery; + + // Amperages, voltages. + lbl_battery = lv_label_create(status_bar_bg, lbl_battery); + lv_obj_set_style(lbl_battery, &hint_small_style_white); + lv_label_set_static_text(lbl_battery, "#96FF00 +0 mA# (0 mV)"); + lv_obj_align(lbl_battery, status_bar.battery, LV_ALIGN_OUT_LEFT_MID, -LV_DPI / 25, -1); + status_bar.battery_more = lbl_battery; + + lv_obj_t *lbl_left = lv_label_create(status_bar_bg, NULL); + lv_label_set_static_text(lbl_left, SYMBOL_CLOCK" "); + lv_obj_align(lbl_left, NULL, LV_ALIGN_IN_LEFT_MID, LV_DPI * 6 / 11, 0); + + // Time, temperature. + lv_obj_t *lbl_time_temp = lv_label_create(status_bar_bg, NULL); + lv_label_set_static_text(lbl_time_temp, "00:00 "SYMBOL_DOT" "SYMBOL_TEMPERATURE" 00.0"); + lv_obj_align(lbl_time_temp, lbl_left, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + status_bar.time_temp = lbl_time_temp; + + lbl_left = lv_label_create(status_bar_bg, NULL); + lv_label_set_static_text(lbl_left, " "SYMBOL_DOT); + lv_obj_align(lbl_left, lbl_time_temp, LV_ALIGN_OUT_RIGHT_MID, 0, -LV_DPI / 14); + status_bar.temp_symbol = lbl_left; + + lv_obj_t *lbl_degrees = lv_label_create(status_bar_bg, NULL); + lv_label_set_static_text(lbl_degrees, "C"); + lv_obj_align(lbl_degrees, lbl_left, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 50, LV_DPI / 14); + status_bar.temp_degrees = lbl_degrees; + + // Middle button. + //! TODO: Utilize it for more. + lv_obj_t *btn_mid = lv_btn_create(status_bar_bg, NULL); + lv_obj_t *lbl_mid = lv_label_create(btn_mid, NULL); + lv_label_set_static_text(lbl_mid, "Save Options"); + lv_obj_set_size(btn_mid, LV_DPI * 5 / 2, LV_DPI / 2); + lv_obj_align(btn_mid, NULL, LV_ALIGN_CENTER, 0, 0); + status_bar.mid = btn_mid; + lv_obj_set_opa_scale(status_bar.mid, LV_OPA_0); + lv_obj_set_opa_scale_enable(status_bar.mid, true); + lv_obj_set_click(status_bar.mid, false); + lv_btn_set_action(btn_mid, LV_BTN_ACTION_CLICK, _save_options_action); +} + +static lv_res_t _show_hide_save_button(lv_obj_t *tv, uint16_t tab_idx) +{ + if (tab_idx == 4) // Options. + { + lv_obj_set_opa_scale(status_bar.mid, LV_OPA_COVER); + lv_obj_set_click(status_bar.mid, true); + } + else + { + lv_obj_set_opa_scale(status_bar.mid, LV_OPA_0); + lv_obj_set_click(status_bar.mid, false); + } + + return LV_RES_OK; +} + +static void _nyx_set_default_styles(lv_theme_t * th) +{ + lv_style_copy(&mbox_darken, &lv_style_plain); + mbox_darken.body.main_color = LV_COLOR_BLACK; + mbox_darken.body.grad_color = mbox_darken.body.main_color; + mbox_darken.body.opa = LV_OPA_30; + + lv_style_copy(&hint_small_style, th->label.hint); + hint_small_style.text.letter_space = 1; + hint_small_style.text.font = &interui_20; + + lv_style_copy(&hint_small_style_white, th->label.prim); + hint_small_style_white.text.letter_space = 1; + hint_small_style_white.text.font = &interui_20; + + lv_style_copy(&monospace_text, &lv_style_plain); + monospace_text.body.main_color = LV_COLOR_HEX(0x1b1b1b); + monospace_text.body.grad_color = LV_COLOR_HEX(0x1b1b1b); + monospace_text.body.border.color = LV_COLOR_HEX(0x1b1b1b); + monospace_text.body.border.width = 0; + monospace_text.body.opa = LV_OPA_TRANSP; + monospace_text.text.color = LV_COLOR_HEX(0xD8D8D8); + monospace_text.text.font = &ubuntu_mono; + monospace_text.text.letter_space = 0; + monospace_text.text.line_space = 0; + + lv_style_copy(&btn_transp_rel, th->btn.rel); + btn_transp_rel.body.main_color = LV_COLOR_HEX(0x444444); + btn_transp_rel.body.grad_color = btn_transp_rel.body.main_color; + btn_transp_rel.body.opa = LV_OPA_50; + + lv_style_copy(&btn_transp_pr, th->btn.pr); + btn_transp_pr.body.main_color = LV_COLOR_HEX(0x888888); + btn_transp_pr.body.grad_color = btn_transp_pr.body.main_color; + btn_transp_pr.body.opa = LV_OPA_50; + + lv_style_copy(&btn_transp_tgl_rel, th->btn.tgl_rel); + btn_transp_tgl_rel.body.main_color = LV_COLOR_HEX(0x444444); + btn_transp_tgl_rel.body.grad_color = btn_transp_tgl_rel.body.main_color; + btn_transp_tgl_rel.body.opa = LV_OPA_50; + + lv_style_copy(&btn_transp_tgl_pr, th->btn.tgl_pr); + btn_transp_tgl_pr.body.main_color = LV_COLOR_HEX(0x888888); + btn_transp_tgl_pr.body.grad_color = btn_transp_tgl_pr.body.main_color; + btn_transp_tgl_pr.body.opa = LV_OPA_50; + + lv_style_copy(&ddlist_transp_bg, th->ddlist.bg); + ddlist_transp_bg.body.main_color = LV_COLOR_HEX(0x2D2D2D); + ddlist_transp_bg.body.grad_color = ddlist_transp_bg.body.main_color; + ddlist_transp_bg.body.opa = 180; + + lv_style_copy(&ddlist_transp_sel, th->ddlist.sel); + ddlist_transp_sel.body.main_color = LV_COLOR_HEX(0x4D4D4D); + ddlist_transp_sel.body.grad_color = ddlist_transp_sel.body.main_color; + ddlist_transp_sel.body.opa = 180; + + lv_style_copy(&tabview_btn_pr, th->tabview.btn.pr); + tabview_btn_pr.body.main_color = LV_COLOR_HEX(0xFFFFFF); + tabview_btn_pr.body.grad_color = tabview_btn_pr.body.main_color; + tabview_btn_pr.body.opa = 35; + + lv_style_copy(&tabview_btn_tgl_pr, th->tabview.btn.tgl_pr); + tabview_btn_tgl_pr.body.main_color = LV_COLOR_HEX(0xFFFFFF); + tabview_btn_tgl_pr.body.grad_color = tabview_btn_tgl_pr.body.main_color; + tabview_btn_tgl_pr.body.opa = 35; +} + +static void _nyx_main_menu(lv_theme_t * th) +{ + static lv_style_t no_padding; + lv_style_copy(&no_padding, &lv_style_transp); + no_padding.body.padding.hor = 0; + + // Initialize global styles. + _nyx_set_default_styles(th); + + // Create screen container. + lv_obj_t *scr = lv_cont_create(NULL, NULL); + lv_scr_load(scr); + lv_cont_set_style(scr, th->bg); + + // Create base background and add a custom one if exists. + lv_obj_t *cnr = lv_cont_create(scr, NULL); + static lv_style_t base_bg_style; + lv_style_copy(&base_bg_style, &lv_style_plain_color); + base_bg_style.body.main_color = LV_COLOR_HEX(0x2D2D2D); + base_bg_style.body.grad_color = LV_COLOR_HEX(0x2D2D2D); + lv_cont_set_style(cnr, &base_bg_style); + lv_obj_set_size(cnr, LV_HOR_RES, LV_VER_RES); + + if (hekate_bg) + { + lv_obj_t *img = lv_img_create(cnr, NULL); + lv_img_set_src(img, hekate_bg); + } + + // Add tabview page to screen. + lv_obj_t *tv = lv_tabview_create(scr, NULL); + if (hekate_bg) + { + lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_PR, &tabview_btn_pr); + lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_TGL_PR, &tabview_btn_tgl_pr); + } + lv_tabview_set_sliding(tv, false); + lv_obj_set_size(tv, LV_HOR_RES, LV_VER_RES); + + // Add all tabs content. + char version[32]; + s_printf(version, "hekate v%d.%d.%d", nyx_str->version & 0xFF, (nyx_str->version >> 8) & 0xFF, (nyx_str->version >> 16) & 0xFF); + lv_obj_t *tab_about = lv_tabview_add_tab(tv, version); + + lv_obj_t *tab_home = lv_tabview_add_tab(tv, SYMBOL_HOME" Home"); + + lv_obj_t *tab_tools = lv_tabview_add_tab(tv, SYMBOL_TOOLS" Tools"); + lv_page_set_style(tab_tools, LV_PAGE_STYLE_BG, &no_padding); + lv_page_set_style(tab_tools, LV_PAGE_STYLE_SCRL, &no_padding); + + lv_obj_t *tab_info = lv_tabview_add_tab(tv, SYMBOL_INFO" Console Info"); + lv_page_set_style(tab_info, LV_PAGE_STYLE_BG, &no_padding); + lv_page_set_style(tab_info, LV_PAGE_STYLE_SCRL, &no_padding); + + lv_obj_t *tab_options = lv_tabview_add_tab(tv, SYMBOL_SETTINGS" Options"); + + _create_tab_about(th, tab_about); + _create_tab_home(th, tab_home); + create_tab_tools(th, tab_tools); + create_tab_info(th, tab_info); + _create_tab_options(th, tab_options); + + lv_tabview_set_tab_act(tv, 1, false); + + // Create status bar. + _create_status_bar(th); + + // Create tasks. + system_tasks.task.dram_periodic_comp = lv_task_create(minerva_periodic_training, 500, LV_TASK_PRIO_HIGHEST, NULL); + lv_task_ready(system_tasks.task.status_bar); + + system_tasks.task.status_bar = lv_task_create(_update_status_bar, 5000, LV_TASK_PRIO_LOW, NULL); + lv_task_ready(system_tasks.task.status_bar); + + lv_task_create(_check_sd_card_removed, 2000, LV_TASK_PRIO_LOWEST, NULL); + + // Create top level global line separators. + lv_obj_t *line = lv_cont_create(lv_layer_top(), NULL); + + static lv_style_t line_style; + lv_style_copy(&line_style, &lv_style_plain_color); + + line_style.body.main_color = LV_COLOR_HEX3(0xDDD); // 0x505050 + line_style.body.grad_color = line_style.body.main_color; + line_style.body.shadow.width = 0; + + lv_cont_set_style(line, &line_style); + lv_obj_set_size(line, LV_HOR_RES - LV_DPI * 3 / 5, 1); + lv_obj_set_pos(line, LV_DPI * 3 / 10, 63); + + lv_obj_set_top(line, true); + + line = lv_cont_create(lv_layer_top(), line); + lv_obj_set_pos(line, LV_DPI * 3 / 10, 656); + lv_obj_set_top(line, true); + + // Option save button. + lv_tabview_set_tab_load_action(tv, _show_hide_save_button); + + // If we rebooted to run sept for dumping, lunch dump immediately. + if (nyx_str->cfg & NYX_CFG_DUMP) + { + nyx_str->cfg &= ~(NYX_CFG_DUMP); + lv_task_t *task_run_dump = lv_task_create(sept_run_dump, 0, LV_TASK_PRIO_MID, NULL); + lv_task_once(task_run_dump); + } +} + +#pragma GCC pop_options + +void nyx_load_and_run() +{ + memset(&system_tasks, 0, sizeof(system_maintenance_tasks_t)); + + lv_init(); + gfx_con.fillbg = 1; + + // Initialize framebuffer drawing functions. + lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); + disp_drv.disp_flush = _disp_fb_flush; + lv_disp_drv_register(&disp_drv); + + // Initialize touch. + touch_power_on(); + lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read = _fts_touch_read; + lv_indev_drv_register(&indev_drv); + touchpad.touch = false; + + //Set the theme. + //! TODO: Finish theme support. + lv_theme_t *th = lv_theme_hekate_init(167, NULL); + lv_theme_set_current(th); + + _nyx_main_menu(th); + + while (true) + lv_task_handler(); +} diff --git a/nyx/nyx_gui/frontend/gui.h b/nyx/nyx_gui/frontend/gui.h new file mode 100644 index 0000000..7c884bc --- /dev/null +++ b/nyx/nyx_gui/frontend/gui.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _GUI_H_ +#define _GUI_H_ + +#include "../libs/lvgl/lvgl.h" + +typedef struct _emmc_tool_gui_t +{ + lv_obj_t *label_log; + lv_obj_t *label_info; + lv_obj_t *label_pct; + lv_obj_t *label_finish; + lv_obj_t *bar; + lv_style_t *bar_teal_bg; + lv_style_t *bar_white_ind; + char *txt_buf; + char *base_path; + bool raw_emummc; +} emmc_tool_gui_t; + +lv_style_t hint_small_style; +lv_style_t hint_small_style_white; +lv_style_t monospace_text; + +lv_obj_t *payload_list; + +lv_img_dsc_t *icon_switch; +lv_img_dsc_t *icon_payload; +lv_img_dsc_t *icon_lakka; + +lv_img_dsc_t *hekate_bg; + +lv_style_t btn_transp_rel, btn_transp_pr, btn_transp_tgl_rel, btn_transp_tgl_pr; +lv_style_t ddlist_transp_bg, ddlist_transp_sel; +lv_style_t tabview_btn_pr, tabview_btn_tgl_pr; + +lv_style_t mbox_darken; + +lv_img_dsc_t *bmp_to_lvimg_obj(const char *path); +lv_res_t mbox_action(lv_obj_t * btns, const char * txt); +void nyx_window_toggle_buttons(lv_obj_t *win, bool disable); +lv_obj_t *nyx_create_standard_window(const char *win_title); +void nyx_create_onoff_button(lv_theme_t *th, lv_obj_t *parent, lv_obj_t *btn, const char *btn_name, lv_action_t action, bool transparent); +lv_res_t nyx_generic_onoff_toggle(lv_obj_t *btn); +void manual_system_maintenance(bool refresh); +void nyx_load_and_run(); + +#endif diff --git a/nyx/nyx_gui/frontend/gui_emmc_tools.c b/nyx/nyx_gui/frontend/gui_emmc_tools.c new file mode 100644 index 0000000..036cd92 --- /dev/null +++ b/nyx/nyx_gui/frontend/gui_emmc_tools.c @@ -0,0 +1,458 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "gui.h" +#include "gui_emmc_tools.h" +#include "fe_emmc_tools.h" +#include "../config/config.h" +#include "../hos/pkg1.h" +#include "../hos/pkg2.h" +#include "../hos/hos.h" +#include "../hos/sept.h" +#include "../libs/fatfs/ff.h" +#include "../mem/heap.h" +#include "../sec/se.h" +#include "../soc/fuse.h" +#include "../storage/nx_emmc.h" +#include "../storage/sdmmc.h" +#include "../utils/sprintf.h" +#include "../utils/util.h" + +extern boot_cfg_t b_cfg; +extern hekate_config h_cfg; + +extern bool sd_mount(); +extern int sd_save_to_file(void *buf, u32 size, const char *filename); +extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); + +#pragma GCC push_options +#pragma GCC target ("thumb") + +typedef struct _emmc_backup_buttons_t +{ + lv_obj_t *emmc_boot; + lv_obj_t *emmc_raw_gpp; + lv_obj_t *emmc_sys; + lv_obj_t *emmc_usr; + bool raw_emummc; + bool restore; +} emmc_backup_buttons_t; + +static emmc_backup_buttons_t emmc_btn_ctxt; + +static void _create_window_backup_restore(emmcPartType_t type, const char* win_label) +{ + emmc_tool_gui_t emmc_tool_gui_ctxt; + + emmc_tool_gui_ctxt.raw_emummc = emmc_btn_ctxt.raw_emummc; + + lv_obj_t *win = nyx_create_standard_window(win_label); + + //Disable buttons. + nyx_window_toggle_buttons(win, true); + + // Create important info container. + lv_obj_t *h1 = lv_cont_create(win, NULL); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 5); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + static lv_style_t h_style; + lv_style_copy(&h_style, lv_cont_get_style(h1)); + h_style.body.main_color = LV_COLOR_HEX(0x1d1d1d); + h_style.body.grad_color = h_style.body.main_color; + h_style.body.opa = LV_OPA_COVER; + + // Create log container. + lv_obj_t *h2 = lv_cont_create(win, h1); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, false); + lv_obj_set_size(h2, (LV_HOR_RES / 11) * 4, LV_DPI * 5); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, 0, LV_DPI / 5); + + lv_obj_t *label_log = lv_label_create(h2, NULL); + lv_label_set_recolor(label_log, true); + lv_obj_set_style(label_log, &monospace_text); + lv_label_set_long_mode(label_log, LV_LABEL_LONG_BREAK); + lv_label_set_static_text(label_log, ""); + lv_obj_set_width(label_log, lv_obj_get_width(h2)); + lv_obj_align(label_log, h2, LV_ALIGN_IN_TOP_LEFT, LV_DPI / 10, LV_DPI / 10); + emmc_tool_gui_ctxt.label_log = label_log; + + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + // Create info elements. + lv_obj_t *label_info = lv_label_create(h1, NULL); + lv_label_set_recolor(label_info, true); + lv_obj_set_width(label_info, lv_obj_get_width(h1)); + lv_label_set_static_text(label_info, "\n\n\n\n\n\n\n\n\n"); + lv_obj_set_style(label_info, lv_theme_get_current()->label.prim); + lv_obj_align(label_info, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 10); + emmc_tool_gui_ctxt.label_info = label_info; + + lv_style_t *bar_teal_bg, *bar_white_ind; + bar_teal_bg = (lv_style_t *)malloc(sizeof(lv_style_t)); + bar_white_ind = (lv_style_t *)malloc(sizeof(lv_style_t)); + + lv_style_copy(bar_teal_bg, lv_theme_get_current()->bar.bg); + bar_teal_bg->body.main_color = LV_COLOR_HEX(0x005a47); + bar_teal_bg->body.grad_color = bar_teal_bg->body.main_color; + + lv_style_copy(bar_white_ind, lv_theme_get_current()->bar.indic); + bar_white_ind->body.main_color = LV_COLOR_HEX(0xF0F0F0); + bar_white_ind->body.grad_color = bar_white_ind->body.main_color; + + emmc_tool_gui_ctxt.bar_teal_bg = bar_teal_bg; + emmc_tool_gui_ctxt.bar_white_ind = bar_white_ind; + + lv_obj_t * bar = lv_bar_create(h1, NULL); + lv_obj_set_size(bar, LV_DPI * 38 / 10, LV_DPI / 5); + lv_bar_set_range(bar, 0, 100); + lv_bar_set_value(bar, 0); + lv_obj_align(bar, label_info, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 8); + lv_obj_set_opa_scale(bar, LV_OPA_0); + lv_obj_set_opa_scale_enable(bar, true); + emmc_tool_gui_ctxt.bar = bar; + + lv_obj_t *label_pct= lv_label_create(h1, NULL); + lv_label_set_recolor(label_pct, true); + lv_label_set_static_text(label_pct, " "SYMBOL_DOT" 0%"); + lv_obj_set_style(label_pct, lv_theme_get_current()->label.prim); + lv_obj_align(label_pct, bar, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 20, 0); + lv_obj_set_opa_scale(label_pct, LV_OPA_0); + lv_obj_set_opa_scale_enable(label_pct, true); + emmc_tool_gui_ctxt.label_pct = label_pct; + + lv_obj_t *label_finish = lv_label_create(h1, NULL); + lv_label_set_recolor(label_finish, true); + lv_label_set_static_text(label_finish, ""); + lv_obj_set_style(label_finish, lv_theme_get_current()->label.prim); + lv_obj_align(label_finish, bar, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 9 / 20); + emmc_tool_gui_ctxt.label_finish = label_finish; + + if (!emmc_btn_ctxt.restore) + dump_emmc_selected(type, &emmc_tool_gui_ctxt); + else + restore_emmc_selected(type, &emmc_tool_gui_ctxt); + + nyx_window_toggle_buttons(win, false); + + free(bar_teal_bg); + free(bar_white_ind); +} + +static lv_res_t _emmc_backup_buttons_decider(lv_obj_t *btn) +{ + char *win_label = lv_label_get_text(lv_obj_get_child(btn, NULL)); + + if (emmc_btn_ctxt.emmc_boot == btn) + _create_window_backup_restore(PART_BOOT, win_label); + else if (emmc_btn_ctxt.emmc_raw_gpp == btn) + _create_window_backup_restore(PART_RAW, win_label); + else if (emmc_btn_ctxt.emmc_sys == btn) + { + if (!emmc_btn_ctxt.restore) + _create_window_backup_restore(PART_SYSTEM, win_label); + else + _create_window_backup_restore(PART_GP_ALL, win_label); + } + else if (!emmc_btn_ctxt.restore && emmc_btn_ctxt.emmc_usr == btn) + _create_window_backup_restore(PART_USER, win_label); + + return LV_RES_OK; +} + +static lv_res_t _emmc_backup_buttons_raw_toggle(lv_obj_t *btn) +{ + nyx_generic_onoff_toggle(btn); + + lv_obj_set_click(emmc_btn_ctxt.emmc_boot, true); + lv_btn_set_state(emmc_btn_ctxt.emmc_boot, LV_BTN_STATE_REL); + lv_obj_set_click(emmc_btn_ctxt.emmc_raw_gpp, true); + lv_btn_set_state(emmc_btn_ctxt.emmc_raw_gpp, LV_BTN_STATE_REL); + + lv_obj_set_click(emmc_btn_ctxt.emmc_sys, true); + lv_btn_set_state(emmc_btn_ctxt.emmc_sys, LV_BTN_STATE_REL); + + // Backup/Restore from and to eMMC. + if (!(lv_btn_get_state(btn) & LV_BTN_STATE_TGL_REL)) + { + if (!emmc_btn_ctxt.restore) + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_boot, NULL), SYMBOL_UPLOAD" eMMC BOOT0 & BOOT1"); + else + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_boot, NULL), SYMBOL_DOWNLOAD" eMMC BOOT0 & BOOT1"); + lv_obj_realign(emmc_btn_ctxt.emmc_boot); + + if (!emmc_btn_ctxt.restore) + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_raw_gpp, NULL), SYMBOL_DOWNLOAD" eMMC RAW GPP"); + else + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_raw_gpp, NULL), SYMBOL_DOWNLOAD" eMMC RAW GPP"); + lv_obj_realign(emmc_btn_ctxt.emmc_raw_gpp); + + if (!emmc_btn_ctxt.restore) + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_sys, NULL), SYMBOL_MODULES" eMMC SYS"); + else + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_sys, NULL), SYMBOL_MODULES" eMMC ALL"); + lv_obj_realign(emmc_btn_ctxt.emmc_sys); + + if (!emmc_btn_ctxt.restore) + { + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_usr, NULL), SYMBOL_MODULES_ALT" eMMC USER"); + lv_obj_realign(emmc_btn_ctxt.emmc_usr); + + lv_obj_set_click(emmc_btn_ctxt.emmc_usr, true); + lv_btn_set_state(emmc_btn_ctxt.emmc_usr, LV_BTN_STATE_REL); + } + + emmc_btn_ctxt.raw_emummc = false; + } + else // Backup/Restore from and to emuMMC. + { + if (!emmc_btn_ctxt.restore) + { + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_boot, NULL), SYMBOL_UPLOAD" SD emuMMC BOOT0 & BOOT1"); + lv_obj_set_click(emmc_btn_ctxt.emmc_boot, false); + lv_btn_set_state(emmc_btn_ctxt.emmc_boot, LV_BTN_STATE_INA); + } + else + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_boot, NULL), SYMBOL_DOWNLOAD" SD emuMMC BOOT0 & BOOT1"); + lv_obj_realign(emmc_btn_ctxt.emmc_boot); + + if (!emmc_btn_ctxt.restore) + { + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_raw_gpp, NULL), SYMBOL_DOWNLOAD" SD emuMMC RAW GPP"); + lv_obj_set_click(emmc_btn_ctxt.emmc_raw_gpp, false); + lv_btn_set_state(emmc_btn_ctxt.emmc_raw_gpp, LV_BTN_STATE_INA); + } + else + lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_raw_gpp, NULL), SYMBOL_DOWNLOAD" SD emuMMC RAW GPP"); + lv_obj_realign(emmc_btn_ctxt.emmc_raw_gpp); + + lv_obj_set_click(emmc_btn_ctxt.emmc_sys, false); + lv_btn_set_state(emmc_btn_ctxt.emmc_sys, LV_BTN_STATE_INA); + + if (!emmc_btn_ctxt.restore) + { + lv_obj_set_click(emmc_btn_ctxt.emmc_usr, false); + lv_btn_set_state(emmc_btn_ctxt.emmc_usr, LV_BTN_STATE_INA); + } + + emmc_btn_ctxt.raw_emummc = true; + } + + return LV_RES_OK; +} + +lv_res_t create_window_backup_restore_tool(lv_obj_t *btn) +{ + lv_obj_t *win; + + emmc_btn_ctxt.restore = false; + if (strcmp(lv_label_get_text(lv_obj_get_child(btn, NULL)), SYMBOL_UPLOAD" Backup eMMC")) + emmc_btn_ctxt.restore = true; + + if (!emmc_btn_ctxt.restore) + win = nyx_create_standard_window(SYMBOL_SD" Backup"); + else + win = nyx_create_standard_window(SYMBOL_SD" Restore"); + + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = 0; + h_style.body.padding.hor = LV_DPI - (LV_DPI / 4); + h_style.body.padding.ver = LV_DPI / 9; + + // Create Full container. + lv_obj_t *h1 = lv_cont_create(win, NULL); + lv_cont_set_style(h1, &h_style); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt = lv_label_create(h1, NULL); + lv_label_set_static_text(label_txt, "Full"); + lv_obj_set_style(label_txt, lv_theme_get_current()->label.prim); + lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI * 3 / 10); + + lv_obj_t *line_sep = lv_line_create(h1, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, lv_theme_get_current()->line.decor); + lv_obj_align(line_sep, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create BOOT0 & BOOT1 button. + lv_obj_t *btn1 = lv_btn_create(h1, NULL); + lv_obj_t *label_btn = lv_label_create(btn1, NULL); + lv_btn_set_fit(btn1, true, true); + if (!emmc_btn_ctxt.restore) + lv_label_set_static_text(label_btn, SYMBOL_UPLOAD" eMMC BOOT0 & BOOT1"); + else + lv_label_set_static_text(label_btn, SYMBOL_DOWNLOAD" eMMC BOOT0 & BOOT1"); + + lv_obj_align(btn1, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, _emmc_backup_buttons_decider); + emmc_btn_ctxt.emmc_boot = btn1; + + lv_obj_t *label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + if (!emmc_btn_ctxt.restore) + { + lv_label_set_static_text(label_txt2, + "Allows you to backup your BOOT physical partitions.\n" + "They contain your BCT, keys and various package1.\n" + "#FF8000 These are paired with the RAW GPP backup.#"); + } + else + { + lv_label_set_static_text(label_txt2, + "Allows you to restore your BOOT physical partitions.\n" + "They contain your BCT, keys and various package1.\n" + "#FF8000 These are paired with the RAW GPP restore.#"); + } + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create RAW GPP button. + lv_obj_t *btn2 = lv_btn_create(h1, btn1); + label_btn = lv_label_create(btn2, NULL); + if (!emmc_btn_ctxt.restore) + lv_label_set_static_text(label_btn, SYMBOL_UPLOAD" eMMC RAW GPP"); + else + lv_label_set_static_text(label_btn, SYMBOL_DOWNLOAD" eMMC RAW GPP"); + lv_obj_align(btn2, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); + lv_btn_set_action(btn2, LV_BTN_ACTION_CLICK, _emmc_backup_buttons_decider); + emmc_btn_ctxt.emmc_raw_gpp= btn2; + + label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + if (!emmc_btn_ctxt.restore) + { + lv_label_set_static_text(label_txt2, + "Allows you to backup your GPP physical partition.\n" + "It contains, CAL0, various package2, SYSTEM, USER, etc.\n" + "#FF8000 This is paired with the BOOT0/1 backups.#"); + } + else + { + lv_label_set_static_text(label_txt2, + "Allows you to restore your GPP physical partition.\n" + "It contains, CAL0, various package2, SYSTEM, USER, etc.\n" + "#FF8000 This is paired with the BOOT0/1 restore.#"); + } + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create GPP Partitions container. + lv_obj_t *h2 = lv_cont_create(win, NULL); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, true); + lv_obj_set_width(h2, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h2, false); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI * 17 / 29, 0); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt3 = lv_label_create(h2, NULL); + lv_label_set_static_text(label_txt3, "GPP Partitions"); + lv_obj_set_style(label_txt3, lv_theme_get_current()->label.prim); + lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI * 4 / 21); + + line_sep = lv_line_create(h2, line_sep); + lv_obj_align(line_sep, label_txt3, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create SYS/ALL button. + lv_obj_t *btn3 = lv_btn_create(h2, NULL); + label_btn = lv_label_create(btn3, NULL); + lv_btn_set_fit(btn3, true, true); + if (!emmc_btn_ctxt.restore) + lv_label_set_static_text(label_btn, SYMBOL_MODULES" eMMC SYS"); + else + lv_label_set_static_text(label_btn, SYMBOL_MODULES" eMMC ALL"); + lv_obj_align(btn3, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + lv_btn_set_action(btn3, LV_BTN_ACTION_CLICK, _emmc_backup_buttons_decider); + emmc_btn_ctxt.emmc_sys = btn3; + + lv_obj_t *label_txt4 = lv_label_create(h2, NULL); + lv_label_set_recolor(label_txt4, true); + if (!emmc_btn_ctxt.restore) + { + lv_label_set_static_text(label_txt4, + "Allows you to backup the partitions from RAW GPP except\n" + "USER. It contains, CAL0, various package2, SYSTEM, etc.\n" + "#FF8000 This is an incomplete backup.#"); + } + else + { + lv_label_set_static_text(label_txt4, + "Allows you to restore ALL partitions from RAW GPP\n" + "It contains, CAL0, various package2, SYSTEM, USER, etc.\n"); + } + + lv_obj_set_style(label_txt4, &hint_small_style); + lv_obj_align(label_txt4, btn3, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create USER button. + if (!emmc_btn_ctxt.restore) + { + lv_obj_t *btn4 = lv_btn_create(h2, btn1); + label_btn = lv_label_create(btn4, NULL); + lv_label_set_static_text(label_btn, SYMBOL_MODULES_ALT" eMMC USER"); + lv_obj_align(btn4, label_txt4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); + lv_btn_set_action(btn4, LV_BTN_ACTION_CLICK, _emmc_backup_buttons_decider); + emmc_btn_ctxt.emmc_usr = btn4; + + label_txt4 = lv_label_create(h2, NULL); + lv_label_set_recolor(label_txt4, true); + lv_label_set_static_text(label_txt4, + "Allows you to backup the USER partition from RAW GPP.\n" + "#FF8000 This is an incomplete backup.#\n"); + lv_obj_set_style(label_txt4, &hint_small_style); + lv_obj_align(label_txt4, btn4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + } + else + { + emmc_btn_ctxt.emmc_usr = NULL; + } + + // Create eMMC/emuMMC On/Off button. + lv_obj_t *h3 = lv_cont_create(win, NULL); + lv_cont_set_style(h3, &h_style); + lv_cont_set_fit(h3, false, true); + lv_obj_set_width(h3, (LV_HOR_RES / 10) * 4); + lv_obj_set_click(h3, false); + lv_cont_set_layout(h3, LV_LAYOUT_OFF); + lv_obj_align(h3, h1, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI * 38 / 11, LV_DPI / 7); + + lv_obj_t *sd_emummc_raw = lv_btn_create(h3, NULL); + nyx_create_onoff_button(lv_theme_get_current(), h3, + sd_emummc_raw, SYMBOL_SD" SD emuMMC Raw Partition", _emmc_backup_buttons_raw_toggle, false); + emmc_btn_ctxt.raw_emummc = false; + + return LV_RES_OK; +} + +#pragma GCC pop_options diff --git a/nyx/nyx_gui/frontend/gui_emmc_tools.h b/nyx/nyx_gui/frontend/gui_emmc_tools.h new file mode 100644 index 0000000..1bc031f --- /dev/null +++ b/nyx/nyx_gui/frontend/gui_emmc_tools.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _GUI_EMMC_TOOLS_H_ +#define _GUI_EMMC_TOOLS_H_ + +#include "../libs/lvgl/lvgl.h" + +lv_res_t create_window_backup_restore_tool(lv_obj_t *btn); + +#endif diff --git a/nyx/nyx_gui/frontend/gui_emummc_tools.c b/nyx/nyx_gui/frontend/gui_emummc_tools.c new file mode 100644 index 0000000..626f287 --- /dev/null +++ b/nyx/nyx_gui/frontend/gui_emummc_tools.c @@ -0,0 +1,1183 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "gui.h" +#include "fe_emummc_tools.h" +#include "../config/ini.h" +#include "../libs/fatfs/ff.h" +#include "../storage/sdmmc.h" +#include "../utils/dirlist.h" +#include "../utils/list.h" +#include "../utils/sprintf.h" +#include "../utils/types.h" + +extern sdmmc_t sd_sdmmc; +extern sdmmc_storage_t sd_storage; + +extern bool sd_mount(); +extern void sd_unmount(bool deinit); +extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); + +#define MBR_1ST_PART_TYPE_OFF 0x1C2 + +static int part_idx; +static u32 sector_start; + +#pragma GCC push_options +#pragma GCC target ("thumb") + +static void _create_window_emummc() +{ + emmc_tool_gui_t emmc_tool_gui_ctxt; + + lv_obj_t *win; + if (!part_idx) + win = nyx_create_standard_window(SYMBOL_DRIVE" Create SD File emuMMC"); + else + win = nyx_create_standard_window(SYMBOL_DRIVE" Create SD Partition emuMMC"); + + //Disable buttons. + nyx_window_toggle_buttons(win, true); + + // Chreate important info container. + lv_obj_t *h1 = lv_cont_create(win, NULL); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 5); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + static lv_style_t h_style; + lv_style_copy(&h_style, lv_cont_get_style(h1)); + h_style.body.main_color = LV_COLOR_HEX(0x1d1d1d); + h_style.body.grad_color = h_style.body.main_color; + h_style.body.opa = LV_OPA_COVER; + + // Chreate log container. + lv_obj_t *h2 = lv_cont_create(win, h1); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, false); + lv_obj_set_size(h2, (LV_HOR_RES / 11) * 4, LV_DPI * 5); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, 0, LV_DPI / 5); + + lv_obj_t *label_log = lv_label_create(h2, NULL); + lv_label_set_recolor(label_log, true); + lv_obj_set_style(label_log, &monospace_text); + lv_label_set_long_mode(label_log, LV_LABEL_LONG_BREAK); + lv_label_set_static_text(label_log, ""); + lv_obj_set_width(label_log, lv_obj_get_width(h2)); + lv_obj_align(label_log, h2, LV_ALIGN_IN_TOP_LEFT, LV_DPI / 10, LV_DPI / 10); + emmc_tool_gui_ctxt.label_log = label_log; + + // Create elements for info container. + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_info = lv_label_create(h1, NULL); + lv_label_set_recolor(label_info, true); + lv_obj_set_width(label_info, lv_obj_get_width(h1)); + lv_label_set_static_text(label_info, "\n\n\n\n\n\n\n\n\n"); + lv_obj_set_style(label_info, lv_theme_get_current()->label.prim); + lv_obj_align(label_info, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 10); + emmc_tool_gui_ctxt.label_info = label_info; + + lv_obj_t * bar = lv_bar_create(h1, NULL); + lv_obj_set_size(bar, LV_DPI * 38 / 10, LV_DPI / 5); + lv_bar_set_range(bar, 0, 100); + lv_bar_set_value(bar, 0); + lv_obj_align(bar, label_info, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 8); + lv_obj_set_opa_scale(bar, LV_OPA_0); + lv_obj_set_opa_scale_enable(bar, true); + emmc_tool_gui_ctxt.bar = bar; + + lv_obj_t *label_pct= lv_label_create(h1, NULL); + lv_label_set_recolor(label_pct, true); + lv_label_set_static_text(label_pct, " "SYMBOL_DOT" 0%"); + lv_obj_set_style(label_pct, lv_theme_get_current()->label.prim); + lv_obj_align(label_pct, bar, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 20, 0); + lv_obj_set_opa_scale(label_pct, LV_OPA_0); + lv_obj_set_opa_scale_enable(label_pct, true); + emmc_tool_gui_ctxt.label_pct = label_pct; + + lv_obj_t *label_finish = lv_label_create(h1, NULL); + lv_label_set_recolor(label_finish, true); + lv_label_set_static_text(label_finish, ""); + lv_obj_set_style(label_finish, lv_theme_get_current()->label.prim); + lv_obj_align(label_finish, bar, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 9 / 20); + emmc_tool_gui_ctxt.label_finish = label_finish; + + if (!part_idx) + dump_emummc_file(&emmc_tool_gui_ctxt); + else + dump_emummc_raw(&emmc_tool_gui_ctxt, part_idx, sector_start); + + nyx_window_toggle_buttons(win, false); +} + + +static lv_res_t _create_emummc_raw_action(lv_obj_t * btns, const char * txt) +{ + int btn_idx = lv_btnm_get_pressed(btns); + lv_obj_t *bg = lv_obj_get_parent(lv_obj_get_parent(btns)); + + if (!btn_idx) + { + lv_obj_set_style(bg, &lv_style_transp); + _create_window_emummc(); + } + + part_idx = 0; + sector_start = 0; + + mbox_action(btns, txt); + + return LV_RES_INV; +} + +static void _create_mbox_emummc_raw() +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char *mbox_btn_map[] = { "\222Continue", "\222Cancel", "" }; + static const char *mbox_btn_map2[] = { "\211", "OK", "\211", "" }; + lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES / 9 * 6); + + char *txt_buf = (char *)malloc(0x500); + u8 *mbr = (u8 *)malloc(0x200); + + sd_mount(); + sdmmc_storage_read(&sd_storage, 0, 1, mbr); + sd_unmount(false); + memcpy(mbr, mbr + 0x1BE, 0x40); + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4); + + for (int i = 1; i < 4; i++) + { + u32 curr_part_size = *(u32 *)&mbr[0x0C + (0x10 * i)]; + sector_start = *(u32 *)&mbr[0x08 + (0x10 * i)]; + u8 type = mbr[0x04 + (0x10 * i)]; + if ((curr_part_size > storage.sec_cnt) && sector_start && type != 0x83) //! TODO: For now it skips linux partitions. + { + part_idx = i; + sector_start += 0x8000; + break; + } + } + + sdmmc_storage_end(&storage); + + if (part_idx) + { + s_printf(txt_buf, + "#C7EA46 Found applicable partition [%d]!#\n" + "#FF8000 Do you want to continue?#\n\n", part_idx); + } + else + s_printf(txt_buf, "Failed to find applicable partition!\n\n"); + + s_printf(txt_buf + strlen(txt_buf), + "Partition table:\n" + "Part 0: Type: %02x, Start: %08x, Size: %08x\n" + "Part 1: Type: %02x, Start: %08x, Size: %08x\n" + "Part 2: Type: %02x, Start: %08x, Size: %08x\n" + "Part 3: Type: %02x, Start: %08x, Size: %08x\n", + mbr[0x04], *(u32 *)&mbr[0x08], *(u32 *)&mbr[0x0C], + mbr[0x14], *(u32 *)&mbr[0x18], *(u32 *)&mbr[0x1C], + mbr[0x24], *(u32 *)&mbr[0x28], *(u32 *)&mbr[0x2C], + mbr[0x34], *(u32 *)&mbr[0x38], *(u32 *)&mbr[0x3C]); + + + lv_mbox_set_text(mbox, txt_buf); + free(txt_buf); + free(mbr); + + if (part_idx) + lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_raw_action); + else + lv_mbox_add_btns(mbox, mbox_btn_map2, mbox_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); +} + +static lv_res_t _create_emummc_action(lv_obj_t * btns, const char * txt) +{ + int btn_idx = lv_btnm_get_pressed(btns); + lv_obj_t *bg = lv_obj_get_parent(lv_obj_get_parent(btns)); + + part_idx = 0; + sector_start = 0; + + switch (btn_idx) + { + case 0: + lv_obj_set_style(bg, &lv_style_transp); + _create_window_emummc(); + break; + case 1: + _create_mbox_emummc_raw(); + // if available. have max 3 buttons. if selected and used, ask to use the backup tool. + break; + } + + mbox_action(btns, txt); + + return LV_RES_INV; +} + +static lv_res_t _create_mbox_emummc_create(lv_obj_t *btn) +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\222SD File", "\222SD Partition", "\222Cancel", "" }; + lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES / 9 * 6); + + lv_mbox_set_text(mbox, + "Welcome to #C7EA46 emuMMC# creation tool!\n\n" + "Please choose what type of emuMMC you want to create.\n" + "#FF8000 SD File# is saved as files in your FAT partition.\n" + "#FF8000 SD Partition# is saved as raw image in an available partition."); + + lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + return LV_RES_OK; +} + +static void _change_raw_emummc_part_type() +{ + u8 *mbr = (u8 *)malloc(0x200); + sdmmc_storage_read(&sd_storage, 0, 1, mbr); + mbr[MBR_1ST_PART_TYPE_OFF + (0x10 * part_idx)] = 0xEE; + sdmmc_storage_write(&sd_storage, 0, 1, mbr); + free(mbr); +} + +static void _migrate_sd_raw_based() +{ + sector_start += 2; + + sd_mount(); + f_mkdir("emuMMC"); + f_mkdir("emuMMC/ER00"); + + f_rename("Emutendo", "emuMMC/ER00/Nintendo"); + FIL fp; + f_open(&fp, "emuMMC/ER00/raw_based", FA_CREATE_ALWAYS | FA_WRITE); + f_write(&fp, §or_start, 4, NULL); + f_close(&fp); + + _change_raw_emummc_part_type(); + + save_emummc_cfg(1, sector_start, "emuMMC/ER00"); + sd_unmount(false); +} + +static void _migrate_sd_raw_emummc_based() +{ + char *tmp = (char *)malloc(0x80); + s_printf(tmp, "emuMMC/RAW%d", part_idx); + + sd_mount(); + f_mkdir("emuMMC"); + f_mkdir(tmp); + strcat(tmp, "/raw_based"); + + FIL fp; + if (!f_open(&fp, tmp, FA_CREATE_ALWAYS | FA_WRITE)) + { + f_write(&fp, §or_start, 4, NULL); + f_close(&fp); + } + + s_printf(tmp, "emuMMC/RAW%d", part_idx); + + _change_raw_emummc_part_type(); + + save_emummc_cfg(part_idx, sector_start, tmp); + + free(tmp); + + sd_unmount(false); +} + +static void _migrate_sd_file_based() +{ + sd_mount(); + f_mkdir("emuMMC"); + f_mkdir("emuMMC/EF00"); + + f_rename("Emutendo", "emuMMC/EF00/Nintendo"); + FIL fp; + f_open(&fp, "emuMMC/EF00/file_based", FA_CREATE_ALWAYS | FA_WRITE); + f_close(&fp); + + char *path = (char *)malloc(128); + char *path2 = (char *)malloc(128); + s_printf(path, "%c%c%c%c%s", 's', 'x', 'o', 's', "/emunand"); + f_rename(path, "emuMMC/EF00/eMMC"); + + for (int i = 0; i < 2; i++) + { + s_printf(path, "emuMMC/EF00/eMMC/boot%d.bin", i); + s_printf(path2, "emuMMC/EF00/eMMC/BOOT%d", i); + f_rename(path, path2); + } + for (int i = 0; i < 8; i++) + { + s_printf(path, "emuMMC/EF00/eMMC/full.%02d.bin", i); + s_printf(path2, "emuMMC/EF00/eMMC/%02d", i); + f_rename(path, path2); + } + + free(path); + free(path2); + + save_emummc_cfg(0, 0, "emuMMC/EF00"); + sd_unmount(false); +} + +static void _migrate_sd_backup_file_based() +{ + sd_mount(); + f_mkdir("emuMMC"); + f_mkdir("emuMMC/BK00"); + f_mkdir("emuMMC/BK00/eMMC"); + + FIL fp; + f_open(&fp, "emuMMC/BK00/file_based", FA_CREATE_ALWAYS | FA_WRITE); + f_close(&fp); + + char *path = (char *)malloc(128); + char *path2 = (char *)malloc(128); + char *path3 = (char *)malloc(128); + + emmcsn_path_impl(path, "", "", NULL); + + s_printf(path2, "%s/BOOT0", path); + f_rename(path2, "emuMMC/BK00/eMMC/BOOT0"); + + s_printf(path2, "%s/BOOT1", path); + f_rename(path2, "emuMMC/BK00/eMMC/BOOT1"); + + bool multipart = false; + s_printf(path2, "%s/rawnand.bin", path); + + FILINFO fno; + + if(f_stat(path2, &fno)) + multipart = true; + + if (!multipart) + f_rename(path2, "emuMMC/BK00/eMMC/00"); + else + { + for (int i = 0; i < 32; i++) + { + s_printf(path2, "%s/rawnand.bin.%02d", path, i); + s_printf(path3, "emuMMC/BK00/eMMC/%02d", i); + if (f_rename(path2, path3)) + break; + } + } + + free(path); + free(path2); + free(path3); + + save_emummc_cfg(0, 0, "emuMMC/BK00"); + sd_unmount(false); +} + +static lv_res_t _create_emummc_mig1_action(lv_obj_t * btns, const char * txt) +{ + switch (lv_btnm_get_pressed(btns)) + { + case 0: + _migrate_sd_file_based(); + break; + case 1: + _migrate_sd_raw_based(); + break; + } + + part_idx = 0; + sector_start = 0; + + mbox_action(btns, txt); + + return LV_RES_INV; +} + +static lv_res_t _create_emummc_mig0_action(lv_obj_t * btns, const char * txt) +{ + switch (lv_btnm_get_pressed(btns)) + { + case 0: + _migrate_sd_file_based(); + break; + } + + part_idx = 0; + sector_start = 0; + + mbox_action(btns, txt); + + return LV_RES_INV; +} + +static lv_res_t _create_emummc_mig2_action(lv_obj_t * btns, const char * txt) +{ + switch (lv_btnm_get_pressed(btns)) + { + case 0: + _migrate_sd_raw_based(); + break; + } + + part_idx = 0; + sector_start = 0; + + mbox_action(btns, txt); + + return LV_RES_INV; +} + +static lv_res_t _create_emummc_mig3_action(lv_obj_t * btns, const char * txt) +{ + switch (lv_btnm_get_pressed(btns)) + { + case 0: + _migrate_sd_raw_emummc_based(); + break; + } + + part_idx = 0; + sector_start = 0; + + mbox_action(btns, txt); + + return LV_RES_INV; +} + +static lv_res_t _create_emummc_mig4_action(lv_obj_t * btns, const char * txt) +{ + switch (lv_btnm_get_pressed(btns)) + { + case 0: + _migrate_sd_backup_file_based(); + break; + } + + part_idx = 0; + sector_start = 0; + + mbox_action(btns, txt); + + return LV_RES_INV; +} + +static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn) +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char *mbox_btn_map[] = { "\222Continue", "\222Cancel", "" }; + static const char *mbox_btn_map1[] = { "\222SD File", "\222SD Partition", "\222Cancel", "" }; + static const char *mbox_btn_map3[] = { "\211", "OK", "\211", "" }; + lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES / 9 * 6); + + char *txt_buf = (char *)malloc(0x500); + u8 *mbr = (u8 *)malloc(0x200); + + sd_mount(); + sdmmc_storage_read(&sd_storage, 0, 1, mbr); + + memcpy(mbr, mbr + 0x1BE, 0x40); + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4); + + bool backup = false; + bool emummc = false; + bool file_based = false; + sector_start = 0; + part_idx = 0; + + for (int i = 1; i < 4; i++) + { + u32 curr_part_size = *(u32 *)&mbr[0x0C + (0x10 * i)]; + sector_start = *(u32 *)&mbr[0x08 + (0x10 * i)]; + if ((curr_part_size > storage.sec_cnt) && sector_start) + { + part_idx = i; + break; + } + } + + //! TODO: What about unallocated + + if (part_idx) + { + sdmmc_storage_read(&sd_storage, sector_start + 0xC001, 1, mbr); + if (!memcmp(mbr, "EFI PART", 8)) + { + sector_start += 0x8000; + emummc = true; + } + else + { + sdmmc_storage_read(&sd_storage, sector_start + 0x4001, 1, mbr); + if (!memcmp(mbr, "EFI PART", 8)) + emummc = true; + } + + if (!emummc) + { + sdmmc_storage_read(&sd_storage, sector_start + 0x4003, 1, mbr); + if (memcmp(mbr, "EFI PART", 8)) + part_idx = 0; + } + } + + FILINFO fno; + s_printf(txt_buf, "%c%c%c%c%s", 's', 'x', 'o','s', "/emunand/boot0.bin"); + + if(!f_stat(txt_buf, &fno)) + file_based = true; + + bool rawnand_backup_found = false; + + emmcsn_path_impl(txt_buf, "", "BOOT0", &storage); + if(!f_stat(txt_buf, &fno)) + backup = true; + + emmcsn_path_impl(txt_buf, "", "rawnand.bin", &storage); + if(!f_stat(txt_buf, &fno)) + rawnand_backup_found = true; + + emmcsn_path_impl(txt_buf, "", "rawnand.bin.00", &storage); + if(!f_stat(txt_buf, &fno)) + rawnand_backup_found = true; + + if (backup && rawnand_backup_found) + backup = true; + else + backup = false; + + sd_unmount(false); + sdmmc_storage_end(&storage); + + if (backup) + { + s_printf(txt_buf, + "#C7EA46 Found suitable backup for emuMMC!#\n" + "#FF8000 Do you want to migrate it?#\n\n"); + lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig4_action); + } + else if (emummc) + { + s_printf(txt_buf, + "#C7EA46 Found SD Partition based emuMMC!#\n" + "#FF8000 Do you want to repair the config for it?#\n\n"); + lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig3_action); + } + else if (part_idx && !file_based) + { + s_printf(txt_buf, + "#C7EA46 Found foreign SD Partition emunand!#\n" + "#FF8000 Do you want to migrate it?#\n\n"); + lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig2_action); + } + else if (!part_idx && file_based) + { + s_printf(txt_buf, + "#C7EA46 Found foreign SD File emunand!#\n" + "#FF8000 Do you want to migrate it?#\n\n"); + lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig0_action); + } + else if (part_idx && file_based) + { + s_printf(txt_buf, + "#C7EA46 Found both foreign SD File and Partition emunand!#\n" + "#FF8000 Choose what to migrate:#\n\n"); + lv_mbox_add_btns(mbox, mbox_btn_map1, _create_emummc_mig1_action); + } + else + { + s_printf(txt_buf, "No foreign emunand or emuMMC found!\n\n"); + lv_mbox_add_btns(mbox, mbox_btn_map3, mbox_action); + } + + lv_mbox_set_text(mbox, txt_buf); + free(txt_buf); + free(mbr); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + return LV_RES_OK; +} + +typedef struct _emummc_images_t +{ + char *dirlist; + u32 part_sector[3]; + u32 part_type[3]; + u32 part_size[3]; + char part_path[3 * 32]; + lv_obj_t *win; +} emummc_images_t; + +static emummc_images_t *emummc_img; + +static lv_obj_t *emummc_manage_window; + +static lv_res_t (*emummc_tools)(lv_obj_t *btn); + +static lv_res_t _save_emummc_cfg_mbox_action(lv_obj_t *btns, const char *txt) +{ + free(emummc_img->dirlist); + lv_obj_del(emummc_img->win); + lv_obj_del(emummc_manage_window); + free(emummc_img); + + mbox_action(btns, txt); + + (*emummc_tools)(NULL); + + return LV_RES_INV; +} + +static void _create_emummc_saved_mbox() +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char *mbox_btn_map[] = { "\211", "OK", "\211", "" }; + lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES / 9 * 4); + + lv_mbox_set_text(mbox, + "#FF8000 emuMMC Configuration#\n\n" + "#96FF00 The emuMMC configuration#\n#96FF00 was saved to sd card!#"); + + lv_mbox_add_btns(mbox, mbox_btn_map, _save_emummc_cfg_mbox_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); +} + +static lv_res_t _save_raw_emummc_cfg_action(lv_obj_t * btn) +{ + lv_btn_ext_t *ext = lv_obj_get_ext_attr(btn); + switch (ext->idx) + { + case 0: + save_emummc_cfg(1, emummc_img->part_sector[0], &emummc_img->part_path[0]); + break; + case 1: + save_emummc_cfg(2, emummc_img->part_sector[1], &emummc_img->part_path[32]); + break; + case 2: + save_emummc_cfg(3, emummc_img->part_sector[2], &emummc_img->part_path[64]); + break; + } + + _create_emummc_saved_mbox(); + sd_unmount(false); + + return LV_RES_INV; +} + +static lv_res_t _save_disable_emummc_cfg_action(lv_obj_t * btn) +{ + save_emummc_cfg(0, 0, NULL); + _create_emummc_saved_mbox(); + sd_unmount(false); + + + return LV_RES_INV; +} + +static lv_res_t _save_file_emummc_cfg_action(lv_obj_t *btn) +{ + save_emummc_cfg(0, 0, lv_list_get_btn_text(btn)); + _create_emummc_saved_mbox(); + sd_unmount(false); + + return LV_RES_INV; +} + +static lv_res_t _create_change_emummc_window() +{ + lv_obj_t *win = nyx_create_standard_window(SYMBOL_SETTINGS" Change emuMMC"); + lv_win_add_btn(win, NULL, SYMBOL_POWER" Disable", _save_disable_emummc_cfg_action); + + sd_mount(); + + emummc_img = malloc(sizeof(emummc_images_t)); + emummc_img->win = win; + + u8 *mbr = (u8 *)malloc(0x200); + char *path = malloc(256); + + sdmmc_storage_read(&sd_storage, 0, 1, mbr); + + memcpy(mbr, mbr + 0x1BE, 0x40); + memset(emummc_img->part_path, 0, 3 * 32); + + for (int i = 1; i < 4; i++) + { + emummc_img->part_size[i - 1] = *(u32 *)&mbr[0x0C + (0x10 * i)]; + emummc_img->part_sector[i - 1] = *(u32 *)&mbr[0x08 + (0x10 * i)]; + emummc_img->part_type[i - 1] = mbr[0x04 + (0x10 * i)]; + } + free(mbr); + + emummc_img->dirlist = dirlist("emuMMC", NULL, false, true); + + if (!emummc_img->dirlist) + goto out0; + + u32 emummc_idx = 0; + FILINFO fno; + FIL fp; + + // Check for sd raw partitions, based on the folders in /emuMMC. + while (emummc_img->dirlist[emummc_idx * 256]) + { + s_printf(path, "emuMMC/%s/raw_based", &emummc_img->dirlist[emummc_idx * 256]); + + if(!f_stat(path, &fno)) + { + f_open(&fp, path, FA_READ); + u32 curr_list_sector = 0; + f_read(&fp, &curr_list_sector, 4, NULL); + f_close(&fp); + + // Check if there's a HOS image there. + if (emummc_img->part_sector[0] && curr_list_sector >= emummc_img->part_sector[0] && emummc_img->part_type[0] != 0x83) + { + if (emummc_img->part_sector[1] && curr_list_sector >= emummc_img->part_sector[1] && emummc_img->part_type[1] != 0x83) + { + if (emummc_img->part_sector[2] && curr_list_sector >= emummc_img->part_sector[2] && emummc_img->part_type[2] != 0x83) + { + s_printf(path, "emuMMC/%s", &emummc_img->dirlist[emummc_idx * 256]); + strcpy(&emummc_img->part_path[2 * 32], path); + emummc_img->part_sector[2] = curr_list_sector; + } + else + { + s_printf(path, "emuMMC/%s", &emummc_img->dirlist[emummc_idx * 256]); + strcpy(&emummc_img->part_path[1 * 32], path); + emummc_img->part_sector[1] = curr_list_sector; + } + + } + else + { + s_printf(path, "emuMMC/%s", &emummc_img->dirlist[emummc_idx * 256]); + strcpy(&emummc_img->part_path[0], path); + emummc_img->part_sector[0] = curr_list_sector; + } + } + + } + emummc_idx++; + } + + emummc_idx = 0; + u32 file_based_idx = 0; + + // Sanitize the directory list with sd file based ones. + while (emummc_img->dirlist[emummc_idx * 256]) + { + s_printf(path, "emuMMC/%s/file_based", &emummc_img->dirlist[emummc_idx * 256]); + + if(!f_stat(path, &fno)) + { + strcpy(&emummc_img->dirlist[file_based_idx * 256], &emummc_img->dirlist[emummc_idx * 256]); + file_based_idx++; + } + emummc_idx++; + } + emummc_img->dirlist[file_based_idx * 256] = 0; + +out0:; + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = 0; + h_style.body.padding.hor = LV_DPI - (LV_DPI / 4); + h_style.body.padding.ver = LV_DPI / 6; + + // Create SD Raw Partitions container. + lv_obj_t *h1 = lv_cont_create(win, NULL); + lv_cont_set_style(h1, &h_style); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt = lv_label_create(h1, NULL); + lv_label_set_static_text(label_txt, "SD Raw Partitions"); + lv_obj_set_style(label_txt, lv_theme_get_current()->label.prim); + lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -(LV_DPI / 2)); + + lv_obj_t *line_sep = lv_line_create(h1, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, lv_theme_get_current()->line.decor); + lv_obj_align(line_sep, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create RAW 1 button. + lv_obj_t *btn = lv_btn_create(h1, NULL); + lv_btn_ext_t *ext = lv_obj_get_ext_attr(btn); + ext->idx = 0; + lv_obj_t *btn_label = lv_label_create(btn, NULL); + if (emummc_img->part_type[0] != 0x83) + lv_label_set_static_text(btn_label, "SD RAW 1"); + else + lv_label_set_static_text(btn_label, "Linux"); + if (!emummc_img->part_sector[0] || emummc_img->part_type[0] == 0x83 || !emummc_img->part_path[0]) + { + lv_btn_set_state(btn, LV_BTN_STATE_INA); + lv_obj_set_click(btn, false); + } + + lv_btn_set_fit(btn, false, true); + lv_obj_set_width(btn, LV_DPI * 3); + lv_obj_align(btn, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 2, LV_DPI / 5); + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, _save_raw_emummc_cfg_action); + + lv_obj_t *lv_desc = lv_label_create(h1, NULL); + lv_label_set_recolor(lv_desc, true); + + char *txt_buf = malloc(0x500); + s_printf(txt_buf, "Sector start: 0x%08X\nFolder: %s", emummc_img->part_sector[0], &emummc_img->part_path[0]); + lv_label_set_array_text(lv_desc, txt_buf, 0x500); + lv_obj_set_style(lv_desc, &hint_small_style); + lv_obj_align(lv_desc, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 5); + + // Create RAW 2 button. + btn = lv_btn_create(h1, btn); + ext = lv_obj_get_ext_attr(btn); + ext->idx = 1; + btn_label = lv_label_create(btn, btn_label); + if (emummc_img->part_type[1] != 0x83) + lv_label_set_static_text(btn_label, "SD RAW 2"); + else + lv_label_set_static_text(btn_label, "Linux"); + if (!emummc_img->part_sector[1] || emummc_img->part_type[1] == 0x83 || !emummc_img->part_path[32]) + { + lv_btn_set_state(btn, LV_BTN_STATE_INA); + lv_obj_set_click(btn, false); + } + lv_obj_align(btn, lv_desc, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, _save_raw_emummc_cfg_action); + + lv_desc = lv_label_create(h1, lv_desc); + s_printf(txt_buf, "Sector start: 0x%08X\nFolder: %s", emummc_img->part_sector[1], &emummc_img->part_path[32]); + lv_label_set_array_text(lv_desc, txt_buf, 0x500); + lv_obj_align(lv_desc, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 5); + + // Create RAW 3 button. + btn = lv_btn_create(h1, btn); + ext = lv_obj_get_ext_attr(btn); + ext->idx = 2; + btn_label = lv_label_create(btn, btn_label); + if (emummc_img->part_type[2] != 0x83) + lv_label_set_static_text(btn_label, "SD RAW 3"); + else + lv_label_set_static_text(btn_label, "Linux"); + + if (!emummc_img->part_sector[2] || emummc_img->part_type[2] == 0x83 || !emummc_img->part_path[64]) + { + lv_btn_set_state(btn, LV_BTN_STATE_INA); + lv_obj_set_click(btn, false); + } + lv_obj_align(btn, lv_desc, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, _save_raw_emummc_cfg_action); + + lv_desc = lv_label_create(h1, lv_desc); + s_printf(txt_buf, "Sector start: 0x%08X\nFolder: %s", emummc_img->part_sector[2], &emummc_img->part_path[64]); + lv_label_set_array_text(lv_desc, txt_buf, 0x500); + lv_obj_align(lv_desc, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 5); + + // Create SD File Based container. + lv_obj_t *h2 = lv_cont_create(win, NULL); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, true); + lv_obj_set_width(h2, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h2, false); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI * 17 / 29, 0); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt3 = lv_label_create(h2, NULL); + lv_label_set_static_text(label_txt3, "SD File Based"); + lv_obj_set_style(label_txt3, lv_theme_get_current()->label.prim); + lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI / 7); + + line_sep = lv_line_create(h2, line_sep); + lv_obj_align(line_sep, label_txt3, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 2), LV_DPI / 8); + lv_line_set_style(line_sep, lv_theme_get_current()->line.decor); + + lv_obj_t *list_sd_based = lv_list_create(h2, NULL); + lv_obj_align(list_sd_based, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 2, LV_DPI / 4); + + lv_obj_set_size(list_sd_based, LV_HOR_RES * 4 / 10, LV_VER_RES * 6 / 10); + lv_list_set_single_mode(list_sd_based, true); + + if (!emummc_img->dirlist) + goto out1; + + emummc_idx = 0; + + // Add file based to the list. + while (emummc_img->dirlist[emummc_idx * 256]) + { + s_printf(path, "emuMMC/%s", &emummc_img->dirlist[emummc_idx * 256]); + + lv_list_add(list_sd_based, NULL, path, _save_file_emummc_cfg_action); + + emummc_idx++; + } + +out1: + free(path); + sd_unmount(false); + + return LV_RES_OK; +} + +lv_res_t create_win_emummc_tools(lv_obj_t *btn) +{ + lv_obj_t *win = nyx_create_standard_window(SYMBOL_EDIT" emuMMC Manage"); + emummc_manage_window = win; + + emummc_tools = (void *)create_win_emummc_tools; + + typedef struct _emummc_cfg_t + { + int enabled; + u32 sector; + u16 id; + char *path; + char *nintendo_path; + } emummc_cfg_t; + + emummc_cfg_t emu_info; + + sd_mount(); + + emu_info.enabled = 0; + emu_info.sector = 0; + emu_info.id = 0; + emu_info.path = NULL; + emu_info.nintendo_path = NULL; + + //! TODO: Always update that info when something was changed. + // Parse emuMMC configuration. + LIST_INIT(ini_sections); + if (ini_parse(&ini_sections, "emuMMC/emummc.ini", false)) + { + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) + { + if (!strcmp(ini_sec->name, "emummc")) + { + LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) + { + if (!strcmp("enabled", kv->key)) + emu_info.enabled = atoi(kv->val); + else if (!strcmp("sector", kv->key)) + emu_info.sector = strtol(kv->val, NULL, 16); + else if (!strcmp("id", kv->key)) + emu_info.id = strtol(kv->val, NULL, 16); + else if (!strcmp("path", kv->key)) + emu_info.path = kv->val; + else if (!strcmp("nintendo_path", kv->key)) + emu_info.nintendo_path = kv->val; + } + } + } + } + + sd_unmount(false); + + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = 0; + h_style.body.padding.hor = LV_DPI - (LV_DPI / 4); + h_style.body.padding.ver = LV_DPI / 9; + + // Create emuMMC Info & Selection container. + lv_obj_t *h1 = lv_cont_create(win, NULL); + lv_cont_set_style(h1, &h_style); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt = lv_label_create(h1, NULL); + lv_label_set_static_text(label_txt, "emuMMC Info & Selection"); + lv_obj_set_style(label_txt, lv_theme_get_current()->label.prim); + lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI / 9); + + lv_obj_t *line_sep = lv_line_create(h1, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, lv_theme_get_current()->line.decor); + lv_obj_align(line_sep, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create emuMMC info labels. + lv_obj_t *label_btn = lv_label_create(h1, NULL); + lv_label_set_recolor(label_btn, true); + lv_label_set_static_text(label_btn, emu_info.enabled ? "#96FF00 "SYMBOL_OK" Enabled!#" : "#FF8000 "SYMBOL_CLOSE" Disabled!#"); + lv_obj_align(label_btn, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + + lv_obj_t *label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + char *txt_buf = (char *)malloc(0x200); + + if (emu_info.enabled) + { + if (emu_info.sector) + s_printf(txt_buf, "#00DDFF Type:# SD Raw Partition\n#00DDFF Sector:# 0x%08X\n#00DDFF Nintendo folder:# %s", + emu_info.sector, emu_info.nintendo_path ? emu_info.nintendo_path : ""); + else + s_printf(txt_buf, "#00DDFF Type:# SD File\n#00DDFF Base folder:# %s\n#00DDFF Nintendo folder:# %s", + emu_info.path ? emu_info.path : "", emu_info.nintendo_path ? emu_info.nintendo_path : ""); + + lv_label_set_array_text(label_txt2, txt_buf, 0x200); + } + else + { + lv_label_set_static_text(label_txt2, "emuMMC is disabled and eMMC will be used for boot.\n\n"); + } + + free(txt_buf); + + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, label_btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create Change emuMMC button. + lv_obj_t *btn2 = lv_btn_create(h1, NULL); + lv_btn_set_fit(btn2, true, true); + label_btn = lv_label_create(btn2, NULL); + lv_label_set_static_text(label_btn, SYMBOL_SETTINGS" Change emuMMC"); + lv_obj_align(btn2, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 6 / 10); + lv_btn_set_action(btn2, LV_BTN_ACTION_CLICK, _create_change_emummc_window); + + label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + lv_label_set_static_text(label_txt2, + "Choose between images created in the emuMMC folder\n" + "or in SD card partitions. You can have at most 3 partition\n" + "based and countless file based."); + + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create emuMMC Tools container. + lv_obj_t *h2 = lv_cont_create(win, NULL); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, true); + lv_obj_set_width(h2, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h2, false); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI * 17 / 29, 0); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt3 = lv_label_create(h2, NULL); + lv_label_set_static_text(label_txt3, "emuMMC Tools"); + lv_obj_set_style(label_txt3, lv_theme_get_current()->label.prim); + lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, 0); + + line_sep = lv_line_create(h2, line_sep); + lv_obj_align(line_sep, label_txt3, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create Create emuMMC button. + lv_obj_t *btn3 = lv_btn_create(h2, btn2); + label_btn = lv_label_create(btn3, NULL); + lv_btn_set_fit(btn3, true, true); + lv_label_set_static_text(label_btn, SYMBOL_DRIVE" Create emuMMC"); + lv_obj_align(btn3, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + lv_btn_set_action(btn3, LV_BTN_ACTION_CLICK, _create_mbox_emummc_create); + + lv_obj_t *label_txt4 = lv_label_create(h2, NULL); + lv_label_set_recolor(label_txt4, true); + lv_label_set_static_text(label_txt4, + "Allows you to create a new #C7EA46 SD File# or #C7EA46 SD Raw Partition#\n" + "emuMMC. You can create it from eMMC or a eMMC Backup."); + + lv_obj_set_style(label_txt4, &hint_small_style); + lv_obj_align(label_txt4, btn3, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + //! TODO: Move it to a window with multiple choices. + // Create Migrate emuMMC button. + lv_obj_t *btn4 = lv_btn_create(h2, btn2); + label_btn = lv_label_create(btn4, NULL); + lv_label_set_static_text(label_btn, SYMBOL_SHUFFLE" Migrate emuMMC"); + lv_obj_align(btn4, label_txt4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); + lv_btn_set_action(btn4, LV_BTN_ACTION_CLICK, NULL); + lv_btn_set_action(btn4, LV_BTN_ACTION_CLICK, _create_mbox_emummc_migrate); + + label_txt4 = lv_label_create(h2, NULL); + lv_label_set_recolor(label_txt4, true); + lv_label_set_static_text(label_txt4, + "Migrate a backup to a #C7EA46 SD File# or repair existing #C7EA46 SD Raw Partition#.\n" + "Additionally it allows you to migrate from other emunand\nsolutions."); + //"Move between #C7EA46 SD File# and #C7EA46 SD Raw Partition# emuMMC.\n" + //"Additionally it allows you to migrate from other emunand\nsolutions."); + lv_obj_set_style(label_txt4, &hint_small_style); + lv_obj_align(label_txt4, btn4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + return LV_RES_OK; +} + +#pragma GCC pop_options diff --git a/nyx/nyx_gui/frontend/gui_emummc_tools.h b/nyx/nyx_gui/frontend/gui_emummc_tools.h new file mode 100644 index 0000000..84cdb6d --- /dev/null +++ b/nyx/nyx_gui/frontend/gui_emummc_tools.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _GUI_EMUMMC_TOOLS_H_ +#define _GUI_EMUMMC_TOOLS_H_ + +#include "../libs/lvgl/lvgl.h" + +lv_res_t create_win_emummc_tools(lv_obj_t *btn); + +#endif diff --git a/nyx/nyx_gui/frontend/gui_info.c b/nyx/nyx_gui/frontend/gui_info.c new file mode 100644 index 0000000..62af1bd --- /dev/null +++ b/nyx/nyx_gui/frontend/gui_info.c @@ -0,0 +1,1179 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018-2019 CTCaer + * Copyright (c) 2018 balika011 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui.h" +#include "../hos/hos.h" +#include "../hos/pkg1.h" +#include "../libs/fatfs/ff.h" +#include "../mem/heap.h" +#include "../power/bq24193.h" +#include "../power/max17050.h" +#include "../sec/tsec.h" +#include "../soc/fuse.h" +#include "../soc/kfuse.h" +#include "../soc/i2c.h" +#include "../soc/smmu.h" +#include "../soc/t210.h" +#include "../storage/mmc.h" +#include "../storage/nx_emmc.h" +#include "../storage/sdmmc.h" +#include "../utils/sprintf.h" +#include "../utils/util.h" + +#define SECTORS_TO_MIB_COEFF 11 + +extern sdmmc_storage_t sd_storage; +extern FATFS sd_fs; + +extern bool sd_mount(); +extern void sd_unmount(bool deinit); +extern int sd_save_to_file(void *buf, u32 size, const char *filename); +extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); + +#pragma GCC push_options +#pragma GCC target ("thumb") + +static lv_res_t _create_window_dump_done(int error, char *dump_filenames) +{ + lv_style_t *darken; + darken = (lv_style_t *)malloc(sizeof(lv_style_t)); + lv_style_copy(darken, &lv_style_plain); + darken->body.main_color = LV_COLOR_BLACK; + darken->body.grad_color = darken->body.main_color; + darken->body.opa = LV_OPA_30; + + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\211", "\222OK", "\211", "" }; + lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); + + char *txt_buf = (char *)malloc(0x1000); + + if (error) + s_printf(txt_buf, "#FFDD00 Failed to dump to# %s#FFDD00 !#\nError: %d", dump_filenames, error); + else + s_printf(txt_buf, "Dumping to SD card finished!\nFiles: #C7EA46 backup/{emmc_sn}/dumps/#%s", dump_filenames); + lv_mbox_set_text(mbox, txt_buf); + + lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); // Important. After set_text. + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + return LV_RES_OK; +} + +static lv_res_t _battery_dump_window_action(lv_obj_t * btn) +{ + int error = !sd_mount(); + + if (!error) + { + char path[64]; + u8 *buf = (u8 *)malloc(0x100 * 2); + + // Dump all battery fuel gauge registers. + for (int i = 0; i < 0x200; i += 2) + { + i2c_recv_buf_small(buf + i, 2, I2C_1, MAXIM17050_I2C_ADDR, i >> 1); + msleep(1); + } + + emmcsn_path_impl(path, "/dumps", "fuel_gauge.bin", NULL); + error = sd_save_to_file((u8 *)buf, 0x200, path); + + sd_unmount(false); + } + + _create_window_dump_done(error, "fuel_gauge.bin"); + + return LV_RES_OK; +} + +static lv_res_t _bootrom_dump_window_action(lv_obj_t * btn) +{ + static const u32 BOOTROM_SIZE = 0x18000; + + int error = !sd_mount(); + if (!error) + { + char path[64]; + u32 iram_evp_thunks[0x200]; + u32 iram_evp_thunks_len = sizeof(iram_evp_thunks); + error = fuse_read_evp_thunk(iram_evp_thunks, &iram_evp_thunks_len); + if (!error) + { + emmcsn_path_impl(path, "/dumps", "evp_thunks.bin", NULL); + error = sd_save_to_file((u8 *)iram_evp_thunks, iram_evp_thunks_len, path); + } + else + error = 255; + + emmcsn_path_impl(path, "/dumps", "bootrom_patched.bin", NULL); + int res = sd_save_to_file((u8 *)BOOTROM_BASE, BOOTROM_SIZE, path); + if (!error) + error = res; + + u32 ipatch_backup[14]; + memcpy(ipatch_backup, (void *)IPATCH_BASE, sizeof(ipatch_backup)); + memset((void*)IPATCH_BASE, 0, sizeof(ipatch_backup)); + + emmcsn_path_impl(path, "/dumps", "bootrom_unpatched.bin", NULL); + res = sd_save_to_file((u8 *)BOOTROM_BASE, BOOTROM_SIZE, path); + if (!error) + error = res; + + memcpy((void*)IPATCH_BASE, ipatch_backup, sizeof(ipatch_backup)); + + sd_unmount(false); + } + _create_window_dump_done(error, "evp_thunks.bin, bootrom_patched.bin, bootrom_unpatched.bin"); + + + return LV_RES_OK; +} + +static lv_res_t _fuse_dump_window_action(lv_obj_t * btn) +{ + int error = !sd_mount(); + if (!error) + { + char path[64]; + emmcsn_path_impl(path, "/dumps", "fuse_cached.bin", NULL); + error = sd_save_to_file((u8 *)0x7000F900, 0x300, path); + + u32 words[192]; + fuse_read_array(words); + emmcsn_path_impl(path, "/dumps", "fuse_array_raw.bin", NULL); + int res = sd_save_to_file((u8 *)words, sizeof(words), path); + if (!error) + error = res; + + sd_unmount(false); + } + _create_window_dump_done(error, "fuse_cached.bin, fuse_array_raw.bin"); + + return LV_RES_OK; +} + +static lv_res_t _kfuse_dump_window_action(lv_obj_t * btn) +{ + u32 buf[KFUSE_NUM_WORDS]; + int error = !kfuse_read(buf); + + if (!error) + error = !sd_mount(); + + if (!error) + { + char path[64]; + emmcsn_path_impl(path, "/dumps", "kfuses.bin", NULL); + error = sd_save_to_file((u8 *)buf, KFUSE_NUM_WORDS * 4, path); + + sd_unmount(false); + } + + _create_window_dump_done(error, "kfuses.bin"); + + return LV_RES_OK; +} + +static u32 tsec_keys[8]; + +static lv_res_t _tsec_keys_dump_window_action(lv_obj_t * btn) +{ + int error = !sd_mount(); + if (!error) + { + char path[64]; + emmcsn_path_impl(path, "/dumps", "tsec_keys.bin", NULL); + error = sd_save_to_file(tsec_keys, 0x10 * 2, path); + + sd_unmount(false); + } + _create_window_dump_done(error, "tsec_keys.bin"); + + return LV_RES_OK; +} + +static lv_res_t _create_window_fuses_info_status(lv_obj_t *btn) +{ + lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" Cached fuses Info"); + lv_win_add_btn(win, NULL, SYMBOL_DOWNLOAD" Dump fuses", _fuse_dump_window_action); + + lv_obj_t *desc = lv_cont_create(win, NULL); + lv_obj_set_size(desc, LV_HOR_RES / 2 / 5 * 2, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_desc = lv_label_create(desc, NULL); + lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc, true); + lv_ta_set_style(lb_desc, LV_TA_STYLE_BG, &monospace_text); + + lv_label_set_static_text(lb_desc, + "#00DDFF Detailed Info:#\n" + "SKU:\n" + "DRAM ID:\n" + "#FF8000 Burnt Fuses (ODM 7/6):#\n" + "Secure Boot key (SBK):\n" + "Device key (DK):\n" + "USB Stack:\n" + "Final Test Revision:\n" + "Chip Probing Revision:\n" + "Bootrom ipatches size:\n" + "CPU Speedo 0 (CPU Val):\n" + "CPU Speedo 1:\n" + "CPU Speedo 2 (GPU Val):\n" + "SoC Speedo 0 (SoC Val):\n" + "SoC Speedo 1 (BROM rev):\n" + "SoC Speedo 2:\n" + "CPU IDDQ Val:\n" + "SoC IDDQ Val:\n" + "Gpu IDDQ Val:\n" + "Vendor Code:\n" + "FAB Code:\n" + "LOT Code 0:\n" + "LOT Code 1:\n" + "Wafer ID:\n" + "X Coordinate:\n" + "Y Coordinate:" + ); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + lv_obj_t *val = lv_cont_create(win, NULL); + lv_obj_set_size(val, LV_HOR_RES / 11 * 3, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_val = lv_label_create(val, lb_desc); + + char *txt_buf = (char *)malloc(0x1000); + + // Decode fuses. + u8 burntFuses7 = 0; + u8 burntFuses6 = 0; + u32 odm4 = fuse_read_odm(4); + u8 dram_id = (odm4 >> 3) & 0x1F; + char dram_man[16] = {0}; + switch (dram_id) + { + case 0: + case 4: + memcpy(dram_man, "Samsung ", 9); + if (!dram_id) + memcpy(dram_man + strlen(dram_man), "4GB", 4); + else + memcpy(dram_man + strlen(dram_man), "6GB", 4); + break; + case 1: + memcpy(dram_man, "Hynix 4GB", 10); + break; + case 2: + memcpy(dram_man, "Micron 4GB", 11); + break; + default: + memcpy(dram_man, "Unknown", 8); + break; + } + + for (u32 i = 0; i < 32; i++) + { + if ((fuse_read_odm(7) >> i) & 1) + burntFuses7++; + } + for (u32 i = 0; i < 32; i++) + { + if ((fuse_read_odm(6) >> i) & 1) + burntFuses6++; + } + + u32 lot_code0 = (FUSE(FUSE_OPT_LOT_CODE_0) & 0xFFFFFFF) << 2; + u32 lot_bin = 0; + for (int i = 0; i < 5; ++i) + { + u32 digit = (lot_code0 & 0xFC000000) >> 26; + lot_bin *= 36; + lot_bin += digit; + lot_code0 <<= 6; + } + + // Parse fuses and display them. + s_printf(txt_buf, + "\n%X - %s - %s\n%d - %s\n%d - %d\n%08X%08X%08X%08X\n%08X\n" + "%s\n%d.%02d (0x%X)\n%d.%02d (0x%X)\n%d\n%d\n%d\n%d\n%d\n0x%X\n%d\n%d\n%d\n%d\n" + "%d\n%d\n%d (0x%X)\n%d\n%d\n%d\n%d", + FUSE(FUSE_SKU_INFO), odm4 & 0x10000 ? "Mariko" : "Erista", (fuse_read_odm(4) & 3) ? "Dev" : "Retail", + dram_id, dram_man, burntFuses7, burntFuses6, + byte_swap_32(FUSE(FUSE_PRIVATE_KEY0)), byte_swap_32(FUSE(FUSE_PRIVATE_KEY1)), + byte_swap_32(FUSE(FUSE_PRIVATE_KEY2)), byte_swap_32(FUSE(FUSE_PRIVATE_KEY3)), + byte_swap_32(FUSE(FUSE_PRIVATE_KEY4)), + (FUSE(FUSE_RESERVED_SW) & 0x80) ? "XUSB" : "USB 2.0", + (FUSE(FUSE_OPT_FT_REV) >> 5) & 0x3F, FUSE(FUSE_OPT_FT_REV) & 0x1F, FUSE(FUSE_OPT_FT_REV), + (FUSE(FUSE_OPT_CP_REV) >> 5) & 0x3F, FUSE(FUSE_OPT_CP_REV) & 0x1F, FUSE(FUSE_OPT_CP_REV), + FUSE(FUSE_FIRST_BOOTROM_PATCH_SIZE) & 0x7F, + FUSE(FUSE_CPU_SPEEDO_0_CALIB), FUSE(FUSE_CPU_SPEEDO_1_CALIB), FUSE(FUSE_CPU_SPEEDO_2_CALIB), + FUSE(FUSE_SOC_SPEEDO_0_CALIB), FUSE(FUSE_SOC_SPEEDO_1_CALIB), FUSE(FUSE_SOC_SPEEDO_2_CALIB), + FUSE(FUSE_CPU_IDDQ_CALIB), FUSE(FUSE_SOC_IDDQ_CALIB), FUSE(FUSE_GPU_IDDQ_CALIB), + FUSE(FUSE_OPT_VENDOR_CODE), FUSE(FUSE_OPT_FAB_CODE), lot_bin, FUSE(FUSE_OPT_LOT_CODE_0), + FUSE(FUSE_OPT_LOT_CODE_1), FUSE(FUSE_OPT_WAFER_ID), FUSE(FUSE_OPT_X_COORDINATE), FUSE(FUSE_OPT_Y_COORDINATE)); + + lv_label_set_array_text(lb_val, txt_buf, 0x1000); + + free(txt_buf); + + lv_obj_set_width(lb_val, lv_obj_get_width(val)); + lv_obj_align(val, desc, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + + lv_obj_t *desc2 = lv_cont_create(win, NULL); + lv_obj_set_size(desc2, LV_HOR_RES / 2 / 5 * 4, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_desc2 = lv_label_create(desc2, NULL); + lv_label_set_long_mode(lb_desc2, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc2, true); + + // Check if patched unit. + if (!fuse_check_patched_rcm()) + lv_label_set_static_text(lb_desc2, "#96FF00 Your unit is exploitable#\n#96FF00 to the RCM bug!#"); + else + lv_label_set_static_text(lb_desc2, "#FF8000 Your unit is patched#\n#FF8000 to the RCM bug!#"); + + lv_obj_set_width(lb_desc2, lv_obj_get_width(desc2)); + lv_obj_align(desc2, val, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 2, 0); + lv_label_set_align(lb_desc2, LV_LABEL_ALIGN_CENTER); + + return LV_RES_OK; +} + +static char *ipatches_txt; +static void _ipatch_process(u32 offset, u32 value) +{ + s_printf(ipatches_txt + strlen(ipatches_txt), "%6X %4X ", BOOTROM_BASE + offset, value); + u8 lo = value & 0xFF; + switch (value >> 8) + { + case 0x20: + s_printf(ipatches_txt + strlen(ipatches_txt), "MOVS R0, ##0x%02X", lo); + break; + case 0xDF: + s_printf(ipatches_txt + strlen(ipatches_txt), "SVC ##0x%02X", lo); + break; + } + s_printf(ipatches_txt + strlen(ipatches_txt), "\n"); +} + +static lv_res_t _create_window_bootrom_info_status(lv_obj_t *btn) +{ + lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" Bootrom Info"); + lv_win_add_btn(win, NULL, SYMBOL_DOWNLOAD" Dump Bootrom", _bootrom_dump_window_action); + + lv_obj_t *desc = lv_cont_create(win, NULL); + lv_obj_set_size(desc, LV_HOR_RES / 2 / 3 * 2, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_desc = lv_label_create(desc, NULL); + lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc, true); + lv_ta_set_style(lb_desc, LV_TA_STYLE_BG, &monospace_text); + + char *txt_buf = (char *)malloc(0x1000); + ipatches_txt = txt_buf; + s_printf(txt_buf, "#00DDFF Ipatches:#\n#FF8000 Address "SYMBOL_DOT" Val "SYMBOL_DOT" Instruction\n"); + + u32 res = fuse_read_ipatch(_ipatch_process); + if (res != 0) + s_printf(txt_buf + strlen(txt_buf), "#FFDD00 Failed to read ipatches. Error: %d#", res); + + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + + free(txt_buf); + + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + return LV_RES_OK; +} + +static lv_res_t _create_window_tsec_keys_status(lv_obj_t *btn) +{ + u32 retries = 0; + + tsec_ctxt_t tsec_ctxt; + sdmmc_storage_t storage; + sdmmc_t sdmmc; + + lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" TSEC Keys"); + + //Disable buttons. + nyx_window_toggle_buttons(win, true); + + lv_obj_t *desc = lv_cont_create(win, NULL); + lv_obj_set_size(desc, LV_HOR_RES / 2 / 2, LV_VER_RES - (LV_DPI * 11 / 6)); + //lv_obj_align(desc, win, LV_ALIGN_ou_TOP_LEFT, 0, 40); + + lv_obj_t * lb_desc = lv_label_create(desc, NULL); + lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc, true); + lv_ta_set_style(lb_desc, LV_TA_STYLE_BG, &monospace_text); + + // Read package1. + char *build_date = malloc(32); + u8 *pkg1 = (u8 *)malloc(0x40000); + sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4); + sdmmc_storage_set_mmc_partition(&storage, 1); + sdmmc_storage_read(&storage, 0x100000 / NX_EMMC_BLOCKSIZE, 0x40000 / NX_EMMC_BLOCKSIZE, pkg1); + sdmmc_storage_end(&storage); + const pkg1_id_t *pkg1_id = pkg1_identify(pkg1, build_date); + + char *txt_buf = (char *)malloc(0x500); + char *txt_buf2 = (char *)malloc(0x500); + s_printf(txt_buf, "#00DDFF Found pkg1 ('%s')#\n", build_date); + free(build_date); + + if (!pkg1_id) + { + s_printf(txt_buf + strlen(txt_buf), "#FFDD00 Unknown pkg1 version for reading#\n#FFDD00 TSEC firmware!#"); + lv_label_set_array_text(lb_desc, txt_buf, 0x500); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + goto out; + } + lv_label_set_array_text(lb_desc, txt_buf, 0x500); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + lv_obj_t *val = lv_cont_create(win, NULL); + lv_obj_set_size(val, LV_HOR_RES / 11 * 3, LV_VER_RES - (LV_DPI * 11 / 6)); + + lv_obj_t * lb_val = lv_label_create(val, lb_desc); + lv_ta_set_style(lb_val, LV_TA_STYLE_BG, &monospace_text); + + lv_label_set_static_text(lb_val, "Please wait..."); + lv_obj_set_width(lb_val, lv_obj_get_width(val)); + lv_obj_align(val, desc, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + manual_system_maintenance(true); + + tsec_ctxt.fw = (u8 *)pkg1 + pkg1_id->tsec_off; + tsec_ctxt.pkg1 = pkg1; + tsec_ctxt.pkg11_off = pkg1_id->pkg11_off; + tsec_ctxt.secmon_base = pkg1_id->secmon_base; + + if (pkg1_id->kb <= KB_FIRMWARE_VERSION_600) + tsec_ctxt.size = 0xF00; + else if (pkg1_id->kb == KB_FIRMWARE_VERSION_620) + tsec_ctxt.size = 0x2900; + else if (pkg1_id->kb == KB_FIRMWARE_VERSION_700) + { + tsec_ctxt.size = 0x3000; + // Exit after TSEC key generation. + *((vu16 *)((u32)tsec_ctxt.fw + 0x2DB5)) = 0x02F8; + } + else + tsec_ctxt.size = 0x3300; + + if (pkg1_id->kb == KB_FIRMWARE_VERSION_620) + { + u8 *tsec_paged = (u8 *)page_alloc(3); + memcpy(tsec_paged, (void *)tsec_ctxt.fw, tsec_ctxt.size); + tsec_ctxt.fw = tsec_paged; + } + + int res = 0; + + while (tsec_query((u8 *)tsec_keys, pkg1_id->kb, &tsec_ctxt) < 0) + { + memset(tsec_keys, 0x00, 0x20); + + retries++; + + if (retries > 3) + { + res = -1; + break; + } + } + + s_printf(txt_buf + strlen(txt_buf), "#C7EA46 TSEC Key:#\n"); + if (res >= 0) + { + s_printf(txt_buf2, "\n%08X%08X%08X%08X\n", + byte_swap_32(tsec_keys[0]), byte_swap_32(tsec_keys[1]), byte_swap_32(tsec_keys[2]), byte_swap_32(tsec_keys[3])); + + if (pkg1_id->kb == KB_FIRMWARE_VERSION_620) + { + s_printf(txt_buf + strlen(txt_buf), "#C7EA46 TSEC root:#\n"); + s_printf(txt_buf2 + strlen(txt_buf2), "%08X%08X%08X%08X\n", + byte_swap_32(tsec_keys[4]), byte_swap_32(tsec_keys[5]), byte_swap_32(tsec_keys[6]), byte_swap_32(tsec_keys[7])); + } + lv_win_add_btn(win, NULL, SYMBOL_DOWNLOAD" Dump Keys", _tsec_keys_dump_window_action); + } + else + { + s_printf(txt_buf2, "Error: %x", res); + } + + lv_label_set_array_text(lb_desc, txt_buf, 0x500); + + lv_label_set_array_text(lb_val, txt_buf2, 0x500); + +out: + free(pkg1); + free(txt_buf); + free(txt_buf2); + + nyx_window_toggle_buttons(win, false); + + return LV_RES_OK; +} + + +static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn) +{ + lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" Internal eMMC Info"); + + lv_obj_t *desc = lv_cont_create(win, NULL); + lv_obj_set_size(desc, LV_HOR_RES / 2 / 6 * 2, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_desc = lv_label_create(desc, NULL); + lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc, true); + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + + char *txt_buf = (char *)malloc(0x1000); + + if (!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4)) + { + lv_label_set_static_text(lb_desc, "#FFDD00 Failed to init eMMC!#"); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + } + else + { + u16 card_type; + u32 speed = 0; + + s_printf(txt_buf, "\n%X\n%X\n%02X\n%c%c%c%c%c%c\n%X\n%04X\n%02d/%04d\n\n", + storage.cid.manfid, storage.cid.card_bga, storage.cid.oemid, + storage.cid.prod_name[0], storage.cid.prod_name[1], storage.cid.prod_name[2], + storage.cid.prod_name[3], storage.cid.prod_name[4], storage.cid.prod_name[5], + storage.cid.prv, storage.cid.serial, storage.cid.month, storage.cid.year); + + card_type = storage.ext_csd.card_type; + char card_type_support[96]; + card_type_support[0] = 0; + if (card_type & EXT_CSD_CARD_TYPE_HS_26) + { + strcat(card_type_support, "HS26"); + speed = (26 << 16) | 26; + } + if (card_type & EXT_CSD_CARD_TYPE_HS_52) + { + strcat(card_type_support, ", HS52"); + speed = (52 << 16) | 52; + } + if (card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) + { + strcat(card_type_support, ", DDR52 1.8V"); + speed = (52 << 16) | 104; + } + if (card_type & EXT_CSD_CARD_TYPE_HS200_1_8V) + { + strcat(card_type_support, ", HS200 1.8V"); + speed = (200 << 16) | 200; + } + if (card_type & EXT_CSD_CARD_TYPE_HS400_1_8V) + { + strcat(card_type_support, ", HS400 1.8V"); + speed = (200 << 16) | 400; + } + + s_printf(txt_buf + strlen(txt_buf), + "#00DDFF V1.%d#\n%02X\n1.%d\n%02X\n%d MB/s (%d MHz)\n%d MB/s\n%s", + storage.ext_csd.ext_struct, storage.csd.mmca_vsn, storage.ext_csd.rev, + storage.csd.cmdclass, speed & 0xFFFF, (speed >> 16) & 0xFFFF, + storage.csd.busspeed, card_type_support); + + lv_label_set_static_text(lb_desc, + "#00DDFF CID:#\n" + "Vendor ID:\n" + "Card/BGA:\n" + "OEM ID:\n" + "Model:\n" + "Prd Rev:\n" + "S/N:\n" + "Month/Year:\n\n" + "#00DDFF Ext CSD#\n" + "Spec Version:\n" + "Extended Rev:\n" + "Cmd Classes:\n" + "Max Rate:\n" + "Current Rate:\n" + "Type Support:" + ); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + lv_obj_t *val = lv_cont_create(win, NULL); + lv_obj_set_size(val, LV_HOR_RES / 11 * 3, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_val = lv_label_create(val, lb_desc); + + lv_label_set_array_text(lb_val, txt_buf, 0x1000); + + lv_obj_set_width(lb_val, lv_obj_get_width(val)); + lv_obj_align(val, desc, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + + lv_obj_t *desc2 = lv_cont_create(win, NULL); + lv_obj_set_size(desc2, LV_HOR_RES / 2 / 4 * 4, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_desc2 = lv_label_create(desc2, lb_desc); + lv_ta_set_style(lb_desc2, LV_TA_STYLE_BG, &monospace_text); + + u32 boot_size = storage.ext_csd.boot_mult << 17; + u32 rpmb_size = storage.ext_csd.rpmb_mult << 17; + s_printf(txt_buf, "#00DDFF eMMC Physical Partitions:#\n"); + s_printf(txt_buf + strlen(txt_buf), "1: #96FF00 BOOT0# Size: %5d KiB (Sect: 0x%08X)\n", boot_size / 1024, boot_size / 512); + s_printf(txt_buf + strlen(txt_buf), "2: #96FF00 BOOT1# Size: %5d KiB (Sect: 0x%08X)\n", boot_size / 1024, boot_size / 512); + s_printf(txt_buf + strlen(txt_buf), "3: #96FF00 RPMB# Size: %5d KiB (Sect: 0x%08X)\n", rpmb_size / 1024, rpmb_size / 512); + s_printf(txt_buf + strlen(txt_buf), "0: #96FF00 GPP# Size: %5d MiB (Sect: 0x%08X)\n\n", storage.sec_cnt >> SECTORS_TO_MIB_COEFF, storage.sec_cnt); + s_printf(txt_buf + strlen(txt_buf), "#00DDFF GPP (eMMC USER) Partition Table:#\n"); + + sdmmc_storage_set_mmc_partition(&storage, 0); + LIST_INIT(gpt); + nx_emmc_gpt_parse(&gpt, &storage); + int gpp_idx = 0; + LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link) + { + if (gpp_idx < 2) + { + s_printf(txt_buf + strlen(txt_buf), "%02d: #96FF00 %s#", gpp_idx++, part->name); + if (gpp_idx < 2) + s_printf(txt_buf + strlen(txt_buf), " "); + s_printf(txt_buf + strlen(txt_buf), " Size: %d MiB (Sect: 0x%4X), Range: %06X-%06X\n", + (part->lba_end - part->lba_start + 1) >> SECTORS_TO_MIB_COEFF, + part->lba_end - part->lba_start + 1, part->lba_start, part->lba_end); + } + else + { + s_printf(txt_buf + strlen(txt_buf), "%02d: #96FF00 %s#\n Size: %6d MiB (Sect: 0x%07X), Range: %07X-%07X\n", + gpp_idx++, part->name, (part->lba_end - part->lba_start + 1) >> SECTORS_TO_MIB_COEFF, + part->lba_end - part->lba_start + 1, part->lba_start, part->lba_end); + } + + } + nx_emmc_gpt_free(&gpt); + + lv_label_set_array_text(lb_desc2, txt_buf, 0x1000); + lv_obj_set_width(lb_desc2, lv_obj_get_width(desc2)); + lv_obj_align(desc2, val, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 6, 0); + } + + sdmmc_storage_end(&storage); + free(txt_buf); + + return LV_RES_OK; +} + +static lv_res_t _create_window_sdcard_info_status(lv_obj_t *btn) +{ + lv_obj_t *win = nyx_create_standard_window(SYMBOL_SD" microSD Card Info"); + + lv_obj_t *desc = lv_cont_create(win, NULL); + lv_obj_set_size(desc, LV_HOR_RES / 2 / 5 * 2, LV_VER_RES - (LV_DPI * 11 / 7) * 5 / 2); + + lv_obj_t * lb_desc = lv_label_create(desc, NULL); + lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc, true); + + lv_label_set_static_text(lb_desc, "#D4FF00 Please wait...#"); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + // Disable buttons. + nyx_window_toggle_buttons(win, true); + + manual_system_maintenance(true); + + if (!sd_mount()) + lv_label_set_static_text(lb_desc, "#FFDD00 Failed to init SD!#"); + else + { + lv_label_set_static_text(lb_desc, + "#00DDFF Card IDentification:#\n" + "Vendor ID:\n" + "OEM ID:\n" + "Model:\n" + "HW rev:\n" + "FW rev:\n" + "S/N:\n" + "Month/Year:" + ); + + lv_obj_t *val = lv_cont_create(win, NULL); + lv_obj_set_size(val, LV_HOR_RES / 9 * 2, LV_VER_RES - (LV_DPI * 11 / 7) * 5 / 2); + + lv_obj_t * lb_val = lv_label_create(val, lb_desc); + + char *txt_buf = (char *)malloc(0x1000); + + s_printf(txt_buf,"\n%02x\n%c%c\n%c%c%c%c%c\n%X\n%X\n%08x\n%02d/%04d", + sd_storage.cid.manfid, (sd_storage.cid.oemid >> 8) & 0xFF, sd_storage.cid.oemid & 0xFF, + sd_storage.cid.prod_name[0], sd_storage.cid.prod_name[1], sd_storage.cid.prod_name[2], + sd_storage.cid.prod_name[3], sd_storage.cid.prod_name[4], + sd_storage.cid.hwrev, sd_storage.cid.fwrev, sd_storage.cid.serial, + sd_storage.cid.month, sd_storage.cid.year); + + lv_label_set_array_text(lb_val, txt_buf, 0x1000); + + lv_obj_set_width(lb_val, lv_obj_get_width(val)); + lv_obj_align(val, desc, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + + lv_obj_t *desc2 = lv_cont_create(win, NULL); + lv_obj_set_size(desc2, LV_HOR_RES / 2 / 4 * 2, LV_VER_RES - (LV_DPI * 11 / 7) * 5 / 2); + + lv_obj_t * lb_desc2 = lv_label_create(desc2, lb_desc); + + lv_label_set_static_text(lb_desc2, + "#00DDFF Card-Specific Data#\n" + "Cmd Classes:\n" + "Capacity:\n" + "Bus Width:\n" + "Current Rate:\n" + "Speed Class:\n" + "UHS Grade:\n" + "Video Class:\n" + "App perf class:\n" + "Write Protect:" + ); + lv_obj_set_width(lb_desc2, lv_obj_get_width(desc2)); + lv_obj_align(desc2, val, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 2, 0); + + lv_obj_t *val2 = lv_cont_create(win, NULL); + lv_obj_set_size(val2, LV_HOR_RES / 13 * 3, LV_VER_RES - (LV_DPI * 11 / 7) * 5 / 2); + + lv_obj_t * lb_val2 = lv_label_create(val2, lb_desc); + + + u32 capacity = sd_storage.csd.capacity >> (20 - sd_storage.csd.read_blkbits); + s_printf(txt_buf, "#00DDFF v%d.0#\n%02X\n%d MiB\n%d\n%d MB/s (%d MHz)\n%d\nU%d\nV%d\nA%d\n%d", + sd_storage.csd.structure + 1, sd_storage.csd.cmdclass, capacity, + sd_storage.ssr.bus_width, sd_storage.csd.busspeed, sd_storage.csd.busspeed * 2, + sd_storage.ssr.speed_class, sd_storage.ssr.uhs_grade, sd_storage.ssr.video_class, + sd_storage.ssr.app_class, sd_storage.csd.write_protect); + + lv_label_set_array_text(lb_val2, txt_buf, 0x1000); + + lv_obj_set_width(lb_val2, lv_obj_get_width(val2)); + lv_obj_align(val2, desc2, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + + lv_obj_t *line_sep = lv_line_create(win, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 12, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, lv_theme_get_current()->line.decor); + lv_obj_align(line_sep, desc, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI * 410 / 100, LV_DPI / 5); + + lv_obj_t *desc3 = lv_cont_create(win, NULL); + lv_obj_set_size(desc3, LV_HOR_RES / 2 / 2 * 2, LV_VER_RES - (LV_DPI * 11 / 8) * 4); + + lv_obj_t * lb_desc3 = lv_label_create(desc3, lb_desc); + + lv_label_set_static_text(lb_desc3, "#D4FF00 Acquiring FAT volume info...#"); + + lv_obj_set_width(lb_desc3, lv_obj_get_width(desc3)); + lv_obj_align(desc3, desc, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); + + manual_system_maintenance(true); + + f_getfree("", &sd_fs.free_clst, NULL); + + lv_label_set_static_text(lb_desc3, + "#00DDFF Found FAT volume:#\n" + "Filesystem:\n" + "Cluster:\n" + "Free:" + ); + lv_obj_set_size(desc3, LV_HOR_RES / 2 / 5 * 2, LV_VER_RES - (LV_DPI * 11 / 8) * 4); + lv_obj_set_width(lb_desc3, lv_obj_get_width(desc3)); + lv_obj_align(desc3, desc, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); + + lv_obj_t *val3 = lv_cont_create(win, NULL); + lv_obj_set_size(val3, LV_HOR_RES / 13 * 3, LV_VER_RES - (LV_DPI * 11 / 8) * 4); + + lv_obj_t * lb_val3 = lv_label_create(val3, lb_desc); + + s_printf(txt_buf, "\n%s\n%d KiB\n%d MiB", + sd_fs.fs_type == FS_EXFAT ? ("exFAT "SYMBOL_SHRK) : ("FAT32"), + (sd_fs.csize > 1) ? (sd_fs.csize >> 1) : 512, + sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF); + + lv_label_set_array_text(lb_val3, txt_buf, 0x1000); + + lv_obj_set_width(lb_val3, lv_obj_get_width(val3)); + lv_obj_align(val3, desc3, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + + free(txt_buf); + sd_unmount(false); + } + + nyx_window_toggle_buttons(win, false); + + return LV_RES_OK; +} + +static lv_res_t _create_window_battery_status(lv_obj_t *btn) +{ + lv_obj_t *win = nyx_create_standard_window(SYMBOL_BATTERY_FULL" Battery Info"); + lv_win_add_btn(win, NULL, SYMBOL_DOWNLOAD" Dump Fuel Regs", _battery_dump_window_action); + + lv_obj_t *desc = lv_cont_create(win, NULL); + lv_obj_set_size(desc, LV_HOR_RES / 2 / 4 * 2, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_desc = lv_label_create(desc, NULL); + lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc, true); + + lv_label_set_static_text(lb_desc, + "#00DDFF Fuel Gauge IC Info:#\n" + "Capacity now:\n" + "Capacity now:\n" + "Capacity full:\n" + "Capacity (design):\n" + "Current now:\n" + "Current average:\n" + "Voltage now:\n" + "Voltage open-circuit:\n" + "Min voltage reached:\n" + "Max voltage reached:\n" + "Empty voltage:\n" + "Battery temp:\n\n" + ); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + lv_obj_t *val = lv_cont_create(win, NULL); + lv_obj_set_size(val, LV_HOR_RES / 5, LV_VER_RES - (LV_DPI * 11 / 7)); + + lv_obj_t * lb_val = lv_label_create(val, lb_desc); + + char *txt_buf = (char *)malloc(0x1000); + int value = 0; + + max17050_get_property(MAX17050_RepSOC, &value); + s_printf(txt_buf, "\n%d %\n", value >> 8); + + max17050_get_property(MAX17050_RepCap, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mAh\n", value); + + max17050_get_property(MAX17050_FullCAP, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mAh\n", value); + + max17050_get_property(MAX17050_DesignCap, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mAh\n", value); + + max17050_get_property(MAX17050_Current, &value); + if (value >= 0) + s_printf(txt_buf + strlen(txt_buf), "%d mA\n", value / 1000); + else + s_printf(txt_buf + strlen(txt_buf), "-%d mA\n", (~value + 1) / 1000); + + max17050_get_property(MAX17050_AvgCurrent, &value); + if (value >= 0) + s_printf(txt_buf + strlen(txt_buf), "%d mA\n", value / 1000); + else + s_printf(txt_buf + strlen(txt_buf), "-%d mA\n", (~value + 1) / 1000); + + max17050_get_property(MAX17050_VCELL, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mV\n", value); + + max17050_get_property(MAX17050_OCVInternal, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mV\n", value); + + max17050_get_property(MAX17050_MinVolt, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mV\n", value); + + max17050_get_property(MAX17050_MaxVolt, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mV\n", value); + + max17050_get_property(MAX17050_V_empty, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mV\n", value); + + max17050_get_property(MAX17050_TEMP, &value); + if (value >= 0) + s_printf(txt_buf + strlen(txt_buf), "%d.%d oC\n", value / 10, value % 10); + else + s_printf(txt_buf + strlen(txt_buf), "-%d.%d oC\n", (~value + 1) / 10, (~value + 1) % 10); + + lv_label_set_array_text(lb_val, txt_buf, 0x1000); + + lv_obj_set_width(lb_val, lv_obj_get_width(val)); + lv_obj_align(val, desc, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + + lv_obj_t *desc2 = lv_cont_create(win, NULL); + lv_obj_set_size(desc2, LV_HOR_RES / 2 / 7 * 4, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_desc2 = lv_label_create(desc2, lb_desc); + + lv_label_set_static_text(lb_desc2, + "#00DDFF Battery Charger IC Info:#\n" + "Input voltage limit:\n" + "Input current limit:\n" + "Min voltage limit:\n" + "Fast charge current limit:\n" + "Charge voltage limit:\n" + "Charge status:\n" + "Temperature status:" + ); + lv_obj_set_width(lb_desc2, lv_obj_get_width(desc2)); + lv_obj_align(desc2, val, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 2, 0); + + lv_obj_t *val2 = lv_cont_create(win, NULL); + lv_obj_set_size(val2, LV_HOR_RES / 2 / 3, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + + lv_obj_t * lb_val2 = lv_label_create(val2, lb_desc); + + bq24193_get_property(BQ24193_InputVoltageLimit, &value); + s_printf(txt_buf, "\n%d mV\n", value); + + bq24193_get_property(BQ24193_InputCurrentLimit, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mA\n", value); + + bq24193_get_property(BQ24193_SystemMinimumVoltage, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mV\n", value); + + bq24193_get_property(BQ24193_FastChargeCurrentLimit, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mA\n", value); + + bq24193_get_property(BQ24193_ChargeVoltageLimit, &value); + s_printf(txt_buf + strlen(txt_buf), "%d mV\n", value); + + bq24193_get_property(BQ24193_ChargeStatus, &value); + switch (value) + { + case 0: + s_printf(txt_buf + strlen(txt_buf), "Not charging\n"); + break; + case 1: + s_printf(txt_buf + strlen(txt_buf), "Pre-charging\n"); + break; + case 2: + s_printf(txt_buf + strlen(txt_buf), "Fast charging\n"); + break; + case 3: + s_printf(txt_buf + strlen(txt_buf), "Charge terminated\n"); + break; + default: + s_printf(txt_buf + strlen(txt_buf), "Unknown (%d)\n", value); + break; + } + + bq24193_get_property(BQ24193_TempStatus, &value); + switch (value) + { + case 0: + s_printf(txt_buf + strlen(txt_buf), "Normal"); + break; + case 2: + s_printf(txt_buf + strlen(txt_buf), "Warm"); + break; + case 3: + s_printf(txt_buf + strlen(txt_buf), "Cool"); + break; + case 5: + s_printf(txt_buf + strlen(txt_buf), "Cold"); + break; + case 6: + s_printf(txt_buf + strlen(txt_buf), "Hot"); + break; + default: + s_printf(txt_buf + strlen(txt_buf), "Unknown (%d)", value); + break; + } + + lv_label_set_array_text(lb_val2, txt_buf, 0x1000); + + lv_obj_set_width(lb_val2, lv_obj_get_width(val2)); + lv_obj_align(val2, desc2, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + + free(txt_buf); + + return LV_RES_OK; +} + +void create_tab_info(lv_theme_t *th, lv_obj_t *parent) +{ + lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY); + + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = 0; + h_style.body.padding.hor = LV_DPI - (LV_DPI / 4); + h_style.body.padding.ver = LV_DPI / 6; + + // Create SoC Info container. + lv_obj_t *h1 = lv_cont_create(parent, NULL); + lv_cont_set_style(h1, &h_style); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt = lv_label_create(h1, NULL); + lv_label_set_static_text(label_txt, "SoC Info"); + lv_obj_set_style(label_txt, th->label.prim); + lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, 0); + + lv_obj_t *line_sep = lv_line_create(h1, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, th->line.decor); + lv_obj_align(line_sep, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create Bootrom button. + lv_obj_t *btn = lv_btn_create(h1, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_transp_pr); + } + lv_obj_t *label_btn = lv_label_create(btn, NULL); + lv_btn_set_fit(btn, true, true); + lv_label_set_static_text(label_btn, SYMBOL_CHIP" Bootrom"); + lv_obj_align(btn, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, _create_window_bootrom_info_status); + + // Create TSEC Keys button. + lv_obj_t *btn2 = lv_btn_create(h1, btn); + label_btn = lv_label_create(btn2, NULL); + lv_label_set_static_text(label_btn, SYMBOL_KEY" TSEC Keys"); + lv_obj_align(btn2, btn, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI * 4 / 9, 0); + lv_btn_set_action(btn2, LV_BTN_ACTION_CLICK, _create_window_tsec_keys_status); + + lv_obj_t *label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + lv_label_set_static_text(label_txt2, + "View Ipatches and dump the unpatched and patched versions\nof BootROM.\n" + "Or view and dump the device's TSEC Keys.\n"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + static lv_style_t line_style; + lv_style_copy(&line_style, th->line.decor); + line_style.line.color = LV_COLOR_HEX3(0x444); + + line_sep = lv_line_create(h1, line_sep); + lv_obj_align(line_sep, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 16); + lv_line_set_style(line_sep, &line_style); + + // Create Fuses button. + lv_obj_t *btn3 = lv_btn_create(h1, NULL); + label_btn = lv_label_create(btn3, NULL); + lv_btn_set_fit(btn3, true, true); + lv_label_set_static_text(label_btn, SYMBOL_CIRCUIT" Fuses "); + lv_obj_align(btn3, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 2); + lv_btn_set_action(btn3, LV_BTN_ACTION_CLICK, _create_window_fuses_info_status); + + // Create KFuses button. + lv_obj_t *btn4 = lv_btn_create(h1, btn); + label_btn = lv_label_create(btn4, NULL); + lv_label_set_static_text(label_btn, SYMBOL_SHUFFLE" KFuses"); + lv_obj_align(btn4, btn3, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI * 123 / 100, 0); + lv_btn_set_action(btn4, LV_BTN_ACTION_CLICK, _kfuse_dump_window_action); + + lv_obj_t *label_txt4 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt4, true); + lv_label_set_static_text(label_txt4, + "View and dump your cached fuses and KFuses.\n" + "Fuses contain info about your SoC and device and KFuses\n" + "contain downstream and upstream HDCP keys used by HDMI."); + lv_obj_set_style(label_txt4, &hint_small_style); + lv_obj_align(label_txt4, btn3, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create Storage & Battery Info container. + lv_obj_t *h2 = lv_cont_create(parent, NULL); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, true); + lv_obj_set_width(h2, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h2, false); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt3 = lv_label_create(h2, NULL); + lv_label_set_static_text(label_txt3, "Storage & Battery Info"); + lv_obj_set_style(label_txt3, th->label.prim); + lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, 0); + + line_sep = lv_line_create(h2, line_sep); + lv_obj_align(line_sep, label_txt3, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 2), LV_DPI / 8); + lv_line_set_style(line_sep, th->line.decor); + + // Create eMMC button. + lv_obj_t *btn5 = lv_btn_create(h2, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn5, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn5, LV_BTN_STYLE_PR, &btn_transp_pr); + } + label_btn = lv_label_create(btn5, NULL); + lv_btn_set_fit(btn5, true, true); + lv_label_set_static_text(label_btn, SYMBOL_CHIP" eMMC "); + lv_obj_align(btn5, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 2, LV_DPI / 4); + lv_btn_set_action(btn5, LV_BTN_ACTION_CLICK, _create_window_emmc_info_status); + + // Create microSD button. + lv_obj_t *btn6 = lv_btn_create(h2, btn); + label_btn = lv_label_create(btn6, NULL); + lv_label_set_static_text(label_btn, SYMBOL_SD" microSD "); + lv_obj_align(btn6, btn5, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI * 3 / 4, 0); + lv_btn_set_action(btn6, LV_BTN_ACTION_CLICK, _create_window_sdcard_info_status); + + lv_obj_t *label_txt5 = lv_label_create(h2, NULL); + lv_label_set_recolor(label_txt5, true); + lv_label_set_static_text(label_txt5, + "View info about your eMMC or microSD and additionally\n" + "view their partition list and info."); + lv_obj_set_style(label_txt5, &hint_small_style); + lv_obj_align(label_txt5, btn5, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + line_sep = lv_line_create(h2, line_sep); + lv_obj_align(line_sep, label_txt5, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 2); + lv_line_set_style(line_sep, &line_style); + + // Create Battery button. + lv_obj_t *btn7 = lv_btn_create(h2, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn7, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn7, LV_BTN_STYLE_PR, &btn_transp_pr); + } + label_btn = lv_label_create(btn7, NULL); + lv_btn_set_fit(btn7, true, true); + lv_label_set_static_text(label_btn, SYMBOL_BATTERY_FULL" Battery"); + lv_obj_align(btn7, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 2); + lv_btn_set_action(btn7, LV_BTN_ACTION_CLICK, _create_window_battery_status); + + lv_obj_t *label_txt6 = lv_label_create(h2, NULL); + lv_label_set_recolor(label_txt6, true); + lv_label_set_static_text(label_txt6, + "View battery and battery charger related info.\n" + "Additionally you can dump battery charger's registers.\n"); + lv_obj_set_style(label_txt6, &hint_small_style); + lv_obj_align(label_txt6, btn7, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); +} + +#pragma GCC pop_options diff --git a/nyx/nyx_gui/frontend/gui_info.h b/nyx/nyx_gui/frontend/gui_info.h new file mode 100644 index 0000000..f729957 --- /dev/null +++ b/nyx/nyx_gui/frontend/gui_info.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _GUI_INFO_H_ +#define _GUI_INFO_H_ + +#include "../libs/lvgl/lvgl.h" + +void create_tab_info(lv_theme_t *th, lv_obj_t *parent); + +#endif diff --git a/nyx/nyx_gui/frontend/gui_tools.c b/nyx/nyx_gui/frontend/gui_tools.c new file mode 100644 index 0000000..532e53f --- /dev/null +++ b/nyx/nyx_gui/frontend/gui_tools.c @@ -0,0 +1,902 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "gui.h" +#include "gui_emmc_tools.h" +#include "../config/config.h" +#include "../hos/pkg1.h" +#include "../hos/pkg2.h" +#include "../hos/hos.h" +#include "../hos/sept.h" +#include "../libs/fatfs/ff.h" +#include "../mem/heap.h" +#include "../sec/se.h" +#include "../soc/fuse.h" +#include "../storage/nx_emmc.h" +#include "../storage/sdmmc.h" +#include "../utils/sprintf.h" +#include "../utils/util.h" + +extern volatile boot_cfg_t *b_cfg; +extern hekate_config h_cfg; + +extern bool sd_mount(); +extern void sd_unmount(bool deinit); +extern int sd_save_to_file(void *buf, u32 size, const char *filename); +extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); + +#pragma GCC push_options +#pragma GCC target ("thumb") + +static bool _get_autorcm_status(bool change) +{ + u8 corr_mod_byte0; + sdmmc_storage_t storage; + sdmmc_t sdmmc; + bool enabled = false; + + sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4); + + u8 *tempbuf = (u8 *)malloc(0x200); + sdmmc_storage_set_mmc_partition(&storage, 1); + sdmmc_storage_read(&storage, 0x200 / NX_EMMC_BLOCKSIZE, 1, tempbuf); + + if ((fuse_read_odm(4) & 3) != 3) + corr_mod_byte0 = 0xF7; + else + corr_mod_byte0 = 0x37; + + if (tempbuf[0x10] != corr_mod_byte0) + enabled = true; + + // Change autorcm status if requested. + if (change) + { + int i, sect = 0; + u8 randomXor = 0; + + for (i = 0; i < 4; i++) + { + sect = (0x200 + (0x4000 * i)) / NX_EMMC_BLOCKSIZE; + sdmmc_storage_read(&storage, sect, 1, tempbuf); + + if (!enabled) + { + do + { + randomXor = get_tmr_us() & 0xFF; // Bricmii style of bricking. + } while (!randomXor); // Avoid the lottery. + + tempbuf[0x10] ^= randomXor; + } + else + tempbuf[0x10] = corr_mod_byte0; + sdmmc_storage_write(&storage, sect, 1, tempbuf); + } + enabled = !(enabled); + } + + free(tempbuf); + sdmmc_storage_end(&storage); + + return enabled; +} + +static lv_res_t _create_mbox_autorcm_status(lv_obj_t *btn) +{ + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\211", "\222OK", "\211", "" }; + lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + + bool enabled = _get_autorcm_status(true); + + if (enabled) + { + lv_mbox_set_text(mbox, + "AutoRCM is now #C7EA46 ENABLED!#\n\n" + "You can now automatically enter RCM by only pressing #FF8000 POWER#.\n" + "Use the AutoRCM button here again if you want to remove it later on."); + } + else + { + lv_mbox_set_text(mbox, + "AutoRCM is now #FF8000 DISABLED!#\n\n" + "The boot process is now normal and you need the #FF8000 VOL-# + #FF8000 HOME# (jig) combo to enter RCM.\n"); + } + + lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + + if (enabled) + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + else + lv_btn_set_state(btn, LV_BTN_STATE_REL); + nyx_generic_onoff_toggle(btn); + + return LV_RES_OK; +} + +static int _fix_attributes(u32 *ufidx, lv_obj_t *lb_val, char *path, u32 *total, u32 hos_folder, u32 check_first_run) +{ + FRESULT res; + DIR dir; + u32 dirLength = 0; + static FILINFO fno; + + if (check_first_run) + { + // Read file attributes. + res = f_stat(path, &fno); + if (res != FR_OK) + return res; + + // Check if archive bit is set. + if (fno.fattrib & AM_ARC) + { + *(u32 *)total = *(u32 *)total + 1; + f_chmod(path, 0, AM_ARC); + } + } + + // Open directory. + res = f_opendir(&dir, path); + if (res != FR_OK) + return res; + + dirLength = strlen(path); + for (;;) + { + // Clear file or folder path. + path[dirLength] = 0; + + // Read a directory item. + res = f_readdir(&dir, &fno); + + // Break on error or end of dir. + if (res != FR_OK || fno.fname[0] == 0) + break; + + // Skip official Nintendo dir if started from root. + if (!hos_folder && !strcmp(fno.fname, "Nintendo")) + continue; + + // Set new directory or file. + memcpy(&path[dirLength], "/", 1); + memcpy(&path[dirLength + 1], fno.fname, strlen(fno.fname) + 1); + + // Check if archive bit is set. + if (fno.fattrib & AM_ARC) + { + *total = *total + 1; + f_chmod(path, 0, AM_ARC); + + if (*ufidx == 0) + lv_label_set_array_text(lb_val, path, 256); + *ufidx += 1; + if (*ufidx > 9) + *ufidx = 0; + } + + manual_system_maintenance(true); + + // Is it a directory? + if (fno.fattrib & AM_DIR) + { + // Set archive bit to NCA folders. + if (hos_folder && !strcmp(fno.fname + strlen(fno.fname) - 4, ".nca")) + { + *total = *total + 1; + f_chmod(path, AM_ARC, AM_ARC); + } + lv_label_set_array_text(lb_val, path, 256); + manual_system_maintenance(true); + + // Enter the directory. + res = _fix_attributes(ufidx, lb_val, path, total, hos_folder, 0); + if (res != FR_OK) + break; + } + } + + f_closedir(&dir); + + return res; +} + +static lv_res_t _create_window_unset_abit_tool(lv_obj_t *btn) +{ + lv_obj_t *win; + + // Find which was called and set window's title. + bool nintendo_folder = false; + if (strcmp(lv_label_get_text(lv_obj_get_child(btn, NULL)), SYMBOL_COPY" Unset archive bit")) + nintendo_folder = true; + + if (!nintendo_folder) + win = nyx_create_standard_window(SYMBOL_COPY" Unset archive bit (except Nintendo folder)"); + else + win = nyx_create_standard_window(SYMBOL_COPY" Fix archive bit (Nintendo folder)"); + + // Disable buttons. + nyx_window_toggle_buttons(win, true); + + lv_obj_t *desc = lv_cont_create(win, NULL); + lv_obj_set_size(desc, LV_HOR_RES * 10 / 11, LV_VER_RES - (LV_DPI * 11 / 7) * 4); + + lv_obj_t * lb_desc = lv_label_create(desc, NULL); + lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc, true); + + if (!sd_mount()) + { + lv_label_set_static_text(lb_desc, "#FFDD00 Failed to init SD!#"); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + } + else + { + if (!nintendo_folder) + lv_label_set_static_text(lb_desc, "#00DDFF Traversing all SD card files!#\nThis may take some time..."); + else + lv_label_set_static_text(lb_desc, "#00DDFF Traversing all Nintendo files!#\nThis may take some time..."); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + lv_obj_t *val = lv_cont_create(win, NULL); + lv_obj_set_size(val, LV_HOR_RES * 10 / 11, LV_VER_RES - (LV_DPI * 11 / 7) * 4); + + lv_obj_t * lb_val = lv_label_create(val, lb_desc); + + char path[256]; + path[0] = 0; + + lv_label_set_static_text(lb_val, ""); + lv_obj_set_width(lb_val, lv_obj_get_width(val)); + lv_obj_align(val, desc, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + + u32 total = 0; + + if (!nintendo_folder) + memcpy(path, "", 1); + else + memcpy(path, "Nintendo", 9); + + u32 ufidx = 0; + + _fix_attributes(&ufidx, lb_val, path, &total, nintendo_folder, nintendo_folder); + + sd_unmount(false); + + lv_obj_t *desc2 = lv_cont_create(win, NULL); + lv_obj_set_size(desc2, LV_HOR_RES * 10 / 11, LV_VER_RES - (LV_DPI * 11 / 7) * 4); + lv_obj_t * lb_desc2 = lv_label_create(desc2, lb_desc); + + char *txt_buf = (char *)malloc(0x500); + + s_printf(txt_buf, "#96FF00 Total archive bits fixed:# #FF8000 %d!#", total); + + lv_label_set_array_text(lb_desc2, txt_buf, 0x500); + lv_obj_set_width(lb_desc2, lv_obj_get_width(desc2)); + lv_obj_align(desc2, val, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); + } + + // Enable buttons. + nyx_window_toggle_buttons(win, false); + + return LV_RES_OK; +} + +static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn) +{ + lv_obj_t *win = nyx_create_standard_window(SYMBOL_MODULES" Dump package1/2"); + + // Disable buttons. + nyx_window_toggle_buttons(win, true); + + lv_obj_t *desc = lv_cont_create(win, NULL); + lv_obj_set_size(desc, LV_HOR_RES * 10 / 11, LV_VER_RES - (LV_DPI * 12 / 7)); + + lv_obj_t * lb_desc = lv_label_create(desc, NULL); + lv_obj_set_style(lb_desc, &monospace_text); + lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); + lv_label_set_recolor(lb_desc, true); + lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); + + if (!sd_mount()) + { + lv_label_set_static_text(lb_desc, "#FFDD00 Failed to init SD!#"); + + goto out_end; + } + + char path[128]; + + u8 *pkg1 = (u8 *)calloc(1, 0x40000); + u8 *warmboot = (u8 *)calloc(1, 0x40000); + u8 *secmon = (u8 *)calloc(1, 0x40000); + u8 *loader = (u8 *)calloc(1, 0x40000); + u8 *pkg2 = NULL; + u8 kb = 0; + + char *txt_buf = (char *)malloc(0x1000); + char *txt_buf2 = (char *)malloc(0x1000); + + tsec_ctxt_t tsec_ctxt; + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + + if (!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4)) + { + lv_label_set_static_text(lb_desc, "#FFDD00 Failed to init eMMC!#"); + + goto out_free; + } + + sdmmc_storage_set_mmc_partition(&storage, 1); + + // Read package1. + char *build_date = malloc(32); + sdmmc_storage_read(&storage, 0x100000 / NX_EMMC_BLOCKSIZE, 0x40000 / NX_EMMC_BLOCKSIZE, pkg1); + const pkg1_id_t *pkg1_id = pkg1_identify(pkg1, build_date); + + s_printf(txt_buf, "#00DDFF Found pkg1 ('%s')#\n\n", build_date); + free(build_date); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + // Dump package1 in its encrypted state if unknown. + if (!pkg1_id) + { + s_printf(txt_buf + strlen(txt_buf), "#FFDD00 Unknown pkg1 version for reading\nTSEC firmware!#"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + emmcsn_path_impl(path, "/pkg1", "pkg1_enc.bin", &storage); + if (sd_save_to_file(pkg1, 0x40000, path)) + goto out_free; + + s_printf(txt_buf + strlen(txt_buf), "\nEncrypted pkg1 dumped to pkg1_enc.bin"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + goto out_free; + } + + const pk11_hdr_t *hdr = (pk11_hdr_t *)(pkg1 + pkg1_id->pkg11_off + 0x20); + + kb = pkg1_id->kb; + + if (!h_cfg.se_keygen_done) + { + tsec_ctxt.fw = (void *)pkg1 + pkg1_id->tsec_off; + tsec_ctxt.pkg1 = (void *)pkg1; + tsec_ctxt.pkg11_off = pkg1_id->pkg11_off; + tsec_ctxt.secmon_base = pkg1_id->secmon_base; + + if (kb >= KB_FIRMWARE_VERSION_700 && !h_cfg.sept_run) + { + b_cfg->autoboot = 0; + b_cfg->autoboot_list = 0; + + if (!reboot_to_sept((u8 *)tsec_ctxt.fw, kb)) + { + lv_label_set_static_text(lb_desc, "FFDD00 Failed to run sept#\n"); + goto out_free; + } + } + + // Read keyblob. + u8 *keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1); + sdmmc_storage_read(&storage, 0x180000 / NX_EMMC_BLOCKSIZE + kb, 1, keyblob); + + // Decrypt. + keygen(keyblob, kb, &tsec_ctxt); + if (kb <= KB_FIRMWARE_VERSION_600) + h_cfg.se_keygen_done = 1; + free(keyblob); + } + + if (kb <= KB_FIRMWARE_VERSION_600) + pkg1_decrypt(pkg1_id, pkg1); + + if (kb <= KB_FIRMWARE_VERSION_620) + { + pkg1_unpack(warmboot, secmon, loader, pkg1_id, pkg1); + + // Display info. + s_printf(txt_buf + strlen(txt_buf), + "#C7EA46 NX Bootloader size: #0x%05X\n" + "#C7EA46 Secure monitor addr: #0x%05X\n" + "#C7EA46 Secure monitor size: #0x%05X\n" + "#C7EA46 Warmboot addr: #0x%05X\n" + "#C7EA46 Warmboot size: #0x%05X\n\n", + hdr->ldr_size, pkg1_id->secmon_base, hdr->sm_size, pkg1_id->warmboot_base, hdr->wb_size); + + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + // Dump package1.1. + emmcsn_path_impl(path, "/pkg1", "pkg1_decr.bin", &storage); + if (sd_save_to_file(pkg1, 0x40000, path)) + goto out_free; + s_printf(txt_buf + strlen(txt_buf), "pkg1 dumped to pkg1_decr.bin\n"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + // Dump nxbootloader. + emmcsn_path_impl(path, "/pkg1", "nxloader.bin", &storage); + if (sd_save_to_file(loader, hdr->ldr_size, path)) + goto out_free; + s_printf(txt_buf + strlen(txt_buf), "NX Bootloader dumped to nxloader.bin\n"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + // Dump secmon. + emmcsn_path_impl(path, "/pkg1", "secmon.bin", &storage); + if (sd_save_to_file(secmon, hdr->sm_size, path)) + goto out_free; + s_printf(txt_buf + strlen(txt_buf), "Secure Monitor dumped to secmon.bin\n"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + // Dump warmboot. + emmcsn_path_impl(path, "/pkg1", "warmboot.bin", &storage); + if (sd_save_to_file(warmboot, hdr->wb_size, path)) + goto out_free; + s_printf(txt_buf + strlen(txt_buf), "Warmboot dumped to warmboot.bin\n\n"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + } + + // Dump package2.1. + sdmmc_storage_set_mmc_partition(&storage, 0); + // Parse eMMC GPT. + LIST_INIT(gpt); + nx_emmc_gpt_parse(&gpt, &storage); + // Find package2 partition. + emmc_part_t *pkg2_part = nx_emmc_part_find(&gpt, "BCPKG2-1-Normal-Main"); + if (!pkg2_part) + goto out; + + // Read in package2 header and get package2 real size. + u8 *tmp = (u8 *)malloc(NX_EMMC_BLOCKSIZE); + nx_emmc_part_read(&storage, pkg2_part, 0x4000 / NX_EMMC_BLOCKSIZE, 1, tmp); + u32 *hdr_pkg2_raw = (u32 *)(tmp + 0x100); + u32 pkg2_size = hdr_pkg2_raw[0] ^ hdr_pkg2_raw[2] ^ hdr_pkg2_raw[3]; + free(tmp); + // Read in package2. + u32 pkg2_size_aligned = ALIGN(pkg2_size, NX_EMMC_BLOCKSIZE); + pkg2 = malloc(pkg2_size_aligned); + nx_emmc_part_read(&storage, pkg2_part, 0x4000 / NX_EMMC_BLOCKSIZE, + pkg2_size_aligned / NX_EMMC_BLOCKSIZE, pkg2); +#if 0 + emmcsn_path_impl(path, "/pkg2", "pkg2_encr.bin", &storage); + if (sd_save_to_file(pkg2, pkg2_size_aligned, path)) + goto out; + gfx_puts("\npkg2 dumped to pkg2_encr.bin\n"); +#endif + + // Decrypt package2 and parse KIP1 blobs in INI1 section. + pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(pkg2); + if (!pkg2_hdr) + { + s_printf(txt_buf + strlen(txt_buf), "FFDD00 Pkg2 decryption failed!#"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + goto out; + } + + // Display info. + s_printf(txt_buf + strlen(txt_buf), + "#C7EA46 Kernel size: #0x%05X\n" + "#C7EA46 INI1 size: #0x%05X\n\n", + pkg2_hdr->sec_size[PKG2_SEC_KERNEL], pkg2_hdr->sec_size[PKG2_SEC_INI1]); + + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + // Dump pkg2.1. + emmcsn_path_impl(path, "/pkg2", "pkg2_decr.bin", &storage); + if (sd_save_to_file(pkg2, pkg2_hdr->sec_size[PKG2_SEC_KERNEL] + pkg2_hdr->sec_size[PKG2_SEC_INI1], path)) + goto out; + s_printf(txt_buf + strlen(txt_buf), "pkg2 dumped to pkg2_decr.bin\n"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + // Dump kernel. + emmcsn_path_impl(path, "/pkg2", "kernel.bin", &storage); + if (sd_save_to_file(pkg2_hdr->data, pkg2_hdr->sec_size[PKG2_SEC_KERNEL], path)) + goto out; + s_printf(txt_buf + strlen(txt_buf), "Kernel dumped to kernel.bin\n"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + // Dump INI1. + u32 ini1_off = pkg2_hdr->sec_size[PKG2_SEC_KERNEL]; + u32 ini1_size = pkg2_hdr->sec_size[PKG2_SEC_INI1]; + if (!ini1_size) + { + ini1_off = *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_START); + ini1_size = *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_END) - *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_START); + } + pkg2_ini1_t *ini1 = (pkg2_ini1_t *)(pkg2_hdr->data + ini1_off); + emmcsn_path_impl(path, "/pkg2", "ini1.bin", &storage); + if (sd_save_to_file(ini1, ini1_size, path)) + goto out; + + s_printf(txt_buf + strlen(txt_buf), "INI1 dumped to ini1.bin\n\n"); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + char filename[32]; + u8 *ptr = (u8 *)ini1; + ptr += sizeof(pkg2_ini1_t); + + // Dump all kips. + u8 *kip_buffer = (u8 *)malloc(0x400000); + + for (u32 i = 0; i < ini1->num_procs; i++) + { + pkg2_kip1_t *kip1 = (pkg2_kip1_t *)ptr; + u32 kip1_size = pkg2_calc_kip1_size(kip1); + + s_printf(filename, "%s.kip1", kip1->name); + if ((u32)kip1 % 8) + { + memcpy(kip_buffer, kip1, kip1_size); + kip1 = (pkg2_kip1_t *)kip_buffer; + } + + emmcsn_path_impl(path, "/pkg2/ini1", filename, &storage); + if (sd_save_to_file(kip1, kip1_size, path)) + { + free(kip_buffer); + goto out; + } + + s_printf(txt_buf + strlen(txt_buf), "%s kip dumped to %s.kip1\n", kip1->name, kip1->name); + lv_label_set_array_text(lb_desc, txt_buf, 0x1000); + manual_system_maintenance(true); + + ptr += kip1_size; + } + free(kip_buffer); + +out: + nx_emmc_gpt_free(&gpt); +out_free: + free(pkg1); + free(secmon); + free(warmboot); + free(loader); + free(pkg2); + free(txt_buf); + free(txt_buf2); + sdmmc_storage_end(&storage); + sd_unmount(false); + + if (kb >= KB_FIRMWARE_VERSION_620) + se_aes_key_clear(8); +out_end: + // Enable buttons. + nyx_window_toggle_buttons(win, false); + + return LV_RES_OK; +} + +void sept_run_dump() +{ + _create_window_dump_pk12_tool(NULL); +} + +static void _create_tab_tools_emmc_pkg12(lv_theme_t *th, lv_obj_t *parent) +{ + lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY); + + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = 0; + h_style.body.padding.hor = LV_DPI - (LV_DPI / 4); + h_style.body.padding.ver = LV_DPI / 6; + + // Create Backup & Restore container. + lv_obj_t *h1 = lv_cont_create(parent, NULL); + lv_cont_set_style(h1, &h_style); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt = lv_label_create(h1, NULL); + lv_label_set_static_text(label_txt, "Backup & Restore"); + lv_obj_set_style(label_txt, th->label.prim); + lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI * 3 / 10); + + lv_obj_t *line_sep = lv_line_create(h1, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, th->line.decor); + lv_obj_align(line_sep, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create Backup eMMC button. + lv_obj_t *btn = lv_btn_create(h1, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_transp_pr); + } + lv_obj_t *label_btn = lv_label_create(btn, NULL); + lv_btn_set_fit(btn, true, true); + lv_label_set_static_text(label_btn, SYMBOL_UPLOAD" Backup eMMC"); + lv_obj_align(btn, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, create_window_backup_restore_tool); + + lv_obj_t *label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + lv_label_set_static_text(label_txt2, + "Allows you to backup your eMMC partitions individually or as\n" + "a whole raw image to your SD card.\n" + "#FF8000 Supports SD cards from 4GB and up. FAT32 and exFAT.#"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create Restore eMMC button. + lv_obj_t *btn2 = lv_btn_create(h1, btn); + label_btn = lv_label_create(btn2, NULL); + lv_label_set_static_text(label_btn, SYMBOL_DOWNLOAD" Restore eMMC"); + lv_obj_align(btn2, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); + lv_btn_set_action(btn2, LV_BTN_ACTION_CLICK, create_window_backup_restore_tool); + + label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + lv_label_set_static_text(label_txt2, + "Allows you to restore your eMMC partitions individually or as\n" + "a whole raw image to your SD card.\n" + "#FF8000 Supports SD cards from 4GB and up. FAT32 and exFAT. #"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create Misc container. + lv_obj_t *h2 = lv_cont_create(parent, NULL); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, true); + lv_obj_set_width(h2, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h2, false); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt3 = lv_label_create(h2, NULL); + lv_label_set_static_text(label_txt3, "Misc"); + lv_obj_set_style(label_txt3, th->label.prim); + lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI * 3 / 10); + + line_sep = lv_line_create(h2, line_sep); + lv_obj_align(line_sep, label_txt3, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create Dump Package1/2 button. + lv_obj_t *btn3 = lv_btn_create(h2, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn3, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn3, LV_BTN_STYLE_PR, &btn_transp_pr); + } + label_btn = lv_label_create(btn3, NULL); + lv_btn_set_fit(btn3, true, true); + lv_label_set_static_text(label_btn, SYMBOL_MODULES" Dump Package1/2"); + lv_obj_align(btn3, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + lv_btn_set_action(btn3, LV_BTN_ACTION_CLICK, _create_window_dump_pk12_tool); + + lv_obj_t *label_txt4 = lv_label_create(h2, NULL); + lv_label_set_recolor(label_txt4, true); + lv_label_set_static_text(label_txt4, + "Allows you to dump and decrypt pkg1 and pkg2 and further\n" + "split it up into their individual parts. It also dumps the kip1.\n\n"); + lv_obj_set_style(label_txt4, &hint_small_style); + lv_obj_align(label_txt4, btn3, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + lv_obj_align(label_sep, label_txt4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 11 / 7); +} + +static void _create_tab_tools_arc_autorcm(lv_theme_t *th, lv_obj_t *parent) +{ + lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY); + + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = 0; + h_style.body.padding.hor = LV_DPI - (LV_DPI / 4); + h_style.body.padding.ver = LV_DPI / 6; + + // Create Misc container. + lv_obj_t *h1 = lv_cont_create(parent, NULL); + lv_cont_set_style(h1, &h_style); + lv_cont_set_fit(h1, false, true); + lv_obj_set_width(h1, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h1, false); + lv_cont_set_layout(h1, LV_LAYOUT_OFF); + + lv_obj_t *label_sep = lv_label_create(h1, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt = lv_label_create(h1, NULL); + lv_label_set_static_text(label_txt, "Misc"); + lv_obj_set_style(label_txt, th->label.prim); + lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI * 3 / 10); + + lv_obj_t *line_sep = lv_line_create(h1, NULL); + static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; + lv_line_set_points(line_sep, line_pp, 2); + lv_line_set_style(line_sep, th->line.decor); + lv_obj_align(line_sep, label_txt, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create Unset archive bit button. + lv_obj_t *btn = lv_btn_create(h1, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_transp_pr); + } + lv_obj_t *label_btn = lv_label_create(btn, NULL); + lv_btn_set_fit(btn, true, true); + lv_label_set_static_text(label_btn, SYMBOL_COPY" Unset archive bit"); + lv_obj_align(btn, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, _create_window_unset_abit_tool); + + lv_obj_t *label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + lv_label_set_static_text(label_txt2, + "Allows you to unset the archive bit for all folders except the\n" + "Nintendo folder.\n" + "#FF8000 If you want the Nintendo folder, use the below option.#"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create Fix archive bit - Nintendo button. + lv_obj_t *btn2 = lv_btn_create(h1, btn); + label_btn = lv_label_create(btn2, NULL); + lv_label_set_static_text(label_btn, SYMBOL_DIRECTORY" Fix archive bit - Nintendo"); + lv_obj_align(btn2, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); + lv_btn_set_action(btn2, LV_BTN_ACTION_CLICK, _create_window_unset_abit_tool); + + label_txt2 = lv_label_create(h1, NULL); + lv_label_set_recolor(label_txt2, true); + lv_label_set_static_text(label_txt2, + "Allows you to fix your Nintendo folder's archive bits.\n" + "They are required for the NCA folders but not anywhere else.\n" + "#FF8000 Use that option when you have corruption messages.#"); + lv_obj_set_style(label_txt2, &hint_small_style); + lv_obj_align(label_txt2, btn2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + // Create Others container. + lv_obj_t *h2 = lv_cont_create(parent, NULL); + lv_cont_set_style(h2, &h_style); + lv_cont_set_fit(h2, false, true); + lv_obj_set_width(h2, (LV_HOR_RES / 9) * 4); + lv_obj_set_click(h2, false); + lv_cont_set_layout(h2, LV_LAYOUT_OFF); + lv_obj_align(h2, h1, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + + lv_obj_t *label_txt3 = lv_label_create(h2, NULL); + lv_label_set_static_text(label_txt3, "Others"); + lv_obj_set_style(label_txt3, th->label.prim); + lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI * 3 / 10); + + line_sep = lv_line_create(h2, line_sep); + lv_obj_align(line_sep, label_txt3, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); + + // Create AutoRCM On/Off button. + lv_obj_t *btn3 = lv_btn_create(h2, NULL); + if (hekate_bg) + { + lv_btn_set_style(btn3, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn3, LV_BTN_STYLE_PR, &btn_transp_pr); + lv_btn_set_style(btn3, LV_BTN_STYLE_TGL_REL, &btn_transp_tgl_rel); + lv_btn_set_style(btn3, LV_BTN_STYLE_TGL_PR, &btn_transp_tgl_pr); + } + label_btn = lv_label_create(btn3, NULL); + lv_btn_set_fit(btn3, true, true); + lv_label_set_recolor(label_btn, true); + lv_label_set_static_text(label_btn, SYMBOL_REFRESH" AutoRCM #00ffc9 ON #"); + lv_obj_align(btn3, line_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 4); + lv_btn_set_action(btn3, LV_BTN_ACTION_CLICK, _create_mbox_autorcm_status); + + // Set default state for AutoRCM and lock it out if patched unit. + if (_get_autorcm_status(false)) + lv_btn_set_state(btn3, LV_BTN_STATE_TGL_REL); + else + lv_btn_set_state(btn3, LV_BTN_STATE_REL); + nyx_generic_onoff_toggle(btn3); + + if (h_cfg.rcm_patched) + { + lv_obj_set_click(btn3, false); + lv_btn_set_state(btn3, LV_BTN_STATE_INA); + } + + char *txt_buf = (char *)malloc(0x1000); + + s_printf(txt_buf, + "Allows you to enter RCM without using #C7EA46 VOL-# + #C7EA46 HOME# (jig).\n" + "#FF8000 It can restore all versions of AutoRCM whenever requested.#\n" + "#FF3C28 This corrupts your BCT and you can't boot without a custom#\n" + "#FF3C28 bootloader.#"); + + if (h_cfg.rcm_patched) + s_printf(txt_buf + strlen(txt_buf), " #FF8000 This is disabled because this unit is patched!#"); + + lv_obj_t *label_txt4 = lv_label_create(h2, NULL); + lv_label_set_recolor(label_txt4, true); + lv_label_set_array_text(label_txt4, txt_buf, 0x1000); + free(txt_buf); + + lv_obj_set_style(label_txt4, &hint_small_style); + lv_obj_align(label_txt4, btn3, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); + + label_sep = lv_label_create(h2, NULL); + lv_label_set_static_text(label_sep, ""); + lv_obj_align(label_sep, label_txt4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 11 / 7); +} + +void create_tab_tools(lv_theme_t *th, lv_obj_t *parent) +{ + lv_obj_t *tv = lv_tabview_create(parent, NULL); + + lv_obj_set_size(tv, LV_HOR_RES, 572); + + static lv_style_t tabview_style; + lv_style_copy(&tabview_style, th->tabview.btn.rel); + tabview_style.body.padding.ver = LV_DPI / 8; + + lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_REL, &tabview_style); + if (hekate_bg) + { + lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_PR, &tabview_btn_pr); + lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_TGL_PR, &tabview_btn_tgl_pr); + } + + lv_tabview_set_sliding(tv, false); + lv_tabview_set_btns_pos(tv, LV_TABVIEW_BTNS_POS_BOTTOM); + + lv_obj_t *tab1= lv_tabview_add_tab(tv, "eMMC "SYMBOL_DOT" Package1/2"); + lv_obj_t *tab2 = lv_tabview_add_tab(tv, "Archive bit "SYMBOL_DOT" AutoRCM"); + + _create_tab_tools_emmc_pkg12(th, tab1); + _create_tab_tools_arc_autorcm(th, tab2); + + lv_tabview_set_tab_act(tv, 0, false); +} + +#pragma GCC pop_options diff --git a/nyx/nyx_gui/frontend/gui_tools.h b/nyx/nyx_gui/frontend/gui_tools.h new file mode 100644 index 0000000..73a78ce --- /dev/null +++ b/nyx/nyx_gui/frontend/gui_tools.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _GUI_TOOLS_H_ +#define _GUI_TOOLS_H_ + +#include "../libs/lvgl/lvgl.h" + +void create_tab_tools(lv_theme_t *th, lv_obj_t *parent); +void sept_run_dump(); + +#endif diff --git a/nyx/nyx_gui/gfx/di.c b/nyx/nyx_gui/gfx/di.c new file mode 100644 index 0000000..28ee3a5 --- /dev/null +++ b/nyx/nyx_gui/gfx/di.c @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "di.h" +#include "../gfx/gfx.h" +#include "../power/max77620.h" +#include "../power/max7762x.h" +#include "../soc/clock.h" +#include "../soc/gpio.h" +#include "../soc/i2c.h" +#include "../soc/pinmux.h" +#include "../soc/pmc.h" +#include "../soc/t210.h" +#include "../utils/util.h" + +#pragma GCC push_options +#pragma GCC target ("thumb") +#pragma GCC optimize ("Os") + +#include "di.inl" + +static u32 _display_ver = 0; + +static void _display_dsi_wait(u32 timeout, u32 off, u32 mask) +{ + u32 end = get_tmr_us() + timeout; + while (get_tmr_us() < end && DSI(off) & mask) + ; + usleep(5); +} + +void display_init() +{ + // Power on. + max77620_regulator_set_volt_and_flags(REGULATOR_LDO0, 1200000, MAX77620_POWER_MODE_NORMAL); // Configure to 1.2V. + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_GPIO7, MAX77620_CNFG_GPIO_OUTPUT_VAL_HIGH | MAX77620_CNFG_GPIO_DRV_PUSHPULL); + + // Enable MIPI CAL, DSI, DISP1, HOST1X, UART_FST_MIPI_CAL, DSIA LP clocks. + CLOCK(CLK_RST_CONTROLLER_RST_DEV_H_CLR) = 0x1010000; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_H_SET) = 0x1010000; + CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_CLR) = 0x18000000; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_SET) = 0x18000000; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_X_SET) = 0x20000; + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_UART_FST_MIP_CAL) = 0xA; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_W_SET) = 0x80000; + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_DSIA_LP) = 0xA; + + // DPD idle. + PMC(APBDEV_PMC_IO_DPD_REQ) = 0x40000000; + PMC(APBDEV_PMC_IO_DPD2_REQ) = 0x40000000; + + // Config pins. + PINMUX_AUX(PINMUX_AUX_NFC_EN) &= ~PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_NFC_INT) &= ~PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) &= ~PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_LCD_BL_EN) &= ~PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_LCD_RST) &= ~PINMUX_TRISTATE; + + gpio_config(GPIO_PORT_I, GPIO_PIN_0 | GPIO_PIN_1, GPIO_MODE_GPIO); // Backlight +-5V. + gpio_output_enable(GPIO_PORT_I, GPIO_PIN_0 | GPIO_PIN_1, GPIO_OUTPUT_ENABLE); // Backlight +-5V. + gpio_write(GPIO_PORT_I, GPIO_PIN_0, GPIO_HIGH); // Backlight +5V enable. + + usleep(10000); + + gpio_write(GPIO_PORT_I, GPIO_PIN_1, GPIO_HIGH); // Backlight -5V enable. + + usleep(10000); + + gpio_config(GPIO_PORT_V, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, GPIO_MODE_GPIO); // Backlight PWM, Enable, Reset. + gpio_output_enable(GPIO_PORT_V, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, GPIO_OUTPUT_ENABLE); + gpio_write(GPIO_PORT_V, GPIO_PIN_1, GPIO_HIGH); // Backlight Enable enable. + + // Config display interface and display. + MIPI_CAL(MIPI_CAL_MIPI_BIAS_PAD_CFG2) = 0; + + exec_cfg((u32 *)CLOCK_BASE, _display_config_1, 4); + exec_cfg((u32 *)DISPLAY_A_BASE, _display_config_2, 94); + exec_cfg((u32 *)DSI_BASE, _display_config_3, 61); + + usleep(10000); + + gpio_write(GPIO_PORT_V, GPIO_PIN_2, GPIO_HIGH); // Backlight Reset enable. + + usleep(60000); + + DSI(_DSIREG(DSI_BTA_TIMING)) = 0x50204; + DSI(_DSIREG(DSI_WR_DATA)) = 0x337; // MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE + DSI(_DSIREG(DSI_TRIGGER)) = DSI_TRIGGER_HOST; + _display_dsi_wait(250000, _DSIREG(DSI_TRIGGER), DSI_TRIGGER_HOST | DSI_TRIGGER_VIDEO); + + DSI(_DSIREG(DSI_WR_DATA)) = 0x406; // MIPI_DCS_GET_DISPLAY_ID + DSI(_DSIREG(DSI_TRIGGER)) = DSI_TRIGGER_HOST; + _display_dsi_wait(250000, _DSIREG(DSI_TRIGGER), DSI_TRIGGER_HOST | DSI_TRIGGER_VIDEO); + + DSI(_DSIREG(DSI_HOST_CONTROL)) = DSI_HOST_CONTROL_TX_TRIG_HOST | DSI_HOST_CONTROL_IMM_BTA | DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC; + _display_dsi_wait(150000, _DSIREG(DSI_HOST_CONTROL), DSI_HOST_CONTROL_IMM_BTA); + + usleep(5000); + + _display_ver = DSI(_DSIREG(DSI_RD_DATA)); + if (_display_ver == 0x10) + exec_cfg((u32 *)DSI_BASE, _display_config_4, 43); + + DSI(_DSIREG(DSI_WR_DATA)) = 0x1105; // MIPI_DCS_EXIT_SLEEP_MODE + DSI(_DSIREG(DSI_TRIGGER)) = DSI_TRIGGER_HOST; + + usleep(180000); + + DSI(_DSIREG(DSI_WR_DATA)) = 0x2905; // MIPI_DCS_SET_DISPLAY_ON + DSI(_DSIREG(DSI_TRIGGER)) = DSI_TRIGGER_HOST; + + usleep(20000); + + exec_cfg((u32 *)CLOCK_BASE, _display_config_6, 3); + exec_cfg((u32 *)DSI_BASE, _display_config_5, 21); + DISPLAY_A(_DIREG(DC_DISP_DISP_CLOCK_CONTROL)) = 4; + exec_cfg((u32 *)DSI_BASE, _display_config_7, 10); + + usleep(10000); + + exec_cfg((u32 *)MIPI_CAL_BASE, _display_config_8, 6); + exec_cfg((u32 *)DSI_BASE, _display_config_9, 4); + exec_cfg((u32 *)MIPI_CAL_BASE, _display_config_10, 16); + + usleep(10000); + + exec_cfg((u32 *)DISPLAY_A_BASE, _display_config_11, 113); +} + +void display_backlight_pwm_init() +{ + clock_enable_pwm(); + + PWM(PWM_CONTROLLER_PWM_CSR_0) = (1 << 31); // Enable PWM + + PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) = (PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) >> 2) << 2 | 1; // PWM clock source. + gpio_config(GPIO_PORT_V, GPIO_PIN_0, GPIO_MODE_SPIO); // Backlight power mode. + +} + +void display_backlight(bool enable) +{ + gpio_write(GPIO_PORT_V, GPIO_PIN_0, enable ? GPIO_HIGH : GPIO_LOW); // Backlight PWM GPIO. +} + +void display_backlight_brightness(u32 brightness, u32 step_delay) +{ + u32 old_value = (PWM(PWM_CONTROLLER_PWM_CSR_0) >> 16) & 0xFF; + if (brightness == old_value) + return; + + if (brightness > 255) + brightness = 255; + + if (old_value < brightness) + { + for (u32 i = old_value; i < brightness + 1; i++) + { + PWM(PWM_CONTROLLER_PWM_CSR_0) = (1 << 31) | (i << 16); // Enable PWM + usleep(step_delay); + } + } + else + { + for (u32 i = old_value; i > brightness; i--) + { + PWM(PWM_CONTROLLER_PWM_CSR_0) = (1 << 31) | (i << 16); // Enable PWM + usleep(step_delay); + } + } + if (!brightness) + PWM(PWM_CONTROLLER_PWM_CSR_0) = 0; +} + +void display_end() +{ + display_backlight_brightness(0, 1000); + + DSI(_DSIREG(DSI_VIDEO_MODE_CONTROL)) = 1; + DSI(_DSIREG(DSI_WR_DATA)) = 0x2805; // MIPI_DCS_SET_DISPLAY_OFF + + DISPLAY_A(_DIREG(DC_CMD_STATE_ACCESS)) = READ_MUX | WRITE_MUX; + DSI(_DSIREG(DSI_VIDEO_MODE_CONTROL)) = 0; + + exec_cfg((u32 *)DISPLAY_A_BASE, _display_config_12, 17); + exec_cfg((u32 *)DSI_BASE, _display_config_13, 16); + + usleep(10000); + + if (_display_ver == 0x10) + exec_cfg((u32 *)DSI_BASE, _display_config_14, 22); + + DSI(_DSIREG(DSI_WR_DATA)) = 0x1005; // MIPI_DCS_ENTER_SLEEP_MODE + DSI(_DSIREG(DSI_TRIGGER)) = DSI_TRIGGER_HOST; + + usleep(50000); + + gpio_write(GPIO_PORT_V, GPIO_PIN_2, GPIO_LOW); //Backlight Reset disable. + + usleep(10000); + + gpio_write(GPIO_PORT_I, GPIO_PIN_1, GPIO_LOW); //Backlight -5V disable. + + usleep(10000); + + gpio_write(GPIO_PORT_I, GPIO_PIN_0, GPIO_LOW); //Backlight +5V disable. + + usleep(10000); + + // Disable clocks. + CLOCK(CLK_RST_CONTROLLER_RST_DEV_H_SET) = 0x1010000; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_H_CLR) = 0x1010000; + CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = 0x18000000; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_CLR) = 0x18000000; + + DSI(_DSIREG(DSI_PAD_CONTROL_0)) = DSI_PAD_CONTROL_VS1_PULLDN_CLK | DSI_PAD_CONTROL_VS1_PULLDN(0xF) | DSI_PAD_CONTROL_VS1_PDIO_CLK | DSI_PAD_CONTROL_VS1_PDIO(0xF); + DSI(_DSIREG(DSI_POWER_CONTROL)) = 0; + + gpio_config(GPIO_PORT_V, GPIO_PIN_0, GPIO_MODE_SPIO); // Backlight PWM. + + PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) = (PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) & ~PINMUX_TRISTATE) | PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) = (PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) >> 2) << 2 | 1; +} + +void display_color_screen(u32 color) +{ + exec_cfg((u32 *)DISPLAY_A_BASE, cfg_display_one_color, 8); + + // Configure display to show single color. + DISPLAY_A(_DIREG(DC_WIN_AD_WIN_OPTIONS)) = 0; + DISPLAY_A(_DIREG(DC_WIN_BD_WIN_OPTIONS)) = 0; + DISPLAY_A(_DIREG(DC_WIN_CD_WIN_OPTIONS)) = 0; + DISPLAY_A(_DIREG(DC_DISP_BLEND_BACKGROUND_COLOR)) = color; + DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = (DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) & 0xFFFFFFFE) | GENERAL_ACT_REQ; + + usleep(35000); + + display_backlight(true); +} + +u32 *display_init_framebuffer() +{ + // Sanitize framebuffer area. + //memset((u32 *)FB_ADDRESS, 0, 0x3C0000); + // This configures the framebuffer @ FB_ADDRESS with a resolution of 1280x720 (line stride 720). + exec_cfg((u32 *)DISPLAY_A_BASE, cfg_display_framebuffer, 32); + + usleep(35000); + + return (u32 *)FB_ADDRESS; +} + +u32 *display_init_framebuffer2() +{ + // Sanitize framebuffer area. + memset((u32 *)FB_ADDRESS, 0, 0x3C0000); + // This configures the framebuffer @ FB_ADDRESS with a resolution of 1280x720 (line stride 720). + exec_cfg((u32 *)DISPLAY_A_BASE, cfg_display_framebuffer2, 32); + + usleep(35000); + + return (u32 *)FB_ADDRESS; +} + +#pragma GCC pop_options diff --git a/nyx/nyx_gui/gfx/di.h b/nyx/nyx_gui/gfx/di.h new file mode 100644 index 0000000..04a4e1d --- /dev/null +++ b/nyx/nyx_gui/gfx/di.h @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _DI_H_ +#define _DI_H_ + +#include "../utils/types.h" + +#define FB_ADDRESS 0xF0800000 + +/*! Display registers. */ +#define _DIREG(reg) ((reg) * 4) + +#define DC_CMD_GENERAL_INCR_SYNCPT 0x00 + +#define DC_CMD_GENERAL_INCR_SYNCPT_CNTRL 0x01 +#define SYNCPT_CNTRL_NO_STALL (1 << 8) +#define SYNCPT_CNTRL_SOFT_RESET (1 << 0) + +#define DC_CMD_CONT_SYNCPT_VSYNC 0x28 +#define SYNCPT_VSYNC_ENABLE (1 << 8) + +#define DC_CMD_DISPLAY_COMMAND_OPTION0 0x031 + +#define DC_CMD_DISPLAY_COMMAND 0x32 +#define DISP_CTRL_MODE_STOP (0 << 5) +#define DISP_CTRL_MODE_C_DISPLAY (1 << 5) +#define DISP_CTRL_MODE_NC_DISPLAY (2 << 5) +#define DISP_CTRL_MODE_MASK (3 << 5) + +#define DC_CMD_DISPLAY_POWER_CONTROL 0x36 +#define PW0_ENABLE (1 << 0) +#define PW1_ENABLE (1 << 2) +#define PW2_ENABLE (1 << 4) +#define PW3_ENABLE (1 << 6) +#define PW4_ENABLE (1 << 8) +#define PM0_ENABLE (1 << 16) +#define PM1_ENABLE (1 << 18) + +#define DC_CMD_INT_MASK 0x38 +#define DC_CMD_INT_ENABLE 0x39 + +#define DC_CMD_STATE_ACCESS 0x40 +#define READ_MUX (1 << 0) +#define WRITE_MUX (1 << 2) + +#define DC_CMD_STATE_CONTROL 0x41 +#define GENERAL_ACT_REQ (1 << 0) +#define WIN_A_ACT_REQ (1 << 1) +#define WIN_B_ACT_REQ (1 << 2) +#define WIN_C_ACT_REQ (1 << 3) +#define CURSOR_ACT_REQ (1 << 7) +#define GENERAL_UPDATE (1 << 8) +#define WIN_A_UPDATE (1 << 9) +#define WIN_B_UPDATE (1 << 10) +#define WIN_C_UPDATE (1 << 11) +#define CURSOR_UPDATE (1 << 15) +#define NC_HOST_TRIG (1 << 24) + +#define DC_CMD_DISPLAY_WINDOW_HEADER 0x42 +#define WINDOW_A_SELECT (1 << 4) +#define WINDOW_B_SELECT (1 << 5) +#define WINDOW_C_SELECT (1 << 6) + +#define DC_CMD_REG_ACT_CONTROL 0x043 + +#define DC_COM_CRC_CONTROL 0x300 +#define DC_COM_PIN_OUTPUT_ENABLE(x) (0x302 + (x)) +#define DC_COM_PIN_OUTPUT_POLARITY(x) (0x306 + (x)) + +#define DC_COM_DSC_TOP_CTL 0x33E + +#define DC_DISP_DISP_WIN_OPTIONS 0x402 +#define HDMI_ENABLE (1 << 30) +#define DSI_ENABLE (1 << 29) +#define SOR1_TIMING_CYA (1 << 27) +#define SOR1_ENABLE (1 << 26) +#define SOR_ENABLE (1 << 25) +#define CURSOR_ENABLE (1 << 16) + +#define DC_DISP_DISP_MEM_HIGH_PRIORITY 0x403 +#define DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER 0x404 +#define DC_DISP_DISP_TIMING_OPTIONS 0x405 +#define DC_DISP_REF_TO_SYNC 0x406 +#define DC_DISP_SYNC_WIDTH 0x407 +#define DC_DISP_BACK_PORCH 0x408 +#define DC_DISP_ACTIVE 0x409 +#define DC_DISP_FRONT_PORCH 0x40A + +#define DC_DISP_DISP_CLOCK_CONTROL 0x42E +#define PIXEL_CLK_DIVIDER_PCD1 (0 << 8) +#define PIXEL_CLK_DIVIDER_PCD1H (1 << 8) +#define PIXEL_CLK_DIVIDER_PCD2 (2 << 8) +#define PIXEL_CLK_DIVIDER_PCD3 (3 << 8) +#define PIXEL_CLK_DIVIDER_PCD4 (4 << 8) +#define PIXEL_CLK_DIVIDER_PCD6 (5 << 8) +#define PIXEL_CLK_DIVIDER_PCD8 (6 << 8) +#define PIXEL_CLK_DIVIDER_PCD9 (7 << 8) +#define PIXEL_CLK_DIVIDER_PCD12 (8 << 8) +#define PIXEL_CLK_DIVIDER_PCD16 (9 << 8) +#define PIXEL_CLK_DIVIDER_PCD18 (10 << 8) +#define PIXEL_CLK_DIVIDER_PCD24 (11 << 8) +#define PIXEL_CLK_DIVIDER_PCD13 (12 << 8) +#define SHIFT_CLK_DIVIDER(x) ((x) & 0xff) + +#define DC_DISP_DISP_INTERFACE_CONTROL 0x42F +#define DISP_DATA_FORMAT_DF1P1C (0 << 0) +#define DISP_DATA_FORMAT_DF1P2C24B (1 << 0) +#define DISP_DATA_FORMAT_DF1P2C18B (2 << 0) +#define DISP_DATA_FORMAT_DF1P2C16B (3 << 0) +#define DISP_DATA_FORMAT_DF2S (4 << 0) +#define DISP_DATA_FORMAT_DF3S (5 << 0) +#define DISP_DATA_FORMAT_DFSPI (6 << 0) +#define DISP_DATA_FORMAT_DF1P3C24B (7 << 0) +#define DISP_DATA_FORMAT_DF1P3C18B (8 << 0) +#define DISP_ALIGNMENT_MSB (0 << 8) +#define DISP_ALIGNMENT_LSB (1 << 8) +#define DISP_ORDER_RED_BLUE (0 << 9) +#define DISP_ORDER_BLUE_RED (1 << 9) + +#define DC_DISP_DISP_COLOR_CONTROL 0x430 +#define DITHER_CONTROL_MASK (3 << 8) +#define DITHER_CONTROL_DISABLE (0 << 8) +#define DITHER_CONTROL_ORDERED (2 << 8) +#define DITHER_CONTROL_ERRDIFF (3 << 8) +#define BASE_COLOR_SIZE_MASK (0xf << 0) +#define BASE_COLOR_SIZE_666 (0 << 0) +#define BASE_COLOR_SIZE_111 (1 << 0) +#define BASE_COLOR_SIZE_222 (2 << 0) +#define BASE_COLOR_SIZE_333 (3 << 0) +#define BASE_COLOR_SIZE_444 (4 << 0) +#define BASE_COLOR_SIZE_555 (5 << 0) +#define BASE_COLOR_SIZE_565 (6 << 0) +#define BASE_COLOR_SIZE_332 (7 << 0) +#define BASE_COLOR_SIZE_888 (8 << 0) + +#define DC_DISP_SHIFT_CLOCK_OPTIONS 0x431 +#define SC1_H_QUALIFIER_NONE (1 << 16) +#define SC0_H_QUALIFIER_NONE (1 << 0) + +#define DC_DISP_DATA_ENABLE_OPTIONS 0x432 +#define DE_SELECT_ACTIVE_BLANK (0 << 0) +#define DE_SELECT_ACTIVE (1 << 0) +#define DE_SELECT_ACTIVE_IS (2 << 0) +#define DE_CONTROL_ONECLK (0 << 2) +#define DE_CONTROL_NORMAL (1 << 2) +#define DE_CONTROL_EARLY_EXT (2 << 2) +#define DE_CONTROL_EARLY (3 << 2) +#define DE_CONTROL_ACTIVE_BLANK (4 << 2) + +#define DC_DISP_DC_MCCIF_FIFOCTRL 0x480 +#define DC_DISP_SD_BL_PARAMETERS 0x4D7 +#define DC_DISP_SD_BL_CONTROL 0x4DC +#define DC_DISP_BLEND_BACKGROUND_COLOR 0x4E4 + +#define DC_WIN_CSC_YOF 0x611 +#define DC_WIN_CSC_KYRGB 0x612 +#define DC_WIN_CSC_KUR 0x613 +#define DC_WIN_CSC_KVR 0x614 +#define DC_WIN_CSC_KUG 0x615 +#define DC_WIN_CSC_KVG 0x616 +#define DC_WIN_CSC_KUB 0x617 +#define DC_WIN_CSC_KVB 0x618 +#define DC_WIN_AD_WIN_OPTIONS 0xB80 +#define DC_WIN_BD_WIN_OPTIONS 0xD80 +#define DC_WIN_CD_WIN_OPTIONS 0xF80 + +// The following registers are A/B/C shadows of the 0xB80/0xD80/0xF80 registers (see DISPLAY_WINDOW_HEADER). +#define DC_WIN_WIN_OPTIONS 0x700 +#define H_DIRECTION (1 << 0) +#define V_DIRECTION (1 << 2) +#define SCAN_COLUMN (1 << 4) +#define COLOR_EXPAND (1 << 6) +#define CSC_ENABLE (1 << 18) +#define WIN_ENABLE (1 << 30) + +#define DC_WIN_COLOR_DEPTH 0x703 +#define WIN_COLOR_DEPTH_P1 0x0 +#define WIN_COLOR_DEPTH_P2 0x1 +#define WIN_COLOR_DEPTH_P4 0x2 +#define WIN_COLOR_DEPTH_P8 0x3 +#define WIN_COLOR_DEPTH_B4G4R4A4 0x4 +#define WIN_COLOR_DEPTH_B5G5R5A 0x5 +#define WIN_COLOR_DEPTH_B5G6R5 0x6 +#define WIN_COLOR_DEPTH_AB5G5R5 0x7 +#define WIN_COLOR_DEPTH_B8G8R8A8 0xC +#define WIN_COLOR_DEPTH_R8G8B8A8 0xD +#define WIN_COLOR_DEPTH_B6x2G6x2R6x2A8 0xE +#define WIN_COLOR_DEPTH_R6x2G6x2B6x2A8 0xF +#define WIN_COLOR_DEPTH_YCbCr422 0x10 +#define WIN_COLOR_DEPTH_YUV422 0x11 +#define WIN_COLOR_DEPTH_YCbCr420P 0x12 +#define WIN_COLOR_DEPTH_YUV420P 0x13 +#define WIN_COLOR_DEPTH_YCbCr422P 0x14 +#define WIN_COLOR_DEPTH_YUV422P 0x15 +#define WIN_COLOR_DEPTH_YCbCr422R 0x16 +#define WIN_COLOR_DEPTH_YUV422R 0x17 +#define WIN_COLOR_DEPTH_YCbCr422RA 0x18 +#define WIN_COLOR_DEPTH_YUV422RA 0x19 + +#define DC_WIN_BUFFER_CONTROL 0x702 +#define DC_WIN_POSITION 0x704 + +#define DC_WIN_SIZE 0x705 +#define H_SIZE(x) (((x) & 0x1fff) << 0) +#define V_SIZE(x) (((x) & 0x1fff) << 16) + +#define DC_WIN_PRESCALED_SIZE 0x706 +#define H_PRESCALED_SIZE(x) (((x) & 0x7fff) << 0) +#define V_PRESCALED_SIZE(x) (((x) & 0x1fff) << 16) + +#define DC_WIN_H_INITIAL_DDA 0x707 +#define DC_WIN_V_INITIAL_DDA 0x708 + +#define DC_WIN_DDA_INC 0x709 +#define H_DDA_INC(x) (((x) & 0xffff) << 0) +#define V_DDA_INC(x) (((x) & 0xffff) << 16) + +#define DC_WIN_LINE_STRIDE 0x70A +#define LINE_STRIDE(x) (x) +#define UV_LINE_STRIDE(x) (((x) & 0xffff) << 16) +#define DC_WIN_DV_CONTROL 0x70E + +// The following registers are A/B/C shadows of the 0xBC0/0xDC0/0xFC0 registers (see DISPLAY_WINDOW_HEADER). +#define DC_WINBUF_START_ADDR 0x800 +#define DC_WINBUF_ADDR_H_OFFSET 0x806 +#define DC_WINBUF_ADDR_V_OFFSET 0x808 +#define DC_WINBUF_SURFACE_KIND 0x80B +#define PITCH (0 << 0) +#define TILED (1 << 0) +#define BLOCK (2 << 0) +#define BLOCK_HEIGHT(x) (((x) & 0x7) << 4) + +/*! Display serial interface registers. */ +#define _DSIREG(reg) ((reg) * 4) + +#define DSI_RD_DATA 0x9 +#define DSI_WR_DATA 0xA + +#define DSI_POWER_CONTROL 0xB +#define DSI_POWER_CONTROL_ENABLE 1 + +#define DSI_INT_ENABLE 0xC +#define DSI_INT_STATUS 0xD +#define DSI_INT_MASK 0xE + +#define DSI_HOST_CONTROL 0xF +#define DSI_HOST_CONTROL_FIFO_RESET (1 << 21) +#define DSI_HOST_CONTROL_CRC_RESET (1 << 20) +#define DSI_HOST_CONTROL_TX_TRIG_SOL (0 << 12) +#define DSI_HOST_CONTROL_TX_TRIG_FIFO (1 << 12) +#define DSI_HOST_CONTROL_TX_TRIG_HOST (2 << 12) +#define DSI_HOST_CONTROL_RAW (1 << 6) +#define DSI_HOST_CONTROL_HS (1 << 5) +#define DSI_HOST_CONTROL_FIFO_SEL (1 << 4) +#define DSI_HOST_CONTROL_IMM_BTA (1 << 3) +#define DSI_HOST_CONTROL_PKT_BTA (1 << 2) +#define DSI_HOST_CONTROL_CS (1 << 1) +#define DSI_HOST_CONTROL_ECC (1 << 0) + +#define DSI_CONTROL 0x10 +#define DSI_CONTROL_HS_CLK_CTRL (1 << 20) +#define DSI_CONTROL_CHANNEL(c) (((c) & 0x3) << 16) +#define DSI_CONTROL_FORMAT(f) (((f) & 0x3) << 12) +#define DSI_CONTROL_TX_TRIG(x) (((x) & 0x3) << 8) +#define DSI_CONTROL_LANES(n) (((n) & 0x3) << 4) +#define DSI_CONTROL_DCS_ENABLE (1 << 3) +#define DSI_CONTROL_SOURCE(s) (((s) & 0x1) << 2) +#define DSI_CONTROL_VIDEO_ENABLE (1 << 1) +#define DSI_CONTROL_HOST_ENABLE (1 << 0) + +#define DSI_SOL_DELAY 0x11 +#define DSI_MAX_THRESHOLD 0x12 + +#define DSI_TRIGGER 0x13 +#define DSI_TRIGGER_HOST (1 << 1) +#define DSI_TRIGGER_VIDEO (1 << 0) + +#define DSI_TX_CRC 0x14 +#define DSI_STATUS 0x15 +#define DSI_INIT_SEQ_CONTROL 0x1A +#define DSI_INIT_SEQ_DATA_0 0x1B +#define DSI_INIT_SEQ_DATA_1 0x1C +#define DSI_INIT_SEQ_DATA_2 0x1D +#define DSI_INIT_SEQ_DATA_3 0x1E +#define DSI_PKT_SEQ_0_LO 0x23 +#define DSI_PKT_SEQ_0_HI 0x24 +#define DSI_PKT_SEQ_1_LO 0x25 +#define DSI_PKT_SEQ_1_HI 0x26 +#define DSI_PKT_SEQ_2_LO 0x27 +#define DSI_PKT_SEQ_2_HI 0x28 +#define DSI_PKT_SEQ_3_LO 0x29 +#define DSI_PKT_SEQ_3_HI 0x2A +#define DSI_PKT_SEQ_4_LO 0x2B +#define DSI_PKT_SEQ_4_HI 0x2C +#define DSI_PKT_SEQ_5_LO 0x2D +#define DSI_PKT_SEQ_5_HI 0x2E +#define DSI_DCS_CMDS 0x33 +#define DSI_PKT_LEN_0_1 0x34 +#define DSI_PKT_LEN_2_3 0x35 +#define DSI_PKT_LEN_4_5 0x36 +#define DSI_PKT_LEN_6_7 0x37 +#define DSI_PHY_TIMING_0 0x3C +#define DSI_PHY_TIMING_1 0x3D +#define DSI_PHY_TIMING_2 0x3E +#define DSI_BTA_TIMING 0x3F + +#define DSI_TIMEOUT_0 0x44 +#define DSI_TIMEOUT_LRX(x) (((x) & 0xffff) << 16) +#define DSI_TIMEOUT_HTX(x) (((x) & 0xffff) << 0) + +#define DSI_TIMEOUT_1 0x45 +#define DSI_TIMEOUT_PR(x) (((x) & 0xffff) << 16) +#define DSI_TIMEOUT_TA(x) (((x) & 0xffff) << 0) + +#define DSI_TO_TALLY 0x46 + +#define DSI_PAD_CONTROL_0 0x4B +#define DSI_PAD_CONTROL_VS1_PULLDN_CLK (1 << 24) +#define DSI_PAD_CONTROL_VS1_PULLDN(x) (((x) & 0xf) << 16) +#define DSI_PAD_CONTROL_VS1_PDIO_CLK (1 << 8) +#define DSI_PAD_CONTROL_VS1_PDIO(x) (((x) & 0xf) << 0) + +#define DSI_PAD_CONTROL_CD 0x4C +#define DSI_VIDEO_MODE_CONTROL 0x4E + +#define DSI_PAD_CONTROL_1 0x4F +#define DSI_PAD_CONTROL_2 0x50 + +#define DSI_PAD_CONTROL_3 0x51 +#define DSI_PAD_PREEMP_PD_CLK(x) (((x) & 0x3) << 12) +#define DSI_PAD_PREEMP_PU_CLK(x) (((x) & 0x3) << 8) +#define DSI_PAD_PREEMP_PD(x) (((x) & 0x3) << 4) +#define DSI_PAD_PREEMP_PU(x) (((x) & 0x3) << 0) + +#define DSI_PAD_CONTROL_4 0x52 +#define DSI_INIT_SEQ_DATA_15 0x5F + +#define MIPI_CAL_MIPI_BIAS_PAD_CFG2 0x60 + +void display_init(); +void display_backlight_pwm_init(); +void display_end(); + +/*! Show one single color on the display. */ +void display_color_screen(u32 color); + +/*! Switches screen backlight ON/OFF. */ +void display_backlight(bool enable); +void display_backlight_brightness(u32 brightness, u32 step_delay); + +/*! Init display in full 1280x720 resolution (B8G8R8A8, line stride 768, framebuffer size = 1280*768*4 bytes). */ +u32 *display_init_framebuffer(); +u32 *display_init_framebuffer2(); + +#endif diff --git a/nyx/nyx_gui/gfx/di.inl b/nyx/nyx_gui/gfx/di.inl new file mode 100644 index 0000000..a19b98a --- /dev/null +++ b/nyx/nyx_gui/gfx/di.inl @@ -0,0 +1,601 @@ +/* +* Copyright (c) 2018 naehrwert +* Copyright (C) 2018 CTCaer +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +//Clock config. +static const cfg_op_t _display_config_1[4] = { + {0x4E, 0x40000000}, //CLK_RST_CONTROLLER_CLK_SOURCE_DISP1 + {0x34, 0x4830A001}, //CLK_RST_CONTROLLER_PLLD_BASE + {0x36, 0x20}, //CLK_RST_CONTROLLER_PLLD_MISC1 + {0x37, 0x2D0AAA} //CLK_RST_CONTROLLER_PLLD_MISC +}; + +//Display A config. +static const cfg_op_t _display_config_2[94] = { + {DC_CMD_STATE_ACCESS, 0}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, + {DC_CMD_REG_ACT_CONTROL, 0x54}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_DISP_DC_MCCIF_FIFOCTRL, 0}, + {DC_DISP_DISP_MEM_HIGH_PRIORITY, 0}, + {DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER, 0}, + {DC_CMD_DISPLAY_POWER_CONTROL, PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE | PW4_ENABLE | PM0_ENABLE | PM1_ENABLE}, + {DC_CMD_GENERAL_INCR_SYNCPT_CNTRL, SYNCPT_CNTRL_NO_STALL}, + {DC_CMD_CONT_SYNCPT_VSYNC, SYNCPT_VSYNC_ENABLE | 0x9}, // 9: SYNCPT + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE | WIN_B_UPDATE | WIN_C_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ | WIN_B_ACT_REQ | WIN_C_ACT_REQ}, + {DC_CMD_STATE_ACCESS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_DV_CONTROL, 0}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + /* Setup default YUV colorspace conversion coefficients */ + {DC_WIN_CSC_YOF, 0xF0}, + {DC_WIN_CSC_KYRGB, 0x12A}, + {DC_WIN_CSC_KUR, 0}, + {DC_WIN_CSC_KVR, 0x198}, + {DC_WIN_CSC_KUG, 0x39B}, + {DC_WIN_CSC_KVG, 0x32F}, + {DC_WIN_CSC_KUB, 0x204}, + {DC_WIN_CSC_KVB, 0}, + /* End of color coefficients */ + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_DV_CONTROL, 0}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + /* Setup default YUV colorspace conversion coefficients */ + {DC_WIN_CSC_YOF, 0xF0}, + {DC_WIN_CSC_KYRGB, 0x12A}, + {DC_WIN_CSC_KUR, 0}, + {DC_WIN_CSC_KVR, 0x198}, + {DC_WIN_CSC_KUG, 0x39B}, + {DC_WIN_CSC_KVG, 0x32F}, + {DC_WIN_CSC_KUB, 0x204}, + {DC_WIN_CSC_KVB, 0}, + /* End of color coefficients */ + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_DV_CONTROL, 0}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + /* Setup default YUV colorspace conversion coefficients */ + {DC_WIN_CSC_YOF, 0xF0}, + {DC_WIN_CSC_KYRGB, 0x12A}, + {DC_WIN_CSC_KUR, 0}, + {DC_WIN_CSC_KVR, 0x198}, + {DC_WIN_CSC_KUG, 0x39B}, + {DC_WIN_CSC_KVG, 0x32F}, + {DC_WIN_CSC_KUB, 0x204}, + {DC_WIN_CSC_KVB, 0}, + /* End of color coefficients */ + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_COLOR_CONTROL, BASE_COLOR_SIZE_888}, + {DC_DISP_DISP_INTERFACE_CONTROL, DISP_DATA_FORMAT_DF1P1C}, + {DC_COM_PIN_OUTPUT_POLARITY(1), 0x1000000}, + {DC_COM_PIN_OUTPUT_POLARITY(3), 0}, + {0x4E4, 0}, + {DC_COM_CRC_CONTROL, 0}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE | WIN_B_UPDATE | WIN_C_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ | WIN_B_ACT_REQ | WIN_C_ACT_REQ}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {0x716, 0x10000FF}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {0x716, 0x10000FF}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {0x716, 0x10000FF}, + {DC_CMD_DISPLAY_COMMAND_OPTION0, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_STOP}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE | WIN_B_UPDATE | WIN_C_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ | WIN_B_ACT_REQ | WIN_C_ACT_REQ} +}; + +//DSI Init config. +static const cfg_op_t _display_config_3[61] = { + {DSI_WR_DATA, 0}, + {DSI_INT_ENABLE, 0}, + {DSI_INT_STATUS, 0}, + {DSI_INT_MASK, 0}, + {DSI_INIT_SEQ_DATA_0, 0}, + {DSI_INIT_SEQ_DATA_1, 0}, + {DSI_INIT_SEQ_DATA_2, 0}, + {DSI_INIT_SEQ_DATA_3, 0}, + {DSI_INIT_SEQ_DATA_15, 0}, + {DSI_DCS_CMDS, 0}, + {DSI_PKT_SEQ_0_LO, 0}, + {DSI_PKT_SEQ_1_LO, 0}, + {DSI_PKT_SEQ_2_LO, 0}, + {DSI_PKT_SEQ_3_LO, 0}, + {DSI_PKT_SEQ_4_LO, 0}, + {DSI_PKT_SEQ_5_LO, 0}, + {DSI_PKT_SEQ_0_HI, 0}, + {DSI_PKT_SEQ_1_HI, 0}, + {DSI_PKT_SEQ_2_HI, 0}, + {DSI_PKT_SEQ_3_HI, 0}, + {DSI_PKT_SEQ_4_HI, 0}, + {DSI_PKT_SEQ_5_HI, 0}, + {DSI_CONTROL, 0}, + {DSI_PAD_CONTROL_CD, 0}, + {DSI_SOL_DELAY, 0x18}, + {DSI_MAX_THRESHOLD, 0x1E0}, + {DSI_TRIGGER, 0}, + {DSI_INIT_SEQ_CONTROL, 0}, + {DSI_PKT_LEN_0_1, 0}, + {DSI_PKT_LEN_2_3, 0}, + {DSI_PKT_LEN_4_5, 0}, + {DSI_PKT_LEN_6_7, 0}, + {DSI_PAD_CONTROL_1, 0}, + {DSI_PHY_TIMING_0, 0x6070601}, + {DSI_PHY_TIMING_1, 0x40A0E05}, + {DSI_PHY_TIMING_2, 0x30109}, + {DSI_BTA_TIMING, 0x190A14}, + {DSI_TIMEOUT_0, DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(0xFFFF)}, + {DSI_TIMEOUT_1, DSI_TIMEOUT_PR(0x765) | DSI_TIMEOUT_TA(0x2000)}, + {DSI_TO_TALLY, 0}, + {DSI_PAD_CONTROL_0, DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0)}, // Enable + {DSI_POWER_CONTROL, DSI_POWER_CONTROL_ENABLE}, + {DSI_POWER_CONTROL, DSI_POWER_CONTROL_ENABLE}, + {DSI_POWER_CONTROL, 0}, + {DSI_POWER_CONTROL, 0}, + {DSI_PAD_CONTROL_1, 0}, + {DSI_PHY_TIMING_0, 0x6070601}, + {DSI_PHY_TIMING_1, 0x40A0E05}, + {DSI_PHY_TIMING_2, 0x30118}, + {DSI_BTA_TIMING, 0x190A14}, + {DSI_TIMEOUT_0, DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(0xFFFF)}, + {DSI_TIMEOUT_1, DSI_TIMEOUT_PR(0x1343) | DSI_TIMEOUT_TA(0x2000)}, + {DSI_TO_TALLY, 0}, + {DSI_HOST_CONTROL, DSI_HOST_CONTROL_CRC_RESET | DSI_HOST_CONTROL_TX_TRIG_HOST | DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC}, + {DSI_CONTROL, DSI_CONTROL_LANES(3) | DSI_CONTROL_HOST_ENABLE}, + {DSI_POWER_CONTROL, DSI_POWER_CONTROL_ENABLE}, + {DSI_POWER_CONTROL, DSI_POWER_CONTROL_ENABLE}, + {DSI_MAX_THRESHOLD, 0x40}, + {DSI_TRIGGER, 0}, + {DSI_TX_CRC, 0}, + {DSI_INIT_SEQ_CONTROL, 0} +}; + +//DSI config (if ver == 0x10). +static const cfg_op_t _display_config_4[43] = { + {DSI_WR_DATA, 0x439}, + {DSI_WR_DATA, 0x9483FFB9}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0xBD15}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0x1939}, + {DSI_WR_DATA, 0xAAAAAAD8}, + {DSI_WR_DATA, 0xAAAAAAEB}, + {DSI_WR_DATA, 0xAAEBAAAA}, + {DSI_WR_DATA, 0xAAAAAAAA}, + {DSI_WR_DATA, 0xAAAAAAEB}, + {DSI_WR_DATA, 0xAAEBAAAA}, + {DSI_WR_DATA, 0xAA}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0x1BD15}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0x2739}, + {DSI_WR_DATA, 0xFFFFFFD8}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFF}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0x2BD15}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0xF39}, + {DSI_WR_DATA, 0xFFFFFFD8}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFFFF}, + {DSI_WR_DATA, 0xFFFFFF}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0xBD15}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0x6D915}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0x439}, + {DSI_WR_DATA, 0xB9}, + {DSI_TRIGGER, DSI_TRIGGER_HOST} +}; + +//DSI config. +static const cfg_op_t _display_config_5[21] = { + {DSI_PAD_CONTROL_1, 0}, + {DSI_PHY_TIMING_0, 0x6070601}, + {DSI_PHY_TIMING_1, 0x40A0E05}, + {DSI_PHY_TIMING_2, 0x30172}, + {DSI_BTA_TIMING, 0x190A14}, + {DSI_TIMEOUT_0, DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(0xA40)}, + {DSI_TIMEOUT_1, DSI_TIMEOUT_PR(0x5A2F) | DSI_TIMEOUT_TA(0x2000)}, + {DSI_TO_TALLY, 0}, + {DSI_PKT_SEQ_0_LO, 0x40000208}, + {DSI_PKT_SEQ_2_LO, 0x40000308}, + {DSI_PKT_SEQ_4_LO, 0x40000308}, + {DSI_PKT_SEQ_1_LO, 0x40000308}, + {DSI_PKT_SEQ_3_LO, 0x3F3B2B08}, + {DSI_PKT_SEQ_3_HI, 0x2CC}, + {DSI_PKT_SEQ_5_LO, 0x3F3B2B08}, + {DSI_PKT_SEQ_5_HI, 0x2CC}, + {DSI_PKT_LEN_0_1, 0xCE0000}, + {DSI_PKT_LEN_2_3, 0x87001A2}, + {DSI_PKT_LEN_4_5, 0x190}, + {DSI_PKT_LEN_6_7, 0x190}, + {DSI_HOST_CONTROL, 0}, +}; + +//Clock config. +static const cfg_op_t _display_config_6[3] = { + {0x34, 0x4810C001}, //CLK_RST_CONTROLLER_PLLD_BASE + {0x36, 0x20}, //CLK_RST_CONTROLLER_PLLD_MISC1 + {0x37, 0x2DFC00} //CLK_RST_CONTROLLER_PLLD_MISC +}; + +//DSI config. +static const cfg_op_t _display_config_7[10] = { + {DSI_TRIGGER, 0}, + {DSI_CONTROL, 0}, + {DSI_SOL_DELAY, 6}, + {DSI_MAX_THRESHOLD, 0x1E0}, + {DSI_POWER_CONTROL, DSI_POWER_CONTROL_ENABLE}, + {DSI_CONTROL, DSI_CONTROL_HS_CLK_CTRL | DSI_CONTROL_FORMAT(3) | DSI_CONTROL_LANES(3) | DSI_CONTROL_VIDEO_ENABLE}, + {DSI_HOST_CONTROL, DSI_HOST_CONTROL_HS | DSI_HOST_CONTROL_FIFO_SEL| DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC}, + {DSI_CONTROL, DSI_CONTROL_HS_CLK_CTRL | DSI_CONTROL_FORMAT(3) | DSI_CONTROL_LANES(3) | DSI_CONTROL_VIDEO_ENABLE}, + {DSI_HOST_CONTROL, DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC}, + {DSI_HOST_CONTROL, DSI_HOST_CONTROL_HS | DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC} +}; + +//MIPI CAL config. +static const cfg_op_t _display_config_8[6] = { + {0x18, 0}, // MIPI_CAL_MIPI_BIAS_PAD_CFG2 + {0x02, 0xF3F10000}, // MIPI_CAL_CIL_MIPI_CAL_STATUS + {0x16, 0}, // MIPI_CAL_MIPI_BIAS_PAD_CFG0 + {0x18, 0}, // MIPI_CAL_MIPI_BIAS_PAD_CFG2 + {0x18, 0x10010}, // MIPI_CAL_MIPI_BIAS_PAD_CFG2 + {0x17, 0x300} // MIPI_CAL_MIPI_BIAS_PAD_CFG1 +}; + +//DSI config. +static const cfg_op_t _display_config_9[4] = { + {DSI_PAD_CONTROL_1, 0}, + {DSI_PAD_CONTROL_2, 0}, + {DSI_PAD_CONTROL_3, DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) | DSI_PAD_PREEMP_PD(0x03) | DSI_PAD_PREEMP_PU(0x3)}, + {DSI_PAD_CONTROL_4, 0} +}; + +//MIPI CAL config. +static const cfg_op_t _display_config_10[16] = { + {0x0E, 0x200200}, // MIPI_CAL_DSIA_MIPI_CAL_CONFIG + {0x0F, 0x200200}, // MIPI_CAL_DSIB_MIPI_CAL_CONFIG + {0x19, 0x200002}, // MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2 + {0x1A, 0x200002}, // MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2 + {0x05, 0}, // MIPI_CAL_CILA_MIPI_CAL_CONFIG + {0x06, 0}, // MIPI_CAL_CILB_MIPI_CAL_CONFIG + {0x07, 0}, // MIPI_CAL_CILC_MIPI_CAL_CONFIG + {0x08, 0}, // MIPI_CAL_CILD_MIPI_CAL_CONFIG + {0x09, 0}, // MIPI_CAL_CILE_MIPI_CAL_CONFIG + {0x0A, 0}, // MIPI_CAL_CILF_MIPI_CAL_CONFIG + {0x10, 0}, // MIPI_CAL_DSIC_MIPI_CAL_CONFIG + {0x11, 0}, // MIPI_CAL_DSID_MIPI_CAL_CONFIG + {0x1A, 0}, // MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2 + {0x1C, 0}, // MIPI_CAL_DSIC_MIPI_CAL_CONFIG_2 + {0x1D, 0}, // MIPI_CAL_DSID_MIPI_CAL_CONFIG_2 + {0, 0x2A000001} // MIPI_CAL_DSIA_MIPI_CAL_CONFIG +}; + +//Display A config. +static const cfg_op_t _display_config_11[113] = { + {DC_CMD_STATE_ACCESS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_DV_CONTROL, 0}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + /* Setup default YUV colorspace conversion coefficients */ + {DC_WIN_CSC_YOF, 0xF0}, + {DC_WIN_CSC_KYRGB, 0x12A}, + {DC_WIN_CSC_KUR, 0}, + {DC_WIN_CSC_KVR, 0x198}, + {DC_WIN_CSC_KUG, 0x39B}, + {DC_WIN_CSC_KVG, 0x32F}, + {DC_WIN_CSC_KUB, 0x204}, + {DC_WIN_CSC_KVB, 0}, + /* End of color coefficients */ + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_DV_CONTROL, 0}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + /* Setup default YUV colorspace conversion coefficients */ + {DC_WIN_CSC_YOF, 0xF0}, + {DC_WIN_CSC_KYRGB, 0x12A}, + {DC_WIN_CSC_KUR, 0}, + {DC_WIN_CSC_KVR, 0x198}, + {DC_WIN_CSC_KUG, 0x39B}, + {DC_WIN_CSC_KVG, 0x32F}, + {DC_WIN_CSC_KUB, 0x204}, + {DC_WIN_CSC_KVB, 0}, + /* End of color coefficients */ + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_DV_CONTROL, 0}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + /* Setup default YUV colorspace conversion coefficients */ + {DC_WIN_CSC_YOF, 0xF0}, + {DC_WIN_CSC_KYRGB, 0x12A}, + {DC_WIN_CSC_KUR, 0}, + {DC_WIN_CSC_KVR, 0x198}, + {DC_WIN_CSC_KUG, 0x39B}, + {DC_WIN_CSC_KVG, 0x32F}, + {DC_WIN_CSC_KUB, 0x204}, + {DC_WIN_CSC_KVB, 0}, + /* End of color coefficients */ + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_COLOR_CONTROL, BASE_COLOR_SIZE_888}, + {DC_DISP_DISP_INTERFACE_CONTROL, DISP_DATA_FORMAT_DF1P1C}, + {DC_COM_PIN_OUTPUT_POLARITY(1), 0x1000000}, + {DC_COM_PIN_OUTPUT_POLARITY(3), 0}, + {0x4E4, 0}, + {DC_COM_CRC_CONTROL, 0}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE | WIN_B_UPDATE | WIN_C_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ | WIN_B_ACT_REQ | WIN_C_ACT_REQ}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {0x716, 0x10000FF}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {0x716, 0x10000FF}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {0x716, 0x10000FF}, + {DC_CMD_DISPLAY_COMMAND_OPTION0, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_STOP}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE | WIN_B_UPDATE | WIN_C_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ | WIN_B_ACT_REQ | WIN_C_ACT_REQ}, + {DC_CMD_STATE_ACCESS, 0}, + /* Set Display timings */ + {DC_DISP_DISP_TIMING_OPTIONS, 0}, + {DC_DISP_REF_TO_SYNC, (1 << 16)}, // h_ref_to_sync = 0, v_ref_to_sync = 1. + {DC_DISP_SYNC_WIDTH, 0x10048}, + {DC_DISP_BACK_PORCH, 0x90048}, + {DC_DISP_ACTIVE, 0x50002D0}, + {DC_DISP_FRONT_PORCH, 0xA0088}, // Sources say that this should be above the DC_DISP_ACTIVE cmd. + /* End of Display timings */ + {DC_DISP_SHIFT_CLOCK_OPTIONS, SC1_H_QUALIFIER_NONE | SC0_H_QUALIFIER_NONE}, + {DC_COM_PIN_OUTPUT_ENABLE(1), 0}, + {DC_DISP_DATA_ENABLE_OPTIONS, DE_SELECT_ACTIVE | DE_CONTROL_NORMAL}, + {DC_DISP_DISP_INTERFACE_CONTROL, DISP_DATA_FORMAT_DF1P1C}, + {DC_DISP_DISP_CLOCK_CONTROL, 0}, + {DC_CMD_DISPLAY_COMMAND_OPTION0, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_C_DISPLAY}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, + {DC_CMD_STATE_ACCESS, READ_MUX | WRITE_MUX}, + {DC_DISP_FRONT_PORCH, 0xA0088}, + {DC_CMD_STATE_ACCESS, 0}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, + {DC_CMD_GENERAL_INCR_SYNCPT, 0x301}, + {DC_CMD_GENERAL_INCR_SYNCPT, 0x301}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, + {DC_CMD_STATE_ACCESS, 0}, + {DC_DISP_DISP_CLOCK_CONTROL, PIXEL_CLK_DIVIDER_PCD1 | SHIFT_CLK_DIVIDER(4)}, + {DC_DISP_DISP_COLOR_CONTROL, BASE_COLOR_SIZE_888}, + {DC_CMD_DISPLAY_COMMAND_OPTION0, 0} +}; + +////Display A config. +static const cfg_op_t _display_config_12[17] = { + {DC_DISP_FRONT_PORCH, 0xA0088}, + {DC_CMD_INT_MASK, 0}, + {DC_CMD_STATE_ACCESS, 0}, + {DC_CMD_INT_ENABLE, 0}, + {DC_CMD_CONT_SYNCPT_VSYNC, 0}, + {DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_STOP}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, + {DC_CMD_GENERAL_INCR_SYNCPT, 0x301}, + {DC_CMD_GENERAL_INCR_SYNCPT, 0x301}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, + {DC_CMD_DISPLAY_POWER_CONTROL, 0}, + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE}, + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ}, +}; + +//DSI config. +static const cfg_op_t _display_config_13[16] = { + {DSI_POWER_CONTROL, 0}, + {DSI_PAD_CONTROL_1, 0}, + {DSI_PHY_TIMING_0, 0x6070601}, + {DSI_PHY_TIMING_1, 0x40A0E05}, + {DSI_PHY_TIMING_2, 0x30118}, + {DSI_BTA_TIMING, 0x190A14}, + {DSI_TIMEOUT_0, DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(0xFFFF) }, + {DSI_TIMEOUT_1, DSI_TIMEOUT_PR(0x1343) | DSI_TIMEOUT_TA(0x2000)}, + {DSI_TO_TALLY, 0}, + {DSI_HOST_CONTROL, DSI_HOST_CONTROL_CRC_RESET | DSI_HOST_CONTROL_TX_TRIG_HOST | DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC}, + {DSI_CONTROL, DSI_CONTROL_LANES(3) | DSI_CONTROL_HOST_ENABLE}, + {DSI_POWER_CONTROL, DSI_POWER_CONTROL_ENABLE}, + {DSI_MAX_THRESHOLD, 0x40}, + {DSI_TRIGGER, 0}, + {DSI_TX_CRC, 0}, + {DSI_INIT_SEQ_CONTROL, 0} +}; + +//DSI config (if ver == 0x10). +static const cfg_op_t _display_config_14[22] = { + {DSI_WR_DATA, 0x439}, + {DSI_WR_DATA, 0x9483FFB9}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0x2139}, + {DSI_WR_DATA, 0x191919D5}, + {DSI_WR_DATA, 0x19191919}, + {DSI_WR_DATA, 0x19191919}, + {DSI_WR_DATA, 0x19191919}, + {DSI_WR_DATA, 0x19191919}, + {DSI_WR_DATA, 0x19191919}, + {DSI_WR_DATA, 0x19191919}, + {DSI_WR_DATA, 0x19191919}, + {DSI_WR_DATA, 0x19}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0xB39}, + {DSI_WR_DATA, 0x4F0F41B1}, + {DSI_WR_DATA, 0xF179A433}, + {DSI_WR_DATA, 0x2D81}, + {DSI_TRIGGER, DSI_TRIGGER_HOST}, + {DSI_WR_DATA, 0x439}, + {DSI_WR_DATA, 0xB9}, + {DSI_TRIGGER, DSI_TRIGGER_HOST} +}; + +//Display A config. +static const cfg_op_t cfg_display_one_color[8] = { + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, //Enable window A. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, //Enable window B. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, //Enable window C. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_C_DISPLAY} //DISPLAY_CTRL_MODE: continuous display. +}; + +//Display A config. +static const cfg_op_t cfg_display_framebuffer[32] = { + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, //Enable window C. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, //Enable window B. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, //Enable window A. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_WIN_COLOR_DEPTH, WIN_COLOR_DEPTH_B8G8R8A8}, //T_A8R8G8B8 //NX Default: T_A8B8G8R8, WIN_COLOR_DEPTH_R8G8B8A8 + {DC_WIN_WIN_OPTIONS, 0}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_WIN_POSITION, 0}, //(0,0) + {DC_WIN_H_INITIAL_DDA, 0}, + {DC_WIN_V_INITIAL_DDA, 0}, + {DC_WIN_PRESCALED_SIZE, V_PRESCALED_SIZE(1280) | H_PRESCALED_SIZE(2880)}, //Pre-scaled size: 1280x2880 bytes. + {DC_WIN_DDA_INC, V_DDA_INC(0x1000) | H_DDA_INC(0x1000)}, + {DC_WIN_SIZE, V_SIZE(1280) | H_SIZE(720)}, //Window size: 1280 vertical lines x 720 horizontal pixels. + {DC_WIN_LINE_STRIDE, UV_LINE_STRIDE(720 * 2) | LINE_STRIDE(720 * 4)}, //768*2x768*4 (= 0x600 x 0xC00) bytes, see TRM for alignment requirements. + {DC_WIN_BUFFER_CONTROL, 0}, + {DC_WINBUF_SURFACE_KIND, 0}, //Regular surface. + //{DC_WINBUF_SURFACE_KIND, BLOCK_HEIGHT(4) | BLOCK}, //Regular surface. + {DC_WINBUF_START_ADDR, FB_ADDRESS}, //Framebuffer address. + {DC_WINBUF_ADDR_H_OFFSET, 0}, //Linear: 0x383FFC, Block: 0x3813FC + {DC_WINBUF_ADDR_V_OFFSET, 1279}, //Linear: 1279, Block: 0 + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_WIN_WIN_OPTIONS, WIN_ENABLE | V_DIRECTION}, //Enable window AD. + //{DC_WIN_WIN_OPTIONS, WIN_ENABLE | | SCAN_COLUMN | H_DIRECTION}, //Enable window AD. | SCAN_COLUMN | H_DIRECTION + {DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_C_DISPLAY}, //DISPLAY_CTRL_MODE: continuous display. + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE}, //General update; window A update. + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ} //General activation request; window A activation request. +}; + +static const cfg_op_t cfg_display_framebuffer2[32] = { + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT}, //Enable window C. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT}, //Enable window B. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT}, //Enable window A. + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_WIN_COLOR_DEPTH, WIN_COLOR_DEPTH_B8G8R8A8}, //T_A8R8G8B8 //NX Default: T_A8B8G8R8, WIN_COLOR_DEPTH_R8G8B8A8 + {DC_WIN_WIN_OPTIONS, 0}, + {DC_WIN_WIN_OPTIONS, 0}, + {DC_WIN_POSITION, 0}, //(0,0) + {DC_WIN_H_INITIAL_DDA, 0}, + {DC_WIN_V_INITIAL_DDA, 0}, + {DC_WIN_PRESCALED_SIZE, V_PRESCALED_SIZE(1280) | H_PRESCALED_SIZE(2880)}, //Pre-scaled size: 1280x2880 bytes. + {DC_WIN_DDA_INC, V_DDA_INC(0x1000) | H_DDA_INC(0x1000)}, + {DC_WIN_SIZE, V_SIZE(1280) | H_SIZE(720)}, //Window size: 1280 vertical lines x 720 horizontal pixels. + {DC_WIN_LINE_STRIDE, UV_LINE_STRIDE(1280 * 2) | LINE_STRIDE(1280 * 4)}, //768*2x768*4 (= 0x600 x 0xC00) bytes, see TRM for alignment requirements. + {DC_WIN_BUFFER_CONTROL, 0}, + {DC_WINBUF_SURFACE_KIND, BLOCK_HEIGHT(4) | BLOCK}, //Regular surface. + {DC_WINBUF_START_ADDR, FB_ADDRESS}, //Framebuffer address. + {DC_WINBUF_ADDR_H_OFFSET, 0x3813FC}, //Linear: 0x383FFC, Block: 0x3813FC + {DC_WINBUF_ADDR_V_OFFSET, 0}, //Linear: 1279, Block: 0 + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_WIN_WIN_OPTIONS, 0}, + {DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE}, //DSI_ENABLE + {DC_WIN_WIN_OPTIONS, WIN_ENABLE | SCAN_COLUMN | H_DIRECTION}, //Enable window AD. | SCAN_COLUMN | H_DIRECTION + {DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_C_DISPLAY}, //DISPLAY_CTRL_MODE: continuous display. + {DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE}, //General update; window A update. + {DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ} //General activation request; window A activation request. +}; diff --git a/nyx/nyx_gui/gfx/gfx.c b/nyx/nyx_gui/gfx/gfx.c new file mode 100644 index 0000000..c7aff0a --- /dev/null +++ b/nyx/nyx_gui/gfx/gfx.c @@ -0,0 +1,628 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "gfx.h" + +#pragma GCC push_options +#pragma GCC target ("thumb") +#pragma GCC optimize ("Os") + +static const u8 _gfx_font[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 032 ( ) + 0x00, 0x30, 0x30, 0x18, 0x18, 0x00, 0x0C, 0x00, // Char 033 (!) + 0x00, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, // Char 034 (") + 0x00, 0x66, 0x66, 0xFF, 0x66, 0xFF, 0x66, 0x66, // Char 035 (#) + 0x00, 0x18, 0x7C, 0x06, 0x3C, 0x60, 0x3E, 0x18, // Char 036 ($) + 0x00, 0x46, 0x66, 0x30, 0x18, 0x0C, 0x66, 0x62, // Char 037 (%) + 0x00, 0x3C, 0x66, 0x3C, 0x1C, 0xE6, 0x66, 0xFC, // Char 038 (&) + 0x00, 0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, // Char 039 (') + 0x00, 0x30, 0x18, 0x0C, 0x0C, 0x18, 0x30, 0x00, // Char 040 (() + 0x00, 0x0C, 0x18, 0x30, 0x30, 0x18, 0x0C, 0x00, // Char 041 ()) + 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, // Char 042 (*) + 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, // Char 043 (+) + 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x0C, 0x00, // Char 044 (,) + 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, // Char 045 (-) + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, // Char 046 (.) + 0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00, // Char 047 (/) + 0x00, 0x3C, 0x66, 0x76, 0x6E, 0x66, 0x3C, 0x00, // Char 048 (0) + 0x00, 0x18, 0x1C, 0x18, 0x18, 0x18, 0x7E, 0x00, // Char 049 (1) + 0x00, 0x3C, 0x62, 0x30, 0x0C, 0x06, 0x7E, 0x00, // Char 050 (2) + 0x00, 0x3C, 0x62, 0x38, 0x60, 0x66, 0x3C, 0x00, // Char 051 (3) + 0x00, 0x6C, 0x6C, 0x66, 0xFE, 0x60, 0x60, 0x00, // Char 052 (4) + 0x00, 0x7E, 0x06, 0x7E, 0x60, 0x66, 0x3C, 0x00, // Char 053 (5) + 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x66, 0x3C, 0x00, // Char 054 (6) + 0x00, 0x7E, 0x30, 0x30, 0x18, 0x18, 0x18, 0x00, // Char 055 (7) + 0x00, 0x3C, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00, // Char 056 (8) + 0x00, 0x3C, 0x66, 0x7C, 0x60, 0x66, 0x3C, 0x00, // Char 057 (9) + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, // Char 058 (:) + 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x0C, 0x00, // Char 059 (;) + 0x00, 0x70, 0x1C, 0x06, 0x06, 0x1C, 0x70, 0x00, // Char 060 (<) + 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, // Char 061 (=) + 0x00, 0x0E, 0x38, 0x60, 0x60, 0x38, 0x0E, 0x00, // Char 062 (>) + 0x00, 0x3C, 0x66, 0x30, 0x18, 0x00, 0x18, 0x00, // Char 063 (?) + 0x00, 0x3C, 0x66, 0x76, 0x76, 0x06, 0x46, 0x3C, // Char 064 (@) + 0x00, 0x3C, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, // Char 065 (A) + 0x00, 0x3E, 0x66, 0x3E, 0x66, 0x66, 0x3E, 0x00, // Char 066 (B) + 0x00, 0x3C, 0x66, 0x06, 0x06, 0x66, 0x3C, 0x00, // Char 067 (C) + 0x00, 0x1E, 0x36, 0x66, 0x66, 0x36, 0x1E, 0x00, // Char 068 (D) + 0x00, 0x7E, 0x06, 0x1E, 0x06, 0x06, 0x7E, 0x00, // Char 069 (E) + 0x00, 0x3E, 0x06, 0x1E, 0x06, 0x06, 0x06, 0x00, // Char 070 (F) + 0x00, 0x3C, 0x66, 0x06, 0x76, 0x66, 0x3C, 0x00, // Char 071 (G) + 0x00, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, // Char 072 (H) + 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 073 (I) + 0x00, 0x78, 0x30, 0x30, 0x30, 0x36, 0x1C, 0x00, // Char 074 (J) + 0x00, 0x66, 0x36, 0x1E, 0x1E, 0x36, 0x66, 0x00, // Char 075 (K) + 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7E, 0x00, // Char 076 (L) + 0x00, 0x46, 0x6E, 0x7E, 0x56, 0x46, 0x46, 0x00, // Char 077 (M) + 0x00, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x66, 0x00, // Char 078 (N) + 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, // Char 079 (O) + 0x00, 0x3E, 0x66, 0x3E, 0x06, 0x06, 0x06, 0x00, // Char 080 (P) + 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x70, 0x00, // Char 081 (Q) + 0x00, 0x3E, 0x66, 0x3E, 0x1E, 0x36, 0x66, 0x00, // Char 082 (R) + 0x00, 0x3C, 0x66, 0x0C, 0x30, 0x66, 0x3C, 0x00, // Char 083 (S) + 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 084 (T) + 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, // Char 085 (U) + 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, // Char 086 (V) + 0x00, 0x46, 0x46, 0x56, 0x7E, 0x6E, 0x46, 0x00, // Char 087 (W) + 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00, // Char 088 (X) + 0x00, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00, // Char 089 (Y) + 0x00, 0x7E, 0x30, 0x18, 0x0C, 0x06, 0x7E, 0x00, // Char 090 (Z) + 0x00, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, // Char 091 ([) + 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00, // Char 092 (\) + 0x00, 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, // Char 093 (]) + 0x00, 0x18, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, // Char 094 (^) + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, // Char 095 (_) + 0x00, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, // Char 096 (`) + 0x00, 0x00, 0x3C, 0x60, 0x7C, 0x66, 0x7C, 0x00, // Char 097 (a) + 0x00, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E, 0x00, // Char 098 (b) + 0x00, 0x00, 0x3C, 0x06, 0x06, 0x06, 0x3C, 0x00, // Char 099 (c) + 0x00, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00, // Char 100 (d) + 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x06, 0x3C, 0x00, // Char 101 (e) + 0x00, 0x38, 0x0C, 0x3E, 0x0C, 0x0C, 0x0C, 0x00, // Char 102 (f) + 0x00, 0x00, 0x7C, 0x66, 0x7C, 0x40, 0x3C, 0x00, // Char 103 (g) + 0x00, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x66, 0x00, // Char 104 (h) + 0x00, 0x18, 0x00, 0x1C, 0x18, 0x18, 0x3C, 0x00, // Char 105 (i) + 0x00, 0x30, 0x00, 0x30, 0x30, 0x30, 0x1E, 0x00, // Char 106 (j) + 0x00, 0x06, 0x06, 0x36, 0x1E, 0x36, 0x66, 0x00, // Char 107 (k) + 0x00, 0x1C, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 108 (l) + 0x00, 0x00, 0x66, 0xFE, 0xFE, 0xD6, 0xC6, 0x00, // Char 109 (m) + 0x00, 0x00, 0x3E, 0x66, 0x66, 0x66, 0x66, 0x00, // Char 110 (n) + 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00, // Char 111 (o) + 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x00, // Char 112 (p) + 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x00, // Char 113 (q) + 0x00, 0x00, 0x3E, 0x66, 0x06, 0x06, 0x06, 0x00, // Char 114 (r) + 0x00, 0x00, 0x7C, 0x06, 0x3C, 0x60, 0x3E, 0x00, // Char 115 (s) + 0x00, 0x18, 0x7E, 0x18, 0x18, 0x18, 0x70, 0x00, // Char 116 (t) + 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x00, // Char 117 (u) + 0x00, 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, // Char 118 (v) + 0x00, 0x00, 0xC6, 0xD6, 0xFE, 0x7C, 0x6C, 0x00, // Char 119 (w) + 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x00, // Char 120 (x) + 0x00, 0x00, 0x66, 0x66, 0x7C, 0x60, 0x3C, 0x00, // Char 121 (y) + 0x00, 0x00, 0x7E, 0x30, 0x18, 0x0C, 0x7E, 0x00, // Char 122 (z) + 0x00, 0x18, 0x08, 0x08, 0x04, 0x08, 0x08, 0x18, // Char 123 ({) + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, // Char 124 (|) + 0x00, 0x0C, 0x08, 0x08, 0x10, 0x08, 0x08, 0x0C, // Char 125 (}) + 0x00, 0x00, 0x00, 0x4C, 0x32, 0x00, 0x00, 0x00 // Char 126 (~) +}; + +void gfx_init_ctxt(u32 *fb, u32 width, u32 height, u32 stride) +{ + gfx_ctxt.fb = fb; + gfx_ctxt.width = width; + gfx_ctxt.height = height; + gfx_ctxt.stride = stride; +} + +void gfx_clear_grey(u8 color) +{ + memset(gfx_ctxt.fb, color, 0x3C0000); +} + +void gfx_clear_color(u32 color) +{ + for (u32 i = 0; i < gfx_ctxt.height * gfx_ctxt.stride; i++) + gfx_ctxt.fb[i] = color; +} + +void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height) +{ + memset(gfx_ctxt.fb + pos_x * gfx_ctxt.stride, color, height * 4 * gfx_ctxt.stride); +} + +void gfx_con_init() +{ + gfx_con.gfx_ctxt = &gfx_ctxt; + gfx_con.fntsz = 16; + gfx_con.x = 0; + gfx_con.y = 0; + gfx_con.savedx = 0; + gfx_con.savedy = 0; + gfx_con.fgcol = 0xFFCCCCCC; + gfx_con.fillbg = 1; + gfx_con.bgcol = 0xFF1B1B1B; + gfx_con.mute = 0; +} + +void gfx_con_setcol(u32 fgcol, int fillbg, u32 bgcol) +{ + gfx_con.fgcol = fgcol; + gfx_con.fillbg = fillbg; + gfx_con.bgcol = bgcol; +} + +void gfx_con_getpos(u32 *x, u32 *y) +{ + *x = gfx_con.x; + *y = gfx_con.y; +} + +void gfx_con_setpos(u32 x, u32 y) +{ + gfx_con.x = x; + gfx_con.y = y; +} + +void gfx_putc(char c) +{ + // Duplicate code for performance reasons. + switch (gfx_con.fntsz) + { + case 16: + if (c >= 32 && c <= 126) + { + u8 *cbuf = (u8 *)&_gfx_font[8 * (c - 32)]; + u32 *fb = gfx_ctxt.fb + gfx_con.x + gfx_con.y * gfx_ctxt.stride; + + for (u32 i = 0; i < 16; i+=2) + { + u8 v = *cbuf++; + for (u32 k = 0; k < 2; k++) + { + for (u32 j = 0; j < 8; j++) + { + if (v & 1) + { + *fb = gfx_con.fgcol; + fb++; + *fb = gfx_con.fgcol; + } + else if (gfx_con.fillbg) + { + *fb = gfx_con.bgcol; + fb++; + *fb = gfx_con.bgcol; + } + else + fb++; + v >>= 1; + fb++; + } + fb += gfx_ctxt.stride - 16; + v = *cbuf; + } + } + gfx_con.x += 16; + } + else if (c == '\n') + { + gfx_con.x = 0; + gfx_con.y +=16; + if (gfx_con.y > gfx_ctxt.height - 16) + gfx_con.y = 0; + } + break; + case 8: + default: + if (c >= 32 && c <= 126) + { + u8 *cbuf = (u8 *)&_gfx_font[8 * (c - 32)]; + u32 *fb = gfx_ctxt.fb + gfx_con.x + gfx_con.y * gfx_ctxt.stride; + for (u32 i = 0; i < 8; i++) + { + u8 v = *cbuf++; + for (u32 j = 0; j < 8; j++) + { + if (v & 1) + *fb = gfx_con.fgcol; + else if (gfx_con.fillbg) + *fb = gfx_con.bgcol; + v >>= 1; + fb++; + } + fb += gfx_ctxt.stride - 8; + } + gfx_con.x += 8; + } + else if (c == '\n') + { + gfx_con.x = 0; + gfx_con.y += 8; + if (gfx_con.y > gfx_ctxt.height - 8) + gfx_con.y = 0; + } + break; + } + +} + +void gfx_puts(const char *s) +{ + if (!s || gfx_con.mute) + return; + + for (; *s; s++) + gfx_putc(*s); +} + +static void _gfx_putn(u32 v, int base, char fill, int fcnt) +{ + char buf[65]; + static const char digits[] = "0123456789ABCDEFghijklmnopqrstuvwxyz"; + char *p; + int c = fcnt; + + if (base > 36) + return; + + p = buf + 64; + *p = 0; + do + { + c--; + *--p = digits[v % base]; + v /= base; + } while (v); + + if (fill != 0) + { + while (c > 0) + { + *--p = fill; + c--; + } + } + + gfx_puts(p); +} + +void gfx_put_small_sep() +{ + u8 prevFontSize = gfx_con.fntsz; + gfx_con.fntsz = 8; + gfx_putc('\n'); + gfx_con.fntsz = prevFontSize; +} + +void gfx_put_big_sep() +{ + u8 prevFontSize = gfx_con.fntsz; + gfx_con.fntsz = 16; + gfx_putc('\n'); + gfx_con.fntsz = prevFontSize; +} + +void gfx_printf(const char *fmt, ...) +{ + if (gfx_con.mute) + return; + + va_list ap; + int fill, fcnt; + + va_start(ap, fmt); + while(*fmt) + { + if(*fmt == '%') + { + fmt++; + fill = 0; + fcnt = 0; + if ((*fmt >= '0' && *fmt <= '9') || *fmt == ' ') + { + fcnt = *fmt; + fmt++; + if (*fmt >= '0' && *fmt <= '9') + { + fill = fcnt; + fcnt = *fmt - '0'; + fmt++; + } + else + { + fill = ' '; + fcnt -= '0'; + } + } + switch(*fmt) + { + case 'c': + gfx_putc(va_arg(ap, u32)); + break; + case 's': + gfx_puts(va_arg(ap, char *)); + break; + case 'd': + _gfx_putn(va_arg(ap, u32), 10, fill, fcnt); + break; + case 'p': + case 'P': + case 'x': + case 'X': + _gfx_putn(va_arg(ap, u32), 16, fill, fcnt); + break; + case 'k': + gfx_con.fgcol = va_arg(ap, u32); + break; + case 'K': + gfx_con.bgcol = va_arg(ap, u32); + gfx_con.fillbg = 1; + break; + case '%': + gfx_putc('%'); + break; + case '\0': + goto out; + default: + gfx_putc('%'); + gfx_putc(*fmt); + break; + } + } + else + gfx_putc(*fmt); + fmt++; + } + + out: + va_end(ap); +} + +void gfx_hexdump(u32 base, const u8 *buf, u32 len) +{ + if (gfx_con.mute) + return; + + u8 prevFontSize = gfx_con.fntsz; + gfx_con.fntsz = 8; + for(u32 i = 0; i < len; i++) + { + if(i % 0x10 == 0) + { + if(i != 0) + { + gfx_puts("| "); + for(u32 j = 0; j < 0x10; j++) + { + u8 c = buf[i - 0x10 + j]; + if(c >= 32 && c <= 126) + gfx_putc(c); + else + gfx_putc('.'); + } + gfx_putc('\n'); + } + gfx_printf("%08x: ", base + i); + } + gfx_printf("%02x ", buf[i]); + if (i == len - 1) + { + int ln = len % 0x10 != 0; + u32 k = 0x10 - 1; + if (ln) + { + k = (len & 0xF) - 1; + for (u32 j = 0; j < 0x10 - k; j++) + gfx_puts(" "); + } + gfx_puts("| "); + for(u32 j = 0; j < (ln ? k : k + 1); j++) + { + u8 c = buf[i - k + j]; + if(c >= 32 && c <= 126) + gfx_putc(c); + else + gfx_putc('.'); + } + gfx_putc('\n'); + } + } + gfx_putc('\n'); + gfx_con.fntsz = prevFontSize; +} + +static int abs(int x) +{ + if (x < 0) + return -x; + return x; +} + +void gfx_set_pixel(u32 x, u32 y, u32 color) +{ + gfx_ctxt.fb[x + y * gfx_ctxt.stride] = color; +} + +void gfx_line(int x0, int y0, int x1, int y1, u32 color) +{ + int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1; + int dy = abs(y1 - y0), sy = y0 < y1 ? 1 : -1; + int err = (dx > dy ? dx : -dy) / 2, e2; + + while (1) + { + gfx_set_pixel(x0, y0, color); + if (x0 == x1 && y0 == y1) + break; + e2 = err; + if (e2 >-dx) + { + err -= dy; + x0 += sx; + } + if (e2 < dy) + { + err += dx; + y0 += sy; + } + } +} + +#pragma GCC pop_options + +void gfx_set_rect_grey(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) +{ + u32 pos = 0; + for (u32 y = pos_y; y < (pos_y + size_y); y++) + { + for (u32 x = pos_x; x < (pos_x + size_x); x++) + { + memset(&gfx_ctxt.fb[x + y*gfx_ctxt.stride], buf[pos], 4); + pos++; + } + } +} + + +void gfx_set_rect_rgb(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) +{ + u32 pos = 0; + for (u32 y = pos_y; y < (pos_y + size_y); y++) + { + for (u32 x = pos_x; x < (pos_x + size_x); x++) + { + gfx_ctxt.fb[x + y * gfx_ctxt.stride] = buf[pos + 2] | (buf[pos + 1] << 8) | (buf[pos] << 16); + pos+=3; + } + } +} + +void gfx_set_rect_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) +{ + u32 *ptr = (u32 *)buf; + for (u32 y = pos_y; y < (pos_y + size_y); y++) + for (u32 x = pos_x; x < (pos_x + size_x); x++) + gfx_ctxt.fb[x + y * gfx_ctxt.stride] = *ptr++; +} + +void gfx_set_rect_argb_land(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) +{ + u32 pos = 0; + for (u32 y = pos_y; y < (pos_y + size_y); y++) + { + for (u32 x = pos_x; x < (pos_x + size_x); x++) + { + gfx_ctxt.fb[y + (gfx_ctxt.width - x) * gfx_ctxt.stride] = buf[pos]; + pos+=1; + } + } +} + +void gfx_fill_rect_argb(const u32 color, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) +{ + for (u32 y = pos_y; y < (pos_y + size_y); y++) + for (u32 x = pos_x; x < (pos_x + size_x); x++) + gfx_ctxt.fb[x + y * gfx_ctxt.stride] = color; +} + +void gfx_render_bmp_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) +{ + for (u32 y = pos_y; y < (pos_y + size_y); y++) + { + for (u32 x = pos_x; x < (pos_x + size_x); x++) + gfx_ctxt.fb[x + y * gfx_ctxt.stride] = buf[(size_y + pos_y - 1 - y ) * size_x + x - pos_x]; + } +} + +__attribute__((target("arm"))) void gfx_set_rect_land_pitch(u32 *fb, const u32 *buf, u32 pos_x, u32 pos_y, u32 pos_x2, u32 pos_y2) +{ + u32 *ptr = (u32 *)buf; + + u32 pixels_w = pos_x2 - pos_x + 1; + + if (!(pixels_w % 8)) + { + for (u32 y = pos_y; y < (pos_y2 + 1); y++) + for (u32 x = pos_x; x < (pos_x2 + 1); x+=8) + { + u32 *fbx = &fb[x * gfx_ctxt.stride + y]; + + fbx[0] = *ptr++; + fbx[gfx_ctxt.stride] = *ptr++; + fbx[gfx_ctxt.stride * 2] = *ptr++; + fbx[gfx_ctxt.stride * 3] = *ptr++; + fbx[gfx_ctxt.stride * 4] = *ptr++; + fbx[gfx_ctxt.stride * 5] = *ptr++; + fbx[gfx_ctxt.stride * 6] = *ptr++; + fbx[gfx_ctxt.stride * 7] = *ptr++; + } + } + else + { + for (u32 y = pos_y; y < (pos_y2 + 1); y++) + for (u32 x = pos_x; x < (pos_x2 + 1); x++) + fb[x * gfx_ctxt.stride + y] = *ptr++; + } +} + +__attribute__((target("arm"))) void gfx_set_rect_land_block(const u32 *buf, u32 pos_x, u32 pos_y, u32 pos_x2, u32 pos_y2) +{ + u32 *ptr = (u32 *)buf; + u32 GOB_address = 0; + u32 addr = 0; + u32 x2 = 0; + + // Optimized + u32 image_width_in_gobs = 655360; //1280 + for (u32 y = pos_y; y < (pos_y2 + 1); y++) + { + for (u32 x = pos_x; x < (pos_x2 + 1); x++) + { + GOB_address = (y >> 7) * image_width_in_gobs + ((x >> 4) << 13) + (((y % 128) >> 3) << 9); + + x2 = x << 2; + addr = GOB_address + + (((x2 % 64) >> 5) << 8) + + (((y % 8) >> 1) << 6) + + (((x2 % 32) >> 4) << 5) + + ((y % 2) << 4) + (x2 % 16); + + *(u32 *)(gfx_ctxt.fb + (addr >> 2)) = *ptr++; + } + } + + // Proper + // u32 block_height = 16; + // u32 image_width_in_gobs = (512 * block_height * 1280 * 4) / 64; + // for (u32 y = pos_y; y <= pos_y2; y++) + // { + // for (int x = pos_x; x <= pos_x2; x++) + // { + // GOB_address = (y / (8 * block_height)) * image_width_in_gobs + ((x * 4 / 64) * 512 * block_height) + ((y % (8 * block_height) / 8) * 512); + + // x2 = x << 2; + // addr = GOB_address + // + (((x2 % 64) >> 5) << 8) + // + (((y % 8) >> 1) << 6) + // + (((x2 % 32) >> 4) << 5) + // + ((y % 2) << 4) + (x2 % 16); + + // *(u32 *)(gfx_ctxt.fb + (addr >> 2)) = *ptr++; + // } + // } +} diff --git a/nyx/nyx_gui/gfx/gfx.h b/nyx/nyx_gui/gfx/gfx.h new file mode 100644 index 0000000..b3d0aca --- /dev/null +++ b/nyx/nyx_gui/gfx/gfx.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018-2019 CTCaer + * Copyright (C) 2018 M4xw + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _GFX_H_ +#define _GFX_H_ + +#include "../../../common/common_gfx.h" + +#define EPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) +#define EPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) +#define WPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) +#define WPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC) + +void gfx_init_ctxt(u32 *fb, u32 width, u32 height, u32 stride); +void gfx_clear_grey(u8 color); +void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height); +void gfx_clear_color(u32 color); +void gfx_con_init(); +void gfx_con_setcol(u32 fgcol, int fillbg, u32 bgcol); +void gfx_con_getpos(u32 *x, u32 *y); +void gfx_con_setpos(u32 x, u32 y); +void gfx_putc(char c); +void gfx_puts(const char *s); +void gfx_printf(const char *fmt, ...); +void gfx_hexdump(u32 base, const u8 *buf, u32 len); + +void gfx_set_pixel(u32 x, u32 y, u32 color); +void gfx_line(int x0, int y0, int x1, int y1, u32 color); +void gfx_put_small_sep(); +void gfx_put_big_sep(); +void gfx_set_rect_grey(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); +void gfx_set_rect_rgb(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); +void gfx_set_rect_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); + +void gfx_set_rect_argb_land(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); +void gfx_fill_rect_argb(const u32 color, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); +void gfx_render_bmp_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); + +void gfx_set_rect_land_pitch(u32 *fb, const u32 *buf, u32 pos_x, u32 pos_y, u32 pos_x2, u32 pos_y2); +void gfx_set_rect_land_block(const u32 *buf, u32 pos_x, u32 pos_y, u32 pos_x2, u32 pos_y2); + +// Global gfx console and context. +gfx_ctxt_t gfx_ctxt; +gfx_con_t gfx_con; + +#endif diff --git a/nyx/nyx_gui/gfx/logos-gui.h b/nyx/nyx_gui/gfx/logos-gui.h new file mode 100644 index 0000000..502e5fc --- /dev/null +++ b/nyx/nyx_gui/gfx/logos-gui.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../libs/lv_conf.h" +#include "../libs/lvgl/lv_draw/lv_draw_img.h" +#include "../utils/types.h" + +#define HEKATE_LOGO + +#ifdef HEKATE_LOGO + +lv_img_dsc_t hekate_logo = { + .header.always_zero = 0, + .header.w = 193, + .header.h = 76, + .data_size = 14668 * LV_IMG_PX_SIZE_ALPHA_BYTE, + .header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA, + .data = (const uint8_t *)(NYX_RES_ADDR + 0x1D900), +}; + +lv_img_dsc_t ctcaer_logo = { + .header.always_zero = 0, + .header.w = 147, + .header.h = 76, + .data_size = 11172 * LV_IMG_PX_SIZE_ALPHA_BYTE, + .header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA, + .data = (const uint8_t *)(NYX_RES_ADDR + 0x2BF00), +}; + +#endif \ No newline at end of file diff --git a/nyx/nyx_gui/hos/hos.c b/nyx/nyx_gui/hos/hos.c new file mode 100644 index 0000000..9166e4d --- /dev/null +++ b/nyx/nyx_gui/hos/hos.c @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 st4rk + * Copyright (c) 2018 Ced2911 + * Copyright (c) 2018-2019 CTCaer + * Copyright (c) 2018 balika011 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "hos.h" +#include "sept.h" +#include "../config/config.h" +#include "../gfx/di.h" +#include "../gfx/gfx.h" +#include "../mem/heap.h" +#include "../mem/mc.h" +#include "../sec/se.h" +#include "../sec/se_t210.h" +#include "../sec/tsec.h" +#include "../soc/bpmp.h" +#include "../soc/cluster.h" +#include "../soc/fuse.h" +#include "../soc/pmc.h" +#include "../soc/smmu.h" +#include "../soc/t210.h" +#include "../storage/nx_emmc.h" +#include "../storage/sdmmc.h" +#include "../utils/util.h" + +extern hekate_config h_cfg; + +extern void sd_unmount(bool deinit); + +//#define DPRINTF(...) gfx_printf(__VA_ARGS__) +#define DPRINTF(...) + +#define PKG2_LOAD_ADDR 0xA9800000 + + // Secmon mailbox. +#define SECMON_MB_ADDR 0x40002EF8 +#define SECMON7_MB_ADDR 0x400000F8 +typedef struct _secmon_mailbox_t +{ + // < 4.0.0 Signals - 0: Not ready, 1: BCT ready, 2: DRAM and pkg2 ready, 3: Continue boot. + // >= 4.0.0 Signals - 0: Not ready, 1: BCT ready, 2: DRAM ready, 4: pkg2 ready and continue boot. + u32 in; + // Non-zero: Secmon ready. + u32 out; +} secmon_mailbox_t; + +static const u8 keyblob_keyseeds[][0x10] = { + { 0xDF, 0x20, 0x6F, 0x59, 0x44, 0x54, 0xEF, 0xDC, 0x70, 0x74, 0x48, 0x3B, 0x0D, 0xED, 0x9F, 0xD3 }, //1.0.0 + { 0x0C, 0x25, 0x61, 0x5D, 0x68, 0x4C, 0xEB, 0x42, 0x1C, 0x23, 0x79, 0xEA, 0x82, 0x25, 0x12, 0xAC }, //3.0.0 + { 0x33, 0x76, 0x85, 0xEE, 0x88, 0x4A, 0xAE, 0x0A, 0xC2, 0x8A, 0xFD, 0x7D, 0x63, 0xC0, 0x43, 0x3B }, //3.0.1 + { 0x2D, 0x1F, 0x48, 0x80, 0xED, 0xEC, 0xED, 0x3E, 0x3C, 0xF2, 0x48, 0xB5, 0x65, 0x7D, 0xF7, 0xBE }, //4.0.0 + { 0xBB, 0x5A, 0x01, 0xF9, 0x88, 0xAF, 0xF5, 0xFC, 0x6C, 0xFF, 0x07, 0x9E, 0x13, 0x3C, 0x39, 0x80 }, //5.0.0 + { 0xD8, 0xCC, 0xE1, 0x26, 0x6A, 0x35, 0x3F, 0xCC, 0x20, 0xF3, 0x2D, 0x3B, 0x51, 0x7D, 0xE9, 0xC0 } //6.0.0 +}; + +static const u8 cmac_keyseed[0x10] = + { 0x59, 0xC7, 0xFB, 0x6F, 0xBE, 0x9B, 0xBE, 0x87, 0x65, 0x6B, 0x15, 0xC0, 0x53, 0x73, 0x36, 0xA5 }; + +static const u8 master_keyseed_retail[0x10] = + { 0xD8, 0xA2, 0x41, 0x0A, 0xC6, 0xC5, 0x90, 0x01, 0xC6, 0x1D, 0x6A, 0x26, 0x7C, 0x51, 0x3F, 0x3C }; + +static const u8 console_keyseed[0x10] = + { 0x4F, 0x02, 0x5F, 0x0E, 0xB6, 0x6D, 0x11, 0x0E, 0xDC, 0x32, 0x7D, 0x41, 0x86, 0xC2, 0xF4, 0x78 }; + +static const u8 package2_keyseed[] = + { 0xFB, 0x8B, 0x6A, 0x9C, 0x79, 0x00, 0xC8, 0x49, 0xEF, 0xD2, 0x4D, 0x85, 0x4D, 0x30, 0xA0, 0xC7 }; + +static const u8 master_keyseed_4xx_5xx_610[0x10] = + { 0x2D, 0xC1, 0xF4, 0x8D, 0xF3, 0x5B, 0x69, 0x33, 0x42, 0x10, 0xAC, 0x65, 0xDA, 0x90, 0x46, 0x66 }; + +static const u8 master_keyseed_620[0x10] = + { 0x37, 0x4B, 0x77, 0x29, 0x59, 0xB4, 0x04, 0x30, 0x81, 0xF6, 0xE5, 0x8C, 0x6D, 0x36, 0x17, 0x9A }; + +static const u8 console_keyseed_4xx_5xx[0x10] = + { 0x0C, 0x91, 0x09, 0xDB, 0x93, 0x93, 0x07, 0x81, 0x07, 0x3C, 0xC4, 0x16, 0x22, 0x7C, 0x6C, 0x28 }; + +int keygen(u8 *keyblob, u32 kb, tsec_ctxt_t *tsec_ctxt) +{ + u8 tmp[0x20]; + u32 retries = 0; + + if (kb > KB_FIRMWARE_VERSION_MAX) + return 0; + + if (kb <= KB_FIRMWARE_VERSION_600) + tsec_ctxt->size = 0xF00; + else if (kb == KB_FIRMWARE_VERSION_620) + tsec_ctxt->size = 0x2900; + else if (kb == KB_FIRMWARE_VERSION_700) + tsec_ctxt->size = 0x3000; + else + tsec_ctxt->size = 0x3300; + + // Prepare smmu tsec page for 6.2.0. + if (kb == KB_FIRMWARE_VERSION_620) + { + u8 *tsec_paged = (u8 *)page_alloc(3); + memcpy(tsec_paged, (void *)tsec_ctxt->fw, tsec_ctxt->size); + tsec_ctxt->fw = tsec_paged; + } + + // Get TSEC key. + if (kb <= KB_FIRMWARE_VERSION_620) + { + while (tsec_query(tmp, kb, tsec_ctxt) < 0) + { + memset(tmp, 0x00, 0x20); + retries++; + + // We rely on racing conditions, make sure we cover even the unluckiest cases. + if (retries > 15) + return 0; + } + } + + if (kb >= KB_FIRMWARE_VERSION_700) + se_aes_unwrap_key(8, 12, package2_keyseed); + else if (kb == KB_FIRMWARE_VERSION_620) + { + // Set TSEC key. + se_aes_key_set(12, tmp, 0x10); + // Set TSEC root key. + se_aes_key_set(13, tmp + 0x10, 0x10); + + // Package2 key. + se_aes_key_set(8, tmp + 0x10, 0x10); + se_aes_unwrap_key(8, 8, master_keyseed_620); + se_aes_unwrap_key(8, 8, master_keyseed_retail); + se_aes_unwrap_key(8, 8, package2_keyseed); + } + else + { + se_key_acc_ctrl(13, 0x15); + se_key_acc_ctrl(14, 0x15); + + // Set TSEC key. + se_aes_key_set(13, tmp, 0x10); + + // Derive keyblob keys from TSEC+SBK. + se_aes_crypt_block_ecb(13, 0, tmp, keyblob_keyseeds[0]); + se_aes_unwrap_key(15, 14, tmp); + se_aes_crypt_block_ecb(13, 0, tmp, keyblob_keyseeds[kb]); + se_aes_unwrap_key(13, 14, tmp); + + // Clear SBK. + se_aes_key_clear(14); + + //TODO: verify keyblob CMAC. + //se_aes_unwrap_key(11, 13, cmac_keyseed); + //se_aes_cmac(tmp, 0x10, 11, keyblob + 0x10, 0xA0); + //if (!memcmp(keyblob, tmp, 0x10)) + // return 0; + + se_aes_crypt_block_ecb(13, 0, tmp, cmac_keyseed); + se_aes_unwrap_key(11, 13, cmac_keyseed); + + // Decrypt keyblob and set keyslots. + se_aes_crypt_ctr(13, keyblob + 0x20, 0x90, keyblob + 0x20, 0x90, keyblob + 0x10); + se_aes_key_set(11, keyblob + 0x20 + 0x80, 0x10); // Package1 key. + se_aes_key_set(12, keyblob + 0x20, 0x10); + se_aes_key_set(13, keyblob + 0x20, 0x10); + + se_aes_crypt_block_ecb(12, 0, tmp, master_keyseed_retail); + + switch (kb) + { + case KB_FIRMWARE_VERSION_100_200: + case KB_FIRMWARE_VERSION_300: + case KB_FIRMWARE_VERSION_301: + se_aes_unwrap_key(13, 15, console_keyseed); + se_aes_unwrap_key(12, 12, master_keyseed_retail); + break; + case KB_FIRMWARE_VERSION_400: + se_aes_unwrap_key(13, 15, console_keyseed_4xx_5xx); + se_aes_unwrap_key(15, 15, console_keyseed); + se_aes_unwrap_key(14, 12, master_keyseed_4xx_5xx_610); + se_aes_unwrap_key(12, 12, master_keyseed_retail); + break; + case KB_FIRMWARE_VERSION_500: + case KB_FIRMWARE_VERSION_600: + se_aes_unwrap_key(10, 15, console_keyseed_4xx_5xx); + se_aes_unwrap_key(15, 15, console_keyseed); + se_aes_unwrap_key(14, 12, master_keyseed_4xx_5xx_610); + se_aes_unwrap_key(12, 12, master_keyseed_retail); + break; + } + + // Package2 key. + se_key_acc_ctrl(8, 0x15); + se_aes_unwrap_key(8, 12, package2_keyseed); + } + + return 1; +} diff --git a/nyx/nyx_gui/hos/hos.h b/nyx/nyx_gui/hos/hos.h new file mode 100644 index 0000000..3a4fe2f --- /dev/null +++ b/nyx/nyx_gui/hos/hos.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _HOS_H_ +#define _HOS_H_ + +#include "pkg1.h" +#include "pkg2.h" +#include "../utils/types.h" +#include "../config/ini.h" +#include "../sec/tsec.h" + +#define KB_FIRMWARE_VERSION_100_200 0 +#define KB_FIRMWARE_VERSION_300 1 +#define KB_FIRMWARE_VERSION_301 2 +#define KB_FIRMWARE_VERSION_400 3 +#define KB_FIRMWARE_VERSION_500 4 +#define KB_FIRMWARE_VERSION_600 5 +#define KB_FIRMWARE_VERSION_620 6 +#define KB_FIRMWARE_VERSION_700 7 +#define KB_FIRMWARE_VERSION_810 8 +#define KB_FIRMWARE_VERSION_MAX KB_FIRMWARE_VERSION_810 + +#define HOS_PKG11_MAGIC 0x31314B50 + +typedef struct _launch_ctxt_t +{ + void *keyblob; + + void *pkg1; + const pkg1_id_t *pkg1_id; + + void *warmboot; + u32 warmboot_size; + void *secmon; + u32 secmon_size; + + void *pkg2; + u32 pkg2_size; + + bool new_pkg2; + void *kernel; + u32 kernel_size; + link_t kip1_list; + char* kip1_patches; + + bool svcperm; + bool debugmode; + bool stock; + bool atmosphere; + + ini_sec_t *cfg; +} launch_ctxt_t; + +int keygen(u8 *keyblob, u32 kb, tsec_ctxt_t *tsec_ctxt); + +#endif diff --git a/nyx/nyx_gui/hos/pkg1.c b/nyx/nyx_gui/hos/pkg1.c new file mode 100644 index 0000000..ff34af0 --- /dev/null +++ b/nyx/nyx_gui/hos/pkg1.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 st4rk + * Copyright (c) 2018-2019 CTCaer + * Copyright (c) 2018 balika011 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "pkg1.h" +#include "../gfx/gfx.h" +#include "../mem/heap.h" +#include "../sec/se.h" +#include "../utils/aarch64_util.h" + +/* + * package1.1 header: + * package1.1 layout: + * 1.0: {sm, ldr, wb} { 2, 1, 0 } + * 2.0: {wb, ldr, sm} { 0, 1, 2 } + * 3.0: {wb, ldr, sm} { 0, 1, 2 } + * 3.1: {wb, ldr, sm} { 0, 1, 2 } + * 4.0: {ldr, sm, wb} { 1, 2, 0 } + * 5.0: {ldr, sm, wb} { 1, 2, 0 } + * 6.0: {ldr, sm, wb} { 1, 2, 0 } + * 6.2: {ldr, sm, wb} { 1, 2, 0 } + * 7.0: {ldr, sm, wb} { 1, 2, 0 } + */ + +static const pkg1_id_t _pkg1_ids[] = { + { "20161121183008", 0, 0x1900, 0x3FE0, { 2, 1, 0 }, 0x40014020, 0x8000D000 }, //1.0.0 + { "20170210155124", 0, 0x1900, 0x3FE0, { 0, 1, 2 }, 0x4002D000, 0x8000D000 }, //2.0.0 - 2.3.0 + { "20170519101410", 1, 0x1A00, 0x3FE0, { 0, 1, 2 }, 0x4002D000, 0x8000D000 }, //3.0.0 + { "20170710161758", 2, 0x1A00, 0x3FE0, { 0, 1, 2 }, 0x4002D000, 0x8000D000 }, //3.0.1 - 3.0.2 + { "20170921172629", 3, 0x1800, 0x3FE0, { 1, 2, 0 }, 0x4002B000, 0x4003B000 }, //4.0.0 - 4.1.0 + { "20180220163747", 4, 0x1900, 0x3FE0, { 1, 2, 0 }, 0x4002B000, 0x4003B000 }, //5.0.0 - 5.1.0 + { "20180802162753", 5, 0x1900, 0x3FE0, { 1, 2, 0 }, 0x4002B000, 0x4003D800 }, //6.0.0 - 6.1.0 + { "20181107105733", 6, 0x0E00, 0x6FE0, { 1, 2, 0 }, 0x4002B000, 0x4003D800 }, //6.2.0 + { "20181218175730", 7, 0x0F00, 0x6FE0, { 1, 2, 0 }, 0x40030000, 0x4003E000 }, //7.0.0 + { "20190208150037", 7, 0x0F00, 0x6FE0, { 1, 2, 0 }, 0x40030000, 0x4003E000 }, //7.0.1 + { "20190314172056", 7, 0x0E00, 0x6FE0, { 1, 2, 0 }, 0x40030000, 0x4003E000 }, //8.0.0 - 8.0.1 + { "20190531152432", 8, 0x0E00, 0x6FE0, { 1, 2, 0 }, 0x40030000, 0x4003E000 }, //8.1.0 + { NULL } //End. +}; + +const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date) +{ + memcpy(build_date, (char *)(pkg1 + 0x10), 14); + build_date[14] = 0; + + for (u32 i = 0; _pkg1_ids[i].id; i++) + if (!memcmp(pkg1 + 0x10, _pkg1_ids[i].id, 12)) + return &_pkg1_ids[i]; + return NULL; +} + +void pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1) +{ + // Decrypt package1. + u8 *pkg11 = pkg1 + id->pkg11_off; + u32 pkg11_size = *(u32 *)pkg11; + se_aes_crypt_ctr(11, pkg11 + 0x20, pkg11_size, pkg11 + 0x20, pkg11_size, pkg11 + 0x10); +} + +void pkg1_unpack(void *warmboot_dst, void *secmon_dst, void *ldr_dst, const pkg1_id_t *id, u8 *pkg1) +{ + pk11_hdr_t *hdr = (pk11_hdr_t *)(pkg1 + id->pkg11_off + 0x20); + + u32 sec_size[3] = { hdr->wb_size, hdr->ldr_size, hdr->sm_size }; + //u32 sec_off[3] = { hdr->wb_off, hdr->ldr_off, hdr->sm_off }; + + u8 *pdata = (u8 *)hdr + sizeof(pk11_hdr_t); + for (u32 i = 0; i < 3; i++) + { + if (id->sec_map[i] == 0 && warmboot_dst) + memcpy(warmboot_dst, pdata, sec_size[id->sec_map[i]]); + else if (id->sec_map[i] == 1 && ldr_dst) + memcpy(ldr_dst, pdata, sec_size[id->sec_map[i]]); + else if (id->sec_map[i] == 2 && secmon_dst) + memcpy(secmon_dst, pdata, sec_size[id->sec_map[i]]); + pdata += sec_size[id->sec_map[i]]; + } +} diff --git a/nyx/nyx_gui/hos/pkg1.h b/nyx/nyx_gui/hos/pkg1.h new file mode 100644 index 0000000..d22b672 --- /dev/null +++ b/nyx/nyx_gui/hos/pkg1.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _PKG1_H_ +#define _PKG1_H_ + +#include "../utils/types.h" + +typedef struct _pkg1_id_t +{ + const char *id; + u32 kb; + u32 tsec_off; + u32 pkg11_off; + u32 sec_map[3]; + u32 secmon_base; + u32 warmboot_base; +} pkg1_id_t; + +typedef struct _pk11_hdr_t +{ + u32 magic; + u32 wb_size; + u32 wb_off; + u32 pad; + u32 ldr_size; + u32 ldr_off; + u32 sm_size; + u32 sm_off; +} pk11_hdr_t; + +const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date); +void pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1); +void pkg1_unpack(void *warmboot_dst, void *secmon_dst, void *ldr_dst, const pkg1_id_t *id, u8 *pkg1); + +#endif diff --git a/nyx/nyx_gui/hos/pkg2.c b/nyx/nyx_gui/hos/pkg2.c new file mode 100644 index 0000000..28af5e0 --- /dev/null +++ b/nyx/nyx_gui/hos/pkg2.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "pkg2.h" +#include "hos.h" + +#include "../libs/fatfs/ff.h" +#include "../utils/aarch64_util.h" +#include "../mem/heap.h" +#include "../sec/se.h" +#include "../libs/compr/blz.h" + +#include "../gfx/gfx.h" + +/*#include "util.h" +#define DPRINTF(...) gfx_printf(__VA_ARGS__) +#define DEBUG_PRINTING*/ +#define DPRINTF(...) + +u32 pkg2_calc_kip1_size(pkg2_kip1_t *kip1) +{ + u32 size = sizeof(pkg2_kip1_t); + for (u32 j = 0; j < KIP1_NUM_SECTIONS; j++) + size += kip1->sections[j].size_comp; + return size; +} + +void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2) +{ + u8 *ptr; + // Check for new pkg2 type. + if (!pkg2->sec_size[PKG2_SEC_INI1]) + { + u32 kernel_ini1_off = *(u32 *)(pkg2->data + PKG2_NEWKERN_INI1_START); + ptr = pkg2->data + kernel_ini1_off; + *new_pkg2 = true; + } + else + ptr = pkg2->data + pkg2->sec_size[PKG2_SEC_KERNEL]; + + pkg2_ini1_t *ini1 = (pkg2_ini1_t *)ptr; + ptr += sizeof(pkg2_ini1_t); + + for (u32 i = 0; i < ini1->num_procs; i++) + { + pkg2_kip1_t *kip1 = (pkg2_kip1_t *)ptr; + pkg2_kip1_info_t *ki = (pkg2_kip1_info_t *)malloc(sizeof(pkg2_kip1_info_t)); + ki->kip1 = kip1; + ki->size = pkg2_calc_kip1_size(kip1); + list_append(info, &ki->link); + ptr += ki->size; +DPRINTF(" kip1 %d:%s @ %08X (%08X)\n", i, kip1->name, (u32)kip1, ki->size); + } +} + +pkg2_hdr_t *pkg2_decrypt(void *data) +{ + u8 *pdata = (u8 *)data; + + // Skip signature. + pdata += 0x100; + + pkg2_hdr_t *hdr = (pkg2_hdr_t *)pdata; + + // Skip header. + pdata += sizeof(pkg2_hdr_t); + + // Decrypt header. + se_aes_crypt_ctr(8, hdr, sizeof(pkg2_hdr_t), hdr, sizeof(pkg2_hdr_t), hdr); + //gfx_hexdump((u32)hdr, hdr, 0x100); + + if (hdr->magic != PKG2_MAGIC) + return NULL; + + for (u32 i = 0; i < 4; i++) + { +DPRINTF("sec %d has size %08X\n", i, hdr->sec_size[i]); + if (!hdr->sec_size[i]) + continue; + + se_aes_crypt_ctr(8, pdata, hdr->sec_size[i], pdata, hdr->sec_size[i], &hdr->sec_ctr[i * 0x10]); + //gfx_hexdump((u32)pdata, pdata, 0x100); + + pdata += hdr->sec_size[i]; + } + + return hdr; +} diff --git a/nyx/nyx_gui/hos/pkg2.h b/nyx/nyx_gui/hos/pkg2.h new file mode 100644 index 0000000..fc189f5 --- /dev/null +++ b/nyx/nyx_gui/hos/pkg2.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _PKG2_H_ +#define _PKG2_H_ + +#include "../utils/types.h" +#include "../utils/list.h" + +#define PKG2_MAGIC 0x31324B50 +#define PKG2_SEC_BASE 0x80000000 +#define PKG2_SEC_KERNEL 0 +#define PKG2_SEC_INI1 1 + +#define INI1_MAGIC 0x31494E49 +#define PKG2_NEWKERN_INI1_START 0x168 +#define PKG2_NEWKERN_INI1_END 0x170 +#define PKG2_NEWKERN_START 0x800 + +typedef struct _pkg2_hdr_t +{ + u8 ctr[0x10]; + u8 sec_ctr[0x40]; + u32 magic; + u32 base; + u32 pad0; + u16 version; + u16 pad1; + u32 sec_size[4]; + u32 sec_off[4]; + u8 sec_sha256[0x80]; + u8 data[]; +} pkg2_hdr_t; + +typedef struct _pkg2_ini1_t +{ + u32 magic; + u32 size; + u32 num_procs; + u32 pad; +} pkg2_ini1_t; + +typedef struct _pkg2_kip1_sec_t +{ + u32 offset; + u32 size_decomp; + u32 size_comp; + u32 attrib; +} pkg2_kip1_sec_t; + +#define KIP1_NUM_SECTIONS 6 + +typedef struct _pkg2_kip1_t +{ + u32 magic; + u8 name[12]; + u64 tid; + u32 proc_cat; + u8 main_thrd_prio; + u8 def_cpu_core; + u8 res; + u8 flags; + pkg2_kip1_sec_t sections[KIP1_NUM_SECTIONS]; + u32 caps[0x20]; + u8 data[]; +} pkg2_kip1_t; + +typedef struct _pkg2_kip1_info_t +{ + pkg2_kip1_t *kip1; + u32 size; + link_t link; +} pkg2_kip1_info_t; + +u32 pkg2_calc_kip1_size(pkg2_kip1_t *kip1); +void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2); + +pkg2_hdr_t *pkg2_decrypt(void *data); + +#endif diff --git a/nyx/nyx_gui/hos/sept.c b/nyx/nyx_gui/hos/sept.c new file mode 100644 index 0000000..3d50f41 --- /dev/null +++ b/nyx/nyx_gui/hos/sept.c @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "hos.h" +#include "sept.h" +#include "../config/config.h" +#include "../gfx/di.h" +#include "../ianos/ianos.h" +#include "../libs/fatfs/ff.h" +#include "../mem/heap.h" +#include "../soc/hw_init.h" +#include "../soc/pmc.h" +#include "../soc/t210.h" +#include "../storage/nx_emmc.h" +#include "../storage/sdmmc.h" +#include "../utils/btn.h" +#include "../utils/types.h" +#include "../utils/util.h" + +#include "../gfx/gfx.h" + +#define RELOC_META_OFF 0x7C +#define PATCHED_RELOC_SZ 0x94 + +#define WB_RST_ADDR 0x40010ED0 +#define WB_RST_SIZE 0x30 + +u8 warmboot_reboot[] = { + 0x14, 0x00, 0x9F, 0xE5, // LDR R0, =0x7000E450 + 0x01, 0x10, 0xB0, 0xE3, // MOVS R1, #1 + 0x00, 0x10, 0x80, 0xE5, // STR R1, [R0] + 0x0C, 0x00, 0x9F, 0xE5, // LDR R0, =0x7000E400 + 0x10, 0x10, 0xB0, 0xE3, // MOVS R1, #0x10 + 0x00, 0x10, 0x80, 0xE5, // STR R1, [R0] + 0xFE, 0xFF, 0xFF, 0xEA, // LOOP + 0x50, 0xE4, 0x00, 0x70, // #0x7000E450 + 0x00, 0xE4, 0x00, 0x70 // #0x7000E400 +}; + +#define SEPT_PRI_ADDR 0x4003F000 + +#define SEPT_PK1T_ADDR 0xC0400000 +#define SEPT_TCSZ_ADDR (SEPT_PK1T_ADDR - 0x4) +#define SEPT_STG1_ADDR (SEPT_PK1T_ADDR + 0x2E100) +#define SEPT_STG2_ADDR (SEPT_PK1T_ADDR + 0x60E0) +#define SEPT_PKG_SZ (0x2F100 + WB_RST_SIZE) + +extern volatile boot_cfg_t *b_cfg; +extern hekate_config h_cfg; +extern volatile nyx_storage_t *nyx_str; + +extern void *sd_file_read(char *path); +extern void sd_mount(); +extern void sd_unmount(bool deinit); +extern bool is_ipl_updated(void *buf); +extern void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size); + +void check_sept() +{ + // Check if non-hekate payload is used for sept and restore it. + if (h_cfg.sept_run && !f_stat("sept/payload.bak", NULL)) + { + f_unlink("sept/payload.bin"); + f_rename("sept/payload.bak", "sept/payload.bin"); + return; + } + + u8 *pkg1 = (u8 *)calloc(1, 0x40000); + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + if (!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4)) + { + EPRINTF("Failed to init eMMC."); + goto out_free; + } + sdmmc_storage_set_mmc_partition(&storage, 1); + + // Read package1. + char *build_date = malloc(32); + sdmmc_storage_read(&storage, 0x100000 / NX_EMMC_BLOCKSIZE, 0x40000 / NX_EMMC_BLOCKSIZE, pkg1); + const pkg1_id_t *pkg1_id = pkg1_identify(pkg1, build_date); + free(build_date); + if (!pkg1_id) + { + gfx_con.fntsz = 16; + EPRINTF("Unknown pkg1 version."); + goto out_free; + } + + if (pkg1_id->kb >= KB_FIRMWARE_VERSION_700 && !h_cfg.sept_run) + { + sdmmc_storage_end(&storage); + reboot_to_sept((u8 *)pkg1 + pkg1_id->tsec_off, pkg1_id->kb); + } + +out_free: + free(pkg1); + sdmmc_storage_end(&storage); +} + +int reboot_to_sept(const u8 *tsec_fw, u32 kb) +{ + FIL fp; + + // Copy warmboot reboot code and TSEC fw. + u32 tsec_fw_size = 0x3000; + if (kb > KB_FIRMWARE_VERSION_700) + tsec_fw_size = 0x3300; + memcpy((u8 *)(SEPT_PK1T_ADDR - WB_RST_SIZE), (u8 *)warmboot_reboot, sizeof(warmboot_reboot)); + memcpy((void *)SEPT_PK1T_ADDR, tsec_fw, tsec_fw_size); + *(vu32 *)SEPT_TCSZ_ADDR = tsec_fw_size; + + // Copy sept-primary. + if (f_open(&fp, "sept/sept-primary.bin", FA_READ)) + goto error; + + if (f_read(&fp, (u8 *)SEPT_STG1_ADDR, f_size(&fp), NULL)) + { + f_close(&fp); + goto error; + } + f_close(&fp); + + // Copy sept-secondary. + if (kb < KB_FIRMWARE_VERSION_810) + { + if (f_open(&fp, "sept/sept-secondary_00.enc", FA_READ)) + if (f_open(&fp, "sept/sept-secondary.enc", FA_READ)) // Try the deprecated version. + goto error; + } + else + { + if (f_open(&fp, "sept/sept-secondary_01.enc", FA_READ)) + goto error; + } + + if (f_read(&fp, (u8 *)SEPT_STG2_ADDR, f_size(&fp), NULL)) + { + f_close(&fp); + goto error; + } + f_close(&fp); + + b_cfg->boot_cfg |= (BOOT_CFG_AUTOBOOT_EN | BOOT_CFG_SEPT_RUN); + b_cfg->extra_cfg = EXTRA_CFG_NYX_DUMP; + + bool update_sept_payload = true; + if (!f_open(&fp, "sept/payload.bin", FA_READ | FA_WRITE)) + { + ipl_ver_meta_t tmp_ver; + ipl_ver_meta_t heka_ver; + f_lseek(&fp, PATCHED_RELOC_SZ + sizeof(boot_cfg_t)); + f_read(&fp, &tmp_ver, sizeof(ipl_ver_meta_t), NULL); + memcpy(&heka_ver, (u8 *)nyx_str->hekate + 0x118, sizeof(ipl_ver_meta_t)); + + if (tmp_ver.magic == heka_ver.magic) + { + if (tmp_ver.version == heka_ver.version) + { + // Save auto boot config to sept payload, if any. + boot_cfg_t *tmp_cfg = malloc(sizeof(boot_cfg_t)); + memcpy(tmp_cfg, (boot_cfg_t *)b_cfg, sizeof(boot_cfg_t)); + f_lseek(&fp, PATCHED_RELOC_SZ); + f_write(&fp, tmp_cfg, sizeof(boot_cfg_t), NULL); + f_close(&fp); + update_sept_payload = false; + } + } + else + f_rename("sept/payload.bin", "sept/payload.bak"); // Backup foreign payload. + + f_close(&fp); + } + + if (update_sept_payload) + { + volatile reloc_meta_t *reloc = (reloc_meta_t *)(nyx_str->hekate + RELOC_META_OFF); + f_open(&fp, "sept/payload.bin", FA_WRITE | FA_CREATE_ALWAYS); + f_write(&fp, (u8 *)nyx_str->hekate, reloc->end - reloc->start, NULL); + f_close(&fp); + } + + sd_unmount(true); + + u32 pk1t_sept = SEPT_PK1T_ADDR - (ALIGN(PATCHED_RELOC_SZ, 0x10) + WB_RST_SIZE); + + void (*sept)() = (void *)pk1t_sept; + + reloc_patcher(WB_RST_ADDR, pk1t_sept, SEPT_PKG_SZ); + + // Patch SDRAM init to perform an SVC immediately after second write. + PMC(APBDEV_PMC_SCRATCH45) = 0x2E38DFFF; + PMC(APBDEV_PMC_SCRATCH46) = 0x6001DC28; + // Set SVC handler to jump to sept-primary in IRAM. + PMC(APBDEV_PMC_SCRATCH33) = SEPT_PRI_ADDR; + PMC(APBDEV_PMC_SCRATCH40) = 0x6000F208; + + reconfig_hw_workaround(false, 0); + + (*sept)(); + +error: + return 0; +} \ No newline at end of file diff --git a/nyx/nyx_gui/hos/sept.h b/nyx/nyx_gui/hos/sept.h new file mode 100644 index 0000000..7b44c73 --- /dev/null +++ b/nyx/nyx_gui/hos/sept.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _SEPT_H_ +#define _SEPT_H_ + +#include "../utils/types.h" + +void check_sept(); +int reboot_to_sept(const u8 *tsec_fw, u32 kb); + +#endif diff --git a/nyx/nyx_gui/ianos/ianos.c b/nyx/nyx_gui/ianos/ianos.c new file mode 100644 index 0000000..a1fd29e --- /dev/null +++ b/nyx/nyx_gui/ianos/ianos.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2018 M4xw + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "ianos.h" +#include "../utils/types.h" +#include "../libs/elfload/elfload.h" +#include "../../../common/common_module.h" +#include "../mem/heap.h" +#include "../gfx/gfx.h" + +#define IRAM_LIB_ADDR 0x4002B000 +#define DRAM_LIB_ADDR 0xE0000000 + +extern heap_t _heap; + +extern void *sd_file_read(const char *path, u32 *fsize); +extern bool sd_mount(); +extern void sd_unmount(bool deinit); + +void *elfBuf = NULL; +void *fileBuf = NULL; + +static void _ianos_call_ep(moduleEntrypoint_t entrypoint, void *moduleConfig) +{ + bdkParams_t bdkParameters = (bdkParams_t)malloc(sizeof(struct _bdkParams_t)); + bdkParameters->gfxCon = &gfx_con; + bdkParameters->gfxCtx = &gfx_ctxt; + bdkParameters->memcpy = (memcpy_t)&memcpy; + bdkParameters->memset = (memset_t)&memset; + bdkParameters->sharedHeap = &_heap; + + entrypoint(moduleConfig, bdkParameters); +} + +static void *_ianos_alloc_cb(el_ctx *ctx, Elf_Addr phys, Elf_Addr virt, Elf_Addr size) +{ + (void)ctx; + (void)phys; + (void)size; + return (void *)virt; +} + +static bool _ianos_read_cb(el_ctx *ctx, void *dest, size_t numberBytes, size_t offset) +{ + (void)ctx; + + memcpy(dest, fileBuf + offset, numberBytes); + + return true; +} + +//TODO: Support shared libraries. +uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void *moduleConfig) +{ + uintptr_t epaddr = 0; + + if (sdmount) + { + if (!sd_mount()) + goto elfLoadFinalOut; + } + + fileBuf = sd_file_read(path, NULL); + + if (sdmount) + sd_unmount(true); + + if (!fileBuf) + goto elfLoadFinalOut; + + + el_ctx ctx; + ctx.pread = _ianos_read_cb; + + if (el_init(&ctx)) + goto elfLoadFinalOut; + + // Set our relocated library's buffer. + switch (type & 0xFFFF) + { + case EXEC_ELF: + case AR64_ELF: + elfBuf = (void *)DRAM_LIB_ADDR; + sd_unmount(true); + break; + default: + elfBuf = memalign(ctx.align, ctx.memsz); + } + + if (!elfBuf) + goto elfLoadFinalOut; + + // Load and relocate library. + ctx.base_load_vaddr = ctx.base_load_paddr = (uintptr_t)elfBuf; + if (el_load(&ctx, _ianos_alloc_cb)) + goto elfFreeOut; + + if (el_relocate(&ctx)) + goto elfFreeOut; + + // Launch. + epaddr = ctx.ehdr.e_entry + (uintptr_t)elfBuf; + moduleEntrypoint_t ep = (moduleEntrypoint_t)epaddr; + + _ianos_call_ep(ep, moduleConfig); + +elfFreeOut: + free(fileBuf); + elfBuf = NULL; + fileBuf = NULL; + +elfLoadFinalOut: + + return epaddr; +} \ No newline at end of file diff --git a/nyx/nyx_gui/ianos/ianos.h b/nyx/nyx_gui/ianos/ianos.h new file mode 100644 index 0000000..74d02c1 --- /dev/null +++ b/nyx/nyx_gui/ianos/ianos.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018 M4xw + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef IANOS_H +#define IANOS_H + +#include "../utils/types.h" + +typedef enum +{ + DRAM_LIB = 0, // DRAM library. + EXEC_ELF = 1, // Executable elf that does not return. + DR64_LIB = 2, // AARCH64 DRAM library. + AR64_ELF = 3, // Executable elf that does not return. + KEEP_IN_RAM = (1 << 31) // Shared library mask. +} elfType_t; + +uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void* config); + +#endif \ No newline at end of file diff --git a/nyx/nyx_gui/input/als.c b/nyx/nyx_gui/input/als.c new file mode 100644 index 0000000..47aad77 --- /dev/null +++ b/nyx/nyx_gui/input/als.c @@ -0,0 +1,118 @@ +/* + * Ambient light sensor driver for Nintendo Switch's Rohm BH1730 + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "als.h" +#include "../power/max77620.h" +#include "../soc/clock.h" +#include "../soc/i2c.h" +#include "../soc/pinmux.h" +#include "../utils/util.h" + +#define HOS_GAIN BH1730_GAIN_64X +#define HOS_ITIME 38 + +void set_als_cfg(als_table_t *als_val, u8 gain, u8 itime) +{ + i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_GAIN_REG), gain); + i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_TIMING_REG), (256 - itime)); + + als_val->gain = gain; + als_val->itime = itime; +} + +void get_als_lux(als_table_t *als_val) +{ + u32 data[2]; + float pre_gain_lux; + float visible_light; + float ir_light; + float light_ratio; + + u8 adc_ready = 0; + u8 retries = 100; + + const float als_gain_idx_tbl[4] = { 1.0, 2.0, 64.0, 128.0 }; + const float als_norm_res = 100.0; + const float als_multiplier = 3.6; + const float als_tint = 2.7; + + // Wait for ADC to prepare new data. + while (!(adc_ready & BH1730_CTL_ADC_VALID) && retries) + { + retries--; + adc_ready = i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_CONTROL_REG)); + } + + // Get visible and ir light raw data. + data[0] = i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_DATA0LOW_REG)) + + (i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_DATA0HIGH_REG)) << 8); + data[1] = i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_DATA1LOW_REG)) + + (i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_DATA1HIGH_REG)) << 8); + + + als_val->over_limit = data[0] > 65534 || data[1] > 65534; + als_val->vi_light = data[0]; + als_val->ir_light = data[1]; + + if (!data[0] || !retries) + { + als_val->lux = 0.0; + + return; + } + + visible_light = (float)data[0]; + ir_light = (float)data[1]; + light_ratio = (float)data[1] / (float)data[0]; + + // The following are specific to the light filter Switch uses. + if (light_ratio < 0.5) + pre_gain_lux = visible_light * 5.002 - ir_light * 7.502; + else if (light_ratio < 0.754) + pre_gain_lux = visible_light * 2.250 - ir_light * 2.000; + else if (light_ratio < 1.029) + pre_gain_lux = visible_light * 1.999 - ir_light * 1.667; + else if (light_ratio < 1.373) + pre_gain_lux = visible_light * 0.884 - ir_light * 0.583; + else if (light_ratio < 1.879) + pre_gain_lux = visible_light * 0.309 - ir_light * 0.165; + else pre_gain_lux = 0.0; + + als_val->lux = (pre_gain_lux / als_gain_idx_tbl[als_val->gain]) * (als_norm_res / ((float)als_val->itime * als_tint)) * als_multiplier; +} + +u8 als_init(als_table_t *als_val) +{ + pinmux_config_i2c(I2C_2); + clock_enable_i2c(I2C_2); + i2c_init(I2C_2); + + max77620_regulator_set_volt_and_flags(REGULATOR_LDO6, 2900000, MAX77620_POWER_MODE_NORMAL); + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_LDO6_CFG2, 0xD8 | MAX77620_LDO_CFG2_ADE_MASK); + + u8 id = i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(0x12)); + i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_SPEC(BH1730_SPECCMD_RESET), 0); + i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_GAIN_REG), HOS_GAIN); + i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_TIMING_REG), (256 - HOS_ITIME)); + i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_CONTROL_REG), BH1730_CTL_POWER_ON | BH1730_CTL_ADC_EN); + + als_val->gain = HOS_GAIN; + als_val->itime = HOS_ITIME; + + return id; +} diff --git a/nyx/nyx_gui/input/als.h b/nyx/nyx_gui/input/als.h new file mode 100644 index 0000000..11f1e5e --- /dev/null +++ b/nyx/nyx_gui/input/als.h @@ -0,0 +1,65 @@ +/* + * Ambient light sensor driver for Nintendo Switch's Rohm BH1730 + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __ALS_H_ +#define __ALS_H_ + +#include "../utils/types.h" + +#define BH1730_I2C_ADDR 0x29 + +#define BH1730_CMD_MAGIC 0x80 +#define BH1730_CMD_SETADDR 0x00 +#define BH1730_CMD_SPECCMD 0x60 +#define BH1730_SPECCMD_RESET 0x4 + +#define BH1730_CONTROL_REG 0x00 +#define BH1730_CTL_ADC_VALID 0x10 +#define BH1730_CTL_ONE_TIME 0x08 +#define BH1730_CTL_DAT0_ONLY 0x04 +#define BH1730_CTL_ADC_EN 0x02 +#define BH1730_CTL_POWER_ON 0x01 +#define BH1730_TIMING_REG 0x01 +#define BH1730_GAIN_REG 0x07 +#define BH1730_GAIN_1X 0x00 +#define BH1730_GAIN_2X 0x01 +#define BH1730_GAIN_64X 0x02 +#define BH1730_GAIN_128X 0x03 +#define BH1730_DATA0LOW_REG 0x14 +#define BH1730_DATA0HIGH_REG 0x15 +#define BH1730_DATA1LOW_REG 0x16 +#define BH1730_DATA1HIGH_REG 0x17 + +#define BH1730_ADDR(reg) (BH1730_CMD_MAGIC | BH1730_CMD_SETADDR | reg) +#define BH1730_SPEC(cmd) (BH1730_CMD_MAGIC | BH1730_CMD_SPECCMD | cmd) + +typedef struct _als_table_t +{ + float lux; + bool over_limit; + u32 vi_light; + u32 ir_light; + u8 gain; + u8 itime; +} als_table_t; + +void set_als_cfg(als_table_t *als_val, u8 gain, u8 itime); +void get_als_lux(als_table_t *als_val); +u8 als_init(als_table_t *als_val); + +#endif /* __ALS_H_ */ diff --git a/nyx/nyx_gui/input/touch.c b/nyx/nyx_gui/input/touch.c new file mode 100644 index 0000000..eb54c8a --- /dev/null +++ b/nyx/nyx_gui/input/touch.c @@ -0,0 +1,206 @@ +/* + * Touch driver for Nintendo Switch's STMicroelectronics FingerTip touch controller + * + * Copyright (c) 2018 langerhans + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "../soc/clock.h" +#include "../soc/i2c.h" +#include "../soc/pinmux.h" +#include "../power/max7762x.h" +#include "../power/max77620.h" +#include "../soc/gpio.h" +#include "../soc/t210.h" +#include "../utils/util.h" +#include "touch.h" + + +#include "../gfx/gfx.h" +extern gfx_ctxt_t gfx_ctxt; +extern gfx_con_t gfx_con; +#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) + +static int touch_command(u8 cmd) +{ + int err = i2c_send_byte(I2C_3, STMFTS_I2C_ADDR, cmd, 0); + if (!err) + return 1; + + // TODO: Check for completion in event loop + msleep(1); + return 0; +} + +static void _touch_process_contact_event(touch_event *event, bool touching) +{ + event->x = (event->raw[2] << 4) | ((event->raw[4] & STMFTS_MASK_Y_LSB) >> 4); + + // Normally, GUI elements have bigger horizontal estate. + // Avoid parsing y axis when finger is removed to minimize touch noise. + if (touching) + { + event->y = (event->raw[3] << 4) | (event->raw[4] & STMFTS_MASK_X_MSB); + event->z = event->raw[5]; + event->fingers = ((event->raw[1] & STMFTS_MASK_TOUCH_ID) >> 4) + 1; + } + else + event->fingers = 0; +} + +static void _touch_parse_event(touch_event *event) +{ + event->type = event->raw[1] & STMFTS_MASK_EVENT_ID; + + switch (event->type) + { + case STMFTS_EV_MULTI_TOUCH_ENTER: + case STMFTS_EV_MULTI_TOUCH_MOTION: + _touch_process_contact_event(event, true); + if (event->z > 52) // Discard noisy hover touch. + event->touch = true; + else + { + event->touch = false; + event->type = STMFTS_EV_MULTI_TOUCH_LEAVE; + } + break; + case STMFTS_EV_MULTI_TOUCH_LEAVE: + event->touch = false; + _touch_process_contact_event(event, false); + break; + case STMFTS_EV_NO_EVENT: + if (event->touch) + event->type = STMFTS_EV_MULTI_TOUCH_MOTION; + break; + default: + if (event->touch && event->raw[0] == STMFTS_EV_MULTI_TOUCH_MOTION) + event->type = STMFTS_EV_MULTI_TOUCH_MOTION; + else + event->type = STMFTS_EV_MULTI_TOUCH_LEAVE; + } + + // gfx_con_setpos(&gfx_con, 0, 300); + // DPRINTF("x = %d \ny = %d \nz: %d \n", event->x, event->y, event->z); + // DPRINTF("0 = %02X\n1 = %02x\n2 = %02x\n3 = %02x\n", event->raw[0], event->raw[1], event->raw[2], event->raw[3]); + // DPRINTF("4 = %02X\n5 = %02x\n6 = %02x\n7 = %02x\n", event->raw[4], event->raw[5], event->raw[6], event->raw[7]); +} + +void touch_poll(touch_event *event) +{ + i2c_recv_buf_small(event->raw, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_LATEST_EVENT); + + _touch_parse_event(event); +} + +touch_event touch_poll_wait() +{ + touch_event event; + do + { + touch_poll(&event); + } while (event.type != STMFTS_EV_MULTI_TOUCH_LEAVE); + + return event; +} + +touch_info touch_get_info() +{ + touch_info info; + u8 buf[8]; + memset(&buf, 0, 8); + i2c_recv_buf_small(buf, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_READ_INFO); + + info.chip_id = buf[0] << 8 | buf[1]; + info.fw_ver = buf[2] << 8 | buf[3]; + info.config_id = buf[4]; + info.config_ver = buf[5]; + + //DPRINTF("ID: %04X, FW Ver: %d.%02d\nCfg ID: %02x, Cfg Ver: %d\n", + // info.chip_id, info.fw_ver >> 8, info.fw_ver & 0xFF, info.config_id, info.config_ver); + + return info; +} + +int touch_power_on() +{ + // Configure touchscreen GPIO. + PINMUX_AUX(PINMUX_AUX_DAP4_SCLK) = PINMUX_PULL_DOWN | 3; + gpio_config(GPIO_PORT_J, GPIO_PIN_7, GPIO_MODE_GPIO); + gpio_output_enable(GPIO_PORT_J, GPIO_PIN_7, GPIO_OUTPUT_ENABLE); + gpio_write(GPIO_PORT_J, GPIO_PIN_7, GPIO_HIGH); + + // IRQ and more. + // PINMUX_AUX(PINMUX_AUX_TOUCH_INT) = PINMUX_TRISTATE | PINMUX_PULL_UP | 3; + // gpio_config(GPIO_PORT_X, GPIO_PIN_1, GPIO_MODE_GPIO); + // gpio_write(GPIO_PORT_X, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, GPIO_LOW); + + // Configure Touscreen and GCAsic shared GPIO. + PINMUX_AUX(PINMUX_AUX_CAM_I2C_SDA) = PINMUX_TRISTATE | PINMUX_INPUT_ENABLE | PINMUX_PULL_UP | 3; + gpio_config(GPIO_PORT_S, GPIO_PIN_3, GPIO_MODE_GPIO); + + // Initialize I2C3. + pinmux_config_i2c(I2C_3); + clock_enable_i2c(I2C_3); + i2c_init(I2C_3); + + // Enables LDO6 for touchscreen VDD/AVDD supply + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_LDO6_CFG, 0xEA); + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_LDO6_CFG2, 0xDA); + + msleep(20); + + // Initialize touchscreen module. + if (touch_command(STMFTS_SYSTEM_RESET)) + return 0; + + if (touch_command(STMFTS_SLEEP_OUT)) + return 0; + + if (touch_command(STMFTS_MS_CX_TUNING)) + return 0; + + if (touch_command(STMFTS_SS_CX_TUNING)) + return 0; + + if (touch_command(STMFTS_FULL_FORCE_CALIBRATION)) + return 0; + + if (touch_command(STMFTS_MS_MT_SENSE_ON)) + return 0; + + if (touch_command(STMFTS_SS_HOVER_SENSE_OFF)) + return 0; + + return 1; +} + +void touch_power_off() +{ + touch_command(STMFTS_SLEEP_IN); + + // Disables LDO6 for touchscreen VDD, AVDD supply + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_LDO6_CFG, 0x28); + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_LDO6_CFG2, 0xD2); + + clock_disable_i2c(I2C_3); + + // Disable touchscreen power. + gpio_write(GPIO_PORT_J, GPIO_PIN_7, GPIO_LOW); + + pinmux_config_i2c(I2C_3); +} \ No newline at end of file diff --git a/nyx/nyx_gui/input/touch.h b/nyx/nyx_gui/input/touch.h new file mode 100644 index 0000000..2fdff35 --- /dev/null +++ b/nyx/nyx_gui/input/touch.h @@ -0,0 +1,115 @@ +/* + * Touch driver for Nintendo Switch's STMicroelectronics FingerTip S touch controller + * + * Copyright (c) 2018 langerhans + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __TOUCH_H_ +#define __TOUCH_H_ + +#include "../utils/types.h" + +#define STMFTS_I2C_ADDR 0x49 + +/* I2C commands */ +#define STMFTS_READ_INFO 0x80 +#define STMFTS_READ_STATUS 0x84 +#define STMFTS_READ_ONE_EVENT 0x85 +#define STMFTS_READ_ALL_EVENT 0x86 +#define STMFTS_LATEST_EVENT 0x87 +#define STMFTS_SLEEP_IN 0x90 +#define STMFTS_SLEEP_OUT 0x91 +#define STMFTS_MS_MT_SENSE_OFF 0x92 +#define STMFTS_MS_MT_SENSE_ON 0x93 +#define STMFTS_SS_HOVER_SENSE_OFF 0x94 +#define STMFTS_SS_HOVER_SENSE_ON 0x95 +#define STMFTS_MS_KEY_SENSE_OFF 0x9A +#define STMFTS_MS_KEY_SENSE_ON 0x9B +#define STMFTS_SYSTEM_RESET 0xA0 +#define STMFTS_CLEAR_EVENT_STACK 0xA1 +#define STMFTS_FULL_FORCE_CALIBRATION 0xA2 +#define STMFTS_MS_CX_TUNING 0xA3 +#define STMFTS_SS_CX_TUNING 0xA4 +#define STMFTS_RELEASEINFO 0xAA +#define STMFTS_WRITE_REG 0xB6 +#define STMFTS_RW_FB_REG 0xD0 // read data + +#define STMFTS_UNK0 0xB8 //Request compensation +#define STMFTS_UNK1 0xCF +#define STMFTS_UNK2 0xF7 +#define STMFTS_UNK3 0xFA +#define STMFTS_UNK4 0xF9 +#define STMFTS_UNK5 0x62 + + +/* events */ +#define STMFTS_EV_NO_EVENT 0x00 +#define STMFTS_EV_MULTI_TOUCH_DETECTED 0x02 +#define STMFTS_EV_MULTI_TOUCH_ENTER 0x03 +#define STMFTS_EV_MULTI_TOUCH_LEAVE 0x04 +#define STMFTS_EV_MULTI_TOUCH_MOTION 0x05 +#define STMFTS_EV_HOVER_ENTER 0x07 +#define STMFTS_EV_HOVER_LEAVE 0x08 +#define STMFTS_EV_HOVER_MOTION 0x09 +#define STMFTS_EV_KEY_STATUS 0x0e +#define STMFTS_EV_ERROR 0x0f + +#define STMFTS_EV_CONTROLLER_READY 0x10 +#define STMFTS_EV_SLEEP_OUT_CONTROLLER_READY 0x11 +#define STMFTS_EV_STATUS 0x16 +#define STMFTS_EV_DEBUG 0xDB + +/* multi touch related event masks */ +#define STMFTS_MASK_EVENT_ID 0x0F +#define STMFTS_MASK_TOUCH_ID 0xF0 +#define STMFTS_MASK_LEFT_EVENT 0x0F +#define STMFTS_MASK_X_MSB 0x0F +#define STMFTS_MASK_Y_LSB 0xF0 + +/* key related event masks */ +#define STMFTS_MASK_KEY_NO_TOUCH 0x00 +#define STMFTS_MASK_KEY_MENU 0x01 +#define STMFTS_MASK_KEY_BACK 0x02 + +#define STMFTS_EVENT_SIZE 8 +#define STMFTS_STACK_DEPTH 32 +#define STMFTS_DATA_MAX_SIZE (STMFTS_EVENT_SIZE * STMFTS_STACK_DEPTH) +#define STMFTS_MAX_FINGERS 10 + +typedef struct _touch_event { + u8 raw[8]; + u16 type; // Event type. + u16 x; // Horizontal coordinates. + u16 y; // Vertical coordinates. + u8 z; + u8 fingers; + bool touch; +} touch_event; + +typedef struct _touch_info { + u16 chip_id; + u16 fw_ver; + u16 config_id; + u16 config_ver; +} touch_info; + +int touch_power_on(); +void touch_power_off(); +void touch_poll(touch_event *event); +touch_event touch_poll_wait(); +touch_info touch_get_info(); + +#endif /* __TOUCH_H_ */ \ No newline at end of file diff --git a/nyx/nyx_gui/libs/compr/blz.c b/nyx/nyx_gui/libs/compr/blz.c new file mode 100644 index 0000000..487fa26 --- /dev/null +++ b/nyx/nyx_gui/libs/compr/blz.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2018 rajkosto + * Copyright (c) 2018 SciresM + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "blz.h" + +const blz_footer *blz_get_footer(const unsigned char *compData, unsigned int compDataLen, blz_footer *outFooter) +{ + if (compDataLen < sizeof(blz_footer)) + return NULL; + + const blz_footer *srcFooter = (const blz_footer*)&compData[compDataLen - sizeof(blz_footer)]; + if (outFooter != NULL) + memcpy(outFooter, srcFooter, sizeof(blz_footer)); // Must be a memcpy because no umaligned accesses on ARMv4. + + return srcFooter; +} + +// From https://github.com/SciresM/hactool/blob/master/kip.c which is exactly how kernel does it, thanks SciresM! +int blz_uncompress_inplace(unsigned char *dataBuf, unsigned int compSize, const blz_footer *footer) +{ + u32 addl_size = footer->addl_size; + u32 header_size = footer->header_size; + u32 cmp_and_hdr_size = footer->cmp_and_hdr_size; + + unsigned char* cmp_start = &dataBuf[compSize] - cmp_and_hdr_size; + u32 cmp_ofs = cmp_and_hdr_size - header_size; + u32 out_ofs = cmp_and_hdr_size + addl_size; + + while (out_ofs) + { + unsigned char control = cmp_start[--cmp_ofs]; + for (unsigned int i=0; i<8; i++) + { + if (control & 0x80) + { + if (cmp_ofs < 2) + return 0; // Out of bounds. + + cmp_ofs -= 2; + u16 seg_val = ((unsigned int)(cmp_start[cmp_ofs + 1]) << 8) | cmp_start[cmp_ofs]; + u32 seg_size = ((seg_val >> 12) & 0xF) + 3; + u32 seg_ofs = (seg_val & 0x0FFF) + 3; + if (out_ofs < seg_size) // Kernel restricts segment copy to stay in bounds. + seg_size = out_ofs; + + out_ofs -= seg_size; + + for (unsigned int j = 0; j < seg_size; j++) + cmp_start[out_ofs + j] = cmp_start[out_ofs + j + seg_ofs]; + } + else + { + // Copy directly. + if (cmp_ofs < 1) + return 0; //out of bounds + + cmp_start[--out_ofs] = cmp_start[--cmp_ofs]; + } + control <<= 1; + if (out_ofs == 0) // Blz works backwards, so if it reaches byte 0, it's done. + return 1; + } + } + + return 1; +} + +int blz_uncompress_srcdest(const unsigned char *compData, unsigned int compDataLen, unsigned char *dstData, unsigned int dstSize) +{ + blz_footer footer; + const blz_footer *compFooterPtr = blz_get_footer(compData, compDataLen, &footer); + if (compFooterPtr == NULL) + return 0; + + // Decompression must be done in-place, so need to copy the relevant compressed data first. + unsigned int numCompBytes = (const unsigned char*)(compFooterPtr)-compData; + memcpy(dstData, compData, numCompBytes); + memset(&dstData[numCompBytes], 0, dstSize - numCompBytes); + + return blz_uncompress_inplace(dstData, compDataLen, &footer); +} \ No newline at end of file diff --git a/nyx/nyx_gui/libs/compr/blz.h b/nyx/nyx_gui/libs/compr/blz.h new file mode 100644 index 0000000..3c17f8d --- /dev/null +++ b/nyx/nyx_gui/libs/compr/blz.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018 rajkosto + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _BLZ_H_ +#define _BLZ_H_ + +#include "../../utils/types.h" + +typedef struct _blz_footer +{ + u32 cmp_and_hdr_size; + u32 header_size; + u32 addl_size; +} blz_footer; + +// Returns pointer to footer in compData if present, additionally copies it to outFooter if not NULL. +const blz_footer *blz_get_footer(const unsigned char *compData, unsigned int compDataLen, blz_footer *outFooter); +// Returns 0 on failure. +int blz_uncompress_inplace(unsigned char *dataBuf, unsigned int compSize, const blz_footer *footer); +// Returns 0 on failure. +int blz_uncompress_srcdest(const unsigned char *compData, unsigned int compDataLen, unsigned char *dstData, unsigned int dstSize); + +#endif \ No newline at end of file diff --git a/nyx/nyx_gui/libs/compr/lz.c b/nyx/nyx_gui/libs/compr/lz.c new file mode 100644 index 0000000..a17c6e4 --- /dev/null +++ b/nyx/nyx_gui/libs/compr/lz.c @@ -0,0 +1,179 @@ +/************************************************************************* +* Name: lz.c +* Author: Marcus Geelnard +* Description: LZ77 coder/decoder implementation. +* Reentrant: Yes +* +* The LZ77 compression scheme is a substitutional compression scheme +* proposed by Abraham Lempel and Jakob Ziv in 1977. It is very simple in +* its design, and uses no fancy bit level compression. +* +* This is my first attempt at an implementation of a LZ77 code/decoder. +* +* The principle of the LZ77 compression algorithm is to store repeated +* occurrences of strings as references to previous occurrences of the same +* string. The point is that the reference consumes less space than the +* string itself, provided that the string is long enough (in this +* implementation, the string has to be at least 4 bytes long, since the +* minimum coded reference is 3 bytes long). Also note that the term +* "string" refers to any kind of byte sequence (it does not have to be +* an ASCII string, for instance). +* +* The coder uses a brute force approach to finding string matches in the +* history buffer (or "sliding window", if you wish), which is very, very +* slow. I recon the complexity is somewhere between O(n^2) and O(n^3), +* depending on the input data. +* +* There is also a faster implementation that uses a large working buffer +* in which a "jump table" is stored, which is used to quickly find +* possible string matches (see the source code for LZ_CompressFast() for +* more information). The faster method is an order of magnitude faster, +* but still quite slow compared to other compression methods. +* +* The upside is that decompression is very fast, and the compression ratio +* is often very good. +* +* The reference to a string is coded as a (length,offset) pair, where the +* length indicates the length of the string, and the offset gives the +* offset from the current data position. To distinguish between string +* references and literal strings (uncompressed bytes), a string reference +* is preceded by a marker byte, which is chosen as the least common byte +* symbol in the input data stream (this marker byte is stored in the +* output stream as the first byte). +* +* Occurrences of the marker byte in the stream are encoded as the marker +* byte followed by a zero byte, which means that occurrences of the marker +* byte have to be coded with two bytes. +* +* The lengths and offsets are coded in a variable length fashion, allowing +* values of any magnitude (up to 4294967295 in this implementation). +* +* With this compression scheme, the worst case compression result is +* (257/256)*insize + 1. +* +*------------------------------------------------------------------------- +* Copyright (c) 2003-2006 Marcus Geelnard +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would +* be appreciated but is not required. +* +* 2. Altered source versions must be plainly marked as such, and must not +* be misrepresented as being the original software. +* +* 3. This notice may not be removed or altered from any source +* distribution. +* +* Marcus Geelnard +* marcus.geelnard at home.se +*************************************************************************/ + + +/************************************************************************* +* INTERNAL FUNCTIONS * +*************************************************************************/ + + +/************************************************************************* +* _LZ_ReadVarSize() - Read unsigned integer with variable number of +* bytes depending on value. +*************************************************************************/ + +static int _LZ_ReadVarSize( unsigned int * x, const unsigned char * buf ) +{ + unsigned int y, b, num_bytes; + + /* Read complete value (stop when byte contains zero in 8:th bit) */ + y = 0; + num_bytes = 0; + do + { + b = (unsigned int) (*buf ++); + y = (y << 7) | (b & 0x0000007f); + ++ num_bytes; + } + while( b & 0x00000080 ); + + /* Store value in x */ + *x = y; + + /* Return number of bytes read */ + return num_bytes; +} + + + +/************************************************************************* +* PUBLIC FUNCTIONS * +*************************************************************************/ + + +/************************************************************************* +* LZ_Uncompress() - Uncompress a block of data using an LZ77 decoder. +* in - Input (compressed) buffer. +* out - Output (uncompressed) buffer. This buffer must be large +* enough to hold the uncompressed data. +* insize - Number of input bytes. +*************************************************************************/ + +void LZ_Uncompress( const unsigned char *in, unsigned char *out, + unsigned int insize ) +{ + unsigned char marker, symbol; + unsigned int i, inpos, outpos, length, offset; + + /* Do we have anything to uncompress? */ + if( insize < 1 ) + { + return; + } + + /* Get marker symbol from input stream */ + marker = in[ 0 ]; + inpos = 1; + + /* Main decompression loop */ + outpos = 0; + do + { + symbol = in[ inpos ++ ]; + if( symbol == marker ) + { + /* We had a marker byte */ + if( in[ inpos ] == 0 ) + { + /* It was a single occurrence of the marker byte */ + out[ outpos ++ ] = marker; + ++ inpos; + } + else + { + /* Extract true length and offset */ + inpos += _LZ_ReadVarSize( &length, &in[ inpos ] ); + inpos += _LZ_ReadVarSize( &offset, &in[ inpos ] ); + + /* Copy corresponding data from history window */ + for( i = 0; i < length; ++ i ) + { + out[ outpos ] = out[ outpos - offset ]; + ++ outpos; + } + } + } + else + { + /* No marker, plain copy */ + out[ outpos ++ ] = symbol; + } + } + while( inpos < insize ); +} diff --git a/nyx/nyx_gui/libs/compr/lz.h b/nyx/nyx_gui/libs/compr/lz.h new file mode 100644 index 0000000..6f31b4a --- /dev/null +++ b/nyx/nyx_gui/libs/compr/lz.h @@ -0,0 +1,52 @@ +/************************************************************************* +* Name: lz.h +* Author: Marcus Geelnard +* Description: LZ77 coder/decoder interface. +* Reentrant: Yes +*------------------------------------------------------------------------- +* Copyright (c) 2003-2006 Marcus Geelnard +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would +* be appreciated but is not required. +* +* 2. Altered source versions must be plainly marked as such, and must not +* be misrepresented as being the original software. +* +* 3. This notice may not be removed or altered from any source +* distribution. +* +* Marcus Geelnard +* marcus.geelnard at home.se +*************************************************************************/ + +#ifndef _lz_h_ +#define _lz_h_ + +#ifdef __cplusplus +extern "C" { +#endif + + +/************************************************************************* +* Function prototypes +*************************************************************************/ + +void LZ_Uncompress( const unsigned char *in, unsigned char *out, + unsigned int insize ); + + +#ifdef __cplusplus +} +#endif + +#endif /* _lz_h_ */ diff --git a/nyx/nyx_gui/libs/elfload/elf.h b/nyx/nyx_gui/libs/elfload/elf.h new file mode 100644 index 0000000..196cf87 --- /dev/null +++ b/nyx/nyx_gui/libs/elfload/elf.h @@ -0,0 +1,589 @@ +/* $OpenBSD: exec_elf.h,v 1.53 2014/01/03 03:00:39 guenther Exp $ */ +/* + * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* imported sys/exec_elf.h from OpenBSD */ + +#ifndef ELF_H +#define ELF_H +#include + +typedef uint8_t Elf_Byte; + +typedef uint32_t Elf32_Addr; /* Unsigned program address */ +typedef uint32_t Elf32_Off; /* Unsigned file offset */ +typedef int32_t Elf32_Sword; /* Signed large integer */ +typedef uint32_t Elf32_Word; /* Unsigned large integer */ +typedef uint16_t Elf32_Half; /* Unsigned medium integer */ + +typedef uint64_t Elf64_Addr; +typedef uint64_t Elf64_Off; +typedef int32_t Elf64_Shalf; + +#ifdef __alpha__ +typedef int64_t Elf64_Sword; +typedef uint64_t Elf64_Word; +#else +typedef int32_t Elf64_Sword; +typedef uint32_t Elf64_Word; +#endif + +typedef int64_t Elf64_Sxword; +typedef uint64_t Elf64_Xword; + +typedef uint32_t Elf64_Half; +typedef uint16_t Elf64_Quarter; + +/* + * e_ident[] identification indexes + * See http://www.sco.com/developers/gabi/latest/ch4.eheader.html + */ +#define EI_MAG0 0 /* file ID */ +#define EI_MAG1 1 /* file ID */ +#define EI_MAG2 2 /* file ID */ +#define EI_MAG3 3 /* file ID */ +#define EI_CLASS 4 /* file class */ +#define EI_DATA 5 /* data encoding */ +#define EI_VERSION 6 /* ELF header version */ +#define EI_OSABI 7 /* OS/ABI ID */ +#define EI_ABIVERSION 8 /* ABI version */ +#define EI_PAD 9 /* start of pad bytes */ +#define EI_NIDENT 16 /* Size of e_ident[] */ + +/* e_ident[] magic number */ +#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ +#define ELFMAG1 'E' /* e_ident[EI_MAG1] */ +#define ELFMAG2 'L' /* e_ident[EI_MAG2] */ +#define ELFMAG3 'F' /* e_ident[EI_MAG3] */ +#define ELFMAG "\177ELF" /* magic */ +#define SELFMAG 4 /* size of magic */ + +/* e_ident[] file class */ +#define ELFCLASSNONE 0 /* invalid */ +#define ELFCLASS32 1 /* 32-bit objs */ +#define ELFCLASS64 2 /* 64-bit objs */ +#define ELFCLASSNUM 3 /* number of classes */ + +/* e_ident[] data encoding */ +#define ELFDATANONE 0 /* invalid */ +#define ELFDATA2LSB 1 /* Little-Endian */ +#define ELFDATA2MSB 2 /* Big-Endian */ +#define ELFDATANUM 3 /* number of data encode defines */ + +/* e_ident[] Operating System/ABI */ +#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ +#define ELFOSABI_HPUX 1 /* HP-UX operating system */ +#define ELFOSABI_NETBSD 2 /* NetBSD */ +#define ELFOSABI_LINUX 3 /* GNU/Linux */ +#define ELFOSABI_HURD 4 /* GNU/Hurd */ +#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ +#define ELFOSABI_SOLARIS 6 /* Solaris */ +#define ELFOSABI_MONTEREY 7 /* Monterey */ +#define ELFOSABI_IRIX 8 /* IRIX */ +#define ELFOSABI_FREEBSD 9 /* FreeBSD */ +#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ +#define ELFOSABI_MODESTO 11 /* Novell Modesto */ +#define ELFOSABI_OPENBSD 12 /* OpenBSD */ +#define ELFOSABI_ARM 97 /* ARM */ +#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ + +/* e_ident */ +#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ + (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ + (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ + (ehdr).e_ident[EI_MAG3] == ELFMAG3) + +/* ELF Header */ +typedef struct +{ + unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ + Elf32_Half e_type; /* object file type */ + Elf32_Half e_machine; /* machine */ + Elf32_Word e_version; /* object file version */ + Elf32_Addr e_entry; /* virtual entry point */ + Elf32_Off e_phoff; /* program header table offset */ + Elf32_Off e_shoff; /* section header table offset */ + Elf32_Word e_flags; /* processor-specific flags */ + Elf32_Half e_ehsize; /* ELF header size */ + Elf32_Half e_phentsize; /* program header entry size */ + Elf32_Half e_phnum; /* number of program header entries */ + Elf32_Half e_shentsize; /* section header entry size */ + Elf32_Half e_shnum; /* number of section header entries */ + Elf32_Half e_shstrndx; /* section header table's "section + header string table" entry offset */ +} Elf32_Ehdr; + +typedef struct +{ + unsigned char e_ident[EI_NIDENT]; /* Id bytes */ + Elf64_Quarter e_type; /* file type */ + Elf64_Quarter e_machine; /* machine type */ + Elf64_Half e_version; /* version number */ + Elf64_Addr e_entry; /* entry point */ + Elf64_Off e_phoff; /* Program hdr offset */ + Elf64_Off e_shoff; /* Section hdr offset */ + Elf64_Half e_flags; /* Processor flags */ + Elf64_Quarter e_ehsize; /* sizeof ehdr */ + Elf64_Quarter e_phentsize; /* Program header entry size */ + Elf64_Quarter e_phnum; /* Number of program headers */ + Elf64_Quarter e_shentsize; /* Section header entry size */ + Elf64_Quarter e_shnum; /* Number of section headers */ + Elf64_Quarter e_shstrndx; /* String table index */ +} Elf64_Ehdr; + +/* e_type */ +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* relocatable file */ +#define ET_EXEC 2 /* executable file */ +#define ET_DYN 3 /* shared object file */ +#define ET_CORE 4 /* core file */ +#define ET_NUM 5 /* number of types */ +#define ET_LOPROC 0xff00 /* reserved range for processor */ +#define ET_HIPROC 0xffff /* specific e_type */ + +/* e_machine */ +#define EM_NONE 0 /* No Machine */ +#define EM_M32 1 /* AT&T WE 32100 */ +#define EM_SPARC 2 /* SPARC */ +#define EM_386 3 /* Intel 80386 */ +#define EM_68K 4 /* Motorola 68000 */ +#define EM_88K 5 /* Motorola 88000 */ +#define EM_486 6 /* Intel 80486 - unused? */ +#define EM_860 7 /* Intel 80860 */ +#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ +/* + * Don't know if EM_MIPS_RS4_BE, + * EM_SPARC64, EM_PARISC, + * or EM_PPC are ABI compliant + */ +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ +#define EM_SPARC64 11 /* SPARC v9 64-bit unofficial */ +#define EM_PARISC 15 /* HPPA */ +#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ +#define EM_PPC 20 /* PowerPC */ +#define EM_ARM 40 /* ARM AArch32 */ +#define EM_ALPHA 41 /* DEC ALPHA */ +#define EM_SH 42 /* Hitachi/Renesas Super-H */ +#define EM_SPARCV9 43 /* SPARC version 9 */ +#define EM_IA_64 50 /* Intel IA-64 Processor */ +#define EM_AMD64 62 /* AMD64 architecture */ +#define EM_VAX 75 /* DEC VAX */ +#define EM_AARCH64 183 /* ARM AArch64 */ + +/* Non-standard */ +#define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */ + +/* Version */ +#define EV_NONE 0 /* Invalid */ +#define EV_CURRENT 1 /* Current */ +#define EV_NUM 2 /* number of versions */ + +/* Section Header */ +typedef struct +{ + Elf32_Word sh_name; /* name - index into section header + * string table section */ + Elf32_Word sh_type; /* type */ + Elf32_Word sh_flags; /* flags */ + Elf32_Addr sh_addr; /* address */ + Elf32_Off sh_offset; /* file offset */ + Elf32_Word sh_size; /* section size */ + Elf32_Word sh_link; /* section header table index link */ + Elf32_Word sh_info; /* extra information */ + Elf32_Word sh_addralign; /* address alignment */ + Elf32_Word sh_entsize; /* section entry size */ +} Elf32_Shdr; + +typedef struct +{ + Elf64_Half sh_name; /* section name */ + Elf64_Half sh_type; /* section type */ + Elf64_Xword sh_flags; /* section flags */ + Elf64_Addr sh_addr; /* virtual address */ + Elf64_Off sh_offset; /* file offset */ + Elf64_Xword sh_size; /* section size */ + Elf64_Half sh_link; /* link to another */ + Elf64_Half sh_info; /* misc info */ + Elf64_Xword sh_addralign; /* memory alignment */ + Elf64_Xword sh_entsize; /* table entry size */ +} Elf64_Shdr; + +/* Special Section Indexes */ +#define SHN_UNDEF 0 /* undefined */ +#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ +#define SHN_LOPROC 0xff00 /* reserved range for processor */ +#define SHN_HIPROC 0xff1f /* specific section indexes */ +#define SHN_ABS 0xfff1 /* absolute value */ +#define SHN_COMMON 0xfff2 /* common symbol */ +#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ + +/* sh_type */ +#define SHT_NULL 0 /* inactive */ +#define SHT_PROGBITS 1 /* program defined information */ +#define SHT_SYMTAB 2 /* symbol table section */ +#define SHT_STRTAB 3 /* string table section */ +#define SHT_RELA 4 /* relocation section with addends*/ +#define SHT_HASH 5 /* symbol hash table section */ +#define SHT_DYNAMIC 6 /* dynamic section */ +#define SHT_NOTE 7 /* note section */ +#define SHT_NOBITS 8 /* no space section */ +#define SHT_REL 9 /* relation section without addends */ +#define SHT_SHLIB 10 /* reserved - purpose unknown */ +#define SHT_DYNSYM 11 /* dynamic symbol table section */ +#define SHT_NUM 12 /* number of section types */ +#define SHT_LOPROC 0x70000000 /* reserved range for processor */ +#define SHT_HIPROC 0x7fffffff /* specific section header types */ +#define SHT_LOUSER 0x80000000 /* reserved range for application */ +#define SHT_HIUSER 0xffffffff /* specific indexes */ + +/* Section names */ +#define ELF_BSS ".bss" /* uninitialized data */ +#define ELF_DATA ".data" /* initialized data */ +#define ELF_DEBUG ".debug" /* debug */ +#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ +#define ELF_DYNSTR ".dynstr" /* dynamic string table */ +#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ +#define ELF_FINI ".fini" /* termination code */ +#define ELF_GOT ".got" /* global offset table */ +#define ELF_HASH ".hash" /* symbol hash table */ +#define ELF_INIT ".init" /* initialization code */ +#define ELF_REL_DATA ".rel.data" /* relocation data */ +#define ELF_REL_FINI ".rel.fini" /* relocation termination code */ +#define ELF_REL_INIT ".rel.init" /* relocation initialization code */ +#define ELF_REL_DYN ".rel.dyn" /* relocation dynamic link info */ +#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ +#define ELF_REL_TEXT ".rel.text" /* relocation code */ +#define ELF_RODATA ".rodata" /* read-only data */ +#define ELF_SHSTRTAB ".shstrtab" /* section header string table */ +#define ELF_STRTAB ".strtab" /* string table */ +#define ELF_SYMTAB ".symtab" /* symbol table */ +#define ELF_TEXT ".text" /* code */ + +/* Section Attribute Flags - sh_flags */ +#define SHF_WRITE 0x1 /* Writable */ +#define SHF_ALLOC 0x2 /* occupies memory */ +#define SHF_EXECINSTR 0x4 /* executable */ +#define SHF_TLS 0x400 /* thread local storage */ +#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor \ + * specific section attributes */ + +/* Symbol Table Entry */ +typedef struct elf32_sym +{ + Elf32_Word st_name; /* name - index into string table */ + Elf32_Addr st_value; /* symbol value */ + Elf32_Word st_size; /* symbol size */ + unsigned char st_info; /* type and binding */ + unsigned char st_other; /* 0 - no defined meaning */ + Elf32_Half st_shndx; /* section header index */ +} Elf32_Sym; + +typedef struct +{ + Elf64_Half st_name; /* Symbol name index in str table */ + Elf_Byte st_info; /* type / binding attrs */ + Elf_Byte st_other; /* unused */ + Elf64_Quarter st_shndx; /* section index of symbol */ + Elf64_Xword st_value; /* value of symbol */ + Elf64_Xword st_size; /* size of symbol */ +} Elf64_Sym; + +/* Symbol table index */ +#define STN_UNDEF 0 /* undefined */ + +/* Extract symbol info - st_info */ +#define ELF32_ST_BIND(x) ((x) >> 4) +#define ELF32_ST_TYPE(x) (((unsigned int)x) & 0xf) +#define ELF32_ST_INFO(b, t) (((b) << 4) + ((t)&0xf)) + +#define ELF64_ST_BIND(x) ((x) >> 4) +#define ELF64_ST_TYPE(x) (((unsigned int)x) & 0xf) +#define ELF64_ST_INFO(b, t) (((b) << 4) + ((t)&0xf)) + +/* Symbol Binding - ELF32_ST_BIND - st_info */ +#define STB_LOCAL 0 /* Local symbol */ +#define STB_GLOBAL 1 /* Global symbol */ +#define STB_WEAK 2 /* like global - lower precedence */ +#define STB_NUM 3 /* number of symbol bindings */ +#define STB_LOPROC 13 /* reserved range for processor */ +#define STB_HIPROC 15 /* specific symbol bindings */ + +/* Symbol type - ELF32_ST_TYPE - st_info */ +#define STT_NOTYPE 0 /* not specified */ +#define STT_OBJECT 1 /* data object */ +#define STT_FUNC 2 /* function */ +#define STT_SECTION 3 /* section */ +#define STT_FILE 4 /* file */ +#define STT_TLS 6 /* thread local storage */ +#define STT_LOPROC 13 /* reserved range for processor */ +#define STT_HIPROC 15 /* specific symbol types */ + +/* Relocation entry with implicit addend */ +typedef struct +{ + Elf32_Addr r_offset; /* offset of relocation */ + Elf32_Word r_info; /* symbol table index and type */ +} Elf32_Rel; + +/* Relocation entry with explicit addend */ +typedef struct +{ + Elf32_Addr r_offset; /* offset of relocation */ + Elf32_Word r_info; /* symbol table index and type */ + Elf32_Sword r_addend; +} Elf32_Rela; + +/* Extract relocation info - r_info */ +#define ELF32_R_SYM(i) ((i) >> 8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s, t) (((s) << 8) + (unsigned char)(t)) + +typedef struct +{ + Elf64_Xword r_offset; /* where to do it */ + Elf64_Xword r_info; /* index & type of relocation */ +} Elf64_Rel; + +typedef struct +{ + Elf64_Xword r_offset; /* where to do it */ + Elf64_Xword r_info; /* index & type of relocation */ + Elf64_Sxword r_addend; /* adjustment value */ +} Elf64_Rela; + +#define ELF64_R_SYM(info) ((info) >> 32) +#define ELF64_R_TYPE(info) ((info)&0xFFFFFFFF) +#define ELF64_R_INFO(s, t) (((s) << 32) + (__uint32_t)(t)) + +#if defined(__mips64__) && defined(__MIPSEL__) +/* + * The 64-bit MIPS ELF ABI uses a slightly different relocation format + * than the regular ELF ABI: the r_info field is split into several + * pieces (see gnu/usr.bin/binutils/include/elf/mips.h for details). + */ +#undef ELF64_R_SYM +#undef ELF64_R_TYPE +#undef ELF64_R_INFO +#define ELF64_R_TYPE(info) (swap32((info) >> 32)) +#define ELF64_R_SYM(info) ((info)&0xFFFFFFFF) +#define ELF64_R_INFO(s, t) (((__uint64_t)swap32(t) << 32) + (__uint32_t)(s)) +#endif /* __mips64__ && __MIPSEL__ */ + +/* Program Header */ +typedef struct +{ + Elf32_Word p_type; /* segment type */ + Elf32_Off p_offset; /* segment offset */ + Elf32_Addr p_vaddr; /* virtual address of segment */ + Elf32_Addr p_paddr; /* physical address - ignored? */ + Elf32_Word p_filesz; /* number of bytes in file for seg. */ + Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ + Elf32_Word p_flags; /* flags */ + Elf32_Word p_align; /* memory alignment */ +} Elf32_Phdr; + +typedef struct +{ + Elf64_Half p_type; /* entry type */ + Elf64_Half p_flags; /* flags */ + Elf64_Off p_offset; /* offset */ + Elf64_Addr p_vaddr; /* virtual address */ + Elf64_Addr p_paddr; /* physical address */ + Elf64_Xword p_filesz; /* file size */ + Elf64_Xword p_memsz; /* memory size */ + Elf64_Xword p_align; /* memory & file alignment */ +} Elf64_Phdr; + +/* Segment types - p_type */ +#define PT_NULL 0 /* unused */ +#define PT_LOAD 1 /* loadable segment */ +#define PT_DYNAMIC 2 /* dynamic linking section */ +#define PT_INTERP 3 /* the RTLD */ +#define PT_NOTE 4 /* auxiliary information */ +#define PT_SHLIB 5 /* reserved - purpose undefined */ +#define PT_PHDR 6 /* program header */ +#define PT_TLS 7 /* thread local storage */ +#define PT_LOOS 0x60000000 /* reserved range for OS */ +#define PT_HIOS 0x6fffffff /* specific segment types */ +#define PT_LOPROC 0x70000000 /* reserved range for processor */ +#define PT_HIPROC 0x7fffffff /* specific segment types */ + +#define PT_OPENBSD_RANDOMIZE 0x65a3dbe6 /* fill with random data */ +#define PT_GANDR_KERNEL 0x67646b6c /* gdkl */ + +/* Segment flags - p_flags */ +#define PF_X 0x1 /* Executable */ +#define PF_W 0x2 /* Writable */ +#define PF_R 0x4 /* Readable */ +#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ + /* specific segment flags */ + +/* Dynamic structure */ +typedef struct +{ + Elf32_Sword d_tag; /* controls meaning of d_val */ + union { + Elf32_Word d_val; /* Multiple meanings - see d_tag */ + Elf32_Addr d_ptr; /* program virtual address */ + } d_un; +} Elf32_Dyn; + +typedef struct +{ + Elf64_Xword d_tag; /* controls meaning of d_val */ + union { + Elf64_Addr d_ptr; + Elf64_Xword d_val; + } d_un; +} Elf64_Dyn; + +/* Dynamic Array Tags - d_tag */ +#define DT_NULL 0 /* marks end of _DYNAMIC array */ +#define DT_NEEDED 1 /* string table offset of needed lib */ +#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ +#define DT_PLTGOT 3 /* address PLT/GOT */ +#define DT_HASH 4 /* address of symbol hash table */ +#define DT_STRTAB 5 /* address of string table */ +#define DT_SYMTAB 6 /* address of symbol table */ +#define DT_RELA 7 /* address of relocation table */ +#define DT_RELASZ 8 /* size of relocation table */ +#define DT_RELAENT 9 /* size of relocation entry */ +#define DT_STRSZ 10 /* size of string table */ +#define DT_SYMENT 11 /* size of symbol table entry */ +#define DT_INIT 12 /* address of initialization func. */ +#define DT_FINI 13 /* address of termination function */ +#define DT_SONAME 14 /* string table offset of shared obj */ +#define DT_RPATH 15 /* string table offset of library \ + * search path */ +#define DT_SYMBOLIC 16 /* start sym search in shared obj. */ +#define DT_REL 17 /* address of rel. tbl. w addends */ +#define DT_RELSZ 18 /* size of DT_REL relocation table */ +#define DT_RELENT 19 /* size of DT_REL relocation entry */ +#define DT_PLTREL 20 /* PLT referenced relocation entry */ +#define DT_DEBUG 21 /* bugger */ +#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ +#define DT_JMPREL 23 /* add. of PLT's relocation entries */ +#define DT_BIND_NOW 24 /* Bind now regardless of env setting */ +#define DT_LOOS 0x6000000d /* reserved range for OS */ +#define DT_HIOS 0x6ffff000 /* specific dynamic array tags */ +#define DT_LOPROC 0x70000000 /* reserved range for processor */ +#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ + +/* some other useful tags */ +#define DT_RELACOUNT 0x6ffffff9 /* if present, number of RELATIVE */ +#define DT_RELCOUNT 0x6ffffffa /* relocs, which must come first */ +#define DT_FLAGS_1 0x6ffffffb + +/* Dynamic Flags - DT_FLAGS_1 .dynamic entry */ +#define DF_1_NOW 0x00000001 +#define DF_1_GLOBAL 0x00000002 +#define DF_1_GROUP 0x00000004 +#define DF_1_NODELETE 0x00000008 +#define DF_1_LOADFLTR 0x00000010 +#define DF_1_INITFIRST 0x00000020 +#define DF_1_NOOPEN 0x00000040 +#define DF_1_ORIGIN 0x00000080 +#define DF_1_DIRECT 0x00000100 +#define DF_1_TRANS 0x00000200 +#define DF_1_INTERPOSE 0x00000400 +#define DF_1_NODEFLIB 0x00000800 +#define DF_1_NODUMP 0x00001000 +#define DF_1_CONLFAT 0x00002000 + +/* ld.so: number of low tags that are used saved internally (0 .. DT_NUM-1) */ +#define DT_NUM (DT_JMPREL + 1) + +/* + * Note Definitions + */ +typedef struct +{ + Elf32_Word namesz; + Elf32_Word descsz; + Elf32_Word type; +} Elf32_Note; + +typedef struct +{ + Elf64_Half namesz; + Elf64_Half descsz; + Elf64_Half type; +} Elf64_Note; + +#if defined(ELFSIZE) && (ELFSIZE == 32) +#define Elf_Ehdr Elf32_Ehdr +#define Elf_Phdr Elf32_Phdr +#define Elf_Shdr Elf32_Shdr +#define Elf_Sym Elf32_Sym +#define Elf_Rel Elf32_Rel +#define Elf_RelA Elf32_Rela +#define Elf_Dyn Elf32_Dyn +#define Elf_Half Elf32_Half +#define Elf_Word Elf32_Word +#define Elf_Sword Elf32_Sword +#define Elf_Addr Elf32_Addr +#define Elf_Off Elf32_Off +#define Elf_Nhdr Elf32_Nhdr +#define Elf_Note Elf32_Note + +#define ELF_R_SYM ELF32_R_SYM +#define ELF_R_TYPE ELF32_R_TYPE +#define ELF_R_INFO ELF32_R_INFO +#define ELFCLASS ELFCLASS32 + +#define ELF_ST_BIND ELF32_ST_BIND +#define ELF_ST_TYPE ELF32_ST_TYPE +#define ELF_ST_INFO ELF32_ST_INFO + +#elif defined(ELFSIZE) && (ELFSIZE == 64) + +#define Elf_Ehdr Elf64_Ehdr +#define Elf_Phdr Elf64_Phdr +#define Elf_Shdr Elf64_Shdr +#define Elf_Sym Elf64_Sym +#define Elf_Rel Elf64_Rel +#define Elf_RelA Elf64_Rela +#define Elf_Dyn Elf64_Dyn +#define Elf_Half Elf64_Half +#define Elf_Word Elf64_Word +#define Elf_Sword Elf64_Sword +#define Elf_Addr Elf64_Addr +#define Elf_Off Elf64_Off +#define Elf_Nhdr Elf64_Nhdr +#define Elf_Note Elf64_Note + +#define ELF_R_SYM ELF64_R_SYM +#define ELF_R_TYPE ELF64_R_TYPE +#define ELF_R_INFO ELF64_R_INFO +#define ELFCLASS ELFCLASS64 + +#define ELF_ST_BIND ELF64_ST_BIND +#define ELF_ST_TYPE ELF64_ST_TYPE +#define ELF_ST_INFO ELF64_ST_INFO + +#endif + +#endif diff --git a/nyx/nyx_gui/libs/elfload/elfarch.h b/nyx/nyx_gui/libs/elfload/elfarch.h new file mode 100644 index 0000000..f1cc388 --- /dev/null +++ b/nyx/nyx_gui/libs/elfload/elfarch.h @@ -0,0 +1,49 @@ +/* + * Copyright © 2014, Owen Shepherd + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef ELFARCH_H +#define ELFARCH_H + +#if defined(__i386__) +#define EM_THIS EM_386 +#define EL_ARCH_USES_REL +#elif defined(__amd64__) +#define EM_THIS EM_AMD64 +#define EL_ARCH_USES_RELA +#elif defined(__arm__) +#define EM_THIS EM_ARM +#define EL_ARCH_USES_REL +#elif defined(__aarch64__) +#define EM_THIS EM_AARCH64 +#define EL_ARCH_USES_RELA +#define EL_ARCH_USES_REL +#else +#error specify your ELF architecture +#endif + +#if defined(__LP64__) || defined(__LLP64__) +#define ELFSIZE 64 +#else +#define ELFSIZE 32 +#endif + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define ELFDATATHIS ELFDATA2LSB +#else +#define ELFDATATHIS ELFDATA2MSB +#endif + +#endif diff --git a/nyx/nyx_gui/libs/elfload/elfload.c b/nyx/nyx_gui/libs/elfload/elfload.c new file mode 100644 index 0000000..84201ec --- /dev/null +++ b/nyx/nyx_gui/libs/elfload/elfload.c @@ -0,0 +1,329 @@ +/* + * Copyright © 2018, M4xw + * Copyright © 2014, Owen Shepherd + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "elfload.h" + +#pragma GCC push_options +#pragma GCC target ("thumb") + +el_status el_pread(el_ctx *ctx, void *def, size_t nb, size_t offset) +{ + return ctx->pread(ctx, def, nb, offset) ? EL_OK : EL_EIO; +} + +#define EL_PHOFF(ctx, num) (((ctx)->ehdr.e_phoff + (num) *(ctx)->ehdr.e_phentsize)) +el_status el_findphdr(el_ctx *ctx, Elf_Phdr *phdr, uint32_t type, unsigned *i) +{ + el_status rv = EL_OK; + for (; *i < ctx->ehdr.e_phnum; (*i)++) + { + if ((rv = el_pread(ctx, phdr, sizeof *phdr, EL_PHOFF(ctx, *i)))) + return rv; + + if (phdr->p_type == type) + { + return rv; + } + } + + *i = -1; + return rv; +} + +#define EL_SHOFF(ctx, num) (((ctx)->ehdr.e_shoff + (num) *(ctx)->ehdr.e_shentsize)) +el_status el_findshdr(el_ctx *ctx, Elf_Shdr *shdr, uint32_t type, unsigned *i) +{ + el_status rv = EL_OK; + + for (; *i < ctx->ehdr.e_shnum; (*i)++) + { + if ((rv = el_pread(ctx, shdr, sizeof *shdr, EL_SHOFF(ctx, *i)))) + + return rv; + + if (shdr->sh_type == type) + { + return rv; + } + } + + *i = -1; + + return rv; +} + +el_status el_init(el_ctx *ctx) +{ + el_status rv = EL_OK; + if ((rv = el_pread(ctx, &ctx->ehdr, sizeof ctx->ehdr, 0))) + return rv; + + /* validate header */ + + if (!IS_ELF(ctx->ehdr)) + return EL_NOTELF; + + if (ctx->ehdr.e_ident[EI_CLASS] != ELFCLASS) + return EL_WRONGBITS; + + if (ctx->ehdr.e_ident[EI_DATA] != ELFDATATHIS) + return EL_WRONGENDIAN; + + if (ctx->ehdr.e_ident[EI_VERSION] != EV_CURRENT) + return EL_NOTELF; + + if (ctx->ehdr.e_type != ET_EXEC && ctx->ehdr.e_type != ET_DYN) + return EL_NOTEXEC; + + if (ctx->ehdr.e_machine != EM_THIS) + return EL_WRONGARCH; + + if (ctx->ehdr.e_version != EV_CURRENT) + return EL_NOTELF; + + /* load phdrs */ + Elf_Phdr ph; + + /* iterate through, calculate extents */ + ctx->base_load_paddr = ctx->base_load_vaddr = 0; + ctx->align = 1; + ctx->memsz = 0; + + unsigned i = 0; + for (;;) + { + if ((rv = el_findphdr(ctx, &ph, PT_LOAD, &i))) + return rv; + + if (i == (unsigned)-1) + break; + + Elf_Addr phend = ph.p_vaddr + ph.p_memsz; + if (phend > ctx->memsz) + ctx->memsz = phend; + + if (ph.p_align > ctx->align) + ctx->align = ph.p_align; + + i++; + } + + // Program Header + if (ctx->ehdr.e_type == ET_DYN) + { + i = 0; + + if ((rv = el_findphdr(ctx, &ph, PT_DYNAMIC, &i))) + return rv; + + if (i == (unsigned)-1) + return EL_NODYN; + + ctx->dynoff = ph.p_offset; + ctx->dynsize = ph.p_filesz; + } + else + { + ctx->dynoff = 0; + ctx->dynsize = 0; + } + + // Section String Table + if (ctx->ehdr.e_type == ET_DYN) + { + i = ctx->ehdr.e_shstrndx - 1; + + if ((rv = el_findshdr(ctx, &ctx->shstr, SHT_STRTAB, &i))) + return rv; + + // Reset + i = 0; + + if ((rv = el_findshdr(ctx, &ctx->symtab, SHT_SYMTAB, &i))) + return rv; + + if (i == (unsigned)-1) + return EL_NODYN; + } + + return rv; +} + +/* +typedef void* (*el_alloc_cb)( + el_ctx *ctx, + Elf_Addr phys, + Elf_Addr virt, + Elf_Addr size); +*/ + +el_status el_load(el_ctx *ctx, el_alloc_cb alloc) +{ + el_status rv = EL_OK; + + /* address deltas */ + Elf_Addr pdelta = ctx->base_load_paddr; + Elf_Addr vdelta = ctx->base_load_vaddr; + + /* iterate paddrs */ + Elf_Phdr ph; + unsigned i = 0; + for (;;) + { + if ((rv = el_findphdr(ctx, &ph, PT_LOAD, &i))) + return rv; + + if (i == (unsigned)-1) + break; + + Elf_Addr pload = ph.p_paddr + pdelta; + Elf_Addr vload = ph.p_vaddr + vdelta; + + /* allocate mem */ + char *dest = alloc(ctx, pload, vload, ph.p_memsz); + if (!dest) + return EL_ENOMEM; + + EL_DEBUG("Loading seg fileoff %x, vaddr %x to %p\n", + ph.p_offset, ph.p_vaddr, dest); + + /* read loaded portion */ + if ((rv = el_pread(ctx, dest, ph.p_filesz, ph.p_offset))) + return rv; + + /* zero mem-only portion */ + memset(dest + ph.p_filesz, 0, ph.p_memsz - ph.p_filesz); + + i++; + } + + return rv; +} + +el_status el_finddyn(el_ctx *ctx, Elf_Dyn *dyn, uint32_t tag) +{ + el_status rv = EL_OK; + size_t ndyn = ctx->dynsize / sizeof(Elf_Dyn); + + for (unsigned i = 0; i < ndyn; i++) + { + if ((rv = el_pread(ctx, dyn, sizeof *dyn, ctx->dynoff + i * sizeof *dyn))) + return rv; + + if (dyn->d_tag == tag) + return EL_OK; + } + + dyn->d_tag = DT_NULL; + return EL_OK; +} + +el_status el_findrelocs(el_ctx *ctx, el_relocinfo *ri, uint32_t type) +{ + el_status rv = EL_OK; + + Elf_Dyn rel, relsz, relent; + + if ((rv = el_finddyn(ctx, &rel, type))) + return rv; + + if ((rv = el_finddyn(ctx, &relsz, type + 1))) + return rv; + + if ((rv = el_finddyn(ctx, &relent, type + 2))) + return rv; + + if (rel.d_tag == DT_NULL || relsz.d_tag == DT_NULL || relent.d_tag == DT_NULL) + { + ri->entrysize = 0; + ri->tablesize = 0; + ri->tableoff = 0; + } + else + { + ri->tableoff = rel.d_un.d_ptr; + ri->tablesize = relsz.d_un.d_val; + ri->entrysize = relent.d_un.d_val; + } + + return rv; +} + +extern el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel); +extern el_status el_applyrela(el_ctx *ctx, Elf_RelA *rela); + +el_status el_relocate(el_ctx *ctx) +{ + el_status rv = EL_OK; + + // not dynamic + if (ctx->ehdr.e_type != ET_DYN) + return EL_OK; + + char *base = (char *)ctx->base_load_paddr; + + el_relocinfo ri; +#ifdef EL_ARCH_USES_REL + if ((rv = el_findrelocs(ctx, &ri, DT_REL))) + return rv; + + if (ri.entrysize != sizeof(Elf_Rel) && ri.tablesize) + { + EL_DEBUG("Relocation size %u doesn't match expected %u\n", + ri.entrysize, sizeof(Elf_Rel)); + return EL_BADREL; + } + + size_t relcnt = ri.tablesize / sizeof(Elf_Rel); + Elf_Rel *reltab = (Elf_Rel *)(base + ri.tableoff); + for (size_t i = 0; i < relcnt; i++) + { + if ((rv = el_applyrel(ctx, &reltab[i]))) + return rv; + } +#endif + +#ifdef EL_ARCH_USES_RELA + if ((rv = el_findrelocs(ctx, &ri, DT_RELA))) + return rv; + + if (ri.entrysize != sizeof(Elf_RelA) && ri.tablesize) + { + EL_DEBUG("Relocation size %u doesn't match expected %u\n", + ri.entrysize, sizeof(Elf_RelA)); + return EL_BADREL; + } + + size_t relacnt = ri.tablesize / sizeof(Elf_RelA); + Elf_RelA *relatab = (Elf_RelA *)(base + ri.tableoff); + for (size_t i = 0; i < relacnt; i++) + { + if ((rv = el_applyrela(ctx, &relatab[i]))) + return rv; + } +#endif + +#if !defined(EL_ARCH_USES_REL) && !defined(EL_ARCH_USES_RELA) +#error No relocation type defined! +#endif + + return rv; +} + +#pragma GCC pop_options diff --git a/nyx/nyx_gui/libs/elfload/elfload.h b/nyx/nyx_gui/libs/elfload/elfload.h new file mode 100644 index 0000000..a261708 --- /dev/null +++ b/nyx/nyx_gui/libs/elfload/elfload.h @@ -0,0 +1,127 @@ +/* + * Copyright © 2018, M4xw + * Copyright © 2014, Owen Shepherd + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef ELFLOAD_H +#define ELFLOAD_H +#include + +#include "elfarch.h" +#include "elf.h" + +#include "../../utils/types.h" + +#ifdef DEBUG +#include "../../gfx/gfx.h" +#define EL_DEBUG(format, ...) \ + gfx_printf(format __VA_OPT__(, ) __VA_ARGS__) +#else +#define EL_DEBUG(...) \ + do \ + { \ + } while (0) +#endif + +typedef enum +{ + EL_OK = 0, + + EL_EIO, + EL_ENOMEM, + + EL_NOTELF, + EL_WRONGBITS, + EL_WRONGENDIAN, + EL_WRONGARCH, + EL_WRONGOS, + EL_NOTEXEC, + EL_NODYN, + EL_BADREL, + +} el_status; + +typedef struct el_ctx +{ + bool (*pread)(struct el_ctx *ctx, void *dest, size_t nb, size_t offset); + + /* base_load_* -> address we are actually going to load at + */ + Elf_Addr + base_load_paddr, + base_load_vaddr; + + /* size in memory of binary */ + Elf_Addr memsz; + + /* required alignment */ + Elf_Addr align; + + /* ELF header */ + Elf_Ehdr ehdr; + + // Section Header Str Table + Elf_Shdr shstr; + Elf_Shdr symtab; + + /* Offset of dynamic table (0 if not ET_DYN) */ + Elf_Off dynoff; + /* Size of dynamic table (0 if not ET_DYN) */ + Elf_Addr dynsize; +} el_ctx; + +el_status el_pread(el_ctx *ctx, void *def, size_t nb, size_t offset); + +el_status el_init(el_ctx *ctx); +typedef void *(*el_alloc_cb)( + el_ctx *ctx, + Elf_Addr phys, + Elf_Addr virt, + Elf_Addr size); + +el_status el_load(el_ctx *ctx, el_alloc_cb alloccb); + +/* find the next phdr of type \p type, starting at \p *i. + * On success, returns EL_OK with *i set to the phdr number, and the phdr loaded + * in *phdr. + * + * If the end of the phdrs table was reached, *i is set to -1 and the contents + * of *phdr are undefined + */ +el_status el_findphdr(el_ctx *ctx, Elf_Phdr *phdr, uint32_t type, unsigned *i); + +/* Relocate the loaded executable */ +el_status el_relocate(el_ctx *ctx); + +/* find a dynamic table entry + * returns the entry on success, dyn->d_tag = DT_NULL on failure + */ +el_status el_finddyn(el_ctx *ctx, Elf_Dyn *dyn, uint32_t type); + +typedef struct +{ + Elf_Off tableoff; + Elf_Addr tablesize; + Elf_Addr entrysize; +} el_relocinfo; + +/* find all information regarding relocations of a specific type. + * + * pass DT_REL or DT_RELA for type + * sets ri->entrysize = 0 if not found + */ +el_status el_findrelocs(el_ctx *ctx, el_relocinfo *ri, uint32_t type); + +#endif diff --git a/nyx/nyx_gui/libs/elfload/elfreloc_aarch64.c b/nyx/nyx_gui/libs/elfload/elfreloc_aarch64.c new file mode 100644 index 0000000..bbb0ce4 --- /dev/null +++ b/nyx/nyx_gui/libs/elfload/elfreloc_aarch64.c @@ -0,0 +1,84 @@ +/* + * Copyright © 2014, Owen Shepherd + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "elfload.h" + +#if defined(__aarch64__) + +#define R_AARCH64_NONE 0 +#define R_AARCH64_RELATIVE 1027 + +el_status el_applyrela(el_ctx *ctx, Elf_RelA *rel) +{ + uintptr_t *p = (uintptr_t *)(rel->r_offset + ctx->base_load_paddr); + uint32_t type = ELF_R_TYPE(rel->r_info); + uint32_t sym = ELF_R_SYM(rel->r_info); + + switch (type) + { + case R_AARCH64_NONE: + EL_DEBUG("R_AARCH64_NONE\n"); + break; + case R_AARCH64_RELATIVE: + if (sym) + { + EL_DEBUG("R_AARCH64_RELATIVE with symbol ref!\n"); + return EL_BADREL; + } + + EL_DEBUG("Applying R_AARCH64_RELATIVE reloc @%p\n", p); + *p = rel->r_addend + ctx->base_load_vaddr; + break; + + default: + EL_DEBUG("Bad relocation %u\n", type); + return EL_BADREL; + } + + return EL_OK; +} + +el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel) +{ + uintptr_t *p = (uintptr_t *)(rel->r_offset + ctx->base_load_paddr); + uint32_t type = ELF_R_TYPE(rel->r_info); + uint32_t sym = ELF_R_SYM(rel->r_info); + + switch (type) + { + case R_AARCH64_NONE: + EL_DEBUG("R_AARCH64_NONE\n"); + break; + case R_AARCH64_RELATIVE: + if (sym) + { + EL_DEBUG("R_AARCH64_RELATIVE with symbol ref!\n"); + return EL_BADREL; + } + + EL_DEBUG("Applying R_AARCH64_RELATIVE reloc @%p\n", p); + *p += ctx->base_load_vaddr; + break; + + default: + EL_DEBUG("Bad relocation %u\n", type); + return EL_BADREL; + } + + return EL_OK; +} + +#endif diff --git a/nyx/nyx_gui/libs/elfload/elfreloc_arm.c b/nyx/nyx_gui/libs/elfload/elfreloc_arm.c new file mode 100644 index 0000000..8b905cb --- /dev/null +++ b/nyx/nyx_gui/libs/elfload/elfreloc_arm.c @@ -0,0 +1,66 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you can do + * whatever you want with this stuff. If we meet some day, and you think this + * stuff is worth it, you can buy me a beer in return. M4xw + * ---------------------------------------------------------------------------- + */ + +#include "elfload.h" + +#if defined(__arm__) + +// Taken from http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf +#define R_ARM_NONE 0 +#define R_ARM_ABS32 2 +#define R_ARM_JUMP_SLOT 22 +#define R_ARM_GLOB_DAT 21 +#define R_ARM_RELATIVE 23 + +el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel) +{ + uint32_t sym = ELF_R_SYM(rel->r_info); // Symbol offset + uint32_t type = ELF_R_TYPE(rel->r_info); // Relocation Type + uintptr_t *p = (uintptr_t *)(rel->r_offset + ctx->base_load_paddr); // Target Addr + +#if 0 // For later symbol usage + Elf32_Sym *elfSym; + const char *symbolName; + + // We resolve relocs from the originating elf-image + elfSym = (Elf32_Sym *)(ctx->symtab.sh_offset + (char *)buffteg) + sym; + int strtab_offset = ctx->shstr.sh_offset; + char *strtab = (char *)buffteg + strtab_offset; + symbolName = strtab + elfSym->st_name; + //EL_DEBUG("Str: %s sz: %x val: %x\n", symbolName, elfSym->st_size, elfSym->st_value); +#endif + + switch (type) + { + case R_ARM_NONE: + EL_DEBUG("R_ARM_NONE\n"); + break; + case R_ARM_JUMP_SLOT: + case R_ARM_ABS32: + case R_ARM_GLOB_DAT: + // Stubbed for later purpose + //*p += elfSym->st_value; // + vaddr from sec + //*p |= 0; // 1 if Thumb && STT_FUNC, ignored for now + break; + case R_ARM_RELATIVE: // Needed for PIE + if (sym) + { + return EL_BADREL; + } + *p += ctx->base_load_vaddr; + break; + + default: + return EL_BADREL; + } + + return EL_OK; +} + +#endif diff --git a/nyx/nyx_gui/libs/fatfs/diskio.c b/nyx/nyx_gui/libs/fatfs/diskio.c new file mode 100644 index 0000000..73a21e7 --- /dev/null +++ b/nyx/nyx_gui/libs/fatfs/diskio.c @@ -0,0 +1,89 @@ +/*-----------------------------------------------------------------------*/ +/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */ +/*-----------------------------------------------------------------------*/ +/* If a working storage control module is available, it should be */ +/* attached to the FatFs via a glue function rather than modifying it. */ +/* This is an example of glue functions to attach various exsisting */ +/* storage control modules to the FatFs module with a defined API. */ +/*-----------------------------------------------------------------------*/ + +#include +#include "diskio.h" /* FatFs lower layer API */ +#include "../../storage/sdmmc.h" + +#define SDMMC_UPPER_BUFFER 0xB8000000 +#define DRAM_START 0x80000000 + +extern sdmmc_storage_t sd_storage; + +/*-----------------------------------------------------------------------*/ +/* Get Drive Status */ +/*-----------------------------------------------------------------------*/ +DSTATUS disk_status ( + BYTE pdrv /* Physical drive nmuber to identify the drive */ +) +{ + return 0; +} + +/*-----------------------------------------------------------------------*/ +/* Inidialize a Drive */ +/*-----------------------------------------------------------------------*/ +DSTATUS disk_initialize ( + BYTE pdrv /* Physical drive nmuber to identify the drive */ +) +{ + return 0; +} + +/*-----------------------------------------------------------------------*/ +/* Read Sector(s) */ +/*-----------------------------------------------------------------------*/ +DRESULT disk_read ( + BYTE pdrv, /* Physical drive nmuber to identify the drive */ + BYTE *buff, /* Data buffer to store read data */ + DWORD sector, /* Start sector in LBA */ + UINT count /* Number of sectors to read */ +) +{ + if ((u32)buff >= DRAM_START) + return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; + u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; + if (sdmmc_storage_read(&sd_storage, sector, count, buf)) + { + memcpy(buff, buf, 512 * count); + return RES_OK; + } + return RES_ERROR; +} + +/*-----------------------------------------------------------------------*/ +/* Write Sector(s) */ +/*-----------------------------------------------------------------------*/ +DRESULT disk_write ( + BYTE pdrv, /* Physical drive nmuber to identify the drive */ + const BYTE *buff, /* Data to be written */ + DWORD sector, /* Start sector in LBA */ + UINT count /* Number of sectors to write */ +) +{ + if ((u32)buff >= DRAM_START) + return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; + u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; //TODO: define this somewhere. + memcpy(buf, buff, 512 * count); + if (sdmmc_storage_write(&sd_storage, sector, count, buf)) + return RES_OK; + return RES_ERROR; +} + +/*-----------------------------------------------------------------------*/ +/* Miscellaneous Functions */ +/*-----------------------------------------------------------------------*/ +DRESULT disk_ioctl ( + BYTE pdrv, /* Physical drive nmuber (0..) */ + BYTE cmd, /* Control code */ + void *buff /* Buffer to send/receive control data */ +) +{ + return RES_OK; +} diff --git a/nyx/nyx_gui/libs/fatfs/diskio.h b/nyx/nyx_gui/libs/fatfs/diskio.h new file mode 100644 index 0000000..d6ae8f8 --- /dev/null +++ b/nyx/nyx_gui/libs/fatfs/diskio.h @@ -0,0 +1,79 @@ +/*-----------------------------------------------------------------------/ +/ Low level disk interface modlue include file (C)ChaN, 2014 / +/-----------------------------------------------------------------------*/ + +#ifndef _DISKIO_DEFINED +#define _DISKIO_DEFINED + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../utils/types.h" + +/* Status of Disk Functions */ +typedef BYTE DSTATUS; + +/* Results of Disk Functions */ +typedef enum { + RES_OK = 0, /* 0: Successful */ + RES_ERROR, /* 1: R/W Error */ + RES_WRPRT, /* 2: Write Protected */ + RES_NOTRDY, /* 3: Not Ready */ + RES_PARERR /* 4: Invalid Parameter */ +} DRESULT; + + +/*---------------------------------------*/ +/* Prototypes for disk control functions */ + + +DSTATUS disk_initialize (BYTE pdrv); +DSTATUS disk_status (BYTE pdrv); +DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); +DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); +DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); + + +/* Disk Status Bits (DSTATUS) */ + +#define STA_NOINIT 0x01 /* Drive not initialized */ +#define STA_NODISK 0x02 /* No medium in the drive */ +#define STA_PROTECT 0x04 /* Write protected */ + + +/* Command code for disk_ioctrl fucntion */ + +/* Generic command (Used by FatFs) */ +#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */ +#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */ +#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */ +#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */ +#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */ + +/* Generic command (Not used by FatFs) */ +#define CTRL_POWER 5 /* Get/Set power status */ +#define CTRL_LOCK 6 /* Lock/Unlock media removal */ +#define CTRL_EJECT 7 /* Eject media */ +#define CTRL_FORMAT 8 /* Create physical format on the media */ + +/* MMC/SDC specific ioctl command */ +#define MMC_GET_TYPE 10 /* Get card type */ +#define MMC_GET_CSD 11 /* Get CSD */ +#define MMC_GET_CID 12 /* Get CID */ +#define MMC_GET_OCR 13 /* Get OCR */ +#define MMC_GET_SDSTAT 14 /* Get SD status */ +#define ISDIO_READ 55 /* Read data form SD iSDIO register */ +#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ +#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ + +/* ATA/CF specific ioctl command */ +#define ATA_GET_REV 20 /* Get F/W revision */ +#define ATA_GET_MODEL 21 /* Get model name */ +#define ATA_GET_SN 22 /* Get serial number */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/nyx/nyx_gui/libs/fatfs/ff.c b/nyx/nyx_gui/libs/fatfs/ff.c new file mode 100644 index 0000000..d8d6768 --- /dev/null +++ b/nyx/nyx_gui/libs/fatfs/ff.c @@ -0,0 +1,6866 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/*----------------------------------------------------------------------------/ +/ FatFs - Generic FAT Filesystem Module R0.13c (p3) / +/-----------------------------------------------------------------------------/ +/ +/ Copyright (C) 2018, ChaN, all right reserved. +/ +/ FatFs module is an open source software. Redistribution and use of FatFs in +/ source and binary forms, with or without modification, are permitted provided +/ that the following condition is met: +/ +/ 1. Redistributions of source code must retain the above copyright notice, +/ this condition and the following disclaimer. +/ +/ This software is provided by the copyright holder and contributors "AS IS" +/ and any warranties related to this software are DISCLAIMED. +/ The copyright owner or contributors be NOT LIABLE for any damages caused +/ by use of this software. +/ +/----------------------------------------------------------------------------*/ + + +#include "ff.h" /* Declarations of FatFs API */ +#include "diskio.h" /* Declarations of device I/O functions */ +#include "../../gfx/gfx.h" + +#pragma GCC push_options +#pragma GCC target ("thumb") + +#define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF); +//#define EFSPRINTF(...) + +/*-------------------------------------------------------------------------- + + Module Private Definitions + +---------------------------------------------------------------------------*/ + +#if FF_DEFINED != 86604 /* Revision ID */ +#error Wrong include file (ff.h). +#endif + + +/* Limits and boundaries */ +#define MAX_DIR 0x200000 /* Max size of FAT directory */ +#define MAX_DIR_EX 0x10000000 /* Max size of exFAT directory */ +#define MAX_FAT12 0xFF5 /* Max FAT12 clusters (differs from specs, but right for real DOS/Windows behavior) */ +#define MAX_FAT16 0xFFF5 /* Max FAT16 clusters (differs from specs, but right for real DOS/Windows behavior) */ +#define MAX_FAT32 0x0FFFFFF5 /* Max FAT32 clusters (not specified, practical limit) */ +#define MAX_EXFAT 0x7FFFFFFD /* Max exFAT clusters (differs from specs, implementation limit) */ + + +/* Character code support macros */ +#define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') +#define IsLower(c) ((c) >= 'a' && (c) <= 'z') +#define IsDigit(c) ((c) >= '0' && (c) <= '9') +#define IsSurrogate(c) ((c) >= 0xD800 && (c) <= 0xDFFF) +#define IsSurrogateH(c) ((c) >= 0xD800 && (c) <= 0xDBFF) +#define IsSurrogateL(c) ((c) >= 0xDC00 && (c) <= 0xDFFF) + + +/* Additional file access control and file status flags for internal use */ +#define FA_SEEKEND 0x20 /* Seek to end of the file on file open */ +#define FA_MODIFIED 0x40 /* File has been modified */ +#define FA_DIRTY 0x80 /* FIL.buf[] needs to be written-back */ + + +/* Additional file attribute bits for internal use */ +#define AM_VOL 0x08 /* Volume label */ +#define AM_LFN 0x0F /* LFN entry */ +#define AM_MASK 0x3F /* Mask of defined bits */ + + +/* Name status flags in fn[11] */ +#define NSFLAG 11 /* Index of the name status byte */ +#define NS_LOSS 0x01 /* Out of 8.3 format */ +#define NS_LFN 0x02 /* Force to create LFN entry */ +#define NS_LAST 0x04 /* Last segment */ +#define NS_BODY 0x08 /* Lower case flag (body) */ +#define NS_EXT 0x10 /* Lower case flag (ext) */ +#define NS_DOT 0x20 /* Dot entry */ +#define NS_NOLFN 0x40 /* Do not find LFN */ +#define NS_NONAME 0x80 /* Not followed */ + + +/* exFAT directory entry types */ +#define ET_BITMAP 0x81 /* Allocation bitmap */ +#define ET_UPCASE 0x82 /* Up-case table */ +#define ET_VLABEL 0x83 /* Volume label */ +#define ET_FILEDIR 0x85 /* File and directory */ +#define ET_STREAM 0xC0 /* Stream extension */ +#define ET_FILENAME 0xC1 /* Name extension */ + + +/* FatFs refers the FAT structure as simple byte array instead of structure member +/ because the C structure is not binary compatible between different platforms */ + +#define BS_JmpBoot 0 /* x86 jump instruction (3-byte) */ +#define BS_OEMName 3 /* OEM name (8-byte) */ +#define BPB_BytsPerSec 11 /* Sector size [byte] (WORD) */ +#define BPB_SecPerClus 13 /* Cluster size [sector] (BYTE) */ +#define BPB_RsvdSecCnt 14 /* Size of reserved area [sector] (WORD) */ +#define BPB_NumFATs 16 /* Number of FATs (BYTE) */ +#define BPB_RootEntCnt 17 /* Size of root directory area for FAT [entry] (WORD) */ +#define BPB_TotSec16 19 /* Volume size (16-bit) [sector] (WORD) */ +#define BPB_Media 21 /* Media descriptor byte (BYTE) */ +#define BPB_FATSz16 22 /* FAT size (16-bit) [sector] (WORD) */ +#define BPB_SecPerTrk 24 /* Number of sectors per track for int13h [sector] (WORD) */ +#define BPB_NumHeads 26 /* Number of heads for int13h (WORD) */ +#define BPB_HiddSec 28 /* Volume offset from top of the drive (DWORD) */ +#define BPB_TotSec32 32 /* Volume size (32-bit) [sector] (DWORD) */ +#define BS_DrvNum 36 /* Physical drive number for int13h (BYTE) */ +#define BS_NTres 37 /* WindowsNT error flag (BYTE) */ +#define BS_BootSig 38 /* Extended boot signature (BYTE) */ +#define BS_VolID 39 /* Volume serial number (DWORD) */ +#define BS_VolLab 43 /* Volume label string (8-byte) */ +#define BS_FilSysType 54 /* Filesystem type string (8-byte) */ +#define BS_BootCode 62 /* Boot code (448-byte) */ +#define BS_55AA 510 /* Signature word (WORD) */ + +#define BPB_FATSz32 36 /* FAT32: FAT size [sector] (DWORD) */ +#define BPB_ExtFlags32 40 /* FAT32: Extended flags (WORD) */ +#define BPB_FSVer32 42 /* FAT32: Filesystem version (WORD) */ +#define BPB_RootClus32 44 /* FAT32: Root directory cluster (DWORD) */ +#define BPB_FSInfo32 48 /* FAT32: Offset of FSINFO sector (WORD) */ +#define BPB_BkBootSec32 50 /* FAT32: Offset of backup boot sector (WORD) */ +#define BS_DrvNum32 64 /* FAT32: Physical drive number for int13h (BYTE) */ +#define BS_NTres32 65 /* FAT32: Error flag (BYTE) */ +#define BS_BootSig32 66 /* FAT32: Extended boot signature (BYTE) */ +#define BS_VolID32 67 /* FAT32: Volume serial number (DWORD) */ +#define BS_VolLab32 71 /* FAT32: Volume label string (8-byte) */ +#define BS_FilSysType32 82 /* FAT32: Filesystem type string (8-byte) */ +#define BS_BootCode32 90 /* FAT32: Boot code (420-byte) */ + +#define BPB_ZeroedEx 11 /* exFAT: MBZ field (53-byte) */ +#define BPB_VolOfsEx 64 /* exFAT: Volume offset from top of the drive [sector] (QWORD) */ +#define BPB_TotSecEx 72 /* exFAT: Volume size [sector] (QWORD) */ +#define BPB_FatOfsEx 80 /* exFAT: FAT offset from top of the volume [sector] (DWORD) */ +#define BPB_FatSzEx 84 /* exFAT: FAT size [sector] (DWORD) */ +#define BPB_DataOfsEx 88 /* exFAT: Data offset from top of the volume [sector] (DWORD) */ +#define BPB_NumClusEx 92 /* exFAT: Number of clusters (DWORD) */ +#define BPB_RootClusEx 96 /* exFAT: Root directory start cluster (DWORD) */ +#define BPB_VolIDEx 100 /* exFAT: Volume serial number (DWORD) */ +#define BPB_FSVerEx 104 /* exFAT: Filesystem version (WORD) */ +#define BPB_VolFlagEx 106 /* exFAT: Volume flags (WORD) */ +#define BPB_BytsPerSecEx 108 /* exFAT: Log2 of sector size in unit of byte (BYTE) */ +#define BPB_SecPerClusEx 109 /* exFAT: Log2 of cluster size in unit of sector (BYTE) */ +#define BPB_NumFATsEx 110 /* exFAT: Number of FATs (BYTE) */ +#define BPB_DrvNumEx 111 /* exFAT: Physical drive number for int13h (BYTE) */ +#define BPB_PercInUseEx 112 /* exFAT: Percent in use (BYTE) */ +#define BPB_RsvdEx 113 /* exFAT: Reserved (7-byte) */ +#define BS_BootCodeEx 120 /* exFAT: Boot code (390-byte) */ + +#define DIR_Name 0 /* Short file name (11-byte) */ +#define DIR_Attr 11 /* Attribute (BYTE) */ +#define DIR_NTres 12 /* Lower case flag (BYTE) */ +#define DIR_CrtTime10 13 /* Created time sub-second (BYTE) */ +#define DIR_CrtTime 14 /* Created time (DWORD) */ +#define DIR_LstAccDate 18 /* Last accessed date (WORD) */ +#define DIR_FstClusHI 20 /* Higher 16-bit of first cluster (WORD) */ +#define DIR_ModTime 22 /* Modified time (DWORD) */ +#define DIR_FstClusLO 26 /* Lower 16-bit of first cluster (WORD) */ +#define DIR_FileSize 28 /* File size (DWORD) */ +#define LDIR_Ord 0 /* LFN: LFN order and LLE flag (BYTE) */ +#define LDIR_Attr 11 /* LFN: LFN attribute (BYTE) */ +#define LDIR_Type 12 /* LFN: Entry type (BYTE) */ +#define LDIR_Chksum 13 /* LFN: Checksum of the SFN (BYTE) */ +#define LDIR_FstClusLO 26 /* LFN: MBZ field (WORD) */ +#define XDIR_Type 0 /* exFAT: Type of exFAT directory entry (BYTE) */ +#define XDIR_NumLabel 1 /* exFAT: Number of volume label characters (BYTE) */ +#define XDIR_Label 2 /* exFAT: Volume label (11-WORD) */ +#define XDIR_CaseSum 4 /* exFAT: Sum of case conversion table (DWORD) */ +#define XDIR_NumSec 1 /* exFAT: Number of secondary entries (BYTE) */ +#define XDIR_SetSum 2 /* exFAT: Sum of the set of directory entries (WORD) */ +#define XDIR_Attr 4 /* exFAT: File attribute (WORD) */ +#define XDIR_CrtTime 8 /* exFAT: Created time (DWORD) */ +#define XDIR_ModTime 12 /* exFAT: Modified time (DWORD) */ +#define XDIR_AccTime 16 /* exFAT: Last accessed time (DWORD) */ +#define XDIR_CrtTime10 20 /* exFAT: Created time subsecond (BYTE) */ +#define XDIR_ModTime10 21 /* exFAT: Modified time subsecond (BYTE) */ +#define XDIR_CrtTZ 22 /* exFAT: Created timezone (BYTE) */ +#define XDIR_ModTZ 23 /* exFAT: Modified timezone (BYTE) */ +#define XDIR_AccTZ 24 /* exFAT: Last accessed timezone (BYTE) */ +#define XDIR_GenFlags 33 /* exFAT: General secondary flags (BYTE) */ +#define XDIR_NumName 35 /* exFAT: Number of file name characters (BYTE) */ +#define XDIR_NameHash 36 /* exFAT: Hash of file name (WORD) */ +#define XDIR_ValidFileSize 40 /* exFAT: Valid file size (QWORD) */ +#define XDIR_FstClus 52 /* exFAT: First cluster of the file data (DWORD) */ +#define XDIR_FileSize 56 /* exFAT: File/Directory size (QWORD) */ + +#define SZDIRE 32 /* Size of a directory entry */ +#define DDEM 0xE5 /* Deleted directory entry mark set to DIR_Name[0] */ +#define RDDEM 0x05 /* Replacement of the character collides with DDEM */ +#define LLEF 0x40 /* Last long entry flag in LDIR_Ord */ + +#define FSI_LeadSig 0 /* FAT32 FSI: Leading signature (DWORD) */ +#define FSI_StrucSig 484 /* FAT32 FSI: Structure signature (DWORD) */ +#define FSI_Free_Count 488 /* FAT32 FSI: Number of free clusters (DWORD) */ +#define FSI_Nxt_Free 492 /* FAT32 FSI: Last allocated cluster (DWORD) */ + +#define MBR_Table 446 /* MBR: Offset of partition table in the MBR */ +#define SZ_PTE 16 /* MBR: Size of a partition table entry */ +#define PTE_Boot 0 /* MBR PTE: Boot indicator */ +#define PTE_StHead 1 /* MBR PTE: Start head */ +#define PTE_StSec 2 /* MBR PTE: Start sector */ +#define PTE_StCyl 3 /* MBR PTE: Start cylinder */ +#define PTE_System 4 /* MBR PTE: System ID */ +#define PTE_EdHead 5 /* MBR PTE: End head */ +#define PTE_EdSec 6 /* MBR PTE: End sector */ +#define PTE_EdCyl 7 /* MBR PTE: End cylinder */ +#define PTE_StLba 8 /* MBR PTE: Start in LBA */ +#define PTE_SizLba 12 /* MBR PTE: Size in LBA */ + + +/* Post process on fatal error in the file operations */ +#define ABORT(fs, res) { fp->err = (BYTE)(res); LEAVE_FF(fs, res); } + + +/* Re-entrancy related */ +#if FF_FS_REENTRANT +#if FF_USE_LFN == 1 +#error Static LFN work area cannot be used at thread-safe configuration +#endif +#define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; } +#else +#define LEAVE_FF(fs, res) return res +#endif + + +/* Definitions of volume - physical location conversion */ +#if FF_MULTI_PARTITION +#define LD2PD(vol) VolToPart[vol].pd /* Get physical drive number */ +#define LD2PT(vol) VolToPart[vol].pt /* Get partition index */ +#else +#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */ +#define LD2PT(vol) 0 /* Find first valid partition or in SFD */ +#endif + + +/* Definitions of sector size */ +#if (FF_MAX_SS < FF_MIN_SS) || (FF_MAX_SS != 512 && FF_MAX_SS != 1024 && FF_MAX_SS != 2048 && FF_MAX_SS != 4096) || (FF_MIN_SS != 512 && FF_MIN_SS != 1024 && FF_MIN_SS != 2048 && FF_MIN_SS != 4096) +#error Wrong sector size configuration +#endif +#if FF_MAX_SS == FF_MIN_SS +#define SS(fs) ((UINT)FF_MAX_SS) /* Fixed sector size */ +#else +#define SS(fs) ((fs)->ssize) /* Variable sector size */ +#endif + + +/* Timestamp */ +#if FF_FS_NORTC == 1 +#if FF_NORTC_YEAR < 1980 || FF_NORTC_YEAR > 2107 || FF_NORTC_MON < 1 || FF_NORTC_MON > 12 || FF_NORTC_MDAY < 1 || FF_NORTC_MDAY > 31 +#error Invalid FF_FS_NORTC settings +#endif +#define GET_FATTIME() ((DWORD)(FF_NORTC_YEAR - 1980) << 25 | (DWORD)FF_NORTC_MON << 21 | (DWORD)FF_NORTC_MDAY << 16) +#else +#define GET_FATTIME() get_fattime() +#endif + + +/* File lock controls */ +#if FF_FS_LOCK != 0 +#if FF_FS_READONLY +#error FF_FS_LOCK must be 0 at read-only configuration +#endif +typedef struct { + FATFS *fs; /* Object ID 1, volume (NULL:blank entry) */ + DWORD clu; /* Object ID 2, containing directory (0:root) */ + DWORD ofs; /* Object ID 3, offset in the directory */ + WORD ctr; /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */ +} FILESEM; +#endif + + +/* SBCS up-case tables (\x80-\xFF) */ +#define TBL_CT437 {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \ + 0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ + 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ + 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ + 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ + 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ + 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} +#define TBL_CT720 {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ + 0x90,0x91,0x92,0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B6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xCF,0xCF,0xD0,0xEF, \ + 0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF} + + +/* DBCS code range |----- 1st byte -----| |----------- 2nd byte -----------| */ +#define TBL_DC932 {0x81, 0x9F, 0xE0, 0xFC, 0x40, 0x7E, 0x80, 0xFC, 0x00, 0x00} +#define TBL_DC936 {0x81, 0xFE, 0x00, 0x00, 0x40, 0x7E, 0x80, 0xFE, 0x00, 0x00} +#define TBL_DC949 {0x81, 0xFE, 0x00, 0x00, 0x41, 0x5A, 0x61, 0x7A, 0x81, 0xFE} +#define TBL_DC950 {0x81, 0xFE, 0x00, 0x00, 0x40, 0x7E, 0xA1, 0xFE, 0x00, 0x00} + + +/* Macros for table definitions */ +#define MERGE_2STR(a, b) a ## b +#define MKCVTBL(hd, cp) MERGE_2STR(hd, cp) + + + + +/*-------------------------------------------------------------------------- + + Module Private Work Area + +---------------------------------------------------------------------------*/ +/* Remark: Variables defined here without initial value shall be guaranteed +/ zero/null at start-up. If not, the linker option or start-up routine is +/ not compliance with C standard. */ + +/*--------------------------------*/ +/* File/Volume controls */ +/*--------------------------------*/ + +#if FF_VOLUMES < 1 || FF_VOLUMES > 10 +#error Wrong FF_VOLUMES setting +#endif +static FATFS* FatFs[FF_VOLUMES]; /* Pointer to the filesystem objects (logical drives) */ +static WORD Fsid; /* Filesystem mount ID */ + +#if FF_FS_RPATH != 0 +static BYTE CurrVol; /* Current drive */ +#endif + +#if FF_FS_LOCK != 0 +static FILESEM Files[FF_FS_LOCK]; /* Open object lock semaphores */ +#endif + +#if FF_STR_VOLUME_ID +#ifdef FF_VOLUME_STRS +static const char* const VolumeStr[FF_VOLUMES] = {FF_VOLUME_STRS}; /* Pre-defined volume ID */ +#endif +#endif + + +/*--------------------------------*/ +/* LFN/Directory working buffer */ +/*--------------------------------*/ + +#if FF_USE_LFN == 0 /* Non-LFN configuration */ +#if FF_FS_EXFAT +#error LFN must be enabled when enable exFAT +#endif +#define DEF_NAMBUF +#define INIT_NAMBUF(fs) +#define FREE_NAMBUF() +#define LEAVE_MKFS(res) return res + +#else /* LFN configurations */ +#if FF_MAX_LFN < 12 || FF_MAX_LFN > 255 +#error Wrong setting of FF_MAX_LFN +#endif +#if FF_LFN_BUF < FF_SFN_BUF || FF_SFN_BUF < 12 +#error Wrong setting of FF_LFN_BUF or FF_SFN_BUF +#endif +#if FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3 +#error Wrong setting of FF_LFN_UNICODE +#endif +static const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* FAT: Offset of LFN characters in the directory entry */ +#define MAXDIRB(nc) ((nc + 44U) / 15 * SZDIRE) /* exFAT: Size of directory entry block scratchpad buffer needed for the name length */ + +#if FF_USE_LFN == 1 /* LFN enabled with static working buffer */ +#if FF_FS_EXFAT +static BYTE DirBuf[MAXDIRB(FF_MAX_LFN)]; /* Directory entry block scratchpad buffer */ +#endif +static WCHAR LfnBuf[FF_MAX_LFN + 1]; /* LFN working buffer */ +#define DEF_NAMBUF +#define INIT_NAMBUF(fs) +#define FREE_NAMBUF() +#define LEAVE_MKFS(res) return res + +#elif FF_USE_LFN == 2 /* LFN enabled with dynamic working buffer on the stack */ +#if FF_FS_EXFAT +#define DEF_NAMBUF WCHAR lbuf[FF_MAX_LFN+1]; BYTE dbuf[MAXDIRB(FF_MAX_LFN)]; /* LFN working buffer and directory entry block scratchpad buffer */ +#define INIT_NAMBUF(fs) { (fs)->lfnbuf = lbuf; (fs)->dirbuf = dbuf; } +#define FREE_NAMBUF() +#else +#define DEF_NAMBUF WCHAR lbuf[FF_MAX_LFN+1]; /* LFN working buffer */ +#define INIT_NAMBUF(fs) { (fs)->lfnbuf = lbuf; } +#define FREE_NAMBUF() +#endif +#define LEAVE_MKFS(res) return res + +#elif FF_USE_LFN == 3 /* LFN enabled with dynamic working buffer on the heap */ +#if FF_FS_EXFAT +#define DEF_NAMBUF WCHAR *lfn; /* Pointer to LFN working buffer and directory entry block scratchpad buffer */ +#define INIT_NAMBUF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2 + MAXDIRB(FF_MAX_LFN)); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; (fs)->dirbuf = (BYTE*)(lfn+FF_MAX_LFN+1); } +#define FREE_NAMBUF() ff_memfree(lfn) +#else +#define DEF_NAMBUF WCHAR *lfn; /* Pointer to LFN working buffer */ +#define INIT_NAMBUF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } +#define FREE_NAMBUF() ff_memfree(lfn) +#endif +#define LEAVE_MKFS(res) { if (!work) ff_memfree(buf); return res; } +#define MAX_MALLOC 0x8000 /* Must be >=FF_MAX_SS */ + +#else +#error Wrong setting of FF_USE_LFN + +#endif /* FF_USE_LFN == 1 */ +#endif /* FF_USE_LFN == 0 */ + + + +/*--------------------------------*/ +/* Code conversion tables */ +/*--------------------------------*/ + +#if FF_CODE_PAGE == 0 /* Run-time code page configuration */ +#define CODEPAGE CodePage +static WORD CodePage; /* Current code page */ +static const BYTE *ExCvt, *DbcTbl; /* Pointer to current SBCS up-case table and DBCS code range table below */ + +static const BYTE Ct437[] = TBL_CT437; +static const BYTE Ct720[] = TBL_CT720; +static const BYTE Ct737[] = TBL_CT737; +static const BYTE Ct771[] = TBL_CT771; +static const BYTE Ct775[] = TBL_CT775; +static const BYTE Ct850[] = TBL_CT850; +static const BYTE Ct852[] = TBL_CT852; +static const BYTE Ct855[] = TBL_CT855; +static const BYTE Ct857[] = TBL_CT857; +static const BYTE Ct860[] = TBL_CT860; +static const BYTE Ct861[] = TBL_CT861; +static const BYTE Ct862[] = TBL_CT862; +static const BYTE Ct863[] = TBL_CT863; +static const BYTE Ct864[] = TBL_CT864; +static const BYTE Ct865[] = TBL_CT865; +static const BYTE Ct866[] = TBL_CT866; +static const BYTE Ct869[] = TBL_CT869; +static const BYTE Dc932[] = TBL_DC932; +static const BYTE Dc936[] = TBL_DC936; +static const BYTE Dc949[] = TBL_DC949; +static const BYTE Dc950[] = TBL_DC950; + +#elif FF_CODE_PAGE < 900 /* Static code page configuration (SBCS) */ +#define CODEPAGE FF_CODE_PAGE +static const BYTE ExCvt[] = MKCVTBL(TBL_CT, FF_CODE_PAGE); + +#else /* Static code page configuration (DBCS) */ +#define CODEPAGE FF_CODE_PAGE +static const BYTE DbcTbl[] = MKCVTBL(TBL_DC, FF_CODE_PAGE); + +#endif + + + + +/*-------------------------------------------------------------------------- + + Module Private Functions + +---------------------------------------------------------------------------*/ + +/*-----------------------------------------------------------------------*/ +/* Print error header */ +/*-----------------------------------------------------------------------*/ + +void print_error() +{ + gfx_printf("\n\n\n%k[FatFS] Error: %k", 0xFFFFFF00, 0xFFFFFFFF); +} + + +/*-----------------------------------------------------------------------*/ +/* Load/Store multi-byte word in the FAT structure */ +/*-----------------------------------------------------------------------*/ + +static WORD ld_word (const BYTE* ptr) /* Load a 2-byte little-endian word */ +{ + WORD rv; + + rv = ptr[1]; + rv = rv << 8 | ptr[0]; + return rv; +} + +static DWORD ld_dword (const BYTE* ptr) /* Load a 4-byte little-endian word */ +{ + DWORD rv; + + rv = ptr[3]; + rv = rv << 8 | ptr[2]; + rv = rv << 8 | ptr[1]; + rv = rv << 8 | ptr[0]; + return rv; +} + +#if FF_FS_EXFAT +static QWORD ld_qword (const BYTE* ptr) /* Load an 8-byte little-endian word */ +{ + QWORD rv; + + rv = ptr[7]; + rv = rv << 8 | ptr[6]; + rv = rv << 8 | ptr[5]; + rv = rv << 8 | ptr[4]; + rv = rv << 8 | ptr[3]; + rv = rv << 8 | ptr[2]; + rv = rv << 8 | ptr[1]; + rv = rv << 8 | ptr[0]; + return rv; +} +#endif + +#if !FF_FS_READONLY +static void st_word (BYTE* ptr, WORD val) /* Store a 2-byte word in little-endian */ +{ + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; +} + +static void st_dword (BYTE* ptr, DWORD val) /* Store a 4-byte word in little-endian */ +{ + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; +} + +#if FF_FS_EXFAT +static void st_qword (BYTE* ptr, QWORD val) /* Store an 8-byte word in little-endian */ +{ + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; val >>= 8; + *ptr++ = (BYTE)val; +} +#endif +#endif /* !FF_FS_READONLY */ + + + +/*-----------------------------------------------------------------------*/ +/* String functions */ +/*-----------------------------------------------------------------------*/ + +/* Copy memory to memory */ +static void mem_cpy (void* dst, const void* src, UINT cnt) +{ + BYTE *d = (BYTE*)dst; + const BYTE *s = (const BYTE*)src; + + if (cnt != 0) { + do { + *d++ = *s++; + } while (--cnt); + } +} + + +/* Fill memory block */ +static void mem_set (void* dst, int val, UINT cnt) +{ + BYTE *d = (BYTE*)dst; + + do { + *d++ = (BYTE)val; + } while (--cnt); +} + + +/* Compare memory block */ +static int mem_cmp (const void* dst, const void* src, UINT cnt) /* ZR:same, NZ:different */ +{ + const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src; + int r = 0; + + do { + r = *d++ - *s++; + } while (--cnt && r == 0); + + return r; +} + + +/* Check if chr is contained in the string */ +static int chk_chr (const char* str, int chr) /* NZ:contained, ZR:not contained */ +{ + while (*str && *str != chr) str++; + return *str; +} + + +/* Test if the character is DBC 1st byte */ +static int dbc_1st (BYTE c) +{ +#if FF_CODE_PAGE == 0 /* Variable code page */ + if (DbcTbl && c >= DbcTbl[0]) { + if (c <= DbcTbl[1]) return 1; /* 1st byte range 1 */ + if (c >= DbcTbl[2] && c <= DbcTbl[3]) return 1; /* 1st byte range 2 */ + } +#elif FF_CODE_PAGE >= 900 /* DBCS fixed code page */ + if (c >= DbcTbl[0]) { + if (c <= DbcTbl[1]) return 1; + if (c >= DbcTbl[2] && c <= DbcTbl[3]) return 1; + } +#else /* SBCS fixed code page */ + if (c != 0) return 0; /* Always false */ +#endif + return 0; +} + + +/* Test if the character is DBC 2nd byte */ +static int dbc_2nd (BYTE c) +{ +#if FF_CODE_PAGE == 0 /* Variable code page */ + if (DbcTbl && c >= DbcTbl[4]) { + if (c <= DbcTbl[5]) return 1; /* 2nd byte range 1 */ + if (c >= DbcTbl[6] && c <= DbcTbl[7]) return 1; /* 2nd byte range 2 */ + if (c >= DbcTbl[8] && c <= DbcTbl[9]) return 1; /* 2nd byte range 3 */ + } +#elif FF_CODE_PAGE >= 900 /* DBCS fixed code page */ + if (c >= DbcTbl[4]) { + if (c <= DbcTbl[5]) return 1; + if (c >= DbcTbl[6] && c <= DbcTbl[7]) return 1; + if (c >= DbcTbl[8] && c <= DbcTbl[9]) return 1; + } +#else /* SBCS fixed code page */ + if (c != 0) return 0; /* Always false */ +#endif + return 0; +} + + +#if FF_USE_LFN + +/* Get a character from TCHAR string in defined API encodeing */ +static DWORD tchar2uni ( /* Returns character in UTF-16 encoding (>=0x10000 on double encoding unit, 0xFFFFFFFF on decode error) */ + const TCHAR** str /* Pointer to pointer to TCHAR string in configured encoding */ +) +{ + DWORD uc; + const TCHAR *p = *str; + +#if FF_LFN_UNICODE == 1 /* UTF-16 input */ + WCHAR wc; + + uc = *p++; /* Get a unit */ + if (IsSurrogate(uc)) { /* Surrogate? */ + wc = *p++; /* Get low surrogate */ + if (!IsSurrogateH(uc) || !IsSurrogateL(wc)) return 0xFFFFFFFF; /* Wrong surrogate? */ + uc = uc << 16 | wc; + } + +#elif FF_LFN_UNICODE == 2 /* UTF-8 input */ + BYTE b; + int nf; + + uc = (BYTE)*p++; /* Get a unit */ + if (uc & 0x80) { /* Multiple byte code? */ + if ((uc & 0xE0) == 0xC0) { /* 2-byte sequence? */ + uc &= 0x1F; nf = 1; + } else { + if ((uc & 0xF0) == 0xE0) { /* 3-byte sequence? */ + uc &= 0x0F; nf = 2; + } else { + if ((uc & 0xF8) == 0xF0) { /* 4-byte sequence? */ + uc &= 0x07; nf = 3; + } else { /* Wrong sequence */ + return 0xFFFFFFFF; + } + } + } + do { /* Get trailing bytes */ + b = (BYTE)*p++; + if ((b & 0xC0) != 0x80) return 0xFFFFFFFF; /* Wrong sequence? */ + uc = uc << 6 | (b & 0x3F); + } while (--nf != 0); + if (uc < 0x80 || IsSurrogate(uc) || uc >= 0x110000) return 0xFFFFFFFF; /* Wrong code? */ + if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); /* Make a surrogate pair if needed */ + } + +#elif FF_LFN_UNICODE == 3 /* UTF-32 input */ + uc = (TCHAR)*p++; /* Get a unit */ + if (uc >= 0x110000) return 0xFFFFFFFF; /* Wrong code? */ + if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); /* Make a surrogate pair if needed */ + +#else /* ANSI/OEM input */ + BYTE b; + WCHAR wc; + + wc = (BYTE)*p++; /* Get a byte */ + if (dbc_1st((BYTE)wc)) { /* Is it a DBC 1st byte? */ + b = (BYTE)*p++; /* Get 2nd byte */ + if (!dbc_2nd(b)) return 0xFFFFFFFF; /* Invalid code? */ + wc = (wc << 8) + b; /* Make a DBC */ + } + if (wc != 0) { + wc = ff_oem2uni(wc, CODEPAGE); /* ANSI/OEM ==> Unicode */ + if (wc == 0) return 0xFFFFFFFF; /* Invalid code? */ + } + uc = wc; + +#endif + *str = p; /* Next read pointer */ + return uc; +} + + +/* Output a TCHAR string in defined API encoding */ +static BYTE put_utf ( /* Returns number of encoding units written (0:buffer overflow or wrong encoding) */ + DWORD chr, /* UTF-16 encoded character (Double encoding unit char if >=0x10000) */ + TCHAR* buf, /* Output buffer */ + UINT szb /* Size of the buffer */ +) +{ +#if FF_LFN_UNICODE == 1 /* UTF-16 output */ + WCHAR hs, wc; + + hs = (WCHAR)(chr >> 16); + wc = (WCHAR)chr; + if (hs == 0) { /* Single encoding unit? */ + if (szb < 1 || IsSurrogate(wc)) return 0; /* Buffer overflow or wrong code? */ + *buf = wc; + return 1; + } + if (szb < 2 || !IsSurrogateH(hs) || !IsSurrogateL(wc)) return 0; /* Buffer overflow or wrong surrogate? */ + *buf++ = hs; + *buf++ = wc; + return 2; + +#elif FF_LFN_UNICODE == 2 /* UTF-8 output */ + DWORD hc; + + if (chr < 0x80) { /* Single byte code? */ + if (szb < 1) return 0; /* Buffer overflow? */ + *buf = (TCHAR)chr; + return 1; + } + if (chr < 0x800) { /* 2-byte sequence? */ + if (szb < 2) return 0; /* Buffer overflow? */ + *buf++ = (TCHAR)(0xC0 | (chr >> 6 & 0x1F)); + *buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F)); + return 2; + } + if (chr < 0x10000) { /* 3-byte sequence? */ + if (szb < 3 || IsSurrogate(chr)) return 0; /* Buffer overflow or wrong code? */ + *buf++ = (TCHAR)(0xE0 | (chr >> 12 & 0x0F)); + *buf++ = (TCHAR)(0x80 | (chr >> 6 & 0x3F)); + *buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F)); + return 3; + } + /* 4-byte sequence */ + if (szb < 4) return 0; /* Buffer overflow? */ + hc = ((chr & 0xFFFF0000) - 0xD8000000) >> 6; /* Get high 10 bits */ + chr = (chr & 0xFFFF) - 0xDC00; /* Get low 10 bits */ + if (hc >= 0x100000 || chr >= 0x400) return 0; /* Wrong surrogate? */ + chr = (hc | chr) + 0x10000; + *buf++ = (TCHAR)(0xF0 | (chr >> 18 & 0x07)); + *buf++ = (TCHAR)(0x80 | (chr >> 12 & 0x3F)); + *buf++ = (TCHAR)(0x80 | (chr >> 6 & 0x3F)); + *buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F)); + return 4; + +#elif FF_LFN_UNICODE == 3 /* UTF-32 output */ + DWORD hc; + + if (szb < 1) return 0; /* Buffer overflow? */ + if (chr >= 0x10000) { /* Out of BMP? */ + hc = ((chr & 0xFFFF0000) - 0xD8000000) >> 6; /* Get high 10 bits */ + chr = (chr & 0xFFFF) - 0xDC00; /* Get low 10 bits */ + if (hc >= 0x100000 || chr >= 0x400) return 0; /* Wrong surrogate? */ + chr = (hc | chr) + 0x10000; + } + *buf++ = (TCHAR)chr; + return 1; + +#else /* ANSI/OEM output */ + WCHAR wc; + + wc = ff_uni2oem(chr, CODEPAGE); + if (wc >= 0x100) { /* Is this a DBC? */ + if (szb < 2) return 0; + *buf++ = (char)(wc >> 8); /* Store DBC 1st byte */ + *buf++ = (TCHAR)wc; /* Store DBC 2nd byte */ + return 2; + } + if (wc == 0 || szb < 1) return 0; /* Invalid char or buffer overflow? */ + *buf++ = (TCHAR)wc; /* Store the character */ + return 1; +#endif +} +#endif /* FF_USE_LFN */ + + +#if FF_FS_REENTRANT +/*-----------------------------------------------------------------------*/ +/* Request/Release grant to access the volume */ +/*-----------------------------------------------------------------------*/ +static int lock_fs ( /* 1:Ok, 0:timeout */ + FATFS* fs /* Filesystem object */ +) +{ + return ff_req_grant(fs->sobj); +} + + +static void unlock_fs ( + FATFS* fs, /* Filesystem object */ + FRESULT res /* Result code to be returned */ +) +{ + if (fs && res != FR_NOT_ENABLED && res != FR_INVALID_DRIVE && res != FR_TIMEOUT) { + ff_rel_grant(fs->sobj); + } +} + +#endif + + + +#if FF_FS_LOCK != 0 +/*-----------------------------------------------------------------------*/ +/* File lock control functions */ +/*-----------------------------------------------------------------------*/ + +static FRESULT chk_lock ( /* Check if the file can be accessed */ + DIR* dp, /* Directory object pointing the file to be checked */ + int acc /* Desired access type (0:Read mode open, 1:Write mode open, 2:Delete or rename) */ +) +{ + UINT i, be; + + /* Search open object table for the object */ + be = 0; + for (i = 0; i < FF_FS_LOCK; i++) { + if (Files[i].fs) { /* Existing entry */ + if (Files[i].fs == dp->obj.fs && /* Check if the object matches with an open object */ + Files[i].clu == dp->obj.sclust && + Files[i].ofs == dp->dptr) break; + } else { /* Blank entry */ + be = 1; + } + } + if (i == FF_FS_LOCK) { /* The object has not been opened */ + return (!be && acc != 2) ? FR_TOO_MANY_OPEN_FILES : FR_OK; /* Is there a blank entry for new object? */ + } + + /* The object was opened. Reject any open against writing file and all write mode open */ + return (acc != 0 || Files[i].ctr == 0x100) ? FR_LOCKED : FR_OK; +} + + +static int enq_lock (void) /* Check if an entry is available for a new object */ +{ + UINT i; + + for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; + return (i == FF_FS_LOCK) ? 0 : 1; +} + + +static UINT inc_lock ( /* Increment object open counter and returns its index (0:Internal error) */ + DIR* dp, /* Directory object pointing the file to register or increment */ + int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */ +) +{ + UINT i; + + + for (i = 0; i < FF_FS_LOCK; i++) { /* Find the object */ + if (Files[i].fs == dp->obj.fs && + Files[i].clu == dp->obj.sclust && + Files[i].ofs == dp->dptr) break; + } + + if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */ + for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; + if (i == FF_FS_LOCK) return 0; /* No free entry to register (int err) */ + Files[i].fs = dp->obj.fs; + Files[i].clu = dp->obj.sclust; + Files[i].ofs = dp->dptr; + Files[i].ctr = 0; + } + + if (acc >= 1 && Files[i].ctr) return 0; /* Access violation (int err) */ + + Files[i].ctr = acc ? 0x100 : Files[i].ctr + 1; /* Set semaphore value */ + + return i + 1; /* Index number origin from 1 */ +} + + +static FRESULT dec_lock ( /* Decrement object open counter */ + UINT i /* Semaphore index (1..) */ +) +{ + WORD n; + FRESULT res; + + + if (--i < FF_FS_LOCK) { /* Index number origin from 0 */ + n = Files[i].ctr; + if (n == 0x100) n = 0; /* If write mode open, delete the entry */ + if (n > 0) n--; /* Decrement read mode open count */ + Files[i].ctr = n; + if (n == 0) Files[i].fs = 0; /* Delete the entry if open count gets zero */ + res = FR_OK; + } else { + res = FR_INT_ERR; /* Invalid index nunber */ + } + return res; +} + + +static void clear_lock ( /* Clear lock entries of the volume */ + FATFS *fs +) +{ + UINT i; + + for (i = 0; i < FF_FS_LOCK; i++) { + if (Files[i].fs == fs) Files[i].fs = 0; + } +} + +#endif /* FF_FS_LOCK != 0 */ + + + +/*-----------------------------------------------------------------------*/ +/* Move/Flush disk access window in the filesystem object */ +/*-----------------------------------------------------------------------*/ +#if !FF_FS_READONLY +static FRESULT sync_window ( /* Returns FR_OK or FR_DISK_ERR */ + FATFS* fs /* Filesystem object */ +) +{ + FRESULT res = FR_OK; + + + if (fs->wflag) { /* Is the disk access window dirty */ + if (disk_write(fs->pdrv, fs->win, fs->winsect, 1) == RES_OK) { /* Write back the window */ + fs->wflag = 0; /* Clear window dirty flag */ + if (fs->winsect - fs->fatbase < fs->fsize) { /* Is it in the 1st FAT? */ + if (fs->n_fats == 2) disk_write(fs->pdrv, fs->win, fs->winsect + fs->fsize, 1); /* Reflect it to 2nd FAT if needed */ + } + } else { + res = FR_DISK_ERR; + } + } + return res; +} +#endif + + +static FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */ + FATFS* fs, /* Filesystem object */ + DWORD sector /* Sector number to make appearance in the fs->win[] */ +) +{ + FRESULT res = FR_OK; + + + if (sector != fs->winsect) { /* Window offset changed? */ +#if !FF_FS_READONLY + res = sync_window(fs); /* Write-back changes */ +#endif + if (res == FR_OK) { /* Fill sector window with new data */ + if (disk_read(fs->pdrv, fs->win, sector, 1) != RES_OK) { + sector = 0xFFFFFFFF; /* Invalidate window if read data is not valid */ + res = FR_DISK_ERR; + } + fs->winsect = sector; + } + } + return res; +} + + + + +#if !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Synchronize filesystem and data on the storage */ +/*-----------------------------------------------------------------------*/ + +static FRESULT sync_fs ( /* Returns FR_OK or FR_DISK_ERR */ + FATFS* fs /* Filesystem object */ +) +{ + FRESULT res; + + + res = sync_window(fs); + if (res == FR_OK) { + if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) { /* FAT32: Update FSInfo sector if needed */ + /* Create FSInfo structure */ + mem_set(fs->win, 0, sizeof fs->win); + st_word(fs->win + BS_55AA, 0xAA55); + st_dword(fs->win + FSI_LeadSig, 0x41615252); + st_dword(fs->win + FSI_StrucSig, 0x61417272); + st_dword(fs->win + FSI_Free_Count, fs->free_clst); + st_dword(fs->win + FSI_Nxt_Free, fs->last_clst); + /* Write it into the FSInfo sector */ + fs->winsect = fs->volbase + 1; + disk_write(fs->pdrv, fs->win, fs->winsect, 1); + fs->fsi_flag = 0; + } + /* Make sure that no pending write process in the lower layer */ + if (disk_ioctl(fs->pdrv, CTRL_SYNC, 0) != RES_OK) res = FR_DISK_ERR; + } + + return res; +} + +#endif + + + +/*-----------------------------------------------------------------------*/ +/* Get physical sector number from cluster number */ +/*-----------------------------------------------------------------------*/ + +static DWORD clst2sect ( /* !=0:Sector number, 0:Failed (invalid cluster#) */ + FATFS* fs, /* Filesystem object */ + DWORD clst /* Cluster# to be converted */ +) +{ + clst -= 2; /* Cluster number is origin from 2 */ + if (clst >= fs->n_fatent - 2) return 0; /* Is it invalid cluster number? */ + return fs->database + fs->csize * clst; /* Start sector number of the cluster */ +} + + + + +/*-----------------------------------------------------------------------*/ +/* FAT access - Read value of a FAT entry */ +/*-----------------------------------------------------------------------*/ + +static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFFF:Cluster status */ + FFOBJID* obj, /* Corresponding object */ + DWORD clst /* Cluster number to get the value */ +) +{ + UINT wc, bc; + DWORD val; + FATFS *fs = obj->fs; + + + if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */ + val = 1; /* Internal error */ + + } else { + val = 0xFFFFFFFF; /* Default value falls on disk error */ + + switch (fs->fs_type) { + case FS_FAT12 : + bc = (UINT)clst; bc += bc / 2; + if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break; + wc = fs->win[bc++ % SS(fs)]; /* Get 1st byte of the entry */ + if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break; + wc |= fs->win[bc % SS(fs)] << 8; /* Merge 2nd byte of the entry */ + val = (clst & 1) ? (wc >> 4) : (wc & 0xFFF); /* Adjust bit position */ + break; + + case FS_FAT16 : + if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))) != FR_OK) break; + val = ld_word(fs->win + clst * 2 % SS(fs)); /* Simple WORD array */ + break; + + case FS_FAT32 : + if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break; + val = ld_dword(fs->win + clst * 4 % SS(fs)) & 0x0FFFFFFF; /* Simple DWORD array but mask out upper 4 bits */ + break; +#if FF_FS_EXFAT + case FS_EXFAT : + if ((obj->objsize != 0 && obj->sclust != 0) || obj->stat == 0) { /* Object except root dir must have valid data length */ + DWORD cofs = clst - obj->sclust; /* Offset from start cluster */ + DWORD clen = (DWORD)((obj->objsize - 1) / SS(fs)) / fs->csize; /* Number of clusters - 1 */ + + if (obj->stat == 2 && cofs <= clen) { /* Is it a contiguous chain? */ + val = (cofs == clen) ? 0x7FFFFFFF : clst + 1; /* No data on the FAT, generate the value */ + break; + } + if (obj->stat == 3 && cofs < obj->n_cont) { /* Is it in the 1st fragment? */ + val = clst + 1; /* Generate the value */ + break; + } + if (obj->stat != 2) { /* Get value from FAT if FAT chain is valid */ + if (obj->n_frag != 0) { /* Is it on the growing edge? */ + val = 0x7FFFFFFF; /* Generate EOC */ + } else { + if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break; + val = ld_dword(fs->win + clst * 4 % SS(fs)) & 0x7FFFFFFF; + } + break; + } + } + /* go to default */ +#endif + default: + val = 1; /* Internal error */ + } + } + + return val; +} + + + + +#if !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* FAT access - Change value of a FAT entry */ +/*-----------------------------------------------------------------------*/ + +static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */ + FATFS* fs, /* Corresponding filesystem object */ + DWORD clst, /* FAT index number (cluster number) to be changed */ + DWORD val /* New value to be set to the entry */ +) +{ + UINT bc; + BYTE *p; + FRESULT res = FR_INT_ERR; + + + if (clst >= 2 && clst < fs->n_fatent) { /* Check if in valid range */ + switch (fs->fs_type) { + case FS_FAT12 : + bc = (UINT)clst; bc += bc / 2; /* bc: byte offset of the entry */ + res = move_window(fs, fs->fatbase + (bc / SS(fs))); + if (res != FR_OK) break; + p = fs->win + bc++ % SS(fs); + *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; /* Put 1st byte */ + fs->wflag = 1; + res = move_window(fs, fs->fatbase + (bc / SS(fs))); + if (res != FR_OK) break; + p = fs->win + bc % SS(fs); + *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); /* Put 2nd byte */ + fs->wflag = 1; + break; + + case FS_FAT16 : + res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))); + if (res != FR_OK) break; + st_word(fs->win + clst * 2 % SS(fs), (WORD)val); /* Simple WORD array */ + fs->wflag = 1; + break; + + case FS_FAT32 : +#if FF_FS_EXFAT + case FS_EXFAT : +#endif + res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))); + if (res != FR_OK) break; + if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { + val = (val & 0x0FFFFFFF) | (ld_dword(fs->win + clst * 4 % SS(fs)) & 0xF0000000); + } + st_dword(fs->win + clst * 4 % SS(fs), val); + fs->wflag = 1; + break; + } + } + return res; +} + +#endif /* !FF_FS_READONLY */ + + + + +#if FF_FS_EXFAT && !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* exFAT: Accessing FAT and Allocation Bitmap */ +/*-----------------------------------------------------------------------*/ + +/*--------------------------------------*/ +/* Find a contiguous free cluster block */ +/*--------------------------------------*/ + +static DWORD find_bitmap ( /* 0:Not found, 2..:Cluster block found, 0xFFFFFFFF:Disk error */ + FATFS* fs, /* Filesystem object */ + DWORD clst, /* Cluster number to scan from */ + DWORD ncl /* Number of contiguous clusters to find (1..) */ +) +{ + BYTE bm, bv; + UINT i; + DWORD val, scl, ctr; + + + clst -= 2; /* The first bit in the bitmap corresponds to cluster #2 */ + if (clst >= fs->n_fatent - 2) clst = 0; + scl = val = clst; ctr = 0; + for (;;) { + if (move_window(fs, fs->bitbase + val / 8 / SS(fs)) != FR_OK) return 0xFFFFFFFF; + i = val / 8 % SS(fs); bm = 1 << (val % 8); + do { + do { + bv = fs->win[i] & bm; bm <<= 1; /* Get bit value */ + if (++val >= fs->n_fatent - 2) { /* Next cluster (with wrap-around) */ + val = 0; bm = 0; i = SS(fs); + } + if (bv == 0) { /* Is it a free cluster? */ + if (++ctr == ncl) return scl + 2; /* Check if run length is sufficient for required */ + } else { + scl = val; ctr = 0; /* Encountered a cluster in-use, restart to scan */ + } + if (val == clst) return 0; /* All cluster scanned? */ + } while (bm != 0); + bm = 1; + } while (++i < SS(fs)); + } +} + + +/*----------------------------------------*/ +/* Set/Clear a block of allocation bitmap */ +/*----------------------------------------*/ + +static FRESULT change_bitmap ( + FATFS* fs, /* Filesystem object */ + DWORD clst, /* Cluster number to change from */ + DWORD ncl, /* Number of clusters to be changed */ + int bv /* bit value to be set (0 or 1) */ +) +{ + BYTE bm; + UINT i; + DWORD sect; + + + clst -= 2; /* The first bit corresponds to cluster #2 */ + sect = fs->bitbase + clst / 8 / SS(fs); /* Sector address */ + i = clst / 8 % SS(fs); /* Byte offset in the sector */ + bm = 1 << (clst % 8); /* Bit mask in the byte */ + for (;;) { + if (move_window(fs, sect++) != FR_OK) return FR_DISK_ERR; + do { + do { + if (bv == (int)((fs->win[i] & bm) != 0)) return FR_INT_ERR; /* Is the bit expected value? */ + fs->win[i] ^= bm; /* Flip the bit */ + fs->wflag = 1; + if (--ncl == 0) return FR_OK; /* All bits processed? */ + } while (bm <<= 1); /* Next bit */ + bm = 1; + } while (++i < SS(fs)); /* Next byte */ + i = 0; + } +} + + +/*---------------------------------------------*/ +/* Fill the first fragment of the FAT chain */ +/*---------------------------------------------*/ + +static FRESULT fill_first_frag ( + FFOBJID* obj /* Pointer to the corresponding object */ +) +{ + FRESULT res; + DWORD cl, n; + + + if (obj->stat == 3) { /* Has the object been changed 'fragmented' in this session? */ + for (cl = obj->sclust, n = obj->n_cont; n; cl++, n--) { /* Create cluster chain on the FAT */ + res = put_fat(obj->fs, cl, cl + 1); + if (res != FR_OK) return res; + } + obj->stat = 0; /* Change status 'FAT chain is valid' */ + } + return FR_OK; +} + + +/*---------------------------------------------*/ +/* Fill the last fragment of the FAT chain */ +/*---------------------------------------------*/ + +static FRESULT fill_last_frag ( + FFOBJID* obj, /* Pointer to the corresponding object */ + DWORD lcl, /* Last cluster of the fragment */ + DWORD term /* Value to set the last FAT entry */ +) +{ + FRESULT res; + + + while (obj->n_frag > 0) { /* Create the chain of last fragment */ + res = put_fat(obj->fs, lcl - obj->n_frag + 1, (obj->n_frag > 1) ? lcl - obj->n_frag + 2 : term); + if (res != FR_OK) return res; + obj->n_frag--; + } + return FR_OK; +} + +#endif /* FF_FS_EXFAT && !FF_FS_READONLY */ + + + +#if !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* FAT handling - Remove a cluster chain */ +/*-----------------------------------------------------------------------*/ + +static FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */ + FFOBJID* obj, /* Corresponding object */ + DWORD clst, /* Cluster to remove a chain from */ + DWORD pclst /* Previous cluster of clst (0 if entire chain) */ +) +{ + FRESULT res = FR_OK; + DWORD nxt; + FATFS *fs = obj->fs; +#if FF_FS_EXFAT || FF_USE_TRIM + DWORD scl = clst, ecl = clst; +#endif +#if FF_USE_TRIM + DWORD rt[2]; +#endif + + if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR; /* Check if in valid range */ + + /* Mark the previous cluster 'EOC' on the FAT if it exists */ + if (pclst != 0 && (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT || obj->stat != 2)) { + res = put_fat(fs, pclst, 0xFFFFFFFF); + if (res != FR_OK) return res; + } + + /* Remove the chain */ + do { + nxt = get_fat(obj, clst); /* Get cluster status */ + if (nxt == 0) break; /* Empty cluster? */ + if (nxt == 1) return FR_INT_ERR; /* Internal error? */ + if (nxt == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error? */ + if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { + res = put_fat(fs, clst, 0); /* Mark the cluster 'free' on the FAT */ + if (res != FR_OK) return res; + } + if (fs->free_clst < fs->n_fatent - 2) { /* Update FSINFO */ + fs->free_clst++; + fs->fsi_flag |= 1; + } +#if FF_FS_EXFAT || FF_USE_TRIM + if (ecl + 1 == nxt) { /* Is next cluster contiguous? */ + ecl = nxt; + } else { /* End of contiguous cluster block */ +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + res = change_bitmap(fs, scl, ecl - scl + 1, 0); /* Mark the cluster block 'free' on the bitmap */ + if (res != FR_OK) return res; + } +#endif +#if FF_USE_TRIM + rt[0] = clst2sect(fs, scl); /* Start of data area freed */ + rt[1] = clst2sect(fs, ecl) + fs->csize - 1; /* End of data area freed */ + disk_ioctl(fs->pdrv, CTRL_TRIM, rt); /* Inform device the data in the block is no longer needed */ +#endif + scl = ecl = nxt; + } +#endif + clst = nxt; /* Next cluster */ + } while (clst < fs->n_fatent); /* Repeat while not the last link */ + +#if FF_FS_EXFAT + /* Some post processes for chain status */ + if (fs->fs_type == FS_EXFAT) { + if (pclst == 0) { /* Has the entire chain been removed? */ + obj->stat = 0; /* Change the chain status 'initial' */ + } else { + if (obj->stat == 0) { /* Is it a fragmented chain from the beginning of this session? */ + clst = obj->sclust; /* Follow the chain to check if it gets contiguous */ + while (clst != pclst) { + nxt = get_fat(obj, clst); + if (nxt < 2) return FR_INT_ERR; + if (nxt == 0xFFFFFFFF) return FR_DISK_ERR; + if (nxt != clst + 1) break; /* Not contiguous? */ + clst++; + } + if (clst == pclst) { /* Has the chain got contiguous again? */ + obj->stat = 2; /* Change the chain status 'contiguous' */ + } + } else { + if (obj->stat == 3 && pclst >= obj->sclust && pclst <= obj->sclust + obj->n_cont) { /* Was the chain fragmented in this session and got contiguous again? */ + obj->stat = 2; /* Change the chain status 'contiguous' */ + } + } + } + } +#endif + return FR_OK; +} + + + + +/*-----------------------------------------------------------------------*/ +/* FAT handling - Stretch a chain or Create a new chain */ +/*-----------------------------------------------------------------------*/ + +static DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */ + FFOBJID* obj, /* Corresponding object */ + DWORD clst /* Cluster# to stretch, 0:Create a new chain */ +) +{ + DWORD cs, ncl, scl; + FRESULT res; + FATFS *fs = obj->fs; + + + if (clst == 0) { /* Create a new chain */ + scl = fs->last_clst; /* Suggested cluster to start to find */ + if (scl == 0 || scl >= fs->n_fatent) scl = 1; + } + else { /* Stretch a chain */ + cs = get_fat(obj, clst); /* Check the cluster status */ + if (cs < 2) return 1; /* Test for insanity */ + if (cs == 0xFFFFFFFF) return cs; /* Test for disk error */ + if (cs < fs->n_fatent) return cs; /* It is already followed by next cluster */ + scl = clst; /* Cluster to start to find */ + } + if (fs->free_clst == 0) return 0; /* No free cluster */ + +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + ncl = find_bitmap(fs, scl, 1); /* Find a free cluster */ + if (ncl == 0 || ncl == 0xFFFFFFFF) return ncl; /* No free cluster or hard error? */ + res = change_bitmap(fs, ncl, 1, 1); /* Mark the cluster 'in use' */ + if (res == FR_INT_ERR) return 1; + if (res == FR_DISK_ERR) return 0xFFFFFFFF; + if (clst == 0) { /* Is it a new chain? */ + obj->stat = 2; /* Set status 'contiguous' */ + } else { /* It is a stretched chain */ + if (obj->stat == 2 && ncl != scl + 1) { /* Is the chain got fragmented? */ + obj->n_cont = scl - obj->sclust; /* Set size of the contiguous part */ + obj->stat = 3; /* Change status 'just fragmented' */ + } + } + if (obj->stat != 2) { /* Is the file non-contiguous? */ + if (ncl == clst + 1) { /* Is the cluster next to previous one? */ + obj->n_frag = obj->n_frag ? obj->n_frag + 1 : 2; /* Increment size of last framgent */ + } else { /* New fragment */ + if (obj->n_frag == 0) obj->n_frag = 1; + res = fill_last_frag(obj, clst, ncl); /* Fill last fragment on the FAT and link it to new one */ + if (res == FR_OK) obj->n_frag = 1; + } + } + } else +#endif + { /* On the FAT/FAT32 volume */ + ncl = 0; + if (scl == clst) { /* Stretching an existing chain? */ + ncl = scl + 1; /* Test if next cluster is free */ + if (ncl >= fs->n_fatent) ncl = 2; + cs = get_fat(obj, ncl); /* Get next cluster status */ + if (cs == 1 || cs == 0xFFFFFFFF) return cs; /* Test for error */ + if (cs != 0) { /* Not free? */ + cs = fs->last_clst; /* Start at suggested cluster if it is valid */ + if (cs >= 2 && cs < fs->n_fatent) scl = cs; + ncl = 0; + } + } + if (ncl == 0) { /* The new cluster cannot be contiguous and find another fragment */ + ncl = scl; /* Start cluster */ + for (;;) { + ncl++; /* Next cluster */ + if (ncl >= fs->n_fatent) { /* Check wrap-around */ + ncl = 2; + if (ncl > scl) return 0; /* No free cluster found? */ + } + cs = get_fat(obj, ncl); /* Get the cluster status */ + if (cs == 0) break; /* Found a free cluster? */ + if (cs == 1 || cs == 0xFFFFFFFF) return cs; /* Test for error */ + if (ncl == scl) return 0; /* No free cluster found? */ + } + } + res = put_fat(fs, ncl, 0xFFFFFFFF); /* Mark the new cluster 'EOC' */ + if (res == FR_OK && clst != 0) { + res = put_fat(fs, clst, ncl); /* Link it from the previous one if needed */ + } + } + + if (res == FR_OK) { /* Update FSINFO if function succeeded. */ + fs->last_clst = ncl; + if (fs->free_clst <= fs->n_fatent - 2) fs->free_clst--; + fs->fsi_flag |= 1; + } else { + ncl = (res == FR_DISK_ERR) ? 0xFFFFFFFF : 1; /* Failed. Generate error status */ + } + + return ncl; /* Return new cluster number or error status */ +} + +#endif /* !FF_FS_READONLY */ + + + + +#if FF_USE_FASTSEEK +/*-----------------------------------------------------------------------*/ +/* FAT handling - Convert offset into cluster with link map table */ +/*-----------------------------------------------------------------------*/ + +static DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */ + FIL* fp, /* Pointer to the file object */ + FSIZE_t ofs /* File offset to be converted to cluster# */ +) +{ + DWORD cl, ncl, *tbl; + FATFS *fs = fp->obj.fs; + + + tbl = fp->cltbl + 1; /* Top of CLMT */ + cl = (DWORD)(ofs / SS(fs) / fs->csize); /* Cluster order from top of the file */ + for (;;) { + ncl = *tbl++; /* Number of cluters in the fragment */ + if (ncl == 0) return 0; /* End of table? (error) */ + if (cl < ncl) break; /* In this fragment? */ + cl -= ncl; tbl++; /* Next fragment */ + } + return cl + *tbl; /* Return the cluster number */ +} + +#endif /* FF_USE_FASTSEEK */ + + + + +/*-----------------------------------------------------------------------*/ +/* Directory handling - Fill a cluster with zeros */ +/*-----------------------------------------------------------------------*/ + +#if !FF_FS_READONLY +static FRESULT dir_clear ( /* Returns FR_OK or FR_DISK_ERR */ + FATFS *fs, /* Filesystem object */ + DWORD clst /* Directory table to clear */ +) +{ + DWORD sect; + UINT n, szb; + BYTE *ibuf; + + + if (sync_window(fs) != FR_OK) return FR_DISK_ERR; /* Flush disk access window */ + sect = clst2sect(fs, clst); /* Top of the cluster */ + fs->winsect = sect; /* Set window to top of the cluster */ + mem_set(fs->win, 0, sizeof fs->win); /* Clear window buffer */ +#if FF_USE_LFN == 3 /* Quick table clear by using multi-secter write */ + /* Allocate a temporary buffer */ + for (szb = ((DWORD)fs->csize * SS(fs) >= MAX_MALLOC) ? MAX_MALLOC : fs->csize * SS(fs), ibuf = 0; szb > SS(fs) && (ibuf = ff_memalloc(szb)) == 0; szb /= 2) ; + if (szb > SS(fs)) { /* Buffer allocated? */ + mem_set(ibuf, 0, szb); + szb /= SS(fs); /* Bytes -> Sectors */ + for (n = 0; n < fs->csize && disk_write(fs->pdrv, ibuf, sect + n, szb) == RES_OK; n += szb) ; /* Fill the cluster with 0 */ + ff_memfree(ibuf); + } else +#endif + { + ibuf = fs->win; szb = 1; /* Use window buffer (many single-sector writes may take a time) */ + for (n = 0; n < fs->csize && disk_write(fs->pdrv, ibuf, sect + n, szb) == RES_OK; n += szb) ; /* Fill the cluster with 0 */ + } + return (n == fs->csize) ? FR_OK : FR_DISK_ERR; +} +#endif /* !FF_FS_READONLY */ + + + + +/*-----------------------------------------------------------------------*/ +/* Directory handling - Set directory index */ +/*-----------------------------------------------------------------------*/ + +static FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */ + DIR* dp, /* Pointer to directory object */ + DWORD ofs /* Offset of directory table */ +) +{ + DWORD csz, clst; + FATFS *fs = dp->obj.fs; + + + if (ofs >= (DWORD)((FF_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR) || ofs % SZDIRE) { /* Check range of offset and alignment */ + return FR_INT_ERR; + } + dp->dptr = ofs; /* Set current offset */ + clst = dp->obj.sclust; /* Table start cluster (0:root) */ + if (clst == 0 && fs->fs_type >= FS_FAT32) { /* Replace cluster# 0 with root cluster# */ + clst = fs->dirbase; + if (FF_FS_EXFAT) dp->obj.stat = 0; /* exFAT: Root dir has an FAT chain */ + } + + if (clst == 0) { /* Static table (root-directory on the FAT volume) */ + if (ofs / SZDIRE >= fs->n_rootdir) return FR_INT_ERR; /* Is index out of range? */ + dp->sect = fs->dirbase; + + } else { /* Dynamic table (sub-directory or root-directory on the FAT32/exFAT volume) */ + csz = (DWORD)fs->csize * SS(fs); /* Bytes per cluster */ + while (ofs >= csz) { /* Follow cluster chain */ + clst = get_fat(&dp->obj, clst); /* Get next cluster */ + if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */ + if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR; /* Reached to end of table or internal error */ + ofs -= csz; + } + dp->sect = clst2sect(fs, clst); + } + dp->clust = clst; /* Current cluster# */ + if (dp->sect == 0) return FR_INT_ERR; + dp->sect += ofs / SS(fs); /* Sector# of the directory entry */ + dp->dir = fs->win + (ofs % SS(fs)); /* Pointer to the entry in the win[] */ + + return FR_OK; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Directory handling - Move directory table index next */ +/*-----------------------------------------------------------------------*/ + +static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */ + DIR* dp, /* Pointer to the directory object */ + int stretch /* 0: Do not stretch table, 1: Stretch table if needed */ +) +{ + DWORD ofs, clst; + FATFS *fs = dp->obj.fs; + + + ofs = dp->dptr + SZDIRE; /* Next entry */ + if (ofs >= (DWORD)((FF_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR)) dp->sect = 0; /* Disable it if the offset reached the max value */ + if (dp->sect == 0) return FR_NO_FILE; /* Report EOT if it has been disabled */ + + if (ofs % SS(fs) == 0) { /* Sector changed? */ + dp->sect++; /* Next sector */ + + if (dp->clust == 0) { /* Static table */ + if (ofs / SZDIRE >= fs->n_rootdir) { /* Report EOT if it reached end of static table */ + dp->sect = 0; return FR_NO_FILE; + } + } + else { /* Dynamic table */ + if ((ofs / SS(fs) & (fs->csize - 1)) == 0) { /* Cluster changed? */ + clst = get_fat(&dp->obj, dp->clust); /* Get next cluster */ + if (clst <= 1) return FR_INT_ERR; /* Internal error */ + if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */ + if (clst >= fs->n_fatent) { /* It reached end of dynamic table */ +#if !FF_FS_READONLY + if (!stretch) { /* If no stretch, report EOT */ + dp->sect = 0; return FR_NO_FILE; + } + clst = create_chain(&dp->obj, dp->clust); /* Allocate a cluster */ + if (clst == 0) return FR_DENIED; /* No free cluster */ + if (clst == 1) return FR_INT_ERR; /* Internal error */ + if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */ + if (dir_clear(fs, clst) != FR_OK) return FR_DISK_ERR; /* Clean up the stretched table */ + if (FF_FS_EXFAT) dp->obj.stat |= 4; /* exFAT: The directory has been stretched */ +#else + if (!stretch) dp->sect = 0; /* (this line is to suppress compiler warning) */ + dp->sect = 0; return FR_NO_FILE; /* Report EOT */ +#endif + } + dp->clust = clst; /* Initialize data for new cluster */ + dp->sect = clst2sect(fs, clst); + } + } + } + dp->dptr = ofs; /* Current entry */ + dp->dir = fs->win + ofs % SS(fs); /* Pointer to the entry in the win[] */ + + return FR_OK; +} + + + + +#if !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Directory handling - Reserve a block of directory entries */ +/*-----------------------------------------------------------------------*/ + +static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */ + DIR* dp, /* Pointer to the directory object */ + UINT nent /* Number of contiguous entries to allocate */ +) +{ + FRESULT res; + UINT n; + FATFS *fs = dp->obj.fs; + + + res = dir_sdi(dp, 0); + if (res == FR_OK) { + n = 0; + do { + res = move_window(fs, dp->sect); + if (res != FR_OK) break; +#if FF_FS_EXFAT + if ((fs->fs_type == FS_EXFAT) ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) { +#else + if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) { +#endif + if (++n == nent) break; /* A block of contiguous free entries is found */ + } else { + n = 0; /* Not a blank entry. Restart to search */ + } + res = dir_next(dp, 1); + } while (res == FR_OK); /* Next entry with table stretch enabled */ + } + + if (res == FR_NO_FILE) res = FR_DENIED; /* No directory entry to allocate */ + return res; +} + +#endif /* !FF_FS_READONLY */ + + + + +/*-----------------------------------------------------------------------*/ +/* FAT: Directory handling - Load/Store start cluster number */ +/*-----------------------------------------------------------------------*/ + +static DWORD ld_clust ( /* Returns the top cluster value of the SFN entry */ + FATFS* fs, /* Pointer to the fs object */ + const BYTE* dir /* Pointer to the key entry */ +) +{ + DWORD cl; + + cl = ld_word(dir + DIR_FstClusLO); + if (fs->fs_type == FS_FAT32) { + cl |= (DWORD)ld_word(dir + DIR_FstClusHI) << 16; + } + + return cl; +} + + +#if !FF_FS_READONLY +static void st_clust ( + FATFS* fs, /* Pointer to the fs object */ + BYTE* dir, /* Pointer to the key entry */ + DWORD cl /* Value to be set */ +) +{ + st_word(dir + DIR_FstClusLO, (WORD)cl); + if (fs->fs_type == FS_FAT32) { + st_word(dir + DIR_FstClusHI, (WORD)(cl >> 16)); + } +} +#endif + + + +#if FF_USE_LFN +/*--------------------------------------------------------*/ +/* FAT-LFN: Compare a part of file name with an LFN entry */ +/*--------------------------------------------------------*/ + +static int cmp_lfn ( /* 1:matched, 0:not matched */ + const WCHAR* lfnbuf, /* Pointer to the LFN working buffer to be compared */ + BYTE* dir /* Pointer to the directory entry containing the part of LFN */ +) +{ + UINT i, s; + WCHAR wc, uc; + + + if (ld_word(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO */ + + i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the LFN buffer */ + + for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */ + uc = ld_word(dir + LfnOfs[s]); /* Pick an LFN character */ + if (wc != 0) { + if (i >= FF_MAX_LFN + 1 || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) { /* Compare it */ + return 0; /* Not matched */ + } + wc = uc; + } else { + if (uc != 0xFFFF) return 0; /* Check filler */ + } + } + + if ((dir[LDIR_Ord] & LLEF) && wc && lfnbuf[i]) return 0; /* Last segment matched but different length */ + + return 1; /* The part of LFN matched */ +} + + +#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 || FF_USE_LABEL || FF_FS_EXFAT +/*-----------------------------------------------------*/ +/* FAT-LFN: Pick a part of file name from an LFN entry */ +/*-----------------------------------------------------*/ + +static int pick_lfn ( /* 1:succeeded, 0:buffer overflow or invalid LFN entry */ + WCHAR* lfnbuf, /* Pointer to the LFN working buffer */ + BYTE* dir /* Pointer to the LFN entry */ +) +{ + UINT i, s; + WCHAR wc, uc; + + + if (ld_word(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO is 0 */ + + i = ((dir[LDIR_Ord] & ~LLEF) - 1) * 13; /* Offset in the LFN buffer */ + + for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */ + uc = ld_word(dir + LfnOfs[s]); /* Pick an LFN character */ + if (wc != 0) { + if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */ + lfnbuf[i++] = wc = uc; /* Store it */ + } else { + if (uc != 0xFFFF) return 0; /* Check filler */ + } + } + + if (dir[LDIR_Ord] & LLEF && wc != 0) { /* Put terminator if it is the last LFN part and not terminated */ + if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */ + lfnbuf[i] = 0; + } + + return 1; /* The part of LFN is valid */ +} +#endif + + +#if !FF_FS_READONLY +/*-----------------------------------------*/ +/* FAT-LFN: Create an entry of LFN entries */ +/*-----------------------------------------*/ + +static void put_lfn ( + const WCHAR* lfn, /* Pointer to the LFN */ + BYTE* dir, /* Pointer to the LFN entry to be created */ + BYTE ord, /* LFN order (1-20) */ + BYTE sum /* Checksum of the corresponding SFN */ +) +{ + UINT i, s; + WCHAR wc; + + + dir[LDIR_Chksum] = sum; /* Set checksum */ + dir[LDIR_Attr] = AM_LFN; /* Set attribute. LFN entry */ + dir[LDIR_Type] = 0; + st_word(dir + LDIR_FstClusLO, 0); + + i = (ord - 1) * 13; /* Get offset in the LFN working buffer */ + s = wc = 0; + do { + if (wc != 0xFFFF) wc = lfn[i++]; /* Get an effective character */ + st_word(dir + LfnOfs[s], wc); /* Put it */ + if (wc == 0) wc = 0xFFFF; /* Padding characters for left locations */ + } while (++s < 13); + if (wc == 0xFFFF || !lfn[i]) ord |= LLEF; /* Last LFN part is the start of LFN sequence */ + dir[LDIR_Ord] = ord; /* Set the LFN order */ +} + +#endif /* !FF_FS_READONLY */ +#endif /* FF_USE_LFN */ + + + +#if FF_USE_LFN && !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* FAT-LFN: Create a Numbered SFN */ +/*-----------------------------------------------------------------------*/ + +static void gen_numname ( + BYTE* dst, /* Pointer to the buffer to store numbered SFN */ + const BYTE* src, /* Pointer to SFN */ + const WCHAR* lfn, /* Pointer to LFN */ + UINT seq /* Sequence number */ +) +{ + BYTE ns[8], c; + UINT i, j; + WCHAR wc; + DWORD sr; + + + mem_cpy(dst, src, 11); + + if (seq > 5) { /* In case of many collisions, generate a hash number instead of sequential number */ + sr = seq; + while (*lfn) { /* Create a CRC as hash value */ + wc = *lfn++; + for (i = 0; i < 16; i++) { + sr = (sr << 1) + (wc & 1); + wc >>= 1; + if (sr & 0x10000) sr ^= 0x11021; + } + } + seq = (UINT)sr; + } + + /* itoa (hexdecimal) */ + i = 7; + do { + c = (BYTE)((seq % 16) + '0'); + if (c > '9') c += 7; + ns[i--] = c; + seq /= 16; + } while (seq); + ns[i] = '~'; + + /* Append the number to the SFN body */ + for (j = 0; j < i && dst[j] != ' '; j++) { + if (dbc_1st(dst[j])) { + if (j == i - 1) break; + j++; + } + } + do { + dst[j++] = (i < 8) ? ns[i++] : ' '; + } while (j < 8); +} +#endif /* FF_USE_LFN && !FF_FS_READONLY */ + + + +#if FF_USE_LFN +/*-----------------------------------------------------------------------*/ +/* FAT-LFN: Calculate checksum of an SFN entry */ +/*-----------------------------------------------------------------------*/ + +static BYTE sum_sfn ( + const BYTE* dir /* Pointer to the SFN entry */ +) +{ + BYTE sum = 0; + UINT n = 11; + + do { + sum = (sum >> 1) + (sum << 7) + *dir++; + } while (--n); + return sum; +} + +#endif /* FF_USE_LFN */ + + + +#if FF_FS_EXFAT +/*-----------------------------------------------------------------------*/ +/* exFAT: Checksum */ +/*-----------------------------------------------------------------------*/ + +static WORD xdir_sum ( /* Get checksum of the directoly entry block */ + const BYTE* dir /* Directory entry block to be calculated */ +) +{ + UINT i, szblk; + WORD sum; + + + szblk = (dir[XDIR_NumSec] + 1) * SZDIRE; /* Number of bytes of the entry block */ + for (i = sum = 0; i < szblk; i++) { + if (i == XDIR_SetSum) { /* Skip 2-byte sum field */ + i++; + } else { + sum = ((sum & 1) ? 0x8000 : 0) + (sum >> 1) + dir[i]; + } + } + return sum; +} + + + +static WORD xname_sum ( /* Get check sum (to be used as hash) of the file name */ + const WCHAR* name /* File name to be calculated */ +) +{ + WCHAR chr; + WORD sum = 0; + + + while ((chr = *name++) != 0) { + chr = (WCHAR)ff_wtoupper(chr); /* File name needs to be up-case converted */ + sum = ((sum & 1) ? 0x8000 : 0) + (sum >> 1) + (chr & 0xFF); + sum = ((sum & 1) ? 0x8000 : 0) + (sum >> 1) + (chr >> 8); + } + return sum; +} + + +#if !FF_FS_READONLY && FF_USE_MKFS +static DWORD xsum32 ( /* Returns 32-bit checksum */ + BYTE dat, /* Byte to be calculated (byte-by-byte processing) */ + DWORD sum /* Previous sum value */ +) +{ + sum = ((sum & 1) ? 0x80000000 : 0) + (sum >> 1) + dat; + return sum; +} +#endif + + +#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 +/*------------------------------------------------------*/ +/* exFAT: Get object information from a directory block */ +/*------------------------------------------------------*/ + +static void get_xfileinfo ( + BYTE* dirb, /* Pointer to the direcotry entry block 85+C0+C1s */ + FILINFO* fno /* Buffer to store the extracted file information */ +) +{ + WCHAR wc, hs; + UINT di, si, nc; + + /* Get file name from the entry block */ + si = SZDIRE * 2; /* 1st C1 entry */ + nc = 0; hs = 0; di = 0; + while (nc < dirb[XDIR_NumName]) { + if (si >= MAXDIRB(FF_MAX_LFN)) { di = 0; break; } /* Truncated directory block? */ + if ((si % SZDIRE) == 0) si += 2; /* Skip entry type field */ + wc = ld_word(dirb + si); si += 2; nc++; /* Get a character */ + if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */ + hs = wc; continue; /* Get low surrogate */ + } + wc = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */ + if (wc == 0) { di = 0; break; } /* Buffer overflow or wrong encoding? */ + di += wc; + hs = 0; + } + if (hs != 0) di = 0; /* Broken surrogate pair? */ + if (di == 0) fno->fname[di++] = '?'; /* Inaccessible object name? */ + fno->fname[di] = 0; /* Terminate the name */ + fno->altname[0] = 0; /* exFAT does not support SFN */ + + fno->fattrib = dirb[XDIR_Attr]; /* Attribute */ + fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_qword(dirb + XDIR_FileSize); /* Size */ + fno->ftime = ld_word(dirb + XDIR_ModTime + 0); /* Time */ + fno->fdate = ld_word(dirb + XDIR_ModTime + 2); /* Date */ +} + +#endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */ + + +/*-----------------------------------*/ +/* exFAT: Get a directry entry block */ +/*-----------------------------------*/ + +static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */ + DIR* dp /* Reading direcotry object pointing top of the entry block to load */ +) +{ + FRESULT res; + UINT i, sz_ent; + BYTE* dirb = dp->obj.fs->dirbuf; /* Pointer to the on-memory direcotry entry block 85+C0+C1s */ + + + /* Load file-directory entry */ + res = move_window(dp->obj.fs, dp->sect); + if (res != FR_OK) return res; + if (dp->dir[XDIR_Type] != ET_FILEDIR) return FR_INT_ERR; /* Invalid order */ + mem_cpy(dirb + 0 * SZDIRE, dp->dir, SZDIRE); + sz_ent = (dirb[XDIR_NumSec] + 1) * SZDIRE; + if (sz_ent < 3 * SZDIRE || sz_ent > 19 * SZDIRE) return FR_INT_ERR; + + /* Load stream-extension entry */ + res = dir_next(dp, 0); + if (res == FR_NO_FILE) res = FR_INT_ERR; /* It cannot be */ + if (res != FR_OK) return res; + res = move_window(dp->obj.fs, dp->sect); + if (res != FR_OK) return res; + if (dp->dir[XDIR_Type] != ET_STREAM) return FR_INT_ERR; /* Invalid order */ + mem_cpy(dirb + 1 * SZDIRE, dp->dir, SZDIRE); + if (MAXDIRB(dirb[XDIR_NumName]) > sz_ent) return FR_INT_ERR; + + /* Load file-name entries */ + i = 2 * SZDIRE; /* Name offset to load */ + do { + res = dir_next(dp, 0); + if (res == FR_NO_FILE) res = FR_INT_ERR; /* It cannot be */ + if (res != FR_OK) return res; + res = move_window(dp->obj.fs, dp->sect); + if (res != FR_OK) return res; + if (dp->dir[XDIR_Type] != ET_FILENAME) return FR_INT_ERR; /* Invalid order */ + if (i < MAXDIRB(FF_MAX_LFN)) mem_cpy(dirb + i, dp->dir, SZDIRE); + } while ((i += SZDIRE) < sz_ent); + + /* Sanity check (do it for only accessible object) */ + if (i <= MAXDIRB(FF_MAX_LFN)) { + if (xdir_sum(dirb) != ld_word(dirb + XDIR_SetSum)) return FR_INT_ERR; + } + return FR_OK; +} + + +/*------------------------------------------------------------------*/ +/* exFAT: Initialize object allocation info with loaded entry block */ +/*------------------------------------------------------------------*/ + +static void init_alloc_info ( + FATFS* fs, /* Filesystem object */ + FFOBJID* obj /* Object allocation information to be initialized */ +) +{ + obj->sclust = ld_dword(fs->dirbuf + XDIR_FstClus); /* Start cluster */ + obj->objsize = ld_qword(fs->dirbuf + XDIR_FileSize); /* Size */ + obj->stat = fs->dirbuf[XDIR_GenFlags] & 2; /* Allocation status */ + obj->n_frag = 0; /* No last fragment info */ +} + + + +#if !FF_FS_READONLY || FF_FS_RPATH != 0 +/*------------------------------------------------*/ +/* exFAT: Load the object's directory entry block */ +/*------------------------------------------------*/ + +static FRESULT load_obj_xdir ( + DIR* dp, /* Blank directory object to be used to access containing direcotry */ + const FFOBJID* obj /* Object with its containing directory information */ +) +{ + FRESULT res; + + /* Open object containing directory */ + dp->obj.fs = obj->fs; + dp->obj.sclust = obj->c_scl; + dp->obj.stat = (BYTE)obj->c_size; + dp->obj.objsize = obj->c_size & 0xFFFFFF00; + dp->obj.n_frag = 0; + dp->blk_ofs = obj->c_ofs; + + res = dir_sdi(dp, dp->blk_ofs); /* Goto object's entry block */ + if (res == FR_OK) { + res = load_xdir(dp); /* Load the object's entry block */ + } + return res; +} +#endif + + +#if !FF_FS_READONLY +/*----------------------------------------*/ +/* exFAT: Store the directory entry block */ +/*----------------------------------------*/ + +static FRESULT store_xdir ( + DIR* dp /* Pointer to the direcotry object */ +) +{ + FRESULT res; + UINT nent; + BYTE* dirb = dp->obj.fs->dirbuf; /* Pointer to the direcotry entry block 85+C0+C1s */ + + /* Create set sum */ + st_word(dirb + XDIR_SetSum, xdir_sum(dirb)); + nent = dirb[XDIR_NumSec] + 1; + + /* Store the direcotry entry block to the directory */ + res = dir_sdi(dp, dp->blk_ofs); + while (res == FR_OK) { + res = move_window(dp->obj.fs, dp->sect); + if (res != FR_OK) break; + mem_cpy(dp->dir, dirb, SZDIRE); + dp->obj.fs->wflag = 1; + if (--nent == 0) break; + dirb += SZDIRE; + res = dir_next(dp, 0); + } + return (res == FR_OK || res == FR_DISK_ERR) ? res : FR_INT_ERR; +} + + + +/*-------------------------------------------*/ +/* exFAT: Create a new directory enrty block */ +/*-------------------------------------------*/ + +static void create_xdir ( + BYTE* dirb, /* Pointer to the direcotry entry block buffer */ + const WCHAR* lfn /* Pointer to the object name */ +) +{ + UINT i; + BYTE nc1, nlen; + WCHAR wc; + + + /* Create file-directory and stream-extension entry */ + mem_set(dirb, 0, 2 * SZDIRE); + dirb[0 * SZDIRE + XDIR_Type] = ET_FILEDIR; + dirb[1 * SZDIRE + XDIR_Type] = ET_STREAM; + + /* Create file-name entries */ + i = SZDIRE * 2; /* Top of file_name entries */ + nlen = nc1 = 0; wc = 1; + do { + dirb[i++] = ET_FILENAME; dirb[i++] = 0; + do { /* Fill name field */ + if (wc != 0 && (wc = lfn[nlen]) != 0) nlen++; /* Get a character if exist */ + st_word(dirb + i, wc); /* Store it */ + i += 2; + } while (i % SZDIRE != 0); + nc1++; + } while (lfn[nlen]); /* Fill next entry if any char follows */ + + dirb[XDIR_NumName] = nlen; /* Set name length */ + dirb[XDIR_NumSec] = 1 + nc1; /* Set secondary count (C0 + C1s) */ + st_word(dirb + XDIR_NameHash, xname_sum(lfn)); /* Set name hash */ +} + +#endif /* !FF_FS_READONLY */ +#endif /* FF_FS_EXFAT */ + + + +#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 || FF_USE_LABEL || FF_FS_EXFAT +/*-----------------------------------------------------------------------*/ +/* Read an object from the directory */ +/*-----------------------------------------------------------------------*/ + +#define DIR_READ_FILE(dp) dir_read(dp, 0) +#define DIR_READ_LABEL(dp) dir_read(dp, 1) + +static FRESULT dir_read ( + DIR* dp, /* Pointer to the directory object */ + int vol /* Filtered by 0:file/directory or 1:volume label */ +) +{ + FRESULT res = FR_NO_FILE; + FATFS *fs = dp->obj.fs; + BYTE attr, b; +#if FF_USE_LFN + BYTE ord = 0xFF, sum = 0xFF; +#endif + + while (dp->sect) { + res = move_window(fs, dp->sect); + if (res != FR_OK) break; + b = dp->dir[DIR_Name]; /* Test for the entry type */ + if (b == 0) { + res = FR_NO_FILE; break; /* Reached to end of the directory */ + } +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + if (FF_USE_LABEL && vol) { + if (b == ET_VLABEL) break; /* Volume label entry? */ + } else { + if (b == ET_FILEDIR) { /* Start of the file entry block? */ + dp->blk_ofs = dp->dptr; /* Get location of the block */ + res = load_xdir(dp); /* Load the entry block */ + if (res == FR_OK) { + dp->obj.attr = fs->dirbuf[XDIR_Attr] & AM_MASK; /* Get attribute */ + } + break; + } + } + } else +#endif + { /* On the FAT/FAT32 volume */ + dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK; /* Get attribute */ +#if FF_USE_LFN /* LFN configuration */ + if (b == DDEM || b == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */ + ord = 0xFF; + } else { + if (attr == AM_LFN) { /* An LFN entry is found */ + if (b & LLEF) { /* Is it start of an LFN sequence? */ + sum = dp->dir[LDIR_Chksum]; + b &= (BYTE)~LLEF; ord = b; + dp->blk_ofs = dp->dptr; + } + /* Check LFN validity and capture it */ + ord = (b == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; + } else { /* An SFN entry is found */ + if (ord != 0 || sum != sum_sfn(dp->dir)) { /* Is there a valid LFN? */ + dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */ + } + break; + } + } +#else /* Non LFN configuration */ + if (b != DDEM && b != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */ + break; + } +#endif + } + res = dir_next(dp, 0); /* Next entry */ + if (res != FR_OK) break; + } + + if (res != FR_OK) dp->sect = 0; /* Terminate the read operation on error or EOT */ + return res; +} + +#endif /* FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2 */ + + + +/*-----------------------------------------------------------------------*/ +/* Directory handling - Find an object in the directory */ +/*-----------------------------------------------------------------------*/ + +static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ + DIR* dp /* Pointer to the directory object with the file name */ +) +{ + FRESULT res; + FATFS *fs = dp->obj.fs; + BYTE c; +#if FF_USE_LFN + BYTE a, ord, sum; +#endif + + res = dir_sdi(dp, 0); /* Rewind directory object */ + if (res != FR_OK) return res; +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + BYTE nc; + UINT di, ni; + WORD hash = xname_sum(fs->lfnbuf); /* Hash value of the name to find */ + + while ((res = DIR_READ_FILE(dp)) == FR_OK) { /* Read an item */ +#if FF_MAX_LFN < 255 + if (fs->dirbuf[XDIR_NumName] > FF_MAX_LFN) continue; /* Skip comparison if inaccessible object name */ +#endif + if (ld_word(fs->dirbuf + XDIR_NameHash) != hash) continue; /* Skip comparison if hash mismatched */ + for (nc = fs->dirbuf[XDIR_NumName], di = SZDIRE * 2, ni = 0; nc; nc--, di += 2, ni++) { /* Compare the name */ + if ((di % SZDIRE) == 0) di += 2; + if (ff_wtoupper(ld_word(fs->dirbuf + di)) != ff_wtoupper(fs->lfnbuf[ni])) break; + } + if (nc == 0 && !fs->lfnbuf[ni]) break; /* Name matched? */ + } + return res; + } +#endif + /* On the FAT/FAT32 volume */ +#if FF_USE_LFN + ord = sum = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */ +#endif + do { + res = move_window(fs, dp->sect); + if (res != FR_OK) break; + c = dp->dir[DIR_Name]; + if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ +#if FF_USE_LFN /* LFN configuration */ + dp->obj.attr = a = dp->dir[DIR_Attr] & AM_MASK; + if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ + ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */ + } else { + if (a == AM_LFN) { /* An LFN entry is found */ + if (!(dp->fn[NSFLAG] & NS_NOLFN)) { + if (c & LLEF) { /* Is it start of LFN sequence? */ + sum = dp->dir[LDIR_Chksum]; + c &= (BYTE)~LLEF; ord = c; /* LFN start order */ + dp->blk_ofs = dp->dptr; /* Start offset of LFN */ + } + /* Check validity of the LFN entry and compare it with given name */ + ord = (c == ord && sum == dp->dir[LDIR_Chksum] && cmp_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; + } + } else { /* An SFN entry is found */ + if (ord == 0 && sum == sum_sfn(dp->dir)) break; /* LFN matched? */ + if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dp->dir, dp->fn, 11)) break; /* SFN matched? */ + ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */ + } + } +#else /* Non LFN configuration */ + dp->obj.attr = dp->dir[DIR_Attr] & AM_MASK; + if (!(dp->dir[DIR_Attr] & AM_VOL) && !mem_cmp(dp->dir, dp->fn, 11)) break; /* Is it a valid entry? */ +#endif + res = dir_next(dp, 0); /* Next entry */ + } while (res == FR_OK); + + return res; +} + + + + +#if !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Register an object to the directory */ +/*-----------------------------------------------------------------------*/ + +static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */ + DIR* dp /* Target directory with object name to be created */ +) +{ + FRESULT res; + FATFS *fs = dp->obj.fs; +#if FF_USE_LFN /* LFN configuration */ + UINT n, nlen, nent; + BYTE sn[12], sum; + + + if (dp->fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME; /* Check name validity */ + for (nlen = 0; fs->lfnbuf[nlen]; nlen++) ; /* Get lfn length */ + +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + nent = (nlen + 14) / 15 + 2; /* Number of entries to allocate (85+C0+C1s) */ + res = dir_alloc(dp, nent); /* Allocate directory entries */ + if (res != FR_OK) return res; + dp->blk_ofs = dp->dptr - SZDIRE * (nent - 1); /* Set the allocated entry block offset */ + + if (dp->obj.stat & 4) { /* Has the directory been stretched by new allocation? */ + dp->obj.stat &= ~4; + res = fill_first_frag(&dp->obj); /* Fill the first fragment on the FAT if needed */ + if (res != FR_OK) return res; + res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF); /* Fill the last fragment on the FAT if needed */ + if (res != FR_OK) return res; + if (dp->obj.sclust != 0) { /* Is it a sub-directory? */ + DIR dj; + + res = load_obj_xdir(&dj, &dp->obj); /* Load the object status */ + if (res != FR_OK) return res; + dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */ + st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); /* Update the allocation status */ + st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize); + fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; + res = store_xdir(&dj); /* Store the object status */ + if (res != FR_OK) return res; + } + } + + create_xdir(fs->dirbuf, fs->lfnbuf); /* Create on-memory directory block to be written later */ + return FR_OK; + } +#endif + /* On the FAT/FAT32 volume */ + mem_cpy(sn, dp->fn, 12); + if (sn[NSFLAG] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */ + dp->fn[NSFLAG] = NS_NOLFN; /* Find only SFN */ + for (n = 1; n < 100; n++) { + gen_numname(dp->fn, sn, fs->lfnbuf, n); /* Generate a numbered name */ + res = dir_find(dp); /* Check if the name collides with existing SFN */ + if (res != FR_OK) break; + } + if (n == 100) return FR_DENIED; /* Abort if too many collisions */ + if (res != FR_NO_FILE) return res; /* Abort if the result is other than 'not collided' */ + dp->fn[NSFLAG] = sn[NSFLAG]; + } + + /* Create an SFN with/without LFNs. */ + nent = (sn[NSFLAG] & NS_LFN) ? (nlen + 12) / 13 + 1 : 1; /* Number of entries to allocate */ + res = dir_alloc(dp, nent); /* Allocate entries */ + if (res == FR_OK && --nent) { /* Set LFN entry if needed */ + res = dir_sdi(dp, dp->dptr - nent * SZDIRE); + if (res == FR_OK) { + sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */ + do { /* Store LFN entries in bottom first */ + res = move_window(fs, dp->sect); + if (res != FR_OK) break; + put_lfn(fs->lfnbuf, dp->dir, (BYTE)nent, sum); + fs->wflag = 1; + res = dir_next(dp, 0); /* Next entry */ + } while (res == FR_OK && --nent); + } + } + +#else /* Non LFN configuration */ + res = dir_alloc(dp, 1); /* Allocate an entry for SFN */ + +#endif + + /* Set SFN entry */ + if (res == FR_OK) { + res = move_window(fs, dp->sect); + if (res == FR_OK) { + mem_set(dp->dir, 0, SZDIRE); /* Clean the entry */ + mem_cpy(dp->dir + DIR_Name, dp->fn, 11); /* Put SFN */ +#if FF_USE_LFN + dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */ +#endif + fs->wflag = 1; + } + } + + return res; +} + +#endif /* !FF_FS_READONLY */ + + + +#if !FF_FS_READONLY && FF_FS_MINIMIZE == 0 +/*-----------------------------------------------------------------------*/ +/* Remove an object from the directory */ +/*-----------------------------------------------------------------------*/ + +static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */ + DIR* dp /* Directory object pointing the entry to be removed */ +) +{ + FRESULT res; + FATFS *fs = dp->obj.fs; +#if FF_USE_LFN /* LFN configuration */ + DWORD last = dp->dptr; + + res = (dp->blk_ofs == 0xFFFFFFFF) ? FR_OK : dir_sdi(dp, dp->blk_ofs); /* Goto top of the entry block if LFN is exist */ + if (res == FR_OK) { + do { + res = move_window(fs, dp->sect); + if (res != FR_OK) break; + if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + dp->dir[XDIR_Type] &= 0x7F; /* Clear the entry InUse flag. */ + } else { /* On the FAT/FAT32 volume */ + dp->dir[DIR_Name] = DDEM; /* Mark the entry 'deleted'. */ + } + fs->wflag = 1; + if (dp->dptr >= last) break; /* If reached last entry then all entries of the object has been deleted. */ + res = dir_next(dp, 0); /* Next entry */ + } while (res == FR_OK); + if (res == FR_NO_FILE) res = FR_INT_ERR; + } +#else /* Non LFN configuration */ + + res = move_window(fs, dp->sect); + if (res == FR_OK) { + dp->dir[DIR_Name] = DDEM; /* Mark the entry 'deleted'.*/ + fs->wflag = 1; + } +#endif + + return res; +} + +#endif /* !FF_FS_READONLY && FF_FS_MINIMIZE == 0 */ + + + +#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 +/*-----------------------------------------------------------------------*/ +/* Get file information from directory entry */ +/*-----------------------------------------------------------------------*/ + +static void get_fileinfo ( + DIR* dp, /* Pointer to the directory object */ + FILINFO* fno /* Pointer to the file information to be filled */ +) +{ + UINT si, di; +#if FF_USE_LFN + BYTE lcf; + WCHAR wc, hs; + FATFS *fs = dp->obj.fs; +#else + TCHAR c; +#endif + + + fno->fname[0] = 0; /* Invaidate file info */ + if (dp->sect == 0) return; /* Exit if read pointer has reached end of directory */ + +#if FF_USE_LFN /* LFN configuration */ +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + get_xfileinfo(fs->dirbuf, fno); + return; + } else +#endif + { /* On the FAT/FAT32 volume */ + if (dp->blk_ofs != 0xFFFFFFFF) { /* Get LFN if available */ + si = di = hs = 0; + while (fs->lfnbuf[si] != 0) { + wc = fs->lfnbuf[si++]; /* Get an LFN character (UTF-16) */ + if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */ + hs = wc; continue; /* Get low surrogate */ + } + wc = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in UTF-16 or UTF-8 encoding */ + if (wc == 0) { di = 0; break; } /* Invalid char or buffer overflow? */ + di += wc; + hs = 0; + } + if (hs != 0) di = 0; /* Broken surrogate pair? */ + fno->fname[di] = 0; /* Terminate the LFN (null string means LFN is invalid) */ + } + } + + si = di = 0; + while (si < 11) { /* Get SFN from SFN entry */ + wc = dp->dir[si++]; /* Get a char */ + if (wc == ' ') continue; /* Skip padding spaces */ + if (wc == RDDEM) wc = DDEM; /* Restore replaced DDEM character */ + if (si == 9 && di < FF_SFN_BUF) fno->altname[di++] = '.'; /* Insert a . if extension is exist */ +#if FF_LFN_UNICODE >= 1 /* Unicode output */ + if (dbc_1st((BYTE)wc) && si != 8 && si != 11 && dbc_2nd(dp->dir[si])) { /* Make a DBC if needed */ + wc = wc << 8 | dp->dir[si++]; + } + wc = ff_oem2uni(wc, CODEPAGE); /* ANSI/OEM -> Unicode */ + if (wc == 0) { di = 0; break; } /* Wrong char in the current code page? */ + wc = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di); /* Store it in Unicode */ + if (wc == 0) { di = 0; break; } /* Buffer overflow? */ + di += wc; +#else /* ANSI/OEM output */ + fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */ +#endif + } + fno->altname[di] = 0; /* Terminate the SFN (null string means SFN is invalid) */ + + if (fno->fname[0] == 0) { /* If LFN is invalid, altname[] needs to be copied to fname[] */ + if (di == 0) { /* If LFN and SFN both are invalid, this object is inaccesible */ + fno->fname[di++] = '?'; + } else { + for (si = di = 0, lcf = NS_BODY; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */ + wc = (WCHAR)fno->altname[si]; + if (wc == '.') lcf = NS_EXT; + if (IsUpper(wc) && (dp->dir[DIR_NTres] & lcf)) wc += 0x20; + fno->fname[di] = (TCHAR)wc; + } + } + fno->fname[di] = 0; /* Terminate the LFN */ + if (!dp->dir[DIR_NTres]) fno->altname[0] = 0; /* Altname is not needed if neither LFN nor case info is exist. */ + } + +#else /* Non-LFN configuration */ + si = di = 0; + while (si < 11) { /* Copy name body and extension */ + c = (TCHAR)dp->dir[si++]; + if (c == ' ') continue; /* Skip padding spaces */ + if (c == RDDEM) c = DDEM; /* Restore replaced DDEM character */ + if (si == 9) fno->fname[di++] = '.';/* Insert a . if extension is exist */ + fno->fname[di++] = c; + } + fno->fname[di] = 0; +#endif + + fno->fattrib = dp->dir[DIR_Attr]; /* Attribute */ + fno->fsize = ld_dword(dp->dir + DIR_FileSize); /* Size */ + fno->ftime = ld_word(dp->dir + DIR_ModTime + 0); /* Time */ + fno->fdate = ld_word(dp->dir + DIR_ModTime + 2); /* Date */ +} + +#endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */ + + + +#if FF_USE_FIND && FF_FS_MINIMIZE <= 1 +/*-----------------------------------------------------------------------*/ +/* Pattern matching */ +/*-----------------------------------------------------------------------*/ + +static DWORD get_achar ( /* Get a character and advances ptr */ + const TCHAR** ptr /* Pointer to pointer to the ANSI/OEM or Unicode string */ +) +{ + DWORD chr; + + +#if FF_USE_LFN && FF_LFN_UNICODE >= 1 /* Unicode input */ + chr = tchar2uni(ptr); + if (chr == 0xFFFFFFFF) chr = 0; /* Wrong UTF encoding is recognized as end of the string */ + chr = ff_wtoupper(chr); + +#else /* ANSI/OEM input */ + chr = (BYTE)*(*ptr)++; /* Get a byte */ + if (IsLower(chr)) chr -= 0x20; /* To upper ASCII char */ +#if FF_CODE_PAGE == 0 + if (ExCvt && chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper SBCS extended char */ +#elif FF_CODE_PAGE < 900 + if (chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper SBCS extended char */ +#endif +#if FF_CODE_PAGE == 0 || FF_CODE_PAGE >= 900 + if (dbc_1st((BYTE)chr)) { /* Get DBC 2nd byte if needed */ + chr = dbc_2nd((BYTE)**ptr) ? chr << 8 | (BYTE)*(*ptr)++ : 0; + } +#endif + +#endif + return chr; +} + + +static int pattern_matching ( /* 0:not matched, 1:matched */ + const TCHAR* pat, /* Matching pattern */ + const TCHAR* nam, /* String to be tested */ + int skip, /* Number of pre-skip chars (number of ?s) */ + int inf /* Infinite search (* specified) */ +) +{ + const TCHAR *pp, *np; + DWORD pc, nc; + int nm, nx; + + + while (skip--) { /* Pre-skip name chars */ + if (!get_achar(&nam)) return 0; /* Branch mismatched if less name chars */ + } + if (*pat == 0 && inf) return 1; /* (short circuit) */ + + do { + pp = pat; np = nam; /* Top of pattern and name to match */ + for (;;) { + if (*pp == '?' || *pp == '*') { /* Wildcard? */ + nm = nx = 0; + do { /* Analyze the wildcard block */ + if (*pp++ == '?') nm++; else nx = 1; + } while (*pp == '?' || *pp == '*'); + if (pattern_matching(pp, np, nm, nx)) return 1; /* Test new branch (recurs upto number of wildcard blocks in the pattern) */ + nc = *np; break; /* Branch mismatched */ + } + pc = get_achar(&pp); /* Get a pattern char */ + nc = get_achar(&np); /* Get a name char */ + if (pc != nc) break; /* Branch mismatched? */ + if (pc == 0) return 1; /* Branch matched? (matched at end of both strings) */ + } + get_achar(&nam); /* nam++ */ + } while (inf && nc); /* Retry until end of name if infinite search is specified */ + + return 0; +} + +#endif /* FF_USE_FIND && FF_FS_MINIMIZE <= 1 */ + + + +/*-----------------------------------------------------------------------*/ +/* Pick a top segment and create the object name in directory form */ +/*-----------------------------------------------------------------------*/ + +static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create */ + DIR* dp, /* Pointer to the directory object */ + const TCHAR** path /* Pointer to pointer to the segment in the path string */ +) +{ +#if FF_USE_LFN /* LFN configuration */ + BYTE b, cf; + WCHAR wc, *lfn; + DWORD uc; + UINT i, ni, si, di; + const TCHAR *p; + + + /* Create LFN into LFN working buffer */ + p = *path; lfn = dp->obj.fs->lfnbuf; di = 0; + for (;;) { + uc = tchar2uni(&p); /* Get a character */ + if (uc == 0xFFFFFFFF) return FR_INVALID_NAME; /* Invalid code or UTF decode error */ + if (uc >= 0x10000) lfn[di++] = (WCHAR)(uc >> 16); /* Store high surrogate if needed */ + wc = (WCHAR)uc; + if (wc < ' ' || wc == '/' || wc == '\\') break; /* Break if end of the path or a separator is found */ + if (wc < 0x80 && chk_chr("\"*:<>\?|\x7F", wc)) return FR_INVALID_NAME; /* Reject illegal characters for LFN */ + if (di >= FF_MAX_LFN) return FR_INVALID_NAME; /* Reject too long name */ + lfn[di++] = wc; /* Store the Unicode character */ + } + while (*p == '/' || *p == '\\') p++; /* Skip duplicated separators if exist */ + *path = p; /* Return pointer to the next segment */ + cf = (wc < ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */ + +#if FF_FS_RPATH != 0 + if ((di == 1 && lfn[di - 1] == '.') || + (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot name? */ + lfn[di] = 0; + for (i = 0; i < 11; i++) { /* Create dot name for SFN entry */ + dp->fn[i] = (i < di) ? '.' : ' '; + } + dp->fn[i] = cf | NS_DOT; /* This is a dot entry */ + return FR_OK; + } +#endif + while (di) { /* Snip off trailing spaces and dots if exist */ + wc = lfn[di - 1]; + if (wc != ' ' && wc != '.') break; + di--; + } + lfn[di] = 0; /* LFN is created into the working buffer */ + if (di == 0) return FR_INVALID_NAME; /* Reject null name */ + + /* Create SFN in directory form */ + for (si = 0; lfn[si] == ' '; si++) ; /* Remove leading spaces */ + if (si > 0 || lfn[si] == '.') cf |= NS_LOSS | NS_LFN; /* Is there any leading space or dot? */ + while (di > 0 && lfn[di - 1] != '.') di--; /* Find last dot (di<=si: no extension) */ + + mem_set(dp->fn, ' ', 11); + i = b = 0; ni = 8; + for (;;) { + wc = lfn[si++]; /* Get an LFN character */ + if (wc == 0) break; /* Break on end of the LFN */ + if (wc == ' ' || (wc == '.' && si != di)) { /* Remove embedded spaces and dots */ + cf |= NS_LOSS | NS_LFN; + continue; + } + + if (i >= ni || si == di) { /* End of field? */ + if (ni == 11) { /* Name extension overflow? */ + cf |= NS_LOSS | NS_LFN; + break; + } + if (si != di) cf |= NS_LOSS | NS_LFN; /* Name body overflow? */ + if (si > di) break; /* No name extension? */ + si = di; i = 8; ni = 11; b <<= 2; /* Enter name extension */ + continue; + } + + if (wc >= 0x80) { /* Is this a non-ASCII character? */ + cf |= NS_LFN; /* LFN entry needs to be created */ +#if FF_CODE_PAGE == 0 + if (ExCvt) { /* At SBCS */ + wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */ + if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */ + } else { /* At DBCS */ + wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Upper convert ==> ANSI/OEM code */ + } +#elif FF_CODE_PAGE < 900 /* SBCS cfg */ + wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */ + if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */ +#else /* DBCS cfg */ + wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Upper convert ==> ANSI/OEM code */ +#endif + } + + if (wc >= 0x100) { /* Is this a DBC? */ + if (i >= ni - 1) { /* Field overflow? */ + cf |= NS_LOSS | NS_LFN; + i = ni; continue; /* Next field */ + } + dp->fn[i++] = (BYTE)(wc >> 8); /* Put 1st byte */ + } else { /* SBC */ + if (wc == 0 || chk_chr("+,;=[]", wc)) { /* Replace illegal characters for SFN if needed */ + wc = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */ + } else { + if (IsUpper(wc)) { /* ASCII upper case? */ + b |= 2; + } + if (IsLower(wc)) { /* ASCII lower case? */ + b |= 1; wc -= 0x20; + } + } + } + dp->fn[i++] = (BYTE)wc; + } + + if (dp->fn[0] == DDEM) dp->fn[0] = RDDEM; /* If the first character collides with DDEM, replace it with RDDEM */ + + if (ni == 8) b <<= 2; /* Shift capital flags if no extension */ + if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03) cf |= NS_LFN; /* LFN entry needs to be created if composite capitals */ + if (!(cf & NS_LFN)) { /* When LFN is in 8.3 format without extended character, NT flags are created */ + if (b & 0x01) cf |= NS_EXT; /* NT flag (Extension has small capital letters only) */ + if (b & 0x04) cf |= NS_BODY; /* NT flag (Body has small capital letters only) */ + } + + dp->fn[NSFLAG] = cf; /* SFN is created into dp->fn[] */ + + return FR_OK; + + +#else /* FF_USE_LFN : Non-LFN configuration */ + BYTE c, d, *sfn; + UINT ni, si, i; + const char *p; + + /* Create file name in directory form */ + p = *path; sfn = dp->fn; + mem_set(sfn, ' ', 11); + si = i = 0; ni = 8; +#if FF_FS_RPATH != 0 + if (p[si] == '.') { /* Is this a dot entry? */ + for (;;) { + c = (BYTE)p[si++]; + if (c != '.' || si >= 3) break; + sfn[i++] = c; + } + if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME; + *path = p + si; /* Return pointer to the next segment */ + sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of the path */ + return FR_OK; + } +#endif + for (;;) { + c = (BYTE)p[si++]; /* Get a byte */ + if (c <= ' ') break; /* Break if end of the path name */ + if (c == '/' || c == '\\') { /* Break if a separator is found */ + while (p[si] == '/' || p[si] == '\\') si++; /* Skip duplicated separator if exist */ + break; + } + if (c == '.' || i >= ni) { /* End of body or field overflow? */ + if (ni == 11 || c != '.') return FR_INVALID_NAME; /* Field overflow or invalid dot? */ + i = 8; ni = 11; /* Enter file extension field */ + continue; + } +#if FF_CODE_PAGE == 0 + if (ExCvt && c >= 0x80) { /* Is SBC extended character? */ + c = ExCvt[c & 0x7F]; /* To upper SBC extended character */ + } +#elif FF_CODE_PAGE < 900 + if (c >= 0x80) { /* Is SBC extended character? */ + c = ExCvt[c & 0x7F]; /* To upper SBC extended character */ + } +#endif + if (dbc_1st(c)) { /* Check if it is a DBC 1st byte */ + d = (BYTE)p[si++]; /* Get 2nd byte */ + if (!dbc_2nd(d) || i >= ni - 1) return FR_INVALID_NAME; /* Reject invalid DBC */ + sfn[i++] = c; + sfn[i++] = d; + } else { /* SBC */ + if (chk_chr("\"*+,:;<=>\?[]|\x7F", c)) return FR_INVALID_NAME; /* Reject illegal chrs for SFN */ + if (IsLower(c)) c -= 0x20; /* To upper */ + sfn[i++] = c; + } + } + *path = p + si; /* Return pointer to the next segment */ + if (i == 0) return FR_INVALID_NAME; /* Reject nul string */ + + if (sfn[0] == DDEM) sfn[0] = RDDEM; /* If the first character collides with DDEM, replace it with RDDEM */ + sfn[NSFLAG] = (c <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */ + + return FR_OK; +#endif /* FF_USE_LFN */ +} + + + + +/*-----------------------------------------------------------------------*/ +/* Follow a file path */ +/*-----------------------------------------------------------------------*/ + +static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ + DIR* dp, /* Directory object to return last directory and found object */ + const TCHAR* path /* Full-path string to find a file or directory */ +) +{ + FRESULT res; + BYTE ns; + FATFS *fs = dp->obj.fs; + + +#if FF_FS_RPATH != 0 + if (*path != '/' && *path != '\\') { /* Without heading separator */ + dp->obj.sclust = fs->cdir; /* Start from current directory */ + } else +#endif + { /* With heading separator */ + while (*path == '/' || *path == '\\') path++; /* Strip heading separator */ + dp->obj.sclust = 0; /* Start from root directory */ + } +#if FF_FS_EXFAT + dp->obj.n_frag = 0; /* Invalidate last fragment counter of the object */ +#if FF_FS_RPATH != 0 + if (fs->fs_type == FS_EXFAT && dp->obj.sclust) { /* exFAT: Retrieve the sub-directory's status */ + DIR dj; + + dp->obj.c_scl = fs->cdc_scl; + dp->obj.c_size = fs->cdc_size; + dp->obj.c_ofs = fs->cdc_ofs; + res = load_obj_xdir(&dj, &dp->obj); + if (res != FR_OK) return res; + dp->obj.objsize = ld_dword(fs->dirbuf + XDIR_FileSize); + dp->obj.stat = fs->dirbuf[XDIR_GenFlags] & 2; + } +#endif +#endif + + if ((UINT)*path < ' ') { /* Null path name is the origin directory itself */ + dp->fn[NSFLAG] = NS_NONAME; + res = dir_sdi(dp, 0); + + } else { /* Follow path */ + for (;;) { + res = create_name(dp, &path); /* Get a segment name of the path */ + if (res != FR_OK) break; + res = dir_find(dp); /* Find an object with the segment name */ + ns = dp->fn[NSFLAG]; + if (res != FR_OK) { /* Failed to find the object */ + if (res == FR_NO_FILE) { /* Object is not found */ + if (FF_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, stay there */ + if (!(ns & NS_LAST)) continue; /* Continue to follow if not last segment */ + dp->fn[NSFLAG] = NS_NONAME; + res = FR_OK; + } else { /* Could not find the object */ + if (!(ns & NS_LAST)) res = FR_NO_PATH; /* Adjust error code if not last segment */ + } + } + break; + } + if (ns & NS_LAST) break; /* Last segment matched. Function completed. */ + /* Get into the sub-directory */ + if (!(dp->obj.attr & AM_DIR)) { /* It is not a sub-directory and cannot follow */ + res = FR_NO_PATH; break; + } +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* Save containing directory information for next dir */ + dp->obj.c_scl = dp->obj.sclust; + dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat; + dp->obj.c_ofs = dp->blk_ofs; + init_alloc_info(fs, &dp->obj); /* Open next directory */ + } else +#endif + { + dp->obj.sclust = ld_clust(fs, fs->win + dp->dptr % SS(fs)); /* Open next directory */ + } + } + } + + return res; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Get logical drive number from path name */ +/*-----------------------------------------------------------------------*/ + +static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive number or null pointer) */ + const TCHAR** path /* Pointer to pointer to the path name */ +) +{ + const TCHAR *tp, *tt; + TCHAR tc; + int i, vol = -1; +#if FF_STR_VOLUME_ID /* Find string volume ID */ + const char *sp; + char c; +#endif + + tt = tp = *path; + if (!tp) return vol; /* Invalid path name? */ + do tc = *tt++; while ((UINT)tc >= (FF_USE_LFN ? ' ' : '!') && tc != ':'); /* Find a colon in the path */ + + if (tc == ':') { /* DOS/Windows style volume ID? */ + i = FF_VOLUMES; + if (IsDigit(*tp) && tp + 2 == tt) { /* Is there a numeric volume ID + colon? */ + i = (int)*tp - '0'; /* Get the LD number */ + } +#if FF_STR_VOLUME_ID == 1 /* Arbitrary string is enabled */ + else { + i = 0; + do { + sp = VolumeStr[i]; tp = *path; /* This string volume ID and path name */ + do { /* Compare the volume ID with path name */ + c = *sp++; tc = *tp++; + if (IsLower(c)) c -= 0x20; + if (IsLower(tc)) tc -= 0x20; + } while (c && (TCHAR)c == tc); + } while ((c || tp != tt) && ++i < FF_VOLUMES); /* Repeat for each id until pattern match */ + } +#endif + if (i < FF_VOLUMES) { /* If a volume ID is found, get the drive number and strip it */ + vol = i; /* Drive number */ + *path = tt; /* Snip the drive prefix off */ + } + return vol; + } +#if FF_STR_VOLUME_ID == 2 /* Unix style volume ID is enabled */ + if (*tp == '/') { + i = 0; + do { + sp = VolumeStr[i]; tp = *path; /* This string volume ID and path name */ + do { /* Compare the volume ID with path name */ + c = *sp++; tc = *(++tp); + if (IsLower(c)) c -= 0x20; + if (IsLower(tc)) tc -= 0x20; + } while (c && (TCHAR)c == tc); + } while ((c || (tc != '/' && (UINT)tc >= (FF_USE_LFN ? ' ' : '!'))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */ + if (i < FF_VOLUMES) { /* If a volume ID is found, get the drive number and strip it */ + vol = i; /* Drive number */ + *path = tp; /* Snip the drive prefix off */ + return vol; + } + } +#endif + /* No drive prefix is found */ +#if FF_FS_RPATH != 0 + vol = CurrVol; /* Default drive is current drive */ +#else + vol = 0; /* Default drive is 0 */ +#endif + return vol; /* Return the default drive */ +} + + + + +/*-----------------------------------------------------------------------*/ +/* Load a sector and check if it is an FAT VBR */ +/*-----------------------------------------------------------------------*/ + +static BYTE check_fs ( /* 0:FAT, 1:exFAT, 2:Valid BS but not FAT, 3:Not a BS, 4:Disk error */ + FATFS* fs, /* Filesystem object */ + DWORD sect /* Sector# (lba) to load and check if it is an FAT-VBR or not */ +) +{ + fs->wflag = 0; fs->winsect = 0xFFFFFFFF; /* Invaidate window */ + if (move_window(fs, sect) != FR_OK) return 4; /* Load boot record */ + + if (ld_word(fs->win + BS_55AA) != 0xAA55) return 3; /* Check boot record signature (always here regardless of the sector size) */ + +#if FF_FS_EXFAT + if (!mem_cmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11)) return 1; /* Check if exFAT VBR */ +#endif + if (fs->win[BS_JmpBoot] == 0xE9 || fs->win[BS_JmpBoot] == 0xEB || fs->win[BS_JmpBoot] == 0xE8) { /* Valid JumpBoot code? */ + if (!mem_cmp(fs->win + BS_FilSysType, "FAT", 3)) return 0; /* Is it an FAT VBR? */ + if (!mem_cmp(fs->win + BS_FilSysType32, "FAT32", 5)) return 0; /* Is it an FAT32 VBR? */ + } + return 2; /* Valid BS but not FAT */ +} + + + + +/*-----------------------------------------------------------------------*/ +/* Determine logical drive number and mount the volume if needed */ +/*-----------------------------------------------------------------------*/ + +static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ + const TCHAR** path, /* Pointer to pointer to the path name (drive number) */ + FATFS** rfs, /* Pointer to pointer to the found filesystem object */ + BYTE mode /* !=0: Check write protection for write access */ +) +{ + BYTE fmt, *pt; + int vol; + DSTATUS stat; + DWORD bsect, fasize, tsect, sysect, nclst, szbfat, br[4]; + WORD nrsv; + FATFS *fs; + UINT i; + + + /* Get logical drive number */ + *rfs = 0; + vol = get_ldnumber(path); + if (vol < 0) return FR_INVALID_DRIVE; + + /* Check if the filesystem object is valid or not */ + fs = FatFs[vol]; /* Get pointer to the filesystem object */ + if (!fs) return FR_NOT_ENABLED; /* Is the filesystem object available? */ +#if FF_FS_REENTRANT + if (!lock_fs(fs)) return FR_TIMEOUT; /* Lock the volume */ +#endif + *rfs = fs; /* Return pointer to the filesystem object */ + + mode &= (BYTE)~FA_READ; /* Desired access mode, write access or not */ + if (fs->fs_type != 0) { /* If the volume has been mounted */ + stat = disk_status(fs->pdrv); + if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized */ + if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check write protection if needed */ + EFSPRINTF("WPEN1"); + return FR_WRITE_PROTECTED; + } + return FR_OK; /* The filesystem object is valid */ + } + } + + /* The filesystem object is not valid. */ + /* Following code attempts to mount the volume. (analyze BPB and initialize the filesystem object) */ + + fs->fs_type = 0; /* Clear the filesystem object */ + fs->pdrv = LD2PD(vol); /* Bind the logical drive and a physical drive */ + stat = disk_initialize(fs->pdrv); /* Initialize the physical drive */ + if (stat & STA_NOINIT) { /* Check if the initialization succeeded */ + EFSPRINTF("MDNR"); + return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */ + } + if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check disk write protection if needed */ + EFSPRINTF("WPEN2"); + return FR_WRITE_PROTECTED; + } +#if FF_MAX_SS != FF_MIN_SS /* Get sector size (multiple sector size cfg only) */ + if (disk_ioctl(fs->pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK) return FR_DISK_ERR; + if (SS(fs) > FF_MAX_SS || SS(fs) < FF_MIN_SS || (SS(fs) & (SS(fs) - 1))) return FR_DISK_ERR; +#endif + + /* Find an FAT partition on the drive. Supports only generic partitioning rules, FDISK (MBR) and SFD (w/o partition). */ + bsect = 0; + fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT-VBR as SFD */ + if (fmt == 2 || (fmt < 2 && LD2PT(vol) != 0)) { /* Not an FAT-VBR or forced partition number */ + for (i = 0; i < 4; i++) { /* Get partition offset */ + pt = fs->win + (MBR_Table + i * SZ_PTE); + br[i] = pt[PTE_System] ? ld_dword(pt + PTE_StLba) : 0; + } + i = LD2PT(vol); /* Partition number: 0:auto, 1-4:forced */ + if (i != 0) i--; + do { /* Find an FAT volume */ + bsect = br[i]; + fmt = bsect ? check_fs(fs, bsect) : 3; /* Check the partition */ + } while (LD2PT(vol) == 0 && fmt >= 2 && ++i < 4); + } + if (fmt == 4) { + EFSPRINTF("BRNL"); + return FR_DISK_ERR; /* An error occured in the disk I/O layer */ + } + if (fmt >= 2) { + EFSPRINTF("NOFAT"); + return FR_NO_FILESYSTEM; /* No FAT volume is found */ + } + + /* An FAT volume is found (bsect). Following code initializes the filesystem object */ + +#if FF_FS_EXFAT + if (fmt == 1) { + QWORD maxlba; + DWORD so, cv, bcl; + + for (i = BPB_ZeroedEx; i < BPB_ZeroedEx + 53 && fs->win[i] == 0; i++) ; /* Check zero filler */ + if (i < BPB_ZeroedEx + 53) return FR_NO_FILESYSTEM; + + if (ld_word(fs->win + BPB_FSVerEx) != 0x100) return FR_NO_FILESYSTEM; /* Check exFAT version (must be version 1.0) */ + + if (1 << fs->win[BPB_BytsPerSecEx] != SS(fs)) { /* (BPB_BytsPerSecEx must be equal to the physical sector size) */ + EFSPRINTF("EXSPS"); + return FR_NO_FILESYSTEM; + } + + maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA + 1 of the volume */ + if (maxlba >= 0x100000000) return FR_NO_FILESYSTEM; /* (It cannot be handled in 32-bit LBA) */ + + fs->fsize = ld_dword(fs->win + BPB_FatSzEx); /* Number of sectors per FAT */ + + fs->n_fats = fs->win[BPB_NumFATsEx]; /* Number of FATs */ + if (fs->n_fats != 1) { + EFSPRINTF("EXFNF"); + return FR_NO_FILESYSTEM; /* (Supports only 1 FAT) */ + } + + fs->csize = 1 << fs->win[BPB_SecPerClusEx]; /* Cluster size */ + if (fs->csize == 0) return FR_NO_FILESYSTEM; /* (Must be 1..32768) */ + + nclst = ld_dword(fs->win + BPB_NumClusEx); /* Number of clusters */ + if (nclst > MAX_EXFAT) return FR_NO_FILESYSTEM; /* (Too many clusters) */ + fs->n_fatent = nclst + 2; + + /* Boundaries and Limits */ + fs->volbase = bsect; + fs->database = bsect + ld_dword(fs->win + BPB_DataOfsEx); + fs->fatbase = bsect + ld_dword(fs->win + BPB_FatOfsEx); + if (maxlba < (QWORD)fs->database + nclst * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size requiered) */ + fs->dirbase = ld_dword(fs->win + BPB_RootClusEx); + + /* Get bitmap location and check if it is contiguous (implementation assumption) */ + so = i = 0; + for (;;) { /* Find the bitmap entry in the root directory (in only first cluster) */ + if (i == 0) { + if (so >= fs->csize) return FR_NO_FILESYSTEM; /* Not found? */ + if (move_window(fs, clst2sect(fs, fs->dirbase) + so) != FR_OK) { + EFSPRINTF("EXBM1C"); + return FR_DISK_ERR; + } + so++; + } + if (fs->win[i] == ET_BITMAP) break; /* Is it a bitmap entry? */ + i = (i + SZDIRE) % SS(fs); /* Next entry */ + } + bcl = ld_dword(fs->win + i + 20); /* Bitmap cluster */ + if (bcl < 2 || bcl >= fs->n_fatent) { + EFSPRINTF("EXBMM"); + return FR_NO_FILESYSTEM; + } + fs->bitbase = fs->database + fs->csize * (bcl - 2); /* Bitmap sector */ + for (;;) { /* Check if bitmap is contiguous */ + if (move_window(fs, fs->fatbase + bcl / (SS(fs) / 4)) != FR_OK) return FR_DISK_ERR; + cv = ld_dword(fs->win + bcl % (SS(fs) / 4) * 4); + if (cv == 0xFFFFFFFF) break; /* Last link? */ + if (cv != ++bcl) { + EFSPRINTF("EXBMM"); + return FR_NO_FILESYSTEM; /* Fragmented? */ + } + } + +#if !FF_FS_READONLY + fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */ +#endif + fmt = FS_EXFAT; /* FAT sub-type */ + } else +#endif /* FF_FS_EXFAT */ + { + if (ld_word(fs->win + BPB_BytsPerSec) != SS(fs)) { + EFSPRINTF("32SPS"); + return FR_NO_FILESYSTEM; /* (BPB_BytsPerSec must be equal to the physical sector size) */ + } + + fasize = ld_word(fs->win + BPB_FATSz16); /* Number of sectors per FAT */ + if (fasize == 0) fasize = ld_dword(fs->win + BPB_FATSz32); + fs->fsize = fasize; + + fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FATs */ + if (fs->n_fats != 1 && fs->n_fats != 2) return FR_NO_FILESYSTEM; /* (Must be 1 or 2) */ + fasize *= fs->n_fats; /* Number of sectors for FAT area */ + + fs->csize = fs->win[BPB_SecPerClus]; /* Cluster size */ + if (fs->csize == 0 || (fs->csize & (fs->csize - 1))) return FR_NO_FILESYSTEM; /* (Must be power of 2) */ + + fs->n_rootdir = ld_word(fs->win + BPB_RootEntCnt); /* Number of root directory entries */ + if (fs->n_rootdir % (SS(fs) / SZDIRE)) return FR_NO_FILESYSTEM; /* (Must be sector aligned) */ + + tsect = ld_word(fs->win + BPB_TotSec16); /* Number of sectors on the volume */ + if (tsect == 0) tsect = ld_dword(fs->win + BPB_TotSec32); + + nrsv = ld_word(fs->win + BPB_RsvdSecCnt); /* Number of reserved sectors */ + if (nrsv == 0) return FR_NO_FILESYSTEM; /* (Must not be 0) */ + + /* Determine the FAT sub type */ + sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZDIRE); /* RSV + FAT + DIR */ + if (tsect < sysect) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ + nclst = (tsect - sysect) / fs->csize; /* Number of clusters */ + if (nclst == 0) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ + fmt = 0; + if (nclst <= MAX_FAT32) fmt = FS_FAT32; + if (nclst <= MAX_FAT16) fmt = FS_FAT16; + if (nclst <= MAX_FAT12) fmt = FS_FAT12; + if (fmt == 0) return FR_NO_FILESYSTEM; + + /* Boundaries and Limits */ + fs->n_fatent = nclst + 2; /* Number of FAT entries */ + fs->volbase = bsect; /* Volume start sector */ + fs->fatbase = bsect + nrsv; /* FAT start sector */ + fs->database = bsect + sysect; /* Data start sector */ + if (fmt == FS_FAT32) { + if (ld_word(fs->win + BPB_FSVer32) != 0) return FR_NO_FILESYSTEM; /* (Must be FAT32 revision 0.0) */ + if (fs->n_rootdir != 0) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */ + fs->dirbase = ld_dword(fs->win + BPB_RootClus32); /* Root directory start cluster */ + szbfat = fs->n_fatent * 4; /* (Needed FAT size) */ + } else { + if (fs->n_rootdir == 0) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */ + fs->dirbase = fs->fatbase + fasize; /* Root directory start sector */ + szbfat = (fmt == FS_FAT16) ? /* (Needed FAT size) */ + fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1); + } + if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) return FR_NO_FILESYSTEM; /* (BPB_FATSz must not be less than the size needed) */ + +#if !FF_FS_READONLY + /* Get FSInfo if available */ + fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */ + fs->fsi_flag = 0x80; +#if (FF_FS_NOFSINFO & 3) != 3 + if (fmt == FS_FAT32 /* Allow to update FSInfo only if BPB_FSInfo32 == 1 */ + && ld_word(fs->win + BPB_FSInfo32) == 1 + && move_window(fs, bsect + 1) == FR_OK) + { + fs->fsi_flag = 0; + if (ld_word(fs->win + BS_55AA) == 0xAA55 /* Load FSInfo data if available */ + && ld_dword(fs->win + FSI_LeadSig) == 0x41615252 + && ld_dword(fs->win + FSI_StrucSig) == 0x61417272) + { +#if (FF_FS_NOFSINFO & 1) == 0 + fs->free_clst = ld_dword(fs->win + FSI_Free_Count); +#endif +#if (FF_FS_NOFSINFO & 2) == 0 + fs->last_clst = ld_dword(fs->win + FSI_Nxt_Free); +#endif + } + } +#endif /* (FF_FS_NOFSINFO & 3) != 3 */ +#endif /* !FF_FS_READONLY */ + } + + fs->fs_type = fmt; /* FAT sub-type */ + fs->id = ++Fsid; /* Volume mount ID */ +#if FF_USE_LFN == 1 + fs->lfnbuf = LfnBuf; /* Static LFN working buffer */ +#if FF_FS_EXFAT + fs->dirbuf = DirBuf; /* Static directory block scratchpad buffer */ +#endif +#endif +#if FF_FS_RPATH != 0 + fs->cdir = 0; /* Initialize current directory */ +#endif +#if FF_FS_LOCK != 0 /* Clear file lock semaphores */ + clear_lock(fs); +#endif + return FR_OK; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Check if the file/directory object is valid or not */ +/*-----------------------------------------------------------------------*/ + +static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */ + FFOBJID* obj, /* Pointer to the FFOBJID, the 1st member in the FIL/DIR object, to check validity */ + FATFS** rfs /* Pointer to pointer to the owner filesystem object to return */ +) +{ + FRESULT res = FR_INVALID_OBJECT; + + + if (obj && obj->fs && obj->fs->fs_type && obj->id == obj->fs->id) { /* Test if the object is valid */ +#if FF_FS_REENTRANT + if (lock_fs(obj->fs)) { /* Obtain the filesystem object */ + if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */ + res = FR_OK; + } else { + unlock_fs(obj->fs, FR_OK); + } + } else { + res = FR_TIMEOUT; + } +#else + if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */ + res = FR_OK; + } +#endif + } + *rfs = (res == FR_OK) ? obj->fs : 0; /* Corresponding filesystem object */ + return res; +} + + + + +/*--------------------------------------------------------------------------- + + Public Functions (FatFs API) + +----------------------------------------------------------------------------*/ + + + +/*-----------------------------------------------------------------------*/ +/* Mount/Unmount a Logical Drive */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_mount ( + FATFS* fs, /* Pointer to the filesystem object (NULL:unmount)*/ + const TCHAR* path, /* Logical drive number to be mounted/unmounted */ + BYTE opt /* Mode option 0:Do not mount (delayed mount), 1:Mount immediately */ +) +{ + FATFS *cfs; + int vol; + FRESULT res; + const TCHAR *rp = path; + + + /* Get logical drive number */ + vol = get_ldnumber(&rp); + if (vol < 0) { + EFSPRINTF("IDRIVE!"); + return FR_INVALID_DRIVE; + } + cfs = FatFs[vol]; /* Pointer to fs object */ + + if (cfs) { +#if FF_FS_LOCK != 0 + clear_lock(cfs); +#endif +#if FF_FS_REENTRANT /* Discard sync object of the current volume */ + if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR; +#endif + cfs->fs_type = 0; /* Clear old fs object */ + } + + if (fs) { + fs->fs_type = 0; /* Clear new fs object */ +#if FF_FS_REENTRANT /* Create sync object for the new volume */ + if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR; +#endif + } + FatFs[vol] = fs; /* Register new fs object */ + + if (opt == 0) return FR_OK; /* Do not mount now, it will be mounted later */ + + res = find_volume(&path, &fs, 0); /* Force mounted the volume */ + LEAVE_FF(fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Open or Create a File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_open ( + FIL* fp, /* Pointer to the blank file object */ + const TCHAR* path, /* Pointer to the file name */ + BYTE mode /* Access mode and file open mode flags */ +) +{ + FRESULT res; + DIR dj; + FATFS *fs; +#if !FF_FS_READONLY + DWORD dw, cl, bcs, clst, sc; + FSIZE_t ofs; +#endif + DEF_NAMBUF + + + if (!fp) return FR_INVALID_OBJECT; + + /* Get logical drive number */ + mode &= FF_FS_READONLY ? FA_READ : FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_CREATE_NEW | FA_OPEN_ALWAYS | FA_OPEN_APPEND; + res = find_volume(&path, &fs, mode); + if (res == FR_OK) { + dj.obj.fs = fs; + INIT_NAMBUF(fs); + res = follow_path(&dj, path); /* Follow the file path */ +#if !FF_FS_READONLY /* Read/Write configuration */ + if (res == FR_OK) { + if (dj.fn[NSFLAG] & NS_NONAME) { /* Origin directory itself? */ + res = FR_INVALID_NAME; + } +#if FF_FS_LOCK != 0 + else { + res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0); /* Check if the file can be used */ + } +#endif + } + /* Create or Open a file */ + if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) { + if (res != FR_OK) { /* No file, create new */ + if (res == FR_NO_FILE) { /* There is no file to open, create a new entry */ +#if FF_FS_LOCK != 0 + res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES; +#else + res = dir_register(&dj); +#endif + } + mode |= FA_CREATE_ALWAYS; /* File is created */ + } + else { /* Any object with the same name is already existing */ + if (dj.obj.attr & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or DIR) */ + res = FR_DENIED; + } else { + if (mode & FA_CREATE_NEW) res = FR_EXIST; /* Cannot create as new file */ + } + } + if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate the file if overwrite mode */ +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + /* Get current allocation info */ + fp->obj.fs = fs; + init_alloc_info(fs, &fp->obj); + /* Set directory entry block initial state */ + mem_set(fs->dirbuf + 2, 0, 30); /* Clear 85 entry except for NumSec */ + mem_set(fs->dirbuf + 38, 0, 26); /* Clear C0 entry except for NumName and NameHash */ + fs->dirbuf[XDIR_Attr] = AM_ARC; + st_dword(fs->dirbuf + XDIR_CrtTime, GET_FATTIME()); + fs->dirbuf[XDIR_GenFlags] = 1; + res = store_xdir(&dj); + if (res == FR_OK && fp->obj.sclust != 0) { /* Remove the cluster chain if exist */ + res = remove_chain(&fp->obj, fp->obj.sclust, 0); + fs->last_clst = fp->obj.sclust - 1; /* Reuse the cluster hole */ + } + } else +#endif + { + /* Set directory entry initial state */ + cl = ld_clust(fs, dj.dir); /* Get current cluster chain */ + st_dword(dj.dir + DIR_CrtTime, GET_FATTIME()); /* Set created time */ + dj.dir[DIR_Attr] = AM_ARC; /* Reset attribute */ + st_clust(fs, dj.dir, 0); /* Reset file allocation info */ + st_dword(dj.dir + DIR_FileSize, 0); + fs->wflag = 1; + if (cl != 0) { /* Remove the cluster chain if exist */ + dw = fs->winsect; + res = remove_chain(&dj.obj, cl, 0); + if (res == FR_OK) { + res = move_window(fs, dw); + fs->last_clst = cl - 1; /* Reuse the cluster hole */ + } + } + } + } + } + else { /* Open an existing file */ + if (res == FR_OK) { /* Is the object exsiting? */ + if (dj.obj.attr & AM_DIR) { /* File open against a directory */ + res = FR_NO_FILE; + } else { + if ((mode & FA_WRITE) && (dj.obj.attr & AM_RDO)) { /* Write mode open against R/O file */ + res = FR_DENIED; + } + } + } + } + if (res == FR_OK) { + if (mode & FA_CREATE_ALWAYS) mode |= FA_MODIFIED; /* Set file change flag if created or overwritten */ + fp->dir_sect = fs->winsect; /* Pointer to the directory entry */ + fp->dir_ptr = dj.dir; +#if FF_FS_LOCK != 0 + fp->obj.lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0); /* Lock the file for this session */ + if (fp->obj.lockid == 0) res = FR_INT_ERR; +#endif + } +#else /* R/O configuration */ + if (res == FR_OK) { + if (dj.fn[NSFLAG] & NS_NONAME) { /* Is it origin directory itself? */ + res = FR_INVALID_NAME; + } else { + if (dj.obj.attr & AM_DIR) { /* Is it a directory? */ + res = FR_NO_FILE; + } + } + } +#endif + + if (res == FR_OK) { +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + fp->obj.c_scl = dj.obj.sclust; /* Get containing directory info */ + fp->obj.c_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat; + fp->obj.c_ofs = dj.blk_ofs; + init_alloc_info(fs, &fp->obj); + } else +#endif + { + fp->obj.sclust = ld_clust(fs, dj.dir); /* Get object allocation info */ + fp->obj.objsize = ld_dword(dj.dir + DIR_FileSize); + } +#if FF_USE_FASTSEEK + fp->cltbl = 0; /* Disable fast seek mode */ +#endif + fp->obj.fs = fs; /* Validate the file object */ + fp->obj.id = fs->id; + fp->flag = mode; /* Set file access mode */ + fp->err = 0; /* Clear error flag */ + fp->sect = 0; /* Invalidate current data sector */ + fp->fptr = 0; /* Set file pointer top of the file */ +#if !FF_FS_READONLY +#if !FF_FS_TINY + mem_set(fp->buf, 0, sizeof fp->buf); /* Clear sector buffer */ +#endif + if ((mode & FA_SEEKEND) && fp->obj.objsize > 0) { /* Seek to end of file if FA_OPEN_APPEND is specified */ + fp->fptr = fp->obj.objsize; /* Offset to seek */ + bcs = (DWORD)fs->csize * SS(fs); /* Cluster size in byte */ + clst = fp->obj.sclust; /* Follow the cluster chain */ + for (ofs = fp->obj.objsize; res == FR_OK && ofs > bcs; ofs -= bcs) { + clst = get_fat(&fp->obj, clst); + if (clst <= 1) res = FR_INT_ERR; + if (clst == 0xFFFFFFFF) res = FR_DISK_ERR; + } + fp->clust = clst; + if (res == FR_OK && ofs % SS(fs)) { /* Fill sector buffer if not on the sector boundary */ + if ((sc = clst2sect(fs, clst)) == 0) { + res = FR_INT_ERR; + } else { + fp->sect = sc + (DWORD)(ofs / SS(fs)); +#if !FF_FS_TINY + if (disk_read(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) res = FR_DISK_ERR; +#endif + } + } + } +#endif + } + + FREE_NAMBUF(); + } + + if (res != FR_OK) fp->obj.fs = 0; /* Invalidate file object on error */ + + LEAVE_FF(fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Read File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_read ( + FIL* fp, /* Pointer to the file object */ + void* buff, /* Pointer to data buffer */ + UINT btr, /* Number of bytes to read */ + UINT* br /* Pointer to number of bytes read */ +) +{ + FRESULT res; + FATFS *fs; + DWORD clst, sect; + FSIZE_t remain; + UINT rcnt, cc, csect; + BYTE *rbuff = (BYTE*)buff; + + UINT br_tmp; + if (!br) + br = &br_tmp; + *br = 0; /* Clear read byte counter */ + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) { + EFSPRINTF("FOV"); + LEAVE_FF(fs, res); /* Check validity */ + } + if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */ + remain = fp->obj.objsize - fp->fptr; + if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ + + for ( ; btr; /* Repeat until btr bytes read */ + btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) { + if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */ + csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */ + if (csect == 0) { /* On the cluster boundary? */ + if (fp->fptr == 0) { /* On the top of the file? */ + clst = fp->obj.sclust; /* Follow cluster chain from the origin */ + } else { /* Middle or end of the file */ +#if FF_USE_FASTSEEK + if (fp->cltbl) { + clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ + } else +#endif + { + clst = get_fat(&fp->obj, fp->clust); /* Follow cluster chain on the FAT */ + } + } + if (clst < 2) { + EFSPRINTF("CCHK"); + ABORT(fs, FR_INT_ERR); + } + if (clst == 0xFFFFFFFF) { + EFSPRINTF("DSKC"); + ABORT(fs, FR_DISK_ERR); + } + fp->clust = clst; /* Update current cluster */ + } + sect = clst2sect(fs, fp->clust); /* Get current sector */ + if (sect == 0) ABORT(fs, FR_INT_ERR); + sect += csect; + cc = btr / SS(fs); /* When remaining bytes >= sector size, */ + if (cc > 0) { /* Read maximum contiguous sectors directly */ + if (csect + cc > fs->csize) { /* Clip at cluster boundary */ + cc = fs->csize - csect; + } + if (disk_read(fs->pdrv, rbuff, sect, cc) != RES_OK) { + EFSPRINTF("RLIO"); + ABORT(fs, FR_DISK_ERR); + } +#if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */ +#if FF_FS_TINY + if (fs->wflag && fs->winsect - sect < cc) { + mem_cpy(rbuff + ((fs->winsect - sect) * SS(fs)), fs->win, SS(fs)); + } +#else + if ((fp->flag & FA_DIRTY) && fp->sect - sect < cc) { + mem_cpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs)); + } +#endif +#endif + rcnt = SS(fs) * cc; /* Number of bytes transferred */ + continue; + } +#if !FF_FS_TINY + if (fp->sect != sect) { /* Load data sector if not in cache */ +#if !FF_FS_READONLY + if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */ + if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) { + EFSPRINTF("RDC"); + ABORT(fs, FR_DISK_ERR); + } + fp->flag &= (BYTE)~FA_DIRTY; + } +#endif + if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) { + EFSPRINTF("RSC"); + ABORT(fs, FR_DISK_ERR); /* Fill sector cache */ + } + } +#endif + fp->sect = sect; + } + rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes left in the sector */ + if (rcnt > btr) rcnt = btr; /* Clip it by btr if needed */ +#if FF_FS_TINY + if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */ + mem_cpy(rbuff, fs->win + fp->fptr % SS(fs), rcnt); /* Extract partial sector */ +#else + mem_cpy(rbuff, fp->buf + fp->fptr % SS(fs), rcnt); /* Extract partial sector */ +#endif + } + + LEAVE_FF(fs, FR_OK); +} + + + + +#ifdef FF_FASTFS +/*-----------------------------------------------------------------------*/ +/* Fast Read Aligned Sized File Without a Cache */ +/*-----------------------------------------------------------------------*/ +#if FF_USE_FASTSEEK +FRESULT f_read_fast ( + FIL* fp, /* Pointer to the file object */ + const void* buff, /* Pointer to the data to be written */ + UINT btr /* Number of bytes to read */ +) +{ + FRESULT res; + FATFS *fs; + UINT csize_bytes; + DWORD clst; + UINT count = 0; + FSIZE_t work_sector = 0; + FSIZE_t sector_base = 0; + BYTE *wbuff = (BYTE*)buff; + + // TODO support sector reading inside a cluster + + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) { + EFSPRINTF("FOV"); + LEAVE_FF(fs, res); /* Check validity */ + } + + if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */ + FSIZE_t remain = fp->obj.objsize - fp->fptr; + if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ + + csize_bytes = fs->csize * SS(fs); + + if (!fp->fptr) { /* On the top of the file? */ + clst = fp->obj.sclust; /* Follow from the origin */ + } else { + if (fp->cltbl) clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ + else { EFSPRINTF("CLTBL"); ABORT(fs, FR_CLTBL_NO_INIT); } + } + if (clst < 2) { EFSPRINTF("CCHK"); ABORT(fs, FR_INT_ERR); } + else if (clst == 0xFFFFFFFF) { EFSPRINTF("DSKC"); ABORT(fs, FR_DISK_ERR); } + + fp->clust = clst; /* Set working cluster */ + + sector_base = clst2sect(fs, fp->clust); + count += fs->csize; + btr -= csize_bytes; + fp->fptr += csize_bytes; + + while (btr) { + clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ + + if (clst < 2) { EFSPRINTF("CCHK2"); ABORT(fs, FR_INT_ERR); } + else if (clst == 0xFFFFFFFF) { EFSPRINTF("DSKC"); ABORT(fs, FR_DISK_ERR); } + + fp->clust = clst; + + work_sector = clst2sect(fs, fp->clust); + if ((work_sector - sector_base) == count) count += fs->csize; + else { + if (disk_read(fs->pdrv, wbuff, sector_base, count) != RES_OK) ABORT(fs, FR_DISK_ERR); + wbuff += count * SS(fs); + + sector_base = work_sector; + count = fs->csize; + } + + fp->fptr += MIN(btr, csize_bytes); + btr -= MIN(btr, csize_bytes); + + // TODO: what about if data is smaller than cluster? + // Must read-write back that cluster. + + if (!btr) { /* Final cluster/sectors read. */ + if (disk_read(fs->pdrv, wbuff, sector_base, count) != RES_OK) ABORT(fs, FR_DISK_ERR); + } + } + + LEAVE_FF(fs, FR_OK); +} +#endif +#endif + + + + +#if !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Write File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_write ( + FIL* fp, /* Pointer to the file object */ + const void* buff, /* Pointer to the data to be written */ + UINT btw, /* Number of bytes to write */ + UINT* bw /* Pointer to number of bytes written */ +) +{ + FRESULT res; + FATFS *fs; + DWORD clst, sect; + UINT wcnt, cc, csect; + const BYTE *wbuff = (const BYTE*)buff; + + UINT bw_tmp; + if (!bw) + bw = &bw_tmp; + *bw = 0; /* Clear write byte counter */ + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) { + EFSPRINTF("FOV"); + LEAVE_FF(fs, res); /* Check validity */ + } + if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */ + + /* Check fptr wrap-around (file size cannot reach 4 GiB at FAT volume) */ + if ((!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) && (DWORD)(fp->fptr + btw) < (DWORD)fp->fptr) { + btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr); + } + + for ( ; btw; /* Repeat until all data written */ + btw -= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize) { + if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */ + csect = (UINT)(fp->fptr / SS(fs)) & (fs->csize - 1); /* Sector offset in the cluster */ + if (csect == 0) { /* On the cluster boundary? */ + if (fp->fptr == 0) { /* On the top of the file? */ + clst = fp->obj.sclust; /* Follow from the origin */ + if (clst == 0) { /* If no cluster is allocated, */ + clst = create_chain(&fp->obj, 0); /* create a new cluster chain */ + } + } else { /* On the middle or end of the file */ +#if FF_USE_FASTSEEK + if (fp->cltbl) { + clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ + } else +#endif + { + clst = create_chain(&fp->obj, fp->clust); /* Follow or stretch cluster chain on the FAT */ + } + } + if (clst == 0) { + EFSPRINTF("DSKFULL"); + break; /* Could not allocate a new cluster (disk full) */ + } + if (clst == 1) { + EFSPRINTF("CCHK"); + ABORT(fs, FR_INT_ERR); + } + if (clst == 0xFFFFFFFF) { + EFSPRINTF("DERR"); + ABORT(fs, FR_DISK_ERR); + } + fp->clust = clst; /* Update current cluster */ + if (fp->obj.sclust == 0) fp->obj.sclust = clst; /* Set start cluster if the first write */ + } +#if FF_FS_TINY + if (fs->winsect == fp->sect && sync_window(fs) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Write-back sector cache */ +#else + if (fp->flag & FA_DIRTY) { /* Write-back sector cache */ + if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); + fp->flag &= (BYTE)~FA_DIRTY; + } +#endif + sect = clst2sect(fs, fp->clust); /* Get current sector */ + if (sect == 0) ABORT(fs, FR_INT_ERR); + sect += csect; + cc = btw / SS(fs); /* When remaining bytes >= sector size, */ + if (cc > 0) { /* Write maximum contiguous sectors directly */ + if (csect + cc > fs->csize) { /* Clip at cluster boundary */ + cc = fs->csize - csect; + } + if (disk_write(fs->pdrv, wbuff, sect, cc) != RES_OK) { + EFSPRINTF("WLIO"); + ABORT(fs, FR_DISK_ERR); + } +#if FF_FS_MINIMIZE <= 2 +#if FF_FS_TINY + if (fs->winsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ + mem_cpy(fs->win, wbuff + ((fs->winsect - sect) * SS(fs)), SS(fs)); + fs->wflag = 0; + } +#else + if (fp->sect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ + mem_cpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs)); + fp->flag &= (BYTE)~FA_DIRTY; + } +#endif +#endif + wcnt = SS(fs) * cc; /* Number of bytes transferred */ + continue; + } +#if FF_FS_TINY + if (fp->fptr >= fp->obj.objsize) { /* Avoid silly cache filling on the growing edge */ + if (sync_window(fs) != FR_OK) ABORT(fs, FR_DISK_ERR); + fs->winsect = sect; + } +#else + if (fp->sect != sect && /* Fill sector cache with file data */ + fp->fptr < fp->obj.objsize && + disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) { + ABORT(fs, FR_DISK_ERR); + } +#endif + fp->sect = sect; + } + wcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes left in the sector */ + if (wcnt > btw) wcnt = btw; /* Clip it by btw if needed */ +#if FF_FS_TINY + if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */ + mem_cpy(fs->win + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */ + fs->wflag = 1; +#else + mem_cpy(fp->buf + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */ + fp->flag |= FA_DIRTY; +#endif + } + + fp->flag |= FA_MODIFIED; /* Set file change flag */ + + LEAVE_FF(fs, FR_OK); +} + + + + +#ifdef FF_FASTFS +/*-----------------------------------------------------------------------*/ +/* Fast Write Aligned Sized File Without a Cache */ +/*-----------------------------------------------------------------------*/ +#if FF_USE_FASTSEEK +FRESULT f_write_fast ( + FIL* fp, /* Pointer to the file object */ + const void* buff, /* Pointer to the data to be written */ + UINT btw /* Number of bytes to write */ +) +{ + FRESULT res; + FATFS *fs; + UINT csize_bytes; + DWORD clst; + UINT count = 0; + FSIZE_t work_sector = 0; + FSIZE_t sector_base = 0; + const BYTE *wbuff = (const BYTE*)buff; + + // TODO support sector writing inside a cluster + + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) { + EFSPRINTF("FOV"); + LEAVE_FF(fs, res); /* Check validity */ + } + + if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */ + /* Check fptr wrap-around (file size cannot reach 4 GiB at FAT volume) */ + if ((!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) && (DWORD)(fp->fptr + btw) < (DWORD)fp->fptr) { + btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr); + } + + csize_bytes = fs->csize * SS(fs); + + if (!fp->fptr) { /* On the top of the file? */ + clst = fp->obj.sclust; /* Follow from the origin */ + } else { + if (fp->cltbl) clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ + else { EFSPRINTF("CLTBL"); ABORT(fs, FR_CLTBL_NO_INIT); } + } + + if (clst < 2) { EFSPRINTF("CCHK"); ABORT(fs, FR_INT_ERR); } + else if (clst == 0xFFFFFFFF) { EFSPRINTF("DERR"); ABORT(fs, FR_DISK_ERR); } + + fp->clust = clst; /* Set working cluster */ + + sector_base = clst2sect(fs, fp->clust); + count += fs->csize; + btw -= csize_bytes; + fp->fptr += csize_bytes; + + while (btw) { + clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ + + if (clst < 2) { EFSPRINTF("CCHK2"); ABORT(fs, FR_INT_ERR); } + else if (clst == 0xFFFFFFFF) { EFSPRINTF("DERR"); ABORT(fs, FR_DISK_ERR); } + + fp->clust = clst; + + work_sector = clst2sect(fs, fp->clust); + if ((work_sector - sector_base) == count) count += fs->csize; + else { + if (disk_write(fs->pdrv, wbuff, sector_base, count) != RES_OK) ABORT(fs, FR_DISK_ERR); + wbuff += count * SS(fs); + + sector_base = work_sector; + count = fs->csize; + } + + fp->fptr += MIN(btw, csize_bytes); + btw -= MIN(btw, csize_bytes); + + // what about if data is smaller than cluster? + // Probably must read-write back that cluster. + if (!btw) { /* Final cluster/sectors write. */ + if (disk_write(fs->pdrv, wbuff, sector_base, count) != RES_OK) ABORT(fs, FR_DISK_ERR); + fp->flag &= (BYTE)~FA_DIRTY; + } + } + + fp->flag |= FA_MODIFIED; /* Set file change flag */ + + LEAVE_FF(fs, FR_OK); +} +#endif +#endif + + + + +/*-----------------------------------------------------------------------*/ +/* Synchronize the File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_sync ( + FIL* fp /* Pointer to the file object */ +) +{ + FRESULT res; + FATFS *fs; + DWORD tm; + BYTE *dir; + + + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res == FR_OK) { + if (fp->flag & FA_MODIFIED) { /* Is there any change to the file? */ +#if !FF_FS_TINY + if (fp->flag & FA_DIRTY) { /* Write-back cached data if needed */ + if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) LEAVE_FF(fs, FR_DISK_ERR); + fp->flag &= (BYTE)~FA_DIRTY; + } +#endif + /* Update the directory entry */ + tm = GET_FATTIME(); /* Modified time */ +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + res = fill_first_frag(&fp->obj); /* Fill first fragment on the FAT if needed */ + if (res == FR_OK) { + res = fill_last_frag(&fp->obj, fp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed */ + } + if (res == FR_OK) { + DIR dj; + DEF_NAMBUF + + INIT_NAMBUF(fs); + res = load_obj_xdir(&dj, &fp->obj); /* Load directory entry block */ + if (res == FR_OK) { + fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */ + fs->dirbuf[XDIR_GenFlags] = fp->obj.stat | 1; /* Update file allocation information */ + st_dword(fs->dirbuf + XDIR_FstClus, fp->obj.sclust); + st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize); + st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize); + st_dword(fs->dirbuf + XDIR_ModTime, tm); /* Update modified time */ + fs->dirbuf[XDIR_ModTime10] = 0; + st_dword(fs->dirbuf + XDIR_AccTime, 0); + res = store_xdir(&dj); /* Restore it to the directory */ + if (res == FR_OK) { + res = sync_fs(fs); + fp->flag &= (BYTE)~FA_MODIFIED; + } + } + FREE_NAMBUF(); + } + } else +#endif + { + res = move_window(fs, fp->dir_sect); + if (res == FR_OK) { + dir = fp->dir_ptr; + dir[DIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */ + st_clust(fp->obj.fs, dir, fp->obj.sclust); /* Update file allocation information */ + st_dword(dir + DIR_FileSize, (DWORD)fp->obj.objsize); /* Update file size */ + st_dword(dir + DIR_ModTime, tm); /* Update modified time */ + st_word(dir + DIR_LstAccDate, 0); + fs->wflag = 1; + res = sync_fs(fs); /* Restore it to the directory */ + fp->flag &= (BYTE)~FA_MODIFIED; + } + } + } + } + + LEAVE_FF(fs, res); +} + +#endif /* !FF_FS_READONLY */ + + + + +/*-----------------------------------------------------------------------*/ +/* Close File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_close ( + FIL* fp /* Pointer to the file object to be closed */ +) +{ + FRESULT res; + FATFS *fs; + +#if !FF_FS_READONLY + res = f_sync(fp); /* Flush cached data */ + if (res == FR_OK) +#endif + { + res = validate(&fp->obj, &fs); /* Lock volume */ + if (res == FR_OK) { +#if FF_FS_LOCK != 0 + res = dec_lock(fp->obj.lockid); /* Decrement file open counter */ + if (res == FR_OK) fp->obj.fs = 0; /* Invalidate file object */ +#else + fp->obj.fs = 0; /* Invalidate file object */ +#endif +#if FF_FS_REENTRANT + unlock_fs(fs, FR_OK); /* Unlock volume */ +#endif + } + } + return res; +} + + + + +#if FF_FS_RPATH >= 1 +/*-----------------------------------------------------------------------*/ +/* Change Current Directory or Current Drive, Get Current Directory */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_chdrive ( + const TCHAR* path /* Drive number to set */ +) +{ + int vol; + + + /* Get logical drive number */ + vol = get_ldnumber(&path); + if (vol < 0) return FR_INVALID_DRIVE; + CurrVol = (BYTE)vol; /* Set it as current volume */ + + return FR_OK; +} + + + +FRESULT f_chdir ( + const TCHAR* path /* Pointer to the directory path */ +) +{ +#if FF_STR_VOLUME_ID == 2 + UINT i; +#endif + FRESULT res; + DIR dj; + FATFS *fs; + DEF_NAMBUF + + + /* Get logical drive */ + res = find_volume(&path, &fs, 0); + if (res == FR_OK) { + dj.obj.fs = fs; + INIT_NAMBUF(fs); + res = follow_path(&dj, path); /* Follow the path */ + if (res == FR_OK) { /* Follow completed */ + if (dj.fn[NSFLAG] & NS_NONAME) { /* Is it the start directory itself? */ + fs->cdir = dj.obj.sclust; +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + fs->cdc_scl = dj.obj.c_scl; + fs->cdc_size = dj.obj.c_size; + fs->cdc_ofs = dj.obj.c_ofs; + } +#endif + } else { + if (dj.obj.attr & AM_DIR) { /* It is a sub-directory */ +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + fs->cdir = ld_dword(fs->dirbuf + XDIR_FstClus); /* Sub-directory cluster */ + fs->cdc_scl = dj.obj.sclust; /* Save containing directory information */ + fs->cdc_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat; + fs->cdc_ofs = dj.blk_ofs; + } else +#endif + { + fs->cdir = ld_clust(fs, dj.dir); /* Sub-directory cluster */ + } + } else { + res = FR_NO_PATH; /* Reached but a file */ + } + } + } + FREE_NAMBUF(); + if (res == FR_NO_FILE) res = FR_NO_PATH; +#if FF_STR_VOLUME_ID == 2 /* Also current drive is changed at Unix style volume ID */ + if (res == FR_OK) { + for (i = FF_VOLUMES - 1; i && fs != FatFs[i]; i--) ; /* Set current drive */ + CurrVol = (BYTE)i; + } +#endif + } + + LEAVE_FF(fs, res); +} + + +#if FF_FS_RPATH >= 2 +FRESULT f_getcwd ( + TCHAR* buff, /* Pointer to the directory path */ + UINT len /* Size of buff in unit of TCHAR */ +) +{ + FRESULT res; + DIR dj; + FATFS *fs; + UINT i, n; + DWORD ccl; + TCHAR *tp = buff; +#if FF_VOLUMES >= 2 + UINT vl; +#endif +#if FF_STR_VOLUME_ID + const char *vp; +#endif + FILINFO fno; + DEF_NAMBUF + + + /* Get logical drive */ + buff[0] = 0; /* Set null string to get current volume */ + res = find_volume((const TCHAR**)&buff, &fs, 0); /* Get current volume */ + if (res == FR_OK) { + dj.obj.fs = fs; + INIT_NAMBUF(fs); + + /* Follow parent directories and create the path */ + i = len; /* Bottom of buffer (directory stack base) */ + if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* (Cannot do getcwd on exFAT and returns root path) */ + dj.obj.sclust = fs->cdir; /* Start to follow upper directory from current directory */ + while ((ccl = dj.obj.sclust) != 0) { /* Repeat while current directory is a sub-directory */ + res = dir_sdi(&dj, 1 * SZDIRE); /* Get parent directory */ + if (res != FR_OK) break; + res = move_window(fs, dj.sect); + if (res != FR_OK) break; + dj.obj.sclust = ld_clust(fs, dj.dir); /* Goto parent directory */ + res = dir_sdi(&dj, 0); + if (res != FR_OK) break; + do { /* Find the entry links to the child directory */ + res = DIR_READ_FILE(&dj); + if (res != FR_OK) break; + if (ccl == ld_clust(fs, dj.dir)) break; /* Found the entry */ + res = dir_next(&dj, 0); + } while (res == FR_OK); + if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */ + if (res != FR_OK) break; + get_fileinfo(&dj, &fno); /* Get the directory name and push it to the buffer */ + for (n = 0; fno.fname[n]; n++) ; /* Name length */ + if (i < n + 1) { /* Insufficient space to store the path name? */ + res = FR_NOT_ENOUGH_CORE; break; + } + while (n) buff[--i] = fno.fname[--n]; /* Stack the name */ + buff[--i] = '/'; + } + } + if (res == FR_OK) { + if (i == len) buff[--i] = '/'; /* Is it the root-directory? */ +#if FF_VOLUMES >= 2 /* Put drive prefix */ + vl = 0; +#if FF_STR_VOLUME_ID >= 1 /* String volume ID */ + for (n = 0, vp = (const char*)VolumeStr[CurrVol]; vp[n]; n++) ; + if (i >= n + 2) { + if (FF_STR_VOLUME_ID == 2) *tp++ = (TCHAR)'/'; + for (vl = 0; vl < n; *tp++ = (TCHAR)vp[vl], vl++) ; + if (FF_STR_VOLUME_ID == 1) *tp++ = (TCHAR)':'; + vl++; + } +#else /* Numeric volume ID */ + if (i >= 3) { + *tp++ = (TCHAR)'0' + CurrVol; + *tp++ = (TCHAR)':'; + vl = 2; + } +#endif + if (vl == 0) res = FR_NOT_ENOUGH_CORE; +#endif + /* Add current directory path */ + if (res == FR_OK) { + do *tp++ = buff[i++]; while (i < len); /* Copy stacked path string */ + } + } + FREE_NAMBUF(); + } + + *tp = 0; + LEAVE_FF(fs, res); +} + +#endif /* FF_FS_RPATH >= 2 */ +#endif /* FF_FS_RPATH >= 1 */ + + + +#if FF_FS_MINIMIZE <= 2 +/*-----------------------------------------------------------------------*/ +/* Seek File Read/Write Pointer */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_lseek ( + FIL* fp, /* Pointer to the file object */ + FSIZE_t ofs /* File pointer from top of file */ +) +{ + FRESULT res; + FATFS *fs; + DWORD clst, bcs, nsect; + FSIZE_t ifptr; +#if FF_USE_FASTSEEK + DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl; +#endif + + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res == FR_OK) res = (FRESULT)fp->err; +#if FF_FS_EXFAT && !FF_FS_READONLY + if (res == FR_OK && fs->fs_type == FS_EXFAT) { + res = fill_last_frag(&fp->obj, fp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed */ + } +#endif + if (res != FR_OK) LEAVE_FF(fs, res); + +#if FF_USE_FASTSEEK + if (fp->cltbl) { /* Fast seek */ + if (ofs == CREATE_LINKMAP) { /* Create CLMT */ + tbl = fp->cltbl; + tlen = *tbl++; ulen = 2; /* Given table size and required table size */ + cl = fp->obj.sclust; /* Origin of the chain */ + if (cl != 0) { + do { + /* Get a fragment */ + tcl = cl; ncl = 0; ulen += 2; /* Top, length and used items */ + do { + pcl = cl; ncl++; + cl = get_fat(&fp->obj, cl); + if (cl <= 1) ABORT(fs, FR_INT_ERR); + if (cl == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR); + } while (cl == pcl + 1); + if (ulen <= tlen) { /* Store the length and top of the fragment */ + *tbl++ = ncl; *tbl++ = tcl; + } + } while (cl < fs->n_fatent); /* Repeat until end of chain */ + } + *fp->cltbl = ulen; /* Number of items used */ + if (ulen <= tlen) { + *tbl = 0; /* Terminate table */ + } else { + res = FR_NOT_ENOUGH_CORE; /* Given table size is smaller than required */ + } + } else { /* Fast seek */ + if (ofs > fp->obj.objsize) ofs = fp->obj.objsize; /* Clip offset at the file size */ + fp->fptr = ofs; /* Set file pointer */ + if (ofs > 0) { + fp->clust = clmt_clust(fp, ofs - 1); + dsc = clst2sect(fs, fp->clust); + if (dsc == 0) ABORT(fs, FR_INT_ERR); + dsc += (DWORD)((ofs - 1) / SS(fs)) & (fs->csize - 1); + if (fp->fptr % SS(fs) && dsc != fp->sect) { /* Refill sector cache if needed */ +#if !FF_FS_TINY +#if !FF_FS_READONLY + if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */ + if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); + fp->flag &= (BYTE)~FA_DIRTY; + } +#endif + if (disk_read(fs->pdrv, fp->buf, dsc, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Load current sector */ +#endif + fp->sect = dsc; + } + } + } + } else +#endif + + /* Normal Seek */ + { +#if FF_FS_EXFAT + if (fs->fs_type != FS_EXFAT && ofs >= 0x100000000) ofs = 0xFFFFFFFF; /* Clip at 4 GiB - 1 if at FATxx */ +#endif + if (ofs > fp->obj.objsize && (FF_FS_READONLY || !(fp->flag & FA_WRITE))) { /* In read-only mode, clip offset with the file size */ + ofs = fp->obj.objsize; + } + ifptr = fp->fptr; + fp->fptr = nsect = 0; + if (ofs > 0) { + bcs = (DWORD)fs->csize * SS(fs); /* Cluster size (byte) */ + if (ifptr > 0 && + (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */ + fp->fptr = (ifptr - 1) & ~(FSIZE_t)(bcs - 1); /* start from the current cluster */ + ofs -= fp->fptr; + clst = fp->clust; + } else { /* When seek to back cluster, */ + clst = fp->obj.sclust; /* start from the first cluster */ +#if !FF_FS_READONLY + if (clst == 0) { /* If no cluster chain, create a new chain */ + clst = create_chain(&fp->obj, 0); + if (clst == 1) ABORT(fs, FR_INT_ERR); + if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR); + fp->obj.sclust = clst; + } +#endif + fp->clust = clst; + } + if (clst != 0) { + while (ofs > bcs) { /* Cluster following loop */ + ofs -= bcs; fp->fptr += bcs; +#if !FF_FS_READONLY + if (fp->flag & FA_WRITE) { /* Check if in write mode or not */ + if (FF_FS_EXFAT && fp->fptr > fp->obj.objsize) { /* No FAT chain object needs correct objsize to generate FAT value */ + fp->obj.objsize = fp->fptr; + fp->flag |= FA_MODIFIED; + } + clst = create_chain(&fp->obj, clst); /* Follow chain with forceed stretch */ + if (clst == 0) { /* Clip file size in case of disk full */ + ofs = 0; break; + } + } else +#endif + { + clst = get_fat(&fp->obj, clst); /* Follow cluster chain if not in write mode */ + } + if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR); + if (clst <= 1 || clst >= fs->n_fatent) ABORT(fs, FR_INT_ERR); + fp->clust = clst; + } + fp->fptr += ofs; + if (ofs % SS(fs)) { + nsect = clst2sect(fs, clst); /* Current sector */ + if (nsect == 0) ABORT(fs, FR_INT_ERR); + nsect += (DWORD)(ofs / SS(fs)); + } + } + } + if (!FF_FS_READONLY && fp->fptr > fp->obj.objsize) { /* Set file change flag if the file size is extended */ + fp->obj.objsize = fp->fptr; + fp->flag |= FA_MODIFIED; + } + if (fp->fptr % SS(fs) && nsect != fp->sect) { /* Fill sector cache if needed */ +#if !FF_FS_TINY +#if !FF_FS_READONLY + if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */ + if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); + fp->flag &= (BYTE)~FA_DIRTY; + } +#endif + if (disk_read(fs->pdrv, fp->buf, nsect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache */ +#endif + fp->sect = nsect; + } + } + + LEAVE_FF(fs, res); +} + + + +#ifdef FF_FASTFS +#if FF_USE_FASTSEEK +/*-----------------------------------------------------------------------*/ +/* Seek File Read/Write Pointer */ +/*-----------------------------------------------------------------------*/ + +DWORD *f_expand_cltbl ( + FIL* fp, /* Pointer to the file object */ + UINT tblsz, /* Size of table */ + FSIZE_t ofs /* File pointer from top of file */ +) +{ + if (fp->flag & FA_WRITE) f_lseek(fp, ofs); /* Expand file if write is enabled */ + if (!fp->cltbl) { /* Allocate memory for cluster link table */ + fp->cltbl = (DWORD *)ff_memalloc(tblsz); + fp->cltbl[0] = tblsz; + } + if (f_lseek(fp, CREATE_LINKMAP)) { /* Create cluster link table */ + ff_memfree(fp->cltbl); + fp->cltbl = NULL; + EFSPRINTF("CLTBLSZ"); + return NULL; + } + f_lseek(fp, 0); + + return fp->cltbl; +} +#endif +#endif + + + + +#if FF_FS_MINIMIZE <= 1 +/*-----------------------------------------------------------------------*/ +/* Create a Directory Object */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_opendir ( + DIR* dp, /* Pointer to directory object to create */ + const TCHAR* path /* Pointer to the directory path */ +) +{ + FRESULT res; + FATFS *fs; + DEF_NAMBUF + + + if (!dp) return FR_INVALID_OBJECT; + + /* Get logical drive */ + res = find_volume(&path, &fs, 0); + if (res == FR_OK) { + dp->obj.fs = fs; + INIT_NAMBUF(fs); + res = follow_path(dp, path); /* Follow the path to the directory */ + if (res == FR_OK) { /* Follow completed */ + if (!(dp->fn[NSFLAG] & NS_NONAME)) { /* It is not the origin directory itself */ + if (dp->obj.attr & AM_DIR) { /* This object is a sub-directory */ +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + dp->obj.c_scl = dp->obj.sclust; /* Get containing directory inforamation */ + dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat; + dp->obj.c_ofs = dp->blk_ofs; + init_alloc_info(fs, &dp->obj); /* Get object allocation info */ + } else +#endif + { + dp->obj.sclust = ld_clust(fs, dp->dir); /* Get object allocation info */ + } + } else { /* This object is a file */ + res = FR_NO_PATH; + } + } + if (res == FR_OK) { + dp->obj.id = fs->id; + res = dir_sdi(dp, 0); /* Rewind directory */ +#if FF_FS_LOCK != 0 + if (res == FR_OK) { + if (dp->obj.sclust != 0) { + dp->obj.lockid = inc_lock(dp, 0); /* Lock the sub directory */ + if (!dp->obj.lockid) res = FR_TOO_MANY_OPEN_FILES; + } else { + dp->obj.lockid = 0; /* Root directory need not to be locked */ + } + } +#endif + } + } + FREE_NAMBUF(); + if (res == FR_NO_FILE) res = FR_NO_PATH; + } + if (res != FR_OK) dp->obj.fs = 0; /* Invalidate the directory object if function faild */ + + LEAVE_FF(fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Close Directory */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_closedir ( + DIR *dp /* Pointer to the directory object to be closed */ +) +{ + FRESULT res; + FATFS *fs; + + + res = validate(&dp->obj, &fs); /* Check validity of the file object */ + if (res == FR_OK) { +#if FF_FS_LOCK != 0 + if (dp->obj.lockid) res = dec_lock(dp->obj.lockid); /* Decrement sub-directory open counter */ + if (res == FR_OK) dp->obj.fs = 0; /* Invalidate directory object */ +#else + dp->obj.fs = 0; /* Invalidate directory object */ +#endif +#if FF_FS_REENTRANT + unlock_fs(fs, FR_OK); /* Unlock volume */ +#endif + } + return res; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Read Directory Entries in Sequence */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_readdir ( + DIR* dp, /* Pointer to the open directory object */ + FILINFO* fno /* Pointer to file information to return */ +) +{ + FRESULT res; + FATFS *fs; + DEF_NAMBUF + + + res = validate(&dp->obj, &fs); /* Check validity of the directory object */ + if (res == FR_OK) { + if (!fno) { + res = dir_sdi(dp, 0); /* Rewind the directory object */ + } else { + INIT_NAMBUF(fs); + res = DIR_READ_FILE(dp); /* Read an item */ + if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory */ + if (res == FR_OK) { /* A valid entry is found */ + get_fileinfo(dp, fno); /* Get the object information */ + res = dir_next(dp, 0); /* Increment index for next */ + if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory now */ + } + FREE_NAMBUF(); + } + } + LEAVE_FF(fs, res); +} + + + +#if FF_USE_FIND +/*-----------------------------------------------------------------------*/ +/* Find Next File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_findnext ( + DIR* dp, /* Pointer to the open directory object */ + FILINFO* fno /* Pointer to the file information structure */ +) +{ + FRESULT res; + + + for (;;) { + res = f_readdir(dp, fno); /* Get a directory item */ + if (res != FR_OK || !fno || !fno->fname[0]) break; /* Terminate if any error or end of directory */ + if (pattern_matching(dp->pat, fno->fname, 0, 0)) break; /* Test for the file name */ +#if FF_USE_LFN && FF_USE_FIND == 2 + if (pattern_matching(dp->pat, fno->altname, 0, 0)) break; /* Test for alternative name if exist */ +#endif + } + return res; +} + + + +/*-----------------------------------------------------------------------*/ +/* Find First File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_findfirst ( + DIR* dp, /* Pointer to the blank directory object */ + FILINFO* fno, /* Pointer to the file information structure */ + const TCHAR* path, /* Pointer to the directory to open */ + const TCHAR* pattern /* Pointer to the matching pattern */ +) +{ + FRESULT res; + + + dp->pat = pattern; /* Save pointer to pattern string */ + res = f_opendir(dp, path); /* Open the target directory */ + if (res == FR_OK) { + res = f_findnext(dp, fno); /* Find the first item */ + } + return res; +} + +#endif /* FF_USE_FIND */ + + + +#if FF_FS_MINIMIZE == 0 +/*-----------------------------------------------------------------------*/ +/* Get File Status */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_stat ( + const TCHAR* path, /* Pointer to the file path */ + FILINFO* fno /* Pointer to file information to return */ +) +{ + FRESULT res; + DIR dj; + DEF_NAMBUF + + + /* Get logical drive */ + res = find_volume(&path, &dj.obj.fs, 0); + if (res == FR_OK) { + INIT_NAMBUF(dj.obj.fs); + res = follow_path(&dj, path); /* Follow the file path */ + if (res == FR_OK) { /* Follow completed */ + if (dj.fn[NSFLAG] & NS_NONAME) { /* It is origin directory */ + res = FR_INVALID_NAME; + } else { /* Found an object */ + if (fno) get_fileinfo(&dj, fno); + } + } + FREE_NAMBUF(); + } + + LEAVE_FF(dj.obj.fs, res); +} + + + +#if !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Get Number of Free Clusters */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_getfree ( + const TCHAR* path, /* Logical drive number */ + DWORD* nclst, /* Pointer to a variable to return number of free clusters */ + FATFS** fatfs /* Pointer to return pointer to corresponding filesystem object */ +) +{ + FRESULT res; + FATFS *fs; + DWORD nfree, clst, sect, stat; + UINT i; + FFOBJID obj; + + + /* Get logical drive */ + res = find_volume(&path, &fs, 0); + if (res == FR_OK) { + if (fatfs) *fatfs = fs; /* Return ptr to the fs object */ + /* If free_clst is valid, return it without full FAT scan */ + if (fs->free_clst <= fs->n_fatent - 2) { + *nclst = fs->free_clst; + } else { + /* Scan FAT to obtain number of free clusters */ + nfree = 0; + if (fs->fs_type == FS_FAT12) { /* FAT12: Scan bit field FAT entries */ + clst = 2; obj.fs = fs; + do { + stat = get_fat(&obj, clst); + if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } + if (stat == 1) { res = FR_INT_ERR; break; } + if (stat == 0) nfree++; + } while (++clst < fs->n_fatent); + } else { +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* exFAT: Scan allocation bitmap */ + BYTE bm; + UINT b; + + clst = fs->n_fatent - 2; /* Number of clusters */ + sect = fs->bitbase; /* Bitmap sector */ + i = 0; /* Offset in the sector */ + do { /* Counts numbuer of bits with zero in the bitmap */ + if (i == 0) { + res = move_window(fs, sect++); + if (res != FR_OK) break; + } + for (b = 8, bm = fs->win[i]; b && clst; b--, clst--) { + if (!(bm & 1)) nfree++; + bm >>= 1; + } + i = (i + 1) % SS(fs); + } while (clst); + } else +#endif + { /* FAT16/32: Scan WORD/DWORD FAT entries */ + clst = fs->n_fatent; /* Number of entries */ + sect = fs->fatbase; /* Top of the FAT */ + i = 0; /* Offset in the sector */ + do { /* Counts numbuer of entries with zero in the FAT */ + if (i == 0) { + res = move_window(fs, sect++); + if (res != FR_OK) break; + } + if (fs->fs_type == FS_FAT16) { + if (ld_word(fs->win + i) == 0) nfree++; + i += 2; + } else { + if ((ld_dword(fs->win + i) & 0x0FFFFFFF) == 0) nfree++; + i += 4; + } + i %= SS(fs); + } while (--clst); + } + } + *nclst = nfree; /* Return the free clusters */ + fs->free_clst = nfree; /* Now free_clst is valid */ + fs->fsi_flag |= 1; /* FAT32: FSInfo is to be updated */ + } + } + + LEAVE_FF(fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Truncate File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_truncate ( + FIL* fp /* Pointer to the file object */ +) +{ + FRESULT res; + FATFS *fs; + DWORD ncl; + + + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res); + if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */ + + if (fp->fptr < fp->obj.objsize) { /* Process when fptr is not on the eof */ + if (fp->fptr == 0) { /* When set file size to zero, remove entire cluster chain */ + res = remove_chain(&fp->obj, fp->obj.sclust, 0); + fp->obj.sclust = 0; + } else { /* When truncate a part of the file, remove remaining clusters */ + ncl = get_fat(&fp->obj, fp->clust); + res = FR_OK; + if (ncl == 0xFFFFFFFF) res = FR_DISK_ERR; + if (ncl == 1) res = FR_INT_ERR; + if (res == FR_OK && ncl < fs->n_fatent) { + res = remove_chain(&fp->obj, ncl, fp->clust); + } + } + fp->obj.objsize = fp->fptr; /* Set file size to current read/write point */ + fp->flag |= FA_MODIFIED; +#if !FF_FS_TINY + if (res == FR_OK && (fp->flag & FA_DIRTY)) { + if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) { + res = FR_DISK_ERR; + } else { + fp->flag &= (BYTE)~FA_DIRTY; + } + } +#endif + if (res != FR_OK) ABORT(fs, res); + } + + LEAVE_FF(fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Delete a File/Directory */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_unlink ( + const TCHAR* path /* Pointer to the file or directory path */ +) +{ + FRESULT res; + DIR dj, sdj; + DWORD dclst = 0; + FATFS *fs; +#if FF_FS_EXFAT + FFOBJID obj; +#endif + DEF_NAMBUF + + + /* Get logical drive */ + res = find_volume(&path, &fs, FA_WRITE); + if (res == FR_OK) { + dj.obj.fs = fs; + INIT_NAMBUF(fs); + res = follow_path(&dj, path); /* Follow the file path */ + if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) { + res = FR_INVALID_NAME; /* Cannot remove dot entry */ + } +#if FF_FS_LOCK != 0 + if (res == FR_OK) res = chk_lock(&dj, 2); /* Check if it is an open object */ +#endif + if (res == FR_OK) { /* The object is accessible */ + if (dj.fn[NSFLAG] & NS_NONAME) { + res = FR_INVALID_NAME; /* Cannot remove the origin directory */ + } else { + if (dj.obj.attr & AM_RDO) { + res = FR_DENIED; /* Cannot remove R/O object */ + } + } + if (res == FR_OK) { +#if FF_FS_EXFAT + obj.fs = fs; + if (fs->fs_type == FS_EXFAT) { + init_alloc_info(fs, &obj); + dclst = obj.sclust; + } else +#endif + { + dclst = ld_clust(fs, dj.dir); + } + if (dj.obj.attr & AM_DIR) { /* Is it a sub-directory? */ +#if FF_FS_RPATH != 0 + if (dclst == fs->cdir) { /* Is it the current directory? */ + res = FR_DENIED; + } else +#endif + { + sdj.obj.fs = fs; /* Open the sub-directory */ + sdj.obj.sclust = dclst; +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + sdj.obj.objsize = obj.objsize; + sdj.obj.stat = obj.stat; + } +#endif + res = dir_sdi(&sdj, 0); + if (res == FR_OK) { + res = DIR_READ_FILE(&sdj); /* Test if the directory is empty */ + if (res == FR_OK) res = FR_DENIED; /* Not empty? */ + if (res == FR_NO_FILE) res = FR_OK; /* Empty? */ + } + } + } + } + if (res == FR_OK) { + res = dir_remove(&dj); /* Remove the directory entry */ + if (res == FR_OK && dclst != 0) { /* Remove the cluster chain if exist */ +#if FF_FS_EXFAT + res = remove_chain(&obj, dclst, 0); +#else + res = remove_chain(&dj.obj, dclst, 0); +#endif + } + if (res == FR_OK) res = sync_fs(fs); + } + } + FREE_NAMBUF(); + } + + LEAVE_FF(fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Create a Directory */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_mkdir ( + const TCHAR* path /* Pointer to the directory path */ +) +{ + FRESULT res; + DIR dj; + FFOBJID sobj; + FATFS *fs; + DWORD dcl, pcl, tm; + DEF_NAMBUF + + + res = find_volume(&path, &fs, FA_WRITE); /* Get logical drive */ + if (res == FR_OK) { + dj.obj.fs = fs; + INIT_NAMBUF(fs); + res = follow_path(&dj, path); /* Follow the file path */ + if (res == FR_OK) res = FR_EXIST; /* Name collision? */ + if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) { /* Invalid name? */ + res = FR_INVALID_NAME; + } + if (res == FR_NO_FILE) { /* It is clear to create a new directory */ + sobj.fs = fs; /* New object id to create a new chain */ + dcl = create_chain(&sobj, 0); /* Allocate a cluster for the new directory */ + res = FR_OK; + if (dcl == 0) res = FR_DENIED; /* No space to allocate a new cluster? */ + if (dcl == 1) res = FR_INT_ERR; /* Any insanity? */ + if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR; /* Disk error? */ + tm = GET_FATTIME(); + if (res == FR_OK) { + res = dir_clear(fs, dcl); /* Clean up the new table */ + if (res == FR_OK) { + if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* Create dot entries (FAT only) */ + mem_set(fs->win + DIR_Name, ' ', 11); /* Create "." entry */ + fs->win[DIR_Name] = '.'; + fs->win[DIR_Attr] = AM_DIR; + st_dword(fs->win + DIR_ModTime, tm); + st_clust(fs, fs->win, dcl); + mem_cpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */ + fs->win[SZDIRE + 1] = '.'; pcl = dj.obj.sclust; + st_clust(fs, fs->win + SZDIRE, pcl); + fs->wflag = 1; + } + res = dir_register(&dj); /* Register the object to the parent directoy */ + } + } + if (res == FR_OK) { +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* Initialize directory entry block */ + st_dword(fs->dirbuf + XDIR_ModTime, tm); /* Created time */ + st_dword(fs->dirbuf + XDIR_FstClus, dcl); /* Table start cluster */ + st_dword(fs->dirbuf + XDIR_FileSize, (DWORD)fs->csize * SS(fs)); /* File size needs to be valid */ + st_dword(fs->dirbuf + XDIR_ValidFileSize, (DWORD)fs->csize * SS(fs)); + fs->dirbuf[XDIR_GenFlags] = 3; /* Initialize the object flag */ + fs->dirbuf[XDIR_Attr] = AM_DIR; /* Attribute */ + res = store_xdir(&dj); + } else +#endif + { + st_dword(dj.dir + DIR_ModTime, tm); /* Created time */ + st_clust(fs, dj.dir, dcl); /* Table start cluster */ + dj.dir[DIR_Attr] = AM_DIR; /* Attribute */ + fs->wflag = 1; + } + if (res == FR_OK) { + res = sync_fs(fs); + } + } else { + remove_chain(&sobj, dcl, 0); /* Could not register, remove the allocated cluster */ + } + } + FREE_NAMBUF(); + } + + LEAVE_FF(fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Rename a File/Directory */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_rename ( + const TCHAR* path_old, /* Pointer to the object name to be renamed */ + const TCHAR* path_new /* Pointer to the new name */ +) +{ + FRESULT res; + DIR djo, djn; + FATFS *fs; + BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir; + DWORD dw; + DEF_NAMBUF + + + get_ldnumber(&path_new); /* Snip the drive number of new name off */ + res = find_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */ + if (res == FR_OK) { + djo.obj.fs = fs; + INIT_NAMBUF(fs); + res = follow_path(&djo, path_old); /* Check old object */ + if (res == FR_OK && (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check validity of name */ +#if FF_FS_LOCK != 0 + if (res == FR_OK) { + res = chk_lock(&djo, 2); + } +#endif + if (res == FR_OK) { /* Object to be renamed is found */ +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* At exFAT volume */ + BYTE nf, nn; + WORD nh; + + mem_cpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */ + mem_cpy(&djn, &djo, sizeof djo); + res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */ + if (res == FR_OK) { /* Is new name already in use by any other object? */ + res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST; + } + if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ + res = dir_register(&djn); /* Register the new entry */ + if (res == FR_OK) { + nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName]; + nh = ld_word(fs->dirbuf + XDIR_NameHash); + mem_cpy(fs->dirbuf, buf, SZDIRE * 2); /* Restore 85+C0 entry */ + fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn; + st_word(fs->dirbuf + XDIR_NameHash, nh); + if (!(fs->dirbuf[XDIR_Attr] & AM_DIR)) fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */ +/* Start of critical section where an interruption can cause a cross-link */ + res = store_xdir(&djn); + } + } + } else +#endif + { /* At FAT/FAT32 volume */ + mem_cpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */ + mem_cpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */ + res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */ + if (res == FR_OK) { /* Is new name already in use by any other object? */ + res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST; + } + if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ + res = dir_register(&djn); /* Register the new entry */ + if (res == FR_OK) { + dir = djn.dir; /* Copy directory entry of the object except name */ + mem_cpy(dir + 13, buf + 13, SZDIRE - 13); + dir[DIR_Attr] = buf[DIR_Attr]; + if (!(dir[DIR_Attr] & AM_DIR)) dir[DIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */ + fs->wflag = 1; + if ((dir[DIR_Attr] & AM_DIR) && djo.obj.sclust != djn.obj.sclust) { /* Update .. entry in the sub-directory if needed */ + dw = clst2sect(fs, ld_clust(fs, dir)); + if (dw == 0) { + res = FR_INT_ERR; + } else { +/* Start of critical section where an interruption can cause a cross-link */ + res = move_window(fs, dw); + dir = fs->win + SZDIRE * 1; /* Ptr to .. entry */ + if (res == FR_OK && dir[1] == '.') { + st_clust(fs, dir, djn.obj.sclust); + fs->wflag = 1; + } + } + } + } + } + } + if (res == FR_OK) { + res = dir_remove(&djo); /* Remove old entry */ + if (res == FR_OK) { + res = sync_fs(fs); + } + } +/* End of the critical section */ + } + FREE_NAMBUF(); + } + + LEAVE_FF(fs, res); +} + +#endif /* !FF_FS_READONLY */ +#endif /* FF_FS_MINIMIZE == 0 */ +#endif /* FF_FS_MINIMIZE <= 1 */ +#endif /* FF_FS_MINIMIZE <= 2 */ + + + +#if FF_USE_CHMOD && !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Change Attribute */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_chmod ( + const TCHAR* path, /* Pointer to the file path */ + BYTE attr, /* Attribute bits */ + BYTE mask /* Attribute mask to change */ +) +{ + FRESULT res; + DIR dj; + FATFS *fs; + DEF_NAMBUF + + + res = find_volume(&path, &fs, FA_WRITE); /* Get logical drive */ + if (res == FR_OK) { + dj.obj.fs = fs; + INIT_NAMBUF(fs); + res = follow_path(&dj, path); /* Follow the file path */ + if (res == FR_OK && (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check object validity */ + if (res == FR_OK) { + mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */ +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + fs->dirbuf[XDIR_Attr] = (attr & mask) | (fs->dirbuf[XDIR_Attr] & (BYTE)~mask); /* Apply attribute change */ + res = store_xdir(&dj); + } else +#endif + { + dj.dir[DIR_Attr] = (attr & mask) | (dj.dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */ + fs->wflag = 1; + } + if (res == FR_OK) { + res = sync_fs(fs); + } + } + FREE_NAMBUF(); + } + + LEAVE_FF(fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Change Timestamp */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_utime ( + const TCHAR* path, /* Pointer to the file/directory name */ + const FILINFO* fno /* Pointer to the timestamp to be set */ +) +{ + FRESULT res; + DIR dj; + FATFS *fs; + DEF_NAMBUF + + + res = find_volume(&path, &fs, FA_WRITE); /* Get logical drive */ + if (res == FR_OK) { + dj.obj.fs = fs; + INIT_NAMBUF(fs); + res = follow_path(&dj, path); /* Follow the file path */ + if (res == FR_OK && (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check object validity */ + if (res == FR_OK) { +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + st_dword(fs->dirbuf + XDIR_ModTime, (DWORD)fno->fdate << 16 | fno->ftime); + res = store_xdir(&dj); + } else +#endif + { + st_dword(dj.dir + DIR_ModTime, (DWORD)fno->fdate << 16 | fno->ftime); + fs->wflag = 1; + } + if (res == FR_OK) { + res = sync_fs(fs); + } + } + FREE_NAMBUF(); + } + + LEAVE_FF(fs, res); +} + +#endif /* FF_USE_CHMOD && !FF_FS_READONLY */ + + + +#if FF_USE_LABEL +/*-----------------------------------------------------------------------*/ +/* Get Volume Label */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_getlabel ( + const TCHAR* path, /* Logical drive number */ + TCHAR* label, /* Buffer to store the volume label */ + DWORD* vsn /* Variable to store the volume serial number */ +) +{ + FRESULT res; + DIR dj; + FATFS *fs; + UINT si, di; + WCHAR wc; + + /* Get logical drive */ + res = find_volume(&path, &fs, 0); + + /* Get volume label */ + if (res == FR_OK && label) { + dj.obj.fs = fs; dj.obj.sclust = 0; /* Open root directory */ + res = dir_sdi(&dj, 0); + if (res == FR_OK) { + res = DIR_READ_LABEL(&dj); /* Find a volume label entry */ + if (res == FR_OK) { +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + WCHAR hs; + + for (si = di = hs = 0; si < dj.dir[XDIR_NumLabel]; si++) { /* Extract volume label from 83 entry */ + wc = ld_word(dj.dir + XDIR_Label + si * 2); + if (hs == 0 && IsSurrogate(wc)) { /* Is the code a surrogate? */ + hs = wc; continue; + } + wc = put_utf((DWORD)hs << 16 | wc, &label[di], 4); + if (wc == 0) { di = 0; break; } + di += wc; + hs = 0; + } + if (hs != 0) di = 0; /* Broken surrogate pair? */ + label[di] = 0; + } else +#endif + { + si = di = 0; /* Extract volume label from AM_VOL entry */ + while (si < 11) { + wc = dj.dir[si++]; +#if FF_USE_LFN && FF_LFN_UNICODE >= 1 /* Unicode output */ + if (dbc_1st((BYTE)wc) && si < 11) wc = wc << 8 | dj.dir[si++]; /* Is it a DBC? */ + wc = ff_oem2uni(wc, CODEPAGE); /* Convert it into Unicode */ + if (wc != 0) wc = put_utf(wc, &label[di], 4); /* Put it in Unicode */ + if (wc == 0) { di = 0; break; } + di += wc; +#else /* ANSI/OEM output */ + label[di++] = (TCHAR)wc; +#endif + } + do { /* Truncate trailing spaces */ + label[di] = 0; + if (di == 0) break; + } while (label[--di] == ' '); + } + } + } + if (res == FR_NO_FILE) { /* No label entry and return nul string */ + label[0] = 0; + res = FR_OK; + } + } + + /* Get volume serial number */ + if (res == FR_OK && vsn) { + res = move_window(fs, fs->volbase); + if (res == FR_OK) { + switch (fs->fs_type) { + case FS_EXFAT: + di = BPB_VolIDEx; break; + + case FS_FAT32: + di = BS_VolID32; break; + + default: + di = BS_VolID; + } + *vsn = ld_dword(fs->win + di); + } + } + + LEAVE_FF(fs, res); +} + + + +#if !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Set Volume Label */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_setlabel ( + const TCHAR* label /* Volume label to set with heading logical drive number */ +) +{ + FRESULT res; + DIR dj; + FATFS *fs; + BYTE dirvn[22]; + UINT di; + WCHAR wc; + static const char badchr[] = "+.,;=[]/\\\"*:<>\?|\x7F"; /* [0..] for FAT, [7..] for exFAT */ +#if FF_USE_LFN + DWORD dc; +#endif + + /* Get logical drive */ + res = find_volume(&label, &fs, FA_WRITE); + if (res != FR_OK) LEAVE_FF(fs, res); + +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + mem_set(dirvn, 0, 22); + di = 0; + while ((UINT)*label >= ' ') { /* Create volume label */ + dc = tchar2uni(&label); /* Get a Unicode character */ + if (dc >= 0x10000) { + if (dc == 0xFFFFFFFF || di >= 10) { /* Wrong surrogate or buffer overflow */ + dc = 0; + } else { + st_word(dirvn + di * 2, (WCHAR)(dc >> 16)); di++; + } + } + if (dc == 0 || chk_chr(badchr + 7, (int)dc) || di >= 11) { /* Check validity of the volume label */ + LEAVE_FF(fs, FR_INVALID_NAME); + } + st_word(dirvn + di * 2, (WCHAR)dc); di++; + } + } else +#endif + { /* On the FAT/FAT32 volume */ + mem_set(dirvn, ' ', 11); + di = 0; + while ((UINT)*label >= ' ') { /* Create volume label */ +#if FF_USE_LFN + dc = tchar2uni(&label); + wc = (dc < 0x10000) ? ff_uni2oem(ff_wtoupper(dc), CODEPAGE) : 0; +#else /* ANSI/OEM input */ + wc = (BYTE)*label++; + if (dbc_1st((BYTE)wc)) wc = dbc_2nd((BYTE)*label) ? wc << 8 | (BYTE)*label++ : 0; + if (IsLower(wc)) wc -= 0x20; /* To upper ASCII characters */ +#if FF_CODE_PAGE == 0 + if (ExCvt && wc >= 0x80) wc = ExCvt[wc - 0x80]; /* To upper extended characters (SBCS cfg) */ +#elif FF_CODE_PAGE < 900 + if (wc >= 0x80) wc = ExCvt[wc - 0x80]; /* To upper extended characters (SBCS cfg) */ +#endif +#endif + if (wc == 0 || chk_chr(badchr + 0, (int)wc) || di >= (UINT)((wc >= 0x100) ? 10 : 11)) { /* Reject invalid characters for volume label */ + LEAVE_FF(fs, FR_INVALID_NAME); + } + if (wc >= 0x100) dirvn[di++] = (BYTE)(wc >> 8); + dirvn[di++] = (BYTE)wc; + } + if (dirvn[0] == DDEM) LEAVE_FF(fs, FR_INVALID_NAME); /* Reject illegal name (heading DDEM) */ + while (di && dirvn[di - 1] == ' ') di--; /* Snip trailing spaces */ + } + + /* Set volume label */ + dj.obj.fs = fs; dj.obj.sclust = 0; /* Open root directory */ + res = dir_sdi(&dj, 0); + if (res == FR_OK) { + res = DIR_READ_LABEL(&dj); /* Get volume label entry */ + if (res == FR_OK) { + if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) { + dj.dir[XDIR_NumLabel] = (BYTE)di; /* Change the volume label */ + mem_cpy(dj.dir + XDIR_Label, dirvn, 22); + } else { + if (di != 0) { + mem_cpy(dj.dir, dirvn, 11); /* Change the volume label */ + } else { + dj.dir[DIR_Name] = DDEM; /* Remove the volume label */ + } + } + fs->wflag = 1; + res = sync_fs(fs); + } else { /* No volume label entry or an error */ + if (res == FR_NO_FILE) { + res = FR_OK; + if (di != 0) { /* Create a volume label entry */ + res = dir_alloc(&dj, 1); /* Allocate an entry */ + if (res == FR_OK) { + mem_set(dj.dir, 0, SZDIRE); /* Clean the entry */ + if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) { + dj.dir[XDIR_Type] = ET_VLABEL; /* Create volume label entry */ + dj.dir[XDIR_NumLabel] = (BYTE)di; + mem_cpy(dj.dir + XDIR_Label, dirvn, 22); + } else { + dj.dir[DIR_Attr] = AM_VOL; /* Create volume label entry */ + mem_cpy(dj.dir, dirvn, 11); + } + fs->wflag = 1; + res = sync_fs(fs); + } + } + } + } + } + + LEAVE_FF(fs, res); +} + +#endif /* !FF_FS_READONLY */ +#endif /* FF_USE_LABEL */ + + + +#if FF_USE_EXPAND && !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Allocate a Contiguous Blocks to the File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_expand ( + FIL* fp, /* Pointer to the file object */ + FSIZE_t fsz, /* File size to be expanded to */ + BYTE opt /* Operation mode 0:Find and prepare or 1:Find and allocate */ +) +{ + FRESULT res; + FATFS *fs; + DWORD n, clst, stcl, scl, ncl, tcl, lclst; + + + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res); + if (fsz == 0 || fp->obj.objsize != 0 || !(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); +#if FF_FS_EXFAT + if (fs->fs_type != FS_EXFAT && fsz >= 0x100000000) LEAVE_FF(fs, FR_DENIED); /* Check if in size limit */ +#endif + n = (DWORD)fs->csize * SS(fs); /* Cluster size */ + tcl = (DWORD)(fsz / n) + ((fsz & (n - 1)) ? 1 : 0); /* Number of clusters required */ + stcl = fs->last_clst; lclst = 0; + if (stcl < 2 || stcl >= fs->n_fatent) stcl = 2; + +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { + scl = find_bitmap(fs, stcl, tcl); /* Find a contiguous cluster block */ + if (scl == 0) res = FR_DENIED; /* No contiguous cluster block was found */ + if (scl == 0xFFFFFFFF) res = FR_DISK_ERR; + if (res == FR_OK) { /* A contiguous free area is found */ + if (opt) { /* Allocate it now */ + res = change_bitmap(fs, scl, tcl, 1); /* Mark the cluster block 'in use' */ + lclst = scl + tcl - 1; + } else { /* Set it as suggested point for next allocation */ + lclst = scl - 1; + } + } + } else +#endif + { + scl = clst = stcl; ncl = 0; + for (;;) { /* Find a contiguous cluster block */ + n = get_fat(&fp->obj, clst); + if (++clst >= fs->n_fatent) clst = 2; + if (n == 1) { res = FR_INT_ERR; break; } + if (n == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } + if (n == 0) { /* Is it a free cluster? */ + if (++ncl == tcl) break; /* Break if a contiguous cluster block is found */ + } else { + scl = clst; ncl = 0; /* Not a free cluster */ + } + if (clst == stcl) { res = FR_DENIED; break; } /* No contiguous cluster? */ + } + if (res == FR_OK) { /* A contiguous free area is found */ + if (opt) { /* Allocate it now */ + for (clst = scl, n = tcl; n; clst++, n--) { /* Create a cluster chain on the FAT */ + res = put_fat(fs, clst, (n == 1) ? 0xFFFFFFFF : clst + 1); + if (res != FR_OK) break; + lclst = clst; + } + } else { /* Set it as suggested point for next allocation */ + lclst = scl - 1; + } + } + } + + if (res == FR_OK) { + fs->last_clst = lclst; /* Set suggested start cluster to start next */ + if (opt) { /* Is it allocated now? */ + fp->obj.sclust = scl; /* Update object allocation information */ + fp->obj.objsize = fsz; + if (FF_FS_EXFAT) fp->obj.stat = 2; /* Set status 'contiguous chain' */ + fp->flag |= FA_MODIFIED; + if (fs->free_clst <= fs->n_fatent - 2) { /* Update FSINFO */ + fs->free_clst -= tcl; + fs->fsi_flag |= 1; + } + } + } + + LEAVE_FF(fs, res); +} + +#endif /* FF_USE_EXPAND && !FF_FS_READONLY */ + + + +#if FF_USE_FORWARD +/*-----------------------------------------------------------------------*/ +/* Forward Data to the Stream Directly */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_forward ( + FIL* fp, /* Pointer to the file object */ + UINT (*func)(const BYTE*,UINT), /* Pointer to the streaming function */ + UINT btf, /* Number of bytes to forward */ + UINT* bf /* Pointer to number of bytes forwarded */ +) +{ + FRESULT res; + FATFS *fs; + DWORD clst, sect; + FSIZE_t remain; + UINT rcnt, csect; + BYTE *dbuf; + + + *bf = 0; /* Clear transfer byte counter */ + res = validate(&fp->obj, &fs); /* Check validity of the file object */ + if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res); + if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */ + + remain = fp->obj.objsize - fp->fptr; + if (btf > remain) btf = (UINT)remain; /* Truncate btf by remaining bytes */ + + for ( ; btf && (*func)(0, 0); /* Repeat until all data transferred or stream goes busy */ + fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) { + csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */ + if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */ + if (csect == 0) { /* On the cluster boundary? */ + clst = (fp->fptr == 0) ? /* On the top of the file? */ + fp->obj.sclust : get_fat(&fp->obj, fp->clust); + if (clst <= 1) ABORT(fs, FR_INT_ERR); + if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR); + fp->clust = clst; /* Update current cluster */ + } + } + sect = clst2sect(fs, fp->clust); /* Get current data sector */ + if (sect == 0) ABORT(fs, FR_INT_ERR); + sect += csect; +#if FF_FS_TINY + if (move_window(fs, sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window to the file data */ + dbuf = fs->win; +#else + if (fp->sect != sect) { /* Fill sector cache with file data */ +#if !FF_FS_READONLY + if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */ + if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); + fp->flag &= (BYTE)~FA_DIRTY; + } +#endif + if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); + } + dbuf = fp->buf; +#endif + fp->sect = sect; + rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes left in the sector */ + if (rcnt > btf) rcnt = btf; /* Clip it by btr if needed */ + rcnt = (*func)(dbuf + ((UINT)fp->fptr % SS(fs)), rcnt); /* Forward the file data */ + if (rcnt == 0) ABORT(fs, FR_INT_ERR); + } + + LEAVE_FF(fs, FR_OK); +} +#endif /* FF_USE_FORWARD */ + + + +#if FF_USE_MKFS && !FF_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Create an FAT/exFAT volume */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_mkfs ( + const TCHAR* path, /* Logical drive number */ + BYTE opt, /* Format option */ + DWORD au, /* Size of allocation unit (cluster) [byte] */ + void* work, /* Pointer to working buffer (null: use heap memory) */ + UINT len /* Size of working buffer [byte] */ +) +{ + const UINT n_fats = 1; /* Number of FATs for FAT/FAT32 volume (1 or 2) */ + const UINT n_rootdir = 512; /* Number of root directory entries for FAT volume */ + static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */ + static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */ + BYTE fmt, sys, *buf, *pte, pdrv, part; + WORD ss; /* Sector size */ + DWORD szb_buf, sz_buf, sz_blk, n_clst, pau, sect, nsect, n; + DWORD b_vol, b_fat, b_data; /* Base LBA for volume, fat, data */ + DWORD sz_vol, sz_rsv, sz_fat, sz_dir; /* Size for volume, fat, dir, data */ + UINT i; + int vol; + DSTATUS stat; +#if FF_USE_TRIM || FF_FS_EXFAT + DWORD tbl[3]; +#endif + + + /* Check mounted drive and clear work area */ + vol = get_ldnumber(&path); /* Get target logical drive */ + if (vol < 0) return FR_INVALID_DRIVE; + if (FatFs[vol]) FatFs[vol]->fs_type = 0; /* Clear the volume if mounted */ + pdrv = LD2PD(vol); /* Physical drive */ + part = LD2PT(vol); /* Partition (0:create as new, 1-4:get from partition table) */ + + /* Check physical drive status */ + stat = disk_initialize(pdrv); + if (stat & STA_NOINIT) return FR_NOT_READY; + if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; + if (disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_blk) != RES_OK || !sz_blk || sz_blk > 32768 || (sz_blk & (sz_blk - 1))) sz_blk = 1; /* Erase block to align data area */ +#if FF_MAX_SS != FF_MIN_SS /* Get sector size of the medium if variable sector size cfg. */ + if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) return FR_DISK_ERR; + if (ss > FF_MAX_SS || ss < FF_MIN_SS || (ss & (ss - 1))) return FR_DISK_ERR; +#else + ss = FF_MAX_SS; +#endif + if ((au != 0 && au < ss) || au > 0x1000000 || (au & (au - 1))) return FR_INVALID_PARAMETER; /* Check if au is valid */ + au /= ss; /* Cluster size in unit of sector */ + + /* Get working buffer */ +#if FF_USE_LFN == 3 + if (!work) { /* Use heap memory for working buffer */ + for (szb_buf = MAX_MALLOC, buf = 0; szb_buf >= ss && (buf = ff_memalloc(szb_buf)) == 0; szb_buf /= 2) ; + sz_buf = szb_buf / ss; /* Size of working buffer (sector) */ + } else +#endif + { + buf = (BYTE*)work; /* Working buffer */ + sz_buf = len / ss; /* Size of working buffer (sector) */ + szb_buf = sz_buf * ss; /* Size of working buffer (byte) */ + } + if (!buf || sz_buf == 0) return FR_NOT_ENOUGH_CORE; + + /* Determine where the volume to be located (b_vol, sz_vol) */ + if (FF_MULTI_PARTITION && part != 0) { + /* Get partition information from partition table in the MBR */ + if (disk_read(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Load MBR */ + if (ld_word(buf + BS_55AA) != 0xAA55) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if MBR is valid */ + pte = buf + (MBR_Table + (part - 1) * SZ_PTE); + if (pte[PTE_System] == 0) LEAVE_MKFS(FR_MKFS_ABORTED); /* No partition? */ + b_vol = ld_dword(pte + PTE_StLba); /* Get volume start sector */ + sz_vol = ld_dword(pte + PTE_SizLba); /* Get volume size */ + } else { + /* Create a single-partition in this function */ + if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_vol) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + b_vol = (opt & FM_SFD) ? 0 : 63; /* Volume start sector */ + if (sz_vol < b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); + sz_vol -= b_vol; /* Volume size */ + } + if (sz_vol < 128) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if volume size is >=128s */ + + /* Pre-determine the FAT type */ + do { + if (FF_FS_EXFAT && (opt & FM_EXFAT)) { /* exFAT possible? */ + if ((opt & FM_ANY) == FM_EXFAT || sz_vol >= 0x4000000 || au > 128) { /* exFAT only, vol >= 64Ms or au > 128s ? */ + fmt = FS_EXFAT; break; + } + } + if (au > 128) LEAVE_MKFS(FR_INVALID_PARAMETER); /* Too large au for FAT/FAT32 */ + if (opt & FM_FAT32) { /* FAT32 possible? */ + if ((opt & FM_ANY) == FM_FAT32 || !(opt & FM_FAT)) { /* FAT32 only or no-FAT? */ + fmt = FS_FAT32; break; + } + } + if (!(opt & FM_FAT)) LEAVE_MKFS(FR_INVALID_PARAMETER); /* no-FAT? */ + fmt = FS_FAT16; + } while (0); + +#if FF_FS_EXFAT + if (fmt == FS_EXFAT) { /* Create an exFAT volume */ + DWORD szb_bit, szb_case, sum, nb, cl; + WCHAR ch, si; + UINT j, st; + BYTE b; + + if (sz_vol < 0x1000) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume? */ +#if FF_USE_TRIM + tbl[0] = b_vol; tbl[1] = b_vol + sz_vol - 1; /* Inform the device the volume area may be erased */ + disk_ioctl(pdrv, CTRL_TRIM, tbl); +#endif + /* Determine FAT location, data location and number of clusters */ + if (au == 0) { /* au auto-selection */ + au = 8; + if (sz_vol >= 0x80000) au = 64; /* >= 512Ks */ + if (sz_vol >= 0x4000000) au = 256; /* >= 64Ms */ + } + b_fat = b_vol + 32; /* FAT start at offset 32 */ + sz_fat = ((sz_vol / au + 2) * 4 + ss - 1) / ss; /* Number of FAT sectors */ + b_data = (b_fat + sz_fat + sz_blk - 1) & ~(sz_blk - 1); /* Align data area to the erase block boundary */ + if (b_data - b_vol >= sz_vol / 2) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume? */ + n_clst = (sz_vol - (b_data - b_vol)) / au; /* Number of clusters */ + if (n_clst <16) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too few clusters? */ + if (n_clst > MAX_EXFAT) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too many clusters? */ + + szb_bit = (n_clst + 7) / 8; /* Size of allocation bitmap */ + tbl[0] = (szb_bit + au * ss - 1) / (au * ss); /* Number of allocation bitmap clusters */ + + /* Create a compressed up-case table */ + sect = b_data + au * tbl[0]; /* Table start sector */ + sum = 0; /* Table checksum to be stored in the 82 entry */ + st = 0; si = 0; i = 0; j = 0; szb_case = 0; + do { + switch (st) { + case 0: + ch = (WCHAR)ff_wtoupper(si); /* Get an up-case char */ + if (ch != si) { + si++; break; /* Store the up-case char if exist */ + } + for (j = 1; (WCHAR)(si + j) && (WCHAR)(si + j) == ff_wtoupper((WCHAR)(si + j)); j++) ; /* Get run length of no-case block */ + if (j >= 128) { + ch = 0xFFFF; st = 2; break; /* Compress the no-case block if run is >= 128 */ + } + st = 1; /* Do not compress short run */ + /* go to next case */ + case 1: + ch = si++; /* Fill the short run */ + if (--j == 0) st = 0; + break; + + default: + ch = (WCHAR)j; si += (WCHAR)j; /* Number of chars to skip */ + st = 0; + } + sum = xsum32(buf[i + 0] = (BYTE)ch, sum); /* Put it into the write buffer */ + sum = xsum32(buf[i + 1] = (BYTE)(ch >> 8), sum); + i += 2; szb_case += 2; + if (si == 0 || i == szb_buf) { /* Write buffered data when buffer full or end of process */ + n = (i + ss - 1) / ss; + if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + sect += n; i = 0; + } + } while (si); + tbl[1] = (szb_case + au * ss - 1) / (au * ss); /* Number of up-case table clusters */ + tbl[2] = 1; /* Number of root dir clusters */ + + /* Initialize the allocation bitmap */ + sect = b_data; nsect = (szb_bit + ss - 1) / ss; /* Start of bitmap and number of sectors */ + nb = tbl[0] + tbl[1] + tbl[2]; /* Number of clusters in-use by system */ + do { + mem_set(buf, 0, szb_buf); + for (i = 0; nb >= 8 && i < szb_buf; buf[i++] = 0xFF, nb -= 8) ; + for (b = 1; nb != 0 && i < szb_buf; buf[i] |= b, b <<= 1, nb--) ; + n = (nsect > sz_buf) ? sz_buf : nsect; /* Write the buffered data */ + if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + sect += n; nsect -= n; + } while (nsect); + + /* Initialize the FAT */ + sect = b_fat; nsect = sz_fat; /* Start of FAT and number of FAT sectors */ + j = nb = cl = 0; + do { + mem_set(buf, 0, szb_buf); i = 0; /* Clear work area and reset write index */ + if (cl == 0) { /* Set entry 0 and 1 */ + st_dword(buf + i, 0xFFFFFFF8); i += 4; cl++; + st_dword(buf + i, 0xFFFFFFFF); i += 4; cl++; + } + do { /* Create chains of bitmap, up-case and root dir */ + while (nb != 0 && i < szb_buf) { /* Create a chain */ + st_dword(buf + i, (nb > 1) ? cl + 1 : 0xFFFFFFFF); + i += 4; cl++; nb--; + } + if (nb == 0 && j < 3) nb = tbl[j++]; /* Next chain */ + } while (nb != 0 && i < szb_buf); + n = (nsect > sz_buf) ? sz_buf : nsect; /* Write the buffered data */ + if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + sect += n; nsect -= n; + } while (nsect); + + /* Initialize the root directory */ + mem_set(buf, 0, szb_buf); + buf[SZDIRE * 0 + 0] = ET_VLABEL; /* Volume label entry */ + buf[SZDIRE * 1 + 0] = ET_BITMAP; /* Bitmap entry */ + st_dword(buf + SZDIRE * 1 + 20, 2); /* cluster */ + st_dword(buf + SZDIRE * 1 + 24, szb_bit); /* size */ + buf[SZDIRE * 2 + 0] = ET_UPCASE; /* Up-case table entry */ + st_dword(buf + SZDIRE * 2 + 4, sum); /* sum */ + st_dword(buf + SZDIRE * 2 + 20, 2 + tbl[0]); /* cluster */ + st_dword(buf + SZDIRE * 2 + 24, szb_case); /* size */ + sect = b_data + au * (tbl[0] + tbl[1]); nsect = au; /* Start of the root directory and number of sectors */ + do { /* Fill root directory sectors */ + n = (nsect > sz_buf) ? sz_buf : nsect; + if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + mem_set(buf, 0, ss); + sect += n; nsect -= n; + } while (nsect); + + /* Create two set of the exFAT VBR blocks */ + sect = b_vol; + for (n = 0; n < 2; n++) { + /* Main record (+0) */ + mem_set(buf, 0, ss); + mem_cpy(buf + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11); /* Boot jump code (x86), OEM name */ + st_dword(buf + BPB_VolOfsEx, b_vol); /* Volume offset in the physical drive [sector] */ + st_dword(buf + BPB_TotSecEx, sz_vol); /* Volume size [sector] */ + st_dword(buf + BPB_FatOfsEx, b_fat - b_vol); /* FAT offset [sector] */ + st_dword(buf + BPB_FatSzEx, sz_fat); /* FAT size [sector] */ + st_dword(buf + BPB_DataOfsEx, b_data - b_vol); /* Data offset [sector] */ + st_dword(buf + BPB_NumClusEx, n_clst); /* Number of clusters */ + st_dword(buf + BPB_RootClusEx, 2 + tbl[0] + tbl[1]); /* Root dir cluster # */ + st_dword(buf + BPB_VolIDEx, GET_FATTIME()); /* VSN */ + st_word(buf + BPB_FSVerEx, 0x100); /* Filesystem version (1.00) */ + for (buf[BPB_BytsPerSecEx] = 0, i = ss; i >>= 1; buf[BPB_BytsPerSecEx]++) ; /* Log2 of sector size [byte] */ + for (buf[BPB_SecPerClusEx] = 0, i = au; i >>= 1; buf[BPB_SecPerClusEx]++) ; /* Log2 of cluster size [sector] */ + buf[BPB_NumFATsEx] = 1; /* Number of FATs */ + buf[BPB_DrvNumEx] = 0x80; /* Drive number (for int13) */ + st_word(buf + BS_BootCodeEx, 0xFEEB); /* Boot code (x86) */ + st_word(buf + BS_55AA, 0xAA55); /* Signature (placed here regardless of sector size) */ + for (i = sum = 0; i < ss; i++) { /* VBR checksum */ + if (i != BPB_VolFlagEx && i != BPB_VolFlagEx + 1 && i != BPB_PercInUseEx) sum = xsum32(buf[i], sum); + } + if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + /* Extended bootstrap record (+1..+8) */ + mem_set(buf, 0, ss); + st_word(buf + ss - 2, 0xAA55); /* Signature (placed at end of sector) */ + for (j = 1; j < 9; j++) { + for (i = 0; i < ss; sum = xsum32(buf[i++], sum)) ; /* VBR checksum */ + if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + } + /* OEM/Reserved record (+9..+10) */ + mem_set(buf, 0, ss); + for ( ; j < 11; j++) { + for (i = 0; i < ss; sum = xsum32(buf[i++], sum)) ; /* VBR checksum */ + if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + } + /* Sum record (+11) */ + for (i = 0; i < ss; i += 4) st_dword(buf + i, sum); /* Fill with checksum value */ + if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + } + + } else +#endif /* FF_FS_EXFAT */ + { /* Create an FAT/FAT32 volume */ + do { + pau = au; + /* Pre-determine number of clusters and FAT sub-type */ + if (fmt == FS_FAT32) { /* FAT32 volume */ + if (pau == 0) { /* au auto-selection */ + n = sz_vol / 0x20000; /* Volume size in unit of 128KS */ + for (i = 0, pau = 1; cst32[i] && cst32[i] <= n; i++, pau <<= 1) ; /* Get from table */ + } + n_clst = sz_vol / pau; /* Number of clusters */ + sz_fat = (n_clst * 4 + 8 + ss - 1) / ss; /* FAT size [sector] */ + sz_rsv = 32; /* Number of reserved sectors */ + sz_dir = 0; /* No static directory */ + if (n_clst <= MAX_FAT16 || n_clst > MAX_FAT32) LEAVE_MKFS(FR_MKFS_ABORTED); + } else { /* FAT volume */ + if (pau == 0) { /* au auto-selection */ + n = sz_vol / 0x1000; /* Volume size in unit of 4KS */ + for (i = 0, pau = 1; cst[i] && cst[i] <= n; i++, pau <<= 1) ; /* Get from table */ + } + n_clst = sz_vol / pau; + if (n_clst > MAX_FAT12) { + n = n_clst * 2 + 4; /* FAT size [byte] */ + } else { + fmt = FS_FAT12; + n = (n_clst * 3 + 1) / 2 + 3; /* FAT size [byte] */ + } + sz_fat = (n + ss - 1) / ss; /* FAT size [sector] */ + sz_rsv = 1; /* Number of reserved sectors */ + sz_dir = (DWORD)n_rootdir * SZDIRE / ss; /* Rootdir size [sector] */ + } + b_fat = b_vol + sz_rsv; /* FAT base */ + b_data = b_fat + sz_fat * n_fats + sz_dir; /* Data base */ + + /* Align data base to erase block boundary (for flash memory media) */ + n = ((b_data + sz_blk - 1) & ~(sz_blk - 1)) - b_data; /* Next nearest erase block from current data base */ + if (fmt == FS_FAT32) { /* FAT32: Move FAT base */ + sz_rsv += n; b_fat += n; + } else { /* FAT: Expand FAT size */ + sz_fat += n / n_fats; + } + + /* Determine number of clusters and final check of validity of the FAT sub-type */ + if (sz_vol < b_data + pau * 16 - b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume */ + n_clst = (sz_vol - sz_rsv - sz_fat * n_fats - sz_dir) / pau; + if (fmt == FS_FAT32) { + if (n_clst <= MAX_FAT16) { /* Too few clusters for FAT32 */ + if (au == 0 && (au = pau / 2) != 0) continue; /* Adjust cluster size and retry */ + LEAVE_MKFS(FR_MKFS_ABORTED); + } + } + if (fmt == FS_FAT16) { + if (n_clst > MAX_FAT16) { /* Too many clusters for FAT16 */ + if (au == 0 && (pau * 2) <= 64) { + au = pau * 2; continue; /* Adjust cluster size and retry */ + } + if ((opt & FM_FAT32)) { + fmt = FS_FAT32; continue; /* Switch type to FAT32 and retry */ + } + if (au == 0 && (au = pau * 2) <= 128) continue; /* Adjust cluster size and retry */ + LEAVE_MKFS(FR_MKFS_ABORTED); + } + if (n_clst <= MAX_FAT12) { /* Too few clusters for FAT16 */ + if (au == 0 && (au = pau * 2) <= 128) continue; /* Adjust cluster size and retry */ + LEAVE_MKFS(FR_MKFS_ABORTED); + } + } + if (fmt == FS_FAT12 && n_clst > MAX_FAT12) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too many clusters for FAT12 */ + + /* Ok, it is the valid cluster configuration */ + break; + } while (1); + +#if FF_USE_TRIM + tbl[0] = b_vol; tbl[1] = b_vol + sz_vol - 1; /* Inform the device the volume area can be erased */ + disk_ioctl(pdrv, CTRL_TRIM, tbl); +#endif + /* Create FAT VBR */ + mem_set(buf, 0, ss); + mem_cpy(buf + BS_JmpBoot, "\xEB\xFE\x90" "MSDOS5.0", 11);/* Boot jump code (x86), OEM name */ + st_word(buf + BPB_BytsPerSec, ss); /* Sector size [byte] */ + buf[BPB_SecPerClus] = (BYTE)pau; /* Cluster size [sector] */ + st_word(buf + BPB_RsvdSecCnt, (WORD)sz_rsv); /* Size of reserved area */ + buf[BPB_NumFATs] = (BYTE)n_fats; /* Number of FATs */ + st_word(buf + BPB_RootEntCnt, (WORD)((fmt == FS_FAT32) ? 0 : n_rootdir)); /* Number of root directory entries */ + if (sz_vol < 0x10000) { + st_word(buf + BPB_TotSec16, (WORD)sz_vol); /* Volume size in 16-bit LBA */ + } else { + st_dword(buf + BPB_TotSec32, sz_vol); /* Volume size in 32-bit LBA */ + } + buf[BPB_Media] = 0xF8; /* Media descriptor byte */ + st_word(buf + BPB_SecPerTrk, 63); /* Number of sectors per track (for int13) */ + st_word(buf + BPB_NumHeads, 255); /* Number of heads (for int13) */ + st_dword(buf + BPB_HiddSec, b_vol); /* Volume offset in the physical drive [sector] */ + if (fmt == FS_FAT32) { + st_dword(buf + BS_VolID32, GET_FATTIME()); /* VSN */ + st_dword(buf + BPB_FATSz32, sz_fat); /* FAT size [sector] */ + st_dword(buf + BPB_RootClus32, 2); /* Root directory cluster # (2) */ + st_word(buf + BPB_FSInfo32, 1); /* Offset of FSINFO sector (VBR + 1) */ + st_word(buf + BPB_BkBootSec32, 6); /* Offset of backup VBR (VBR + 6) */ + buf[BS_DrvNum32] = 0x80; /* Drive number (for int13) */ + buf[BS_BootSig32] = 0x29; /* Extended boot signature */ + mem_cpy(buf + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */ + } else { + st_dword(buf + BS_VolID, GET_FATTIME()); /* VSN */ + st_word(buf + BPB_FATSz16, (WORD)sz_fat); /* FAT size [sector] */ + buf[BS_DrvNum] = 0x80; /* Drive number (for int13) */ + buf[BS_BootSig] = 0x29; /* Extended boot signature */ + mem_cpy(buf + BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */ + } + st_word(buf + BS_55AA, 0xAA55); /* Signature (offset is fixed here regardless of sector size) */ + if (disk_write(pdrv, buf, b_vol, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it to the VBR sector */ + + /* Create FSINFO record if needed */ + if (fmt == FS_FAT32) { + disk_write(pdrv, buf, b_vol + 6, 1); /* Write backup VBR (VBR + 6) */ + mem_set(buf, 0, ss); + st_dword(buf + FSI_LeadSig, 0x41615252); + st_dword(buf + FSI_StrucSig, 0x61417272); + st_dword(buf + FSI_Free_Count, n_clst - 1); /* Number of free clusters */ + st_dword(buf + FSI_Nxt_Free, 2); /* Last allocated cluster# */ + st_word(buf + BS_55AA, 0xAA55); + disk_write(pdrv, buf, b_vol + 7, 1); /* Write backup FSINFO (VBR + 7) */ + disk_write(pdrv, buf, b_vol + 1, 1); /* Write original FSINFO (VBR + 1) */ + } + + /* Initialize FAT area */ + mem_set(buf, 0, (UINT)szb_buf); + sect = b_fat; /* FAT start sector */ + for (i = 0; i < n_fats; i++) { /* Initialize FATs each */ + if (fmt == FS_FAT32) { + st_dword(buf + 0, 0xFFFFFFF8); /* Entry 0 */ + st_dword(buf + 4, 0xFFFFFFFF); /* Entry 1 */ + st_dword(buf + 8, 0x0FFFFFFF); /* Entry 2 (root directory) */ + } else { + st_dword(buf + 0, (fmt == FS_FAT12) ? 0xFFFFF8 : 0xFFFFFFF8); /* Entry 0 and 1 */ + } + nsect = sz_fat; /* Number of FAT sectors */ + do { /* Fill FAT sectors */ + n = (nsect > sz_buf) ? sz_buf : nsect; + if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + mem_set(buf, 0, ss); + sect += n; nsect -= n; + } while (nsect); + } + + /* Initialize root directory (fill with zero) */ + nsect = (fmt == FS_FAT32) ? pau : sz_dir; /* Number of root directory sectors */ + do { + n = (nsect > sz_buf) ? sz_buf : nsect; + if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + sect += n; nsect -= n; + } while (nsect); + } + + /* Determine system ID in the partition table */ + if (FF_FS_EXFAT && fmt == FS_EXFAT) { + sys = 0x07; /* HPFS/NTFS/exFAT */ + } else { + if (fmt == FS_FAT32) { + sys = 0x0C; /* FAT32X */ + } else { + if (sz_vol >= 0x10000) { + sys = 0x06; /* FAT12/16 (large) */ + } else { + sys = (fmt == FS_FAT16) ? 0x04 : 0x01; /* FAT16 : FAT12 */ + } + } + } + + /* Update partition information */ + if (FF_MULTI_PARTITION && part != 0) { /* Created in the existing partition */ + /* Update system ID in the partition table */ + if (disk_read(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Read the MBR */ + buf[MBR_Table + (part - 1) * SZ_PTE + PTE_System] = sys; /* Set system ID */ + if (disk_write(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it back to the MBR */ + } else { /* Created as a new single partition */ + if (!(opt & FM_SFD)) { /* Create partition table if in FDISK format */ + mem_set(buf, 0, ss); + st_word(buf + BS_55AA, 0xAA55); /* MBR signature */ + pte = buf + MBR_Table; /* Create partition table for single partition in the drive */ + pte[PTE_Boot] = 0; /* Boot indicator */ + pte[PTE_StHead] = 1; /* Start head */ + pte[PTE_StSec] = 1; /* Start sector */ + pte[PTE_StCyl] = 0; /* Start cylinder */ + pte[PTE_System] = sys; /* System type */ + n = (b_vol + sz_vol) / (63 * 255); /* (End CHS may be invalid) */ + pte[PTE_EdHead] = 254; /* End head */ + pte[PTE_EdSec] = (BYTE)(((n >> 2) & 0xC0) | 63); /* End sector */ + pte[PTE_EdCyl] = (BYTE)n; /* End cylinder */ + st_dword(pte + PTE_StLba, b_vol); /* Start offset in LBA */ + st_dword(pte + PTE_SizLba, sz_vol); /* Size in sectors */ + if (disk_write(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it to the MBR */ + } + } + + if (disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); + + LEAVE_MKFS(FR_OK); +} + + + +#if FF_MULTI_PARTITION +/*-----------------------------------------------------------------------*/ +/* Create Partition Table on the Physical Drive */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_fdisk ( + BYTE pdrv, /* Physical drive number */ + const DWORD* szt, /* Pointer to the size table for each partitions */ + void* work /* Pointer to the working buffer (null: use heap memory) */ +) +{ + UINT i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl; + BYTE s_hd, e_hd, *p, *buf = (BYTE*)work; + DSTATUS stat; + DWORD sz_disk, sz_part, s_part; + FRESULT res; + + + stat = disk_initialize(pdrv); + if (stat & STA_NOINIT) return FR_NOT_READY; + if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; + if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_disk)) return FR_DISK_ERR; + + buf = (BYTE*)work; +#if FF_USE_LFN == 3 + if (!buf) buf = ff_memalloc(FF_MAX_SS); /* Use heap memory for working buffer */ +#endif + if (!buf) return FR_NOT_ENOUGH_CORE; + + /* Determine the CHS without any consideration of the drive geometry */ + for (n = 16; n < 256 && sz_disk / n / 63 > 1024; n *= 2) ; + if (n == 256) n--; + e_hd = (BYTE)(n - 1); + sz_cyl = 63 * n; + tot_cyl = sz_disk / sz_cyl; + + /* Create partition table */ + mem_set(buf, 0, FF_MAX_SS); + p = buf + MBR_Table; b_cyl = 0; + for (i = 0; i < 4; i++, p += SZ_PTE) { + p_cyl = (szt[i] <= 100U) ? (DWORD)tot_cyl * szt[i] / 100 : szt[i] / sz_cyl; /* Number of cylinders */ + if (p_cyl == 0) continue; + s_part = (DWORD)sz_cyl * b_cyl; + sz_part = (DWORD)sz_cyl * p_cyl; + if (i == 0) { /* Exclude first track of cylinder 0 */ + s_hd = 1; + s_part += 63; sz_part -= 63; + } else { + s_hd = 0; + } + e_cyl = b_cyl + p_cyl - 1; /* End cylinder */ + if (e_cyl >= tot_cyl) LEAVE_MKFS(FR_INVALID_PARAMETER); + + /* Set partition table */ + p[1] = s_hd; /* Start head */ + p[2] = (BYTE)(((b_cyl >> 2) & 0xC0) | 1); /* Start sector */ + p[3] = (BYTE)b_cyl; /* Start cylinder */ + p[4] = 0x07; /* System type (temporary setting) */ + p[5] = e_hd; /* End head */ + p[6] = (BYTE)(((e_cyl >> 2) & 0xC0) | 63); /* End sector */ + p[7] = (BYTE)e_cyl; /* End cylinder */ + st_dword(p + 8, s_part); /* Start sector in LBA */ + st_dword(p + 12, sz_part); /* Number of sectors */ + + /* Next partition */ + b_cyl += p_cyl; + } + st_word(p, 0xAA55); /* MBR signature (always at offset 510) */ + + /* Write it to the MBR */ + res = (disk_write(pdrv, buf, 0, 1) == RES_OK && disk_ioctl(pdrv, CTRL_SYNC, 0) == RES_OK) ? FR_OK : FR_DISK_ERR; + LEAVE_MKFS(res); +} + +#endif /* FF_MULTI_PARTITION */ +#endif /* FF_USE_MKFS && !FF_FS_READONLY */ + + + + +#if FF_USE_STRFUNC +#if FF_USE_LFN && FF_LFN_UNICODE && (FF_STRF_ENCODE < 0 || FF_STRF_ENCODE > 3) +#error Wrong FF_STRF_ENCODE setting +#endif +/*-----------------------------------------------------------------------*/ +/* Get a String from the File */ +/*-----------------------------------------------------------------------*/ + +TCHAR* f_gets ( + TCHAR* buff, /* Pointer to the string buffer to read */ + int len, /* Size of string buffer (items) */ + FIL* fp /* Pointer to the file object */ +) +{ + int nc = 0; + TCHAR *p = buff; + BYTE s[4]; + UINT rc; + DWORD dc; +#if FF_USE_LFN && FF_LFN_UNICODE && FF_STRF_ENCODE <= 2 + WCHAR wc; +#endif +#if FF_USE_LFN && FF_LFN_UNICODE && FF_STRF_ENCODE == 3 + UINT ct; +#endif + +#if FF_USE_LFN && FF_LFN_UNICODE /* With code conversion (Unicode API) */ + /* Make a room for the character and terminator */ + if (FF_LFN_UNICODE == 1) len -= (FF_STRF_ENCODE == 0) ? 1 : 2; + if (FF_LFN_UNICODE == 2) len -= (FF_STRF_ENCODE == 0) ? 3 : 4; + if (FF_LFN_UNICODE == 3) len -= 1; + while (nc < len) { +#if FF_STRF_ENCODE == 0 /* Read a character in ANSI/OEM */ + f_read(fp, s, 1, &rc); + if (rc != 1) break; + wc = s[0]; + if (dbc_1st((BYTE)wc)) { + f_read(fp, s, 1, &rc); + if (rc != 1 || !dbc_2nd(s[0])) continue; + wc = wc << 8 | s[0]; + } + dc = ff_oem2uni(wc, CODEPAGE); + if (dc == 0) continue; +#elif FF_STRF_ENCODE == 1 || FF_STRF_ENCODE == 2 /* Read a character in UTF-16LE/BE */ + f_read(fp, s, 2, &rc); + if (rc != 2) break; + dc = (FF_STRF_ENCODE == 1) ? ld_word(s) : s[0] << 8 | s[1]; + if (IsSurrogateL(dc)) continue; + if (IsSurrogateH(dc)) { + f_read(fp, s, 2, &rc); + if (rc != 2) break; + wc = (FF_STRF_ENCODE == 1) ? ld_word(s) : s[0] << 8 | s[1]; + if (!IsSurrogateL(wc)) continue; + dc = ((dc & 0x3FF) + 0x40) << 10 | (wc & 0x3FF); + } +#else /* Read a character in UTF-8 */ + f_read(fp, s, 1, &rc); + if (rc != 1) break; + dc = s[0]; + if (dc >= 0x80) { /* Multi-byte character? */ + ct = 0; + if ((dc & 0xE0) == 0xC0) { dc &= 0x1F; ct = 1; } /* 2-byte? */ + if ((dc & 0xF0) == 0xE0) { dc &= 0x0F; ct = 2; } /* 3-byte? */ + if ((dc & 0xF8) == 0xF0) { dc &= 0x07; ct = 3; } /* 4-byte? */ + if (ct == 0) continue; + f_read(fp, s, ct, &rc); /* Get trailing bytes */ + if (rc != ct) break; + rc = 0; + do { /* Merge trailing bytes */ + if ((s[rc] & 0xC0) != 0x80) break; + dc = dc << 6 | (s[rc] & 0x3F); + } while (++rc < ct); + if (rc != ct || dc < 0x80 || IsSurrogate(dc) || dc >= 0x110000) continue; /* Wrong encoding? */ + } +#endif + if (FF_USE_STRFUNC == 2 && dc == '\r') continue; /* Strip \r off if needed */ +#if FF_LFN_UNICODE == 1 || FF_LFN_UNICODE == 3 /* Output it in UTF-16/32 encoding */ + if (FF_LFN_UNICODE == 1 && dc >= 0x10000) { /* Out of BMP at UTF-16? */ + *p++ = (TCHAR)(0xD800 | ((dc >> 10) - 0x40)); nc++; /* Make and output high surrogate */ + dc = 0xDC00 | (dc & 0x3FF); /* Make low surrogate */ + } + *p++ = (TCHAR)dc; nc++; + if (dc == '\n') break; /* End of line? */ +#elif FF_LFN_UNICODE == 2 /* Output it in UTF-8 encoding */ + if (dc < 0x80) { /* 1-byte */ + *p++ = (TCHAR)dc; + nc++; + if (dc == '\n') break; /* End of line? */ + } else { + if (dc < 0x800) { /* 2-byte */ + *p++ = (TCHAR)(0xC0 | (dc >> 6 & 0x1F)); + *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); + nc += 2; + } else { + if (dc < 0x10000) { /* 3-byte */ + *p++ = (TCHAR)(0xE0 | (dc >> 12 & 0x0F)); + *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F)); + *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); + nc += 3; + } else { /* 4-byte */ + *p++ = (TCHAR)(0xF0 | (dc >> 18 & 0x07)); + *p++ = (TCHAR)(0x80 | (dc >> 12 & 0x3F)); + *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F)); + *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); + nc += 4; + } + } + } +#endif + } + +#else /* Byte-by-byte without any conversion (ANSI/OEM API) */ + len -= 1; /* Make a room for the terminator */ + while (nc < len) { + f_read(fp, s, 1, &rc); + if (rc != 1) break; + dc = s[0]; + if (FF_USE_STRFUNC == 2 && dc == '\r') continue; + *p++ = (TCHAR)dc; nc++; + if (dc == '\n') break; + } +#endif + + *p = 0; /* Terminate the string */ + return nc ? buff : 0; /* When no data read due to EOF or error, return with error. */ +} + + + + +#if !FF_FS_READONLY +#include +/*-----------------------------------------------------------------------*/ +/* Put a Character to the File */ +/*-----------------------------------------------------------------------*/ + +typedef struct { /* Putchar output buffer and work area */ + FIL *fp; /* Ptr to the writing file */ + int idx, nchr; /* Write index of buf[] (-1:error), number of encoding units written */ +#if FF_USE_LFN && FF_LFN_UNICODE == 1 + WCHAR hs; +#elif FF_USE_LFN && FF_LFN_UNICODE == 2 + BYTE bs[4]; + UINT wi, ct; +#endif + BYTE buf[64]; /* Write buffer */ +} putbuff; + + +static void putc_bfd ( /* Buffered write with code conversion */ + putbuff* pb, + TCHAR c +) +{ + UINT n; + int i, nc; +#if FF_USE_LFN && FF_LFN_UNICODE + WCHAR hs, wc; +#if FF_LFN_UNICODE == 2 + DWORD dc; + TCHAR *tp; +#endif +#endif + + if (FF_USE_STRFUNC == 2 && c == '\n') { /* LF -> CRLF conversion */ + putc_bfd(pb, '\r'); + } + + i = pb->idx; /* Write index of pb->buf[] */ + if (i < 0) return; + nc = pb->nchr; /* Write unit counter */ + +#if FF_USE_LFN && FF_LFN_UNICODE +#if FF_LFN_UNICODE == 1 /* UTF-16 input */ + if (IsSurrogateH(c)) { + pb->hs = c; return; + } + hs = pb->hs; pb->hs = 0; + if (hs != 0) { + if (!IsSurrogateL(c)) hs = 0; + } else { + if (IsSurrogateL(c)) return; + } + wc = c; +#elif FF_LFN_UNICODE == 2 /* UTF-8 input */ + for (;;) { + if (pb->ct == 0) { /* Out of multi-byte sequence? */ + pb->bs[pb->wi = 0] = (BYTE)c; /* Save 1st byte */ + if ((BYTE)c < 0x80) break; /* 1-byte? */ + if (((BYTE)c & 0xE0) == 0xC0) pb->ct = 1; /* 2-byte? */ + if (((BYTE)c & 0xF0) == 0xE0) pb->ct = 2; /* 3-byte? */ + if (((BYTE)c & 0xF1) == 0xF0) pb->ct = 3; /* 4-byte? */ + return; + } else { /* In the multi-byte sequence */ + if (((BYTE)c & 0xC0) != 0x80) { /* Broken sequence? */ + pb->ct = 0; continue; + } + pb->bs[++pb->wi] = (BYTE)c; /* Save the trailing byte */ + if (--pb->ct == 0) break; /* End of multi-byte sequence? */ + return; + } + } + tp = (TCHAR*)pb->bs; + dc = tchar2uni(&tp); /* UTF-8 ==> UTF-16 */ + if (dc == 0xFFFFFFFF) return; + wc = (WCHAR)dc; + hs = (WCHAR)(dc >> 16); +#elif FF_LFN_UNICODE == 3 /* UTF-32 input */ + if (IsSurrogate(c) || c >= 0x110000) return; + if (c >= 0x10000) { + hs = (WCHAR)(0xD800 | ((c >> 10) - 0x40)); /* Make high surrogate */ + wc = 0xDC00 | (c & 0x3FF); /* Make low surrogate */ + } else { + hs = 0; + wc = (WCHAR)c; + } +#endif + +#if FF_STRF_ENCODE == 1 /* Write a character in UTF-16LE */ + if (hs != 0) { + st_word(&pb->buf[i], hs); + i += 2; + nc++; + } + st_word(&pb->buf[i], wc); + i += 2; +#elif FF_STRF_ENCODE == 2 /* Write a character in UTF-16BE */ + if (hs != 0) { + pb->buf[i++] = (BYTE)(hs >> 8); + pb->buf[i++] = (BYTE)hs; + nc++; + } + pb->buf[i++] = (BYTE)(wc >> 8); + pb->buf[i++] = (BYTE)wc; +#elif FF_STRF_ENCODE == 3 /* Write it in UTF-8 */ + if (hs != 0) { /* 4-byte */ + nc += 3; + hs = (hs & 0x3FF) + 0x40; + pb->buf[i++] = (BYTE)(0xF0 | hs >> 8); + pb->buf[i++] = (BYTE)(0x80 | (hs >> 2 & 0x3F)); + pb->buf[i++] = (BYTE)(0x80 | (hs & 3) << 4 | (wc >> 6 & 0x0F)); + pb->buf[i++] = (BYTE)(0x80 | (wc & 0x3F)); + } else { + if (wc < 0x80) { /* 1-byte */ + pb->buf[i++] = (BYTE)wc; + } else { + if (wc < 0x800) { /* 2-byte */ + nc += 1; + pb->buf[i++] = (BYTE)(0xC0 | wc >> 6); + } else { /* 3-byte */ + nc += 2; + pb->buf[i++] = (BYTE)(0xE0 | wc >> 12); + pb->buf[i++] = (BYTE)(0x80 | (wc >> 6 & 0x3F)); + } + pb->buf[i++] = (BYTE)(0x80 | (wc & 0x3F)); + } + } +#else /* Write it in ANSI/OEM */ + if (hs != 0) return; + wc = ff_uni2oem(wc, CODEPAGE); /* UTF-16 ==> ANSI/OEM */ + if (wc == 0) return; + if (wc >= 0x100) { + pb->buf[i++] = (BYTE)(wc >> 8); nc++; + } + pb->buf[i++] = (BYTE)wc; +#endif + +#else /* ANSI/OEM input (without re-encode) */ + pb->buf[i++] = (BYTE)c; +#endif + + if (i >= (int)(sizeof pb->buf) - 4) { /* Write buffered characters to the file */ + f_write(pb->fp, pb->buf, (UINT)i, &n); + i = (n == (UINT)i) ? 0 : -1; + } + pb->idx = i; + pb->nchr = nc + 1; +} + + +static int putc_flush ( /* Flush left characters in the buffer */ + putbuff* pb +) +{ + UINT nw; + + if ( pb->idx >= 0 /* Flush buffered characters to the file */ + && f_write(pb->fp, pb->buf, (UINT)pb->idx, &nw) == FR_OK + && (UINT)pb->idx == nw) return pb->nchr; + return EOF; +} + + +static void putc_init ( /* Initialize write buffer */ + putbuff* pb, + FIL* fp +) +{ + mem_set(pb, 0, sizeof (putbuff)); + pb->fp = fp; +} + + + +int f_putc ( + TCHAR c, /* A character to be output */ + FIL* fp /* Pointer to the file object */ +) +{ + putbuff pb; + + + putc_init(&pb, fp); + putc_bfd(&pb, c); /* Put the character */ + return putc_flush(&pb); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Put a String to the File */ +/*-----------------------------------------------------------------------*/ + +int f_puts ( + const TCHAR* str, /* Pointer to the string to be output */ + FIL* fp /* Pointer to the file object */ +) +{ + putbuff pb; + + + putc_init(&pb, fp); + while (*str) putc_bfd(&pb, *str++); /* Put the string */ + return putc_flush(&pb); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Put a Formatted String to the File */ +/*-----------------------------------------------------------------------*/ + +int f_printf ( + FIL* fp, /* Pointer to the file object */ + const TCHAR* fmt, /* Pointer to the format string */ + ... /* Optional arguments... */ +) +{ + va_list arp; + putbuff pb; + BYTE f, r; + UINT i, j, w; + DWORD v; + TCHAR c, d, str[32], *p; + + + putc_init(&pb, fp); + + va_start(arp, fmt); + + for (;;) { + c = *fmt++; + if (c == 0) break; /* End of string */ + if (c != '%') { /* Non escape character */ + putc_bfd(&pb, c); + continue; + } + w = f = 0; + c = *fmt++; + if (c == '0') { /* Flag: '0' padding */ + f = 1; c = *fmt++; + } else { + if (c == '-') { /* Flag: left justified */ + f = 2; c = *fmt++; + } + } + if (c == '*') { /* Minimum width by argument */ + w = va_arg(arp, int); + c = *fmt++; + } else { + while (IsDigit(c)) { /* Minimum width */ + w = w * 10 + c - '0'; + c = *fmt++; + } + } + if (c == 'l' || c == 'L') { /* Type prefix: Size is long int */ + f |= 4; c = *fmt++; + } + if (c == 0) break; + d = c; + if (IsLower(d)) d -= 0x20; + switch (d) { /* Atgument type is... */ + case 'S' : /* String */ + p = va_arg(arp, TCHAR*); + for (j = 0; p[j]; j++) ; + if (!(f & 2)) { /* Right padded */ + while (j++ < w) putc_bfd(&pb, ' ') ; + } + while (*p) putc_bfd(&pb, *p++) ; /* String body */ + while (j++ < w) putc_bfd(&pb, ' ') ; /* Left padded */ + continue; + + case 'C' : /* Character */ + putc_bfd(&pb, (TCHAR)va_arg(arp, int)); continue; + + case 'B' : /* Unsigned binary */ + r = 2; break; + + case 'O' : /* Unsigned octal */ + r = 8; break; + + case 'D' : /* Signed decimal */ + case 'U' : /* Unsigned decimal */ + r = 10; break; + + case 'X' : /* Unsigned hexdecimal */ + r = 16; break; + + default: /* Unknown type (pass-through) */ + putc_bfd(&pb, c); continue; + } + + /* Get an argument and put it in numeral */ + v = (f & 4) ? (DWORD)va_arg(arp, long) : ((d == 'D') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int)); + if (d == 'D' && (v & 0x80000000)) { + v = 0 - v; + f |= 8; + } + i = 0; + do { + d = (TCHAR)(v % r); v /= r; + if (d > 9) d += (c == 'x') ? 0x27 : 0x07; + str[i++] = d + '0'; + } while (v && i < sizeof str / sizeof *str); + if (f & 8) str[i++] = '-'; + j = i; d = (f & 1) ? '0' : ' '; + if (!(f & 2)) { + while (j++ < w) putc_bfd(&pb, d); /* Right pad */ + } + do { + putc_bfd(&pb, str[--i]); /* Number body */ + } while (i); + while (j++ < w) putc_bfd(&pb, d); /* Left pad */ + } + + va_end(arp); + + return putc_flush(&pb); +} + +#endif /* !FF_FS_READONLY */ +#endif /* FF_USE_STRFUNC */ + + + +#if FF_CODE_PAGE == 0 +/*-----------------------------------------------------------------------*/ +/* Set Active Codepage for the Path Name */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_setcp ( + WORD cp /* Value to be set as active code page */ +) +{ + static const WORD validcp[] = { 437, 720, 737, 771, 775, 850, 852, 857, 860, 861, 862, 863, 864, 865, 866, 869, 932, 936, 949, 950, 0}; + static const BYTE* const tables[] = {Ct437, Ct720, Ct737, Ct771, Ct775, Ct850, Ct852, Ct857, Ct860, Ct861, Ct862, Ct863, Ct864, Ct865, Ct866, Ct869, Dc932, Dc936, Dc949, Dc950, 0}; + UINT i; + + + for (i = 0; validcp[i] != 0 && validcp[i] != cp; i++) ; /* Find the code page */ + if (validcp[i] != cp) return FR_INVALID_PARAMETER; /* Not found? */ + + CodePage = cp; + if (cp >= 900) { /* DBCS */ + ExCvt = 0; + DbcTbl = tables[i]; + } else { /* SBCS */ + ExCvt = tables[i]; + DbcTbl = 0; + } + return FR_OK; +} +#endif /* FF_CODE_PAGE == 0 */ + +#pragma GCC pop_options diff --git a/nyx/nyx_gui/libs/fatfs/ff.h b/nyx/nyx_gui/libs/fatfs/ff.h new file mode 100644 index 0000000..b966fa2 --- /dev/null +++ b/nyx/nyx_gui/libs/fatfs/ff.h @@ -0,0 +1,391 @@ +/*----------------------------------------------------------------------------/ +/ FatFs - Generic FAT Filesystem module R0.13c / +/-----------------------------------------------------------------------------/ +/ +/ Copyright (C) 2018, ChaN, all right reserved. +/ +/ FatFs module is an open source software. Redistribution and use of FatFs in +/ source and binary forms, with or without modification, are permitted provided +/ that the following condition is met: + +/ 1. Redistributions of source code must retain the above copyright notice, +/ this condition and the following disclaimer. +/ +/ This software is provided by the copyright holder and contributors "AS IS" +/ and any warranties related to this software are DISCLAIMED. +/ The copyright owner or contributors be NOT LIABLE for any damages caused +/ by use of this software. +/ +/----------------------------------------------------------------------------*/ + + +#ifndef FF_DEFINED +#define FF_DEFINED 86604 /* Revision ID */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../utils/types.h" /* Basic integer types */ +#include "ffconf.h" /* FatFs configuration options */ + +#if FF_DEFINED != FFCONF_DEF +#error Wrong configuration file (ffconf.h). +#endif + + + +/* Definitions of volume management */ + +#if FF_MULTI_PARTITION /* Multiple partition configuration */ +typedef struct { + BYTE pd; /* Physical drive number */ + BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ +} PARTITION; +extern PARTITION VolToPart[]; /* Volume - Partition resolution table */ +#endif + +#if FF_STR_VOLUME_ID +#ifndef FF_VOLUME_STRS +extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */ +#endif +#endif + + + +/* Type of path name strings on FatFs API */ + +#ifndef _INC_TCHAR +#define _INC_TCHAR + +#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */ +typedef WCHAR TCHAR; +#define _T(x) L ## x +#define _TEXT(x) L ## x +#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */ +typedef char TCHAR; +#define _T(x) u8 ## x +#define _TEXT(x) u8 ## x +#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */ +typedef DWORD TCHAR; +#define _T(x) U ## x +#define _TEXT(x) U ## x +#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3) +#error Wrong FF_LFN_UNICODE setting +#else /* ANSI/OEM code in SBCS/DBCS */ +typedef char TCHAR; +#define _T(x) x +#define _TEXT(x) x +#endif + +#endif + + + +/* Type of file size variables */ + +#if FF_FS_EXFAT +typedef QWORD FSIZE_t; +#else +typedef DWORD FSIZE_t; +#endif + + + +/* Filesystem object structure (FATFS) */ + +typedef struct { + BYTE fs_type; /* Filesystem type (0:not mounted) */ + BYTE pdrv; /* Associated physical drive */ + BYTE n_fats; /* Number of FATs (1 or 2) */ + BYTE wflag; /* win[] flag (b0:dirty) */ + BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */ + WORD id; /* Volume mount ID */ + WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ + WORD csize; /* Cluster size [sectors] */ +#if FF_MAX_SS != FF_MIN_SS + WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */ +#endif +#if FF_USE_LFN + WCHAR* lfnbuf; /* LFN working buffer */ +#endif +#if FF_FS_EXFAT + BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */ +#endif +#if FF_FS_REENTRANT + FF_SYNC_t sobj; /* Identifier of sync object */ +#endif +#if !FF_FS_READONLY + DWORD last_clst; /* Last allocated cluster */ + DWORD free_clst; /* Number of free clusters */ +#endif +#if FF_FS_RPATH + DWORD cdir; /* Current directory start cluster (0:root) */ +#if FF_FS_EXFAT + DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */ + DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */ + DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */ +#endif +#endif + DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */ + DWORD fsize; /* Size of an FAT [sectors] */ + DWORD volbase; /* Volume base sector */ + DWORD fatbase; /* FAT base sector */ + DWORD dirbase; /* Root directory base sector/cluster */ + DWORD database; /* Data base sector */ +#if FF_FS_EXFAT + DWORD bitbase; /* Allocation bitmap base sector */ +#endif + DWORD winsect; /* Current sector appearing in the win[] */ + BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ +} FATFS; + + + +/* Object ID and allocation information (FFOBJID) */ + +typedef struct { + FATFS* fs; /* Pointer to the hosting volume of this object */ + WORD id; /* Hosting volume mount ID */ + BYTE attr; /* Object attribute */ + BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */ + DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */ + FSIZE_t objsize; /* Object size (valid when sclust != 0) */ +#if FF_FS_EXFAT + DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */ + DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */ + DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */ + DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */ + DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */ +#endif +#if FF_FS_LOCK + UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */ +#endif +} FFOBJID; + + + +/* File object structure (FIL) */ + +typedef struct { + FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ + BYTE flag; /* File status flags */ + BYTE err; /* Abort flag (error code) */ + FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */ + DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */ + DWORD sect; /* Sector number appearing in buf[] (0:invalid) */ +#if !FF_FS_READONLY + DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */ + BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */ +#endif +#if !FF_FS_TINY + BYTE buf[FF_MAX_SS]; /* File private data read/write window */ +#endif +#if FF_USE_FASTSEEK + DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */ +#endif +} FIL; + + + +/* Directory object structure (DIR) */ + +typedef struct { + FFOBJID obj; /* Object identifier */ + DWORD dptr; /* Current read/write offset */ + DWORD clust; /* Current cluster */ + DWORD sect; /* Current sector (0:Read operation has terminated) */ + BYTE* dir; /* Pointer to the directory item in the win[] */ + BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */ +#if FF_USE_LFN + DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */ +#endif +#if FF_USE_FIND + const TCHAR* pat; /* Pointer to the name matching pattern */ +#endif +} DIR; + + + +/* File information structure (FILINFO) */ + +typedef struct { + FSIZE_t fsize; /* File size */ + WORD fdate; /* Modified date */ + WORD ftime; /* Modified time */ + BYTE fattrib; /* File attribute */ +#if FF_USE_LFN + TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */ + TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */ +#else + TCHAR fname[12 + 1]; /* File name */ +#endif +} FILINFO; + + + +/* File function return code (FRESULT) */ + +typedef enum { + FR_OK = 0, /* (0) Succeeded */ + FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */ + FR_INT_ERR, /* (2) Assertion failed */ + FR_NOT_READY, /* (3) The physical drive cannot work */ + FR_NO_FILE, /* (4) Could not find the file */ + FR_NO_PATH, /* (5) Could not find the path */ + FR_INVALID_NAME, /* (6) The path name format is invalid */ + FR_DENIED, /* (7) Access denied due to prohibited access or directory full */ + FR_EXIST, /* (8) Access denied due to prohibited access */ + FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ + FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ + FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ + FR_NOT_ENABLED, /* (12) The volume has no work area */ + FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */ + FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */ + FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ + FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */ + FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ + FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */ +#ifdef FF_FASTFS + FR_INVALID_PARAMETER, /* (19) Given parameter is invalid */ + FR_CLTBL_NO_INIT /* (20) The cluster table for fast seek/read/write was not created */ +#else + FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ +#endif +} FRESULT; + + + +/*--------------------------------------------------------------*/ +/* FatFs module application interface */ + +FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */ +FRESULT f_close (FIL* fp); /* Close an open file object */ +FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */ +FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */ +#ifdef FF_FASTFS +FRESULT f_read_fast (FIL* fp, const void* buff, UINT btr); /* Fast read data from the file */ +FRESULT f_write_fast (FIL* fp, const void* buff, UINT btw); /* Fast write data to the file */ +#endif +FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */ +FRESULT f_truncate (FIL* fp); /* Truncate the file */ +FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */ +FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */ +FRESULT f_closedir (DIR* dp); /* Close an open directory */ +FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */ +FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */ +FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */ +FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */ +FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */ +FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */ +FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */ +FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */ +FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */ +FRESULT f_chdir (const TCHAR* path); /* Change current directory */ +FRESULT f_chdrive (const TCHAR* path); /* Change current drive */ +FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */ +FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */ +FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */ +FRESULT f_setlabel (const TCHAR* label); /* Set volume label */ +FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */ +#ifdef FF_FASTFS +DWORD *f_expand_cltbl (FIL* fp, UINT tblsz, FSIZE_t ofs); /* Expand file and populate cluster table */ +#endif +FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */ +FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */ +FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */ +FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */ +FRESULT f_setcp (WORD cp); /* Set current code page */ +int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */ +int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */ +int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */ +TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */ + +#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize)) +#define f_error(fp) ((fp)->err) +#define f_tell(fp) ((fp)->fptr) +#define f_size(fp) ((fp)->obj.objsize) +#define f_rewind(fp) f_lseek((fp), 0) +#define f_rewinddir(dp) f_readdir((dp), 0) +#define f_rmdir(path) f_unlink(path) +#define f_unmount(path) f_mount(0, path, 0) + +#ifndef EOF +#define EOF (-1) +#endif + + + + +/*--------------------------------------------------------------*/ +/* Additional user defined functions */ + +/* RTC function */ +#if !FF_FS_READONLY && !FF_FS_NORTC +DWORD get_fattime (void); +#endif + +/* LFN support functions */ +#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */ +WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */ +WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */ +DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */ +#endif +#if FF_USE_LFN == 3 /* Dynamic memory allocation */ +void* ff_memalloc (UINT msize); /* Allocate memory block */ +void ff_memfree (void* mblock); /* Free memory block */ +#endif + +/* Sync functions */ +#if FF_FS_REENTRANT +int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */ +int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */ +void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */ +int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */ +#endif + + + + +/*--------------------------------------------------------------*/ +/* Flags and offset address */ + + +/* File access mode and open method flags (3rd argument of f_open) */ +#define FA_READ 0x01 +#define FA_WRITE 0x02 +#define FA_OPEN_EXISTING 0x00 +#define FA_CREATE_NEW 0x04 +#define FA_CREATE_ALWAYS 0x08 +#define FA_OPEN_ALWAYS 0x10 +#define FA_OPEN_APPEND 0x30 + +/* Fast seek controls (2nd argument of f_lseek) */ +#define CREATE_LINKMAP ((FSIZE_t)0 - 1) + +/* Format options (2nd argument of f_mkfs) */ +#define FM_FAT 0x01 +#define FM_FAT32 0x02 +#define FM_EXFAT 0x04 +#define FM_ANY 0x07 +#define FM_SFD 0x08 + +/* Filesystem type (FATFS.fs_type) */ +#define FS_FAT12 1 +#define FS_FAT16 2 +#define FS_FAT32 3 +#define FS_EXFAT 4 + +/* File attribute bits for directory entry (FILINFO.fattrib) */ +#define AM_RDO 0x01 /* Read only */ +#define AM_HID 0x02 /* Hidden */ +#define AM_SYS 0x04 /* System */ +#define AM_DIR 0x10 /* Directory */ +#define AM_ARC 0x20 /* Archive */ + + +#ifdef __cplusplus +} +#endif + +#endif /* FF_DEFINED */ diff --git a/nyx/nyx_gui/libs/fatfs/ffconf.h b/nyx/nyx_gui/libs/fatfs/ffconf.h new file mode 100644 index 0000000..e54f7fd --- /dev/null +++ b/nyx/nyx_gui/libs/fatfs/ffconf.h @@ -0,0 +1,293 @@ +/*---------------------------------------------------------------------------/ +/ FatFs Functional Configurations +/---------------------------------------------------------------------------*/ + +#define FFCONF_DEF 86604 /* Revision ID */ + +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: Basic functions are fully enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + + +#define FF_USE_STRFUNC 2 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + + +#define FF_USE_FIND 1 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + + +#define FF_USE_MKFS 0 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + +#define FF_FASTFS 1 + +#ifdef FF_FASTFS +#define FF_USE_FASTSEEK 1 +#else +#define FF_USE_FASTSEEK 0 +#endif +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + + +#define FF_USE_CHMOD 1 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ + + +#define FF_USE_LABEL 0 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) */ + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 850 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect code page setting can cause a file open failure. +/ +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +/ 0 - Include all code pages above and configured by f_setcp() +*/ + + +#define FF_USE_LFN 3 +#define FF_MAX_LFN 255 +/* The FF_USE_LFN switches the support for LFN (long file name). +/ +/ 0: Disable LFN. FF_MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function +/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and +/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. +/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can +/ be in range of 12 to 255. It is recommended to be set 255 to fully support LFN +/ specification. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree() in ffsystem.c, need to be added to the project. */ + + +#define FF_LFN_UNICODE 0 +/* This option switches the character encoding on the API when LFN is enabled. +/ +/ 0: ANSI/OEM in current CP (TCHAR = char) +/ 1: Unicode in UTF-16 (TCHAR = WCHAR) +/ 2: Unicode in UTF-8 (TCHAR = char) +/ 3: Unicode in UTF-32 (TCHAR = DWORD) +/ +/ Also behavior of string I/O functions will be affected by this option. +/ When LFN is not enabled, this option has no effect. */ + + +#define FF_LFN_BUF 255 +#define FF_SFN_BUF 12 +/* This set of options defines size of file name members in the FILINFO structure +/ which is used to read out directory items. These values should be suffcient for +/ the file names to read. The maximum possible length of the read file name depends +/ on character encoding. When LFN is not enabled, these options have no effect. */ + + +#define FF_STRF_ENCODE 0 +/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(), +/ f_putc(), f_puts and f_printf() convert the character encoding in it. +/ This option selects assumption of character encoding ON THE FILE to be +/ read/written via those functions. +/ +/ 0: ANSI/OEM in current CP +/ 1: Unicode in UTF-16LE +/ 2: Unicode in UTF-16BE +/ 3: Unicode in UTF-8 +*/ + + +#define FF_FS_RPATH 0 +/* This option configures support for relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 1 +/* Number of volumes (logical drives) to be used. (1-10) */ + + +#define FF_STR_VOLUME_ID 0 +#define FF_VOLUME_STRS "sd" +/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. +/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive +/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each +/ logical drives. Number of items must not be less than FF_VOLUMES. Valid +/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are +/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is +/ not defined, a user defined volume string table needs to be defined as: +/ +/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... +*/ + + +#define FF_MULTI_PARTITION 0 +/* This option switches support for multiple volumes on the physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When this function is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + + +#define FF_MIN_SS 512 +#define FF_MAX_SS 512 +/* This set of options configures the range of sector size to be supported. (512, +/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured +/ for variable sector size mode and disk_ioctl() function needs to implement +/ GET_SECTOR_SIZE command. */ + + +#define FF_USE_TRIM 0 +/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + + +#define FF_FS_NOFSINFO 1 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 0 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ + + +#define FF_FS_EXFAT 1 +/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) +/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1) +/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ + + +#define FF_FS_NORTC 1 +#define FF_NORTC_MON 1 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2019 +/* The option FF_FS_NORTC switches timestamp function. If the system does not have +/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable +/ the timestamp function. Every object modified by FatFs will have a fixed timestamp +/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. +/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */ + + +#define FF_FS_LOCK 0 +/* The option FF_FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + + +/* #include // O/S definitions */ +#define FF_FS_REENTRANT 0 +#define FF_FS_TIMEOUT 1000 +#define FF_SYNC_t HANDLE +/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. +/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.h. */ + + + +/*--- End of configuration options ---*/ diff --git a/nyx/nyx_gui/libs/fatfs/ffsystem.c b/nyx/nyx_gui/libs/fatfs/ffsystem.c new file mode 100644 index 0000000..fa44f8e --- /dev/null +++ b/nyx/nyx_gui/libs/fatfs/ffsystem.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------*/ +/* Sample Code of OS Dependent Functions for FatFs */ +/* (C) ChaN, 2018 */ +/* (C) CTCaer, 2018 */ +/*------------------------------------------------------------------------*/ + + +#include "ff.h" +#include "../../mem/heap.h" + + + +#if FF_USE_LFN == 3 /* Dynamic memory allocation */ + +/*------------------------------------------------------------------------*/ +/* Allocate a memory block */ +/*------------------------------------------------------------------------*/ + +void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */ + UINT msize /* Number of bytes to allocate */ +) +{ + return malloc(msize); /* Allocate a new memory block with POSIX API */ +} + + +/*------------------------------------------------------------------------*/ +/* Free a memory block */ +/*------------------------------------------------------------------------*/ + +void ff_memfree ( + void* mblock /* Pointer to the memory block to free (nothing to do if null) */ +) +{ + free(mblock); /* Free the memory block with POSIX API */ +} + +#endif + diff --git a/nyx/nyx_gui/libs/fatfs/ffunicode.c b/nyx/nyx_gui/libs/fatfs/ffunicode.c new file mode 100644 index 0000000..35d3fa2 --- /dev/null +++ b/nyx/nyx_gui/libs/fatfs/ffunicode.c @@ -0,0 +1,632 @@ +/*------------------------------------------------------------------------*/ +/* Unicode handling functions for FatFs R0.13c */ +/*------------------------------------------------------------------------*/ +/* This module will occupy a huge memory in the .const section when the / +/ FatFs is configured for LFN with DBCS. If the system has any Unicode / +/ utilitiy for the code conversion, this module should be modified to use / +/ that function to avoid silly memory consumption. / +/-------------------------------------------------------------------------*/ +/* +/ Copyright (C) 2018, ChaN, all right reserved. +/ +/ FatFs module is an open source software. Redistribution and use of FatFs in +/ source and binary forms, with or without modification, are permitted provided +/ that the following condition is met: +/ +/ 1. Redistributions of source code must retain the above copyright notice, +/ this condition and the following disclaimer. +/ +/ This software is provided by the copyright holder and contributors "AS IS" +/ and any warranties related to this software are DISCLAIMED. +/ The copyright owner or contributors be NOT LIABLE for any damages caused +/ by use of this software. +*/ + + +#include "ff.h" + +#if FF_USE_LFN /* This module will be blanked at non-LFN configuration */ + +#if FF_DEFINED != 86604 /* Revision ID */ +#error Wrong include file (ff.h). +#endif + +#define MERGE2(a, b) a ## b +#define CVTBL(tbl, cp) MERGE2(tbl, cp) + +#pragma GCC push_options +#pragma GCC target ("thumb") + + +/*------------------------------------------------------------------------*/ +/* Code Conversion Tables */ +/*------------------------------------------------------------------------*/ + +#if FF_CODE_PAGE == 437 || FF_CODE_PAGE == 0 +static const WCHAR uc437[] = { /* CP437(U.S.) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 720 || FF_CODE_PAGE == 0 +static const WCHAR uc720[] = { /* CP720(Arabic) to Unicode conversion table */ + 0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9, 0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627, + 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A, + 0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0x0650, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 737 || FF_CODE_PAGE == 0 +static const WCHAR uc737[] = { /* CP737(Greek) to Unicode conversion table */ + 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0, + 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8, + 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD, 0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E, + 0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 771 || FF_CODE_PAGE == 0 +static const WCHAR uc771[] = { /* CP771(KBL) to Unicode conversion table */ + 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, + 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, + 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x0104, 0x0105, 0x010C, 0x010D, + 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, + 0x0118, 0x0119, 0x0116, 0x0117, 0x012E, 0x012F, 0x0160, 0x0161, 0x0172, 0x0173, 0x016A, 0x016B, 0x017D, 0x017E, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 775 || FF_CODE_PAGE == 0 +static const WCHAR uc775[] = { /* CP775(Baltic) to Unicode conversion table */ + 0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107, 0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4, + 0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6, 0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118, 0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D, + 0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B, 0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144, 0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019, + 0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E, 0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 850 || FF_CODE_PAGE == 0 +static const WCHAR uc850[] = { /* CP850(Latin 1) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580, + 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4, + 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 852 || FF_CODE_PAGE == 0 +static const WCHAR uc852[] = { /* CP852(Latin 2) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7, 0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106, + 0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E, 0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A, 0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE, 0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580, + 0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161, 0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4, + 0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 855 || FF_CODE_PAGE == 0 +static const WCHAR uc855[] = { /* CP855(Cyrillic) to Unicode conversion table */ + 0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404, 0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408, + 0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C, 0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A, + 0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414, 0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438, 0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E, 0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580, + 0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443, 0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116, + 0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D, 0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 857 || FF_CODE_PAGE == 0 +static const WCHAR uc857[] = { /* CP857(Turkish) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580, + 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000, 0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4, + 0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 860 || FF_CODE_PAGE == 0 +static const WCHAR uc860[] = { /* CP860(Portuguese) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E3, 0x00E0, 0x00C1, 0x00E7, 0x00EA, 0x00CA, 0x00E8, 0x00CD, 0x00D4, 0x00EC, 0x00C3, 0x00C2, + 0x00C9, 0x00C0, 0x00C8, 0x00F4, 0x00F5, 0x00F2, 0x00DA, 0x00F9, 0x00CC, 0x00D5, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x20A7, 0x00D3, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00D2, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 861 || FF_CODE_PAGE == 0 +static const WCHAR uc861[] = { /* CP861(Icelandic) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00D0, 0x00F0, 0x00DE, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00FE, 0x00FB, 0x00DD, 0x00FD, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00C1, 0x00CD, 0x00D3, 0x00DA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 862 || FF_CODE_PAGE == 0 +static const WCHAR uc862[] = { /* CP862(Hebrew) to Unicode conversion table */ + 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, + 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 863 || FF_CODE_PAGE == 0 +static const WCHAR uc863[] = { /* CP863(Canadian French) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00C2, 0x00E0, 0x00B6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x2017, 0x00C0, + 0x00C9, 0x00C8, 0x00CA, 0x00F4, 0x00CB, 0x00CF, 0x00FB, 0x00F9, 0x00A4, 0x00D4, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x00DB, 0x0192, + 0x00A6, 0x00B4, 0x00F3, 0x00FA, 0x00A8, 0x00BB, 0x00B3, 0x00AF, 0x00CE, 0x3210, 0x00AC, 0x00BD, 0x00BC, 0x00BE, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2219, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 864 || FF_CODE_PAGE == 0 +static const WCHAR uc864[] = { /* CP864(Arabic) to Unicode conversion table */ + 0x00B0, 0x00B7, 0x2219, 0x221A, 0x2592, 0x2500, 0x2502, 0x253C, 0x2524, 0x252C, 0x251C, 0x2534, 0x2510, 0x250C, 0x2514, 0x2518, + 0x03B2, 0x221E, 0x03C6, 0x00B1, 0x00BD, 0x00BC, 0x2248, 0x00AB, 0x00BB, 0xFEF7, 0xFEF8, 0x0000, 0x0000, 0xFEFB, 0xFEFC, 0x0000, + 0x00A0, 0x00AD, 0xFE82, 0x00A3, 0x00A4, 0xFE84, 0x0000, 0x20AC, 0xFE8E, 0xFE8F, 0xFE95, 0xFE99, 0x060C, 0xFE9D, 0xFEA1, 0xFEA5, + 0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, 0x0668, 0x0669, 0xFED1, 0x061B, 0xFEB1, 0xFEB5, 0xFEB9, 0x061F, + 0x00A2, 0xFE80, 0xFE81, 0xFE83, 0xFE85, 0xFECA, 0xFE8B, 0xFE8D, 0xFE91, 0xFE93, 0xFE97, 0xFE9B, 0xFE9F, 0xFEA3, 0xFEA7, 0xFEA9, + 0xFEAB, 0xFEAD, 0xFEAF, 0xFEB3, 0xFEB7, 0xFEBB, 0xFEBF, 0xFEC1, 0xFEC5, 0xFECB, 0xFECF, 0x00A6, 0x00AC, 0x00F7, 0x00D7, 0xFEC9, + 0x0640, 0xFED3, 0xFED7, 0xFEDB, 0xFEDF, 0xFEE3, 0xFEE7, 0xFEEB, 0xFEED, 0xFEEF, 0xFEF3, 0xFEBD, 0xFECC, 0xFECE, 0xFECD, 0xFEE1, + 0xFE7D, 0x0651, 0xFEE5, 0xFEE9, 0xFEEC, 0xFEF0, 0xFEF2, 0xFED0, 0xFED5, 0xFEF5, 0xFEF6, 0xFEDD, 0xFED9, 0xFEF1, 0x25A0, 0x0000 +}; +#endif +#if FF_CODE_PAGE == 865 || FF_CODE_PAGE == 0 +static const WCHAR uc865[] = { /* CP865(Nordic) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + 0x00C5, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00A4, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 866 || FF_CODE_PAGE == 0 +static const WCHAR uc866[] = { /* CP866(Russian) to Unicode conversion table */ + 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, + 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, + 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, + 0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0 +}; +#endif +#if FF_CODE_PAGE == 869 || FF_CODE_PAGE == 0 +static const WCHAR uc869[] = { /* CP869(Greek 2) to Unicode conversion table */ + 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x0386, 0x00B7, 0x00B7, 0x00AC, 0x00A6, 0x2018, 0x2019, 0x0388, 0x2015, 0x0389, + 0x038A, 0x03AA, 0x038C, 0x00B7, 0x00B7, 0x038E, 0x03AB, 0x00A9, 0x038F, 0x00B2, 0x00B3, 0x03AC, 0x00A3, 0x03AD, 0x03AE, 0x03AF, + 0x03CA, 0x0390, 0x03CC, 0x03CD, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x00BD, 0x0398, 0x0399, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x039A, 0x039B, 0x039C, 0x039D, 0x2563, 0x2551, 0x2557, 0x255D, 0x039E, 0x039F, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0A30, 0x03A1, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x03A3, + 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x2518, 0x250C, 0x2588, 0x2584, 0x03B4, 0x03B5, 0x2580, + 0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x0384, + 0x00AD, 0x00B1, 0x03C5, 0x03C6, 0x03C7, 0x00A7, 0x03C8, 0x0385, 0x00B0, 0x00A8, 0x03C9, 0x03CB, 0x03B0, 0x03CE, 0x25A0, 0x00A0 +}; +#endif + + + + +/*------------------------------------------------------------------------*/ +/* OEM <==> Unicode conversions for static code page configuration */ +/* SBCS fixed code page */ +/*------------------------------------------------------------------------*/ + +#if FF_CODE_PAGE != 0 && FF_CODE_PAGE < 900 +WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ + DWORD uni, /* UTF-16 encoded character to be converted */ + WORD cp /* Code page for the conversion */ +) +{ + WCHAR c = 0; + const WCHAR *p = CVTBL(uc, FF_CODE_PAGE); + + + if (uni < 0x80) { /* ASCII? */ + c = (WCHAR)uni; + + } else { /* Non-ASCII */ + if (uni < 0x10000 && cp == FF_CODE_PAGE) { /* Is it in BMP and valid code page? */ + for (c = 0; c < 0x80 && uni != p[c]; c++) ; + c = (c + 0x80) & 0xFF; + } + } + + return c; +} + +WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */ + WCHAR oem, /* OEM code to be converted */ + WORD cp /* Code page for the conversion */ +) +{ + WCHAR c = 0; + const WCHAR *p = CVTBL(uc, FF_CODE_PAGE); + + + if (oem < 0x80) { /* ASCII? */ + c = oem; + + } else { /* Extended char */ + if (cp == FF_CODE_PAGE) { /* Is it a valid code page? */ + if (oem < 0x100) c = p[oem - 0x80]; + } + } + + return c; +} + +#endif + + + +/*------------------------------------------------------------------------*/ +/* OEM <==> Unicode conversions for static code page configuration */ +/* DBCS fixed code page */ +/*------------------------------------------------------------------------*/ + +#if FF_CODE_PAGE >= 900 +WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ + DWORD uni, /* UTF-16 encoded character to be converted */ + WORD cp /* Code page for the conversion */ +) +{ + const WCHAR *p; + WCHAR c = 0, uc; + UINT i = 0, n, li, hi; + + + if (uni < 0x80) { /* ASCII? */ + c = (WCHAR)uni; + + } else { /* Non-ASCII */ + if (uni < 0x10000 && cp == FF_CODE_PAGE) { /* Is it in BMP and valid code page? */ + uc = (WCHAR)uni; + p = CVTBL(uni2oem, FF_CODE_PAGE); + hi = sizeof CVTBL(uni2oem, FF_CODE_PAGE) / 4 - 1; + li = 0; + for (n = 16; n; n--) { + i = li + (hi - li) / 2; + if (uc == p[i * 2]) break; + if (uc > p[i * 2]) { + li = i; + } else { + hi = i; + } + } + if (n != 0) c = p[i * 2 + 1]; + } + } + + return c; +} + + +WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */ + WCHAR oem, /* OEM code to be converted */ + WORD cp /* Code page for the conversion */ +) +{ + const WCHAR *p; + WCHAR c = 0; + UINT i = 0, n, li, hi; + + + if (oem < 0x80) { /* ASCII? */ + c = oem; + + } else { /* Extended char */ + if (cp == FF_CODE_PAGE) { /* Is it valid code page? */ + p = CVTBL(oem2uni, FF_CODE_PAGE); + hi = sizeof CVTBL(oem2uni, FF_CODE_PAGE) / 4 - 1; + li = 0; + for (n = 16; n; n--) { + i = li + (hi - li) / 2; + if (oem == p[i * 2]) break; + if (oem > p[i * 2]) { + li = i; + } else { + hi = i; + } + } + if (n != 0) c = p[i * 2 + 1]; + } + } + + return c; +} +#endif + + + +/*------------------------------------------------------------------------*/ +/* OEM <==> Unicode conversions for dynamic code page configuration */ +/*------------------------------------------------------------------------*/ + +#if FF_CODE_PAGE == 0 + +static const WORD cp_code[] = { 437, 720, 737, 771, 775, 850, 852, 855, 857, 860, 861, 862, 863, 864, 865, 866, 869, 0}; +static const WCHAR* const cp_table[] = {uc437, uc720, uc737, uc771, uc775, uc850, uc852, uc855, uc857, uc860, uc861, uc862, uc863, uc864, uc865, uc866, uc869, 0}; + + +WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ + DWORD uni, /* UTF-16 encoded character to be converted */ + WORD cp /* Code page for the conversion */ +) +{ + const WCHAR *p; + WCHAR c = 0, uc; + UINT i, n, li, hi; + + + if (uni < 0x80) { /* ASCII? */ + c = (WCHAR)uni; + + } else { /* Non-ASCII */ + if (uni < 0x10000) { /* Is it in BMP? */ + uc = (WCHAR)uni; + p = 0; + if (cp < 900) { /* SBCS */ + for (i = 0; cp_code[i] != 0 && cp_code[i] != cp; i++) ; /* Get conversion table */ + p = cp_table[i]; + if (p) { /* Is it valid code page ? */ + for (c = 0; c < 0x80 && uc != p[c]; c++) ; /* Find OEM code in the table */ + c = (c + 0x80) & 0xFF; + } + } else { /* DBCS */ + switch (cp) { /* Get conversion table */ + case 932 : p = uni2oem932; hi = sizeof uni2oem932 / 4 - 1; break; + case 936 : p = uni2oem936; hi = sizeof uni2oem936 / 4 - 1; break; + case 949 : p = uni2oem949; hi = sizeof uni2oem949 / 4 - 1; break; + case 950 : p = uni2oem950; hi = sizeof uni2oem950 / 4 - 1; break; + } + if (p) { /* Is it valid code page? */ + li = 0; + for (n = 16; n; n--) { /* Find OEM code */ + i = li + (hi - li) / 2; + if (uc == p[i * 2]) break; + if (uc > p[i * 2]) { + li = i; + } else { + hi = i; + } + } + if (n != 0) c = p[i * 2 + 1]; + } + } + } + } + + return c; +} + + +WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */ + WCHAR oem, /* OEM code to be converted (DBC if >=0x100) */ + WORD cp /* Code page for the conversion */ +) +{ + const WCHAR *p; + WCHAR c = 0; + UINT i, n, li, hi; + + + if (oem < 0x80) { /* ASCII? */ + c = oem; + + } else { /* Extended char */ + p = 0; + if (cp < 900) { /* SBCS */ + for (i = 0; cp_code[i] != 0 && cp_code[i] != cp; i++) ; /* Get table */ + p = cp_table[i]; + if (p) { /* Is it a valid CP ? */ + if (oem < 0x100) c = p[oem - 0x80]; + } + } else { /* DBCS */ + switch (cp) { + case 932 : p = oem2uni932; hi = sizeof oem2uni932 / 4 - 1; break; + case 936 : p = oem2uni936; hi = sizeof oem2uni936 / 4 - 1; break; + case 949 : p = oem2uni949; hi = sizeof oem2uni949 / 4 - 1; break; + case 950 : p = oem2uni950; hi = sizeof oem2uni950 / 4 - 1; break; + } + if (p) { + li = 0; + for (n = 16; n; n--) { + i = li + (hi - li) / 2; + if (oem == p[i * 2]) break; + if (oem > p[i * 2]) { + li = i; + } else { + hi = i; + } + } + if (n != 0) c = p[i * 2 + 1]; + } + } + } + + return c; +} +#endif + + + +/*------------------------------------------------------------------------*/ +/* Unicode up-case conversion */ +/*------------------------------------------------------------------------*/ + +DWORD ff_wtoupper ( /* Returns up-converted code point */ + DWORD uni /* Unicode code point to be up-converted */ +) +{ + const WORD *p; + WORD uc, bc, nc, cmd; + static const WORD cvt1[] = { /* Compressed up conversion table for U+0000 - U+0FFF */ + /* Basic Latin */ + 0x0061,0x031A, + /* Latin-1 Supplement */ + 0x00E0,0x0317, + 0x00F8,0x0307, + 0x00FF,0x0001,0x0178, + /* Latin Extended-A */ + 0x0100,0x0130, + 0x0132,0x0106, + 0x0139,0x0110, + 0x014A,0x012E, + 0x0179,0x0106, + /* Latin Extended-B */ + 0x0180,0x004D,0x0243,0x0181,0x0182,0x0182,0x0184,0x0184,0x0186,0x0187,0x0187,0x0189,0x018A,0x018B,0x018B,0x018D,0x018E,0x018F,0x0190,0x0191,0x0191,0x0193,0x0194,0x01F6,0x0196,0x0197,0x0198,0x0198,0x023D,0x019B,0x019C,0x019D,0x0220,0x019F,0x01A0,0x01A0,0x01A2,0x01A2,0x01A4,0x01A4,0x01A6,0x01A7,0x01A7,0x01A9,0x01AA,0x01AB,0x01AC,0x01AC,0x01AE,0x01AF,0x01AF,0x01B1,0x01B2,0x01B3,0x01B3,0x01B5,0x01B5,0x01B7,0x01B8,0x01B8,0x01BA,0x01BB,0x01BC,0x01BC,0x01BE,0x01F7,0x01C0,0x01C1,0x01C2,0x01C3,0x01C4,0x01C5,0x01C4,0x01C7,0x01C8,0x01C7,0x01CA,0x01CB,0x01CA, + 0x01CD,0x0110, + 0x01DD,0x0001,0x018E, + 0x01DE,0x0112, + 0x01F3,0x0003,0x01F1,0x01F4,0x01F4, + 0x01F8,0x0128, + 0x0222,0x0112, + 0x023A,0x0009,0x2C65,0x023B,0x023B,0x023D,0x2C66,0x023F,0x0240,0x0241,0x0241, + 0x0246,0x010A, + /* IPA Extensions */ + 0x0253,0x0040,0x0181,0x0186,0x0255,0x0189,0x018A,0x0258,0x018F,0x025A,0x0190,0x025C,0x025D,0x025E,0x025F,0x0193,0x0261,0x0262,0x0194,0x0264,0x0265,0x0266,0x0267,0x0197,0x0196,0x026A,0x2C62,0x026C,0x026D,0x026E,0x019C,0x0270,0x0271,0x019D,0x0273,0x0274,0x019F,0x0276,0x0277,0x0278,0x0279,0x027A,0x027B,0x027C,0x2C64,0x027E,0x027F,0x01A6,0x0281,0x0282,0x01A9,0x0284,0x0285,0x0286,0x0287,0x01AE,0x0244,0x01B1,0x01B2,0x0245,0x028D,0x028E,0x028F,0x0290,0x0291,0x01B7, + /* Greek, Coptic */ + 0x037B,0x0003,0x03FD,0x03FE,0x03FF, + 0x03AC,0x0004,0x0386,0x0388,0x0389,0x038A, + 0x03B1,0x0311, + 0x03C2,0x0002,0x03A3,0x03A3, + 0x03C4,0x0308, + 0x03CC,0x0003,0x038C,0x038E,0x038F, + 0x03D8,0x0118, + 0x03F2,0x000A,0x03F9,0x03F3,0x03F4,0x03F5,0x03F6,0x03F7,0x03F7,0x03F9,0x03FA,0x03FA, + /* Cyrillic */ + 0x0430,0x0320, + 0x0450,0x0710, + 0x0460,0x0122, + 0x048A,0x0136, + 0x04C1,0x010E, + 0x04CF,0x0001,0x04C0, + 0x04D0,0x0144, + /* Armenian */ + 0x0561,0x0426, + + 0x0000 /* EOT */ + }; + static const WORD cvt2[] = { /* Compressed up conversion table for U+1000 - U+FFFF */ + /* Phonetic Extensions */ + 0x1D7D,0x0001,0x2C63, + /* Latin Extended Additional */ + 0x1E00,0x0196, + 0x1EA0,0x015A, + /* Greek Extended */ + 0x1F00,0x0608, + 0x1F10,0x0606, + 0x1F20,0x0608, + 0x1F30,0x0608, + 0x1F40,0x0606, + 0x1F51,0x0007,0x1F59,0x1F52,0x1F5B,0x1F54,0x1F5D,0x1F56,0x1F5F, + 0x1F60,0x0608, + 0x1F70,0x000E,0x1FBA,0x1FBB,0x1FC8,0x1FC9,0x1FCA,0x1FCB,0x1FDA,0x1FDB,0x1FF8,0x1FF9,0x1FEA,0x1FEB,0x1FFA,0x1FFB, + 0x1F80,0x0608, + 0x1F90,0x0608, + 0x1FA0,0x0608, + 0x1FB0,0x0004,0x1FB8,0x1FB9,0x1FB2,0x1FBC, + 0x1FCC,0x0001,0x1FC3, + 0x1FD0,0x0602, + 0x1FE0,0x0602, + 0x1FE5,0x0001,0x1FEC, + 0x1FF3,0x0001,0x1FFC, + /* Letterlike Symbols */ + 0x214E,0x0001,0x2132, + /* Number forms */ + 0x2170,0x0210, + 0x2184,0x0001,0x2183, + /* Enclosed Alphanumerics */ + 0x24D0,0x051A, + 0x2C30,0x042F, + /* Latin Extended-C */ + 0x2C60,0x0102, + 0x2C67,0x0106, 0x2C75,0x0102, + /* Coptic */ + 0x2C80,0x0164, + /* Georgian Supplement */ + 0x2D00,0x0826, + /* Full-width */ + 0xFF41,0x031A, + + 0x0000 /* EOT */ + }; + + + if (uni < 0x10000) { /* Is it in BMP? */ + uc = (WORD)uni; + p = uc < 0x1000 ? cvt1 : cvt2; + for (;;) { + bc = *p++; /* Get the block base */ + if (bc == 0 || uc < bc) break; /* Not matched? */ + nc = *p++; cmd = nc >> 8; nc &= 0xFF; /* Get processing command and block size */ + if (uc < bc + nc) { /* In the block? */ + switch (cmd) { + case 0: uc = p[uc - bc]; break; /* Table conversion */ + case 1: uc -= (uc - bc) & 1; break; /* Case pairs */ + case 2: uc -= 16; break; /* Shift -16 */ + case 3: uc -= 32; break; /* Shift -32 */ + case 4: uc -= 48; break; /* Shift -48 */ + case 5: uc -= 26; break; /* Shift -26 */ + case 6: uc += 8; break; /* Shift +8 */ + case 7: uc -= 80; break; /* Shift -80 */ + case 8: uc -= 0x1C60; break; /* Shift -0x1C60 */ + } + break; + } + if (cmd == 0) p += nc; /* Skip table if needed */ + } + uni = uc; + } + + return uni; +} + +#pragma GCC pop_options + + +#endif /* #if FF_USE_LFN */ diff --git a/nyx/nyx_gui/libs/lv_conf.h b/nyx/nyx_gui/libs/lv_conf.h new file mode 100644 index 0000000..efd4667 --- /dev/null +++ b/nyx/nyx_gui/libs/lv_conf.h @@ -0,0 +1,376 @@ +/* + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LV_CONF_H +#define LV_CONF_H + +#include "../utils/types.h" +/*=================== + Dynamic memory + *===================*/ + +/* Memory size which will be used by the library + * to store the graphical objects and other data */ +#define LV_MEM_CUSTOM 0 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/ +#if LV_MEM_CUSTOM == 0 +# define LV_MEM_SIZE (0x38000U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ +# define LV_MEM_ATTR /*Complier prefix for big array declaration*/ +# define LV_MEM_ADR 0xF1000000 /*Set an address for memory pool instead of allocation it as an array. Can be in external SRAM too.*/ +# define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/ +#else /*LV_MEM_CUSTOM*/ +# define LV_MEM_CUSTOM_INCLUDE "../../../mem/heap.h" /*Header for the dynamic memory function*/ +# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ +# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ +#endif /*LV_MEM_CUSTOM*/ + +/* Garbage Collector settings + * Used if lvgl is binded to higher language and the memory is managed by that language */ +#define LV_ENABLE_GC 0 +#if LV_ENABLE_GC != 0 +# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/ +# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/ +# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ +#endif /* LV_ENABLE_GC */ + +/*=================== + Graphical settings + *===================*/ + +/* Horizontal and vertical resolution of the library.*/ +#define LV_HOR_RES (1280) +#define LV_VER_RES (720) + +/* Dot Per Inch: used to initialize default sizes. E.g. a button with width = LV_DPI / 2 -> half inch wide + * (Not so important, you can adjust it to modify default sizes and spaces)*/ +#define LV_DPI 100 + +/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ +#define LV_ANTIALIAS 1 /*1: Enable anti-aliasing*/ + +/*Screen refresh period in milliseconds*/ +#define LV_REFR_PERIOD 33 + +/*----------------- + * VDB settings + *----------------*/ + +/* VDB (Virtual Display Buffer) is an internal graphics buffer. + * The GUI will be drawn into this buffer first and then + * the buffer will be passed to your `disp_drv.disp_flush` function to + * copy it to your frame buffer. + * VDB is required for: buffered drawing, opacity, anti-aliasing and shadows + * Learn more: https://docs.littlevgl.com/#Drawing*/ + +/* Size of the VDB in pixels. Typical size: ~1/10 screen. Must be >= LV_HOR_RES + * Setting it to 0 will disable VDB and `disp_drv.disp_fill` and `disp_drv.disp_map` functions + * will be called to draw to the frame buffer directly*/ +#define LV_VDB_SIZE (LV_VER_RES * LV_HOR_RES) + + /* Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays. + * Special formats are handled with `disp_drv.vdb_wr`)*/ +#define LV_VDB_PX_BPP LV_COLOR_SIZE /*LV_COLOR_SIZE comes from LV_COLOR_DEPTH below to set 8, 16 or 32 bit pixel size automatically */ + + /* Place VDB to a specific address (e.g. in external RAM) + * 0: allocate automatically into RAM + * LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/ +#define LV_VDB_ADR 0xF0000000 + +/* Use two Virtual Display buffers (VDB) to parallelize rendering and flushing + * The flushing should use DMA to write the frame buffer in the background */ +#define LV_VDB_DOUBLE 0 + +/* Place VDB2 to a specific address (e.g. in external RAM) + * 0: allocate automatically into RAM + * LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/ +#define LV_VDB2_ADR 0 + +/* Using true double buffering in `disp_drv.disp_flush` you will always get the image of the whole screen. + * Your only task is to set the rendered image (`color_p` parameter) as frame buffer address or send it to your display. + * The best if you do in the blank period of you display to avoid tearing effect. + * Requires: + * - LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES + * - LV_VDB_DOUBLE = 1 + */ +#define LV_VDB_TRUE_DOUBLE_BUFFERED 0 + +/*================= + Misc. setting + *=================*/ + +/*Input device settings*/ +#define LV_INDEV_READ_PERIOD 33 /*Input device read period in milliseconds*/ +#define LV_INDEV_POINT_MARKER 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/ +#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */ +#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */ +#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/ +#define LV_INDEV_LONG_PRESS_REP_TIME 1000 //Fix keyb /*Repeated trigger period in long press [ms] */ + +/*Color settings*/ +#define LV_COLOR_DEPTH 32 /*Color depth: 1/8/16/32*/ +#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/ +#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/ +#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/ + +/*Text settings*/ +#define LV_TXT_UTF8 0 /*Enable UTF-8 coded Unicode character usage */ +#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/ +#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */ +#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */ +#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */ + +/*Feature usage*/ +#define USE_LV_ANIMATION 1 /*1: Enable all animations*/ +#define USE_LV_SHADOW 1 /*1: Enable shadows*/ +#define USE_LV_GROUP 0 /*1: Enable object groups (for keyboards)*/ +#define USE_LV_GPU 0 /*1: Enable GPU interface*/ +#define USE_LV_REAL_DRAW 0 /*1: Enable function which draw directly to the frame buffer instead of VDB (required if LV_VDB_SIZE = 0)*/ +#define USE_LV_FILESYSTEM 0 /*1: Enable file system (might be required for images*/ +#define USE_LV_MULTI_LANG 0 /* Number of languages for labels to store (0: to disable this feature)*/ + +/*Compiler settings*/ +#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */ +#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */ +#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/ +#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 /* 1: Initialization with non constant values are supported */ + +/*HAL settings*/ +#define LV_TICK_CUSTOM 1 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */ +#if LV_TICK_CUSTOM == 1 +#define LV_TICK_CUSTOM_INCLUDE "../../../utils/util.h" /*Header for the sys time function*/ +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (get_tmr_ms()) /*Expression evaluating to current systime in ms*/ +#endif /*LV_TICK_CUSTOM*/ + + +/*Log settings*/ +#define USE_LV_LOG 0 /*Enable/disable the log module*/ +#if USE_LV_LOG +/* How important log should be added: + * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information + * LV_LOG_LEVEL_INFO Log important events + * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't caused problem + * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail + */ +# define LV_LOG_LEVEL LV_LOG_LEVEL_TRACE +/* 1: Print the log with 'printf'; 0: user need to register a callback*/ +# define LV_LOG_PRINTF 1 +#endif /*USE_LV_LOG*/ + +/*================ + * THEME USAGE + *================*/ +#define LV_THEME_LIVE_UPDATE 0 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/ + +#define USE_LV_THEME_HEKATE 1 /*Flat theme with bold colors and light shadows*/ + +/*================== + * FONT USAGE + *===================*/ + +/* More info about fonts: https://docs.littlevgl.com/#Fonts + * To enable a built-in font use 1,2,4 or 8 values + * which will determine the bit-per-pixel. Higher value means smoother fonts */ +#define LV_FONT_QUALITY 8 + +#define USE_UBUNTU_MONO LV_FONT_QUALITY + +#define USE_INTERUI_20 LV_FONT_QUALITY +#define USE_INTERUI_30 LV_FONT_QUALITY + +#define USE_HEKATE_SYMBOL_20 USE_INTERUI_20 +#define USE_HEKATE_SYMBOL_30 USE_INTERUI_30 +#define USE_HEKATE_SYMBOL_120 LV_FONT_QUALITY + +/* Optionally declare your custom fonts here. + * You can use these fonts as default font too + * and they will be available globally. E.g. + * #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \ + * LV_FONT_DECLARE(my_font_2) \ + */ +#define LV_FONT_CUSTOM_DECLARE + +#define LV_FONT_DEFAULT &interui_30 /*Always set a default font from the built-in fonts*/ + +/*=================== + * LV_OBJ SETTINGS + *==================*/ +#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/ +#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/ +#define LV_OBJ_REALIGN 1 // 0 in OG gui /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/ + +/*================== + * LV OBJ X USAGE + *================*/ +/* + * Documentation of the object types: https://docs.littlevgl.com/#Object-types + */ + +/***************** + * Simple object + *****************/ + +/*Label (dependencies: -*/ +#define USE_LV_LABEL 1 +#if USE_LV_LABEL != 0 +# define LV_LABEL_SCROLL_SPEED 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/ +#endif + +/*Image (dependencies: lv_label*/ +#define USE_LV_IMG 1 +#if USE_LV_IMG != 0 +# define LV_IMG_CF_INDEXED 0 /*Enable indexed (palette) images*/ +# define LV_IMG_CF_ALPHA 1 /*Enable alpha indexed images*/ +#endif + +/*Line (dependencies: -*/ +#define USE_LV_LINE 1 + +/*Arc (dependencies: -)*/ +#define USE_LV_ARC 0 + +/******************* + * Container objects + *******************/ + +/*Container (dependencies: -*/ +#define USE_LV_CONT 1 + +/*Page (dependencies: lv_cont)*/ +#define USE_LV_PAGE 1 + +/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ +#define USE_LV_WIN 1 + +/*Tab (dependencies: lv_page, lv_btnm)*/ +#define USE_LV_TABVIEW 1 +# if USE_LV_TABVIEW != 0 +# define LV_TABVIEW_ANIM_TIME 0 /*Time of slide animation [ms] (0: no animation)*/ +#endif + +/*Tileview (dependencies: lv_page) */ +#define USE_LV_TILEVIEW 0 +#if USE_LV_TILEVIEW +# define LV_TILEVIEW_ANIM_TIME 0 /*Time of slide animation [ms] (0: no animation)*/ +#endif + +/************************* + * Data visualizer objects + *************************/ + +/*Bar (dependencies: -)*/ +#define USE_LV_BAR 1 + +/*Line meter (dependencies: *;)*/ +#define USE_LV_LMETER 0 + +/*Gauge (dependencies:lv_bar, lv_lmeter)*/ +#define USE_LV_GAUGE 0 + +/*Chart (dependencies: -)*/ +#define USE_LV_CHART 0 + +/*Table (dependencies: lv_label)*/ +#define USE_LV_TABLE 1 +#if USE_LV_TABLE +# define LV_TABLE_COL_MAX 12 +#endif + +/*LED (dependencies: -)*/ +#define USE_LV_LED 0 + +/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ +#define USE_LV_MBOX 1 + +/*Text area (dependencies: lv_label, lv_page)*/ +#define USE_LV_TA 1 +#if USE_LV_TA != 0 +# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/ +# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/ +#endif + +/*Spinbox (dependencies: lv_ta)*/ +#define USE_LV_SPINBOX 0 + +/*Calendar (dependencies: -)*/ +#define USE_LV_CALENDAR 0 + +/*Preload (dependencies: lv_arc)*/ +#define USE_LV_PRELOAD 0 +#if USE_LV_PRELOAD != 0 +# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/ +# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/ +# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC +#endif + +/*Canvas (dependencies: lv_img)*/ +#define USE_LV_CANVAS 0 +/************************* + * User input objects + *************************/ + +/*Button (dependencies: lv_cont*/ +#define USE_LV_BTN 1 +#if USE_LV_BTN != 0 +# define LV_BTN_INK_EFFECT 0 /*Enable button-state animations - draw a circle on click (dependencies: USE_LV_ANIMATION)*/ +#endif + +/*Image Button (dependencies: lv_btn*/ +#define USE_LV_IMGBTN 1 +#if USE_LV_IMGBTN +# define LV_IMGBTN_TILED 0 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/ +#endif + +/*Button matrix (dependencies: -)*/ +#define USE_LV_BTNM 1 + +/*Keyboard (dependencies: lv_btnm)*/ +#define USE_LV_KB 0 + +/*Check box (dependencies: lv_btn, lv_label)*/ +#define USE_LV_CB 1 + +/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ +#define USE_LV_LIST 1 +#if USE_LV_LIST != 0 +# define LV_LIST_FOCUS_TIME 100 /*Default animation time of focusing to a list element [ms] (0: no animation) */ +#endif + +/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ +#define USE_LV_DDLIST 1 +#if USE_LV_DDLIST != 0 +# define LV_DDLIST_ANIM_TIME 100 /*Open and close default animation time [ms] (0: no animation)*/ +#endif + +/*Roller (dependencies: lv_ddlist)*/ +#define USE_LV_ROLLER 1 +#if USE_LV_ROLLER != 0 +# define LV_ROLLER_ANIM_TIME 200 /*Focus animation time [ms] (0: no animation)*/ +#endif + +/*Slider (dependencies: lv_bar)*/ +#define USE_LV_SLIDER 1 + +/*Switch (dependencies: lv_slider)*/ +#define USE_LV_SW 1 + +/************************* + * Non-user section + *************************/ +#ifdef _MSC_VER /* Disable warnings for Visual Studio*/ +#define _CRT_SECURE_NO_WARNINGS +#endif + +#endif /*LV_CONF_H*/ + diff --git a/nyx/nyx_gui/libs/lvgl/docs/CODE_OF_CONDUCT.md b/nyx/nyx_gui/libs/lvgl/docs/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..c7d7eeb --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/docs/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +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. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +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. + +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. + +## Scope + +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. + +## Enforcement + +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. + +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. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/nyx/nyx_gui/libs/lvgl/docs/CONTRIBUTING.md b/nyx/nyx_gui/libs/lvgl/docs/CONTRIBUTING.md new file mode 100644 index 0000000..5d1d912 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/docs/CONTRIBUTING.md @@ -0,0 +1,103 @@ +# Contributing to Littlev Graphics Library + +**Welcome! It's glad to see that you are interested in contributing to LittlevGL! There are several types of task where you can help to build a better library! Let's see how to get started!** + + +There are many different possibilities to join the community. If you have some time to work with us I'm sure you will find something that fits you! You can: +- answer other's questions +- report and/or fix bugs +- suggest and/or implement new features +- improve and/or translate the documentation +- write a blog post about your experiences + +But first, start with the most Frequently Asked Questions. + +## FAQ about contributing + +### What license does my code need to be under? + +Any code added to LittlevGL must be licensed under [MIT](https://choosealicense.com/licenses/mit/) or another license that is fully compatible. Contributions under other licenses are highly likely to be rejected. + +If you borrow code from another project, please make sure to add their copyright notice to your contribution. + +### Where do I ask questions, give feedback, or report bugs? + +We use the [forum](http://forum.littlevgl.com/) for questions, feature suggestions, and discussions. + +We use [GitHub's issue tracker](https://github.com/littlevgl/lvgl/issues) to report bugs. + +For both of these there are some rules: +- Be kind and friendly. +- Speak about one thing in one issue. +- Give feedback and close the issue if your question is answered. +- Explain exactly what you experience or expect. _"The button is not working"_ is not enough info to get help. +- For most issues you should send an absolute minimal code example in order to reproduce the issue. Ideally this should be easily usable in the PC simulator. +- Use [Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) to format your post. +- If you don't get any answer in a week write a comment like "Can somebody help?". Maybe your issue wasn't noticed. + +### How can I send fixes and improvements? +Merging new code happens via Pull Requests. If you are still not familiar with the Pull Requests (PR for short) here is a quick guide about them: +1. **Fork** the [lvgl repository](https://github.com/littlevgl/lvgl). To do this click the "Fork" button in the top right corner. It will "copy" the `lvgl` repository to your GitHub account (`https://github.com/your_name?tab=repositories`) +2. **Clone** the forked repository and add your updates +3. **Create a PR** on the GitHub on the page of you `lvgl` repository(`https://github.com/your_name/lvgl`) by hitting the "New pull request" button +4. **Set the base branch**. It means where you want to merge your update. Bugfixes for the last release go to `master`, new features to the actual `dev-x.y` branch. +5. **Describe** what is in the update. An example code is welcome if applicable. + +Some advice: +- If you are not sure about your fix or feature it's better to open an issue first, and discuss the details there. +- Maybe your fix or update won't be perfect at first. Don't be afraid, just improve it and push the new commits. The PR will be updated accordingly. +- If your update needs some extra work it's okay to say: _"I'm busy now and I will improve it soon"_ or _"Sorry, I don't have time to improve it, I hope it helps in this form too"_. So it's better to say don't have time to continue then saying nothing. +- Please read and follow this [guide about the coding style](https://docs.littlevgl.com/#Coding-Style-Guide) + + +### Where is the documentation? + +You can read the documentation here: https://docs.littlevgl.com/ +You can edit the documentation here: https://github.com/littlevgl/doc + +### Where is the blog? + +You can read the blog here: https://blog.littlevgl.com/ +You can edit the blog here: https://github.com/littlevgl/blog + + +## So how and where can I contribute? + +### Answering other's questions + +It's a great way to contribute to the library if you already use it. Just go the [issue tracker](https://github.com/littlevgl/lvgl/issues), read the titles and if you are already familiar with a topic, don't be shy, and write your suggestion. + +### Reporting and/or fixing bugs +For simple bugfixes (typos, missing error handling, fixing a warning) is fine to send a Pull request directly. However, for more complex bugs it's better to open an issue first. In the issue, you should describe how to reproduce the bug and even add the minimal code snippet. + +### Suggesting and/or implementing new features +If you have a good idea don't hesitate to share with us. It's even better if you have time to deal with its implementation. Don't be afraid if you still don't know LittlevGL well enough. We will help you to get started. + +During the implementation don't forget the [Code style guide](https://docs.littlevgl.com/#Coding-Style-Guide). + +### Improving and/or translating the documentation + +The documentation of LittlevGL is written in Markdown and available [here](https://github.com/littlevgl/doc) for editing. If you find some parts of the documentation obscure or insufficient just search the related `.md` file, hit the edit icon and add your updates. This way a new Pull request will be generated automatically. + +If you can devote more time to improve the documentation you can translate it! +1. Just copy the English `.md` files from the root folder to `locale/LANGUAGE_CODE` (language code is e.g. DE, FR, ES etc) +2. Append the language code the end of files (e.g. Welcome_fr.md) +3. Update the filenames in `_Sidebar.md` +4. Translate the page(s) you want +5. Create a Pull request + +### Writing a blog post about your experiences + +Have ported LittlevGL to a new platform? Have you created a fancy GUI? Do you know a great trick? +You can share your knowledge on LittelvGL's blog! It's super easy to add your own post: +- Fork and clone the [blog repository](https://github.com/littlevgl/blog) +- Add your post in Markdown to the `_posts` folder. +- Store the images and other resources in a dedicated folder in `assets` +- Create a Pull Request + +The blog uses [Jekyll](https://jekyllrb.com/) to convert the `.md` files to a webpage. You can easily [run Jekyll offline](https://jekyllrb.com/docs/) to check your post before creating the Pull request + +## Summary + +I hope you have taken a liking to contribute to LittelvGL. A helpful and friendly community is waiting for you! :) + diff --git a/nyx/nyx_gui/libs/lvgl/docs/astyle_c b/nyx/nyx_gui/libs/lvgl/docs/astyle_c new file mode 100644 index 0000000..9b9d7f3 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/docs/astyle_c @@ -0,0 +1 @@ +--style=kr --convert-tabs --indent=spaces=4 --indent-switches --pad-oper --unpad-paren --align-pointer=middle --suffix=.bak --lineend=linux --min-conditional-indent= diff --git a/nyx/nyx_gui/libs/lvgl/docs/astyle_h b/nyx/nyx_gui/libs/lvgl/docs/astyle_h new file mode 100644 index 0000000..d9c7633 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/docs/astyle_h @@ -0,0 +1 @@ +--convert-tabs --indent=spaces=4 diff --git a/nyx/nyx_gui/libs/lvgl/licence.txt b/nyx/nyx_gui/libs/lvgl/licence.txt new file mode 100644 index 0000000..beaef1d --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/licence.txt @@ -0,0 +1,8 @@ +MIT licence +Copyright (c) 2016 Gábor Kiss-Vámosi + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_core.mk b/nyx/nyx_gui/libs/lvgl/lv_core/lv_core.mk new file mode 100644 index 0000000..9992e3f --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_core.mk @@ -0,0 +1,12 @@ +CSRCS += lv_group.c +CSRCS += lv_indev.c +CSRCS += lv_obj.c +CSRCS += lv_refr.c +CSRCS += lv_style.c +CSRCS += lv_vdb.c +CSRCS += lv_lang.c + +DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_core +VPATH += :$(LVGL_DIR)/lvgl/lv_core + +CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core" diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_group.c b/nyx/nyx_gui/libs/lvgl/lv_core/lv_group.c new file mode 100644 index 0000000..3fd4120 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_group.c @@ -0,0 +1,554 @@ +/** + * @file lv_group.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_group.h" +#if USE_LV_GROUP != 0 +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void style_mod_def(lv_style_t * style); +static void style_mod_edit_def(lv_style_t * style); +static void lv_group_refocus(lv_group_t *g); +static void obj_to_foreground(lv_obj_t * obj); + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a new object group + * @return pointer to the new object group + */ +lv_group_t * lv_group_create(void) +{ + lv_group_t * group = lv_mem_alloc(sizeof(lv_group_t)); + lv_mem_assert(group); + if(group == NULL) return NULL; + lv_ll_init(&group->obj_ll, sizeof(lv_obj_t *)); + + group->style_mod = style_mod_def; + group->style_mod_edit = style_mod_edit_def; + group->obj_focus = NULL; + group->frozen = 0; + group->focus_cb = NULL; + group->click_focus = 1; + group->editing = 0; + + return group; +} + +/** + * Delete a group object + * @param group pointer to a group + */ +void lv_group_del(lv_group_t * group) +{ + /*Defocus the the currently focused object*/ + if(group->obj_focus != NULL) { + (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL); + lv_obj_invalidate(*group->obj_focus); + } + + /*Remove the objects from the group*/ + lv_obj_t ** obj; + LL_READ(group->obj_ll, obj) { + (*obj)->group_p = NULL; + } + + lv_ll_clear(&(group->obj_ll)); + lv_mem_free(group); +} + +/** + * Add an object to a group + * @param group pointer to a group + * @param obj pointer to an object to add + */ +void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj) +{ + if(group == NULL) return; + + /*If the object is already in a group and focused then defocus it*/ + if(obj->group_p) { + if(lv_obj_is_focused(obj)) { + lv_group_refocus(obj->group_p); + + LV_LOG_INFO("group: assign object to an other group"); + } + } + + obj->group_p = group; + lv_obj_t ** next = lv_ll_ins_tail(&group->obj_ll); + lv_mem_assert(next); + if(next == NULL) return; + *next = obj; + + /* If the head and the tail is equal then there is only one object in the linked list. + * In this case automatically activate it*/ + if(lv_ll_get_head(&group->obj_ll) == next) { + lv_group_refocus(group); + } +} + +/** + * Remove an object from its group + * @param obj pointer to an object to remove + */ +void lv_group_remove_obj(lv_obj_t * obj) +{ + lv_group_t * g = obj->group_p; + if(g == NULL) return; + if(g->obj_focus == NULL) return; /*Just to be sure (Not possible if there is at least one object in the group)*/ + + /*Focus on the next object*/ + if(*g->obj_focus == obj) { + /*If this is the only object in the group then focus to nothing.*/ + if(lv_ll_get_head(&g->obj_ll) == g->obj_focus && lv_ll_get_tail(&g->obj_ll) == g->obj_focus) { + (*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL); + } + /*If there more objects in the group then focus to the next/prev object*/ + else { + lv_group_refocus(g); + } + } + + /* If the focuses object is still the same then it was the only object in the group but it will be deleted. + * Set the `obj_focus` to NULL to get back to the initial state of the group with zero objects*/ + if(*g->obj_focus == obj) { + g->obj_focus = NULL; + } + + /*Search the object and remove it from its group */ + lv_obj_t ** i; + LL_READ(g->obj_ll, i) { + if(*i == obj) { + lv_ll_rem(&g->obj_ll, i); + lv_mem_free(i); + obj->group_p = NULL; + break; + } + } +} + +/** + * Focus on an object (defocus the current) + * @param obj pointer to an object to focus on + */ +void lv_group_focus_obj(lv_obj_t * obj) +{ + lv_group_t * g = obj->group_p; + if(g == NULL) return; + + if(g->frozen != 0) return; + + /*On defocus edit mode must be leaved*/ + lv_group_set_editing(g, false); + + lv_obj_t ** i; + LL_READ(g->obj_ll, i) { + if(*i == obj) { + if(g->obj_focus == i) return; /*Don't focus the already focused object again*/ + if(g->obj_focus != NULL) { + (*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL); + lv_obj_invalidate(*g->obj_focus); + } + + g->obj_focus = i; + + if(g->obj_focus != NULL) { + (*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_FOCUS, NULL); + if(g->focus_cb) g->focus_cb(g); + lv_obj_invalidate(*g->obj_focus); + + /*If the object or its parent has `top == true` bring it to the foregorund*/ + obj_to_foreground(*g->obj_focus); + } + break; + } + } +} + +/** + * Focus the next object in a group (defocus the current) + * @param group pointer to a group + */ +void lv_group_focus_next(lv_group_t * group) +{ + if(group->frozen) return; + + if(group->obj_focus) { + (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL); + lv_obj_invalidate(*group->obj_focus); + } + + lv_obj_t ** obj_next; + if(group->obj_focus == NULL) obj_next = lv_ll_get_head(&group->obj_ll); + else obj_next = lv_ll_get_next(&group->obj_ll, group->obj_focus); + + if(obj_next == NULL) { + if(group->wrap) obj_next = lv_ll_get_head(&group->obj_ll); + else obj_next = lv_ll_get_tail(&group->obj_ll); + } + group->obj_focus = obj_next; + + if(group->obj_focus) { + (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_FOCUS, NULL); + lv_obj_invalidate(*group->obj_focus); + + if(group->focus_cb) group->focus_cb(group); + + /*If the object or its parent has `top == true` bring it to the foregorund*/ + obj_to_foreground(*group->obj_focus); + } +} + +/** + * Focus the previous object in a group (defocus the current) + * @param group pointer to a group + */ +void lv_group_focus_prev(lv_group_t * group) +{ + if(group->frozen) return; + + if(group->obj_focus) { + (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL); + lv_obj_invalidate(*group->obj_focus); + } + + lv_obj_t ** obj_next; + if(group->obj_focus == NULL) obj_next = lv_ll_get_tail(&group->obj_ll); + else obj_next = lv_ll_get_prev(&group->obj_ll, group->obj_focus); + + if(obj_next == NULL) { + if(group->wrap) obj_next = lv_ll_get_tail(&group->obj_ll); + else obj_next = lv_ll_get_head(&group->obj_ll); + } + group->obj_focus = obj_next; + + if(group->obj_focus != NULL) { + (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_FOCUS, NULL); + lv_obj_invalidate(*group->obj_focus); + + if(group->focus_cb) group->focus_cb(group); + + /*If the object or its parent has `top == true` bring it to the foregorund*/ + obj_to_foreground(*group->obj_focus); + } + +} + +/** + * Do not let to change the focus from the current object + * @param group pointer to a group + * @param en true: freeze, false: release freezing (normal mode) + */ +void lv_group_focus_freeze(lv_group_t * group, bool en) +{ + if(en == false) group->frozen = 0; + else group->frozen = 1; +} + +/** + * Send a control character to the focuses object of a group + * @param group pointer to a group + * @param c a character (use LV_GROUP_KEY_.. to navigate) + * @return result of focused object in group. + */ +lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c) +{ + lv_obj_t * act = lv_group_get_focused(group); + if(act == NULL) return LV_RES_OK; + + return act->signal_func(act, LV_SIGNAL_CONTROLL, &c); +} + +/** + * Set a function for a group which will modify the object's style if it is in focus + * @param group pointer to a group + * @param style_mod_func the style modifier function pointer + */ +void lv_group_set_style_mod_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func) +{ + group->style_mod = style_mod_func; + if(group->obj_focus != NULL) lv_obj_invalidate(*group->obj_focus); +} + +/** + * Set a function for a group which will modify the object's style if it is in focus in edit mode + * @param group pointer to a group + * @param style_mod_func the style modifier function pointer + */ +void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func) +{ + group->style_mod_edit = style_mod_func; + if(group->obj_focus != NULL) lv_obj_invalidate(*group->obj_focus); +} + +/** + * Set a function for a group which will be called when a new object is focused + * @param group pointer to a group + * @param focus_cb the call back function or NULL if unused + */ +void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb) +{ + group->focus_cb = focus_cb; +} + +/** + * Manually set the current mode (edit or navigate). + * @param group pointer to group + * @param edit: true: edit mode; false: navigate mode + */ +void lv_group_set_editing(lv_group_t * group, bool edit) +{ + uint8_t en_val = edit ? 1 : 0; + + if(en_val == group->editing) return; /*Do not set the same mode again*/ + + group->editing = en_val; + lv_obj_t * focused = lv_group_get_focused(group); + + if(focused) focused->signal_func(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again to properly leave edit mode*/ + + lv_obj_invalidate(focused); +} + +/** + * Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked. + * @param group pointer to group + * @param en: true: enable `click_focus` + */ +void lv_group_set_click_focus(lv_group_t * group, bool en) +{ + group->click_focus = en ? 1 : 0; +} + +void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy) { + group->refocus_policy = policy & 0x01; +} + +static void lv_group_refocus(lv_group_t *g) { + /*Refocus must temporarily allow wrapping to work correctly*/ + uint8_t temp_wrap = g->wrap; + g->wrap = 1; + + if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_NEXT) + lv_group_focus_next(g); + else if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_PREV) + lv_group_focus_prev(g); + /*Restore wrap property*/ + g->wrap = temp_wrap; +} + +/** + * Set whether focus next/prev will allow wrapping from first->last or last->first. + * @param group pointer to group + * @param en: true: enable `click_focus` + */ +void lv_group_set_wrap(lv_group_t * group, bool en) +{ + group->wrap = en ? 1 : 0; +} + +/** + * Modify a style with the set 'style_mod' function. The input style remains unchanged. + * @param group pointer to group + * @param style pointer to a style to modify + * @return a copy of the input style but modified with the 'style_mod' function + */ +lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style) +{ + lv_style_copy(&group->style_tmp, style); + + if(group->editing) { + if(group->style_mod_edit) group->style_mod_edit(&group->style_tmp); + } else { + if(group->style_mod) group->style_mod(&group->style_tmp); + } + return &group->style_tmp; +} + +/** + * Get the focused object or NULL if there isn't one + * @param group pointer to a group + * @return pointer to the focused object + */ +lv_obj_t * lv_group_get_focused(const lv_group_t * group) +{ + if(!group) return NULL; + if(group->obj_focus == NULL) return NULL; + + return *group->obj_focus; +} + +/** + * Get a the style modifier function of a group + * @param group pointer to a group + * @return pointer to the style modifier function + */ +lv_group_style_mod_func_t lv_group_get_style_mod_cb(const lv_group_t * group) +{ + if(!group) return false; + return group->style_mod ; +} + +/** + * Get a the style modifier function of a group in edit mode + * @param group pointer to a group + * @return pointer to the style modifier function + */ +lv_group_style_mod_func_t lv_group_get_style_mod_edit_cb(const lv_group_t * group) +{ + if(!group) return false; + return group->style_mod_edit; +} + +/** + * Get the focus callback function of a group + * @param group pointer to a group + * @return the call back function or NULL if not set + */ +lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group) +{ + if(!group) return false; + return group->focus_cb; +} + +/** + * Get the current mode (edit or navigate). + * @param group pointer to group + * @return true: edit mode; false: navigate mode + */ +bool lv_group_get_editing(const lv_group_t * group) +{ + if(!group) return false; + return group->editing ? true : false; +} + +/** + * Get the `click_focus` attribute. + * @param group pointer to group + * @return true: `click_focus` is enabled; false: disabled + */ +bool lv_group_get_click_focus(const lv_group_t * group) +{ + if(!group) return false; + return group->click_focus ? true : false; +} + +/** + * Get whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en: true: wrapping enabled; false: wrapping disabled + */ +bool lv_group_get_wrap(lv_group_t * group) +{ + if(!group) return false; + return group->wrap ? true : false; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Default style modifier function + * @param style pointer to a style to modify. (Typically group.style_tmp) It will be OVERWRITTEN. + */ +static void style_mod_def(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_ORANGE; + + /*If not empty or has border then emphasis the border*/ + if(style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_ORANGE, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_ORANGE, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_ORANGE, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_ORANGE, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; + +#endif + +} + +/** + * Default style modifier function + * @param style pointer to a style to modify. (Typically group.style_tmp) It will be OVERWRITTEN. + */ +static void style_mod_edit_def(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_GREEN; + + /*If not empty or has border then emphasis the border*/ + if(style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 3; + +#endif + +} + +static void obj_to_foreground(lv_obj_t * obj) +{ + /*Search for 'top' attribute*/ + lv_obj_t * i = obj; + lv_obj_t * last_top = NULL; + while(i != NULL) { + if(i->top != 0) last_top = i; + i = lv_obj_get_parent(i); + } + + if(last_top != NULL) { + /*Move the last_top object to the foreground*/ + lv_obj_t * par = lv_obj_get_parent(last_top); + /*After list change it will be the new head*/ + lv_ll_chg_list(&par->child_ll, &par->child_ll, last_top); + lv_obj_invalidate(last_top); + } +} + +#endif /*USE_LV_GROUP != 0*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_group.h b/nyx/nyx_gui/libs/lvgl/lv_core/lv_group.h new file mode 100644 index 0000000..6be9b5c --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_group.h @@ -0,0 +1,247 @@ +/** + * @file lv_group.h + * + */ + +#ifndef LV_GROUP_H +#define LV_GROUP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include "lv_obj.h" + +/********************* + * DEFINES + *********************/ +/*Predefined keys to control the focused object via lv_group_send(group, c)*/ +/*For compatibility in signal function define the keys regardless to LV_GROUP*/ +#define LV_GROUP_KEY_UP 17 /*0x11*/ +#define LV_GROUP_KEY_DOWN 18 /*0x12*/ +#define LV_GROUP_KEY_RIGHT 19 /*0x13*/ +#define LV_GROUP_KEY_LEFT 20 /*0x14*/ +#define LV_GROUP_KEY_ESC 27 /*0x1B*/ +#define LV_GROUP_KEY_DEL 127 /*0x7F*/ +#define LV_GROUP_KEY_BACKSPACE 8 /*0x08*/ +#define LV_GROUP_KEY_ENTER 10 /*0x0A, '\n'*/ +#define LV_GROUP_KEY_NEXT 9 /*0x09, '\t'*/ +#define LV_GROUP_KEY_PREV 11 /*0x0B, '*/ + +#if USE_LV_GROUP != 0 +/********************** + * TYPEDEFS + **********************/ +struct _lv_group_t; + +typedef void (*lv_group_style_mod_func_t)(lv_style_t *); +typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *); + +typedef struct _lv_group_t +{ + lv_ll_t obj_ll; /*Linked list to store the objects in the group */ + lv_obj_t ** obj_focus; /*The object in focus*/ + lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/ + lv_group_style_mod_func_t style_mod_edit;/*A function which modifies the style of the focused object*/ + lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/ + lv_style_t style_tmp; /*Stores the modified style of the focused object */ + uint8_t frozen :1; /*1: can't focus to new object*/ + uint8_t editing :1; /*1: Edit mode, 0: Navigate mode*/ + uint8_t click_focus :1; /*1: If an object in a group is clicked by an indev then it will be focused */ + uint8_t refocus_policy :1; /*1: Focus prev if focused on deletion. 0: Focus prev if focused on deletion.*/ + uint8_t wrap :1; /*1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end of list.*/ +} lv_group_t; + +typedef enum _lv_group_refocus_policy_t { + LV_GROUP_REFOCUS_POLICY_NEXT = 0, + LV_GROUP_REFOCUS_POLICY_PREV = 1 +} lv_group_refocus_policy_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a new object group + * @return pointer to the new object group + */ +lv_group_t * lv_group_create(void); + +/** + * Delete a group object + * @param group pointer to a group + */ +void lv_group_del(lv_group_t * group); + +/** + * Add an object to a group + * @param group pointer to a group + * @param obj pointer to an object to add + */ +void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj); + +/** + * Remove an object from its group + * @param obj pointer to an object to remove + */ +void lv_group_remove_obj(lv_obj_t * obj); + +/** + * Focus on an object (defocus the current) + * @param obj pointer to an object to focus on + */ +void lv_group_focus_obj(lv_obj_t * obj); + +/** + * Focus the next object in a group (defocus the current) + * @param group pointer to a group + */ +void lv_group_focus_next(lv_group_t * group); + +/** + * Focus the previous object in a group (defocus the current) + * @param group pointer to a group + */ +void lv_group_focus_prev(lv_group_t * group); + +/** + * Do not let to change the focus from the current object + * @param group pointer to a group + * @param en true: freeze, false: release freezing (normal mode) + */ +void lv_group_focus_freeze(lv_group_t * group, bool en); + +/** + * Send a control character to the focuses object of a group + * @param group pointer to a group + * @param c a character (use LV_GROUP_KEY_.. to navigate) + * @return result of focused object in group. + */ +lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c); + +/** + * Set a function for a group which will modify the object's style if it is in focus + * @param group pointer to a group + * @param style_mod_func the style modifier function pointer + */ +void lv_group_set_style_mod_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func); + +/** + * Set a function for a group which will modify the object's style if it is in focus in edit mode + * @param group pointer to a group + * @param style_mod_func the style modifier function pointer + */ +void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func); + +/** + * Set a function for a group which will be called when a new object is focused + * @param group pointer to a group + * @param focus_cb the call back function or NULL if unused + */ +void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb); + +/** + * Set whether the next or previous item in a group is focused if the currently focussed obj is deleted. + * @param group pointer to a group + * @param new refocus policy enum + */ +void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy); + +/** + * Manually set the current mode (edit or navigate). + * @param group pointer to group + * @param edit: true: edit mode; false: navigate mode + */ +void lv_group_set_editing(lv_group_t * group, bool edit); + +/** + * Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked. + * @param group pointer to group + * @param en: true: enable `click_focus` + */ +void lv_group_set_click_focus(lv_group_t * group, bool en); + +/** + * Set whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en: true: wrapping enabled; false: wrapping disabled + */ +void lv_group_set_wrap(lv_group_t * group, bool en); + +/** + * Modify a style with the set 'style_mod' function. The input style remains unchanged. + * @param group pointer to group + * @param style pointer to a style to modify + * @return a copy of the input style but modified with the 'style_mod' function + */ +lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style); + +/** + * Get the focused object or NULL if there isn't one + * @param group pointer to a group + * @return pointer to the focused object + */ +lv_obj_t * lv_group_get_focused(const lv_group_t * group); + +/** + * Get a the style modifier function of a group + * @param group pointer to a group + * @return pointer to the style modifier function + */ +lv_group_style_mod_func_t lv_group_get_style_mod_cb(const lv_group_t * group); + +/** + * Get a the style modifier function of a group in edit mode + * @param group pointer to a group + * @return pointer to the style modifier function + */ +lv_group_style_mod_func_t lv_group_get_style_mod_edit_cb(const lv_group_t * group); + +/** + * Get the focus callback function of a group + * @param group pointer to a group + * @return the call back function or NULL if not set + */ +lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group); + +/** + * Get the current mode (edit or navigate). + * @param group pointer to group + * @return true: edit mode; false: navigate mode + */ +bool lv_group_get_editing(const lv_group_t * group); + +/** + * Get the `click_focus` attribute. + * @param group pointer to group + * @return true: `click_focus` is enabled; false: disabled + */ +bool lv_group_get_click_focus(const lv_group_t * group); + +/** + * Get whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en: true: wrapping enabled; false: wrapping disabled + */ +bool lv_group_get_wrap(lv_group_t * group); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_GROUP != 0*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_GROUP_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.c b/nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.c new file mode 100644 index 0000000..d3ae93f --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.c @@ -0,0 +1,965 @@ +/** + * @file lv_indev_proc.c + * + */ + +/********************* + * INCLUDES + ********************/ +#include "lv_indev.h" + +#include "../lv_hal/lv_hal_tick.h" +#include "../lv_core/lv_group.h" +#include "../lv_core/lv_refr.h" +#include "../lv_misc/lv_task.h" +#include "../lv_misc/lv_math.h" +#include "../lv_draw/lv_draw_rbasic.h" +#include "lv_obj.h" + +/********************* + * DEFINES + *********************/ + +#if LV_INDEV_DRAG_THROW <= 0 +#warning "LV_INDEV_DRAG_THROW must be greater than 0" +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +#if LV_INDEV_READ_PERIOD != 0 +static void indev_proc_task(void * param); +static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data); +static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data); +static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data); +static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data); +static void indev_proc_press(lv_indev_proc_t * proc); +static void indev_proc_release(lv_indev_proc_t * proc); +static void indev_proc_reset_query_handler(lv_indev_t * indev); +static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj); +static void indev_drag(lv_indev_proc_t * state); +static void indev_drag_throw(lv_indev_proc_t * state); +#endif + +/********************** + * STATIC VARIABLES + **********************/ +static lv_indev_t * indev_act; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the display input device subsystem + */ +void lv_indev_init(void) +{ +#if LV_INDEV_READ_PERIOD != 0 + lv_task_create(indev_proc_task, LV_INDEV_READ_PERIOD, LV_TASK_PRIO_MID, NULL); +#endif + + lv_indev_reset(NULL); /*Reset all input devices*/ +} + +/** + * Get the currently processed input device. Can be used in action functions too. + * @return pointer to the currently processed input device or NULL if no input device processing right now + */ +lv_indev_t * lv_indev_get_act(void) +{ + return indev_act; +} + +/** + * Get the type of an input device + * @param indev pointer to an input device + * @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`) + */ +lv_hal_indev_type_t lv_indev_get_type(const lv_indev_t * indev) +{ + if(indev == NULL) return LV_INDEV_TYPE_NONE; + + return indev->driver.type; +} +/** + * Reset one or all input devices + * @param indev pointer to an input device to reset or NULL to reset all of them + */ +void lv_indev_reset(lv_indev_t * indev) +{ + if(indev) indev->proc.reset_query = 1; + else { + lv_indev_t * i = lv_indev_next(NULL); + while(i) { + i->proc.reset_query = 1; + i = lv_indev_next(i); + } + } +} + +/** + * Reset the long press state of an input device + * @param indev pointer to an input device + */ +void lv_indev_reset_lpr(lv_indev_t * indev) +{ + indev->proc.long_pr_sent = 0; + indev->proc.longpr_rep_timestamp = lv_tick_get(); + indev->proc.pr_timestamp = lv_tick_get(); +} + +/** + * Enable input devices device by type + * @param type Input device type + * @param enable true: enable this type; false: disable this type + */ +void lv_indev_enable(lv_hal_indev_type_t type, bool enable) +{ + lv_indev_t * i = lv_indev_next(NULL); + + while(i) { + if(i->driver.type == type) i->proc.disabled = enable == false ? 1 : 0; + i = lv_indev_next(i); + } +} + +/** + * Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON) + * @param indev pointer to an input device + * @param cur_obj pointer to an object to be used as cursor + */ +void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj) +{ + if(indev->driver.type != LV_INDEV_TYPE_POINTER) return; + + indev->cursor = cur_obj; + lv_obj_set_parent(indev->cursor, lv_layer_sys()); + lv_obj_set_pos(indev->cursor, indev->proc.act_point.x, indev->proc.act_point.y); +} + +#if USE_LV_GROUP +/** + * Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD) + * @param indev pointer to an input device + * @param group point to a group + */ +void lv_indev_set_group(lv_indev_t * indev, lv_group_t * group) +{ + if(indev->driver.type == LV_INDEV_TYPE_KEYPAD || indev->driver.type == LV_INDEV_TYPE_ENCODER) indev->group = group; +} +#endif + +/** + * Set the an array of points for LV_INDEV_TYPE_BUTTON. + * These points will be assigned to the buttons to press a specific point on the screen + * @param indev pointer to an input device + * @param group point to a group + */ +void lv_indev_set_button_points(lv_indev_t * indev, const lv_point_t * points) +{ + if(indev->driver.type == LV_INDEV_TYPE_BUTTON) indev->btn_points = points; +} + +/** + * Set feedback callback for indev. + * @param indev pointer to an input device + * @param feedback feedback callback + */ +void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback) +{ + indev->feedback = feedback; +} + +/** + * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @param point pointer to a point to store the result + */ +void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point) +{ + if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) { + point->x = -1; + point->y = -1; + } else { + point->x = indev->proc.act_point.x; + point->y = indev->proc.act_point.y; + } +} + +/** + * Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD) + * @param indev pointer to an input device + * @return the last pressed key (0 on error) + */ +uint32_t lv_indev_get_key(const lv_indev_t * indev) +{ + if(indev->driver.type != LV_INDEV_TYPE_KEYPAD) return 0; + else return indev->proc.last_key; +} + +/** + * Check if there is dragging with an input device or not (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @return true: drag is in progress + */ +bool lv_indev_is_dragging(const lv_indev_t * indev) +{ + if(indev == NULL) return false; + if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) return false; + return indev->proc.drag_in_prog == 0 ? false : true; +} + +/** + * Get the vector of dragging of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @param point pointer to a point to store the vector + */ +void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point) +{ + if(indev == NULL) { + point->x = 0; + point->y = 0; + return; + } + + if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) { + point->x = 0; + point->y = 0; + } else { + point->x = indev->proc.vect.x; + point->y = indev->proc.vect.y; + } +} + +/** + * Get elapsed time since last press + * @param indev pointer to an input device (NULL to get the overall smallest inactivity) + * @return Elapsed ticks (milliseconds) since last press + */ +uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev) +{ + uint32_t t; + + if(indev) return t = lv_tick_elaps(indev->last_activity_time); + + lv_indev_t * i; + t = UINT16_MAX; + i = lv_indev_next(NULL); + while(i) { + t = LV_MATH_MIN(t, lv_tick_elaps(i->last_activity_time)); + i = lv_indev_next(i); + } + + return t; +} + +/** + * Get feedback callback for indev. + * @param indev pointer to an input device + * @return feedback callback + */ +lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev) +{ + return indev->feedback; +} + +/** + * Do nothing until the next release + * @param indev pointer to an input device + */ +void lv_indev_wait_release(lv_indev_t * indev) +{ + indev->proc.wait_unil_release = 1; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#if LV_INDEV_READ_PERIOD != 0 +/** + * Called periodically to handle the input devices + * @param param unused + */ +static void indev_proc_task(void * param) +{ + (void)param; + + + LV_LOG_TRACE("indev task started"); + + lv_indev_data_t data; + lv_indev_t * i; + i = lv_indev_next(NULL); + + /*Read and process all indevs*/ + while(i) { + indev_act = i; + + /*Handle reset query before processing the point*/ + indev_proc_reset_query_handler(i); + + if(i->proc.disabled == 0) { + bool more_to_read; + do { + /*Read the data*/ + more_to_read = lv_indev_read(i, &data); + indev_proc_reset_query_handler(i); /*The active object might deleted even in the read function*/ + i->proc.state = data.state; + + if(i->proc.state == LV_INDEV_STATE_PR) { + i->last_activity_time = lv_tick_get(); + } + + if(i->driver.type == LV_INDEV_TYPE_POINTER) { + indev_pointer_proc(i, &data); + } else if(i->driver.type == LV_INDEV_TYPE_KEYPAD) { + indev_keypad_proc(i, &data); + } else if(i->driver.type == LV_INDEV_TYPE_ENCODER) { + indev_encoder_proc(i, &data); + } else if(i->driver.type == LV_INDEV_TYPE_BUTTON) { + indev_button_proc(i, &data); + } + /*Handle reset query if it happened in during processing*/ + indev_proc_reset_query_handler(i); + } while(more_to_read); + } + i = lv_indev_next(i); /*Go to the next indev*/ + } + + indev_act = NULL; /*End of indev processing, so no act indev*/ + + LV_LOG_TRACE("indev task finished"); +} + + +/** + * Process a new point from LV_INDEV_TYPE_POINTER input device + * @param i pointer to an input device + * @param data pointer to the data read from the input device + */ +static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data) +{ + /*Move the cursor if set and moved*/ + if(i->cursor != NULL && + (i->proc.last_point.x != data->point.x || + i->proc.last_point.y != data->point.y)) { + lv_obj_set_pos(i->cursor, data->point.x, data->point.y); + } + + i->proc.act_point.x = data->point.x; + i->proc.act_point.y = data->point.y; + + if(i->proc.state == LV_INDEV_STATE_PR) { +#if LV_INDEV_POINT_MARKER != 0 + lv_area_t area; + area.x1 = i->proc.act_point.x - (LV_INDEV_POINT_MARKER >> 1); + area.y1 = i->proc.act_point.y - (LV_INDEV_POINT_MARKER >> 1); + area.x2 = i->proc.act_point.x + ((LV_INDEV_POINT_MARKER >> 1) | 0x1); + area.y2 = i->proc.act_point.y + ((LV_INDEV_POINT_MARKER >> 1) | 0x1); + lv_rfill(&area, NULL, LV_COLOR_MAKE(0xFF, 0, 0), LV_OPA_COVER); +#endif + indev_proc_press(&i->proc); + } else { + indev_proc_release(&i->proc); + } + + i->proc.last_point.x = i->proc.act_point.x; + i->proc.last_point.y = i->proc.act_point.y; +} + +/** + * Process a new point from LV_INDEV_TYPE_KEYPAD input device + * @param i pointer to an input device + * @param data pointer to the data read from the input device + */ +static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) +{ +#if USE_LV_GROUP + if(i->group == NULL) return; + + /*Key press happened*/ + if(data->state == LV_INDEV_STATE_PR && + i->proc.last_state == LV_INDEV_STATE_REL) { + i->proc.pr_timestamp = lv_tick_get(); + lv_obj_t * focused = lv_group_get_focused(i->group); + if(focused && data->key == LV_GROUP_KEY_ENTER) { + focused->signal_func(focused, LV_SIGNAL_PRESSED, indev_act); + } + } + /*Pressing*/ + else if(data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_PR) { + if(data->key == LV_GROUP_KEY_ENTER && + i->proc.long_pr_sent == 0 && + lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) { + /*On enter long press leave edit mode.*/ + lv_obj_t * focused = lv_group_get_focused(i->group); + if(focused) { + focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act); + i->proc.long_pr_sent = 1; + } + } + } + /*Release happened*/ + else if(data->state == LV_INDEV_STATE_REL && i->proc.last_state == LV_INDEV_STATE_PR) { + /*The user might clear the key when it was released. Always release the pressed key*/ + data->key = i->proc.last_key; + + /* Edit mode is not used by KEYPAD devices. + * So leave edit mode if we are in it before focusing on the next/prev object*/ + if(data->key == LV_GROUP_KEY_NEXT || data->key == LV_GROUP_KEY_PREV) { + lv_group_set_editing(i->group, false); + } + + if(data->key == LV_GROUP_KEY_NEXT) { + lv_group_focus_next(i->group); + } else if(data->key == LV_GROUP_KEY_PREV) { + lv_group_focus_prev(i->group); + } else if(data->key == LV_GROUP_KEY_ENTER) { + if(!i->proc.long_pr_sent) { + lv_group_send_data(i->group, data->key); + } + } else { + lv_group_send_data(i->group, data->key); + } + + if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/ + + i->proc.pr_timestamp = 0; + i->proc.long_pr_sent = 0; + } + + i->proc.last_state = data->state; + i->proc.last_key = data->key; +#else + (void)data; /*Unused*/ + (void)i; /*Unused*/ +#endif +} + +/** + * Process a new point from LV_INDEV_TYPE_ENCODER input device + * @param i pointer to an input device + * @param data pointer to the data read from the input device + */ +static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) +{ +#if USE_LV_GROUP + if(i->group == NULL) return; + + /*Process the steps first. They are valid only with released button*/ + if(data->state == LV_INDEV_STATE_REL) { + /*In edit mode send LEFT/RIGHT keys*/ + if(lv_group_get_editing(i->group)) { + int32_t s; + if(data->enc_diff < 0) { + for(s = 0; s < -data->enc_diff; s++) lv_group_send_data(i->group, LV_GROUP_KEY_LEFT); + } else if(data->enc_diff > 0) { + for(s = 0; s < data->enc_diff; s++) lv_group_send_data(i->group, LV_GROUP_KEY_RIGHT); + } + } + /*In navigate mode focus on the next/prev objects*/ + else { + int32_t s; + if(data->enc_diff < 0) { + for(s = 0; s < -data->enc_diff; s++) lv_group_focus_prev(i->group); + } else if(data->enc_diff > 0) { + for(s = 0; s < data->enc_diff; s++) lv_group_focus_next(i->group); + } + } + } + + /*Key press happened*/ + if(data->state == LV_INDEV_STATE_PR && + i->proc.last_state == LV_INDEV_STATE_REL) { + i->proc.pr_timestamp = lv_tick_get(); + } + /*Pressing*/ + else if(data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_PR) { + if(i->proc.long_pr_sent == 0 && + lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) { + /*On enter long press leave edit mode.*/ + lv_obj_t * focused = lv_group_get_focused(i->group); + + bool editable = false; + if(focused) focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable); + + if(editable) { + if(i->group->obj_ll.head != i->group->obj_ll.tail) + lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/ + else if(focused) + focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act); + } + /*If not editable then just send a long press signal*/ + else { + if(focused) + focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act); + } + i->proc.long_pr_sent = 1; + } + } + /*Release happened*/ + else if(data->state == LV_INDEV_STATE_REL && i->proc.last_state == LV_INDEV_STATE_PR) { + lv_obj_t * focused = lv_group_get_focused(i->group); + bool editable = false; + if(focused) focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable); + + /*The button was released on a non-editable object. Just send enter*/ + if(!editable) { + lv_group_send_data(i->group, LV_GROUP_KEY_ENTER); + } + /*An object is being edited and the button is releases. Just send enter */ + else if(i->group->editing) { + if(!i->proc.long_pr_sent || i->group->obj_ll.head == i->group->obj_ll.tail) + lv_group_send_data(i->group, LV_GROUP_KEY_ENTER); /*Ignore long pressed enter release because it comes from mode switch*/ + } + /*If the focused object is editable and now in navigate mode then enter edit mode*/ + else if(editable && !i->group->editing && !i->proc.long_pr_sent) { + lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/ + } + + if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/ + + i->proc.pr_timestamp = 0; + i->proc.long_pr_sent = 0; + } + + i->proc.last_state = data->state; + i->proc.last_key = data->key; +#else + (void)data; /*Unused*/ + (void)i; /*Unused*/ +#endif +} + +/** + * Process new points from a input device. indev->state.pressed has to be set + * @param indev pointer to an input device state + * @param x x coordinate of the next point + * @param y y coordinate of the next point + */ +static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data) +{ + i->proc.act_point.x = i->btn_points[data->btn].x; + i->proc.act_point.y = i->btn_points[data->btn].y; + + /*Still the same point is pressed*/ + if(i->proc.last_point.x == i->proc.act_point.x && + i->proc.last_point.y == i->proc.act_point.y && + data->state == LV_INDEV_STATE_PR) { +#if LV_INDEV_POINT_MARKER != 0 + lv_area_t area; + area.x1 = i->proc.act_point.x - (LV_INDEV_POINT_MARKER >> 1); + area.y1 = i->proc.act_point.y - (LV_INDEV_POINT_MARKER >> 1); + area.x2 = i->proc.act_point.x + ((LV_INDEV_POINT_MARKER >> 1) | 0x1); + area.y2 = i->proc.act_point.y + ((LV_INDEV_POINT_MARKER >> 1) | 0x1); + lv_rfill(&area, NULL, LV_COLOR_MAKE(0xFF, 0, 0), LV_OPA_COVER); +#endif + indev_proc_press(&i->proc); + } else { + /*If a new point comes always make a release*/ + indev_proc_release(&i->proc); + } + + i->proc.last_point.x = i->proc.act_point.x; + i->proc.last_point.y = i->proc.act_point.y; +} + +/** + * Process the pressed state of LV_INDEV_TYPE_POINER input devices + * @param indev pointer to an input device 'proc' + */ +static void indev_proc_press(lv_indev_proc_t * proc) +{ + lv_obj_t * pr_obj = proc->act_obj; + + if(proc->wait_unil_release != 0) return; + + /*If there is no last object then search*/ + if(proc->act_obj == NULL) { + pr_obj = indev_search_obj(proc, lv_layer_top()); + if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act()); + } + /*If there is last object but it is not dragged and not protected also search*/ + else if(proc->drag_in_prog == 0 && + lv_obj_is_protected(proc->act_obj, LV_PROTECT_PRESS_LOST) == false) {/*Now act_obj != NULL*/ + pr_obj = indev_search_obj(proc, lv_layer_top()); + if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act()); + } + /*If a dragable or a protected object was the last then keep it*/ + else { + + } + + /*If a new object was found reset some variables and send a pressed signal*/ + if(pr_obj != proc->act_obj) { + + proc->last_point.x = proc->act_point.x; + proc->last_point.y = proc->act_point.y; + + /*If a new object found the previous was lost, so send a signal*/ + if(proc->act_obj != NULL) { + proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESS_LOST, indev_act); + if(proc->reset_query != 0) return; + } + + proc->act_obj = pr_obj; /*Save the pressed object*/ + proc->last_obj = proc->act_obj; /*Refresh the last_obj*/ + + if(proc->act_obj != NULL) { + /* Save the time when the obj pressed. + * It is necessary to count the long press time.*/ + proc->pr_timestamp = lv_tick_get(); + proc->long_pr_sent = 0; + proc->drag_range_out = 0; + proc->drag_in_prog = 0; + proc->drag_sum.x = 0; + proc->drag_sum.y = 0; + proc->vect.x = 0; + proc->vect.y = 0; + + /*Search for 'top' attribute*/ + lv_obj_t * i = proc->act_obj; + lv_obj_t * last_top = NULL; + while(i != NULL) { + if(i->top != 0) last_top = i; + i = lv_obj_get_parent(i); + } + + if(last_top != NULL) { + /*Move the last_top object to the foreground*/ + lv_obj_t * par = lv_obj_get_parent(last_top); + /*After list change it will be the new head*/ + lv_ll_chg_list(&par->child_ll, &par->child_ll, last_top); + lv_obj_invalidate(last_top); + } + + /*Send a signal about the press*/ + proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESSED, indev_act); + if(proc->reset_query != 0) return; + } + } + + /*Calculate the vector*/ + proc->vect.x = proc->act_point.x - proc->last_point.x; + proc->vect.y = proc->act_point.y - proc->last_point.y; + + /*If there is active object and it can be dragged run the drag*/ + if(proc->act_obj != NULL) { + proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESSING, indev_act); + if(proc->reset_query != 0) return; + + indev_drag(proc); + if(proc->reset_query != 0) return; + + /*If there is no drag then check for long press time*/ + if(proc->drag_in_prog == 0 && proc->long_pr_sent == 0) { + /*Send a signal about the long press if enough time elapsed*/ + if(lv_tick_elaps(proc->pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) { + pr_obj->signal_func(pr_obj, LV_SIGNAL_LONG_PRESS, indev_act); + if(proc->reset_query != 0) return; + + /*Mark the signal sending to do not send it again*/ + proc->long_pr_sent = 1; + + /*Save the long press time stamp for the long press repeat handler*/ + proc->longpr_rep_timestamp = lv_tick_get(); + } + } + /*Send long press repeated signal*/ + if(proc->drag_in_prog == 0 && proc->long_pr_sent == 1) { + /*Send a signal about the long press repeate if enough time elapsed*/ + if(lv_tick_elaps(proc->longpr_rep_timestamp) > LV_INDEV_LONG_PRESS_REP_TIME) { + pr_obj->signal_func(pr_obj, LV_SIGNAL_LONG_PRESS_REP, indev_act); + if(proc->reset_query != 0) return; + proc->longpr_rep_timestamp = lv_tick_get(); + + } + } + } +} + +/** + * Process the released state of LV_INDEV_TYPE_POINER input devices + * @param proc pointer to an input device 'proc' + */ +static void indev_proc_release(lv_indev_proc_t * proc) +{ + if(proc->wait_unil_release != 0) { + proc->act_obj = NULL; + proc->last_obj = NULL; + proc->pr_timestamp = 0; + proc->longpr_rep_timestamp = 0; + proc->wait_unil_release = 0; + } + + /*Forgot the act obj and send a released signal */ + if(proc->act_obj != NULL) { + /* If the object was protected against press lost then it possible that + * the object is already not pressed but still it is the `act_obj`. + * In this case send the `LV_SIGNAL_RELEASED` if the indev is ON the `act_obj` */ + if(lv_obj_is_protected(proc->act_obj, LV_PROTECT_PRESS_LOST)) { + /* Search the object on the current current coordinates. + * The start object is the object itself. If not ON it the the result will be NULL*/ + lv_obj_t * obj_on = indev_search_obj(proc, proc->act_obj); + if(obj_on == proc->act_obj) proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act); + else proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESS_LOST, indev_act); + + } + /* The simple case: `act_obj` was not protected against press lost. + * If it is already not pressed then was handled in `indev_proc_press`*/ + else { + proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act); + } + + if(proc->reset_query != 0) return; + + /*Handle click focus*/ +#if USE_LV_GROUP + /*Edit mode is not used by POINTER devices. So leave edit mode if we are in it*/ + lv_group_t * act_g = lv_obj_get_group(proc->act_obj); + if(lv_group_get_editing(act_g)) { + lv_group_set_editing(act_g, false); + } + + /*Check, if the parent is in a group focus on it.*/ + if(lv_obj_is_protected(proc->act_obj, LV_PROTECT_CLICK_FOCUS) == false) { /*Respect the click protection*/ + lv_group_t * g = lv_obj_get_group(proc->act_obj); + lv_obj_t * parent = proc->act_obj; + + while(g == NULL) { + parent = lv_obj_get_parent(parent); + if(parent == NULL) break; + if(lv_obj_is_protected(parent, LV_PROTECT_CLICK_FOCUS)) { /*Ignore is the protected against click focus*/ + parent = NULL; + break; + } + g = lv_obj_get_group(parent); + } + + if(g != NULL && parent != NULL) + if(lv_group_get_click_focus(g)) { + lv_group_focus_obj(parent); + } + } +#endif + + if(proc->reset_query != 0) return; + proc->act_obj = NULL; + proc->pr_timestamp = 0; + proc->longpr_rep_timestamp = 0; + } + + /*The reset can be set in the signal function. + * In case of reset query ignore the remaining parts.*/ + if(proc->last_obj != NULL && proc->reset_query == 0) { + indev_drag_throw(proc); + if(proc->reset_query != 0) return; + } +} + +/** + * Process a new point from LV_INDEV_TYPE_BUTTON input device + * @param i pointer to an input device + * @param data pointer to the data read from the input device + * Reset input device if a reset query has been sent to it + * @param indev pointer to an input device + */ +static void indev_proc_reset_query_handler(lv_indev_t * indev) +{ + if(indev->proc.reset_query) { + indev->proc.act_obj = NULL; + indev->proc.last_obj = NULL; + indev->proc.drag_range_out = 0; + indev->proc.drag_in_prog = 0; + indev->proc.long_pr_sent = 0; + indev->proc.pr_timestamp = 0; + indev->proc.longpr_rep_timestamp = 0; + indev->proc.drag_sum.x = 0; + indev->proc.drag_sum.y = 0; + indev->proc.reset_query = 0; + } +} +/** + * Search the most top, clickable object on the last point of an input device + * @param proc pointer to the `lv_indev_proc_t` part of the input device + * @param obj pointer to a start object, typically the screen + * @return pointer to the found object or NULL if there was no suitable object + */ +static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj) +{ + lv_obj_t * found_p = NULL; + + /*If the point is on this object*/ + /*Check its children too*/ + if(lv_area_is_point_on(&obj->coords, &proc->act_point)) { + lv_obj_t * i; + + LL_READ(obj->child_ll, i) { + found_p = indev_search_obj(proc, i); + + /*If a child was found then break*/ + if(found_p != NULL) { + break; + } + } + + /*If then the children was not ok, and this obj is clickable + * and it or its parent is not hidden then save this object*/ + if(found_p == NULL && lv_obj_get_click(obj) != false) { + lv_obj_t * hidden_i = obj; + while(hidden_i != NULL) { + if(lv_obj_get_hidden(hidden_i) == true) break; + hidden_i = lv_obj_get_parent(hidden_i); + } + /*No parent found with hidden == true*/ + if(hidden_i == NULL) found_p = obj; + } + + } + + return found_p; +} + +/** + * Handle the dragging of indev_proc_p->act_obj + * @param indev pointer to a input device state + */ +static void indev_drag(lv_indev_proc_t * state) +{ + lv_obj_t * drag_obj = state->act_obj; + + /*If drag parent is active check recursively the drag_parent attribute*/ + while(lv_obj_get_drag_parent(drag_obj) != false && + drag_obj != NULL) { + drag_obj = lv_obj_get_parent(drag_obj); + } + + if(drag_obj == NULL) return; + + if(lv_obj_get_drag(drag_obj) == false) return; + + /*Count the movement by drag*/ + state->drag_sum.x += state->vect.x; + state->drag_sum.y += state->vect.y; + + /*Enough move?*/ + if(state->drag_range_out == 0) { + /*If a move is greater then LV_DRAG_LIMIT then begin the drag*/ + if(LV_MATH_ABS(state->drag_sum.x) >= LV_INDEV_DRAG_LIMIT || + LV_MATH_ABS(state->drag_sum.y) >= LV_INDEV_DRAG_LIMIT) { + state->drag_range_out = 1; + } + } + + /*If the drag limit is stepped over then handle the dragging*/ + if(state->drag_range_out != 0) { + /*Set new position if the vector is not zero*/ + if(state->vect.x != 0 || + state->vect.y != 0) { + /*Get the coordinates of the object and modify them*/ + lv_coord_t act_x = lv_obj_get_x(drag_obj); + lv_coord_t act_y = lv_obj_get_y(drag_obj); + uint16_t inv_buf_size = lv_refr_get_buf_size(); /*Get the number of currently invalidated areas*/ + + lv_coord_t prev_x = drag_obj->coords.x1; + lv_coord_t prev_y = drag_obj->coords.y1; + lv_coord_t prev_par_w = lv_obj_get_width(lv_obj_get_parent(drag_obj)); + lv_coord_t prev_par_h = lv_obj_get_height(lv_obj_get_parent(drag_obj)); + + lv_obj_set_pos(drag_obj, act_x + state->vect.x, act_y + state->vect.y); + + /*Set the drag in progress flag if the object is really moved*/ + + if(drag_obj->coords.x1 != prev_x || drag_obj->coords.y1 != prev_y) { + if(state->drag_range_out != 0) { /*Send the drag begin signal on first move*/ + drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_BEGIN, indev_act); + if(state->reset_query != 0) return; + } + state->drag_in_prog = 1; + } + /*If the object didn't moved then clear the invalidated areas*/ + else { + /*In a special case if the object is moved on a page and + * the scrollable has fit == true and the object is dragged of the page then + * while its coordinate is not changing only the parent's size is reduced */ + lv_coord_t act_par_w = lv_obj_get_width(lv_obj_get_parent(drag_obj)); + lv_coord_t act_par_h = lv_obj_get_height(lv_obj_get_parent(drag_obj)); + if(act_par_w == prev_par_w && act_par_h == prev_par_h) { + uint16_t new_inv_buf_size = lv_refr_get_buf_size(); + lv_refr_pop_from_buf(new_inv_buf_size - inv_buf_size); + } + } + } + } +} + +/** + * Handle throwing by drag if the drag is ended + * @param indev pointer to an input device state + */ +static void indev_drag_throw(lv_indev_proc_t * state) +{ + if(state->drag_in_prog == 0) return; + + /*Set new position if the vector is not zero*/ + lv_obj_t * drag_obj = state->last_obj; + + /*If drag parent is active check recursively the drag_parent attribute*/ + while(lv_obj_get_drag_parent(drag_obj) != false && + drag_obj != NULL) { + drag_obj = lv_obj_get_parent(drag_obj); + } + + if(drag_obj == NULL) return; + + /*Return if the drag throw is not enabled*/ + if(lv_obj_get_drag_throw(drag_obj) == false) { + state->drag_in_prog = 0; + drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act); + return; + } + + /*Reduce the vectors*/ + state->vect.x = state->vect.x * (100 - LV_INDEV_DRAG_THROW) / 100; + state->vect.y = state->vect.y * (100 - LV_INDEV_DRAG_THROW) / 100; + + if(state->vect.x != 0 || + state->vect.y != 0) { + /*Get the coordinates and modify them*/ + lv_area_t coords_ori; + lv_obj_get_coords(drag_obj, &coords_ori); + lv_coord_t act_x = lv_obj_get_x(drag_obj) + state->vect.x; + lv_coord_t act_y = lv_obj_get_y(drag_obj) + state->vect.y; + lv_obj_set_pos(drag_obj, act_x, act_y); + + lv_area_t coord_new; + lv_obj_get_coords(drag_obj, &coord_new); + + /*If non of the coordinates are changed then do not continue throwing*/ + if((coords_ori.x1 == coord_new.x1 || state->vect.x == 0) && + (coords_ori.y1 == coord_new.y1 || state->vect.y == 0)) { + state->drag_in_prog = 0; + state->vect.x = 0; + state->vect.y = 0; + drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act); + + } + } + /*If the vectors become 0 -> drag_in_prog = 0 and send a drag end signal*/ + else { + state->drag_in_prog = 0; + drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act); + } +} +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.h b/nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.h new file mode 100644 index 0000000..19b047c --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_indev.h @@ -0,0 +1,157 @@ +/** + * @file lv_indev_proc.h + * + */ + +#ifndef LV_INDEV_H +#define LV_INDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" +#include "../lv_hal/lv_hal_indev.h" +#include "../lv_core/lv_group.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the display input device subsystem + */ +void lv_indev_init(void); + +/** + * Get the currently processed input device. Can be used in action functions too. + * @return pointer to the currently processed input device or NULL if no input device processing right now + */ +lv_indev_t * lv_indev_get_act(void); + + +/** + * Get the type of an input device + * @param indev pointer to an input device + * @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`) + */ +lv_hal_indev_type_t lv_indev_get_type(const lv_indev_t * indev); + +/** + * Reset one or all input devices + * @param indev pointer to an input device to reset or NULL to reset all of them + */ +void lv_indev_reset(lv_indev_t * indev); + +/** + * Reset the long press state of an input device + * @param indev_proc pointer to an input device + */ +void lv_indev_reset_lpr(lv_indev_t * indev); + +/** + * Enable input devices device by type + * @param type Input device type + * @param enable true: enable this type; false: disable this type + */ +void lv_indev_enable(lv_hal_indev_type_t type, bool enable); + +/** + * Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON) + * @param indev pointer to an input device + * @param cur_obj pointer to an object to be used as cursor + */ +void lv_indev_set_cursor(lv_indev_t *indev, lv_obj_t *cur_obj); + +#if USE_LV_GROUP +/** + * Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD) + * @param indev pointer to an input device + * @param group point to a group + */ +void lv_indev_set_group(lv_indev_t *indev, lv_group_t *group); +#endif + +/** + * Set the an array of points for LV_INDEV_TYPE_BUTTON. + * These points will be assigned to the buttons to press a specific point on the screen + * @param indev pointer to an input device + * @param group point to a group + */ +void lv_indev_set_button_points(lv_indev_t *indev, const lv_point_t *points); + +/** + * Set feedback callback for indev. + * @param indev pointer to an input device + * @param feedback feedback callback + */ +void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback); + +/** + * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @param point pointer to a point to store the result + */ +void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point); + +/** + * Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD) + * @param indev pointer to an input device + * @return the last pressed key (0 on error) + */ +uint32_t lv_indev_get_key(const lv_indev_t * indev); + +/** + * Check if there is dragging with an input device or not (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @return true: drag is in progress + */ +bool lv_indev_is_dragging(const lv_indev_t * indev); + +/** + * Get the vector of dragging of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @param point pointer to a point to store the vector + */ +void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point); +/** + * Get elapsed time since last press + * @param indev pointer to an input device (NULL to get the overall smallest inactivity) + * @return Elapsed ticks (milliseconds) since last press + */ +uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev); + +/** + * Get feedback callback for indev. + * @param indev pointer to an input device + * @return feedback callback + */ +lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev); + +/** + * Do nothing until the next release + * @param indev pointer to an input device + */ +void lv_indev_wait_release(lv_indev_t * indev); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_INDEV_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.c b/nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.c new file mode 100644 index 0000000..c96ed78 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.c @@ -0,0 +1,117 @@ +/** + * @file lv_lang.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_lang.h" +#if USE_LV_MULTI_LANG + +#include "lv_obj.h" +#include "../lv_misc/lv_gc.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void lang_set_core(lv_obj_t * obj); + +/********************** + * STATIC VARIABLES + **********************/ +static uint8_t lang_act = 0; +static const void * (*get_txt)(uint16_t); + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Change the language + * @param lang_id the id of the + */ +void lv_lang_set(uint8_t lang_id) +{ + lang_act = lang_id; + + lv_obj_t * i; + LL_READ(LV_GC_ROOT(_lv_scr_ll), i) { + i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL); + + lang_set_core(i); + } + + lang_set_core(lv_scr_act()); +} + +/** + * Set a function to get the texts of the set languages from a `txt_id` + * @param fp a function pointer to get the texts + */ +void lv_lang_set_text_func(const void * (*fp)(uint16_t)) +{ + get_txt = fp; +} + +/** + * Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language + * @param txt_id an ID of the text to get + * @return the `txt_id` txt on the set language + */ +const void * lv_lang_get_text(uint16_t txt_id) +{ + if(get_txt == NULL) { + LV_LOG_WARN("lv_lang_get_text: text_func is not specified"); + return NULL; /*No text_get function specified */ + } + if(txt_id == LV_LANG_TXT_ID_NONE) { + LV_LOG_WARN("lv_lang_get_text: attempts to get invalid text ID"); + return NULL; /*Invalid txt_id*/ + } + + return get_txt(txt_id); +} + + +/** + * Return with ID of the currently selected language + * @return pointer to the active screen object (loaded by 'lv_scr_load()') + */ +uint8_t lv_lang_act(void) +{ + return lang_act; +} + + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Change the language of the children. (Called recursively) + * @param obj pointer to an object + */ +static void lang_set_core(lv_obj_t * obj) +{ + lv_obj_t * i; + LL_READ(obj->child_ll, i) { + i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL); + + lang_set_core(i); + } +} + +#endif /*USE_LV_MULTI_LANG*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.h b/nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.h new file mode 100644 index 0000000..5d76f64 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_lang.h @@ -0,0 +1,74 @@ +/** + * @file lv_lang.h + * + */ + +#ifndef LV_LANG_H +#define LV_LANG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_MULTI_LANG + +#include + +/********************* + * DEFINES + *********************/ +#define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Change the language + * @param lang_id the id of the + */ +void lv_lang_set(uint8_t lang_id); + +/** + * Set a function to get the texts of the set languages from a `txt_id` + * @param fp a function pointer to get the texts + */ +void lv_lang_set_text_func(const void * (*fp)(uint16_t)); + +/** + * Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language + * @param txt_id an ID of the text to get + * @return the `txt_id` txt on the set language + */ +const void * lv_lang_get_text(uint16_t txt_id); + +/** + * Return with ID of the currently selected language + * @return pointer to the active screen object (loaded by 'lv_scr_load()') + */ +uint8_t lv_lang_act(void); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_MULTI_LANG*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_LANG_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.c b/nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.c new file mode 100644 index 0000000..07407ae --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.c @@ -0,0 +1,1986 @@ +/** + * @file lv_base_obj.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" +#include "lv_indev.h" +#include "lv_refr.h" +#include "lv_group.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_draw/lv_draw.h" +#include "../lv_draw/lv_draw_rbasic.h" +#include "../lv_misc/lv_anim.h" +#include "../lv_misc/lv_task.h" +#include "../lv_misc/lv_fs.h" +#include "../lv_misc/lv_ufs.h" +#include +#include +#include "../lv_misc/lv_gc.h" + +#if defined(LV_GC_INCLUDE) +# include LV_GC_INCLUDE +#endif /* LV_ENABLE_GC */ + +/********************* + * DEFINES + *********************/ +#define LV_OBJ_DEF_WIDTH (LV_DPI) +#define LV_OBJ_DEF_HEIGHT (2 * LV_DPI / 3) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff); +static void report_style_mod_core(void * style_p, lv_obj_t * obj); +static void refresh_children_style(lv_obj_t * obj); +static void delete_children(lv_obj_t * obj); +static bool lv_obj_design(lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode); +static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ + +static bool _lv_initialized = false; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Init. the 'lv' library. + */ +void lv_init(void) +{ + /* Do nothing if already initialized */ + if (_lv_initialized) + return; + + LV_GC_ROOT(_lv_def_scr) = NULL; + LV_GC_ROOT(_lv_act_scr) = NULL; + LV_GC_ROOT(_lv_top_layer) = NULL; + LV_GC_ROOT(_lv_sys_layer) = NULL; + LV_GC_ROOT(_lv_disp_list) = NULL; + LV_GC_ROOT(_lv_indev_list) = NULL; + + LV_LOG_TRACE("lv_init started"); + + /*Initialize the lv_misc modules*/ + lv_mem_init(); + lv_task_init(); + +#if USE_LV_FILESYSTEM + lv_fs_init(); + lv_ufs_init(); +#endif + + lv_font_init(); +#if USE_LV_ANIMATION + lv_anim_init(); +#endif + + /*Init. the sstyles*/ + lv_style_init(); + + /*Initialize the screen refresh system*/ + lv_refr_init(); + + /*Create the default screen*/ + lv_ll_init(&LV_GC_ROOT(_lv_scr_ll), sizeof(lv_obj_t)); + LV_GC_ROOT(_lv_def_scr) = lv_obj_create(NULL, NULL); + + LV_GC_ROOT(_lv_act_scr) = LV_GC_ROOT(_lv_def_scr); + + LV_GC_ROOT(_lv_top_layer) = lv_obj_create(NULL, NULL); + lv_obj_set_style(LV_GC_ROOT(_lv_top_layer), &lv_style_transp_fit); + + LV_GC_ROOT(_lv_sys_layer) = lv_obj_create(NULL, NULL); + lv_obj_set_style(LV_GC_ROOT(_lv_sys_layer), &lv_style_transp_fit); + + /*Refresh the screen*/ + lv_obj_invalidate(LV_GC_ROOT(_lv_act_scr)); + +#if LV_INDEV_READ_PERIOD != 0 + /*Init the input device handling*/ + lv_indev_init(); +#endif + + _lv_initialized = true; + LV_LOG_INFO("lv_init ready"); +} + +/*-------------------- + * Create and delete + *-------------------*/ + +/** + * Create a basic object + * @param parent pointer to a parent object. + * If NULL then a screen will be created + * @param copy pointer to a base object, if not NULL then the new object will be copied from it + * @return pointer to the new object + */ +lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) +{ + + lv_obj_t * new_obj = NULL; + /*Create a screen if the parent is NULL*/ + if(parent == NULL) { + LV_LOG_TRACE("Screen create started"); + + new_obj = lv_ll_ins_head(&LV_GC_ROOT(_lv_scr_ll)); + lv_mem_assert(new_obj); + if(new_obj == NULL) return NULL; + + new_obj->par = NULL; /*Screens has no a parent*/ + lv_ll_init(&(new_obj->child_ll), sizeof(lv_obj_t)); + + /*Set coordinates to full screen size*/ + new_obj->coords.x1 = 0; + new_obj->coords.y1 = 0; + new_obj->coords.x2 = LV_HOR_RES - 1; + new_obj->coords.y2 = LV_VER_RES - 1; + new_obj->ext_size = 0; + + /*Init realign*/ +#if LV_OBJ_REALIGN + new_obj->realign.align = LV_ALIGN_CENTER; + new_obj->realign.xofs = 0; + new_obj->realign.yofs = 0; + new_obj->realign.base = NULL; + new_obj->realign.auto_realign = 0; +#endif + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + new_obj->style_p = th->bg; + } else { + new_obj->style_p = &lv_style_scr; + } + /*Set virtual functions*/ + lv_obj_set_signal_func(new_obj, lv_obj_signal); + lv_obj_set_design_func(new_obj, lv_obj_design); + + /*Set free data*/ +#ifdef LV_OBJ_FREE_NUM_TYPE + new_obj->free_num = 0; +#endif + +#if LV_OBJ_FREE_PTR != 0 + new_obj->free_ptr = NULL; +#endif + +#if USE_LV_GROUP + new_obj->group_p = NULL; +#endif + /*Set attributes*/ + new_obj->click = 0; + new_obj->drag = 0; + new_obj->drag_throw = 0; + new_obj->drag_parent = 0; + new_obj->hidden = 0; + new_obj->top = 0; + new_obj->opa_scale_en = 0; + new_obj->protect = LV_PROTECT_NONE; + new_obj->opa_scale = LV_OPA_COVER; + + new_obj->ext_attr = NULL; + + LV_LOG_INFO("Screen create ready"); + } + /*parent != NULL create normal obj. on a parent*/ + else { + LV_LOG_TRACE("Object create started"); + + new_obj = lv_ll_ins_head(&(parent)->child_ll); + lv_mem_assert(new_obj); + if(new_obj == NULL) return NULL; + + + new_obj->par = parent; /*Set the parent*/ + lv_ll_init(&(new_obj->child_ll), sizeof(lv_obj_t)); + + /*Set coordinates left top corner of parent*/ + new_obj->coords.x1 = parent->coords.x1; + new_obj->coords.y1 = parent->coords.y1; + new_obj->coords.x2 = parent->coords.x1 + + LV_OBJ_DEF_WIDTH; + new_obj->coords.y2 = parent->coords.y1 + + LV_OBJ_DEF_HEIGHT; + new_obj->ext_size = 0; + + /*Init realign*/ +#if LV_OBJ_REALIGN + new_obj->realign.align = LV_ALIGN_CENTER; + new_obj->realign.xofs = 0; + new_obj->realign.yofs = 0; + new_obj->realign.base = NULL; + new_obj->realign.auto_realign = 0; +#endif + /*Set appearance*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + new_obj->style_p = th->panel; + } else { + new_obj->style_p = &lv_style_plain_color; + } + + /*Set virtual functions*/ + lv_obj_set_signal_func(new_obj, lv_obj_signal); + lv_obj_set_design_func(new_obj, lv_obj_design); + + /*Set free data*/ +#ifdef LV_OBJ_FREE_NUM_TYPE + new_obj->free_num = 0; +#endif +#if LV_OBJ_FREE_PTR != 0 + new_obj->free_ptr = NULL; +#endif +#if USE_LV_GROUP + new_obj->group_p = NULL; +#endif + + /*Set attributes*/ + new_obj->click = 1; + new_obj->drag = 0; + new_obj->drag_throw = 0; + new_obj->drag_parent = 0; + new_obj->hidden = 0; + new_obj->top = 0; + new_obj->protect = LV_PROTECT_NONE; + new_obj->opa_scale = LV_OPA_COVER; + new_obj->opa_scale_en = 0; + + new_obj->ext_attr = NULL; + } + + if(copy != NULL) { + lv_area_copy(&new_obj->coords, ©->coords); + new_obj->ext_size = copy->ext_size; + + /*Set free data*/ +#ifdef LV_OBJ_FREE_NUM_TYPE + new_obj->free_num = copy->free_num; +#endif +#if LV_OBJ_FREE_PTR != 0 + new_obj->free_ptr = copy->free_ptr; +#endif + + /*Copy realign*/ +#if LV_OBJ_REALIGN + new_obj->realign.align = copy->realign.align; + new_obj->realign.xofs = copy->realign.xofs; + new_obj->realign.yofs = copy->realign.yofs; + new_obj->realign.base = copy->realign.base; + new_obj->realign.auto_realign = copy->realign.auto_realign; +#endif + + /*Set attributes*/ + new_obj->click = copy->click; + new_obj->drag = copy->drag; + new_obj->drag_throw = copy->drag_throw; + new_obj->drag_parent = copy->drag_parent; + new_obj->hidden = copy->hidden; + new_obj->top = copy->top; + + new_obj->opa_scale_en = copy->opa_scale_en; + new_obj->protect = copy->protect; + new_obj->opa_scale = copy->opa_scale; + + new_obj->style_p = copy->style_p; + +#if USE_LV_GROUP + /*Add to the same group*/ + if(copy->group_p != NULL) { + lv_group_add_obj(copy->group_p, new_obj); + } +#endif + + /*Set the same coordinates for non screen objects*/ + if(lv_obj_get_parent(copy) != NULL && parent != NULL) { + lv_obj_set_pos(new_obj, lv_obj_get_x(copy), lv_obj_get_y(copy)); + } else { + lv_obj_set_pos(new_obj, 0, 0); + } + + LV_LOG_INFO("Object create ready"); + } + + + /*Send a signal to the parent to notify it about the new child*/ + if(parent != NULL) { + parent->signal_func(parent, LV_SIGNAL_CHILD_CHG, new_obj); + + /*Invalidate the area if not screen created*/ + lv_obj_invalidate(new_obj); + } + + return new_obj; +} + +/** + * Delete 'obj' and all of its children + * @param obj pointer to an object to delete + * @return LV_RES_INV because the object is deleted + */ +lv_res_t lv_obj_del(lv_obj_t * obj) +{ + lv_obj_invalidate(obj); + + /*Delete from the group*/ +#if USE_LV_GROUP + if(obj->group_p != NULL) lv_group_remove_obj(obj); +#endif + + /*Remove the animations from this object*/ +#if USE_LV_ANIMATION + lv_anim_del(obj, NULL); +#endif + + /*Recursively delete the children*/ + lv_obj_t * i; + lv_obj_t * i_next; + i = lv_ll_get_head(&(obj->child_ll)); + while(i != NULL) { + /*Get the next object before delete this*/ + i_next = lv_ll_get_next(&(obj->child_ll), i); + + /*Call the recursive del to the child too*/ + delete_children(i); + + /*Set i to the next node*/ + i = i_next; + } + + /*Remove the object from parent's children list*/ + lv_obj_t * par = lv_obj_get_parent(obj); + if(par == NULL) { /*It is a screen*/ + lv_ll_rem(&LV_GC_ROOT(_lv_scr_ll), obj); + } else { + lv_ll_rem(&(par->child_ll), obj); + } + + /* Reset all input devices if + * the currently pressed object is deleted*/ + lv_indev_t * indev = lv_indev_next(NULL); + while(indev) { + if(indev->proc.act_obj == obj || indev->proc.last_obj == obj) { + lv_indev_reset(indev); + } + indev = lv_indev_next(indev); + } + + /* All children deleted. + * Now clean up the object specific data*/ + obj->signal_func(obj, LV_SIGNAL_CLEANUP, NULL); + + /*Delete the base objects*/ + if(obj->ext_attr != NULL) lv_mem_free(obj->ext_attr); + lv_mem_free(obj); /*Free the object itself*/ + + /*Send a signal to the parent to notify it about the child delete*/ + if(par != NULL) { + par->signal_func(par, LV_SIGNAL_CHILD_CHG, NULL); + } + + return LV_RES_INV; +} + +/** + * Delete all children of an object + * @param obj pointer to an object + */ +void lv_obj_clean(lv_obj_t * obj) +{ + lv_obj_t * child = lv_obj_get_child(obj, NULL); + lv_obj_t * child_next; + while(child) { + /* Read the next child before deleting the current + * because the next couldn't be read from a deleted (invalid) node*/ + child_next = lv_obj_get_child(obj, child); + lv_obj_del(child); + child = child_next; + } +} + +/** + * Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task' + * @param obj pointer to an object + */ +void lv_obj_invalidate(const lv_obj_t * obj) +{ + if(lv_obj_get_hidden(obj)) return; + + /*Invalidate the object only if it belongs to the 'LV_GC_ROOT(_lv_act_scr)'*/ + lv_obj_t * obj_scr = lv_obj_get_screen(obj); + if(obj_scr == lv_scr_act() || + obj_scr == lv_layer_top() || + obj_scr == lv_layer_sys()) { + /*Truncate recursively to the parents*/ + lv_area_t area_trunc; + lv_obj_t * par = lv_obj_get_parent(obj); + bool union_ok = true; + /*Start with the original coordinates*/ + lv_coord_t ext_size = obj->ext_size; + lv_area_copy(&area_trunc, &obj->coords); + area_trunc.x1 -= ext_size; + area_trunc.y1 -= ext_size; + area_trunc.x2 += ext_size; + area_trunc.y2 += ext_size; + + /*Check through all parents*/ + while(par != NULL) { + union_ok = lv_area_intersect(&area_trunc, &area_trunc, &par->coords); + if(union_ok == false) break; /*If no common parts with parent break;*/ + if(lv_obj_get_hidden(par)) return; /*If the parent is hidden then the child is hidden and won't be drawn*/ + + par = lv_obj_get_parent(par); + } + + if(union_ok != false) lv_inv_area(&area_trunc); + } +} + + +/*===================== + * Setter functions + *====================*/ + +/*-------------- + * Screen set + *--------------*/ + +/** + * Load a new screen + * @param scr pointer to a screen + */ +void lv_scr_load(lv_obj_t * scr) +{ + LV_GC_ROOT(_lv_act_scr) = scr; + + lv_obj_invalidate(LV_GC_ROOT(_lv_act_scr)); +} + +/*-------------------- + * Parent/children set + *--------------------*/ + +/** + * Set a new parent for an object. Its relative position will be the same. + * @param obj pointer to an object. Can't be a screen. + * @param parent pointer to the new parent object. (Can't be NULL) + */ +void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent) +{ + if(obj->par == NULL) { + LV_LOG_WARN("Can't set the parent of a screen"); + return; + } + + if(parent == NULL) { + LV_LOG_WARN("Can't set parent == NULL to an object"); + return; + } + + + lv_obj_invalidate(obj); + + lv_point_t old_pos; + old_pos.x = lv_obj_get_x(obj); + old_pos.y = lv_obj_get_y(obj); + + lv_obj_t * old_par = obj->par; + + lv_ll_chg_list(&obj->par->child_ll, &parent->child_ll, obj); + obj->par = parent; + lv_obj_set_pos(obj, old_pos.x, old_pos.y); + + /*Notify the original parent because one of its children is lost*/ + old_par->signal_func(old_par, LV_SIGNAL_CHILD_CHG, NULL); + + /*Notify the new parent about the child*/ + parent->signal_func(parent, LV_SIGNAL_CHILD_CHG, obj); + + lv_obj_invalidate(obj); +} + +/*-------------------- + * Coordinate set + * ------------------*/ + +/** + * Set relative the position of an object (relative to the parent) + * @param obj pointer to an object + * @param x new distance from the left side of the parent + * @param y new distance from the top of the parent + */ +void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) +{ + /*Convert x and y to absolute coordinates*/ + lv_obj_t * par = obj->par; + x = x + par->coords.x1; + y = y + par->coords.y1; + + /*Calculate and set the movement*/ + lv_point_t diff; + diff.x = x - obj->coords.x1; + diff.y = y - obj->coords.y1; + + /* Do nothing if the position is not changed */ + /* It is very important else recursive positioning can + * occur without position change*/ + if(diff.x == 0 && diff.y == 0) return; + + /*Invalidate the original area*/ + lv_obj_invalidate(obj); + + /*Save the original coordinates*/ + lv_area_t ori; + lv_obj_get_coords(obj, &ori); + + obj->coords.x1 += diff.x; + obj->coords.y1 += diff.y; + obj->coords.x2 += diff.x; + obj->coords.y2 += diff.y; + + refresh_children_position(obj, diff.x, diff.y); + + /*Inform the object about its new coordinates*/ + obj->signal_func(obj, LV_SIGNAL_CORD_CHG, &ori); + + /*Send a signal to the parent too*/ + par->signal_func(par, LV_SIGNAL_CHILD_CHG, obj); + + /*Invalidate the new area*/ + lv_obj_invalidate(obj); +} + + +/** + * Set the x coordinate of a object + * @param obj pointer to an object + * @param x new distance from the left side from the parent + */ +void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x) +{ + lv_obj_set_pos(obj, x, lv_obj_get_y(obj)); +} + + +/** + * Set the y coordinate of a object + * @param obj pointer to an object + * @param y new distance from the top of the parent + */ +void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y) +{ + lv_obj_set_pos(obj, lv_obj_get_x(obj), y); +} + +/** + * Set the size of an object + * @param obj pointer to an object + * @param w new width + * @param h new height + */ +void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) +{ + + /* Do nothing if the size is not changed */ + /* It is very important else recursive resizing can + * occur without size change*/ + if(lv_obj_get_width(obj) == w && lv_obj_get_height(obj) == h) { + return; + } + + /*Invalidate the original area*/ + lv_obj_invalidate(obj); + + /*Save the original coordinates*/ + lv_area_t ori; + lv_obj_get_coords(obj, &ori); + + //Set the length and height + obj->coords.x2 = obj->coords.x1 + w - 1; + obj->coords.y2 = obj->coords.y1 + h - 1; + + + /*Send a signal to the object with its new coordinates*/ + obj->signal_func(obj, LV_SIGNAL_CORD_CHG, &ori); + + /*Send a signal to the parent too*/ + lv_obj_t * par = lv_obj_get_parent(obj); + if(par != NULL) par->signal_func(par, LV_SIGNAL_CHILD_CHG, obj); + + /*Invalidate the new area*/ + lv_obj_invalidate(obj); + + /*Automatically realign the object if required*/ +#if LV_OBJ_REALIGN + if(obj->realign.auto_realign) lv_obj_realign(obj); +#endif +} + +/** + * Set the width of an object + * @param obj pointer to an object + * @param w new width + */ +void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w) +{ + lv_obj_set_size(obj, w, lv_obj_get_height(obj)); +} + +/** + * Set the height of an object + * @param obj pointer to an object + * @param h new height + */ +void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h) +{ + lv_obj_set_size(obj, lv_obj_get_width(obj), h); +} + +/** + * Align an object to an other object. + * @param obj pointer to an object to align + * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. + * @param align type of alignment (see 'lv_align_t' enum) + * @param x_mod x coordinate shift after alignment + * @param y_mod y coordinate shift after alignment + */ +void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod) +{ + lv_coord_t new_x = lv_obj_get_x(obj); + lv_coord_t new_y = lv_obj_get_y(obj); + + if(base == NULL) { + base = lv_obj_get_parent(obj); + } + + switch(align) { + case LV_ALIGN_CENTER: + new_x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + new_y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; + break; + + case LV_ALIGN_IN_TOP_LEFT: + new_x = 0; + new_y = 0; + break; + case LV_ALIGN_IN_TOP_MID: + new_x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + new_y = 0; + break; + + case LV_ALIGN_IN_TOP_RIGHT: + new_x = lv_obj_get_width(base) - lv_obj_get_width(obj); + new_y = 0; + break; + + case LV_ALIGN_IN_BOTTOM_LEFT: + new_x = 0; + new_y = lv_obj_get_height(base) - lv_obj_get_height(obj); + break; + case LV_ALIGN_IN_BOTTOM_MID: + new_x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + new_y = lv_obj_get_height(base) - lv_obj_get_height(obj); + break; + + case LV_ALIGN_IN_BOTTOM_RIGHT: + new_x = lv_obj_get_width(base) - lv_obj_get_width(obj); + new_y = lv_obj_get_height(base) - lv_obj_get_height(obj); + break; + + case LV_ALIGN_IN_LEFT_MID: + new_x = 0; + new_y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; + break; + + case LV_ALIGN_IN_RIGHT_MID: + new_x = lv_obj_get_width(base) - lv_obj_get_width(obj); + new_y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; + break; + + case LV_ALIGN_OUT_TOP_LEFT: + new_x = 0; + new_y = -lv_obj_get_height(obj); + break; + + case LV_ALIGN_OUT_TOP_MID: + new_x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + new_y = - lv_obj_get_height(obj); + break; + + case LV_ALIGN_OUT_TOP_RIGHT: + new_x = lv_obj_get_width(base) - lv_obj_get_width(obj); + new_y = - lv_obj_get_height(obj); + break; + + case LV_ALIGN_OUT_BOTTOM_LEFT: + new_x = 0; + new_y = lv_obj_get_height(base); + break; + + case LV_ALIGN_OUT_BOTTOM_MID: + new_x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + new_y = lv_obj_get_height(base); + break; + + case LV_ALIGN_OUT_BOTTOM_RIGHT: + new_x = lv_obj_get_width(base) - lv_obj_get_width(obj); + new_y = lv_obj_get_height(base); + break; + + case LV_ALIGN_OUT_LEFT_TOP: + new_x = - lv_obj_get_width(obj); + new_y = 0; + break; + + case LV_ALIGN_OUT_LEFT_MID: + new_x = - lv_obj_get_width(obj); + new_y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; + break; + + case LV_ALIGN_OUT_LEFT_BOTTOM: + new_x = - lv_obj_get_width(obj); + new_y = lv_obj_get_height(base) - lv_obj_get_height(obj); + break; + + case LV_ALIGN_OUT_RIGHT_TOP: + new_x = lv_obj_get_width(base); + new_y = 0; + break; + + case LV_ALIGN_OUT_RIGHT_MID: + new_x = lv_obj_get_width(base); + new_y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; + break; + + case LV_ALIGN_OUT_RIGHT_BOTTOM: + new_x = lv_obj_get_width(base); + new_y = lv_obj_get_height(base) - lv_obj_get_height(obj); + break; + } + + /*Bring together the coordination system of base and obj*/ + lv_obj_t * par = lv_obj_get_parent(obj); + lv_coord_t base_abs_x = base->coords.x1; + lv_coord_t base_abs_y = base->coords.y1; + lv_coord_t par_abs_x = par->coords.x1; + lv_coord_t par_abs_y = par->coords.y1; + new_x += x_mod + base_abs_x; + new_y += y_mod + base_abs_y; + new_x -= par_abs_x; + new_y -= par_abs_y; + + lv_obj_set_pos(obj, new_x, new_y); + +#if LV_OBJ_REALIGN + /*Save the last align parameters to use them in `lv_obj_realign`*/ + obj->realign.align = align; + obj->realign.xofs = x_mod; + obj->realign.yofs = y_mod; + obj->realign.base = base; + obj->realign.origo_align = 0; +#endif +} + +/** + * Align an object to an other object. + * @param obj pointer to an object to align + * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. + * @param align type of alignment (see 'lv_align_t' enum) + * @param x_mod x coordinate shift after alignment + * @param y_mod y coordinate shift after alignment + */ +void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod) +{ + lv_coord_t new_x = lv_obj_get_x(obj); + lv_coord_t new_y = lv_obj_get_y(obj); + + lv_coord_t obj_w_half = lv_obj_get_width(obj) / 2; + lv_coord_t obj_h_half = lv_obj_get_height(obj) / 2; + + if(base == NULL) { + base = lv_obj_get_parent(obj); + } + + switch(align) { + case LV_ALIGN_CENTER: + new_x = lv_obj_get_width(base) / 2 - obj_w_half; + new_y = lv_obj_get_height(base) / 2 - obj_h_half; + break; + + case LV_ALIGN_IN_TOP_LEFT: + new_x = -obj_w_half; + new_y = -obj_h_half; + break; + case LV_ALIGN_IN_TOP_MID: + new_x = lv_obj_get_width(base) / 2 - obj_w_half; + new_y = -obj_h_half; + break; + + case LV_ALIGN_IN_TOP_RIGHT: + new_x = lv_obj_get_width(base) - obj_w_half; + new_y = -obj_h_half; + break; + + case LV_ALIGN_IN_BOTTOM_LEFT: + new_x = -obj_w_half; + new_y = lv_obj_get_height(base) - obj_h_half; + break; + case LV_ALIGN_IN_BOTTOM_MID: + new_x = lv_obj_get_width(base) / 2 - obj_w_half; + new_y = lv_obj_get_height(base) - obj_h_half; + break; + + case LV_ALIGN_IN_BOTTOM_RIGHT: + new_x = lv_obj_get_width(base) - obj_w_half; + new_y = lv_obj_get_height(base) - obj_h_half; + break; + + case LV_ALIGN_IN_LEFT_MID: + new_x = -obj_w_half; + new_y = lv_obj_get_height(base) / 2 - obj_h_half; + break; + + case LV_ALIGN_IN_RIGHT_MID: + new_x = lv_obj_get_width(base) - obj_w_half; + new_y = lv_obj_get_height(base) / 2 - obj_h_half; + break; + + case LV_ALIGN_OUT_TOP_LEFT: + new_x = -obj_w_half; + new_y = -obj_h_half; + break; + + case LV_ALIGN_OUT_TOP_MID: + new_x = lv_obj_get_width(base) / 2 - obj_w_half; + new_y = -obj_h_half; + break; + + case LV_ALIGN_OUT_TOP_RIGHT: + new_x = lv_obj_get_width(base) - obj_w_half; + new_y = - obj_h_half; + break; + + case LV_ALIGN_OUT_BOTTOM_LEFT: + new_x = -obj_w_half; + new_y = lv_obj_get_height(base) - obj_h_half; + break; + + case LV_ALIGN_OUT_BOTTOM_MID: + new_x = lv_obj_get_width(base) / 2 - obj_w_half; + new_y = lv_obj_get_height(base) - obj_h_half; + break; + + case LV_ALIGN_OUT_BOTTOM_RIGHT: + new_x = lv_obj_get_width(base) - obj_w_half; + new_y = lv_obj_get_height(base) - obj_h_half; + break; + + case LV_ALIGN_OUT_LEFT_TOP: + new_x = - obj_w_half ; + new_y = - obj_h_half; + break; + + case LV_ALIGN_OUT_LEFT_MID: + new_x = - obj_w_half; + new_y = lv_obj_get_height(base) / 2 - obj_h_half; + break; + + case LV_ALIGN_OUT_LEFT_BOTTOM: + new_x = - obj_w_half; + new_y = lv_obj_get_height(base) - obj_h_half; + break; + + case LV_ALIGN_OUT_RIGHT_TOP: + new_x = lv_obj_get_width(base) - obj_w_half; + new_y = -obj_h_half; + break; + + case LV_ALIGN_OUT_RIGHT_MID: + new_x = lv_obj_get_width(base) - obj_w_half; + new_y = lv_obj_get_height(base) / 2 - obj_h_half; + break; + + case LV_ALIGN_OUT_RIGHT_BOTTOM: + new_x = lv_obj_get_width(base) - obj_w_half; + new_y = lv_obj_get_height(base) - obj_h_half; + break; + } + + /*Bring together the coordination system of base and obj*/ + lv_obj_t * par = lv_obj_get_parent(obj); + lv_coord_t base_abs_x = base->coords.x1; + lv_coord_t base_abs_y = base->coords.y1; + lv_coord_t par_abs_x = par->coords.x1; + lv_coord_t par_abs_y = par->coords.y1; + new_x += x_mod + base_abs_x; + new_y += y_mod + base_abs_y; + new_x -= par_abs_x; + new_y -= par_abs_y; + + lv_obj_set_pos(obj, new_x, new_y); + +#if LV_OBJ_REALIGN + /*Save the last align parameters to use them in `lv_obj_realign`*/ + obj->realign.align = align; + obj->realign.xofs = x_mod; + obj->realign.yofs = y_mod; + obj->realign.base = base; + obj->realign.origo_align = 1; +#endif +} + +/** + * Realign the object based on the last `lv_obj_align` parameters. + * @param obj pointer to an object + */ +void lv_obj_realign(lv_obj_t * obj) +{ +#if LV_OBJ_REALIGN + if(obj->realign.origo_align) lv_obj_align_origo(obj, obj->realign.base, obj->realign.align, obj->realign.xofs, obj->realign.yofs); + else lv_obj_align(obj, obj->realign.base, obj->realign.align, obj->realign.xofs, obj->realign.yofs); +#else + (void) obj; + LV_LOG_WARN("lv_obj_realaign: no effect because LV_OBJ_REALIGN = 0"); +#endif +} + +/** + * Enable the automatic realign of the object when its size has changed based on the last `lv_obj_align` parameters. + * @param obj pointer to an object + * @param en true: enable auto realign; false: disable auto realign + */ +void lv_obj_set_auto_realign(lv_obj_t * obj, bool en) +{ +#if LV_OBJ_REALIGN + obj->realign.auto_realign = en ? 1 : 0; +#else + (void) obj; + (void) en; + LV_LOG_WARN("lv_obj_set_auto_realign: no effect because LV_OBJ_REALIGN = 0"); +#endif +} + +/*--------------------- + * Appearance set + *--------------------*/ + +/** + * Set a new style for an object + * @param obj pointer to an object + * @param style_p pointer to the new style + */ +void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style) +{ + obj->style_p = style; + + /*Send a signal about style change to every children with NULL style*/ + refresh_children_style(obj); + + /*Notify the object about the style change too*/ + lv_obj_refresh_style(obj); +} + +/** + * Notify an object about its style is modified + * @param obj pointer to an object + */ +void lv_obj_refresh_style(lv_obj_t * obj) +{ + lv_obj_invalidate(obj); + obj->signal_func(obj, LV_SIGNAL_STYLE_CHG, NULL); + lv_obj_invalidate(obj); + +} + +/** + * Notify all object if a style is modified + * @param style pointer to a style. Only the objects with this style will be notified + * (NULL to notify all objects) + */ +void lv_obj_report_style_mod(lv_style_t * style) +{ + lv_obj_t * i; + LL_READ(LV_GC_ROOT(_lv_scr_ll), i) { + if(i->style_p == style || style == NULL) { + lv_obj_refresh_style(i); + } + + report_style_mod_core(style, i); + } +} + +/*----------------- + * Attribute set + *----------------*/ + +/** + * Hide an object. It won't be visible and clickable. + * @param obj pointer to an object + * @param en true: hide the object + */ +void lv_obj_set_hidden(lv_obj_t * obj, bool en) +{ + if(!obj->hidden) lv_obj_invalidate(obj); /*Invalidate when not hidden (hidden objects are ignored) */ + + obj->hidden = en == false ? 0 : 1; + + if(!obj->hidden) lv_obj_invalidate(obj); /*Invalidate when not hidden (hidden objects are ignored) */ + + lv_obj_t * par = lv_obj_get_parent(obj); + par->signal_func(par, LV_SIGNAL_CHILD_CHG, obj); + +} + +/** + * Enable or disable the clicking of an object + * @param obj pointer to an object + * @param en true: make the object clickable + */ +void lv_obj_set_click(lv_obj_t * obj, bool en) +{ + obj->click = (en == true ? 1 : 0); +} + +/** + * Enable to bring this object to the foreground if it + * or any of its children is clicked + * @param obj pointer to an object + * @param en true: enable the auto top feature + */ +void lv_obj_set_top(lv_obj_t * obj, bool en) +{ + obj->top = (en == true ? 1 : 0); +} + +/** + * Enable the dragging of an object + * @param obj pointer to an object + * @param en true: make the object dragable + */ +void lv_obj_set_drag(lv_obj_t * obj, bool en) +{ + if(en == true) lv_obj_set_click(obj, true); /*Drag is useless without enabled clicking*/ + obj->drag = (en == true ? 1 : 0); +} + +/** + * Enable the throwing of an object after is is dragged + * @param obj pointer to an object + * @param en true: enable the drag throw + */ +void lv_obj_set_drag_throw(lv_obj_t * obj, bool en) +{ + obj->drag_throw = (en == true ? 1 : 0); +} + +/** + * Enable to use parent for drag related operations. + * If trying to drag the object the parent will be moved instead + * @param obj pointer to an object + * @param en true: enable the 'drag parent' for the object + */ +void lv_obj_set_drag_parent(lv_obj_t * obj, bool en) +{ + obj->drag_parent = (en == true ? 1 : 0); +} + +/** + * Set the opa scale enable parameter (required to set opa_scale with `lv_obj_set_opa_scale()`) + * @param obj pointer to an object + * @param en true: opa scaling is enabled for this object and all children; false: no opa scaling + */ +void lv_obj_set_opa_scale_enable(lv_obj_t * obj, bool en) +{ + obj->opa_scale_en = en ? 1 : 0; +} + +/** + * Set the opa scale of an object + * @param obj pointer to an object + * @param opa_scale a factor to scale down opacity [0..255] + */ +void lv_obj_set_opa_scale(lv_obj_t * obj, lv_opa_t opa_scale) +{ + obj->opa_scale = opa_scale; + lv_obj_invalidate(obj); +} + +/** + * Set a bit or bits in the protect filed + * @param obj pointer to an object + * @param prot 'OR'-ed values from `lv_protect_t` + */ +void lv_obj_set_protect(lv_obj_t * obj, uint8_t prot) +{ + obj->protect |= prot; +} + +/** + * Clear a bit or bits in the protect filed + * @param obj pointer to an object + * @param prot 'OR'-ed values from `lv_protect_t` + */ +void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot) +{ + prot = (~prot) & 0xFF; + obj->protect &= prot; +} + +/** + * Set the signal function of an object. + * Always call the previous signal function in the new. + * @param obj pointer to an object + * @param fp the new signal function + */ +void lv_obj_set_signal_func(lv_obj_t * obj, lv_signal_func_t fp) +{ + obj->signal_func = fp; +} + +/** + * Set a new design function for an object + * @param obj pointer to an object + * @param fp the new design function + */ +void lv_obj_set_design_func(lv_obj_t * obj, lv_design_func_t fp) +{ + obj->design_func = fp; +} + +/*---------------- + * Other set + *--------------*/ + +/** + * Allocate a new ext. data for an object + * @param obj pointer to an object + * @param ext_size the size of the new ext. data + * @return Normal pointer to the allocated ext + */ +void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size) +{ + obj->ext_attr = lv_mem_realloc(obj->ext_attr, ext_size); + + return (void *)obj->ext_attr; +} + +/** + * Send a 'LV_SIGNAL_REFR_EXT_SIZE' signal to the object + * @param obj pointer to an object + */ +void lv_obj_refresh_ext_size(lv_obj_t * obj) +{ + obj->ext_size = 0; + obj->signal_func(obj, LV_SIGNAL_REFR_EXT_SIZE, NULL); + + lv_obj_invalidate(obj); +} + +#ifdef LV_OBJ_FREE_NUM_TYPE +/** + * Set an application specific number for an object. + * It can help to identify objects in the application. + * @param obj pointer to an object + * @param free_num the new free number + */ +void lv_obj_set_free_num(lv_obj_t * obj, LV_OBJ_FREE_NUM_TYPE free_num) +{ + obj->free_num = free_num; +} +#endif + +#if LV_OBJ_FREE_PTR != 0 +/** + * Set an application specific pointer for an object. + * It can help to identify objects in the application. + * @param obj pointer to an object + * @param free_p the new free pinter + */ +void lv_obj_set_free_ptr(lv_obj_t * obj, void * free_p) +{ + obj->free_ptr = free_p; +} +#endif + +#if USE_LV_ANIMATION +/** + * Animate an object + * @param obj pointer to an object to animate + * @param type type of animation from 'lv_anim_builtin_t'. 'OR' it with ANIM_IN or ANIM_OUT + * @param time time of animation in milliseconds + * @param delay delay before the animation in milliseconds + * @param cb a function to call when the animation is ready + */ +void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint16_t delay, void (*cb)(lv_obj_t *)) +{ + lv_obj_t * par = lv_obj_get_parent(obj); + + /*Get the direction*/ + bool out = (type & LV_ANIM_DIR_MASK) == LV_ANIM_IN ? false : true; + type = type & (~LV_ANIM_DIR_MASK); + + lv_anim_t a; + a.var = obj; + a.time = time; + a.act_time = (int32_t) - delay; + a.end_cb = (void(*)(void *))cb; + a.path = lv_anim_path_linear; + a.playback_pause = 0; + a.repeat_pause = 0; + a.playback = 0; + a.repeat = 0; + + /*Init to ANIM_IN*/ + switch(type) { + case LV_ANIM_FLOAT_LEFT: + a.fp = (void(*)(void *, int32_t))lv_obj_set_x; + a.start = -lv_obj_get_width(obj); + a.end = lv_obj_get_x(obj); + break; + case LV_ANIM_FLOAT_RIGHT: + a.fp = (void(*)(void *, int32_t))lv_obj_set_x; + a.start = lv_obj_get_width(par); + a.end = lv_obj_get_x(obj); + break; + case LV_ANIM_FLOAT_TOP: + a.fp = (void(*)(void *, int32_t))lv_obj_set_y; + a.start = -lv_obj_get_height(obj); + a.end = lv_obj_get_y(obj); + break; + case LV_ANIM_FLOAT_BOTTOM: + a.fp = (void(*)(void *, int32_t))lv_obj_set_y; + a.start = lv_obj_get_height(par); + a.end = lv_obj_get_y(obj); + break; + case LV_ANIM_GROW_H: + a.fp = (void(*)(void *, int32_t))lv_obj_set_width; + a.start = 0; + a.end = lv_obj_get_width(obj); + break; + case LV_ANIM_GROW_V: + a.fp = (void(*)(void *, int32_t))lv_obj_set_height; + a.start = 0; + a.end = lv_obj_get_height(obj); + break; + case LV_ANIM_NONE: + a.fp = NULL; + a.start = 0; + a.end = 0; + break; + default: + break; + } + + /*Swap start and end in case of ANIM OUT*/ + if(out != false) { + int32_t tmp = a.start; + a.start = a.end; + a.end = tmp; + } + + lv_anim_create(&a); +} + +#endif + +/*======================= + * Getter functions + *======================*/ + +/*------------------ + * Screen get + *-----------------*/ + +/** + * Return with a pointer to the active screen + * @return pointer to the active screen object (loaded by 'lv_scr_load()') + */ +lv_obj_t * lv_scr_act(void) +{ + return LV_GC_ROOT(_lv_act_scr); +} + +/** + * Return with the top layer. (Same on every screen and it is above the normal screen layer) + * @return pointer to the top layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_layer_top(void) +{ + return LV_GC_ROOT(_lv_top_layer); +} + +/** + * Return with the system layer. (Same on every screen and it is above the all other layers) + * It is used for example by the cursor + * @return pointer to the system layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_layer_sys(void) +{ + return LV_GC_ROOT(_lv_sys_layer); +} + +/** + * Return with the screen of an object + * @param obj pointer to an object + * @return pointer to a screen + */ +lv_obj_t * lv_obj_get_screen(const lv_obj_t * obj) +{ + const lv_obj_t * par = obj; + const lv_obj_t * act_p; + + do { + act_p = par; + par = lv_obj_get_parent(act_p); + } while(par != NULL); + + return (lv_obj_t *)act_p; +} + +/*--------------------- + * Parent/children get + *--------------------*/ + +/** + * Returns with the parent of an object + * @param obj pointer to an object + * @return pointer to the parent of 'obj' + */ +lv_obj_t * lv_obj_get_parent(const lv_obj_t * obj) +{ + return obj->par; +} + +/** + * Iterate through the children of an object (start from the "youngest") + * @param obj pointer to an object + * @param child NULL at first call to get the next children + * and the previous return value later + * @return the child after 'act_child' or NULL if no more child + */ +lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child) +{ + lv_obj_t * result = NULL; + + if(child == NULL) { + result = lv_ll_get_head(&obj->child_ll); + } else { + result = lv_ll_get_next(&obj->child_ll, child); + } + + return result; +} + +/** + * Iterate through the children of an object (start from the "oldest") + * @param obj pointer to an object + * @param child NULL at first call to get the next children + * and the previous return value later + * @return the child after 'act_child' or NULL if no more child + */ +lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child) +{ + lv_obj_t * result = NULL; + + if(child == NULL) { + result = lv_ll_get_tail(&obj->child_ll); + } else { + result = lv_ll_get_prev(&obj->child_ll, child); + } + + return result; +} + +/** + * Count the children of an object (only children directly on 'obj') + * @param obj pointer to an object + * @return children number of 'obj' + */ +uint16_t lv_obj_count_children(const lv_obj_t * obj) +{ + lv_obj_t * i; + uint16_t cnt = 0; + + LL_READ(obj->child_ll, i) cnt++; + + return cnt; +} + +/*--------------------- + * Coordinate get + *--------------------*/ + +/** + * Copy the coordinates of an object to an area + * @param obj pointer to an object + * @param cords_p pointer to an area to store the coordinates + */ +void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p) +{ + lv_area_copy(cords_p, &obj->coords); +} + + +/** + * Get the x coordinate of object + * @param obj pointer to an object + * @return distance of 'obj' from the left side of its parent + */ +lv_coord_t lv_obj_get_x(const lv_obj_t * obj) +{ + lv_coord_t rel_x; + lv_obj_t * parent = lv_obj_get_parent(obj); + rel_x = obj->coords.x1 - parent->coords.x1; + + return rel_x; +} + +/** + * Get the y coordinate of object + * @param obj pointer to an object + * @return distance of 'obj' from the top of its parent + */ +lv_coord_t lv_obj_get_y(const lv_obj_t * obj) +{ + lv_coord_t rel_y; + lv_obj_t * parent = lv_obj_get_parent(obj); + rel_y = obj->coords.y1 - parent->coords.y1; + + return rel_y; +} + +/** + * Get the width of an object + * @param obj pointer to an object + * @return the width + */ +lv_coord_t lv_obj_get_width(const lv_obj_t * obj) +{ + return lv_area_get_width(&obj->coords); +} + +/** + * Get the height of an object + * @param obj pointer to an object + * @return the height + */ +lv_coord_t lv_obj_get_height(const lv_obj_t * obj) +{ + return lv_area_get_height(&obj->coords); +} + +/** + * Get the extended size attribute of an object + * @param obj pointer to an object + * @return the extended size attribute + */ +lv_coord_t lv_obj_get_ext_size(const lv_obj_t * obj) +{ + return obj->ext_size; +} + +/** + * Get the automatic realign property of the object. + * @param obj pointer to an object + * @return true: auto realign is enabled; false: auto realign is disabled + */ +bool lv_obj_get_auto_realign(lv_obj_t * obj) +{ +#if LV_OBJ_REALIGN + return obj->realign.auto_realign ? true : false; +#else + (void) obj; + return false; +#endif +} + +/*----------------- + * Appearance get + *---------------*/ + +/** + * Get the style pointer of an object (if NULL get style of the parent) + * @param obj pointer to an object + * @return pointer to a style + */ +lv_style_t * lv_obj_get_style(const lv_obj_t * obj) +{ + lv_style_t * style_act = obj->style_p; + if(style_act == NULL) { + lv_obj_t * par = obj->par; + + while(par) { + if(par->style_p) { + if(par->style_p->glass == 0) { +#if USE_LV_GROUP == 0 + style_act = par->style_p; +#else + /*Is a parent is focused then use then focused style*/ + lv_group_t * g = lv_obj_get_group(par); + if(lv_group_get_focused(g) == par) { + style_act = lv_group_mod_style(g, par->style_p); + } else { + style_act = par->style_p; + } +#endif + break; + } + } + par = par->par; + } + } +#if USE_LV_GROUP + if(obj->group_p) { + if(lv_group_get_focused(obj->group_p) == obj) { + style_act = lv_group_mod_style(obj->group_p, style_act); + } + } +#endif + + if(style_act == NULL) style_act = &lv_style_plain; + + return style_act; +} + +/*----------------- + * Attribute get + *----------------*/ + +/** + * Get the hidden attribute of an object + * @param obj pointer to an object + * @return true: the object is hidden + */ +bool lv_obj_get_hidden(const lv_obj_t * obj) +{ + return obj->hidden == 0 ? false : true; +} + +/** + * Get the click enable attribute of an object + * @param obj pointer to an object + * @return true: the object is clickable + */ +bool lv_obj_get_click(const lv_obj_t * obj) +{ + return obj->click == 0 ? false : true; +} + +/** + * Get the top enable attribute of an object + * @param obj pointer to an object + * @return true: the auto top feture is enabled + */ +bool lv_obj_get_top(const lv_obj_t * obj) +{ + return obj->top == 0 ? false : true; +} + +/** + * Get the drag enable attribute of an object + * @param obj pointer to an object + * @return true: the object is dragable + */ +bool lv_obj_get_drag(const lv_obj_t * obj) +{ + return obj->drag == 0 ? false : true; +} + +/** + * Get the drag throw enable attribute of an object + * @param obj pointer to an object + * @return true: drag throw is enabled + */ +bool lv_obj_get_drag_throw(const lv_obj_t * obj) +{ + return obj->drag_throw == 0 ? false : true; +} + +/** + * Get the drag parent attribute of an object + * @param obj pointer to an object + * @return true: drag parent is enabled + */ +bool lv_obj_get_drag_parent(const lv_obj_t * obj) +{ + return obj->drag_parent == 0 ? false : true; +} + +/** + * Get the opa scale enable parameter + * @param obj pointer to an object + * @return true: opa scaling is enabled for this object and all children; false: no opa scaling + */ +lv_opa_t lv_obj_get_opa_scale_enable(const lv_obj_t * obj) +{ + return obj->opa_scale_en == 0 ? false : true; +} + +/** + * Get the opa scale parameter of an object + * @param obj pointer to an object + * @return opa scale [0..255] + */ +lv_opa_t lv_obj_get_opa_scale(const lv_obj_t * obj) +{ + const lv_obj_t * parent = obj; + + while(parent) { + if(parent->opa_scale_en) return parent->opa_scale; + parent = lv_obj_get_parent(parent); + } + + return LV_OPA_COVER; +} + +/** + * Get the protect field of an object + * @param obj pointer to an object + * @return protect field ('OR'ed values of `lv_protect_t`) + */ +uint8_t lv_obj_get_protect(const lv_obj_t * obj) +{ + return obj->protect ; +} + +/** + * Check at least one bit of a given protect bitfield is set + * @param obj pointer to an object + * @param prot protect bits to test ('OR'ed values of `lv_protect_t`) + * @return false: none of the given bits are set, true: at least one bit is set + */ +bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot) +{ + return (obj->protect & prot) == 0 ? false : true ; +} + +/** + * Get the signal function of an object + * @param obj pointer to an object + * @return the signal function + */ +lv_signal_func_t lv_obj_get_signal_func(const lv_obj_t * obj) +{ + return obj->signal_func; +} + +/** + * Get the design function of an object + * @param obj pointer to an object + * @return the design function + */ +lv_design_func_t lv_obj_get_design_func(const lv_obj_t * obj) +{ + return obj->design_func; +} + +/*------------------ + * Other get + *-----------------*/ + +/** + * Get the ext pointer + * @param obj pointer to an object + * @return the ext pointer but not the dynamic version + * Use it as ext->data1, and NOT da(ext)->data1 + */ +void * lv_obj_get_ext_attr(const lv_obj_t * obj) +{ + return obj->ext_attr; +} + +/** + * Get object's and its ancestors type. Put their name in `type_buf` starting with the current type. + * E.g. buf.type[0]="lv_btn", buf.type[1]="lv_cont", buf.type[2]="lv_obj" + * @param obj pointer to an object which type should be get + * @param buf pointer to an `lv_obj_type_t` buffer to store the types + */ +void lv_obj_get_type(lv_obj_t * obj, lv_obj_type_t * buf) +{ + lv_obj_type_t tmp; + + memset(buf, 0, sizeof(lv_obj_type_t)); + memset(&tmp, 0, sizeof(lv_obj_type_t)); + + obj->signal_func(obj, LV_SIGNAL_GET_TYPE, &tmp); + + uint8_t cnt; + for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) { + if(tmp.type[cnt] == NULL) break; + } + + + /*Swap the order. The real type comes first*/ + uint8_t i; + for(i = 0; i < cnt; i++) { + buf->type[i] = tmp.type[cnt - 1 - i]; + } +} + +#ifdef LV_OBJ_FREE_NUM_TYPE +/** + * Get the free number + * @param obj pointer to an object + * @return the free number + */ +LV_OBJ_FREE_NUM_TYPE lv_obj_get_free_num(const lv_obj_t * obj) +{ + return obj->free_num; +} +#endif + +#if LV_OBJ_FREE_PTR != 0 +/** + * Get the free pointer + * @param obj pointer to an object + * @return the free pointer + */ +void * lv_obj_get_free_ptr(const lv_obj_t * obj) +{ + return obj->free_ptr; +} +#endif + + +#if USE_LV_GROUP +/** + * Get the group of the object + * @param obj pointer to an object + * @return the pointer to group of the object + */ +void * lv_obj_get_group(const lv_obj_t * obj) +{ + return obj->group_p; +} + +/** + * Tell whether the ohe object is the focused object of a group or not. + * @param obj pointer to an object + * @return true: the object is focused, false: the object is not focused or not in a group + */ +bool lv_obj_is_focused(const lv_obj_t * obj) +{ + if(obj->group_p) { + if(lv_group_get_focused(obj->group_p) == obj) return true; + } + + return false; +} +#endif + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the base objects. + * @param obj pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * @param return true/false, depends on 'mode' + */ +static bool lv_obj_design(lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + + /* Because of the radius it is not sure the area is covered + * Check the areas where there is no radius*/ + lv_style_t * style = lv_obj_get_style(obj); + if(style->body.empty != 0) return false; + + uint16_t r = style->body.radius; + + if(r == LV_RADIUS_CIRCLE) return false; + + lv_area_t area_tmp; + + /*Check horizontally without radius*/ + lv_obj_get_coords(obj, &area_tmp); + area_tmp.x1 += r; + area_tmp.x2 -= r; + if(lv_area_is_in(mask_p, &area_tmp) == false) return false; + + /*Check vertically without radius*/ + lv_obj_get_coords(obj, &area_tmp); + area_tmp.y1 += r; + area_tmp.y2 -= r; + if(lv_area_is_in(mask_p, &area_tmp) == false) return false; + + } else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_style_t * style = lv_obj_get_style(obj); + lv_draw_rect(&obj->coords, mask_p, style, lv_obj_get_opa_scale(obj)); + } + + return true; +} + +/** + * Signal function of the basic object + * @param obj pointer to an object + * @param sign signal type + * @param param parameter for the signal (depends on signal type) + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) +{ + (void)param; + + lv_res_t res = LV_RES_OK; + + lv_style_t * style = lv_obj_get_style(obj); + + lv_indev_t *indev_act = lv_indev_get_act(); + + if(sign > _LV_SIGNAL_FEEDBACK_SECTION_START && sign < _LV_SIGNAL_FEEDBACK_SECTION_END) { + if(indev_act != NULL && indev_act->feedback != NULL) + indev_act->feedback(indev_act, sign); + } + + if(sign == LV_SIGNAL_CHILD_CHG) { + /*Return 'invalid' if the child change signal is not enabled*/ + if(lv_obj_is_protected(obj, LV_PROTECT_CHILD_CHG) != false) res = LV_RES_INV; + } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + if(style->body.shadow.width > obj->ext_size) obj->ext_size = style->body.shadow.width; + } else if(sign == LV_SIGNAL_STYLE_CHG) { + lv_obj_refresh_ext_size(obj); + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + buf->type[0] = "lv_obj"; + } + + return res; +} + +/** + * Reposition the children of an object. (Called recursively) + * @param obj pointer to an object which children will be repositioned + * @param x_diff x coordinate shift + * @param y_diff y coordinate shift + */ +static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff) +{ + lv_obj_t * i; + LL_READ(obj->child_ll, i) { + i->coords.x1 += x_diff; + i->coords.y1 += y_diff; + i->coords.x2 += x_diff; + i->coords.y2 += y_diff; + + refresh_children_position(i, x_diff, y_diff); + } +} + +/** + * Refresh the style of all children of an object. (Called recursively) + * @param style_p refresh objects only with this style. + * @param obj pointer to an object + */ +static void report_style_mod_core(void * style_p, lv_obj_t * obj) +{ + lv_obj_t * i; + LL_READ(obj->child_ll, i) { + if(i->style_p == style_p || style_p == NULL) { + refresh_children_style(i); + lv_obj_refresh_style(i); + } + + report_style_mod_core(style_p, i); + } +} + +/** + * Recursively refresh the style of the children. Go deeper until a not NULL style is found + * because the NULL styles are inherited from the parent + * @param obj pointer to an object + */ +static void refresh_children_style(lv_obj_t * obj) +{ + lv_obj_t * child = lv_obj_get_child(obj, NULL); + while(child != NULL) { + if(child->style_p == NULL) { + refresh_children_style(child); /*Check children too*/ + lv_obj_refresh_style(child); /*Notify the child about the style change*/ + } else if(child->style_p->glass) { + /*Children with 'glass' parent might be effected if their style == NULL*/ + refresh_children_style(child); + } + child = lv_obj_get_child(obj, child); + } +} + +/** + * Called by 'lv_obj_del' to delete the children objects + * @param obj pointer to an object (all of its children will be deleted) + */ +static void delete_children(lv_obj_t * obj) +{ + lv_obj_t * i; + lv_obj_t * i_next; + i = lv_ll_get_head(&(obj->child_ll)); + + /*Remove from the group; remove before transversing children so that + * the object still has access to all children during the + * LV_SIGNAL_DEFOCUS call*/ +#if USE_LV_GROUP + if(obj->group_p != NULL) lv_group_remove_obj(obj); +#endif + + while(i != NULL) { + /*Get the next object before delete this*/ + i_next = lv_ll_get_next(&(obj->child_ll), i); + + /*Call the recursive del to the child too*/ + delete_children(i); + + /*Set i to the next node*/ + i = i_next; + } + + /*Remove the animations from this object*/ +#if USE_LV_ANIMATION + lv_anim_del(obj, NULL); +#endif + + + /* Reset the input devices if + * the currently pressed object is deleted*/ + lv_indev_t * indev = lv_indev_next(NULL); + while(indev) { + if(indev->proc.act_obj == obj || indev->proc.last_obj == obj) { + lv_indev_reset(indev); + } + indev = lv_indev_next(indev); + } + + /*Remove the object from parent's children list*/ + lv_obj_t * par = lv_obj_get_parent(obj); + lv_ll_rem(&(par->child_ll), obj); + + /* Clean up the object specific data*/ + obj->signal_func(obj, LV_SIGNAL_CLEANUP, NULL); + + /*Delete the base objects*/ + if(obj->ext_attr != NULL) lv_mem_free(obj->ext_attr); + lv_mem_free(obj); /*Free the object itself*/ + +} diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.h b/nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.h new file mode 100644 index 0000000..0ebd916 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_obj.h @@ -0,0 +1,840 @@ +/** + * @file lv_obj.h + * + */ + +#ifndef LV_OBJ_H +#define LV_OBJ_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include +#include "lv_style.h" +#include "../lv_misc/lv_area.h" +#include "../lv_misc/lv_mem.h" +#include "../lv_misc/lv_ll.h" +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_log.h" + +/********************* + * DEFINES + *********************/ + +/*Error check of lv_conf.h*/ +#if LV_HOR_RES == 0 || LV_VER_RES == 0 +#error "LittlevGL: LV_HOR_RES and LV_VER_RES must be greater than 0" +#endif + +#if LV_ANTIALIAS > 1 +#error "LittlevGL: LV_ANTIALIAS can be only 0 or 1" +#endif + +#if LV_VDB_SIZE == 0 && LV_ANTIALIAS != 0 +#error "LittlevGL: If LV_VDB_SIZE == 0 the anti-aliasing must be disabled" +#endif + +#if LV_VDB_SIZE > 0 && LV_VDB_SIZE < LV_HOR_RES +#error "LittlevGL: Small Virtual Display Buffer (lv_conf.h: LV_VDB_SIZE >= LV_HOR_RES)" +#endif + +#if LV_VDB_SIZE == 0 && USE_LV_REAL_DRAW == 0 +#error "LittlevGL: If LV_VDB_SIZE = 0 Real drawing function are required (lv_conf.h: USE_LV_REAL_DRAW 1)" +#endif + + +#define LV_ANIM_IN 0x00 /*Animation to show an object. 'OR' it with lv_anim_builtin_t*/ +#define LV_ANIM_OUT 0x80 /*Animation to hide an object. 'OR' it with lv_anim_builtin_t*/ +#define LV_ANIM_DIR_MASK 0x80 /*ANIM_IN/ANIM_OUT mask*/ + +#define LV_MAX_ANCESTOR_NUM 8 + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; + +enum +{ + LV_DESIGN_DRAW_MAIN, + LV_DESIGN_DRAW_POST, + LV_DESIGN_COVER_CHK, +}; +typedef uint8_t lv_design_mode_t; + +typedef bool (* lv_design_func_t) (struct _lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode); + +enum +{ + LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action function or an operation was failed*/ + LV_RES_OK, /*The object is valid (no deleted) after the action*/ +}; +typedef uint8_t lv_res_t; + +enum +{ + /*General signals*/ + LV_SIGNAL_CLEANUP, + LV_SIGNAL_CHILD_CHG, + LV_SIGNAL_CORD_CHG, + LV_SIGNAL_STYLE_CHG, + LV_SIGNAL_REFR_EXT_SIZE, + LV_SIGNAL_LANG_CHG, + LV_SIGNAL_GET_TYPE, + + _LV_SIGNAL_FEEDBACK_SECTION_START, + /*Input device related*/ + LV_SIGNAL_PRESSED, + LV_SIGNAL_PRESSING, + LV_SIGNAL_PRESS_LOST, + LV_SIGNAL_RELEASED, + LV_SIGNAL_LONG_PRESS, + LV_SIGNAL_LONG_PRESS_REP, + LV_SIGNAL_DRAG_BEGIN, + LV_SIGNAL_DRAG_END, + + /*Group related*/ + LV_SIGNAL_FOCUS, + LV_SIGNAL_DEFOCUS, + LV_SIGNAL_CONTROLL, + _LV_SIGNAL_FEEDBACK_SECTION_END, + LV_SIGNAL_GET_EDITABLE, +}; +typedef uint8_t lv_signal_t; + +typedef lv_res_t (* lv_signal_func_t) (struct _lv_obj_t * obj, lv_signal_t sign, void * param); + +enum +{ + LV_ALIGN_CENTER = 0, + LV_ALIGN_IN_TOP_LEFT, + LV_ALIGN_IN_TOP_MID, + LV_ALIGN_IN_TOP_RIGHT, + LV_ALIGN_IN_BOTTOM_LEFT, + LV_ALIGN_IN_BOTTOM_MID, + LV_ALIGN_IN_BOTTOM_RIGHT, + LV_ALIGN_IN_LEFT_MID, + LV_ALIGN_IN_RIGHT_MID, + LV_ALIGN_OUT_TOP_LEFT, + LV_ALIGN_OUT_TOP_MID, + LV_ALIGN_OUT_TOP_RIGHT, + LV_ALIGN_OUT_BOTTOM_LEFT, + LV_ALIGN_OUT_BOTTOM_MID, + LV_ALIGN_OUT_BOTTOM_RIGHT, + LV_ALIGN_OUT_LEFT_TOP, + LV_ALIGN_OUT_LEFT_MID, + LV_ALIGN_OUT_LEFT_BOTTOM, + LV_ALIGN_OUT_RIGHT_TOP, + LV_ALIGN_OUT_RIGHT_MID, + LV_ALIGN_OUT_RIGHT_BOTTOM, +}; +typedef uint8_t lv_align_t; + +#if LV_OBJ_REALIGN +typedef struct { + const struct _lv_obj_t * base; + lv_coord_t xofs; + lv_coord_t yofs; + lv_align_t align; + uint8_t auto_realign :1; + uint8_t origo_align :1; /*1: the oigo (center of the object) was aligned with `lv_obj_align_origo`*/ +}lv_reailgn_t; +#endif + + +typedef struct _lv_obj_t +{ + struct _lv_obj_t * par; /*Pointer to the parent object*/ + lv_ll_t child_ll; /*Linked list to store the children objects*/ + + lv_area_t coords; /*Coordinates of the object (x1, y1, x2, y2)*/ + + lv_signal_func_t signal_func; /*Object type specific signal function*/ + lv_design_func_t design_func; /*Object type specific design function*/ + + void * ext_attr; /*Object type specific extended data*/ + lv_style_t * style_p; /*Pointer to the object's style*/ + +#if LV_OBJ_FREE_PTR != 0 + void * free_ptr; /*Application specific pointer (set it freely)*/ +#endif + +#if USE_LV_GROUP != 0 + void * group_p; /*Pointer to the group of the object*/ +#endif + /*Attributes and states*/ + uint8_t click :1; /*1: Can be pressed by an input device*/ + uint8_t drag :1; /*1: Enable the dragging*/ + uint8_t drag_throw :1; /*1: Enable throwing with drag*/ + uint8_t drag_parent :1; /*1: Parent will be dragged instead*/ + uint8_t hidden :1; /*1: Object is hidden*/ + uint8_t top :1; /*1: If the object or its children is clicked it goes to the foreground*/ + uint8_t opa_scale_en :1; /*1: opa_scale is set*/ + uint8_t protect; /*Automatically happening actions can be prevented. 'OR'ed values from `lv_protect_t`*/ + lv_opa_t opa_scale; /*Scale down the opacity by this factor. Effects all children as well*/ + + lv_coord_t ext_size; /*EXTtend the size of the object in every direction. E.g. for shadow drawing*/ +#if LV_OBJ_REALIGN + lv_reailgn_t realign; +#endif + +#ifdef LV_OBJ_FREE_NUM_TYPE + LV_OBJ_FREE_NUM_TYPE free_num; /*Application specific identifier (set it freely)*/ +#endif +} lv_obj_t; + +typedef lv_res_t (*lv_action_t) (struct _lv_obj_t * obj); + +/*Protect some attributes (max. 8 bit)*/ +enum +{ + LV_PROTECT_NONE = 0x00, + LV_PROTECT_CHILD_CHG = 0x01, /*Disable the child change signal. Used by the library*/ + LV_PROTECT_PARENT = 0x02, /*Prevent automatic parent change (e.g. in lv_page)*/ + LV_PROTECT_POS = 0x04, /*Prevent automatic positioning (e.g. in lv_cont layout)*/ + LV_PROTECT_FOLLOW = 0x08, /*Prevent the object be followed in automatic ordering (e.g. in lv_cont PRETTY layout)*/ + LV_PROTECT_PRESS_LOST= 0x10, /*If the `indev` was pressing this object but swiped out while pressing do not search other object.*/ + LV_PROTECT_CLICK_FOCUS= 0x20,/*Prevent focusing the object by clicking on it*/ +}; +typedef uint8_t lv_protect_t; + + +/*Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/ +typedef struct { + const char * type[LV_MAX_ANCESTOR_NUM]; /*[0]: the actual type, [1]: ancestor, [2] #1's ancestor ... [x]: "lv_obj" */ +} lv_obj_type_t; + +enum +{ + LV_ANIM_NONE = 0, + LV_ANIM_FLOAT_TOP, /*Float from/to the top*/ + LV_ANIM_FLOAT_LEFT, /*Float from/to the left*/ + LV_ANIM_FLOAT_BOTTOM, /*Float from/to the bottom*/ + LV_ANIM_FLOAT_RIGHT, /*Float from/to the right*/ + LV_ANIM_GROW_H, /*Grow/shrink horizontally*/ + LV_ANIM_GROW_V, /*Grow/shrink vertically*/ +}; +typedef uint8_t lv_anim_builtin_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Init. the 'lv' library. + */ +void lv_init(void); + +/*-------------------- + * Create and delete + *-------------------*/ + +/** + * Create a basic object + * @param parent pointer to a parent object. + * If NULL then a screen will be created + * @param copy pointer to a base object, if not NULL then the new object will be copied from it + * @return pointer to the new object + */ +lv_obj_t * lv_obj_create(lv_obj_t * parent,const lv_obj_t * copy); + +/** + * Delete 'obj' and all of its children + * @param obj pointer to an object to delete + * @return LV_RES_INV because the object is deleted + */ +lv_res_t lv_obj_del(lv_obj_t * obj); + +/** + * Delete all children of an object + * @param obj pointer to an object + */ +void lv_obj_clean(lv_obj_t *obj); + +/** + * Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task' + * @param obj pointer to an object + */ +void lv_obj_invalidate(const lv_obj_t * obj); + +/*===================== + * Setter functions + *====================*/ + +/*-------------- + * Screen set + *--------------*/ + +/** + * Load a new screen + * @param scr pointer to a screen + */ +void lv_scr_load(lv_obj_t * scr); + +/*-------------------- + * Parent/children set + *--------------------*/ + +/** + * Set a new parent for an object. Its relative position will be the same. + * @param obj pointer to an object. Can't be a screen. + * @param parent pointer to the new parent object. (Can't be NULL) + */ +void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent); + +/*-------------------- + * Coordinate set + * ------------------*/ + +/** + * Set relative the position of an object (relative to the parent) + * @param obj pointer to an object + * @param x new distance from the left side of the parent + * @param y new distance from the top of the parent + */ +void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + +/** + * Set the x coordinate of a object + * @param obj pointer to an object + * @param x new distance from the left side from the parent + */ +void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x); + +/** + * Set the y coordinate of a object + * @param obj pointer to an object + * @param y new distance from the top of the parent + */ +void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y); + +/** + * Set the size of an object + * @param obj pointer to an object + * @param w new width + * @param h new height + */ +void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); + +/** + * Set the width of an object + * @param obj pointer to an object + * @param w new width + */ +void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w); + +/** + * Set the height of an object + * @param obj pointer to an object + * @param h new height + */ +void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h); + +/** + * Align an object to an other object. + * @param obj pointer to an object to align + * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. + * @param align type of alignment (see 'lv_align_t' enum) + * @param x_mod x coordinate shift after alignment + * @param y_mod y coordinate shift after alignment + */ +void lv_obj_align(lv_obj_t * obj,const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod); + +/** + * Align an object to an other object. + * @param obj pointer to an object to align + * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. + * @param align type of alignment (see 'lv_align_t' enum) + * @param x_mod x coordinate shift after alignment + * @param y_mod y coordinate shift after alignment + */ +void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod); + +/** + * Realign the object based on the last `lv_obj_align` parameters. + * @param obj pointer to an object + */ +void lv_obj_realign(lv_obj_t * obj); + +/** + * Enable the automatic realign of the object when its size has changed based on the last `lv_obj_align` parameters. + * @param obj pointer to an object + * @param en true: enable auto realign; false: disable auto realign + */ +void lv_obj_set_auto_realign(lv_obj_t * obj, bool en); + +/*--------------------- + * Appearance set + *--------------------*/ + +/** + * Set a new style for an object + * @param obj pointer to an object + * @param style_p pointer to the new style + */ +void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style); + +/** + * Notify an object about its style is modified + * @param obj pointer to an object + */ +void lv_obj_refresh_style(lv_obj_t * obj); + +/** + * Notify all object if a style is modified + * @param style pointer to a style. Only the objects with this style will be notified + * (NULL to notify all objects) + */ +void lv_obj_report_style_mod(lv_style_t * style); + +/*----------------- + * Attribute set + *----------------*/ + +/** + * Hide an object. It won't be visible and clickable. + * @param obj pointer to an object + * @param en true: hide the object + */ +void lv_obj_set_hidden(lv_obj_t * obj, bool en); + +/** + * Enable or disable the clicking of an object + * @param obj pointer to an object + * @param en true: make the object clickable + */ +void lv_obj_set_click(lv_obj_t * obj, bool en); + +/** + * Enable to bring this object to the foreground if it + * or any of its children is clicked + * @param obj pointer to an object + * @param en true: enable the auto top feature + */ +void lv_obj_set_top(lv_obj_t * obj, bool en); + +/** + * Enable the dragging of an object + * @param obj pointer to an object + * @param en true: make the object dragable + */ +void lv_obj_set_drag(lv_obj_t * obj, bool en); + +/** + * Enable the throwing of an object after is is dragged + * @param obj pointer to an object + * @param en true: enable the drag throw + */ +void lv_obj_set_drag_throw(lv_obj_t * obj, bool en); + +/** + * Enable to use parent for drag related operations. + * If trying to drag the object the parent will be moved instead + * @param obj pointer to an object + * @param en true: enable the 'drag parent' for the object + */ +void lv_obj_set_drag_parent(lv_obj_t * obj, bool en); + +/** + * Set editable parameter Used by groups and keyboard/encoder control. + * Editable object has something inside to choose (the elements of a list) + * @param obj pointer to an object + * @param en true: enable editing + */ +//void lv_obj_set_editable(lv_obj_t * obj, bool en); + +/** + * Set the opa scale enable parameter (required to set opa_scale with `lv_obj_set_opa_scale()`) + * @param obj pointer to an object + * @param en true: opa scaling is enabled for this object and all children; false: no opa scaling + */ +void lv_obj_set_opa_scale_enable(lv_obj_t * obj, bool en); + +/** + * Set the opa scale of an object + * @param obj pointer to an object + * @param opa_scale a factor to scale down opacity [0..255] + */ +void lv_obj_set_opa_scale(lv_obj_t * obj, lv_opa_t opa_scale); + +/** + * Set a bit or bits in the protect filed + * @param obj pointer to an object + * @param prot 'OR'-ed values from `lv_protect_t` + */ +void lv_obj_set_protect(lv_obj_t * obj, uint8_t prot); + +/** + * Clear a bit or bits in the protect filed + * @param obj pointer to an object + * @param prot 'OR'-ed values from `lv_protect_t` + */ +void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot); + +/** + * Set the signal function of an object. + * Always call the previous signal function in the new. + * @param obj pointer to an object + * @param fp the new signal function + */ +void lv_obj_set_signal_func(lv_obj_t * obj, lv_signal_func_t fp); + +/** + * Set a new design function for an object + * @param obj pointer to an object + * @param fp the new design function + */ +void lv_obj_set_design_func(lv_obj_t * obj, lv_design_func_t fp); + +/*---------------- + * Other set + *--------------*/ + +/** + * Allocate a new ext. data for an object + * @param obj pointer to an object + * @param ext_size the size of the new ext. data + * @return pointer to the allocated ext + */ +void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size); + +/** + * Send a 'LV_SIGNAL_REFR_EXT_SIZE' signal to the object + * @param obj pointer to an object + */ +void lv_obj_refresh_ext_size(lv_obj_t * obj); + +#ifdef LV_OBJ_FREE_NUM_TYPE +/** + * Set an application specific number for an object. + * It can help to identify objects in the application. + * @param obj pointer to an object + * @param free_num the new free number + */ +void lv_obj_set_free_num(lv_obj_t * obj, LV_OBJ_FREE_NUM_TYPE free_num); +#endif + +#if LV_OBJ_FREE_PTR != 0 +/** + * Set an application specific pointer for an object. + * It can help to identify objects in the application. + * @param obj pointer to an object + * @param free_p the new free pinter + */ +void lv_obj_set_free_ptr(lv_obj_t * obj, void * free_p); +#endif + +#if USE_LV_ANIMATION +/** + * Animate an object + * @param obj pointer to an object to animate + * @param type type of animation from 'lv_anim_builtin_t'. 'OR' it with ANIM_IN or ANIM_OUT + * @param time time of animation in milliseconds + * @param delay delay before the animation in milliseconds + * @param cb a function to call when the animation is ready + */ +void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint16_t delay, void (*cb) (lv_obj_t *)); +#endif + +/*======================= + * Getter functions + *======================*/ + +/*------------------ + * Screen get + *-----------------*/ + +/** + * Return with a pointer to the active screen + * @return pointer to the active screen object (loaded by 'lv_scr_load()') + */ +lv_obj_t * lv_scr_act(void); + +/** + * Return with the top layer. (Same on every screen and it is above the normal screen layer) + * @return pointer to the top layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_layer_top(void); + +/** + * Return with the system layer. (Same on every screen and it is above the all other layers) + * It is used for example by the cursor + * @return pointer to the system layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_layer_sys(void); + +/** + * Return with the screen of an object + * @param obj pointer to an object + * @return pointer to a screen + */ +lv_obj_t * lv_obj_get_screen(const lv_obj_t * obj); + +/*--------------------- + * Parent/children get + *--------------------*/ + +/** + * Returns with the parent of an object + * @param obj pointer to an object + * @return pointer to the parent of 'obj' + */ +lv_obj_t * lv_obj_get_parent(const lv_obj_t * obj); + +/** + * Iterate through the children of an object (start from the "youngest, lastly created") + * @param obj pointer to an object + * @param child NULL at first call to get the next children + * and the previous return value later + * @return the child after 'act_child' or NULL if no more child + */ +lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child); + +/** + * Iterate through the children of an object (start from the "oldest", firstly created) + * @param obj pointer to an object + * @param child NULL at first call to get the next children + * and the previous return value later + * @return the child after 'act_child' or NULL if no more child + */ +lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child); + +/** + * Count the children of an object (only children directly on 'obj') + * @param obj pointer to an object + * @return children number of 'obj' + */ +uint16_t lv_obj_count_children(const lv_obj_t * obj); + +/*--------------------- + * Coordinate get + *--------------------*/ + +/** + * Copy the coordinates of an object to an area + * @param obj pointer to an object + * @param cords_p pointer to an area to store the coordinates + */ +void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p); + +/** + * Get the x coordinate of object + * @param obj pointer to an object + * @return distance of 'obj' from the left side of its parent + */ +lv_coord_t lv_obj_get_x(const lv_obj_t * obj); + +/** + * Get the y coordinate of object + * @param obj pointer to an object + * @return distance of 'obj' from the top of its parent + */ +lv_coord_t lv_obj_get_y(const lv_obj_t * obj); + +/** + * Get the width of an object + * @param obj pointer to an object + * @return the width + */ +lv_coord_t lv_obj_get_width(const lv_obj_t * obj); + +/** + * Get the height of an object + * @param obj pointer to an object + * @return the height + */ +lv_coord_t lv_obj_get_height(const lv_obj_t * obj); + +/** + * Get the extended size attribute of an object + * @param obj pointer to an object + * @return the extended size attribute + */ +lv_coord_t lv_obj_get_ext_size(const lv_obj_t * obj); + +/** + * Get the automatic realign property of the object. + * @param obj pointer to an object + * @return true: auto realign is enabled; false: auto realign is disabled + */ +bool lv_obj_get_auto_realign(lv_obj_t * obj); + +/*----------------- + * Appearance get + *---------------*/ + +/** + * Get the style pointer of an object (if NULL get style of the parent) + * @param obj pointer to an object + * @return pointer to a style + */ +lv_style_t * lv_obj_get_style(const lv_obj_t * obj); + +/*----------------- + * Attribute get + *----------------*/ + +/** + * Get the hidden attribute of an object + * @param obj pointer to an object + * @return true: the object is hidden + */ +bool lv_obj_get_hidden(const lv_obj_t * obj); + +/** + * Get the click enable attribute of an object + * @param obj pointer to an object + * @return true: the object is clickable + */ +bool lv_obj_get_click(const lv_obj_t * obj); + +/** + * Get the top enable attribute of an object + * @param obj pointer to an object + * @return true: the auto top feature is enabled + */ +bool lv_obj_get_top(const lv_obj_t * obj); + +/** + * Get the drag enable attribute of an object + * @param obj pointer to an object + * @return true: the object is dragable + */ +bool lv_obj_get_drag(const lv_obj_t * obj); + +/** + * Get the drag throw enable attribute of an object + * @param obj pointer to an object + * @return true: drag throw is enabled + */ +bool lv_obj_get_drag_throw(const lv_obj_t * obj); + +/** + * Get the drag parent attribute of an object + * @param obj pointer to an object + * @return true: drag parent is enabled + */ +bool lv_obj_get_drag_parent(const lv_obj_t * obj); + + +/** + * Get the opa scale enable parameter + * @param obj pointer to an object + * @return true: opa scaling is enabled for this object and all children; false: no opa scaling + */ +lv_opa_t lv_obj_get_opa_scale_enable(const lv_obj_t * obj); + +/** + * Get the opa scale parameter of an object + * @param obj pointer to an object + * @return opa scale [0..255] + */ +lv_opa_t lv_obj_get_opa_scale(const lv_obj_t * obj); + +/** + * Get the protect field of an object + * @param obj pointer to an object + * @return protect field ('OR'ed values of `lv_protect_t`) + */ +uint8_t lv_obj_get_protect(const lv_obj_t * obj); + +/** + * Check at least one bit of a given protect bitfield is set + * @param obj pointer to an object + * @param prot protect bits to test ('OR'ed values of `lv_protect_t`) + * @return false: none of the given bits are set, true: at least one bit is set + */ +bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot); + +/** + * Get the signal function of an object + * @param obj pointer to an object + * @return the signal function + */ +lv_signal_func_t lv_obj_get_signal_func(const lv_obj_t * obj); + +/** + * Get the design function of an object + * @param obj pointer to an object + * @return the design function + */ +lv_design_func_t lv_obj_get_design_func(const lv_obj_t * obj); + +/*------------------ + * Other get + *-----------------*/ + +/** + * Get the ext pointer + * @param obj pointer to an object + * @return the ext pointer but not the dynamic version + * Use it as ext->data1, and NOT da(ext)->data1 + */ +void * lv_obj_get_ext_attr(const lv_obj_t * obj); + +/** + * Get object's and its ancestors type. Put their name in `type_buf` starting with the current type. + * E.g. buf.type[0]="lv_btn", buf.type[1]="lv_cont", buf.type[2]="lv_obj" + * @param obj pointer to an object which type should be get + * @param buf pointer to an `lv_obj_type_t` buffer to store the types + */ +void lv_obj_get_type(lv_obj_t * obj, lv_obj_type_t * buf); + +#ifdef LV_OBJ_FREE_NUM_TYPE +/** + * Get the free number + * @param obj pointer to an object + * @return the free number + */ +LV_OBJ_FREE_NUM_TYPE lv_obj_get_free_num(const lv_obj_t * obj); +#endif + +#if LV_OBJ_FREE_PTR != 0 +/** + * Get the free pointer + * @param obj pointer to an object + * @return the free pointer + */ +void * lv_obj_get_free_ptr(const lv_obj_t * obj); +#endif + +#if USE_LV_GROUP +/** + * Get the group of the object + * @param obj pointer to an object + * @return the pointer to group of the object + */ +void * lv_obj_get_group(const lv_obj_t * obj); + + +/** + * Tell whether the object is the focused object of a group or not. + * @param obj pointer to an object + * @return true: the object is focused, false: the object is not focused or not in a group + */ +bool lv_obj_is_focused(const lv_obj_t * obj); + +#endif + + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_OBJ_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.c b/nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.c new file mode 100644 index 0000000..1087304 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.c @@ -0,0 +1,614 @@ +/** + * @file lv_refr.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_refr.h" +#include "lv_vdb.h" +#include "../lv_hal/lv_hal_tick.h" +#include "../lv_hal/lv_hal_disp.h" +#include "../lv_misc/lv_task.h" +#include "../lv_misc/lv_mem.h" + +/********************* + * DEFINES + *********************/ +#ifndef LV_INV_FIFO_SIZE +#define LV_INV_FIFO_SIZE 32 /*The average count of objects on a screen */ +#endif + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_area_t area; + uint8_t joined; +} lv_join_t; + +/********************** + * STATIC PROTOTYPES + **********************/ +static void lv_refr_task(void * param); +static void lv_refr_join_area(void); +static void lv_refr_areas(void); +#if LV_VDB_SIZE == 0 +static void lv_refr_area_no_vdb(const lv_area_t * area_p); +#else +static void lv_refr_area_with_vdb(const lv_area_t * area_p); +static void lv_refr_area_part_vdb(const lv_area_t * area_p); +#endif +static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj); +static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p); +static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_join_t inv_buf[LV_INV_FIFO_SIZE]; +static uint16_t inv_buf_p; +static void (*monitor_cb)(uint32_t, uint32_t); /*Monitor the rendering time*/ +static void (*round_cb)(lv_area_t *); /*If set then called to modify invalidated areas for special display controllers*/ +static uint32_t px_num; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the screen refresh subsystem + */ +void lv_refr_init(void) +{ + inv_buf_p = 0; + memset(inv_buf, 0, sizeof(inv_buf)); + + lv_task_t * task; + task = lv_task_create(lv_refr_task, LV_REFR_PERIOD, LV_TASK_PRIO_MID, NULL); + lv_task_ready(task); /*Be sure the screen will be refreshed immediately on start up*/ +} + +/** + * Redraw the invalidated areas now. + * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can + * prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar) + * this function can be called when the screen should be updated. + */ +void lv_refr_now(void) +{ + lv_refr_task(NULL); +} + + +/** + * Invalidate an area + * @param area_p pointer to area which should be invalidated + */ +void lv_inv_area(const lv_area_t * area_p) +{ + /*Clear the invalidate buffer if the parameter is NULL*/ + if(area_p == NULL) { + inv_buf_p = 0; + return; + } + + lv_area_t scr_area; + scr_area.x1 = 0; + scr_area.y1 = 0; + scr_area.x2 = LV_HOR_RES - 1; + scr_area.y2 = LV_VER_RES - 1; + + lv_area_t com_area; + bool suc; + + suc = lv_area_intersect(&com_area, area_p, &scr_area); + + /*The area is truncated to the screen*/ + if(suc != false) { + if(round_cb) round_cb(&com_area); + + /*Save only if this area is not in one of the saved areas*/ + uint16_t i; + for(i = 0; i < inv_buf_p; i++) { + if(lv_area_is_in(&com_area, &inv_buf[i].area) != false) return; + } + + /*Save the area*/ + if(inv_buf_p < LV_INV_FIFO_SIZE) { + lv_area_copy(&inv_buf[inv_buf_p].area, &com_area); + } else {/*If no place for the area add the screen*/ + inv_buf_p = 0; + lv_area_copy(&inv_buf[inv_buf_p].area, &scr_area); + } + inv_buf_p ++; + } +} + +/** + * Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels + * @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num)) + * time_ms: refresh time in [ms] + * px_num: not the drawn pixels but the number of affected pixels of the screen + * (more pixels are drawn because of overlapping objects) + */ +void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)) +{ + monitor_cb = cb; +} + +/** + * Called when an area is invalidated to modify the coordinates of the area. + * Special display controllers may require special coordinate rounding + * @param cb pointer to the a function which will modify the area + */ +void lv_refr_set_round_cb(void(*cb)(lv_area_t *)) +{ + round_cb = cb; +} + +/** + * Get the number of areas in the buffer + * @return number of invalid areas + */ +uint16_t lv_refr_get_buf_size(void) +{ + return inv_buf_p; +} + +/** + * Pop (delete) the last 'num' invalidated areas from the buffer + * @param num number of areas to delete + */ +void lv_refr_pop_from_buf(uint16_t num) +{ + if(inv_buf_p < num) inv_buf_p = 0; + else inv_buf_p -= num; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Called periodically to handle the refreshing + * @param param unused + */ +static void lv_refr_task(void * param) +{ + (void)param; + + LV_LOG_TRACE("display refresh task started"); + + uint32_t start = lv_tick_get(); + + if(lv_disp_get_active() == NULL) { + LV_LOG_TRACE("No display is registered"); + return; + } + + lv_refr_join_area(); + + lv_refr_areas(); + + /*If refresh happened ...*/ + if(inv_buf_p != 0) { + + /*In true double buffered mode copy the refreshed areas to the new VDB to keep it up to date*/ +#if LV_VDB_TRUE_DOUBLE_BUFFERED + lv_vdb_t * vdb_p = lv_vdb_get(); + vdb_p->area.x1 = 0; + vdb_p->area.x2 = LV_HOR_RES-1; + vdb_p->area.y1 = 0; + vdb_p->area.y2 = LV_VER_RES - 1; + + /*Flush the content of the VDB*/ + lv_vdb_flush(); + + /* With true double buffering the flushing should be only the address change of the current frame buffer + * Wait until the address change is ready and copy the active content to the other frame buffer (new active VDB) + * The changes will be written to the new VDB.*/ + lv_vdb_t * vdb_act = lv_vdb_get_active(); + lv_vdb_t * vdb_ina = lv_vdb_get_inactive(); + + uint8_t * buf_act = (uint8_t *) vdb_act->buf; + uint8_t * buf_ina = (uint8_t *) vdb_ina->buf; + + uint16_t a; + for(a = 0; a < inv_buf_p; a++) { + if(inv_buf[a].joined == 0) { + lv_coord_t y; + uint32_t start_offs = ((LV_HOR_RES * inv_buf[a].area.y1 + inv_buf[a].area.x1) * LV_VDB_PX_BPP) >> 3; + uint32_t line_length = (lv_area_get_width(&inv_buf[a].area) * LV_VDB_PX_BPP) >> 3; + + for(y = inv_buf[a].area.y1; y <= inv_buf[a].area.y2; y++) { + memcpy(buf_act + start_offs, buf_ina + start_offs, line_length); + start_offs += (LV_HOR_RES * LV_VDB_PX_BPP) >> 3; + } + } + } + +#endif + + /*Clean up*/ + memset(inv_buf, 0, sizeof(inv_buf)); + inv_buf_p = 0; + + /*Call monitor cb if present*/ + if(monitor_cb != NULL) { + monitor_cb(lv_tick_elaps(start), px_num); + } + } + + LV_LOG_TRACE("display refresh task finished"); +} + + +/** + * Join the areas which has got common parts + */ +static void lv_refr_join_area(void) +{ + uint32_t join_from; + uint32_t join_in; + lv_area_t joined_area; + for(join_in = 0; join_in < inv_buf_p; join_in++) { + if(inv_buf[join_in].joined != 0) continue; + + /*Check all areas to join them in 'join_in'*/ + for(join_from = 0; join_from < inv_buf_p; join_from++) { + /*Handle only unjoined areas and ignore itself*/ + if(inv_buf[join_from].joined != 0 || join_in == join_from) { + continue; + } + + /*Check if the areas are on each other*/ + if(lv_area_is_on(&inv_buf[join_in].area, + &inv_buf[join_from].area) == false) { + continue; + } + + lv_area_join(&joined_area, &inv_buf[join_in].area, + &inv_buf[join_from].area); + + /*Join two area only if the joined area size is smaller*/ + if(lv_area_get_size(&joined_area) < + (lv_area_get_size(&inv_buf[join_in].area) + lv_area_get_size(&inv_buf[join_from].area))) { + lv_area_copy(&inv_buf[join_in].area, &joined_area); + + /*Mark 'join_form' is joined into 'join_in'*/ + inv_buf[join_from].joined = 1; + } + } + } +} + +/** + * Refresh the joined areas + */ +static void lv_refr_areas(void) +{ + px_num = 0; + uint32_t i; + + for(i = 0; i < inv_buf_p; i++) { + /*Refresh the unjoined areas*/ + if(inv_buf[i].joined == 0) { + /*If there is no VDB do simple drawing*/ +#if LV_VDB_SIZE == 0 + lv_refr_area_no_vdb(&inv_buf[i].area); +#else + /*If VDB is used...*/ + lv_refr_area_with_vdb(&inv_buf[i].area); +#endif + if(monitor_cb != NULL) px_num += lv_area_get_size(&inv_buf[i].area); + } + } + +} + +#if LV_VDB_SIZE == 0 +/** + * Refresh an area if there is no Virtual Display Buffer + * @param area_p pointer to an area to refresh + */ +static void lv_refr_area_no_vdb(const lv_area_t * area_p) +{ + lv_obj_t * top_p; + + /*Get top object which is not covered by others*/ + top_p = lv_refr_get_top_obj(area_p, lv_scr_act()); + + /*Do the refreshing*/ + lv_refr_obj_and_children(top_p, area_p); + + /*Also refresh top and sys layer unconditionally*/ + lv_refr_obj_and_children(lv_layer_top(), area_p); + lv_refr_obj_and_children(lv_layer_sys(), area_p); +} + +#else + +/** + * Refresh an area if there is Virtual Display Buffer + * @param area_p pointer to an area to refresh + */ +static void lv_refr_area_with_vdb(const lv_area_t * area_p) +{ + +#if LV_VDB_TRUE_DOUBLE_BUFFERED == 0 + /*Calculate the max row num*/ + lv_coord_t w = lv_area_get_width(area_p); + lv_coord_t h = lv_area_get_height(area_p); + lv_coord_t y2 = area_p->y2 >= LV_VER_RES ? y2 = LV_VER_RES - 1 : area_p->y2; + + int32_t max_row = (uint32_t) LV_VDB_SIZE / w; + + if(max_row > h) max_row = h; + + + /*Round down the lines of VDB if rounding is added*/ + if(round_cb) { + lv_area_t tmp; + tmp.x1 = 0; + tmp.x2 = 0; + tmp.y1 = 0; + + lv_coord_t y_tmp = max_row - 1; + do { + tmp.y2 = y_tmp; + round_cb(&tmp); + + /*If this height fits into `max_row` then fine*/ + if(lv_area_get_height(&tmp) <= max_row) break; + + /*Decrement the height of the area until it fits into `max_row` after rounding*/ + y_tmp --; + } while(y_tmp != 0); + + if(y_tmp == 0) { + LV_LOG_WARN("Can't set VDB height using the round function. (Wrong round_cb or to small VDB)"); + return; + } else { + max_row = tmp.y2 + 1; + } + } + + /*Always use the full row*/ + lv_coord_t row; + lv_coord_t row_last = 0; + for(row = area_p->y1; row + max_row - 1 <= y2; row += max_row) { + lv_vdb_t * vdb_p = lv_vdb_get(); + if(!vdb_p) { + LV_LOG_WARN("Invalid VDB pointer"); + return; + } + + /*Calc. the next y coordinates of VDB*/ + vdb_p->area.x1 = area_p->x1; + vdb_p->area.x2 = area_p->x2; + vdb_p->area.y1 = row; + vdb_p->area.y2 = row + max_row - 1; + if(vdb_p->area.y2 > y2) vdb_p->area.y2 = y2; + row_last = vdb_p->area.y2; + lv_refr_area_part_vdb(area_p); + } + + /*If the last y coordinates are not handled yet ...*/ + if(y2 != row_last) { + lv_vdb_t * vdb_p = lv_vdb_get(); + if(!vdb_p) { + LV_LOG_WARN("Invalid VDB pointer"); + return; + } + + /*Calc. the next y coordinates of VDB*/ + vdb_p->area.x1 = area_p->x1; + vdb_p->area.x2 = area_p->x2; + vdb_p->area.y1 = row; + vdb_p->area.y2 = y2; + + /*Refresh this part too*/ + lv_refr_area_part_vdb(area_p); + } +#else + lv_vdb_t * vdb_p = lv_vdb_get(); + vdb_p->area.x1 = 0; + vdb_p->area.x2 = LV_HOR_RES-1; + vdb_p->area.y1 = 0; + vdb_p->area.y2 = LV_VER_RES - 1; + lv_refr_area_part_vdb(area_p); +#endif +} + +/** + * Refresh a part of an area which is on the actual Virtual Display Buffer + * @param area_p pointer to an area to refresh + */ +static void lv_refr_area_part_vdb(const lv_area_t * area_p) +{ + lv_vdb_t * vdb_p = lv_vdb_get(); + if(!vdb_p) { + LV_LOG_WARN("Invalid VDB pointer"); + return; + } + lv_obj_t * top_p; + + /*Get the new mask from the original area and the act. VDB + It will be a part of 'area_p'*/ + lv_area_t start_mask; + lv_area_intersect(&start_mask, area_p, &vdb_p->area); + + /*Get the most top object which is not covered by others*/ + top_p = lv_refr_get_top_obj(&start_mask, lv_scr_act()); + + /*Do the refreshing from the top object*/ + lv_refr_obj_and_children(top_p, &start_mask); + + /*Also refresh top and sys layer unconditionally*/ + lv_refr_obj_and_children(lv_layer_top(), &start_mask); + lv_refr_obj_and_children(lv_layer_sys(), &start_mask); + + /* In true double buffered mode flush only once when all areas were rendered. + * In normal mode flush after every area */ +#if LV_VDB_TRUE_DOUBLE_BUFFERED == 0 + /*Flush the content of the VDB*/ + lv_vdb_flush(); +#endif +} + +#endif /*LV_VDB_SIZE == 0*/ + +/** + * Search the most top object which fully covers an area + * @param area_p pointer to an area + * @param obj the first object to start the searching (typically a screen) + * @return + */ +static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj) +{ + lv_obj_t * i; + lv_obj_t * found_p = NULL; + + /*If this object is fully cover the draw area check the children too */ + if(lv_area_is_in(area_p, &obj->coords) && obj->hidden == 0) { + LL_READ(obj->child_ll, i) { + found_p = lv_refr_get_top_obj(area_p, i); + + /*If a children is ok then break*/ + if(found_p != NULL) { + break; + } + } + + /*If no better children check this object*/ + if(found_p == NULL) { + lv_style_t * style = lv_obj_get_style(obj); + if(style->body.opa == LV_OPA_COVER && + obj->design_func(obj, area_p, LV_DESIGN_COVER_CHK) != false && + lv_obj_get_opa_scale(obj) == LV_OPA_COVER) { + found_p = obj; + } + } + } + + return found_p; +} + +/** + * Make the refreshing from an object. Draw all its children and the youngers too. + * @param top_p pointer to an objects. Start the drawing from it. + * @param mask_p pointer to an area, the objects will be drawn only here + */ +static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p) +{ + /* Normally always will be a top_obj (at least the screen) + * but in special cases (e.g. if the screen has alpha) it won't. + * In this case use the screen directly */ + if(top_p == NULL) top_p = lv_scr_act(); + + /*Refresh the top object and its children*/ + lv_refr_obj(top_p, mask_p); + + /*Draw the 'younger' sibling objects because they can be on top_obj */ + lv_obj_t * par; + lv_obj_t * i; + lv_obj_t * border_p = top_p; + + par = lv_obj_get_parent(top_p); + + /*Do until not reach the screen*/ + while(par != NULL) { + /*object before border_p has to be redrawn*/ + i = lv_ll_get_prev(&(par->child_ll), border_p); + + while(i != NULL) { + /*Refresh the objects*/ + lv_refr_obj(i, mask_p); + i = lv_ll_get_prev(&(par->child_ll), i); + } + + /*The new border will be there last parents, + *so the 'younger' brothers of parent will be refreshed*/ + border_p = par; + /*Go a level deeper*/ + par = lv_obj_get_parent(par); + } + + /*Call the post draw design function of the parents of the to object*/ + par = lv_obj_get_parent(top_p); + while(par != NULL) { + par->design_func(par, mask_p, LV_DESIGN_DRAW_POST); + par = lv_obj_get_parent(par); + } +} + +/** + * Refresh an object an all of its children. (Called recursively) + * @param obj pointer to an object to refresh + * @param mask_ori_p pointer to an area, the objects will be drawn only here + */ +static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p) +{ + /*Do not refresh hidden objects*/ + if(obj->hidden != 0) return; + + bool union_ok; /* Store the return value of area_union */ + /* Truncate the original mask to the coordinates of the parent + * because the parent and its children are visible only here */ + lv_area_t obj_mask; + lv_area_t obj_ext_mask; + lv_area_t obj_area; + lv_coord_t ext_size = obj->ext_size; + lv_obj_get_coords(obj, &obj_area); + obj_area.x1 -= ext_size; + obj_area.y1 -= ext_size; + obj_area.x2 += ext_size; + obj_area.y2 += ext_size; + union_ok = lv_area_intersect(&obj_ext_mask, mask_ori_p, &obj_area); + + /*Draw the parent and its children only if they ore on 'mask_parent'*/ + if(union_ok != false) { + + /* Redraw the object */ + obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_MAIN); + //usleep(5 * 1000); /*DEBUG: Wait after every object draw to see the order of drawing*/ + + + /*Create a new 'obj_mask' without 'ext_size' because the children can't be visible there*/ + lv_obj_get_coords(obj, &obj_area); + union_ok = lv_area_intersect(&obj_mask, mask_ori_p, &obj_area); + if(union_ok != false) { + lv_area_t mask_child; /*Mask from obj and its child*/ + lv_obj_t * child_p; + lv_area_t child_area; + LL_READ_BACK(obj->child_ll, child_p) { + lv_obj_get_coords(child_p, &child_area); + ext_size = child_p->ext_size; + child_area.x1 -= ext_size; + child_area.y1 -= ext_size; + child_area.x2 += ext_size; + child_area.y2 += ext_size; + /* Get the union (common parts) of original mask (from obj) + * and its child */ + union_ok = lv_area_intersect(&mask_child, &obj_mask, &child_area); + + /*If the parent and the child has common area then refresh the child */ + if(union_ok) { + /*Refresh the next children*/ + lv_refr_obj(child_p, &mask_child); + } + } + } + + /* If all the children are redrawn make 'post draw' design */ + obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_POST); + + } +} diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.h b/nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.h new file mode 100644 index 0000000..b93cb10 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_refr.h @@ -0,0 +1,94 @@ +/** + * @file lv_refr.h + * + */ + +#ifndef LV_REFR_H +#define LV_REFR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the screen refresh subsystem + */ +void lv_refr_init(void); + +/** + * Redraw the invalidated areas now. + * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can + * prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar) + * this function can be called when the screen should be updated. + */ +void lv_refr_now(void); + +/** + * Invalidate an area + * @param area_p pointer to area which should be invalidated + */ +void lv_inv_area(const lv_area_t * area_p); + +/** + * Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels + * @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num)) + */ +void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)); + +/** + * Called when an area is invalidated to modify the coordinates of the area. + * Special display controllers may require special coordinate rounding + * @param cb pointer to the a function which will modify the area + */ +void lv_refr_set_round_cb(void(*cb)(lv_area_t*)); + +/** + * Get the number of areas in the buffer + * @return number of invalid areas + */ +uint16_t lv_refr_get_buf_size(void); + +/** + * Pop (delete) the last 'num' invalidated areas from the buffer + * @param num number of areas to delete + */ +void lv_refr_pop_from_buf(uint16_t num); +/********************** + * STATIC FUNCTIONS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_REFR_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_style.c b/nyx/nyx_gui/libs/lvgl/lv_core/lv_style.c new file mode 100644 index 0000000..02fbcb2 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_style.c @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" +#include "../lv_misc/lv_mem.h" + +/********************* + * DEFINES + *********************/ +#define STYLE_MIX_MAX 256 +#define STYLE_MIX_SHIFT 8 /*log2(STYLE_MIX_MAX)*/ + +#define VAL_PROP(v1, v2, r) v1 + (((v2-v1) * r) >> STYLE_MIX_SHIFT) +#define STYLE_ATTR_MIX(attr, r) if(start->attr != end->attr) {res->attr = VAL_PROP(start->attr, end->attr, r);} else {res->attr = start->attr;} + + +/********************** + * TYPEDEFS + **********************/ +#if USE_LV_ANIMATION +typedef struct { + lv_style_t style_start; /*Save not only pointers because can be same as 'style_anim' then it will be modified too*/ + lv_style_t style_end; + lv_style_t * style_anim; + void (*end_cb)(void *); +} lv_style_anim_dsc_t; +#endif + +/********************** + * STATIC PROTOTYPES + **********************/ +#if USE_LV_ANIMATION +static void style_animator(lv_style_anim_dsc_t * dsc, int32_t val); +static void style_animation_common_end_cb(void * ptr); +#endif + +/********************** + * STATIC VARIABLES + **********************/ +lv_style_t lv_style_scr; +lv_style_t lv_style_transp; +lv_style_t lv_style_transp_fit; +lv_style_t lv_style_transp_tight; +lv_style_t lv_style_plain; +lv_style_t lv_style_plain_color; +lv_style_t lv_style_pretty; +lv_style_t lv_style_pretty_color; +lv_style_t lv_style_btn_rel; +lv_style_t lv_style_btn_pr; +lv_style_t lv_style_btn_tgl_rel; +lv_style_t lv_style_btn_tgl_pr; +lv_style_t lv_style_btn_ina; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Init the basic styles + */ +void lv_style_init(void) +{ + /* Not White/Black/Gray colors are created by HSV model with + * HUE = 210*/ + + /*Screen style*/ + lv_style_scr.glass = 0; + lv_style_scr.body.opa = LV_OPA_COVER; + lv_style_scr.body.main_color = LV_COLOR_BLACK; + lv_style_scr.body.grad_color = LV_COLOR_BLACK; + lv_style_scr.body.radius = 0; + lv_style_scr.body.padding.ver = LV_DPI / 12; + lv_style_scr.body.padding.hor = LV_DPI / 12; + lv_style_scr.body.padding.inner = LV_DPI / 12; + + lv_style_scr.body.border.color = LV_COLOR_WHITE; + lv_style_scr.body.border.opa = LV_OPA_COVER; + lv_style_scr.body.border.width = 0; + lv_style_scr.body.border.part = LV_BORDER_FULL; + + lv_style_scr.body.shadow.color = LV_COLOR_GRAY; + lv_style_scr.body.shadow.type = LV_SHADOW_FULL; + lv_style_scr.body.shadow.width = 0; + + lv_style_scr.text.opa = LV_OPA_COVER; + lv_style_scr.text.color = LV_COLOR_HEX(0xFBFBFB); + lv_style_scr.text.font = LV_FONT_DEFAULT; + lv_style_scr.text.letter_space = 3; // Important + lv_style_scr.text.line_space = 2; + + lv_style_scr.image.opa = LV_OPA_COVER; + lv_style_scr.image.color = LV_COLOR_MAKE(0x20, 0x20, 0x20); + lv_style_scr.image.intense = LV_OPA_TRANSP; + + lv_style_scr.line.opa = LV_OPA_COVER; + lv_style_scr.line.color = LV_COLOR_MAKE(0x20, 0x20, 0x20); + lv_style_scr.line.width = 2; + lv_style_scr.line.rounded = 0; + + /*Plain style (by default near the same as the screen style)*/ + memcpy(&lv_style_plain, &lv_style_scr, sizeof(lv_style_t)); + + /*Plain color style*/ + memcpy(&lv_style_plain_color, &lv_style_plain, sizeof(lv_style_t)); + lv_style_plain_color.text.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0); + lv_style_plain_color.image.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0); + lv_style_plain_color.line.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0); + lv_style_plain_color.body.main_color = LV_COLOR_MAKE(0x55, 0x96, 0xd8); + lv_style_plain_color.body.grad_color = lv_style_plain_color.body.main_color; + + /*Pretty style */ + memcpy(&lv_style_pretty, &lv_style_plain, sizeof(lv_style_t)); + lv_style_pretty.text.color = LV_COLOR_MAKE(0x20, 0x20, 0x20); + lv_style_pretty.image.color = LV_COLOR_MAKE(0x20, 0x20, 0x20); + lv_style_pretty.line.color = LV_COLOR_MAKE(0x20, 0x20, 0x20); + lv_style_pretty.body.main_color = LV_COLOR_WHITE; + lv_style_pretty.body.grad_color = LV_COLOR_SILVER; + lv_style_pretty.body.radius = LV_DPI / 15; + lv_style_pretty.body.border.color = LV_COLOR_MAKE(0x40, 0x40, 0x40); + lv_style_pretty.body.border.width = LV_DPI / 50 >= 1 ? LV_DPI / 50 : 1; + lv_style_pretty.body.border.opa = LV_OPA_30; + + /*Pretty color style*/ + memcpy(&lv_style_pretty_color, &lv_style_pretty, sizeof(lv_style_t)); + lv_style_pretty_color.text.color = LV_COLOR_MAKE(0xe0, 0xe0, 0xe0); + lv_style_pretty_color.image.color = LV_COLOR_MAKE(0xe0, 0xe0, 0xe0); + lv_style_pretty_color.line.color = LV_COLOR_MAKE(0xc0, 0xc0, 0xc0); + lv_style_pretty_color.body.main_color = LV_COLOR_MAKE(0x6b, 0x9a, 0xc7); + lv_style_pretty_color.body.grad_color = LV_COLOR_MAKE(0x2b, 0x59, 0x8b); + lv_style_pretty_color.body.border.color = LV_COLOR_MAKE(0x15, 0x2c, 0x42); + + /*Transparent style*/ + memcpy(&lv_style_transp, &lv_style_plain, sizeof(lv_style_t)); + lv_style_transp.body.empty = 1; + lv_style_transp.glass = 1; + lv_style_transp.body.border.width = 0; + + /*Transparent fitting size*/ + memcpy(&lv_style_transp_fit, &lv_style_transp, sizeof(lv_style_t)); + lv_style_transp_fit.body.padding.hor = 0; + lv_style_transp_fit.body.padding.ver = 0; + + /*Transparent tight style*/ + memcpy(&lv_style_transp_tight, &lv_style_transp_fit, sizeof(lv_style_t)); + lv_style_transp_tight.body.padding.inner = 0; + + /*Button released style*/ + memcpy(&lv_style_btn_rel, &lv_style_plain, sizeof(lv_style_t)); + lv_style_btn_rel.body.main_color = LV_COLOR_MAKE(0x76, 0xa2, 0xd0); + lv_style_btn_rel.body.grad_color = LV_COLOR_MAKE(0x19, 0x3a, 0x5d); + lv_style_btn_rel.body.radius = LV_DPI / 15; + lv_style_btn_rel.body.padding.hor = LV_DPI / 4; + lv_style_btn_rel.body.padding.ver = LV_DPI / 6; + lv_style_btn_rel.body.padding.inner = LV_DPI / 10; + lv_style_btn_rel.body.border.color = LV_COLOR_MAKE(0x0b, 0x19, 0x28); + lv_style_btn_rel.body.border.width = LV_DPI / 50 >= 1 ? LV_DPI / 50 : 1; + lv_style_btn_rel.body.border.opa = LV_OPA_70; + lv_style_btn_rel.body.shadow.color = LV_COLOR_GRAY; + lv_style_btn_rel.body.shadow.width = 0; + lv_style_btn_rel.text.color = LV_COLOR_MAKE(0xff, 0xff, 0xff); + lv_style_btn_rel.image.color = LV_COLOR_MAKE(0xff, 0xff, 0xff); + + /*Button pressed style*/ + memcpy(&lv_style_btn_pr, &lv_style_btn_rel, sizeof(lv_style_t)); + lv_style_btn_pr.body.main_color = LV_COLOR_MAKE(0x33, 0x62, 0x94); + lv_style_btn_pr.body.grad_color = LV_COLOR_MAKE(0x10, 0x26, 0x3c); + lv_style_btn_pr.text.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6); + lv_style_btn_pr.image.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6); + lv_style_btn_pr.line.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6); + + /*Button toggle released style*/ + memcpy(&lv_style_btn_tgl_rel, &lv_style_btn_rel, sizeof(lv_style_t)); + lv_style_btn_tgl_rel.body.main_color = LV_COLOR_MAKE(0x0a, 0x11, 0x22); + lv_style_btn_tgl_rel.body.grad_color = LV_COLOR_MAKE(0x37, 0x62, 0x90); + lv_style_btn_tgl_rel.body.border.color = LV_COLOR_MAKE(0x01, 0x07, 0x0d); + lv_style_btn_tgl_rel.text.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4); + lv_style_btn_tgl_rel.image.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4); + lv_style_btn_tgl_rel.line.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4); + + /*Button toggle pressed style*/ + memcpy(&lv_style_btn_tgl_pr, &lv_style_btn_tgl_rel, sizeof(lv_style_t)); + lv_style_btn_tgl_pr.body.main_color = LV_COLOR_MAKE(0x02, 0x14, 0x27); + lv_style_btn_tgl_pr.body.grad_color = LV_COLOR_MAKE(0x2b, 0x4c, 0x70); + lv_style_btn_tgl_pr.text.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6); + lv_style_btn_tgl_pr.image.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6); + lv_style_btn_tgl_pr.line.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6); + + /*Button inactive style*/ + memcpy(&lv_style_btn_ina, &lv_style_btn_rel, sizeof(lv_style_t)); + lv_style_btn_ina.body.main_color = LV_COLOR_MAKE(0xd8, 0xd8, 0xd8); + lv_style_btn_ina.body.grad_color = LV_COLOR_MAKE(0xd8, 0xd8, 0xd8); + lv_style_btn_ina.body.border.color = LV_COLOR_MAKE(0x90, 0x90, 0x90); + lv_style_btn_ina.text.color = LV_COLOR_MAKE(0x70, 0x70, 0x70); + lv_style_btn_ina.image.color = LV_COLOR_MAKE(0x70, 0x70, 0x70); + lv_style_btn_ina.line.color = LV_COLOR_MAKE(0x70, 0x70, 0x70); +} + + +/** + * Copy a style to an other + * @param dest pointer to the destination style + * @param src pointer to the source style + */ +void lv_style_copy(lv_style_t * dest, const lv_style_t * src) +{ + memcpy(dest, src, sizeof(lv_style_t)); +} + + +/** + * Mix two styles according to a given ratio + * @param start start style + * @param end end style + * @param res store the result style here + * @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style + */ +void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio) +{ + STYLE_ATTR_MIX(body.opa, ratio); + STYLE_ATTR_MIX(body.radius, ratio); + STYLE_ATTR_MIX(body.border.width, ratio); + STYLE_ATTR_MIX(body.border.opa, ratio); + STYLE_ATTR_MIX(body.shadow.width, ratio); + STYLE_ATTR_MIX(body.padding.hor, ratio); + STYLE_ATTR_MIX(body.padding.ver, ratio); + STYLE_ATTR_MIX(body.padding.inner, ratio); + STYLE_ATTR_MIX(text.line_space, ratio); + STYLE_ATTR_MIX(text.letter_space, ratio); + STYLE_ATTR_MIX(text.opa, ratio); + STYLE_ATTR_MIX(line.width, ratio); + STYLE_ATTR_MIX(line.opa, ratio); + STYLE_ATTR_MIX(image.intense, ratio); + STYLE_ATTR_MIX(image.opa, ratio); + + lv_opa_t opa = ratio == STYLE_MIX_MAX ? LV_OPA_COVER : ratio; + + res->body.main_color = lv_color_mix(end->body.main_color, start->body.main_color, opa); + res->body.grad_color = lv_color_mix(end->body.grad_color, start->body.grad_color, opa); + res->body.border.color = lv_color_mix(end->body.border.color, start->body.border.color, opa); + res->body.shadow.color = lv_color_mix(end->body.shadow.color, start->body.shadow.color, opa); + res->text.color = lv_color_mix(end->text.color, start->text.color, opa); + res->image.color = lv_color_mix(end->image.color, start->image.color, opa); + res->line.color = lv_color_mix(end->line.color, start->line.color, opa); + + if(ratio < (STYLE_MIX_MAX >> 1)) { + res->body.empty = start->body.empty; + res->body.border.part = start->body.border.part; + res->glass = start->glass; + res->text.font = start->text.font; + res->body.shadow.type = start->body.shadow.type; + res->line.rounded = start->line.rounded; + } else { + res->body.empty = end->body.empty; + res->body.border.part = end->body.border.part; + res->glass = end->glass; + res->text.font = end->text.font; + res->body.shadow.type = end->body.shadow.type; + res->line.rounded = end->line.rounded; + } +} + +#if USE_LV_ANIMATION + +/** + * Create an animation from a pre-configured 'lv_style_anim_t' variable + * @param anim pointer to a pre-configured 'lv_style_anim_t' variable (will be copied) + * @return pointer to a descriptor. Really this variable will be animated. (Can be used in `lv_anim_del(dsc, NULL)`) + */ +void * lv_style_anim_create(lv_style_anim_t * anim) +{ + lv_style_anim_dsc_t * dsc; + dsc = lv_mem_alloc(sizeof(lv_style_anim_dsc_t)); + lv_mem_assert(dsc); + if(dsc == NULL) return NULL; + + dsc->style_anim = anim->style_anim; + memcpy(&dsc->style_start, anim->style_start, sizeof(lv_style_t)); + memcpy(&dsc->style_end, anim->style_end, sizeof(lv_style_t)); + memcpy(dsc->style_anim, anim->style_start, sizeof(lv_style_t)); + dsc->end_cb = anim->end_cb; + + + lv_anim_t a; + a.var = (void *)dsc; + a.start = 0; + a.end = STYLE_MIX_MAX; + a.fp = (lv_anim_fp_t)style_animator; + a.path = lv_anim_path_linear; + a.end_cb = style_animation_common_end_cb; + a.act_time = anim->act_time; + a.time = anim->time; + a.playback = anim->playback; + a.playback_pause = anim->playback_pause; + a.repeat = anim->repeat; + a.repeat_pause = anim->repeat_pause; + + lv_anim_create(&a); + + return dsc; +} + +#endif +/********************** + * STATIC FUNCTIONS + **********************/ +#if USE_LV_ANIMATION +/** + * Used by the style animations to set the values of a style according to start and end style. + * @param dsc the 'animated variable' set by lv_style_anim_create() + * @param val the current state of the animation between 0 and LV_STYLE_ANIM_RES + */ +static void style_animator(lv_style_anim_dsc_t * dsc, int32_t val) +{ + const lv_style_t * start = &dsc->style_start; + const lv_style_t * end = &dsc->style_end; + lv_style_t * act = dsc->style_anim; + + lv_style_mix(start, end, act, val); + + lv_obj_report_style_mod(dsc->style_anim); +} + +/** + * Called when a style animation is ready + * It called the user defined call back and free the allocated memories + * @param ptr the 'animated variable' set by lv_style_anim_create() + */ +static void style_animation_common_end_cb(void * ptr) +{ + lv_style_anim_dsc_t * dsc = ptr; /*To avoid casting*/ + + if(dsc->end_cb) dsc->end_cb(dsc); + + lv_mem_free(dsc); +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_style.h b/nyx/nyx_gui/libs/lvgl/lv_core/lv_style.h new file mode 100644 index 0000000..0ba03c8 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_style.h @@ -0,0 +1,198 @@ +/** + * @file lv_style.h + * + */ + +#ifndef LV_STYLE_H +#define LV_STYLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_area.h" +#include "../lv_misc/lv_font.h" +#include "../lv_misc/lv_anim.h" + +/********************* + * DEFINES + *********************/ +#define LV_RADIUS_CIRCLE (LV_COORD_MAX) /*A very big radius to always draw as circle*/ + +/********************** + * TYPEDEFS + **********************/ + +/*Border types (Use 'OR'ed values)*/ +enum +{ + LV_BORDER_NONE = 0x00, + LV_BORDER_BOTTOM = 0x01, + LV_BORDER_TOP = 0x02, + LV_BORDER_LEFT = 0x04, + LV_BORDER_RIGHT = 0x08, + LV_BORDER_FULL = 0x0F, + LV_BORDER_INTERNAL = 0x10, /*FOR matrix-like objects (e.g. Button matrix)*/ +}; +typedef uint8_t lv_border_part_t; + +/*Shadow types*/ +enum +{ + LV_SHADOW_BOTTOM = 0, + LV_SHADOW_FULL, +}; +typedef uint8_t lv_shadow_type_t; + +typedef struct +{ + uint8_t glass :1; /*1: Do not inherit this style*/ + + struct { + lv_color_t main_color; + lv_color_t grad_color; /*`grad_color` will be removed in v6.0, use `aux_color` instead*/ + lv_coord_t radius; + lv_opa_t opa; + + struct { + lv_color_t color; + lv_coord_t width; + lv_border_part_t part; + lv_opa_t opa; + } border; + + struct { + lv_color_t color; + lv_coord_t width; + lv_shadow_type_t type; + } shadow; + + struct { + lv_coord_t ver; + lv_coord_t hor; + lv_coord_t inner; + } padding; + + uint8_t empty :1; /*Transparent background (border still drawn)*/ + } body; + + + struct { + lv_color_t color; + const lv_font_t * font; + lv_coord_t letter_space; + lv_coord_t line_space; + lv_opa_t opa; + } text; + + struct { + lv_color_t color; + lv_opa_t intense; + lv_opa_t opa; + } image; + + struct { + lv_color_t color; + lv_coord_t width; + lv_opa_t opa; + uint8_t rounded :1; /*1: rounded line endings*/ + } line; +} lv_style_t; + +#if USE_LV_ANIMATION +typedef struct { + const lv_style_t * style_start; /*Pointer to the starting style*/ + const lv_style_t * style_end; /*Pointer to the destination style*/ + lv_style_t * style_anim; /*Pointer to a style to animate*/ + lv_anim_cb_t end_cb; /*Call it when the animation is ready (NULL if unused)*/ + int16_t time; /*Animation time in ms*/ + int16_t act_time; /*Current time in animation. Set to negative to make delay.*/ + uint16_t playback_pause; /*Wait before play back*/ + uint16_t repeat_pause; /*Wait before repeat*/ + uint8_t playback :1; /*When the animation is ready play it back*/ + uint8_t repeat :1; /*Repeat the animation infinitely*/ +} lv_style_anim_t; + +/* Example initialization +lv_style_anim_t a; +a.style_anim = &style_to_anim; +a.style_start = &style_1; +a.style_end = &style_2; +a.act_time = 0; +a.time = 1000; +a.playback = 0; +a.playback_pause = 0; +a.repeat = 0; +a.repeat_pause = 0; +a.end_cb = NULL; +lv_style_anim_create(&a); + */ +#endif + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Init the basic styles + */ +void lv_style_init (void); + +/** + * Copy a style to an other + * @param dest pointer to the destination style + * @param src pointer to the source style + */ +void lv_style_copy(lv_style_t * dest, const lv_style_t * src); + + +/** + * Mix two styles according to a given ratio + * @param start start style + * @param end end style + * @param res store the result style here + * @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style + */ +void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio); + +#if USE_LV_ANIMATION + +/** + * Create an animation from a pre-configured 'lv_style_anim_t' variable + * @param anim pointer to a pre-configured 'lv_style_anim_t' variable (will be copied) + * @return pointer to a descriptor. Really this variable will be animated. (Can be used in `lv_anim_del(dsc, NULL)`) + */ +void * lv_style_anim_create(lv_style_anim_t * anim); +#endif + +/************************* + * GLOBAL VARIABLES + *************************/ +extern lv_style_t lv_style_scr; +extern lv_style_t lv_style_transp; +extern lv_style_t lv_style_transp_fit; +extern lv_style_t lv_style_transp_tight; +extern lv_style_t lv_style_plain; +extern lv_style_t lv_style_plain_color; +extern lv_style_t lv_style_pretty; +extern lv_style_t lv_style_pretty_color; +extern lv_style_t lv_style_btn_rel; +extern lv_style_t lv_style_btn_pr; +extern lv_style_t lv_style_btn_tgl_rel; +extern lv_style_t lv_style_btn_tgl_pr; +extern lv_style_t lv_style_btn_ina; + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_STYLE_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.c b/nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.c new file mode 100644 index 0000000..38aae34 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.c @@ -0,0 +1,207 @@ +/** + * @file lv_vdb.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_vdb.h" +#if LV_VDB_SIZE != 0 + +#include "../lv_hal/lv_hal_disp.h" +#include "../lv_misc/lv_log.h" +#include + +/********************* + * DEFINES + *********************/ +#ifndef LV_ATTRIBUTE_FLUSH_READY +#define LV_ATTRIBUTE_FLUSH_READY +#endif + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/*Simple VDB*/ +#if LV_VDB_DOUBLE == 0 +# if LV_VDB_ADR == 0 +/*If the buffer address is not specified simply allocate it*/ +static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf[LV_VDB_SIZE_IN_BYTES]; +static lv_vdb_t vdb = {.buf = (lv_color_t *)vdb_buf}; +# else /*LV_VDB_ADR != 0*/ +/*If the buffer address is specified use that address*/ +static lv_vdb_t vdb = {.buf = (lv_color_t *)LV_VDB_ADR}; +# endif + +/*LV_VDB_DOUBLE != 0*/ +#else +/*Double VDB*/ +static uint8_t vdb_active = 0; +# if LV_VDB_ADR == 0 +/*If the buffer address is not specified simply allocate it*/ +static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf1[LV_VDB_SIZE_IN_BYTES]; +static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf2[LV_VDB_SIZE_IN_BYTES]; +static lv_vdb_t vdb[2] = {{.buf = (lv_color_t *) vdb_buf1}, {.buf = (lv_color_t *) vdb_buf2}}; +# else /*LV_VDB_ADR != 0*/ +/*If the buffer address is specified use that address*/ +static lv_vdb_t vdb[2] = {{.buf = (lv_color_t *)LV_VDB_ADR}, {.buf = (lv_color_t *)LV_VDB2_ADR}}; +# endif +#endif + +static volatile bool vdb_flushing = false; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode + * @return pointer to a 'vdb' variable + */ +lv_vdb_t * lv_vdb_get(void) +{ +#if LV_VDB_DOUBLE == 0 + /* Wait until VDB is flushing. + * (Until this user calls of 'lv_flush_ready()' in the display drivers's flush function*/ + while(vdb_flushing); + + return &vdb; +#else + /*If already there is an active do nothing*/ + return &vdb[vdb_active]; +#endif +} + +/** + * Flush the content of the VDB + */ +void lv_vdb_flush(void) +{ + lv_vdb_t * vdb_act = lv_vdb_get(); + if(!vdb_act) { + LV_LOG_WARN("Invalid VDB pointer"); + return; + } + + /*Don't start a new flush while the previous is not finished*/ +#if LV_VDB_DOUBLE + while(vdb_flushing); +#endif /*LV_VDB_DOUBLE*/ + + vdb_flushing = true; + + /*Flush the rendered content to the display*/ + lv_disp_flush(vdb_act->area.x1, vdb_act->area.y1, vdb_act->area.x2, vdb_act->area.y2, vdb_act->buf); + + +#if LV_VDB_DOUBLE + /*Make the other VDB active. The content of the current will be kept until the next flush*/ + vdb_active++; + vdb_active &= 0x1; + + /*If the screen is transparent initialize it when the new VDB is selected*/ +# if LV_COLOR_SCREEN_TRANSP + memset(vdb[vdb_active].buf, 0x00, LV_VDB_SIZE_IN_BYTES); +# endif /*LV_COLOR_SCREEN_TRANSP*/ + +#endif /*#if LV_VDB_DOUBLE*/ + +} + +/** + * Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`. + * It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES` + * @param buf1 address of the VDB. + * @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0` + */ +void lv_vdb_set_adr(void * buf1, void * buf2) +{ +#if LV_VDB_DOUBLE == 0 + (void) buf2; /*unused*/ + vdb.buf = buf1; +#else + vdb[0].buf = buf1; + vdb[1].buf = buf2; +#endif +} + +/** + * Call in the display driver's 'disp_flush' function when the flushing is finished + */ +LV_ATTRIBUTE_FLUSH_READY void lv_flush_ready(void) +{ + vdb_flushing = false; + + /*If the screen is transparent initialize it when the flushing is ready*/ +#if LV_VDB_DOUBLE == 0 && LV_COLOR_SCREEN_TRANSP + memset(vdb_buf, 0x00, LV_VDB_SIZE_IN_BYTES); +#endif +} + +/** + * Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1` + * @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB + */ +lv_vdb_t * lv_vdb_get_active(void) +{ +#if LV_VDB_DOUBLE == 0 + return &vdb; +#else + return &vdb[vdb_active]; +#endif +} + +/** + * Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1` + * @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB + */ +lv_vdb_t * lv_vdb_get_inactive(void) +{ +#if LV_VDB_DOUBLE == 0 + return &vdb; +#else + return &vdb[(vdb_active + 1) & 0x1]; +#endif +} + +/** + * Whether the flushing is in progress or not + * @return true: flushing is in progress; false: flushing ready + */ +bool lv_vdb_is_flushing(void) +{ + return vdb_flushing; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#else + +/** + * Just for compatibility + */ +void lv_flush_ready(void) +{ + /*Do nothing. It is used only for VDB*/ +} +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.h b/nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.h new file mode 100644 index 0000000..e94ba19 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_core/lv_vdb.h @@ -0,0 +1,119 @@ +/** + * @file lv_vdb.h + * + */ + +#ifndef LV_VDB_H +#define LV_VDB_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if LV_VDB_SIZE != 0 + +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_area.h" + +/********************* + * DEFINES + *********************/ +/*Can be used in `lv_conf.h` the set an invalid address for the VDB. It should be replaced later by a valid address using `lv_vdb_set_adr()`*/ +#define LV_VDB_ADR_INV 8 /*8 is still too small to be valid but it's aligned on 64 bit machines as well*/ + +#ifndef LV_VDB_PX_BPP +#define LV_VDB_PX_BPP LV_COLOR_SIZE /* Default is LV_COLOR_SIZE */ +#endif + + +#if LV_VDB_TRUE_DOUBLE_BUFFERED && (LV_VDB_SIZE != LV_HOR_RES * LV_VER_RES || LV_VDB_DOUBLE == 0) +#error "With LV_VDB_TRUE_DOUBLE_BUFFERED: (LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES and LV_VDB_DOUBLE = 1 is required" +#endif + + +/* The size of VDB in bytes. + * (LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3): just divide by 8 to convert bits to bytes + * (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0): add an extra byte to round up. + * E.g. if LV_VDB_SIZE = 10 and LV_VDB_PX_BPP = 1 -> 10 bits -> 2 bytes*/ +#define LV_VDB_SIZE_IN_BYTES ((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0) + +/********************** + * TYPEDEFS + **********************/ + +typedef struct +{ + lv_area_t area; + lv_color_t *buf; +} lv_vdb_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode + * @return pointer to a 'vdb' variable + */ +lv_vdb_t * lv_vdb_get(void); + +/** + * Flush the content of the vdb + */ +void lv_vdb_flush(void); + +/** + * Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`. + * It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES` + * @param buf1 address of the VDB. + * @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0` + */ +void lv_vdb_set_adr(void * buf1, void * buf2); + +/** + * Call in the display driver's 'disp_flush' function when the flushing is finished + */ +void lv_flush_ready(void); + +/** + * Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1` + * @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB + */ +lv_vdb_t * lv_vdb_get_active(void); + +/** + * Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1` + * @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB + */ +lv_vdb_t * lv_vdb_get_inactive(void); + +/** + * Whether the flushing is in progress or not + * @return true: flushing is in progress; false: flushing ready + */ +bool lv_vdb_is_flushing(void); + +/********************** + * MACROS + **********************/ + +#else /*LV_VDB_SIZE != 0*/ + +/*Just for compatibility*/ +void lv_flush_ready(void); +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_VDB_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.c new file mode 100644 index 0000000..af374e3 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.c @@ -0,0 +1,163 @@ +/** + * @file lv_draw.c + * + */ + +/********************* + * INCLUDES + *********************/ + +#include +#include "lv_draw.h" +#include "lv_draw_rbasic.h" +#include "lv_draw_vbasic.h" +#include "../lv_misc/lv_fs.h" +#include "../lv_misc/lv_math.h" +#include "../lv_misc/lv_ufs.h" +#include "../lv_objx/lv_img.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +#if LV_VDB_SIZE != 0 +void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_vpx; +void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_vfill; +void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa) = lv_vletter; +void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p, + const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, + lv_color_t recolor, lv_opa_t recolor_opa) = lv_vmap; +#else +void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_rpx; +void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_rfill; +void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa) = lv_rletter; +void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p, + const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, + lv_color_t recolor, lv_opa_t recolor_opa) = lv_rmap; +#endif + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/********************** + * STATIC FUNCTIONS + **********************/ + +#if LV_ANTIALIAS != 0 + +/** + * Get the opacity of a pixel based it's position in a line segment + * @param seg segment length + * @param px_id position of of a pixel which opacity should be get [0..seg-1] + * @param base_opa the base opacity + * @return the opacity of the given pixel + */ +lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa) +{ + /* How to calculate the opacity of pixels on the edges which makes the anti-aliasing? + * For example we have a line like this (y = -0.5 * x): + * + * | _ _ + * * * | + * + * Anti-aliased pixels come to the '*' characters + * Calculate what percentage of the pixels should be covered if real line (not rasterized) would be drawn: + * 1. A real line should start on (0;0) and end on (2;1) + * 2. So the line intersection coordinates on the first pixel: (0;0) (1;0.5) -> 25% covered pixel in average + * 3. For the second pixel: (1;0.5) (2;1) -> 75% covered pixel in average + * 4. The equation: (px_id * 2 + 1) / (segment_width * 2) + * segment_width: the line segment which is being anti-aliased (was 2 in the example) + * px_id: pixel ID from 0 to (segment_width - 1) + * result: [0..1] coverage of the pixel + */ + + /*Accelerate the common segment sizes to avoid division*/ + static const lv_opa_t seg1[1] = {128}; + static const lv_opa_t seg2[2] = {64, 192}; + static const lv_opa_t seg3[3] = {42, 128, 212}; + static const lv_opa_t seg4[4] = {32, 96, 159, 223}; + static const lv_opa_t seg5[5] = {26, 76, 128, 178, 230}; + static const lv_opa_t seg6[6] = {21, 64, 106, 148, 191, 234}; + static const lv_opa_t seg7[7] = {18, 55, 91, 128, 164, 200, 237}; + static const lv_opa_t seg8[8] = {16, 48, 80, 112, 143, 175, 207, 239}; + + static const lv_opa_t * seg_map[] = {seg1, seg2, seg3, seg4, + seg5, seg6, seg7, seg8 + }; + + if(seg == 0) return LV_OPA_TRANSP; + else if(seg < 8) return (uint32_t)((uint32_t)seg_map[seg - 1][px_id] * base_opa) >> 8; + else { + return ((px_id * 2 + 1) * base_opa) / (2 * seg); + } + +} + +/** + * Add a vertical anti-aliasing segment (pixels with decreasing opacity) + * @param x start point x coordinate + * @param y start point y coordinate + * @param length length of segment (negative value to start from 0 opacity) + * @param mask draw only in this area + * @param color color of pixels + * @param opa maximum opacity + */ +void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) +{ + bool aa_inv = false; + if(length < 0) { + aa_inv = true; + length = -length; + } + + lv_coord_t i; + for(i = 0; i < length; i++) { + lv_opa_t px_opa = lv_draw_aa_get_opa(length, i, opa); + if(aa_inv) px_opa = opa - px_opa; + px_fp(x, y + i, mask, color, px_opa); + } +} + +/** + * Add a horizontal anti-aliasing segment (pixels with decreasing opacity) + * @param x start point x coordinate + * @param y start point y coordinate + * @param length length of segment (negative value to start from 0 opacity) + * @param mask draw only in this area + * @param color color of pixels + * @param opa maximum opacity + */ +void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) +{ + bool aa_inv = false; + if(length < 0) { + aa_inv = true; + length = -length; + } + + lv_coord_t i; + for(i = 0; i < length; i++) { + lv_opa_t px_opa = lv_draw_aa_get_opa(length, i, opa); + if(aa_inv) px_opa = opa - px_opa; + px_fp(x + i, y, mask, color, px_opa); + } +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.h new file mode 100644 index 0000000..cf50e98 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.h @@ -0,0 +1,115 @@ +/** + * @file lv_draw.h + * + */ + +#ifndef LV_DRAW_H +#define LV_DRAW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include "../lv_core/lv_style.h" +#include "../lv_misc/lv_txt.h" + +/********************* + * DEFINES + *********************/ +/*If image pixels contains alpha we need to know how much byte is a pixel*/ +#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8 +# define LV_IMG_PX_SIZE_ALPHA_BYTE 2 +#elif LV_COLOR_DEPTH == 16 +# define LV_IMG_PX_SIZE_ALPHA_BYTE 3 +#elif LV_COLOR_DEPTH == 32 +# define LV_IMG_PX_SIZE_ALPHA_BYTE 4 +#endif + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_IMG_SRC_VARIABLE, + LV_IMG_SRC_FILE, + LV_IMG_SRC_SYMBOL, + LV_IMG_SRC_UNKNOWN, +}; +typedef uint8_t lv_img_src_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +#if LV_ANTIALIAS != 0 + +/** + * Get the opacity of a pixel based it's position in a line segment + * @param seg segment length + * @param px_id position of of a pixel which opacity should be get [0..seg-1] + * @param base_opa the base opacity + * @return the opacity of the given pixel + */ +lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa); + +/** + * Add a vertical anti-aliasing segment (pixels with decreasing opacity) + * @param x start point x coordinate + * @param y start point y coordinate + * @param length length of segment (negative value to start from 0 opacity) + * @param mask draw only in this area + * @param color color of pixels + * @param opa maximum opacity + */ +void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); + +/** + * Add a horizontal anti-aliasing segment (pixels with decreasing opacity) + * @param x start point x coordinate + * @param y start point y coordinate + * @param length length of segment (negative value to start from 0 opacity) + * @param mask draw only in this area + * @param color color of pixels + * @param opa maximum opacity + */ +void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); +#endif + +/********************** + * GLOBAL VARIABLES + **********************/ +extern void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); +extern void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); +extern void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa); +extern void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p, + const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, + lv_color_t recolor, lv_opa_t recolor_opa); + +/********************** + * MACROS + **********************/ + +/********************** + * POST INCLUDES + *********************/ +#include "lv_draw_rect.h" +#include "lv_draw_label.h" +#include "lv_draw_img.h" +#include "lv_draw_line.h" +#include "lv_draw_triangle.h" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DRAW_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.mk b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.mk new file mode 100644 index 0000000..a384eef --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw.mk @@ -0,0 +1,14 @@ +CSRCS += lv_draw_vbasic.c +CSRCS += lv_draw_rbasic.c +CSRCS += lv_draw.c +CSRCS += lv_draw_rect.c +CSRCS += lv_draw_label.c +CSRCS += lv_draw_line.c +CSRCS += lv_draw_img.c +CSRCS += lv_draw_arc.c +CSRCS += lv_draw_triangle.c + +DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_draw +VPATH += :$(LVGL_DIR)/lvgl/lv_draw + +CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw" diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.c new file mode 100644 index 0000000..525e56b --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.c @@ -0,0 +1,264 @@ +/** + * @file lv_draw_arc.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_arc.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static uint16_t fast_atan2(int x, int y); +static void ver_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa); +static void hor_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa); +static bool deg_test_norm(uint16_t deg, uint16_t start, uint16_t end); +static bool deg_test_inv(uint16_t deg, uint16_t start, uint16_t end); + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Draw an arc. (Can draw pie too with great thickness.) + * @param center_x the x coordinate of the center of the arc + * @param center_y the y coordinate of the center of the arc + * @param radius the radius of the arc + * @param mask the arc will be drawn only in this mask + * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) + * @param end_angle the end angle of the arc + * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) + * @param opa_scale scale down all opacities by the factor + */ +void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask, + uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale) +{ + lv_coord_t thickness = style->line.width; + if(thickness > radius) thickness = radius; + + lv_coord_t r_out = radius; + lv_coord_t r_in = r_out - thickness; + int16_t deg_base; + int16_t deg; + lv_coord_t x_start[4]; + lv_coord_t x_end[4]; + + lv_color_t color = style->line.color; + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.opa : (uint16_t)((uint16_t) style->body.opa * opa_scale) >> 8; + + + bool (*deg_test)(uint16_t, uint16_t, uint16_t); + if(start_angle <= end_angle) deg_test = deg_test_norm; + else deg_test = deg_test_inv; + + if(deg_test(270, start_angle, end_angle)) hor_line(center_x - r_out + 1, center_y, mask, thickness - 1, color, opa); // Left Middle + if(deg_test(90, start_angle, end_angle)) hor_line(center_x + r_in, center_y, mask, thickness - 1, color, opa); // Right Middle + if(deg_test(180, start_angle, end_angle)) ver_line(center_x, center_y - r_out + 1, mask, thickness - 1, color, opa); // Top Middle + if(deg_test(0, start_angle, end_angle)) ver_line(center_x, center_y + r_in, mask, thickness - 1, color, opa); // Bottom middle + + uint32_t r_out_sqr = r_out * r_out; + uint32_t r_in_sqr = r_in * r_in; + int16_t xi; + int16_t yi; + for(yi = -r_out; yi < 0; yi++) { + x_start[0] = LV_COORD_MIN; + x_start[1] = LV_COORD_MIN; + x_start[2] = LV_COORD_MIN; + x_start[3] = LV_COORD_MIN; + x_end[0] = LV_COORD_MIN; + x_end[1] = LV_COORD_MIN; + x_end[2] = LV_COORD_MIN; + x_end[3] = LV_COORD_MIN; + for(xi = -r_out; xi < 0; xi++) { + + uint32_t r_act_sqr = xi * xi + yi * yi; + if(r_act_sqr > r_out_sqr) continue; + + deg_base = fast_atan2(xi, yi) - 180; + + deg = 180 + deg_base; + if(deg_test(deg, start_angle, end_angle)) { + if(x_start[0] == LV_COORD_MIN) x_start[0] = xi; + } else if(x_start[0] != LV_COORD_MIN && x_end[0] == LV_COORD_MIN) { + x_end[0] = xi - 1; + } + + deg = 360 - deg_base; + if(deg_test(deg, start_angle, end_angle)) { + if(x_start[1] == LV_COORD_MIN) x_start[1] = xi; + } else if(x_start[1] != LV_COORD_MIN && x_end[1] == LV_COORD_MIN) { + x_end[1] = xi - 1; + } + + deg = 180 - deg_base; + if(deg_test(deg, start_angle, end_angle)) { + if(x_start[2] == LV_COORD_MIN) x_start[2] = xi; + } else if(x_start[2] != LV_COORD_MIN && x_end[2] == LV_COORD_MIN) { + x_end[2] = xi - 1; + } + + deg = deg_base; + if(deg_test(deg, start_angle, end_angle)) { + if(x_start[3] == LV_COORD_MIN) x_start[3] = xi; + } else if(x_start[3] != LV_COORD_MIN && x_end[3] == LV_COORD_MIN) { + x_end[3] = xi - 1; + } + + if(r_act_sqr < r_in_sqr) break; /*No need to continue the iteration in x once we found the inner edge of the arc*/ + } + + + if(x_start[0] != LV_COORD_MIN) { + if(x_end[0] == LV_COORD_MIN) x_end[0] = xi - 1; + hor_line(center_x + x_start[0], center_y + yi, mask, x_end[0] - x_start[0], color, opa); + } + + if(x_start[1] != LV_COORD_MIN) { + if(x_end[1] == LV_COORD_MIN) x_end[1] = xi - 1; + hor_line(center_x + x_start[1], center_y - yi, mask, x_end[1] - x_start[1], color, opa); + } + + if(x_start[2] != LV_COORD_MIN) { + if(x_end[2] == LV_COORD_MIN) x_end[2] = xi - 1; + hor_line(center_x - x_end[2], center_y + yi, mask, LV_MATH_ABS(x_end[2] - x_start[2]), color, opa); + } + + if(x_start[3] != LV_COORD_MIN) { + if(x_end[3] == LV_COORD_MIN) x_end[3] = xi - 1; + hor_line(center_x - x_end[3], center_y - yi, mask, LV_MATH_ABS(x_end[3] - x_start[3]), color, opa); + } + + +#if LV_ANTIALIAS + /*TODO*/ + +#endif + + } +} + +static uint16_t fast_atan2(int x, int y) +{ + // Fast XY vector to integer degree algorithm - Jan 2011 www.RomanBlack.com + // Converts any XY values including 0 to a degree value that should be + // within +/- 1 degree of the accurate value without needing + // large slow trig functions like ArcTan() or ArcCos(). + // NOTE! at least one of the X or Y values must be non-zero! + // This is the full version, for all 4 quadrants and will generate + // the angle in integer degrees from 0-360. + // Any values of X and Y are usable including negative values provided + // they are between -1456 and 1456 so the 16bit multiply does not overflow. + + unsigned char negflag; + unsigned char tempdegree; + unsigned char comp; + unsigned int degree; // this will hold the result + //signed int x; // these hold the XY vector at the start + //signed int y; // (and they will be destroyed) + unsigned int ux; + unsigned int uy; + + // Save the sign flags then remove signs and get XY as unsigned ints + negflag = 0; + if(x < 0) { + negflag += 0x01; // x flag bit + x = (0 - x); // is now + + } + ux = x; // copy to unsigned var before multiply + if(y < 0) { + negflag += 0x02; // y flag bit + y = (0 - y); // is now + + } + uy = y; // copy to unsigned var before multiply + + // 1. Calc the scaled "degrees" + if(ux > uy) { + degree = (uy * 45) / ux; // degree result will be 0-45 range + negflag += 0x10; // octant flag bit + } else { + degree = (ux * 45) / uy; // degree result will be 0-45 range + } + + // 2. Compensate for the 4 degree error curve + comp = 0; + tempdegree = degree; // use an unsigned char for speed! + if(tempdegree > 22) { // if top half of range + if(tempdegree <= 44) comp++; + if(tempdegree <= 41) comp++; + if(tempdegree <= 37) comp++; + if(tempdegree <= 32) comp++; // max is 4 degrees compensated + } else { // else is lower half of range + if(tempdegree >= 2) comp++; + if(tempdegree >= 6) comp++; + if(tempdegree >= 10) comp++; + if(tempdegree >= 15) comp++; // max is 4 degrees compensated + } + degree += comp; // degree is now accurate to +/- 1 degree! + + // Invert degree if it was X>Y octant, makes 0-45 into 90-45 + if(negflag & 0x10) degree = (90 - degree); + + // 3. Degree is now 0-90 range for this quadrant, + // need to invert it for whichever quadrant it was in + if(negflag & 0x02) { // if -Y + if(negflag & 0x01) // if -Y -X + degree = (180 + degree); + else // else is -Y +X + degree = (180 - degree); + } else { // else is +Y + if(negflag & 0x01) // if +Y -X + degree = (360 - degree); + } + return degree; +} + +/********************** + * STATIC FUNCTIONS + **********************/ +static void ver_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa) +{ + lv_area_t area; + lv_area_set(&area, x, y, x, y + len); + + fill_fp(&area, mask, color, opa); +} + +static void hor_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa) +{ + lv_area_t area; + lv_area_set(&area, x, y, x + len, y); + + fill_fp(&area, mask, color, opa); +} + +static bool deg_test_norm(uint16_t deg, uint16_t start, uint16_t end) +{ + if(deg >= start && deg <= end) return true; + else return false; +} + +static bool deg_test_inv(uint16_t deg, uint16_t start, uint16_t end) +{ + if(deg >= start || deg <= end) { + return true; + } else return false; +} diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.h new file mode 100644 index 0000000..203eabe --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_arc.h @@ -0,0 +1,53 @@ +/** + * @file lv_draw_arc.h + * + */ + +#ifndef LV_DRAW_ARC_H +#define LV_DRAW_ARC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Draw an arc. (Can draw pie too with great thickness.) + * @param center_x the x coordinate of the center of the arc + * @param center_y the y coordinate of the center of the arc + * @param radius the radius of the arc + * @param mask the arc will be drawn only in this mask + * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) + * @param end_angle the end angle of the arc + * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) + * @param opa_scale scale down all opacities by the factor + */ +void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask, + uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DRAW_ARC*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.c new file mode 100644 index 0000000..5c24aa8 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.c @@ -0,0 +1,759 @@ +/** + * @file lv_draw_img.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_img.h" +#include "../lv_misc/lv_fs.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, + const void * src, const lv_style_t * style, lv_opa_t opa_scale); + +static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * style); +static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); +static void lv_img_decoder_close(void); +static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); +static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); + +/********************** + * STATIC VARIABLES + **********************/ +static bool decoder_custom; +static const void * decoder_src; +static lv_img_src_t decoder_src_type; +static lv_img_header_t decoder_header; +static const lv_style_t * decoder_style; +#if USE_LV_FILESYSTEM +static lv_fs_file_t decoder_file; +#endif +#if LV_IMG_CF_INDEXED +static lv_color_t decoder_index_map[256]; +#endif + +static lv_img_decoder_info_f_t lv_img_decoder_info_custom; +static lv_img_decoder_open_f_t lv_img_decoder_open_custom; +static lv_img_decoder_read_line_f_t lv_img_decoder_read_line_custom; +static lv_img_decoder_close_f_t lv_img_decoder_close_custom; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Draw an image + * @param coords the coordinates of the image + * @param mask the image will be drawn only in this area + * @param src pointer to a lv_color_t array which contains the pixels of the image + * @param style style of the image + * @param opa_scale scale down all opacities by the factor + */ +void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask, + const void * src, const lv_style_t * style, lv_opa_t opa_scale) +{ + if(src == NULL) { + LV_LOG_WARN("Image draw: src is NULL"); + lv_draw_rect(coords, mask, &lv_style_plain, LV_OPA_COVER); + lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL); + return; + } + + lv_res_t res; + res = lv_img_draw_core(coords, mask, src, style, opa_scale); + + if(res == LV_RES_INV) { + LV_LOG_WARN("Image draw error"); + lv_draw_rect(coords, mask, &lv_style_plain, LV_OPA_COVER); + lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL); + return; + } +} + + +/** + * + * @param src + * @param header + * @param style + * @return + */ +lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header) +{ + header->always_zero = 0; + /*Try to get info with the custom functions first*/ + if(lv_img_decoder_info_custom) { + lv_res_t custom_res; + custom_res = lv_img_decoder_info_custom(src, header); + if(custom_res == LV_RES_OK) return LV_RES_OK; /*Custom info has supported this source*/ + } + + lv_img_src_t src_type = lv_img_src_get_type(src); + if(src_type == LV_IMG_SRC_VARIABLE) { + header->w = ((lv_img_dsc_t *)src)->header.w; + header->h = ((lv_img_dsc_t *)src)->header.h; + header->cf = ((lv_img_dsc_t *)src)->header.cf; + } +#if USE_LV_FILESYSTEM + else if(src_type == LV_IMG_SRC_FILE) { + lv_fs_file_t file; + lv_fs_res_t res; + uint32_t rn; + res = lv_fs_open(&file, src, LV_FS_MODE_RD); + if(res == LV_FS_RES_OK) { + res = lv_fs_read(&file, header, sizeof(lv_img_header_t), &rn); + } + + /*Create a dummy header on fs error*/ + if(res != LV_FS_RES_OK || rn != sizeof(lv_img_header_t)) { + header->w = LV_DPI; + header->h = LV_DPI; + header->cf = LV_IMG_CF_UNKOWN; + } + + lv_fs_close(&file); + } +#endif + else if(src_type == LV_IMG_SRC_SYMBOL) { + /*The size depend on the font but it is unknown here. It should be handled outside of the function*/ + header->w = 1; + header->h = 1; + /* Symbols always have transparent parts. Important because of cover check in the design function. + * The actual value doesn't matter because lv_draw_label will draw it*/ + header->cf = LV_IMG_CF_ALPHA_1BIT; + } else { + LV_LOG_WARN("Image get info found unknown src type"); + return false; + } + return true; + +} + +uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf) +{ + uint8_t px_size = 0; + + switch(cf) { + case LV_IMG_CF_UNKOWN: + case LV_IMG_CF_RAW: + px_size = 0; + break; + case LV_IMG_CF_TRUE_COLOR: + case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: + px_size = LV_COLOR_SIZE; + break; + case LV_IMG_CF_TRUE_COLOR_ALPHA: + px_size = LV_IMG_PX_SIZE_ALPHA_BYTE << 3; + break; + case LV_IMG_CF_INDEXED_1BIT: + case LV_IMG_CF_ALPHA_1BIT: + px_size = 1; + break; + case LV_IMG_CF_INDEXED_2BIT: + case LV_IMG_CF_ALPHA_2BIT: + px_size = 2; + break; + case LV_IMG_CF_INDEXED_4BIT: + case LV_IMG_CF_ALPHA_4BIT: + px_size = 4; + break; + case LV_IMG_CF_INDEXED_8BIT: + case LV_IMG_CF_ALPHA_8BIT: + px_size = 8; + break; + default: + px_size = 0; + break; + } + + return px_size; +} + +bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf) +{ + bool is_chroma_keyed = false; + + switch(cf) { + case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: + case LV_IMG_CF_RAW_CHROMA_KEYED: + case LV_IMG_CF_INDEXED_1BIT: + case LV_IMG_CF_INDEXED_2BIT: + case LV_IMG_CF_INDEXED_4BIT: + case LV_IMG_CF_INDEXED_8BIT: + is_chroma_keyed = true; + break; + default: + is_chroma_keyed = false; + break; + } + + return is_chroma_keyed; +} + + +bool lv_img_color_format_has_alpha(lv_img_cf_t cf) +{ + bool has_alpha = false; + + switch(cf) { + case LV_IMG_CF_TRUE_COLOR_ALPHA: + case LV_IMG_CF_RAW_ALPHA: + case LV_IMG_CF_ALPHA_1BIT: + case LV_IMG_CF_ALPHA_2BIT: + case LV_IMG_CF_ALPHA_4BIT: + case LV_IMG_CF_ALPHA_8BIT: + has_alpha = true; + break; + default: + has_alpha = false; + break; + } + + return has_alpha; +} + +/** + * Get the type of an image source + * @param src pointer to an image source: + * - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code) + * - a path to a file (e.g. "S:/folder/image.bin") + * - or a symbol (e.g. SYMBOL_CLOSE) + * @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN + */ +lv_img_src_t lv_img_src_get_type(const void * src) +{ + lv_img_src_t img_src_type = LV_IMG_SRC_UNKNOWN; + + if(src == NULL) return img_src_type; + const uint8_t * u8_p = src; + + /*The first byte shows the type of the image source*/ + if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F) { + img_src_type = LV_IMG_SRC_FILE; /*If it's an ASCII character then it's file name*/ + } else if(u8_p[0] >= 0x80) { + img_src_type = LV_IMG_SRC_SYMBOL; /*Symbols begins after 0x7F*/ + } else { + img_src_type = LV_IMG_SRC_VARIABLE; /*`lv_img_dsc_t` is design to the first byte < 0x20*/ + } + + if (LV_IMG_SRC_UNKNOWN == img_src_type) { + LV_LOG_WARN("lv_img_src_get_type: unknown image type"); + } + + return img_src_type; +} + +/** + * Set custom decoder functions. See the typdefs of the function typed above for more info about them + * @param info_fp info get function + * @param open_fp open function + * @param read_fp read line function + * @param close_fp clode function + */ +void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp, + lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp) +{ + lv_img_decoder_info_custom = info_fp; + lv_img_decoder_open_custom = open_fp; + lv_img_decoder_read_line_custom = read_fp; + lv_img_decoder_close_custom = close_fp; +} + + +/********************** + * STATIC FUNCTIONS + **********************/ + + +static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, + const void * src, const lv_style_t * style, lv_opa_t opa_scale) +{ + + lv_area_t mask_com; /*Common area of mask and coords*/ + bool union_ok; + union_ok = lv_area_intersect(&mask_com, mask, coords); + if(union_ok == false) { + return LV_RES_OK; /*Out of mask. There is nothing to draw so the image is drawn successfully.*/ + } + + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->image.opa : (uint16_t)((uint16_t) style->image.opa * opa_scale) >> 8; + + lv_img_header_t header; + lv_res_t header_res; + header_res = lv_img_dsc_get_info(src, &header); + if(header_res != LV_RES_OK) { + LV_LOG_WARN("Image draw can't get image info"); + lv_img_decoder_close(); + return LV_RES_INV; + } + + bool chroma_keyed = lv_img_color_format_is_chroma_keyed(header.cf); + bool alpha_byte = lv_img_color_format_has_alpha(header.cf); + + const uint8_t * img_data = lv_img_decoder_open(src, style); + if(img_data == LV_IMG_DECODER_OPEN_FAIL) { + LV_LOG_WARN("Image draw cannot open the image resource"); + lv_img_decoder_close(); + return LV_RES_INV; + } + + /* The decoder open could open the image and gave the entire uncompressed image. + * Just draw it!*/ + if(img_data) { + map_fp(coords, mask, img_data, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense); + } + /* The whole uncompressed image is not available. Try to read it line-by-line*/ + else { + lv_coord_t width = lv_area_get_width(&mask_com); + +#if LV_COMPILER_VLA_SUPPORTED + uint8_t buf[(lv_area_get_width(&mask_com) * ((LV_COLOR_DEPTH >> 3) + 1))]; +#else + uint8_t buf[LV_HOR_RES * ((LV_COLOR_DEPTH >> 3) + 1)]; /*+1 because of the possible alpha byte*/ +#endif + lv_area_t line; + lv_area_copy(&line, &mask_com); + lv_area_set_height(&line, 1); + lv_coord_t x = mask_com.x1 - coords->x1; + lv_coord_t y = mask_com.y1 - coords->y1; + lv_coord_t row; + lv_res_t read_res; + for(row = mask_com.y1; row <= mask_com.y2; row++) { + read_res = lv_img_decoder_read_line(x, y, width, buf); + if(read_res != LV_RES_OK) { + lv_img_decoder_close(); + LV_LOG_WARN("Image draw can't read the line"); + return LV_RES_INV; + } + map_fp(&line, mask, buf, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense); + line.y1++; + line.y2++; + y++; + } + } + + lv_img_decoder_close(); + + return LV_RES_OK; +} + + +static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * style) +{ + decoder_custom = false; + + /*Try to open with the custom functions first*/ + if(lv_img_decoder_open_custom) { + const uint8_t * custom_res; + custom_res = lv_img_decoder_open_custom(src, style); + if(custom_res != LV_IMG_DECODER_OPEN_FAIL) { + decoder_custom = true; /*Mark that custom decoder function should be used for this img source.*/ + return custom_res; /*Custom open supported this source*/ + } + } + + decoder_src = src; + decoder_style = style; + decoder_src_type = lv_img_src_get_type(src); + + lv_res_t header_res; + header_res = lv_img_dsc_get_info(src, &decoder_header); + if(header_res == LV_RES_INV) { + decoder_src = NULL; + decoder_src_type = LV_IMG_SRC_UNKNOWN; + LV_LOG_WARN("Built-in image decoder can't get the header info"); + return LV_IMG_DECODER_OPEN_FAIL; + } + + /*Open the file if it's a file*/ + if(decoder_src_type == LV_IMG_SRC_FILE) { +#if USE_LV_FILESYSTEM + lv_fs_res_t res = lv_fs_open(&decoder_file, src, LV_FS_MODE_RD); + if(res != LV_FS_RES_OK) { + LV_LOG_WARN("Built-in image decoder can't open the file"); + return LV_IMG_DECODER_OPEN_FAIL; + } +#else + LV_LOG_WARN("Image built-in decoder can read file because USE_LV_FILESYSTEM = 0"); + return LV_IMG_DECODER_OPEN_FAIL; +#endif + } + + + /*Process the different color formats*/ + lv_img_cf_t cf = decoder_header.cf; + if(cf == LV_IMG_CF_TRUE_COLOR || + cf == LV_IMG_CF_TRUE_COLOR_ALPHA || + cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { + if(decoder_src_type == LV_IMG_SRC_VARIABLE) { + /*In case of uncompressed formats if the image stored in the ROM/RAM simply give it's pointer*/ + return ((lv_img_dsc_t *)decoder_src)->data; + } else { + /*If it's file it need to be read line by line later*/ + return NULL; + } + } else if(cf == LV_IMG_CF_INDEXED_1BIT || + cf == LV_IMG_CF_INDEXED_2BIT || + cf == LV_IMG_CF_INDEXED_4BIT || + cf == LV_IMG_CF_INDEXED_8BIT) { + +#if LV_IMG_CF_INDEXED +#if USE_LV_FILESYSTEM + lv_color32_t palette_file[256]; +#endif + + lv_color32_t * palette_p = NULL; + uint8_t px_size = lv_img_color_format_get_px_size(cf); + uint32_t palette_size = 1 << px_size; + + if(decoder_src_type == LV_IMG_SRC_FILE) { + /*Read the palette from file*/ +#if USE_LV_FILESYSTEM + lv_fs_seek(&decoder_file, 4); /*Skip the header*/ + lv_fs_read(&decoder_file, palette_file, palette_size * sizeof(lv_color32_t), NULL); + palette_p = palette_file; +#else + LV_LOG_WARN("Image built-in decoder can read the palette because USE_LV_FILESYSTEM = 0"); + return LV_IMG_DECODER_OPEN_FAIL; +#endif + } else { + /*The palette begins in the beginning of the image data. Just point to it.*/ + palette_p = (lv_color32_t *)((lv_img_dsc_t *)decoder_src)->data; + } + + uint32_t i; + for(i = 0; i < palette_size; i++) { + decoder_index_map[i] = LV_COLOR_MAKE(palette_p[i].red, palette_p[i].green, palette_p[i].blue); + } + return NULL; +#else + LV_LOG_WARN("Indexed (palette) images are not enabled in lv_conf.h. See LV_IMG_CF_INDEXED"); + return LV_IMG_DECODER_OPEN_FAIL; +#endif + } else if(cf == LV_IMG_CF_ALPHA_1BIT || + cf == LV_IMG_CF_ALPHA_2BIT || + cf == LV_IMG_CF_ALPHA_4BIT || + cf == LV_IMG_CF_ALPHA_8BIT) { +#if LV_IMG_CF_ALPHA + return NULL; /*Nothing to process*/ +#else + LV_LOG_WARN("Alpha indexed images are not enabled in lv_conf.h. See LV_IMG_CF_ALPHA"); + return LV_IMG_DECODER_OPEN_FAIL; +#endif + } else { + LV_LOG_WARN("Image decoder open: unknown color format") + return LV_IMG_DECODER_OPEN_FAIL; + } +} + + +static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf) +{ + /*Try to read the line with the custom functions*/ + if(decoder_custom) { + if(lv_img_decoder_read_line_custom) { + lv_res_t custom_res; + custom_res = lv_img_decoder_read_line_custom(x, y, len, buf); + return custom_res; + } else { + LV_LOG_WARN("Image open with custom decoder but read not supported") + } + return LV_RES_INV; /*It"s an error if not returned earlier*/ + } + + if(decoder_src_type == LV_IMG_SRC_FILE) { +#if USE_LV_FILESYSTEM + uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf); + + lv_fs_res_t res; + + if(decoder_header.cf == LV_IMG_CF_TRUE_COLOR || + decoder_header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA || + decoder_header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { + uint32_t pos = ((y * decoder_header.w + x) * px_size) >> 3; + pos += 4; /*Skip the header*/ + res = lv_fs_seek(&decoder_file, pos); + if(res != LV_FS_RES_OK) { + LV_LOG_WARN("Built-in image decoder seek failed"); + return false; + } + uint32_t btr = len * (px_size >> 3); + uint32_t br = 0; + lv_fs_read(&decoder_file, buf, btr, &br); + if(res != LV_FS_RES_OK || btr != br) { + LV_LOG_WARN("Built-in image decoder read failed"); + return false; + } + } else if(decoder_header.cf == LV_IMG_CF_ALPHA_1BIT || + decoder_header.cf == LV_IMG_CF_ALPHA_2BIT || + decoder_header.cf == LV_IMG_CF_ALPHA_4BIT || + decoder_header.cf == LV_IMG_CF_ALPHA_8BIT) { + + lv_img_built_in_decoder_line_alpha(x, y, len, buf); + } else if(decoder_header.cf == LV_IMG_CF_INDEXED_1BIT || + decoder_header.cf == LV_IMG_CF_INDEXED_2BIT || + decoder_header.cf == LV_IMG_CF_INDEXED_4BIT || + decoder_header.cf == LV_IMG_CF_INDEXED_8BIT) { + lv_img_built_in_decoder_line_indexed(x, y, len, buf); + } else { + LV_LOG_WARN("Built-in image decoder read not supports the color format"); + return false; + } +#else + LV_LOG_WARN("Image built-in decoder can't read file because USE_LV_FILESYSTEM = 0"); + return false; +#endif + } else if(decoder_src_type == LV_IMG_SRC_VARIABLE) { + const lv_img_dsc_t * img_dsc = decoder_src; + + if(img_dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || + img_dsc->header.cf == LV_IMG_CF_ALPHA_2BIT || + img_dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || + img_dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { + lv_img_built_in_decoder_line_alpha(x, y, len, buf); + } else if(img_dsc->header.cf == LV_IMG_CF_INDEXED_1BIT || + img_dsc->header.cf == LV_IMG_CF_INDEXED_2BIT || + img_dsc->header.cf == LV_IMG_CF_INDEXED_4BIT || + img_dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { + lv_img_built_in_decoder_line_indexed(x, y, len, buf); + } else { + LV_LOG_WARN("Built-in image decoder not supports the color format"); + return false; + } + } + + return true; +} + +static void lv_img_decoder_close(void) +{ + /*Try to close with the custom functions*/ + if(decoder_custom) { + if(lv_img_decoder_close_custom) lv_img_decoder_close_custom(); + return; + } + + /*It was opened with built-in decoder*/ + if(decoder_src) { +#if USE_LV_FILESYSTEM + if(decoder_src_type == LV_IMG_SRC_FILE) { + lv_fs_close(&decoder_file); + } +#endif + decoder_src_type = LV_IMG_SRC_UNKNOWN; + decoder_src = NULL; + } +} + +static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf) +{ + +#if LV_IMG_CF_ALPHA + const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/ + const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/ + const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ + 68, 85, 102, 119, + 136, 153, 170, 187, + 204, 221, 238, 255 + }; + + /*Simply fill the buffer with the color. Later only the alpha value will be modified.*/ + lv_color_t bg_color = decoder_style->image.color; + lv_coord_t i; + for(i = 0; i < len; i++) { +#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1 + buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full; +#elif LV_COLOR_DEPTH == 16 + /*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/ + buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full & 0xFF; + buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + 1] = (bg_color.full >> 8) & 0xFF; +#elif LV_COLOR_DEPTH == 32 + *((uint32_t *)&buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE]) = bg_color.full; +#else +#error "Invalid LV_COLOR_DEPTH. Check it in lv_conf.h" +#endif + } + + const lv_opa_t * opa_table = NULL; + uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf); + uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/ + + lv_coord_t w = 0; + uint32_t ofs = 0; + int8_t pos = 0; + switch(decoder_header.cf) { + case LV_IMG_CF_ALPHA_1BIT: + w = (decoder_header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/ + if(decoder_header.w & 0x7) w++; + ofs += w * y + (x >> 3); /*First pixel*/ + pos = 7 - (x & 0x7); + opa_table = alpha1_opa_table; + break; + case LV_IMG_CF_ALPHA_2BIT: + w = (decoder_header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/ + if(decoder_header.w & 0x3) w++; + ofs += w * y + (x >> 2); /*First pixel*/ + pos = 6 - ((x & 0x3) * 2); + opa_table = alpha2_opa_table; + break; + case LV_IMG_CF_ALPHA_4BIT: + w = (decoder_header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/ + if(decoder_header.w & 0x1) w++; + ofs += w * y + (x >> 1); /*First pixel*/ + pos = 4 - ((x & 0x1) * 4); + opa_table = alpha4_opa_table; + break; + case LV_IMG_CF_ALPHA_8BIT: + w = decoder_header.w; /*E.g. x = 7 -> w = 7 (bytes)*/ + ofs += w * y + x; /*First pixel*/ + pos = 0; + break; + } + +#if USE_LV_FILESYSTEM +# if LV_COMPILER_VLA_SUPPORTED + uint8_t fs_buf[w]; +# else + uint8_t fs_buf[LV_HOR_RES]; +# endif +#endif + const uint8_t * data_tmp = NULL; + if(decoder_src_type == LV_IMG_SRC_VARIABLE) { + const lv_img_dsc_t * img_dsc = decoder_src; + data_tmp = img_dsc->data + ofs; + } else { +#if USE_LV_FILESYSTEM + lv_fs_seek(&decoder_file, ofs + 4); /*+4 to skip the header*/ + lv_fs_read(&decoder_file, fs_buf, w, NULL); + data_tmp = fs_buf; +#else + LV_LOG_WARN("Image built-in alpha line reader can't read file because USE_LV_FILESYSTEM = 0"); + data_tmp = NULL; /*To avoid warnings*/ + return LV_RES_INV; +#endif + } + + + uint8_t byte_act = 0; + uint8_t val_act; + for(i = 0; i < len; i ++) { + val_act = (data_tmp[byte_act] & (mask << pos)) >> pos; + + buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + LV_IMG_PX_SIZE_ALPHA_BYTE - 1] = + decoder_header.cf == LV_IMG_CF_ALPHA_8BIT ? val_act : opa_table[val_act]; + + pos -= px_size; + if(pos < 0) { + pos = 8 - px_size; + data_tmp++; + } + } + + return LV_RES_OK; + +#else + LV_LOG_WARN("Image built-in alpha line reader failed because LV_IMG_CF_ALPHA is 0 in lv_conf.h"); + return LV_RES_INV; +#endif +} + +static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf) +{ + +#if LV_IMG_CF_INDEXED + uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf); + uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/ + + lv_coord_t w = 0; + int8_t pos = 0; + uint32_t ofs = 0; + switch(decoder_header.cf) { + case LV_IMG_CF_INDEXED_1BIT: + w = (decoder_header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/ + if(decoder_header.w & 0x7) w++; + ofs += w * y + (x >> 3); /*First pixel*/ + ofs += 8; /*Skip the palette*/ + pos = 7 - (x & 0x7); + break; + case LV_IMG_CF_INDEXED_2BIT: + w = (decoder_header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/ + if(decoder_header.w & 0x3) w++; + ofs += w * y + (x >> 2); /*First pixel*/ + ofs += 16; /*Skip the palette*/ + pos = 6 - ((x & 0x3) * 2); + break; + case LV_IMG_CF_INDEXED_4BIT: + w = (decoder_header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/ + if(decoder_header.w & 0x1) w++; + ofs += w * y + (x >> 1); /*First pixel*/ + ofs += 64; /*Skip the palette*/ + pos = 4 - ((x & 0x1) * 4); + break; + case LV_IMG_CF_INDEXED_8BIT: + w = decoder_header.w; /*E.g. x = 7 -> w = 7 (bytes)*/ + ofs += w * y + x; /*First pixel*/ + ofs += 1024; /*Skip the palette*/ + pos = 0; + break; + } + +#if USE_LV_FILESYSTEM +# if LV_COMPILER_VLA_SUPPORTED + uint8_t fs_buf[w]; +# else + uint8_t fs_buf[LV_HOR_RES]; +# endif +#endif + const uint8_t * data_tmp = NULL; + if(decoder_src_type == LV_IMG_SRC_VARIABLE) { + const lv_img_dsc_t * img_dsc = decoder_src; + data_tmp = img_dsc->data + ofs; + } else { +#if USE_LV_FILESYSTEM + lv_fs_seek(&decoder_file, ofs + 4); /*+4 to skip the header*/ + lv_fs_read(&decoder_file, fs_buf, w, NULL); + data_tmp = fs_buf; +#else + LV_LOG_WARN("Image built-in indexed line reader can't read file because USE_LV_FILESYSTEM = 0"); + data_tmp = NULL; /*To avoid warnings*/ + return LV_RES_INV; +#endif + } + + uint8_t byte_act = 0; + uint8_t val_act; + lv_coord_t i; + lv_color_t * cbuf = (lv_color_t *) buf; + for(i = 0; i < len; i ++) { + val_act = (data_tmp[byte_act] & (mask << pos)) >> pos; + cbuf[i] = decoder_index_map[val_act]; + + pos -= px_size; + if(pos < 0) { + pos = 8 - px_size; + data_tmp++; + } + } + + return LV_RES_OK; +#else + LV_LOG_WARN("Image built-in indexed line reader failed because LV_IMG_CF_INDEXED is 0 in lv_conf.h"); + return LV_RES_INV; +#endif +} diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.h new file mode 100644 index 0000000..31ed827 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_img.h @@ -0,0 +1,167 @@ +/** + * @file lv_draw_img.h + * + */ + +#ifndef LV_DRAW_IMG_H +#define LV_DRAW_IMG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw.h" +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ +#define LV_IMG_DECODER_OPEN_FAIL ((void*)(-1)) + +/********************** + * TYPEDEFS + **********************/ +struct _lv_img_t; + +typedef struct { + + /* The first 8 bit is very important to distinguish the different source types. + * For more info see `lv_img_get_src_type()` in lv_img.c */ + uint32_t cf :5; /* Color format: See `lv_img_color_format_t`*/ + uint32_t always_zero :3; /*It the upper bits of the first byte. Always zero to look like a non-printable character*/ + + uint32_t reserved :2; /*Reserved to be used later*/ + + uint32_t w:11; /*Width of the image map*/ + uint32_t h:11; /*Height of the image map*/ +} lv_img_header_t; + +/*Image color format*/ +enum { + LV_IMG_CF_UNKOWN = 0, + + LV_IMG_CF_RAW, /*Contains the file as it is. Needs custom decoder function*/ + LV_IMG_CF_RAW_ALPHA, /*Contains the file as it is. The image has alpha. Needs custom decoder function*/ + LV_IMG_CF_RAW_CHROMA_KEYED, /*Contains the file as it is. The image is chroma keyed. Needs custom decoder function*/ + + LV_IMG_CF_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/ + LV_IMG_CF_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/ + LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/ + + LV_IMG_CF_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/ + LV_IMG_CF_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/ + LV_IMG_CF_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/ + LV_IMG_CF_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/ + + LV_IMG_CF_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/ + LV_IMG_CF_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/ + LV_IMG_CF_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/ + LV_IMG_CF_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/ +}; +typedef uint8_t lv_img_cf_t; + +/* Image header it is compatible with + * the result image converter utility*/ +typedef struct +{ + lv_img_header_t header; + uint32_t data_size; + const uint8_t * data; +} lv_img_dsc_t; + +/* Decoder function definitions */ + + +/** + * Get info from an image and store in the `header` + * @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type) + * @param header store the info here + * @return LV_RES_OK: info written correctly; LV_RES_INV: failed + */ +typedef lv_res_t (*lv_img_decoder_info_f_t)(const void * src, lv_img_header_t * header); + +/** + * Open an image for decoding. Prepare it as it is required to read it later + * @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type) + * @param style the style of image (maybe it will be required to determine a color or something) + * @return there are 3 possible return values: + * 1) buffer with the decoded image + * 2) if can decode the whole image NULL. decoder_read_line will be called to read the image line-by-line + * 3) LV_IMG_DECODER_OPEN_FAIL if the image format is unknown to the decoder or an error occurred + */ +typedef const uint8_t * (*lv_img_decoder_open_f_t)(const void * src, const lv_style_t * style); + +/** + * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`. + * Required only if the "open" function can't return with the whole decoded pixel array. + * @param x start x coordinate + * @param y startt y coordinate + * @param len number of pixels to decode + * @param buf a buffer to store the decoded pixels + * @return LV_RES_OK: ok; LV_RES_INV: failed + */ +typedef lv_res_t (*lv_img_decoder_read_line_f_t)(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); + +/** + * Close the pending decoding. Free resources etc. + */ +typedef void (*lv_img_decoder_close_f_t)(void); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Draw an image + * @param coords the coordinates of the image + * @param mask the image will be drawn only in this area + * @param src pointer to a lv_color_t array which contains the pixels of the image + * @param style style of the image + * @param opa_scale scale down all opacities by the factor + */ +void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask, + const void * src, const lv_style_t * style, lv_opa_t opa_scale); + + +/** + * Get the type of an image source + * @param src pointer to an image source: + * - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code) + * - a path to a file (e.g. "S:/folder/image.bin") + * - or a symbol (e.g. SYMBOL_CLOSE) + * @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN + */ +lv_img_src_t lv_img_src_get_type(const void * src); + +/** + * Set custom decoder functions. See the typdefs of the function typed above for more info about them + * @param info_fp info get function + * @param open_fp open function + * @param read_fp read line function + * @param close_fp clode function + */ +void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp, + lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp); + +lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header); + +uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf); + +bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf); + +bool lv_img_color_format_has_alpha(lv_img_cf_t cf); + + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TEMPL_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.c new file mode 100644 index 0000000..0744ff1 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.c @@ -0,0 +1,264 @@ +/** + * @file lv_draw_label.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_label.h" +#include "lv_draw_rbasic.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define LABEL_RECOLOR_PAR_LENGTH 6 + +/********************** + * TYPEDEFS + **********************/ +enum { + CMD_STATE_WAIT, + CMD_STATE_PAR, + CMD_STATE_IN, +}; +typedef uint8_t cmd_state_t; + +/********************** + * STATIC PROTOTYPES + **********************/ +static uint8_t hex_char_to_num(char hex); + +/********************** + * STATIC VARIABLES + **********************/ + + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Write a text + * @param coords coordinates of the label + * @param mask the label will be drawn only in this area + * @param style pointer to a style + * @param opa_scale scale down all opacities by the factor + * @param txt 0 terminated text to write + * @param flag settings for the text from 'txt_flag_t' enum + * @param offset text offset in x and y direction (NULL if unused) + * + */ +void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale, + const char * txt, lv_txt_flag_t flag, lv_point_t * offset) +{ + const lv_font_t * font = style->text.font; + lv_coord_t w; + if((flag & LV_TXT_FLAG_EXPAND) == 0) { + /*Normally use the label's width as width*/ + w = lv_area_get_width(coords); + } else { + /*If EXAPND is enabled then not limit the text's width to the object's width*/ + lv_point_t p; + lv_txt_get_size(&p, txt, style->text.font, style->text.letter_space, style->text.line_space, LV_COORD_MAX, flag); + w = p.x; + } + + lv_coord_t line_height = lv_font_get_height(font) + style->text.line_space; + + + /*Init variables for the first line*/ + lv_coord_t line_width = 0; + lv_point_t pos; + pos.x = coords->x1; + pos.y = coords->y1; + + lv_coord_t x_ofs = 0; + lv_coord_t y_ofs = 0; + if(offset != NULL) { + x_ofs = offset->x; + y_ofs = offset->y; + pos.y += y_ofs; + } + + uint32_t line_start = 0; + uint32_t line_end = lv_txt_get_next_line(txt, font, style->text.letter_space, w, flag); + + /*Go the first visible line*/ + while(pos.y + line_height < mask->y1) { + /*Go to next line*/ + line_start = line_end; + line_end += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, w, flag); + pos.y += line_height; + + if(txt[line_start] == '\0') return; + } + + /*Align to middle*/ + if(flag & LV_TXT_FLAG_CENTER) { + line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, + font, style->text.letter_space, flag); + + pos.x += (lv_area_get_width(coords) - line_width) / 2; + + } + /*Align to the right*/ + else if(flag & LV_TXT_FLAG_RIGHT) { + line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, + font, style->text.letter_space, flag); + pos.x += lv_area_get_width(coords) - line_width; + } + + + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->text.opa : (uint16_t)((uint16_t) style->text.opa * opa_scale) >> 8; + + cmd_state_t cmd_state = CMD_STATE_WAIT; + uint32_t i; + uint16_t par_start = 0; + lv_color_t recolor; + lv_coord_t letter_w; + + /*Real draw need a background color for higher bpp letter*/ +#if LV_VDB_SIZE == 0 + lv_rletter_set_background(style->body.main_color); +#endif + + + /*Write out all lines*/ + while(txt[line_start] != '\0') { + if(offset != NULL) { + pos.x += x_ofs; + } + /*Write all letter of a line*/ + cmd_state = CMD_STATE_WAIT; + i = line_start; + uint32_t letter; + while(i < line_end) { + letter = lv_txt_encoded_next(txt, &i); + + /*Handle the re-color command*/ + if((flag & LV_TXT_FLAG_RECOLOR) != 0) { + if(letter == (uint32_t)LV_TXT_COLOR_CMD[0]) { + if(cmd_state == CMD_STATE_WAIT) { /*Start char*/ + par_start = i; + cmd_state = CMD_STATE_PAR; + continue; + } else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */ + cmd_state = CMD_STATE_WAIT; + } else if(cmd_state == CMD_STATE_IN) { /*Command end */ + cmd_state = CMD_STATE_WAIT; + continue; + } + } + + /*Skip the color parameter and wait the space after it*/ + if(cmd_state == CMD_STATE_PAR) { + if(letter == ' ') { + /*Get the parameter*/ + if(i - par_start == LABEL_RECOLOR_PAR_LENGTH + 1) { + char buf[LABEL_RECOLOR_PAR_LENGTH + 1]; + memcpy(buf, &txt[par_start], LABEL_RECOLOR_PAR_LENGTH); + buf[LABEL_RECOLOR_PAR_LENGTH] = '\0'; + int r, g, b; + r = (hex_char_to_num(buf[0]) << 4) + hex_char_to_num(buf[1]); + g = (hex_char_to_num(buf[2]) << 4) + hex_char_to_num(buf[3]); + b = (hex_char_to_num(buf[4]) << 4) + hex_char_to_num(buf[5]); + recolor = LV_COLOR_MAKE(r, g, b); + } else { + recolor.full = style->text.color.full; + } + cmd_state = CMD_STATE_IN; /*After the parameter the text is in the command*/ + } + continue; + } + } + + lv_color_t color = style->text.color; + + if(cmd_state == CMD_STATE_IN) color = recolor; + + letter_fp(&pos, mask, font, letter, color, opa); + letter_w = lv_font_get_width(font, letter); + + if(letter_w > 0){ + pos.x += letter_w + style->text.letter_space; + } + } + /*Go to next line*/ + line_start = line_end; + line_end += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, w, flag); + + pos.x = coords->x1; + /*Align to middle*/ + if(flag & LV_TXT_FLAG_CENTER) { + line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, + font, style->text.letter_space, flag); + + pos.x += (lv_area_get_width(coords) - line_width) / 2; + + } + /*Align to the right*/ + else if(flag & LV_TXT_FLAG_RIGHT) { + line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, + font, style->text.letter_space, flag); + pos.x += lv_area_get_width(coords) - line_width; + } + + /*Go the next line position*/ + pos.y += line_height; + + if(pos.y > mask->y2) return; + } +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Convert a hexadecimal characters to a number (0..15) + * @param hex Pointer to a hexadecimal character (0..9, A..F) + * @return the numerical value of `hex` or 0 on error + */ +static uint8_t hex_char_to_num(char hex) +{ + uint8_t result = 0; + + if(hex >= '0' && hex <= '9') { + result = hex - '0'; + } + else { + if(hex >= 'a') hex -= 'a' - 'A'; /*Convert to upper case*/ + + switch(hex) { + case 'A': + result = 10; + break; + case 'B': + result = 11; + break; + case 'C': + result = 12; + break; + case 'D': + result = 13; + break; + case 'E': + result = 14; + break; + case 'F': + result = 15; + break; + default: + result = 0; + break; + } + } + + return result; +} diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.h new file mode 100644 index 0000000..8798573 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_label.h @@ -0,0 +1,53 @@ +/** + * @file lv_draw_label.h + * + */ + +#ifndef LV_DRAW_LABEL_H +#define LV_DRAW_LABEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Write a text + * @param coords coordinates of the label + * @param mask the label will be drawn only in this area + * @param style pointer to a style + * @param opa_scale scale down all opacities by the factor + * @param txt 0 terminated text to write + * @param flag settings for the text from 'txt_flag_t' enum + * @param offset text offset in x and y direction (NULL if unused) + * + */ +void lv_draw_label(const lv_area_t * coords,const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale, + const char * txt, lv_txt_flag_t flag, lv_point_t * offset); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DRAW_LABEL_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.c new file mode 100644 index 0000000..6e72ff4 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.c @@ -0,0 +1,607 @@ +/** + * @file lv_draw_line.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_draw.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#if LV_COMPILER_VLA_SUPPORTED == 0 +#define LINE_MAX_WIDTH 64 +#endif + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_point_t p1; + lv_point_t p2; + lv_point_t p_act; + lv_coord_t dx; + lv_coord_t sx; /*-1: x1 < x2; 1: x2 >= x1*/ + lv_coord_t dy; + lv_coord_t sy; /*-1: y1 < y2; 1: y2 >= y1*/ + lv_coord_t err; + lv_coord_t e2; + bool hor; /*Rather horizontal or vertical*/ +} line_draw_t; + +typedef struct { + lv_coord_t width; + lv_coord_t width_1; + lv_coord_t width_half; +} line_width_t; + +/********************** + * STATIC PROTOTYPES + **********************/ +static void line_draw_hor(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void line_draw_ver(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void line_init(line_draw_t * line, const lv_point_t * p1, const lv_point_t * p2); +static bool line_next(line_draw_t * line); +static bool line_next_y(line_draw_t * line); +static bool line_next_x(line_draw_t * line); + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Draw a line + * @param point1 first point of the line + * @param point2 second point of the line + * @param mask the line will be drawn only on this area + * @param style pointer to a line's style + * @param opa_scale scale down all opacities by the factor + */ +void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, + const lv_style_t * style, lv_opa_t opa_scale) +{ + + if(style->line.width == 0) return; + if(point1->x == point2->x && point1->y == point2->y) return; + + line_draw_t main_line; + lv_point_t p1; + lv_point_t p2; + + /*If the line if rather vertical then be sure y1 < y2 else x1 < x2*/ + + if(LV_MATH_ABS(point1->x - point2->x) > LV_MATH_ABS(point1->y - point2->y)) { + + /*Steps less in y then x -> rather horizontal*/ + if(point1->x < point2->x) { + p1.x = point1->x; + p1.y = point1->y; + p2.x = point2->x; + p2.y = point2->y; + } else { + p1.x = point2->x; + p1.y = point2->y; + p2.x = point1->x; + p2.y = point1->y; + } + } else { + /*Steps less in x then y -> rather vertical*/ + if(point1->y < point2->y) { + p1.x = point1->x; + p1.y = point1->y; + p2.x = point2->x; + p2.y = point2->y; + } else { + p1.x = point2->x; + p1.y = point2->y; + p2.x = point1->x; + p2.y = point1->y; + } + } + + line_init(&main_line, &p1, &p2); + + + /*Special case draw a horizontal line*/ + if(main_line.p1.y == main_line.p2.y) { + line_draw_hor(&main_line, mask, style, opa_scale); + } + /*Special case draw a vertical line*/ + else if(main_line.p1.x == main_line.p2.x) { + line_draw_ver(&main_line, mask, style, opa_scale); + } + /*Arbitrary skew line*/ + else { + bool dir_ori = false; +#if LV_ANTIALIAS + lv_point_t p_tmp; + + if(main_line.hor) { + if(main_line.p1.y < main_line.p2.y) { + dir_ori = true; + p_tmp.x = main_line.p2.x; + p_tmp.y = main_line.p2.y - 1; + line_init(&main_line, &p1, &p_tmp); + main_line.sy = LV_MATH_ABS(main_line.sy); /*The sign can change if the line becomes horizontal*/ + } + else if(main_line.p1.y > main_line.p2.y) { + dir_ori = false; + p_tmp.x = main_line.p2.x; + p_tmp.y = main_line.p2.y + 1; + line_init(&main_line, &p1, &p_tmp); + main_line.sy = -LV_MATH_ABS(main_line.sy); /*The sign can change if the line becomes horizontal*/ + } + } + else { + if(main_line.p1.x < main_line.p2.x) { + dir_ori = true; + p_tmp.x = main_line.p2.x - 1; + p_tmp.y = main_line.p2.y; + line_init(&main_line, &p1, &p_tmp); + main_line.sx = LV_MATH_ABS(main_line.sx); /*The sign can change if the line becomes vertical*/ + } + else if(main_line.p1.x > main_line.p2.x) { + dir_ori = false; + p_tmp.x = main_line.p2.x + 1; + p_tmp.y = main_line.p2.y; + line_init(&main_line, &p1, &p_tmp); + main_line.sx = -LV_MATH_ABS(main_line.sx); /*The sign can change if the line becomes vertical*/ + } + } +#endif + line_draw_skew(&main_line, dir_ori, mask, style, opa_scale); + } +} + + +/********************** + * STATIC FUNCTIONS + **********************/ + + +static void line_draw_hor(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + lv_coord_t width = style->line.width - 1; + lv_coord_t width_half = width >> 1; + lv_coord_t width_1 = width & 0x1; + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->line.opa : (uint16_t)((uint16_t) style->line.opa * opa_scale) >> 8; + + lv_area_t act_area; + act_area.x1 = main_line->p1.x; + act_area.x2 = main_line->p2.x; + act_area.y1 = main_line->p1.y - width_half - width_1; + act_area.y2 = main_line->p2.y + width_half ; + + lv_area_t draw_area; + draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2); + draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2); + draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2); + draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2); + fill_fp(&draw_area, mask, style->line.color, opa); +} + +static void line_draw_ver(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + lv_coord_t width = style->line.width - 1; + lv_coord_t width_half = width >> 1; + lv_coord_t width_1 = width & 0x1; + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->line.opa : (uint16_t)((uint16_t) style->line.opa * opa_scale) >> 8; + + + lv_area_t act_area; + act_area.x1 = main_line->p1.x - width_half; + act_area.x2 = main_line->p2.x + width_half + width_1; + act_area.y1 = main_line->p1.y; + act_area.y2 = main_line->p2.y; + + lv_area_t draw_area; + draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2); + draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2); + draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2); + draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2); + fill_fp(&draw_area, mask, style->line.color, opa); +} + +static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->line.opa : (uint16_t)((uint16_t) style->line.opa * opa_scale) >> 8; + + lv_point_t vect_main, vect_norm; + vect_main.x = main_line->p2.x - main_line->p1.x; + vect_main.y = main_line->p2.y - main_line->p1.y; + + if(main_line->hor) { + if(main_line->p1.y < main_line->p2.y + dir_ori) { + vect_norm.x = - vect_main.y; + vect_norm.y = vect_main.x; + } else { + vect_norm.x = vect_main.y; + vect_norm.y = -vect_main.x; + } + } else { + if(main_line->p1.x < main_line->p2.x + dir_ori) { + vect_norm.x = vect_main.y; + vect_norm.y = - vect_main.x; + } else { + vect_norm.x = - vect_main.y; + vect_norm.y = vect_main.x; + } + } + + /* In case of a short but tick line the perpendicular ending is longer then the real line. + * it would break the calculations so make the normal vector larger*/ + vect_norm.x = vect_norm.x << 4; + vect_norm.y = vect_norm.y << 4; + + lv_coord_t width; + width = style->line.width; + + /* The pattern stores the points of the line ending. It has the good direction and length. + * The worth case is the 45° line where pattern can have 1.41 x `width` points*/ +#if LV_COMPILER_VLA_SUPPORTED + lv_point_t pattern[width * 2]; +#else + lv_point_t pattern[LINE_MAX_WIDTH]; +#endif + lv_coord_t i = 0; + + /*Create a perpendicular pattern (a small line)*/ + if(width != 0) { + line_draw_t pattern_line; + lv_point_t p0 = {0, 0}; + line_init(&pattern_line, &p0, &vect_norm); + + uint32_t width_sqr = width * width; + /* Run for a lot of times. Meanwhile the real width will be determined as well */ + for(i = 0; i < (lv_coord_t)sizeof(pattern); i ++) { + pattern[i].x = pattern_line.p_act.x; + pattern[i].y = pattern_line.p_act.y; + + /*Finish the pattern line if it's length equal to the desired width (Use Pythagoras theorem)*/ + uint32_t sqr = pattern_line.p_act.x * pattern_line.p_act.x + pattern_line.p_act.y * pattern_line.p_act.y; + if(sqr >= width_sqr) { + width = i; +#if LV_ANTIALIAS + width--; +#endif + break; + } + + line_next(&pattern_line); + } + } + +#if LV_ANTIALIAS + lv_coord_t width_safe = width; + if(width == 0) width_safe = 1; + + lv_coord_t aa_last_corner; + aa_last_corner = 0; +#endif + + lv_coord_t x_center_ofs = 0; + lv_coord_t y_center_ofs = 0; + + if(width != 0) { + x_center_ofs = pattern[width - 1].x / 2; + y_center_ofs = pattern[width - 1].y / 2; + } + else { + if(main_line->hor && main_line->p1.y >= main_line->p2.y + dir_ori) pattern[0].y --; + if(!main_line->hor && main_line->p1.x >= main_line->p2.x + dir_ori) pattern[0].x --; + } + + /* Make the coordinates relative to the center */ + for(i = 0; i < width; i++) { + pattern[i].x -= x_center_ofs; + pattern[i].y -= y_center_ofs; +#if LV_ANTIALIAS + if(i != 0) { + if(main_line->hor) { + if(pattern[i - 1].x != pattern[i].x) { + lv_coord_t seg_w = pattern[i].y - pattern[aa_last_corner].y; + if(main_line->sy < 0) { + lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w + 1, + seg_w, mask, style->line.color, opa); + + lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w + 1, + -seg_w, mask, style->line.color, opa); + } else { + lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y, + seg_w, mask, style->line.color, opa); + + lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y, + -seg_w, mask, style->line.color, opa); + } + aa_last_corner = i; + } + } else { + if(pattern[i - 1].y != pattern[i].y) { + lv_coord_t seg_w = pattern[i].x - pattern[aa_last_corner].x; + if(main_line->sx < 0) { + lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p1.y + pattern[aa_last_corner].y - 1, + seg_w, mask, style->line.color, opa); + + lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p2.y + pattern[aa_last_corner].y + 1, + -seg_w, mask, style->line.color, opa); + } else { + lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1, + seg_w, mask, style->line.color, opa); + + lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1, + -seg_w, mask, style->line.color, opa); + } + aa_last_corner = i; + } + } + + } +#endif + } + + + +#if LV_ANTIALIAS + /*Add the last part of anti-aliasing for the perpendicular ending*/ + if(width != 0) { /*Due to rounding error with very thin lines it looks ugly*/ + if(main_line->hor) { + lv_coord_t seg_w = pattern[width_safe - 1].y - pattern[aa_last_corner].y; + if(main_line->sy < 0) { + lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w, + seg_w + main_line->sy, mask, style->line.color, opa); + + lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w, + -(seg_w + main_line->sy), mask, style->line.color, opa); + + } else { + lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y, + seg_w + main_line->sy, mask, style->line.color, opa); + + lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y, + -(seg_w + main_line->sy), mask, style->line.color, opa); + } + } else { + lv_coord_t seg_w = pattern[width_safe - 1].x - pattern[aa_last_corner].x; + if(main_line->sx < 0) { + lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w, main_line->p1.y + pattern[aa_last_corner].y - 1, + seg_w + main_line->sx, mask, style->line.color, opa); + + lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w, main_line->p2.y + pattern[aa_last_corner].y + 1, + -(seg_w + main_line->sx), mask, style->line.color, opa); + + } else { + lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1, + seg_w + main_line->sx, mask, style->line.color, opa); + + lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1, + -(seg_w + main_line->sx), mask, style->line.color, opa); + } + + } + } +#endif + +#if LV_ANTIALIAS + + /*Shift the anti aliasing on the edges (-1, 1 or 0 (zero only in case width == 0))*/ + lv_coord_t aa_shift1; + lv_coord_t aa_shift2; + + if(main_line->hor == false) { + if(main_line->sx < 0) { + aa_shift1 = -1; + aa_shift2 = width == 0 ? 0 : aa_shift1; + } else { + aa_shift2 = 1; + aa_shift1 = width == 0 ? 0 : aa_shift2; + } + } else { + if(main_line->sy < 0) { + aa_shift1 = -1; + aa_shift2 = width == 0 ? 0 : aa_shift1; + } else { + aa_shift2 = 1; + aa_shift1 = width == 0 ? 0 : aa_shift2; + } + } + +#endif + + volatile lv_point_t prev_p; + prev_p.x = main_line->p1.x; + prev_p.y = main_line->p1.y; + lv_area_t draw_area; + bool first_run = true; + + if(main_line->hor) { + while(line_next_y(main_line)) { + for(i = 0; i < width; i++) { + draw_area.x1 = prev_p.x + pattern[i].x; + draw_area.y1 = prev_p.y + pattern[i].y; + draw_area.x2 = draw_area.x1 + main_line->p_act.x - prev_p.x - 1; + draw_area.y2 = draw_area.y1; + fill_fp(&draw_area, mask, style->line.color, opa); + + /* Fill the gaps + * When stepping in y one pixel remains empty on every corner (don't do this on the first segment ) */ + if(i != 0 && pattern[i].x != pattern[i - 1].x && !first_run) { + px_fp(draw_area.x1, draw_area.y1 - main_line->sy, mask, style->line.color, opa); + } + } + +#if LV_ANTIALIAS + lv_draw_aa_hor_seg(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1, + -(main_line->p_act.x - prev_p.x), mask, style->line.color, opa); + lv_draw_aa_hor_seg(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2, + main_line->p_act.x - prev_p.x, mask, style->line.color, opa); +#endif + + first_run = false; + + prev_p.x = main_line->p_act.x; + prev_p.y = main_line->p_act.y; + } + + for(i = 0; i < width; i++) { + draw_area.x1 = prev_p.x + pattern[i].x; + draw_area.y1 = prev_p.y + pattern[i].y; + draw_area.x2 = draw_area.x1 + main_line->p_act.x - prev_p.x; + draw_area.y2 = draw_area.y1; + fill_fp(&draw_area, mask, style->line.color, opa); + + /* Fill the gaps + * When stepping in y one pixel remains empty on every corner */ + if(i != 0 && pattern[i].x != pattern[i - 1].x && !first_run) { + px_fp(draw_area.x1, draw_area.y1 - main_line->sy, mask, style->line.color, opa); + } + } + +#if LV_ANTIALIAS + lv_draw_aa_hor_seg(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1, + -(main_line->p_act.x - prev_p.x + 1), mask, style->line.color, opa); + lv_draw_aa_hor_seg(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2, + main_line->p_act.x - prev_p.x + 1, mask, style->line.color, opa); +#endif + } + /*Rather a vertical line*/ + else { + + while(line_next_x(main_line)) { + for(i = 0; i < width; i++) { + draw_area.x1 = prev_p.x + pattern[i].x; + draw_area.y1 = prev_p.y + pattern[i].y; + draw_area.x2 = draw_area.x1; + draw_area.y2 = draw_area.y1 + main_line->p_act.y - prev_p.y - 1; + + fill_fp(&draw_area, mask, style->line.color, opa); + + /* Fill the gaps + * When stepping in x one pixel remains empty on every corner (don't do this on the first segment ) */ + if(i != 0 && pattern[i].y != pattern[i - 1].y && !first_run) { + px_fp(draw_area.x1 - main_line->sx, draw_area.y1, mask, style->line.color, opa); + } + + } + +#if LV_ANTIALIAS + lv_draw_aa_ver_seg(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y, + -(main_line->p_act.y - prev_p.y), mask, style->line.color, opa); + lv_draw_aa_ver_seg(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y, + main_line->p_act.y - prev_p.y, mask, style->line.color, opa); +#endif + + first_run = false; + + prev_p.x = main_line->p_act.x; + prev_p.y = main_line->p_act.y; + } + + /*Draw the last part*/ + for(i = 0; i < width; i++) { + draw_area.x1 = prev_p.x + pattern[i].x; + draw_area.y1 = prev_p.y + pattern[i].y; + draw_area.x2 = draw_area.x1; + draw_area.y2 = draw_area.y1 + main_line->p_act.y - prev_p.y; + + fill_fp(&draw_area, mask, style->line.color, opa); + + /* Fill the gaps + * When stepping in x one pixel remains empty on every corner */ + if(i != 0 && pattern[i].y != pattern[i - 1].y && !first_run) { + px_fp(draw_area.x1 - main_line->sx, draw_area.y1, mask, style->line.color, opa); + } + } + +#if LV_ANTIALIAS + lv_draw_aa_ver_seg(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y, + -(main_line->p_act.y - prev_p.y + 1), mask, style->line.color, opa); + lv_draw_aa_ver_seg(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y, + main_line->p_act.y - prev_p.y + 1, mask, style->line.color, opa); +#endif + } +} + + +static void line_init(line_draw_t * line, const lv_point_t * p1, const lv_point_t * p2) +{ + line->p1.x = p1->x; + line->p1.y = p1->y; + line->p2.x = p2->x; + line->p2.y = p2->y; + + line->dx = LV_MATH_ABS(line->p2.x - line->p1.x); + line->sx = line->p1.x < line->p2.x ? 1 : -1; + line->dy = LV_MATH_ABS(line->p2.y - line->p1.y); + line->sy = line->p1.y < line->p2.y ? 1 : -1; + line->err = (line->dx > line->dy ? line->dx : -line->dy) / 2; + line->e2 = 0; + line->hor = line->dx > line->dy ? true : false; /*Rather horizontal or vertical*/ + + line->p_act.x = line->p1.x; + line->p_act.y = line->p1.y; +} + +static bool line_next(line_draw_t * line) +{ + if(line->p_act.x == line->p2.x && line->p_act.y == line->p2.y) return false; + line->e2 = line->err; + if(line->e2 > -line->dx) { + line->err -= line->dy; + line->p_act.x += line->sx; + } + if(line->e2 < line->dy) { + line->err += line->dx; + line->p_act.y += line->sy; + } + return true; +} + +/** + * Iterate until step one in y direction. + * @param line + * @return + */ +static bool line_next_y(line_draw_t * line) +{ + lv_coord_t last_y = line->p_act.y; + + do { + if(!line_next(line)) return false; + } while(last_y == line->p_act.y); + + return true; + +} + +/** + * Iterate until step one in x direction. + * @param line + * @return + */ +static bool line_next_x(line_draw_t * line) +{ + lv_coord_t last_x = line->p_act.x; + + do { + if(!line_next(line)) return false; + } while(last_x == line->p_act.x); + + return true; + +} + diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.h new file mode 100644 index 0000000..4269475 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_line.h @@ -0,0 +1,49 @@ +/** + * @file lv_draw_line.h + * + */ + +#ifndef LV_DRAW_LINE_H +#define LV_DRAW_LINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Draw a line + * @param point1 first point of the line + * @param point2 second point of the line + * @param mask the line will be drawn only on this area + * @param style pointer to a line's style + * @param opa_scale scale down all opacities by the factor + */ +void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, + const lv_style_t * style, lv_opa_t opa_scale); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DRAW_LINE_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rbasic.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rbasic.c new file mode 100644 index 0000000..369adf5 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rbasic.c @@ -0,0 +1,269 @@ +/** + * @file lv_draw_rbasic.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_rbasic.h" +#if USE_LV_REAL_DRAW != 0 + +#include "../lv_hal/lv_hal_disp.h" +#include "../lv_misc/lv_font.h" +#include "lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static lv_color_t letter_bg_color; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Put a pixel to the display + * @param x x coordinate of the pixel + * @param y y coordinate of the pixel + * @param mask_p the pixel will be drawn on this area + * @param color color of the pixel + * @param opa opacity (ignored, only for compatibility with lv_vpx) + */ +void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa) +{ + (void)opa; /*Opa is used only for compatibility with lv_vpx*/ + + lv_area_t area; + area.x1 = x; + area.y1 = y; + area.x2 = x; + area.y2 = y; + + lv_rfill(&area, mask_p, color, LV_OPA_COVER); +} + +/** + * Fill an area on the display + * @param cords_p coordinates of the area to fill + * @param mask_p fill only o this mask + * @param color fill color + * @param opa opacity (ignored, only for compatibility with lv_vfill) + */ +void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p, + lv_color_t color, lv_opa_t opa) +{ + + (void)opa; /*Opa is used only for compatibility with lv_vfill*/ + + lv_area_t masked_area; + bool union_ok = true; + + if(mask_p != NULL) { + union_ok = lv_area_intersect(&masked_area, cords_p, mask_p); + } else { + lv_area_t scr_area; + lv_area_set(&scr_area, 0, 0, LV_HOR_RES - 1, LV_VER_RES - 1); + union_ok = lv_area_intersect(&masked_area, cords_p, &scr_area); + } + + if(union_ok != false) { + lv_disp_fill(masked_area.x1, masked_area.y1, masked_area.x2, masked_area.y2, color); + } +} + +/** + * Draw a letter to the display + * @param pos_p left-top coordinate of the latter + * @param mask_p the letter will be drawn only on this area + * @param font_p pointer to font + * @param letter a letter to draw + * @param color color of letter + * @param opa opacity of letter (ignored, only for compatibility with lv_vletter) + */ +void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p, + const lv_font_t * font_p, uint32_t letter, + lv_color_t color, lv_opa_t opa) +{ + (void)opa; /*Opa is used only for compatibility with lv_vletter*/ + + static uint8_t bpp1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/ + static uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/ + static uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ + 68, 85, 102, 119, + 136, 153, 170, 187, + 204, 221, 238, 255 + }; + + if(font_p == NULL) return; + + uint8_t letter_w = lv_font_get_width(font_p, letter); + uint8_t letter_h = lv_font_get_height(font_p); + uint8_t bpp = lv_font_get_bpp(font_p, letter); /*Bit per pixel (1,2, 4 or 8)*/ + uint8_t * bpp_opa_table; + uint8_t mask_init; + uint8_t mask; + + switch(bpp) { + case 1: + bpp_opa_table = bpp1_opa_table; + mask_init = 0x80; + break; + case 2: + bpp_opa_table = bpp2_opa_table; + mask_init = 0xC0; + break; + case 4: + bpp_opa_table = bpp4_opa_table; + mask_init = 0xF0; + break; + case 8: + bpp_opa_table = NULL; + mask_init = 0xFF; + break; /*No opa table, pixel value will be used directly*/ + default: + return; /*Invalid bpp. Can't render the letter*/ + } + + const uint8_t * map_p = lv_font_get_bitmap(font_p, letter); + + if(map_p == NULL) return; + + /*If the letter is completely out of mask don't draw it */ + if(pos_p->x + letter_w < mask_p->x1 || pos_p->x > mask_p->x2 || + pos_p->y + letter_h < mask_p->y1 || pos_p->y > mask_p->y2) return; + + lv_coord_t col, row; + uint8_t col_bit; + uint8_t col_byte_cnt; + uint8_t width_byte_scr = letter_w >> 3; /*Width in bytes (on the screen finally) (e.g. w = 11 -> 2 bytes wide)*/ + if(letter_w & 0x7) width_byte_scr++; + uint8_t width_byte_bpp = (letter_w * bpp) >> 3; /*Letter width in byte. Real width in the font*/ + if((letter_w * bpp) & 0x7) width_byte_bpp++; + + /* Calculate the col/row start/end on the map*/ + lv_coord_t col_start = pos_p->x >= mask_p->x1 ? 0 : mask_p->x1 - pos_p->x; + lv_coord_t col_end = pos_p->x + letter_w <= mask_p->x2 ? letter_w : mask_p->x2 - pos_p->x + 1; + lv_coord_t row_start = pos_p->y >= mask_p->y1 ? 0 : mask_p->y1 - pos_p->y; + lv_coord_t row_end = pos_p->y + letter_h <= mask_p->y2 ? letter_h : mask_p->y2 - pos_p->y + 1; + + /*Move on the map too*/ + map_p += (row_start * width_byte_bpp) + ((col_start * bpp) >> 3); + + uint8_t letter_px; + for(row = row_start; row < row_end; row ++) { + col_byte_cnt = 0; + col_bit = (col_start * bpp) % 8; + mask = mask_init >> col_bit; + for(col = col_start; col < col_end; col ++) { + letter_px = (*map_p & mask) >> (8 - col_bit - bpp); + if(letter_px != 0) { + lv_rpx(pos_p->x + col, pos_p->y + row, mask_p, lv_color_mix(color, letter_bg_color, bpp == 8 ? letter_px : bpp_opa_table[letter_px]), LV_OPA_COVER); + } + + if(col_bit < 8 - bpp) { + col_bit += bpp; + mask = mask >> bpp; + } else { + col_bit = 0; + col_byte_cnt ++; + mask = mask_init; + map_p ++; + } + } + + map_p += (width_byte_bpp) - col_byte_cnt; + } +} + +/** + * When the letter is ant-aliased it needs to know the background color + * @param bg_color the background color of the currently drawn letter + */ +void lv_rletter_set_background(lv_color_t color) +{ + letter_bg_color = color; +} + +/** + * Draw a color map to the display (image) + * @param cords_p coordinates the color map + * @param mask_p the map will drawn only on this area + * @param map_p pointer to a lv_color_t array + * @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap') + * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels + * @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it) + * @param recolor mix the pixels with this color + * @param recolor_opa the intense of recoloring + */ +void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p, + const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, + lv_color_t recolor, lv_opa_t recolor_opa) +{ + if(alpha_byte) return; /*Pixel level opacity i not supported in real map drawing*/ + + (void)opa; /*opa is used only for compatibility with lv_vmap*/ + lv_area_t masked_a; + bool union_ok; + + union_ok = lv_area_intersect(&masked_a, cords_p, mask_p); + + /*If there are common part of the mask and map then draw the map*/ + if(union_ok == false) return; + + /*Go to the first pixel*/ + lv_coord_t map_width = lv_area_get_width(cords_p); + map_p += (masked_a.y1 - cords_p->y1) * map_width * sizeof(lv_color_t); + map_p += (masked_a.x1 - cords_p->x1) * sizeof(lv_color_t); + + lv_coord_t row; + if(recolor_opa == LV_OPA_TRANSP && chroma_key == false) { + lv_coord_t mask_w = lv_area_get_width(&masked_a) - 1; + for(row = masked_a.y1; row <= masked_a.y2; row++) { + lv_disp_map(masked_a.x1, row, masked_a.x1 + mask_w, row, (lv_color_t *)map_p); + map_p += map_width * sizeof(lv_color_t); /*Next row on the map*/ + } + } else { + lv_color_t chroma_key_color = LV_COLOR_TRANSP; + lv_coord_t col; + for(row = masked_a.y1; row <= masked_a.y2; row++) { + for(col = masked_a.x1; col <= masked_a.x2; col++) { + lv_color_t * px_color = (lv_color_t *) &map_p[(uint32_t)(col - masked_a.x1) * sizeof(lv_color_t)]; + + if(chroma_key && chroma_key_color.full == px_color->full) continue; + + if(recolor_opa != LV_OPA_TRANSP) { + lv_color_t recolored_px = lv_color_mix(recolor, *px_color, recolor_opa); + + lv_rpx(col, row, mask_p, recolored_px, LV_OPA_COVER); + } else { + lv_rpx(col, row, mask_p, *px_color, LV_OPA_COVER); + } + + } + map_p += map_width * sizeof(lv_color_t); /*Next row on the map*/ + } + } +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif /*USE_LV_REAL_DRAW*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rbasic.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rbasic.h new file mode 100644 index 0000000..b1d62f3 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rbasic.h @@ -0,0 +1,96 @@ +/** + * @file lv_draw_rbasic..h + * + */ + +#ifndef LV_DRAW_RBASIC_H +#define LV_DRAW_RBASIC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_REAL_DRAW != 0 + +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_area.h" +#include "../lv_misc/lv_font.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); + +/** + * Fill an area on the display + * @param cords_p coordinates of the area to fill + * @param mask_p fill only o this mask + * @param color fill color + * @param opa opacity (ignored, only for compatibility with lv_vfill) + */ +void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p, + lv_color_t color, lv_opa_t opa); + +/** + * Draw a letter to the display + * @param pos_p left-top coordinate of the latter + * @param mask_p the letter will be drawn only on this area + * @param font_p pointer to font + * @param letter a letter to draw + * @param color color of letter + * @param opa opacity of letter (ignored, only for compatibility with lv_vletter) + */ +void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p, + const lv_font_t * font_p, uint32_t letter, + lv_color_t color, lv_opa_t opa); + +/** + * When the letter is ant-aliased it needs to know the background color + * @param bg_color the background color of the currently drawn letter + */ +void lv_rletter_set_background(lv_color_t color); + + +/** + * Draw a color map to the display (image) + * @param cords_p coordinates the color map + * @param mask_p the map will drawn only on this area + * @param map_p pointer to a lv_color_t array + * @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap') + * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels + * @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it) + * @param recolor mix the pixels with this color + * @param recolor_opa the intense of recoloring + */ +void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p, + const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, + lv_color_t recolor, lv_opa_t recolor_opa); +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_REAL_DRAW*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DRAW_RBASIC_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.c new file mode 100644 index 0000000..5b4ef16 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.c @@ -0,0 +1,1435 @@ +/** + * @file lv_draw_rect.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_rect.h" +#include "../lv_misc/lv_circ.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD 5 /*Circle segment greater then this value will be anti-aliased by a non-linear (cos) opacity mapping*/ + +#define SHADOW_OPA_EXTRA_PRECISION 8 /*Calculate with 2^x bigger shadow opacity values to avoid rounding errors*/ +#define SHADOW_BOTTOM_AA_EXTRA_RADIUS 3 /*Add extra radius with LV_SHADOW_BOTTOM to cover anti-aliased corners*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void lv_draw_rect_main_mid(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void lv_draw_rect_main_corner(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void lv_draw_rect_border_straight(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void lv_draw_rect_border_corner(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); + +#if USE_LV_SHADOW && LV_VDB_SIZE +static void lv_draw_shadow(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void lv_draw_shadow_full(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void lv_draw_shadow_bottom(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); +static void lv_draw_shadow_full_straight(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, const lv_opa_t * map); +#endif + +static uint16_t lv_draw_cont_radius_corr(uint16_t r, lv_coord_t w, lv_coord_t h); + +#if LV_ANTIALIAS +static lv_opa_t antialias_get_opa_circ(lv_coord_t seg, lv_coord_t px_id, lv_opa_t opa); +#endif + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Draw a rectangle + * @param coords the coordinates of the rectangle + * @param mask the rectangle will be drawn only in this mask + * @param style pointer to a style + * @param opa_scale scale down all opacities by the factor + */ +void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + if(lv_area_get_height(coords) < 1 || lv_area_get_width(coords) < 1) return; + +#if USE_LV_SHADOW && LV_VDB_SIZE + if(style->body.shadow.width != 0) { + lv_draw_shadow(coords, mask, style, opa_scale); + } +#endif + if(style->body.empty == 0 && style->body.opa >= LV_OPA_MIN) { + lv_draw_rect_main_mid(coords, mask, style, opa_scale); + + if(style->body.radius != 0) { + lv_draw_rect_main_corner(coords, mask, style, opa_scale); + } + } + + if(style->body.border.width != 0 && style->body.border.part != LV_BORDER_NONE && style->body.border.opa >= LV_OPA_MIN) { + lv_draw_rect_border_straight(coords, mask, style, opa_scale); + + if(style->body.radius != 0) { + lv_draw_rect_border_corner(coords, mask, style, opa_scale); + } + } +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Draw the middle part (rectangular) of a rectangle + * @param coords the coordinates of the original rectangle + * @param mask the rectangle will be drawn only on this area + * @param rects_p pointer to a rectangle style + * @param opa_scale scale down all opacities by the factor + */ +static void lv_draw_rect_main_mid(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + uint16_t radius = style->body.radius; + + lv_color_t mcolor = style->body.main_color; + lv_color_t gcolor = style->body.grad_color; + uint8_t mix; + lv_coord_t height = lv_area_get_height(coords); + lv_coord_t width = lv_area_get_width(coords); + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.opa : (uint16_t)((uint16_t) style->body.opa * opa_scale) >> 8; + + radius = lv_draw_cont_radius_corr(radius, width, height); + + /*If the radius is too big then there is no body*/ + if(radius > height / 2) return; + + lv_area_t work_area; + work_area.x1 = coords->x1; + work_area.x2 = coords->x2; + + if(mcolor.full == gcolor.full) { + work_area.y1 = coords->y1 + radius; + work_area.y2 = coords->y2 - radius; + + if(style->body.radius != 0) { +#if LV_ANTIALIAS + work_area.y1 += 2; + work_area.y2 -= 2; +#else + work_area.y1 += 1; + work_area.y2 -= 1; +#endif + } + + fill_fp(&work_area, mask, mcolor, opa); + } else { + lv_coord_t row; + lv_coord_t row_start = coords->y1 + radius; + lv_coord_t row_end = coords->y2 - radius; + lv_color_t act_color; + + if(style->body.radius != 0) { +#if LV_ANTIALIAS + row_start += 2; + row_end -= 2; +#else + row_start += 1; + row_end -= 1; +#endif + } + if(row_start < 0) row_start = 0; + + for(row = row_start; row <= row_end; row ++) { + work_area.y1 = row; + work_area.y2 = row; + mix = (uint32_t)((uint32_t)(coords->y2 - work_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + + fill_fp(&work_area, mask, act_color, opa); + } + } +} +/** + * Draw the top and bottom parts (corners) of a rectangle + * @param coords the coordinates of the original rectangle + * @param mask the rectangle will be drawn only on this area + * @param rects_p pointer to a rectangle style + * @param opa_scale scale down all opacities by the factor + */ +static void lv_draw_rect_main_corner(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + uint16_t radius = style->body.radius; + + lv_color_t mcolor = style->body.main_color; + lv_color_t gcolor = style->body.grad_color; + lv_color_t act_color; + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.opa : (uint16_t)((uint16_t) style->body.opa * opa_scale) >> 8; + uint8_t mix; + lv_coord_t height = lv_area_get_height(coords); + lv_coord_t width = lv_area_get_width(coords); + + radius = lv_draw_cont_radius_corr(radius, width, height); + + lv_point_t lt_origo; /*Left Top origo*/ + lv_point_t lb_origo; /*Left Bottom origo*/ + lv_point_t rt_origo; /*Right Top origo*/ + lv_point_t rb_origo; /*Left Bottom origo*/ + + lt_origo.x = coords->x1 + radius + LV_ANTIALIAS; + lt_origo.y = coords->y1 + radius + LV_ANTIALIAS; + + lb_origo.x = coords->x1 + radius + LV_ANTIALIAS; + lb_origo.y = coords->y2 - radius - LV_ANTIALIAS; + + rt_origo.x = coords->x2 - radius - LV_ANTIALIAS; + rt_origo.y = coords->y1 + radius + LV_ANTIALIAS; + + rb_origo.x = coords->x2 - radius - LV_ANTIALIAS; + rb_origo.y = coords->y2 - radius - LV_ANTIALIAS; + + lv_area_t edge_top_area; + lv_area_t mid_top_area; + lv_area_t mid_bot_area; + lv_area_t edge_bot_area; + + lv_point_t cir; + lv_coord_t cir_tmp; + lv_circ_init(&cir, &cir_tmp, radius); + + /*Init the areas*/ + lv_area_set(&mid_bot_area, lb_origo.x + LV_CIRC_OCT4_X(cir), + lb_origo.y + LV_CIRC_OCT4_Y(cir), + rb_origo.x + LV_CIRC_OCT1_X(cir), + rb_origo.y + LV_CIRC_OCT1_Y(cir)); + + lv_area_set(&edge_bot_area, lb_origo.x + LV_CIRC_OCT3_X(cir), + lb_origo.y + LV_CIRC_OCT3_Y(cir), + rb_origo.x + LV_CIRC_OCT2_X(cir), + rb_origo.y + LV_CIRC_OCT2_Y(cir)); + + lv_area_set(&mid_top_area, lt_origo.x + LV_CIRC_OCT5_X(cir), + lt_origo.y + LV_CIRC_OCT5_Y(cir), + rt_origo.x + LV_CIRC_OCT8_X(cir), + rt_origo.y + LV_CIRC_OCT8_Y(cir)); + + lv_area_set(&edge_top_area, lt_origo.x + LV_CIRC_OCT6_X(cir), + lt_origo.y + LV_CIRC_OCT6_Y(cir), + rt_origo.x + LV_CIRC_OCT7_X(cir), + rt_origo.y + LV_CIRC_OCT7_Y(cir)); +#if LV_ANTIALIAS + /*Store some internal states for anti-aliasing*/ + lv_coord_t out_y_seg_start = 0; + lv_coord_t out_y_seg_end = 0; + lv_coord_t out_x_last = radius; + + lv_color_t aa_color_hor_top; + lv_color_t aa_color_hor_bottom; + lv_color_t aa_color_ver; +#endif + + while(lv_circ_cont(&cir)) { +#if LV_ANTIALIAS != 0 + /*New step in y on the outter circle*/ + if(out_x_last != cir.x) { + out_y_seg_end = cir.y; + lv_coord_t seg_size = out_y_seg_end - out_y_seg_start; + lv_point_t aa_p; + + aa_p.x = out_x_last; + aa_p.y = out_y_seg_start; + + mix = (uint32_t)((uint32_t)(radius - out_x_last) * 255) / height; + aa_color_hor_top = lv_color_mix(gcolor, mcolor, mix); + aa_color_hor_bottom = lv_color_mix(mcolor, gcolor, mix); + + lv_coord_t i; + for(i = 0; i < seg_size; i++) { + lv_opa_t aa_opa; + if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/ + aa_opa = antialias_get_opa_circ(seg_size, i, opa); + } else { + aa_opa = opa - lv_draw_aa_get_opa(seg_size, i, opa); + } + + px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, aa_color_hor_bottom, aa_opa); + px_fp(lb_origo.x + LV_CIRC_OCT3_X(aa_p) - i, lb_origo.y + LV_CIRC_OCT3_Y(aa_p) + 1, mask, aa_color_hor_bottom, aa_opa); + px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p) - i, lt_origo.y + LV_CIRC_OCT6_Y(aa_p) - 1, mask, aa_color_hor_top, aa_opa); + px_fp(rt_origo.x + LV_CIRC_OCT7_X(aa_p) + i, rt_origo.y + LV_CIRC_OCT7_Y(aa_p) - 1, mask, aa_color_hor_top, aa_opa); + + mix = (uint32_t)((uint32_t)(radius - out_y_seg_start + i) * 255) / height; + aa_color_ver = lv_color_mix(mcolor, gcolor, mix); + px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) + 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, aa_color_ver, aa_opa); + px_fp(lb_origo.x + LV_CIRC_OCT4_X(aa_p) - 1, lb_origo.y + LV_CIRC_OCT4_Y(aa_p) + i, mask, aa_color_ver, aa_opa); + + aa_color_ver = lv_color_mix(gcolor, mcolor, mix); + px_fp(lt_origo.x + LV_CIRC_OCT5_X(aa_p) - 1, lt_origo.y + LV_CIRC_OCT5_Y(aa_p) - i, mask, aa_color_ver, aa_opa); + px_fp(rt_origo.x + LV_CIRC_OCT8_X(aa_p) + 1, rt_origo.y + LV_CIRC_OCT8_Y(aa_p) - i, mask, aa_color_ver, aa_opa); + } + + out_x_last = cir.x; + out_y_seg_start = out_y_seg_end; + } +#endif + uint8_t edge_top_refr = 0; + uint8_t mid_top_refr = 0; + uint8_t mid_bot_refr = 0; + uint8_t edge_bot_refr = 0; + + /* If a new row coming draw the previous + * The y coordinate can remain the same so wait for a new*/ + if(mid_bot_area.y1 != LV_CIRC_OCT4_Y(cir) + lb_origo.y) mid_bot_refr = 1; + + if(edge_bot_area.y1 != LV_CIRC_OCT2_Y(cir) + lb_origo.y) edge_bot_refr = 1; + + if(mid_top_area.y1 != LV_CIRC_OCT8_Y(cir) + lt_origo.y) mid_top_refr = 1; + + if(edge_top_area.y1 != LV_CIRC_OCT7_Y(cir) + lt_origo.y) edge_top_refr = 1; + + /*Draw the areas which are not disabled*/ + if(edge_top_refr != 0) { + if(mcolor.full == gcolor.full) act_color = mcolor; + else { + mix = (uint32_t)((uint32_t)(coords->y2 - edge_top_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + } + fill_fp(&edge_top_area, mask, act_color, opa); + } + + if(mid_top_refr != 0) { + if(mcolor.full == gcolor.full) act_color = mcolor; + else { + mix = (uint32_t)((uint32_t)(coords->y2 - mid_top_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + } + fill_fp(&mid_top_area, mask, act_color, opa); + } + + if(mid_bot_refr != 0) { + if(mcolor.full == gcolor.full) act_color = mcolor; + else { + mix = (uint32_t)((uint32_t)(coords->y2 - mid_bot_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + } + fill_fp(&mid_bot_area, mask, act_color, opa); + } + + if(edge_bot_refr != 0) { + + if(mcolor.full == gcolor.full) act_color = mcolor; + else { + mix = (uint32_t)((uint32_t)(coords->y2 - edge_bot_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + } + fill_fp(&edge_bot_area, mask, act_color, opa); + } + + /*Save the current coordinates*/ + lv_area_set(&mid_bot_area, lb_origo.x + LV_CIRC_OCT4_X(cir), + lb_origo.y + LV_CIRC_OCT4_Y(cir), + rb_origo.x + LV_CIRC_OCT1_X(cir), + rb_origo.y + LV_CIRC_OCT1_Y(cir)); + + lv_area_set(&edge_bot_area, lb_origo.x + LV_CIRC_OCT3_X(cir), + lb_origo.y + LV_CIRC_OCT3_Y(cir), + rb_origo.x + LV_CIRC_OCT2_X(cir), + rb_origo.y + LV_CIRC_OCT2_Y(cir)); + + lv_area_set(&mid_top_area, lt_origo.x + LV_CIRC_OCT5_X(cir), + lt_origo.y + LV_CIRC_OCT5_Y(cir), + rt_origo.x + LV_CIRC_OCT8_X(cir), + rt_origo.y + LV_CIRC_OCT8_Y(cir)); + + lv_area_set(&edge_top_area, lt_origo.x + LV_CIRC_OCT6_X(cir), + lt_origo.y + LV_CIRC_OCT6_Y(cir), + rt_origo.x + LV_CIRC_OCT7_X(cir), + rt_origo.y + LV_CIRC_OCT7_Y(cir)); + + lv_circ_next(&cir, &cir_tmp); + } + + if(mcolor.full == gcolor.full) act_color = mcolor; + else { + mix = (uint32_t)((uint32_t)(coords->y2 - edge_top_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + } + fill_fp(&edge_top_area, mask, act_color, opa); + + if(edge_top_area.y1 != mid_top_area.y1) { + + if(mcolor.full == gcolor.full) act_color = mcolor; + else { + mix = (uint32_t)((uint32_t)(coords->y2 - mid_top_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + } + fill_fp(&mid_top_area, mask, act_color, opa); + } + + if(mcolor.full == gcolor.full) act_color = mcolor; + else { + mix = (uint32_t)((uint32_t)(coords->y2 - mid_bot_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + } + fill_fp(&mid_bot_area, mask, act_color, opa); + + if(edge_bot_area.y1 != mid_bot_area.y1) { + + if(mcolor.full == gcolor.full) act_color = mcolor; + else { + mix = (uint32_t)((uint32_t)(coords->y2 - edge_bot_area.y1) * 255) / height; + act_color = lv_color_mix(mcolor, gcolor, mix); + } + fill_fp(&edge_bot_area, mask, act_color, opa); + } + + +#if LV_ANTIALIAS + /*The first and the last line is not drawn*/ + edge_top_area.x1 = coords->x1 + radius + 2; + edge_top_area.x2 = coords->x2 - radius - 2; + edge_top_area.y1 = coords->y1; + edge_top_area.y2 = coords->y1; + fill_fp(&edge_top_area, mask, style->body.main_color, opa); + + edge_top_area.y1 = coords->y2; + edge_top_area.y2 = coords->y2; + fill_fp(&edge_top_area, mask, style->body.grad_color, opa); + + /*Last parts of the anti-alias*/ + out_y_seg_end = cir.y; + lv_coord_t seg_size = out_y_seg_end - out_y_seg_start; + lv_point_t aa_p; + + aa_p.x = out_x_last; + aa_p.y = out_y_seg_start; + + mix = (uint32_t)((uint32_t)(radius - out_x_last) * 255) / height; + aa_color_hor_bottom = lv_color_mix(gcolor, mcolor, mix); + aa_color_hor_top = lv_color_mix(mcolor, gcolor, mix); + + lv_coord_t i; + for(i = 0; i < seg_size; i++) { + lv_opa_t aa_opa = opa - lv_draw_aa_get_opa(seg_size, i, opa); + px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, aa_color_hor_top, aa_opa); + px_fp(lb_origo.x + LV_CIRC_OCT3_X(aa_p) - i, lb_origo.y + LV_CIRC_OCT3_Y(aa_p) + 1, mask, aa_color_hor_top, aa_opa); + px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p) - i, lt_origo.y + LV_CIRC_OCT6_Y(aa_p) - 1, mask, aa_color_hor_bottom, aa_opa); + px_fp(rt_origo.x + LV_CIRC_OCT7_X(aa_p) + i, rt_origo.y + LV_CIRC_OCT7_Y(aa_p) - 1, mask, aa_color_hor_bottom, aa_opa); + + mix = (uint32_t)((uint32_t)(radius - out_y_seg_start + i) * 255) / height; + aa_color_ver = lv_color_mix(mcolor, gcolor, mix); + px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) + 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, aa_color_ver, aa_opa); + px_fp(lb_origo.x + LV_CIRC_OCT4_X(aa_p) - 1, lb_origo.y + LV_CIRC_OCT4_Y(aa_p) + i, mask, aa_color_ver, aa_opa); + + aa_color_ver = lv_color_mix(gcolor, mcolor, mix); + px_fp(lt_origo.x + LV_CIRC_OCT5_X(aa_p) - 1, lt_origo.y + LV_CIRC_OCT5_Y(aa_p) - i, mask, aa_color_ver, aa_opa); + px_fp(rt_origo.x + LV_CIRC_OCT8_X(aa_p) + 1, rt_origo.y + LV_CIRC_OCT8_Y(aa_p) - i, mask, aa_color_ver, aa_opa); + } + + /*In some cases the last pixel is not drawn*/ + if(LV_MATH_ABS(aa_p.x - aa_p.y) == seg_size) { + aa_p.x = out_x_last; + aa_p.y = out_x_last; + + mix = (uint32_t)((uint32_t)(out_x_last) * 255) / height; + aa_color_hor_top = lv_color_mix(gcolor, mcolor, mix); + aa_color_hor_bottom = lv_color_mix(mcolor, gcolor, mix); + + lv_opa_t aa_opa = opa >> 1; + px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p), rb_origo.y + LV_CIRC_OCT2_Y(aa_p), mask, aa_color_hor_bottom, aa_opa); + px_fp(lb_origo.x + LV_CIRC_OCT4_X(aa_p), lb_origo.y + LV_CIRC_OCT4_Y(aa_p), mask, aa_color_hor_bottom, aa_opa); + px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p), lt_origo.y + LV_CIRC_OCT6_Y(aa_p), mask, aa_color_hor_top, aa_opa); + px_fp(rt_origo.x + LV_CIRC_OCT8_X(aa_p), rt_origo.y + LV_CIRC_OCT8_Y(aa_p), mask, aa_color_hor_top, aa_opa); + } + +#endif + + +} + +/** + * Draw the straight parts of a rectangle border + * @param coords the coordinates of the original rectangle + * @param mask_ the rectangle will be drawn only on this area + * @param rstyle pointer to a rectangle style + * @param opa_scale scale down all opacities by the factor + */ +static void lv_draw_rect_border_straight(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + uint16_t radius = style->body.radius; + + lv_coord_t width = lv_area_get_width(coords); + lv_coord_t height = lv_area_get_height(coords); + uint16_t bwidth = style->body.border.width; + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.border.opa : (uint16_t)((uint16_t) style->body.border.opa * opa_scale) >> 8; + lv_border_part_t part = style->body.border.part; + lv_color_t color = style->body.border.color; + lv_area_t work_area; + lv_coord_t length_corr = 0; + lv_coord_t corner_size = 0; + + /*the 0 px border width drawn as 1 px, so decrement the b_width*/ + bwidth--; + + radius = lv_draw_cont_radius_corr(radius, width, height); + + if(radius < bwidth) { + length_corr = bwidth - radius - LV_ANTIALIAS; + corner_size = bwidth; + } else { + corner_size = radius + LV_ANTIALIAS; + } + + /*If radius == 0 is a special case*/ + if(style->body.radius == 0) { + /*Left top corner*/ + if(part & LV_BORDER_TOP) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x2; + work_area.y1 = coords->y1; + work_area.y2 = coords->y1 + bwidth; + fill_fp(&work_area, mask, color, opa); + } + + /*Right top corner*/ + if(part & LV_BORDER_RIGHT) { + work_area.x1 = coords->x2 - bwidth; + work_area.x2 = coords->x2; + work_area.y1 = coords->y1 + (part & LV_BORDER_TOP ? bwidth + 1 : 0); + work_area.y2 = coords->y2 - (part & LV_BORDER_BOTTOM ? bwidth + 1 : 0); + fill_fp(&work_area, mask, color, opa); + } + + /*Left bottom corner*/ + if(part & LV_BORDER_LEFT) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x1 + bwidth; + work_area.y1 = coords->y1 + (part & LV_BORDER_TOP ? bwidth + 1 : 0); + work_area.y2 = coords->y2 - (part & LV_BORDER_BOTTOM ? bwidth + 1 : 0); + fill_fp(&work_area, mask, color, opa); + } + + /*Right bottom corner*/ + if(part & LV_BORDER_BOTTOM) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x2; + work_area.y1 = coords->y2 - bwidth; + work_area.y2 = coords->y2; + fill_fp(&work_area, mask, color, opa); + } + return; + } + + /* Modify the corner_size if corner is drawn */ + corner_size ++; + + /*Depending one which part's are drawn modify the area lengths */ + if(part & LV_BORDER_TOP) work_area.y1 = coords->y1 + corner_size; + else work_area.y1 = coords->y1 + radius; + + if(part & LV_BORDER_BOTTOM) work_area.y2 = coords->y2 - corner_size; + else work_area.y2 = coords->y2 - radius; + + /*Left border*/ + if(part & LV_BORDER_LEFT) { + work_area.x1 = coords->x1; + work_area.x2 = work_area.x1 + bwidth; + fill_fp(&work_area, mask, color, opa); + } + + /*Right border*/ + if(part & LV_BORDER_RIGHT) { + work_area.x2 = coords->x2; + work_area.x1 = work_area.x2 - bwidth; + fill_fp(&work_area, mask, color, opa); + } + + work_area.x1 = coords->x1 + corner_size - length_corr; + work_area.x2 = coords->x2 - corner_size + length_corr; + + /*Upper border*/ + if(part & LV_BORDER_TOP) { + work_area.y1 = coords->y1; + work_area.y2 = coords->y1 + bwidth; + fill_fp(&work_area, mask, color, opa); + } + + /*Lower border*/ + if(part & LV_BORDER_BOTTOM) { + work_area.y2 = coords->y2; + work_area.y1 = work_area.y2 - bwidth; + fill_fp(&work_area, mask, color, opa); + } + + /*Draw the a remaining rectangles if the radius is smaller then bwidth */ + if(length_corr != 0) { + /*Left top correction*/ + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x1 + radius + LV_ANTIALIAS; + work_area.y1 = coords->y1 + radius + 1 + LV_ANTIALIAS; + work_area.y2 = coords->y1 + bwidth; + fill_fp(&work_area, mask, color, opa); + } + + /*Right top correction*/ + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + work_area.x1 = coords->x2 - radius - LV_ANTIALIAS; + work_area.x2 = coords->x2; + work_area.y1 = coords->y1 + radius + 1 + LV_ANTIALIAS; + work_area.y2 = coords->y1 + bwidth; + fill_fp(&work_area, mask, color, opa); + } + + /*Left bottom correction*/ + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x1 + radius + LV_ANTIALIAS; + work_area.y1 = coords->y2 - bwidth; + work_area.y2 = coords->y2 - radius - 1 - LV_ANTIALIAS; + fill_fp(&work_area, mask, color, opa); + } + + /*Right bottom correction*/ + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + work_area.x1 = coords->x2 - radius - LV_ANTIALIAS; + work_area.x2 = coords->x2; + work_area.y1 = coords->y2 - bwidth; + work_area.y2 = coords->y2 - radius - 1 - LV_ANTIALIAS; + fill_fp(&work_area, mask, color, opa); + } + } + + /*If radius == 0 one px on the corners are not drawn by main drawer*/ + if(style->body.radius == 0) { + /*Left top corner*/ + if(part & (LV_BORDER_TOP | LV_BORDER_LEFT)) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x1 + LV_ANTIALIAS; + work_area.y1 = coords->y1; + work_area.y2 = coords->y1 + LV_ANTIALIAS; + fill_fp(&work_area, mask, color, opa); + } + + /*Right top corner*/ + if(part & (LV_BORDER_TOP | LV_BORDER_RIGHT)) { + work_area.x1 = coords->x2 - LV_ANTIALIAS; + work_area.x2 = coords->x2; + work_area.y1 = coords->y1; + work_area.y2 = coords->y1 + LV_ANTIALIAS; + fill_fp(&work_area, mask, color, opa); + } + + /*Left bottom corner*/ + if(part & (LV_BORDER_BOTTOM | LV_BORDER_LEFT)) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x1 + LV_ANTIALIAS; + work_area.y1 = coords->y2 - LV_ANTIALIAS; + work_area.y2 = coords->y2; + fill_fp(&work_area, mask, color, opa); + } + + /*Right bottom corner*/ + if(part & (LV_BORDER_BOTTOM | LV_BORDER_RIGHT)) { + work_area.x1 = coords->x2 - LV_ANTIALIAS; + work_area.x2 = coords->x2; + work_area.y1 = coords->y2 - LV_ANTIALIAS; + work_area.y2 = coords->y2; + fill_fp(&work_area, mask, color, opa); + } + } +} + + +/** + * Draw the corners of a rectangle border + * @param coords the coordinates of the original rectangle + * @param mask the rectangle will be drawn only on this area + * @param style pointer to a style + * @param opa_scale scale down all opacities by the factor + */ +static void lv_draw_rect_border_corner(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + uint16_t radius = style->body.radius ; + uint16_t bwidth = style->body.border.width; + lv_color_t color = style->body.border.color; + lv_border_part_t part = style->body.border.part; + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.border.opa : (uint16_t)((uint16_t) style->body.border.opa * opa_scale) >> 8; + /*0 px border width drawn as 1 px, so decrement the bwidth*/ + bwidth--; + +#if LV_ANTIALIAS + bwidth--; /*Because of anti-aliasing the border seems one pixel ticker*/ +#endif + + lv_coord_t width = lv_area_get_width(coords); + lv_coord_t height = lv_area_get_height(coords); + + radius = lv_draw_cont_radius_corr(radius, width, height); + + lv_point_t lt_origo; /*Left Top origo*/ + lv_point_t lb_origo; /*Left Bottom origo*/ + lv_point_t rt_origo; /*Right Top origo*/ + lv_point_t rb_origo; /*Left Bottom origo*/ + + lt_origo.x = coords->x1 + radius + LV_ANTIALIAS; + lt_origo.y = coords->y1 + radius + LV_ANTIALIAS; + + lb_origo.x = coords->x1 + radius + LV_ANTIALIAS; + lb_origo.y = coords->y2 - radius - LV_ANTIALIAS; + + rt_origo.x = coords->x2 - radius - LV_ANTIALIAS; + rt_origo.y = coords->y1 + radius + LV_ANTIALIAS; + + rb_origo.x = coords->x2 - radius - LV_ANTIALIAS; + rb_origo.y = coords->y2 - radius - LV_ANTIALIAS; + + lv_point_t cir_out; + lv_coord_t tmp_out; + lv_circ_init(&cir_out, &tmp_out, radius); + + lv_point_t cir_in; + lv_coord_t tmp_in; + lv_coord_t radius_in = radius - bwidth; + + if(radius_in < 0) { + radius_in = 0; + } + + lv_circ_init(&cir_in, &tmp_in, radius_in); + + lv_area_t circ_area; + lv_coord_t act_w1; + lv_coord_t act_w2; + +#if LV_ANTIALIAS + /*Store some internal states for anti-aliasing*/ + lv_coord_t out_y_seg_start = 0; + lv_coord_t out_y_seg_end = 0; + lv_coord_t out_x_last = radius; + + + lv_coord_t in_y_seg_start = 0; + lv_coord_t in_y_seg_end = 0; + lv_coord_t in_x_last = radius - bwidth; +#endif + + while(cir_out.y <= cir_out.x) { + + /*Calculate the actual width to avoid overwriting pixels*/ + if(cir_in.y < cir_in.x) { + act_w1 = cir_out.x - cir_in.x; + act_w2 = act_w1; + } else { + act_w1 = cir_out.x - cir_out.y; + act_w2 = act_w1 - 1; + } + +#if LV_ANTIALIAS != 0 + /*New step in y on the outter circle*/ + if(out_x_last != cir_out.x) { + out_y_seg_end = cir_out.y; + lv_coord_t seg_size = out_y_seg_end - out_y_seg_start; + lv_point_t aa_p; + + aa_p.x = out_x_last; + aa_p.y = out_y_seg_start; + + lv_coord_t i; + for(i = 0; i < seg_size; i++) { + lv_opa_t aa_opa; + + if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/ + aa_opa = antialias_get_opa_circ(seg_size, i, opa); + } else { + aa_opa = opa - lv_draw_aa_get_opa(seg_size, i, opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) + 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, style->body.border.color, aa_opa); + px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + px_fp(lb_origo.x + LV_CIRC_OCT3_X(aa_p) - i, lb_origo.y + LV_CIRC_OCT3_Y(aa_p) + 1, mask, style->body.border.color, aa_opa); + px_fp(lb_origo.x + LV_CIRC_OCT4_X(aa_p) - 1, lb_origo.y + LV_CIRC_OCT4_Y(aa_p) + i, mask, style->body.border.color, aa_opa); + } + + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + px_fp(lt_origo.x + LV_CIRC_OCT5_X(aa_p) - 1, lt_origo.y + LV_CIRC_OCT5_Y(aa_p) - i, mask, style->body.border.color, aa_opa); + px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p) - i, lt_origo.y + LV_CIRC_OCT6_Y(aa_p) - 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + px_fp(rt_origo.x + LV_CIRC_OCT7_X(aa_p) + i, rt_origo.y + LV_CIRC_OCT7_Y(aa_p) - 1, mask, style->body.border.color, aa_opa); + px_fp(rt_origo.x + LV_CIRC_OCT8_X(aa_p) + 1, rt_origo.y + LV_CIRC_OCT8_Y(aa_p) - i, mask, style->body.border.color, aa_opa); + } + } + + out_x_last = cir_out.x; + out_y_seg_start = out_y_seg_end; + } + + /*New step in y on the inner circle*/ + if(in_x_last != cir_in.x) { + in_y_seg_end = cir_out.y; + lv_coord_t seg_size = in_y_seg_end - in_y_seg_start; + lv_point_t aa_p; + + aa_p.x = in_x_last; + aa_p.y = in_y_seg_start; + + lv_coord_t i; + for(i = 0; i < seg_size; i++) { + lv_opa_t aa_opa; + + if(seg_size > CIRCLE_AA_NON_LINEAR_OPA_THRESHOLD) { /*Use non-linear opa mapping on the first segment*/ + aa_opa = opa - antialias_get_opa_circ(seg_size, i, opa); + } else { + aa_opa = lv_draw_aa_get_opa(seg_size, i, opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) - 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + px_fp(lb_origo.x + LV_CIRC_OCT3_X(aa_p) - i, lb_origo.y + LV_CIRC_OCT3_Y(aa_p) - 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + px_fp(lt_origo.x + LV_CIRC_OCT5_X(aa_p) + 1, lt_origo.y + LV_CIRC_OCT5_Y(aa_p) - i, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + px_fp(rt_origo.x + LV_CIRC_OCT7_X(aa_p) + i, rt_origo.y + LV_CIRC_OCT7_Y(aa_p) + 1, mask, style->body.border.color, aa_opa); + } + + /*Be sure the pixels on the middle are not drawn twice*/ + if(LV_CIRC_OCT1_X(aa_p) - 1 != LV_CIRC_OCT2_X(aa_p) + i) { + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) - 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + px_fp(lb_origo.x + LV_CIRC_OCT4_X(aa_p) + 1, lb_origo.y + LV_CIRC_OCT4_Y(aa_p) + i, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p) - i, lt_origo.y + LV_CIRC_OCT6_Y(aa_p) + 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + px_fp(rt_origo.x + LV_CIRC_OCT8_X(aa_p) - 1, rt_origo.y + LV_CIRC_OCT8_Y(aa_p) - i, mask, style->body.border.color, aa_opa); + } + } + + } + + in_x_last = cir_in.x; + in_y_seg_start = in_y_seg_end; + + } + +#endif + + + /*Draw the octets to the right bottom corner*/ + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + circ_area.x1 = rb_origo.x + LV_CIRC_OCT1_X(cir_out) - act_w2; + circ_area.x2 = rb_origo.x + LV_CIRC_OCT1_X(cir_out); + circ_area.y1 = rb_origo.y + LV_CIRC_OCT1_Y(cir_out); + circ_area.y2 = rb_origo.y + LV_CIRC_OCT1_Y(cir_out); + fill_fp(&circ_area, mask, color, opa); + + circ_area.x1 = rb_origo.x + LV_CIRC_OCT2_X(cir_out); + circ_area.x2 = rb_origo.x + LV_CIRC_OCT2_X(cir_out); + circ_area.y1 = rb_origo.y + LV_CIRC_OCT2_Y(cir_out) - act_w1; + circ_area.y2 = rb_origo.y + LV_CIRC_OCT2_Y(cir_out); + fill_fp(&circ_area, mask, color, opa); + } + + /*Draw the octets to the left bottom corner*/ + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + circ_area.x1 = lb_origo.x + LV_CIRC_OCT3_X(cir_out); + circ_area.x2 = lb_origo.x + LV_CIRC_OCT3_X(cir_out); + circ_area.y1 = lb_origo.y + LV_CIRC_OCT3_Y(cir_out) - act_w2; + circ_area.y2 = lb_origo.y + LV_CIRC_OCT3_Y(cir_out); + fill_fp(&circ_area, mask, color, opa); + + circ_area.x1 = lb_origo.x + LV_CIRC_OCT4_X(cir_out); + circ_area.x2 = lb_origo.x + LV_CIRC_OCT4_X(cir_out) + act_w1; + circ_area.y1 = lb_origo.y + LV_CIRC_OCT4_Y(cir_out); + circ_area.y2 = lb_origo.y + LV_CIRC_OCT4_Y(cir_out); + fill_fp(&circ_area, mask, color, opa); + } + + /*Draw the octets to the left top corner*/ + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + if(lb_origo.y + LV_CIRC_OCT4_Y(cir_out) > lt_origo.y + LV_CIRC_OCT5_Y(cir_out)) { + /*Don't draw if the lines are common in the middle*/ + circ_area.x1 = lt_origo.x + LV_CIRC_OCT5_X(cir_out); + circ_area.x2 = lt_origo.x + LV_CIRC_OCT5_X(cir_out) + act_w2; + circ_area.y1 = lt_origo.y + LV_CIRC_OCT5_Y(cir_out); + circ_area.y2 = lt_origo.y + LV_CIRC_OCT5_Y(cir_out); + fill_fp(&circ_area, mask, color, opa); + } + + circ_area.x1 = lt_origo.x + LV_CIRC_OCT6_X(cir_out); + circ_area.x2 = lt_origo.x + LV_CIRC_OCT6_X(cir_out); + circ_area.y1 = lt_origo.y + LV_CIRC_OCT6_Y(cir_out); + circ_area.y2 = lt_origo.y + LV_CIRC_OCT6_Y(cir_out) + act_w1; + fill_fp(&circ_area, mask, color, opa); + } + + /*Draw the octets to the right top corner*/ + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + circ_area.x1 = rt_origo.x + LV_CIRC_OCT7_X(cir_out); + circ_area.x2 = rt_origo.x + LV_CIRC_OCT7_X(cir_out); + circ_area.y1 = rt_origo.y + LV_CIRC_OCT7_Y(cir_out); + circ_area.y2 = rt_origo.y + LV_CIRC_OCT7_Y(cir_out) + act_w2; + fill_fp(&circ_area, mask, color, opa); + + /*Don't draw if the lines are common in the middle*/ + if(rb_origo.y + LV_CIRC_OCT1_Y(cir_out) > rt_origo.y + LV_CIRC_OCT8_Y(cir_out)) { + circ_area.x1 = rt_origo.x + LV_CIRC_OCT8_X(cir_out) - act_w1; + circ_area.x2 = rt_origo.x + LV_CIRC_OCT8_X(cir_out); + circ_area.y1 = rt_origo.y + LV_CIRC_OCT8_Y(cir_out); + circ_area.y2 = rt_origo.y + LV_CIRC_OCT8_Y(cir_out); + fill_fp(&circ_area, mask, color, opa); + } + } + lv_circ_next(&cir_out, &tmp_out); + + /*The internal circle will be ready faster + * so check it! */ + if(cir_in.y < cir_in.x) { + lv_circ_next(&cir_in, &tmp_in); + } + } + + +#if LV_ANTIALIAS != 0 + + /*Last parts of the outer anti-alias*/ + out_y_seg_end = cir_out.y; + lv_coord_t seg_size = out_y_seg_end - out_y_seg_start; + lv_point_t aa_p; + + aa_p.x = out_x_last; + aa_p.y = out_y_seg_start; + + lv_coord_t i; + for(i = 0; i < seg_size; i++) { + lv_opa_t aa_opa = opa - lv_draw_aa_get_opa(seg_size, i, opa); + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) + 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, style->body.border.color, aa_opa); + px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) + 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + px_fp(lb_origo.x + LV_CIRC_OCT3_X(aa_p) - i, lb_origo.y + LV_CIRC_OCT3_Y(aa_p) + 1, mask, style->body.border.color, aa_opa); + px_fp(lb_origo.x + LV_CIRC_OCT4_X(aa_p) - 1, lb_origo.y + LV_CIRC_OCT4_Y(aa_p) + i, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + px_fp(lt_origo.x + LV_CIRC_OCT5_X(aa_p) - 1, lt_origo.y + LV_CIRC_OCT5_Y(aa_p) - i, mask, style->body.border.color, aa_opa); + px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p) - i, lt_origo.y + LV_CIRC_OCT6_Y(aa_p) - 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + px_fp(rt_origo.x + LV_CIRC_OCT7_X(aa_p) + i, rt_origo.y + LV_CIRC_OCT7_Y(aa_p) - 1, mask, style->body.border.color, aa_opa); + px_fp(rt_origo.x + LV_CIRC_OCT8_X(aa_p) + 1, rt_origo.y + LV_CIRC_OCT8_Y(aa_p) - i, mask, style->body.border.color, aa_opa); + } + } + + /*In some cases the last pixel in the outer middle is not drawn*/ + if(LV_MATH_ABS(aa_p.x - aa_p.y) == seg_size) { + aa_p.x = out_x_last; + aa_p.y = out_x_last; + + lv_opa_t aa_opa = opa >> 1; + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p), rb_origo.y + LV_CIRC_OCT2_Y(aa_p), mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + px_fp(lb_origo.x + LV_CIRC_OCT4_X(aa_p), lb_origo.y + LV_CIRC_OCT4_Y(aa_p), mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p), lt_origo.y + LV_CIRC_OCT6_Y(aa_p), mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + px_fp(rt_origo.x + LV_CIRC_OCT8_X(aa_p), rt_origo.y + LV_CIRC_OCT8_Y(aa_p), mask, style->body.border.color, aa_opa); + } + } + + /*Last parts of the inner anti-alias*/ + in_y_seg_end = cir_in.y; + aa_p.x = in_x_last; + aa_p.y = in_y_seg_start; + seg_size = in_y_seg_end - in_y_seg_start; + + for(i = 0; i < seg_size; i++) { + lv_opa_t aa_opa = lv_draw_aa_get_opa(seg_size, i, opa); + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + px_fp(rb_origo.x + LV_CIRC_OCT1_X(aa_p) - 1, rb_origo.y + LV_CIRC_OCT1_Y(aa_p) + i, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + px_fp(lb_origo.x + LV_CIRC_OCT3_X(aa_p) - i, lb_origo.y + LV_CIRC_OCT3_Y(aa_p) - 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + px_fp(lt_origo.x + LV_CIRC_OCT5_X(aa_p) + 1, lt_origo.y + LV_CIRC_OCT5_Y(aa_p) - i, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + px_fp(rt_origo.x + LV_CIRC_OCT7_X(aa_p) + i, rt_origo.y + LV_CIRC_OCT7_Y(aa_p) + 1, mask, style->body.border.color, aa_opa); + } + + if(LV_CIRC_OCT1_X(aa_p) - 1 != LV_CIRC_OCT2_X(aa_p) + i) { + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_RIGHT)) { + px_fp(rb_origo.x + LV_CIRC_OCT2_X(aa_p) + i, rb_origo.y + LV_CIRC_OCT2_Y(aa_p) - 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_BOTTOM) && (part & LV_BORDER_LEFT)) { + px_fp(lb_origo.x + LV_CIRC_OCT4_X(aa_p) + 1, lb_origo.y + LV_CIRC_OCT4_Y(aa_p) + i, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_LEFT)) { + px_fp(lt_origo.x + LV_CIRC_OCT6_X(aa_p) - i, lt_origo.y + LV_CIRC_OCT6_Y(aa_p) + 1, mask, style->body.border.color, aa_opa); + } + + if((part & LV_BORDER_TOP) && (part & LV_BORDER_RIGHT)) { + px_fp(rt_origo.x + LV_CIRC_OCT8_X(aa_p) - 1, rt_origo.y + LV_CIRC_OCT8_Y(aa_p) - i, mask, style->body.border.color, aa_opa); + } + } + } + +#endif + +} + +#if USE_LV_SHADOW && LV_VDB_SIZE + +/** + * Draw a shadow + * @param rect pointer to rectangle object + * @param mask pointer to a mask area (from the design functions) + * @param opa_scale scale down all opacities by the factor + */ +static void lv_draw_shadow(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + /* If mask is in the middle of cords do not draw shadow*/ + lv_coord_t radius = style->body.radius; + lv_coord_t width = lv_area_get_width(coords); + lv_coord_t height = lv_area_get_height(coords); + radius = lv_draw_cont_radius_corr(radius, width, height); + lv_area_t area_tmp; + + /*Check horizontally without radius*/ + lv_area_copy(&area_tmp, coords); + area_tmp.x1 += radius; + area_tmp.x2 -= radius; + if(lv_area_is_in(mask, &area_tmp) != false) return; + + /*Check vertically without radius*/ + lv_area_copy(&area_tmp, coords); + area_tmp.y1 += radius; + area_tmp.y2 -= radius; + if(lv_area_is_in(mask, &area_tmp) != false) return; + + if(style->body.shadow.type == LV_SHADOW_FULL) { + lv_draw_shadow_full(coords, mask, style, opa_scale); + } else if(style->body.shadow.type == LV_SHADOW_BOTTOM) { + lv_draw_shadow_bottom(coords, mask, style, opa_scale); + } +} + +static void lv_draw_shadow_full(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + + /* KNOWN ISSUE + * The algorithm calculates the shadow only above the middle point of the radius (speaking about the left top corner). + * It causes an error because it doesn't consider how long the straight edge is which effects the value of bottom of the corner shadow. + * In addition the straight shadow is drawn from the middles point of the radius however + * the ends of the straight parts still should be effected by the corner shadow. + * It also causes an issue in opacity. A smaller radius means smaller average shadow opacity. + * The solution should be to start `line` from `- swidth` and handle if the straight part is short (or zero) and the value is taken from + * the other corner. `col` also should start from `- swidth` + */ + + + lv_coord_t radius = style->body.radius; + lv_coord_t swidth = style->body.shadow.width; + + lv_coord_t width = lv_area_get_width(coords); + lv_coord_t height = lv_area_get_height(coords); + + radius = lv_draw_cont_radius_corr(radius, width, height); + + radius += LV_ANTIALIAS; + +#if LV_COMPILER_VLA_SUPPORTED + lv_coord_t curve_x[radius + swidth + 1]; /*Stores the 'x' coordinates of a quarter circle.*/ +#else +# if LV_HOR_RES > LV_VER_RES + lv_coord_t curve_x[LV_HOR_RES]; +# else + lv_coord_t curve_x[LV_VER_RES]; +# endif +#endif + memset(curve_x, 0, sizeof(curve_x)); + lv_point_t circ; + lv_coord_t circ_tmp; + lv_circ_init(&circ, &circ_tmp, radius); + while(lv_circ_cont(&circ)) { + curve_x[LV_CIRC_OCT1_Y(circ)] = LV_CIRC_OCT1_X(circ); + curve_x[LV_CIRC_OCT2_Y(circ)] = LV_CIRC_OCT2_X(circ); + lv_circ_next(&circ, &circ_tmp); + } + int16_t line; + + int16_t filter_width = 2 * swidth + 1; +#if LV_COMPILER_VLA_SUPPORTED + uint32_t line_1d_blur[filter_width]; +#else +# if LV_HOR_RES > LV_VER_RES + uint32_t line_1d_blur[LV_HOR_RES]; +# else + uint32_t line_1d_blur[LV_VER_RES]; +# endif +#endif + /*1D Blur horizontally*/ + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.opa : (uint16_t)((uint16_t) style->body.opa * opa_scale) >> 8; + for(line = 0; line < filter_width; line++) { + line_1d_blur[line] = (uint32_t)((uint32_t)(filter_width - line) * (opa * 2) << SHADOW_OPA_EXTRA_PRECISION) / (filter_width * filter_width); + } + + uint16_t col; +#if LV_COMPILER_VLA_SUPPORTED + lv_opa_t line_2d_blur[radius + swidth + 1]; +#else +# if LV_HOR_RES > LV_VER_RES + lv_opa_t line_2d_blur[LV_HOR_RES]; +# else + lv_opa_t line_2d_blur[LV_VER_RES]; +# endif +#endif + + lv_point_t point_rt; + lv_point_t point_rb; + lv_point_t point_lt; + lv_point_t point_lb; + lv_point_t ofs_rb; + lv_point_t ofs_rt; + lv_point_t ofs_lb; + lv_point_t ofs_lt; + ofs_rb.x = coords->x2 - radius - LV_ANTIALIAS; + ofs_rb.y = coords->y2 - radius - LV_ANTIALIAS; + + ofs_rt.x = coords->x2 - radius - LV_ANTIALIAS; + ofs_rt.y = coords->y1 + radius + LV_ANTIALIAS; + + ofs_lb.x = coords->x1 + radius + LV_ANTIALIAS; + ofs_lb.y = coords->y2 - radius - LV_ANTIALIAS; + + ofs_lt.x = coords->x1 + radius + LV_ANTIALIAS; + ofs_lt.y = coords->y1 + radius + LV_ANTIALIAS; + bool line_ready; + for(line = 0; line <= radius + swidth; line++) { /*Check all rows and make the 1D blur to 2D*/ + line_ready = false; + for(col = 0; col <= radius + swidth; col++) { /*Check all pixels in a 1D blur line (from the origo to last shadow pixel (radius + swidth))*/ + + /*Sum the opacities from the lines above and below this 'row'*/ + int16_t line_rel; + uint32_t px_opa_sum = 0; + for(line_rel = -swidth; line_rel <= swidth; line_rel ++) { + /*Get the relative x position of the 'line_rel' to 'line'*/ + int16_t col_rel; + if(line + line_rel < 0) { /*Below the radius, here is the blur of the edge */ + col_rel = radius - curve_x[line] - col; + } else if(line + line_rel > radius) { /*Above the radius, here won't be more 1D blur*/ + break; + } else { /*Blur from the curve*/ + col_rel = curve_x[line + line_rel] - curve_x[line] - col; + } + + /*Add the value of the 1D blur on 'col_rel' position*/ + if(col_rel < -swidth) { /*Outside of the blurred area. */ + if(line_rel == -swidth) line_ready = true; /*If no data even on the very first line then it wont't be anything else in this line*/ + break; /*Break anyway because only smaller 'col_rel' values will come */ + } else if(col_rel > swidth) px_opa_sum += line_1d_blur[0]; /*Inside the not blurred area*/ + else px_opa_sum += line_1d_blur[swidth - col_rel]; /*On the 1D blur (+ swidth to align to the center)*/ + } + + line_2d_blur[col] = px_opa_sum >> SHADOW_OPA_EXTRA_PRECISION; + if(line_ready) { + col++; /*To make this line to the last one ( drawing will go to '< col')*/ + break; + } + + } + + /*Flush the line*/ + point_rt.x = curve_x[line] + ofs_rt.x + 1; + point_rt.y = ofs_rt.y - line; + + point_rb.x = curve_x[line] + ofs_rb.x + 1; + point_rb.y = ofs_rb.y + line; + + point_lt.x = ofs_lt.x - curve_x[line] - 1; + point_lt.y = ofs_lt.y - line; + + point_lb.x = ofs_lb.x - curve_x[line] - 1; + point_lb.y = ofs_lb.y + line; + + uint16_t d; + for(d = 1; d < col; d++) { + + if(point_lt.x < ofs_lt.x && point_lt.y < ofs_lt.y) { + px_fp(point_lt.x, point_lt.y, mask, style->body.shadow.color, line_2d_blur[d]); + } + + if(point_lb.x < ofs_lb.x && point_lb.y > ofs_lb.y) { + px_fp(point_lb.x, point_lb.y, mask, style->body.shadow.color, line_2d_blur[d]); + } + + if(point_rt.x > ofs_rt.x && point_rt.y < ofs_rt.y) { + px_fp(point_rt.x, point_rt.y, mask, style->body.shadow.color, line_2d_blur[d]); + } + + if(point_rb.x > ofs_rb.x && point_rb.y > ofs_rb.y) { + px_fp(point_rb.x, point_rb.y, mask, style->body.shadow.color, line_2d_blur[d]); + } + + point_rb.x++; + point_lb.x--; + + point_rt.x++; + point_lt.x--; + } + + /* Put the first line to the edges too. + * It is not correct because blur should be done below the corner too + * but is is simple, fast and gives a good enough result*/ + if(line == 0) lv_draw_shadow_full_straight(coords, mask, style, line_2d_blur); + } +} + + +static void lv_draw_shadow_bottom(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) +{ + lv_coord_t radius = style->body.radius; + lv_coord_t swidth = style->body.shadow.width; + lv_coord_t width = lv_area_get_width(coords); + lv_coord_t height = lv_area_get_height(coords); + + radius = lv_draw_cont_radius_corr(radius, width, height); + radius += LV_ANTIALIAS * SHADOW_BOTTOM_AA_EXTRA_RADIUS; + swidth += LV_ANTIALIAS; +#if LV_COMPILER_VLA_SUPPORTED + lv_coord_t curve_x[radius + 1]; /*Stores the 'x' coordinates of a quarter circle.*/ +#else +# if LV_HOR_RES > LV_VER_RES + lv_coord_t curve_x[LV_HOR_RES]; +# else + lv_coord_t curve_x[LV_VER_RES]; +# endif +#endif + lv_point_t circ; + lv_coord_t circ_tmp; + lv_circ_init(&circ, &circ_tmp, radius); + while(lv_circ_cont(&circ)) { + curve_x[LV_CIRC_OCT1_Y(circ)] = LV_CIRC_OCT1_X(circ); + curve_x[LV_CIRC_OCT2_Y(circ)] = LV_CIRC_OCT2_X(circ); + lv_circ_next(&circ, &circ_tmp); + } + + int16_t col; +#if LV_COMPILER_VLA_SUPPORTED + lv_opa_t line_1d_blur[swidth]; +#else +# if LV_HOR_RES > LV_VER_RES + lv_opa_t line_1d_blur[LV_HOR_RES]; +# else + lv_opa_t line_1d_blur[LV_VER_RES]; +# endif +#endif + + lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.opa : (uint16_t)((uint16_t) style->body.opa * opa_scale) >> 8; + for(col = 0; col < swidth; col++) { + line_1d_blur[col] = (uint32_t)((uint32_t)(swidth - col) * opa / 2) / (swidth); + } + + lv_point_t point_l; + lv_point_t point_r; + lv_area_t area_mid; + lv_point_t ofs_l; + lv_point_t ofs_r; + + ofs_l.x = coords->x1 + radius; + ofs_l.y = coords->y2 - radius + 1 - LV_ANTIALIAS; + + ofs_r.x = coords->x2 - radius; + ofs_r.y = coords->y2 - radius + 1 - LV_ANTIALIAS; + + for(col = 0; col <= radius; col++) { + point_l.x = ofs_l.x - col ; + point_l.y = ofs_l.y + curve_x[col]; + + point_r.x = ofs_r.x + col; + point_r.y = ofs_r.y + curve_x[col]; + + lv_opa_t px_opa; + int16_t diff = col == 0 ? 0 : curve_x[col - 1] - curve_x[col]; + uint16_t d; + for(d = 0; d < swidth; d++) { + /*When stepping a pixel in y calculate the average with the pixel from the prev. column to make a blur */ + if(diff == 0) { + px_opa = line_1d_blur[d]; + } else { + px_opa = (uint16_t)((uint16_t)line_1d_blur[d] + line_1d_blur[d - diff]) >> 1; + } + px_fp(point_l.x, point_l.y, mask, style->body.shadow.color, px_opa); + point_l.y ++; + + /*Don't overdraw the pixel on the middle*/ + if(point_r.x > ofs_l.x) { + px_fp(point_r.x, point_r.y, mask, style->body.shadow.color, px_opa); + } + point_r.y ++; + } + + } + + area_mid.x1 = ofs_l.x + 1; + area_mid.y1 = ofs_l.y + radius; + area_mid.x2 = ofs_r.x - 1; + area_mid.y2 = area_mid.y1; + + uint16_t d; + for(d = 0; d < swidth; d++) { + fill_fp(&area_mid, mask, style->body.shadow.color, line_1d_blur[d]); + area_mid.y1 ++; + area_mid.y2 ++; + } +} + +static void lv_draw_shadow_full_straight(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, const lv_opa_t * map) +{ + lv_coord_t radius = style->body.radius; + lv_coord_t swidth = style->body.shadow.width;// + LV_ANTIALIAS; + lv_coord_t width = lv_area_get_width(coords); + lv_coord_t height = lv_area_get_height(coords); + + radius = lv_draw_cont_radius_corr(radius, width, height); + radius += LV_ANTIALIAS; + + lv_area_t right_area; + right_area.x1 = coords->x2 + 1 - LV_ANTIALIAS; + right_area.y1 = coords->y1 + radius + LV_ANTIALIAS; + right_area.x2 = right_area.x1; + right_area.y2 = coords->y2 - radius - LV_ANTIALIAS; + + lv_area_t left_area; + left_area.x1 = coords->x1 - 1 + LV_ANTIALIAS; + left_area.y1 = coords->y1 + radius + LV_ANTIALIAS; + left_area.x2 = left_area.x1; + left_area.y2 = coords->y2 - radius - LV_ANTIALIAS; + + lv_area_t top_area; + top_area.x1 = coords->x1 + radius + LV_ANTIALIAS; + top_area.y1 = coords->y1 - 1 + LV_ANTIALIAS; + top_area.x2 = coords->x2 - radius - LV_ANTIALIAS; + top_area.y2 = top_area.y1; + + lv_area_t bottom_area; + bottom_area.x1 = coords->x1 + radius + LV_ANTIALIAS; + bottom_area.y1 = coords->y2 + 1 - LV_ANTIALIAS; + bottom_area.x2 = coords->x2 - radius - LV_ANTIALIAS; + bottom_area.y2 = bottom_area.y1; + + lv_opa_t opa_act; + int16_t d; + for(d = 1 /*+ LV_ANTIALIAS*/; d <= swidth/* - LV_ANTIALIAS*/; d++) { + opa_act = map[d]; + + fill_fp(&right_area, mask, style->body.shadow.color, opa_act); + right_area.x1++; + right_area.x2++; + + fill_fp(&left_area, mask, style->body.shadow.color, opa_act); + left_area.x1--; + left_area.x2--; + + fill_fp(&top_area, mask, style->body.shadow.color, opa_act); + top_area.y1--; + top_area.y2--; + + fill_fp(&bottom_area, mask, style->body.shadow.color, opa_act); + bottom_area.y1++; + bottom_area.y2++; + } +} + +#endif + + +static uint16_t lv_draw_cont_radius_corr(uint16_t r, lv_coord_t w, lv_coord_t h) +{ + if(r >= (w >> 1)) { + r = (w >> 1); + if(r != 0) r--; + } + if(r >= (h >> 1)) { + r = (h >> 1); + if(r != 0) r--; + } + + if(r > 0) r -= LV_ANTIALIAS; + + return r; +} + +#if LV_ANTIALIAS + +/** + * Approximate the opacity for anti-aliasing. + * Used the first segment of a circle which is the longest and have the most non-linearity (cos) + * @param seg length of the line segment + * @param px_id index of pixel on the line segment + * @param line_opa opacity of the lien (it will be the max opacity) + * @return the desired opacity of the pixel + */ +static lv_opa_t antialias_get_opa_circ(lv_coord_t seg, lv_coord_t px_id, lv_opa_t opa) +{ + static const lv_opa_t opa_map[8] = {250, 242, 221, 196, 163, 122, 74, 18}; + + if(seg == 0) return LV_OPA_TRANSP; + else if(seg == 1) return LV_OPA_80; + else { + + uint8_t id = (uint32_t)((uint32_t)px_id * (sizeof(opa_map) - 1)) / (seg - 1); + return (uint32_t)((uint32_t) opa_map[id] * opa) >> 8; + + } + +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.h new file mode 100644 index 0000000..933590c --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_rect.h @@ -0,0 +1,48 @@ +/** + * @file lv_draw_rect.h + * + */ + +#ifndef LV_DRAW_RECT_H +#define LV_DRAW_RECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Draw a rectangle + * @param coords the coordinates of the rectangle + * @param mask the rectangle will be drawn only in this mask + * @param style pointer to a style + * @param opa_scale scale down all opacities by the factor + */ +void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DRAW_RECT_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_triangle.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_triangle.c new file mode 100644 index 0000000..84c9d3f --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_triangle.c @@ -0,0 +1,168 @@ +/** + * @file lv_draw_triangle.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_triangle.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static void point_swap(lv_point_t * p1, lv_point_t * p2); + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ +#if USE_LV_TRIANGLE != 0 +/** + * + * @param points pointer to an array with 3 points + * @param mask the triangle will be drawn only in this mask + * @param color color of the triangle + */ +void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color) +{ + lv_point_t tri[3]; + + memcpy(tri, points, sizeof(tri)); + + /*Sort the vertices according to their y coordinate (0: y max, 1: y mid, 2:y min)*/ + if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]); + if(tri[2].y < tri[1].y) point_swap(&tri[2], &tri[1]); + if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]); + + /*Return is the triangle is degenerated*/ + if(tri[0].x == tri[1].x && tri[0].y == tri[1].y) return; + if(tri[1].x == tri[2].x && tri[1].y == tri[2].y) return; + if(tri[0].x == tri[2].x && tri[0].y == tri[2].y) return; + + if(tri[0].x == tri[1].x && tri[1].x == tri[2].x) return; + if(tri[0].y == tri[1].y && tri[1].y == tri[2].y) return; + + /*Draw the triangle*/ + lv_point_t edge1; + lv_coord_t dx1 = LV_MATH_ABS(tri[0].x - tri[1].x); + lv_coord_t sx1 = tri[0].x < tri[1].x ? 1 : -1; + lv_coord_t dy1 = LV_MATH_ABS(tri[0].y - tri[1].y); + lv_coord_t sy1 = tri[0].y < tri[1].y ? 1 : -1; + lv_coord_t err1 = (dx1 > dy1 ? dx1 : -dy1) / 2; + lv_coord_t err_tmp1; + + lv_point_t edge2; + lv_coord_t dx2 = LV_MATH_ABS(tri[0].x - tri[2].x); + lv_coord_t sx2 = tri[0].x < tri[2].x ? 1 : -1; + lv_coord_t dy2 = LV_MATH_ABS(tri[0].y - tri[2].y); + lv_coord_t sy2 = tri[0].y < tri[2].y ? 1 : -1; + lv_coord_t err2 = (dx1 > dy2 ? dx2 : -dy2) / 2; + lv_coord_t err_tmp2; + + lv_coord_t y1_tmp; + lv_coord_t y2_tmp; + + edge1.x = tri[0].x; + edge1.y = tri[0].y; + edge2.x = tri[0].x; + edge2.y = tri[0].y; + lv_area_t act_area; + lv_area_t draw_area; + + while(1) { + act_area.x1 = edge1.x; + act_area.x2 = edge2.x ; + act_area.y1 = edge1.y; + act_area.y2 = edge2.y ; + + + draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2); + draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2); + draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2); + draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2); + draw_area.x2--; /*Do not draw most right pixel because it will be drawn by the adjacent triangle*/ + fill_fp(&draw_area, mask, color, LV_OPA_50); + + /*Calc. the next point of edge1*/ + y1_tmp = edge1.y; + do { + if(edge1.x == tri[1].x && edge1.y == tri[1].y) { + + dx1 = LV_MATH_ABS(tri[1].x - tri[2].x); + sx1 = tri[1].x < tri[2].x ? 1 : -1; + dy1 = LV_MATH_ABS(tri[1].y - tri[2].y); + sy1 = tri[1].y < tri[2].y ? 1 : -1; + err1 = (dx1 > dy1 ? dx1 : -dy1) / 2; + } else if(edge1.x == tri[2].x && edge1.y == tri[2].y) return; + err_tmp1 = err1; + if(err_tmp1 > -dx1) { + err1 -= dy1; + edge1.x += sx1; + } + if(err_tmp1 < dy1) { + err1 += dx1; + edge1.y += sy1; + } + } while(edge1.y == y1_tmp); + + /*Calc. the next point of edge2*/ + y2_tmp = edge2.y; + do { + if(edge2.x == tri[2].x && edge2.y == tri[2].y) return; + err_tmp2 = err2; + if(err_tmp2 > -dx2) { + err2 -= dy2; + edge2.x += sx2; + } + if(err_tmp2 < dy2) { + err2 += dx2; + edge2.y += sy2; + } + } while(edge2.y == y2_tmp); + } +} +#endif + +/********************** + * STATIC FUNCTIONS + **********************/ + + +#if USE_LV_TRIANGLE != 0 +/** + * Swap two points + * p1 pointer to the first point + * p2 pointer to the second point + */ +static void point_swap(lv_point_t * p1, lv_point_t * p2) +{ + lv_point_t tmp; + tmp.x = p1->x; + tmp.y = p1->y; + + p1->x = p2->x; + p1->y = p2->y; + + p2->x = tmp.x; + p2->y = tmp.y; + +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_triangle.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_triangle.h new file mode 100644 index 0000000..c3c6208 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_triangle.h @@ -0,0 +1,51 @@ +/** + * @file lv_draw_triangle.h + * + */ + +#ifndef LV_DRAW_TRIANGLE_H +#define LV_DRAW_TRIANGLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +/*Experimental use for 3D modeling*/ +#define USE_LV_TRIANGLE 1 + +#if USE_LV_TRIANGLE != 0 +/** + * + * @param points pointer to an array with 3 points + * @param mask the triangle will be drawn only in this mask + * @param color color of the triangle + */ +void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color); +#endif + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DRAW_TRIANGLE_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_vbasic.c b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_vbasic.c new file mode 100644 index 0000000..ebe5f57 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_vbasic.c @@ -0,0 +1,691 @@ +/** + * @file lv_vdraw.c + * + */ + +#include "lv_draw_vbasic.h" + +#include +#include + +#include "../lv_hal/lv_hal_disp.h" +#include "../lv_misc/lv_area.h" +#include "../lv_misc/lv_font.h" +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_log.h" + +#if LV_VDB_SIZE != 0 + +#include +#include "../lv_core/lv_vdb.h" +#include "lv_draw.h" + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ +#define VFILL_HW_ACC_SIZE_LIMIT 50 /*Always fill < 50 px with 'sw_color_fill' because of the hw. init overhead*/ + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void sw_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa); +static void sw_color_fill(lv_area_t * mem_area, lv_color_t * mem, const lv_area_t * fill_area, lv_color_t color, lv_opa_t opa); + +#if LV_COLOR_SCREEN_TRANSP +static inline lv_color_t color_mix_2_alpha(lv_color_t bg_color, lv_opa_t bg_opa, lv_color_t fg_color, lv_opa_t fg_opa); +#endif + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Put a pixel in the Virtual Display Buffer + * @param x pixel x coordinate + * @param y pixel y coordinate + * @param mask_p fill only on this mask (truncated to VDB area) + * @param color pixel color + * @param opa opacity of the area (0..255) + */ +void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa) +{ + if(opa < LV_OPA_MIN) return; + if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; + + lv_vdb_t * vdb_p = lv_vdb_get(); + if(!vdb_p) { + LV_LOG_WARN("Invalid VDB pointer"); + return; + } + + /*Pixel out of the mask*/ + if(x < mask_p->x1 || x > mask_p->x2 || + y < mask_p->y1 || y > mask_p->y2) { + return; + } + + uint32_t vdb_width = lv_area_get_width(&vdb_p->area); + + /*Make the coordinates relative to VDB*/ + x -= vdb_p->area.x1; + y -= vdb_p->area.y1; + + lv_disp_t * disp = lv_disp_get_active(); + if(disp->driver.vdb_wr) { + disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, x, y, color, opa); + } else { + lv_color_t * vdb_px_p = vdb_p->buf + y * vdb_width + x; +#if LV_COLOR_SCREEN_TRANSP == 0 + if(opa == LV_OPA_COVER) { + *vdb_px_p = color; + } else { + *vdb_px_p = lv_color_mix(color, *vdb_px_p, opa); + } +#else + *vdb_px_p = color_mix_2_alpha(*vdb_px_p, (*vdb_px_p).alpha, color, opa); +#endif + } +} + + +/** + * Fill an area in the Virtual Display Buffer + * @param cords_p coordinates of the area to fill + * @param mask_p fill only o this mask (truncated to VDB area) + * @param color fill color + * @param opa opacity of the area (0..255) + */ +void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p, + lv_color_t color, lv_opa_t opa) +{ + if(opa < LV_OPA_MIN) return; + if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; + + lv_area_t res_a; + bool union_ok; + lv_vdb_t * vdb_p = lv_vdb_get(); + if(!vdb_p) { + LV_LOG_WARN("Invalid VDB pointer"); + return; + } + + /*Get the union of cord and mask*/ + /* The mask is already truncated to the vdb size + * in 'lv_refr_area_with_vdb' function */ + union_ok = lv_area_intersect(&res_a, cords_p, mask_p); + + /*If there are common part of the three area then draw to the vdb*/ + if(union_ok == false) return; + + lv_area_t vdb_rel_a; /*Stores relative coordinates on vdb*/ + vdb_rel_a.x1 = res_a.x1 - vdb_p->area.x1; + vdb_rel_a.y1 = res_a.y1 - vdb_p->area.y1; + vdb_rel_a.x2 = res_a.x2 - vdb_p->area.x1; + vdb_rel_a.y2 = res_a.y2 - vdb_p->area.y1; + + lv_color_t * vdb_buf_tmp = vdb_p->buf; + uint32_t vdb_width = lv_area_get_width(&vdb_p->area); + /*Move the vdb_tmp to the first row*/ + vdb_buf_tmp += vdb_width * vdb_rel_a.y1; + + +#if USE_LV_GPU + static LV_ATTRIBUTE_MEM_ALIGN lv_color_t color_array_tmp[LV_HOR_RES]; /*Used by 'lv_disp_mem_blend'*/ + static lv_coord_t last_width = -1; + + lv_coord_t w = lv_area_get_width(&vdb_rel_a); + /*Don't use hw. acc. for every small fill (because of the init overhead)*/ + if(w < VFILL_HW_ACC_SIZE_LIMIT) { + sw_color_fill(&vdb_p->area, vdb_p->buf, &vdb_rel_a, color, opa); + } + /*Not opaque fill*/ + else if(opa == LV_OPA_COVER) { + /*Use hw fill if present*/ + if(lv_disp_is_mem_fill_supported()) { + lv_coord_t row; + for(row = vdb_rel_a.y1; row <= vdb_rel_a.y2; row++) { + lv_disp_mem_fill(&vdb_buf_tmp[vdb_rel_a.x1], w, color); + vdb_buf_tmp += vdb_width; + } + } + /*Use hw blend if present and the area is not too small*/ + else if(lv_area_get_height(&vdb_rel_a) > VFILL_HW_ACC_SIZE_LIMIT && + lv_disp_is_mem_blend_supported()) { + /*Fill a one line sized buffer with a color and blend this later*/ + if(color_array_tmp[0].full != color.full || last_width != w) { + uint16_t i; + for(i = 0; i < w; i++) { + color_array_tmp[i].full = color.full; + } + last_width = w; + } + + /*Blend the filled line to every line VDB line-by-line*/ + lv_coord_t row; + for(row = vdb_rel_a.y1; row <= vdb_rel_a.y2; row++) { + lv_disp_mem_blend(&vdb_buf_tmp[vdb_rel_a.x1], color_array_tmp, w, opa); + vdb_buf_tmp += vdb_width; + } + + } + /*Else use sw fill if no better option*/ + else { + sw_color_fill(&vdb_p->area, vdb_p->buf, &vdb_rel_a, color, opa); + } + + } + /*Fill with opacity*/ + else { + /*Use hw blend if present*/ + if(lv_disp_is_mem_blend_supported()) { + if(color_array_tmp[0].full != color.full || last_width != w) { + uint16_t i; + for(i = 0; i < w; i++) { + color_array_tmp[i].full = color.full; + } + + last_width = w; + } + lv_coord_t row; + for(row = vdb_rel_a.y1; row <= vdb_rel_a.y2; row++) { + lv_disp_mem_blend(&vdb_buf_tmp[vdb_rel_a.x1], color_array_tmp, w, opa); + vdb_buf_tmp += vdb_width; + } + + } + /*Use sw fill with opa if no better option*/ + else { + sw_color_fill(&vdb_p->area, vdb_p->buf, &vdb_rel_a, color, opa); + } + + } +#else + sw_color_fill(&vdb_p->area, vdb_p->buf, &vdb_rel_a, color, opa); +#endif +} + +/** + * Draw a letter in the Virtual Display Buffer + * @param pos_p left-top coordinate of the latter + * @param mask_p the letter will be drawn only on this area (truncated to VDB area) + * @param font_p pointer to font + * @param letter a letter to draw + * @param color color of letter + * @param opa opacity of letter (0..255) + */ +void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p, + const lv_font_t * font_p, uint32_t letter, + lv_color_t color, lv_opa_t opa) +{ + const uint8_t bpp1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/ + const uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/ + const uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ + 68, 85, 102, 119, + 136, 153, 170, 187, + 204, 221, 238, 255 + }; + if(opa < LV_OPA_MIN) return; + if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; + + if(font_p == NULL) { + LV_LOG_WARN("Font: character's bitmap not found"); + return; + } + + lv_coord_t pos_x = pos_p->x; + lv_coord_t pos_y = pos_p->y; + uint8_t letter_w = lv_font_get_real_width(font_p, letter); + uint8_t letter_h = lv_font_get_height(font_p); + uint8_t bpp = lv_font_get_bpp(font_p, letter); /*Bit per pixel (1,2, 4 or 8)*/ + const uint8_t * bpp_opa_table; + uint8_t mask_init; + uint8_t mask; + + if(lv_font_is_monospace(font_p, letter)) { + pos_x += (lv_font_get_width(font_p, letter) - letter_w) / 2; + } + + + switch(bpp) { + case 1: + bpp_opa_table = bpp1_opa_table; + mask_init = 0x80; + break; + case 2: + bpp_opa_table = bpp2_opa_table; + mask_init = 0xC0; + break; + case 4: + bpp_opa_table = bpp4_opa_table; + mask_init = 0xF0; + break; + case 8: + bpp_opa_table = NULL; + mask_init = 0xFF; + break; /*No opa table, pixel value will be used directly*/ + default: + return; /*Invalid bpp. Can't render the letter*/ + } + + const uint8_t * map_p = lv_font_get_bitmap(font_p, letter); + + if(map_p == NULL) return; + + /*If the letter is completely out of mask don't draw it */ + if(pos_x + letter_w < mask_p->x1 || pos_x > mask_p->x2 || + pos_y + letter_h < mask_p->y1 || pos_y > mask_p->y2) return; + + lv_vdb_t * vdb_p = lv_vdb_get(); + if(!vdb_p) { + LV_LOG_WARN("Invalid VDB pointer"); + return; + } + + lv_coord_t vdb_width = lv_area_get_width(&vdb_p->area); + lv_color_t * vdb_buf_tmp = vdb_p->buf; + lv_coord_t col, row; + uint8_t col_bit; + uint8_t col_byte_cnt; + uint8_t width_byte_scr = letter_w >> 3; /*Width in bytes (on the screen finally) (e.g. w = 11 -> 2 bytes wide)*/ + if(letter_w & 0x7) width_byte_scr++; + uint8_t width_byte_bpp = (letter_w * bpp) >> 3; /*Letter width in byte. Real width in the font*/ + if((letter_w * bpp) & 0x7) width_byte_bpp++; + + /* Calculate the col/row start/end on the map*/ + lv_coord_t col_start = pos_x >= mask_p->x1 ? 0 : mask_p->x1 - pos_x; + lv_coord_t col_end = pos_x + letter_w <= mask_p->x2 ? letter_w : mask_p->x2 - pos_x + 1; + lv_coord_t row_start = pos_y >= mask_p->y1 ? 0 : mask_p->y1 - pos_y; + lv_coord_t row_end = pos_y + letter_h <= mask_p->y2 ? letter_h : mask_p->y2 - pos_y + 1; + + /*Set a pointer on VDB to the first pixel of the letter*/ + vdb_buf_tmp += ((pos_y - vdb_p->area.y1) * vdb_width) + + pos_x - vdb_p->area.x1; + + /*If the letter is partially out of mask the move there on VDB*/ + vdb_buf_tmp += (row_start * vdb_width) + col_start; + + /*Move on the map too*/ + map_p += (row_start * width_byte_bpp) + ((col_start * bpp) >> 3); + + lv_disp_t * disp = lv_disp_get_active(); + + uint8_t letter_px; + lv_opa_t px_opa; + for(row = row_start; row < row_end; row ++) { + col_byte_cnt = 0; + col_bit = (col_start * bpp) % 8; + mask = mask_init >> col_bit; + for(col = col_start; col < col_end; col ++) { + letter_px = (*map_p & mask) >> (8 - col_bit - bpp); + if(letter_px != 0) { + if(opa == LV_OPA_COVER) { + px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px]; + } else { + px_opa = bpp == 8 ? + (uint16_t)((uint16_t)letter_px * opa) >> 8 : + (uint16_t)((uint16_t)bpp_opa_table[letter_px] * opa) >> 8; + } + + if(disp->driver.vdb_wr) { + disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, + (col + pos_x) - vdb_p->area.x1, (row + pos_y) - vdb_p->area.y1, + color, px_opa); + } else { +#if LV_COLOR_SCREEN_TRANSP == 0 + *vdb_buf_tmp = lv_color_mix(color, *vdb_buf_tmp, px_opa); +#else + *vdb_buf_tmp = color_mix_2_alpha(*vdb_buf_tmp, (*vdb_buf_tmp).alpha, color, px_opa); +#endif + } + } + + vdb_buf_tmp++; + + if(col_bit < 8 - bpp) { + col_bit += bpp; + mask = mask >> bpp; + } else { + col_bit = 0; + col_byte_cnt ++; + mask = mask_init; + map_p ++; + } + } + + map_p += (width_byte_bpp) - col_byte_cnt; + vdb_buf_tmp += vdb_width - (col_end - col_start); /*Next row in VDB*/ + } +} + +/** + * Draw a color map to the display (image) + * @param cords_p coordinates the color map + * @param mask_p the map will drawn only on this area (truncated to VDB area) + * @param map_p pointer to a lv_color_t array + * @param opa opacity of the map + * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels + * @param alpha_byte true: extra alpha byte is inserted for every pixel + * @param recolor mix the pixels with this color + * @param recolor_opa the intense of recoloring + */ +void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p, + const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, + lv_color_t recolor, lv_opa_t recolor_opa) +{ + + if(opa < LV_OPA_MIN) return; + if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; + + lv_area_t masked_a; + bool union_ok; + lv_vdb_t * vdb_p = lv_vdb_get(); + if(!vdb_p) { + LV_LOG_WARN("Invalid VDB pointer"); + return; + } + + /*Get the union of map size and mask*/ + /* The mask is already truncated to the vdb size + * in 'lv_refr_area_with_vdb' function */ + union_ok = lv_area_intersect(&masked_a, cords_p, mask_p); + + /*If there are common part of the three area then draw to the vdb*/ + if(union_ok == false) return; + + /*The pixel size in byte is different if an alpha byte is added too*/ + uint8_t px_size_byte = alpha_byte ? LV_IMG_PX_SIZE_ALPHA_BYTE : sizeof(lv_color_t); + + /*If the map starts OUT of the masked area then calc. the first pixel*/ + lv_coord_t map_width = lv_area_get_width(cords_p); + if(cords_p->y1 < masked_a.y1) { + map_p += (uint32_t) map_width * ((masked_a.y1 - cords_p->y1)) * px_size_byte; + } + if(cords_p->x1 < masked_a.x1) { + map_p += (masked_a.x1 - cords_p->x1) * px_size_byte; + } + + /*Stores coordinates relative to the current VDB*/ + masked_a.x1 = masked_a.x1 - vdb_p->area.x1; + masked_a.y1 = masked_a.y1 - vdb_p->area.y1; + masked_a.x2 = masked_a.x2 - vdb_p->area.x1; + masked_a.y2 = masked_a.y2 - vdb_p->area.y1; + + lv_coord_t vdb_width = lv_area_get_width(&vdb_p->area); + lv_color_t * vdb_buf_tmp = vdb_p->buf; + vdb_buf_tmp += (uint32_t) vdb_width * masked_a.y1; /*Move to the first row*/ + vdb_buf_tmp += (uint32_t) masked_a.x1; /*Move to the first col*/ + + lv_coord_t row; + lv_coord_t map_useful_w = lv_area_get_width(&masked_a); + + lv_disp_t * disp = lv_disp_get_active(); + + /*The simplest case just copy the pixels into the VDB*/ + if(chroma_key == false && alpha_byte == false && opa == LV_OPA_COVER && recolor_opa == LV_OPA_TRANSP) { + + /*Use the custom VDB write function is exists*/ + if(disp->driver.vdb_wr) { + lv_coord_t col; + for(row = masked_a.y1; row <= masked_a.y2; row++) { + for(col = 0; col < map_useful_w; col++) { + lv_color_t px_color = *((lv_color_t *)&map_p[(uint32_t)col * px_size_byte]); + disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, col + masked_a.x1, row, px_color, opa); + } + map_p += map_width * px_size_byte; /*Next row on the map*/ + } + } + /*Normal native VDB*/ + else { + for(row = masked_a.y1; row <= masked_a.y2; row++) { +#if USE_LV_GPU + if(lv_disp_is_mem_blend_supported() == false) { + sw_mem_blend(vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa); + } else { + lv_disp_mem_blend(vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa); + } +#else + sw_mem_blend(vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa); +#endif + map_p += map_width * px_size_byte; /*Next row on the map*/ + vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ + } + } + } + + /*In the other cases every pixel need to be checked one-by-one*/ + else { + lv_color_t chroma_key_color = LV_COLOR_TRANSP; + lv_coord_t col; + lv_color_t last_img_px = LV_COLOR_BLACK; + lv_color_t recolored_px = lv_color_mix(recolor, last_img_px, recolor_opa); + for(row = masked_a.y1; row <= masked_a.y2; row++) { + for(col = 0; col < map_useful_w; col++) { + lv_opa_t opa_result = opa; + uint8_t * px_color_p = (uint8_t *) &map_p[(uint32_t)col * px_size_byte]; + lv_color_t px_color; + + /*Calculate with the pixel level alpha*/ + if(alpha_byte) { +#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1 + px_color.full = px_color_p[0]; +#elif LV_COLOR_DEPTH == 16 + /*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/ + px_color.full = px_color_p[0] + (px_color_p[1] << 8); +#elif LV_COLOR_DEPTH == 32 + px_color = *((lv_color_t *)px_color_p); +#endif + lv_opa_t px_opa = *(px_color_p + LV_IMG_PX_SIZE_ALPHA_BYTE - 1); + if(px_opa == LV_OPA_TRANSP) continue; + else if(px_opa != LV_OPA_COVER) opa_result = (uint32_t)((uint32_t)px_opa * opa_result) >> 8; + } else { + px_color = *((lv_color_t *)px_color_p); + } + + /*Handle chroma key*/ + if(chroma_key && px_color.full == chroma_key_color.full) continue; + + /*Re-color the pixel if required*/ + if(recolor_opa != LV_OPA_TRANSP) { + if(last_img_px.full != px_color.full) { /*Minor acceleration: calculate only for new colors (save the last)*/ + last_img_px = px_color; + recolored_px = lv_color_mix(recolor, last_img_px, recolor_opa); + } + /*Handle custom VDB write is present*/ + if(disp->driver.vdb_wr) { + disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, col + masked_a.x1, row, recolored_px, opa_result); + } + /*Normal native VDB write*/ + else { + if(opa_result == LV_OPA_COVER) vdb_buf_tmp[col].full = recolored_px.full; + else vdb_buf_tmp[col] = lv_color_mix(recolored_px, vdb_buf_tmp[col], opa_result); + } + } else { + /*Handle custom VDB write is present*/ + if(disp->driver.vdb_wr) { + disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, col + masked_a.x1, row, px_color, opa_result); + } + /*Normal native VDB write*/ + else { + if(opa_result == LV_OPA_COVER) vdb_buf_tmp[col] = px_color; + else { +#if LV_COLOR_SCREEN_TRANSP == 0 + vdb_buf_tmp[col] = lv_color_mix(px_color, vdb_buf_tmp[col], opa_result); +#else + vdb_buf_tmp[col] = color_mix_2_alpha(vdb_buf_tmp[col], vdb_buf_tmp[col].alpha, px_color, opa_result); +#endif + } + } + } + } + + map_p += map_width * px_size_byte; /*Next row on the map*/ + vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ + } + } +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Blend pixels to destination memory using opacity + * @param dest a memory address. Copy 'src' here. + * @param src pointer to pixel map. Copy it to 'dest'. + * @param length number of pixels in 'src' + * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) + */ +static void sw_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa) +{ + if(opa == LV_OPA_COVER) { + memcpy(dest, src, length * sizeof(lv_color_t)); + } else { + uint32_t col; + for(col = 0; col < length; col++) { + dest[col] = lv_color_mix(src[col], dest[col], opa); + } + } +} + +/** + * + * @param mem_area coordinates of 'mem' memory area + * @param mem a memory address. Considered to a rectangular window according to 'mem_area' + * @param fill_area coordinates of an area to fill. Relative to 'mem_area'. + * @param color fill color + * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) + */ +static void sw_color_fill(lv_area_t * mem_area, lv_color_t * mem, const lv_area_t * fill_area, lv_color_t color, lv_opa_t opa) +{ + /*Set all row in vdb to the given color*/ + lv_coord_t row; + lv_coord_t col; + lv_coord_t mem_width = lv_area_get_width(mem_area); + + lv_disp_t * disp = lv_disp_get_active(); + if(disp->driver.vdb_wr) { + for(col = fill_area->x1; col <= fill_area->x2; col++) { + for(row = fill_area->y1; row <= fill_area->y2; row++) { + disp->driver.vdb_wr((uint8_t *)mem, mem_width, col, row, color, opa); + } + } + } else { + mem += fill_area->y1 * mem_width; /*Go to the first row*/ + + /*Run simpler function without opacity*/ + if(opa == LV_OPA_COVER) { + + /*Fill the first row with 'color'*/ + for(col = fill_area->x1; col <= fill_area->x2; col++) { + mem[col] = color; + } + + /*Copy the first row to all other rows*/ + lv_color_t * mem_first = &mem[fill_area->x1]; + lv_coord_t copy_size = (fill_area->x2 - fill_area->x1 + 1) * sizeof(lv_color_t); + mem += mem_width; + + for(row = fill_area->y1 + 1; row <= fill_area->y2; row++) { + memcpy(&mem[fill_area->x1], mem_first, copy_size); + mem += mem_width; + } + } + /*Calculate with alpha too*/ + else { + +#if LV_COLOR_SCREEN_TRANSP == 0 + lv_color_t bg_tmp = LV_COLOR_BLACK; + lv_color_t opa_tmp = lv_color_mix(color, bg_tmp, opa); +#endif + for(row = fill_area->y1; row <= fill_area->y2; row++) { + for(col = fill_area->x1; col <= fill_area->x2; col++) { +#if LV_COLOR_SCREEN_TRANSP == 0 + /*If the bg color changed recalculate the result color*/ + if(mem[col].full != bg_tmp.full) { + bg_tmp = mem[col]; + opa_tmp = lv_color_mix(color, bg_tmp, opa); + } + + mem[col] = opa_tmp; + +#else + mem[col] = color_mix_2_alpha(mem[col], mem[col].alpha, color, opa); +#endif + } + mem += mem_width; + } + } + } +} + +#if LV_COLOR_SCREEN_TRANSP + +/** + * Mix two colors. Both color can have alpha value. It requires ARGB888 colors. + * @param bg_color background color + * @param bg_opa alpha of the background color + * @param fg_color foreground color + * @param fg_opa alpha of the foreground color + * @return the mixed color. the alpha channel (color.alpha) contains the result alpha + */ +static inline lv_color_t color_mix_2_alpha(lv_color_t bg_color, lv_opa_t bg_opa, lv_color_t fg_color, lv_opa_t fg_opa) +{ + /* Pick the foreground if it's fully opaque or the Background is fully transparent*/ + if(fg_opa == LV_OPA_COVER && bg_opa <= LV_OPA_MIN) { + fg_color.alpha = fg_opa; + return fg_color; + } + /*Transparent foreground: use the Background*/ + else if(fg_opa <= LV_OPA_MIN) { + return bg_color; + } + /*Opaque background: use simple mix*/ + else if(bg_opa >= LV_OPA_MAX) { + return lv_color_mix(fg_color, bg_color, fg_opa); + } + /*Both colors have alpha. Expensive calculation need to be applied*/ + else { + /*Save the parameters and the result. If they will be asked again don't compute again*/ + static lv_opa_t fg_opa_save = 0; + static lv_opa_t bg_opa_save = 0; + static lv_color_t c = {{0}}; + + if(fg_opa != fg_opa_save || bg_opa != bg_opa_save) { + fg_opa_save = fg_opa; + bg_opa_save = bg_opa; + /*Info: https://en.wikipedia.org/wiki/Alpha_compositing#Analytical_derivation_of_the_over_operator*/ + lv_opa_t alpha_res = 255 - ((uint16_t)((uint16_t)(255 - fg_opa) * (255 - bg_opa)) >> 8); + if(alpha_res == 0) { + while(1); + } + lv_opa_t ratio = (uint16_t)((uint16_t) fg_opa * 255) / alpha_res; + c = lv_color_mix(fg_color, bg_color, ratio); + c.alpha = alpha_res; + } + return c; + + } +} +#endif /*LV_COLOR_SCREEN_TRANSP*/ + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_vbasic.h b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_vbasic.h new file mode 100644 index 0000000..88838b7 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_draw/lv_draw_vbasic.h @@ -0,0 +1,89 @@ +/** + * @file lv_draw_vbasic.h + * + */ + +#ifndef LV_DRAW_VBASIC_H +#define LV_DRAW_VBASIC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if LV_VDB_SIZE != 0 + +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_area.h" +#include "../lv_misc/lv_font.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); +/** + * Fill an area in the Virtual Display Buffer + * @param cords_p coordinates of the area to fill + * @param mask_p fill only o this mask + * @param color fill color + * @param opa opacity of the area (0..255) + */ +void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p, + lv_color_t color, lv_opa_t opa); + +/** + * Draw a letter in the Virtual Display Buffer + * @param pos_p left-top coordinate of the latter + * @param mask_p the letter will be drawn only on this area + * @param font_p pointer to font + * @param letter a letter to draw + * @param color color of letter + * @param opa opacity of letter (0..255) + */ +void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p, + const lv_font_t * font_p, uint32_t letter, + lv_color_t color, lv_opa_t opa); + +/** + * Draw a color map to the display (image) + * @param cords_p coordinates the color map + * @param mask_p the map will drawn only on this area (truncated to VDB area) + * @param map_p pointer to a lv_color_t array + * @param opa opacity of the map + * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels + * @param alpha_byte true: extra alpha byte is inserted for every pixel + * @param recolor mix the pixels with this color + * @param recolor_opa the intense of recoloring + */ +void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p, + const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, + lv_color_t recolor, lv_opa_t recolor_opa); + +/********************** + * MACROS + **********************/ + +#endif /*LV_VDB_SIZE != 0*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DRAW_RBASIC_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_120.c b/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_120.c new file mode 100644 index 0000000..f9d2d9f --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_120.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../lv_misc/lv_font.h" + +#if USE_HEKATE_SYMBOL_120 != 0 /*Can be enabled in lv_conf.h*/ + +/*********************************************************************************** + * hekate-symbols-huge.ttf 120 px Font in U+f002 () .. U+f007 () range with all bpp + * Sparse font with only these characters:  +***********************************************************************************/ + +/*Store the glyph descriptions*/ +static const lv_font_glyph_dsc_t hekate_symbol_120_glyph_dsc[] = +{ +#if USE_HEKATE_SYMBOL_120 == 8 + {.w_px = 103, .glyph_index = 0}, /*Unicode: U+f002 ()*/ + {.w_px = 103, .glyph_index = 12360}, /*Unicode: U+f003 ()*/ + {.w_px = 103, .glyph_index = 24720}, /*Unicode: U+f005 ()*/ + {.w_px = 103, .glyph_index = 37080}, /*Unicode: U+f007 ()*/ + +#endif +}; + +lv_font_t hekate_symbol_120 = +{ + .unicode_first = LV_SYMBOL_GLYPH_FIRST, /*First Unicode letter in this font*/ + .unicode_last = LV_SYMBOL_GLYPH_LAST, /*Last Unicode letter in this font*/ + .h_px = 120, /*Font height in pixels*/ + .glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x36E00), /*Bitmap of glyphs*/ + .glyph_dsc = hekate_symbol_120_glyph_dsc, /*Description of glyphs*/ + .glyph_cnt = 4, /*Number of glyphs in the font*/ + .unicode_list = NULL, /*List of unicode characters*/ + .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ + .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ +#if USE_HEKATE_SYMBOL_120 == 8 + .bpp = 8, /*Bit per pixel*/ +#endif + .monospace = 0, /*Fix width (0: if not used)*/ + .next_page = NULL, /*Pointer to a font extension*/ +}; + +#endif /*USE_HEKATE_SYMBOL_100*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_20.c b/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_20.c new file mode 100644 index 0000000..e6b622d --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_20.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../lv_misc/lv_font.h" + +#if USE_HEKATE_SYMBOL_20 != 0 /*Can be enabled in lv_conf.h*/ + +/*********************************************************************************** + * hekate-symbols.ttf 20 px Font in U+f000 () .. U+f2ee () range with all bpp + * Sparse font with only these characters:  +***********************************************************************************/ + +/*Store the glyph descriptions*/ +static const lv_font_glyph_dsc_t hekate_symbol_20_glyph_dsc[] = +{ +#if USE_HEKATE_SYMBOL_20 == 4 + {.w_px = 5, .glyph_index = 0}, /*Unicode: U+f001 ()*/ + {.w_px = 16, .glyph_index = 60}, /*Unicode: U+f008 ()*/ + {.w_px = 20, .glyph_index = 220}, /*Unicode: U+f00b ()*/ + {.w_px = 22, .glyph_index = 420}, /*Unicode: U+f00c ()*/ + {.w_px = 16, .glyph_index = 640}, /*Unicode: U+f00d ()*/ + {.w_px = 18, .glyph_index = 800}, /*Unicode: U+f011 ()*/ + {.w_px = 18, .glyph_index = 980}, /*Unicode: U+f013 ()*/ + {.w_px = 16, .glyph_index = 1160}, /*Unicode: U+f014 ()*/ + {.w_px = 23, .glyph_index = 1320}, /*Unicode: U+f015 ()*/ + {.w_px = 18, .glyph_index = 1560}, /*Unicode: U+f019 ()*/ + {.w_px = 23, .glyph_index = 1740}, /*Unicode: U+f01c ()*/ + {.w_px = 18, .glyph_index = 1980}, /*Unicode: U+f021 ()*/ + {.w_px = 18, .glyph_index = 2160}, /*Unicode: U+f026 ()*/ + {.w_px = 18, .glyph_index = 2340}, /*Unicode: U+f027 ()*/ + {.w_px = 13, .glyph_index = 2520}, /*Unicode: U+f028 ()*/ + {.w_px = 13, .glyph_index = 2660}, /*Unicode: U+f03e ()*/ + {.w_px = 16, .glyph_index = 2800}, /*Unicode: U+f040 ()*/ + {.w_px = 13, .glyph_index = 2960}, /*Unicode: U+f048 ()*/ + {.w_px = 13, .glyph_index = 3100}, /*Unicode: U+f04b ()*/ + {.w_px = 13, .glyph_index = 3240}, /*Unicode: U+f04c ()*/ + {.w_px = 9, .glyph_index = 3380}, /*Unicode: U+f04d ()*/ + {.w_px = 23, .glyph_index = 3480}, /*Unicode: U+f051 ()*/ + {.w_px = 21, .glyph_index = 3720}, /*Unicode: U+f052 ()*/ + {.w_px = 11, .glyph_index = 3940}, /*Unicode: U+f053 ()*/ + {.w_px = 11, .glyph_index = 4060}, /*Unicode: U+f054 ()*/ + {.w_px = 18, .glyph_index = 4180}, /*Unicode: U+f067 ()*/ + {.w_px = 18, .glyph_index = 4360}, /*Unicode: U+f068 ()*/ + {.w_px = 20, .glyph_index = 4540}, /*Unicode: U+f071 ()*/ + {.w_px = 20, .glyph_index = 4740}, /*Unicode: U+f074 ()*/ + {.w_px = 18, .glyph_index = 4940}, /*Unicode: U+f077 ()*/ + {.w_px = 18, .glyph_index = 5120}, /*Unicode: U+f078 ()*/ + {.w_px = 18, .glyph_index = 5300}, /*Unicode: U+f079 ()*/ + {.w_px = 20, .glyph_index = 5480}, /*Unicode: U+f07b ()*/ + {.w_px = 18, .glyph_index = 5680}, /*Unicode: U+f093 ()*/ + {.w_px = 25, .glyph_index = 5860}, /*Unicode: U+f095 ()*/ + {.w_px = 18, .glyph_index = 6120}, /*Unicode: U+f0c4 ()*/ + {.w_px = 16, .glyph_index = 6300}, /*Unicode: U+f0c5 ()*/ + {.w_px = 17, .glyph_index = 6460}, /*Unicode: U+f0c7 ()*/ + {.w_px = 8, .glyph_index = 6640}, /*Unicode: U+f0e7 ()*/ + {.w_px = 12, .glyph_index = 6720}, /*Unicode: U+f0f3 ()*/ + {.w_px = 23, .glyph_index = 6840}, /*Unicode: U+f11c ()*/ + {.w_px = 18, .glyph_index = 7080}, /*Unicode: U+f124 ()*/ + {.w_px = 13, .glyph_index = 7260}, /*Unicode: U+f15b ()*/ + {.w_px = 20, .glyph_index = 7400}, /*Unicode: U+f1eb ()*/ + {.w_px = 26, .glyph_index = 7600}, /*Unicode: U+f240 ()*/ + {.w_px = 26, .glyph_index = 7860}, /*Unicode: U+f241 ()*/ + {.w_px = 26, .glyph_index = 8120}, /*Unicode: U+f242 ()*/ + {.w_px = 26, .glyph_index = 8380}, /*Unicode: U+f243 ()*/ + {.w_px = 26, .glyph_index = 8640}, /*Unicode: U+f244 ()*/ + {.w_px = 20, .glyph_index = 8900}, /*Unicode: U+f293 ()*/ + +#elif USE_HEKATE_SYMBOL_20 == 8 + {.w_px = 5, .glyph_index = 0}, /*Unicode: U+f001 ()*/ + {.w_px = 16, .glyph_index = 100}, /*Unicode: U+f008 ()*/ + {.w_px = 20, .glyph_index = 420}, /*Unicode: U+f00b ()*/ + {.w_px = 22, .glyph_index = 820}, /*Unicode: U+f00c ()*/ + {.w_px = 16, .glyph_index = 1260}, /*Unicode: U+f00d ()*/ + {.w_px = 18, .glyph_index = 1580}, /*Unicode: U+f011 ()*/ + {.w_px = 18, .glyph_index = 1940}, /*Unicode: U+f013 ()*/ + {.w_px = 16, .glyph_index = 2300}, /*Unicode: U+f014 ()*/ + {.w_px = 23, .glyph_index = 2620}, /*Unicode: U+f015 ()*/ + {.w_px = 18, .glyph_index = 3080}, /*Unicode: U+f019 ()*/ + {.w_px = 23, .glyph_index = 3440}, /*Unicode: U+f01c ()*/ + {.w_px = 18, .glyph_index = 3900}, /*Unicode: U+f021 ()*/ + {.w_px = 18, .glyph_index = 4260}, /*Unicode: U+f026 ()*/ + {.w_px = 18, .glyph_index = 4620}, /*Unicode: U+f027 ()*/ + {.w_px = 13, .glyph_index = 4980}, /*Unicode: U+f028 ()*/ + {.w_px = 13, .glyph_index = 5240}, /*Unicode: U+f03e ()*/ + {.w_px = 16, .glyph_index = 5500}, /*Unicode: U+f040 ()*/ + {.w_px = 13, .glyph_index = 5820}, /*Unicode: U+f048 ()*/ + {.w_px = 13, .glyph_index = 6080}, /*Unicode: U+f04b ()*/ + {.w_px = 13, .glyph_index = 6340}, /*Unicode: U+f04c ()*/ + {.w_px = 9, .glyph_index = 6600}, /*Unicode: U+f04d ()*/ + {.w_px = 23, .glyph_index = 6780}, /*Unicode: U+f051 ()*/ + {.w_px = 21, .glyph_index = 7240}, /*Unicode: U+f052 ()*/ + {.w_px = 11, .glyph_index = 7660}, /*Unicode: U+f053 ()*/ + {.w_px = 11, .glyph_index = 7880}, /*Unicode: U+f054 ()*/ + {.w_px = 18, .glyph_index = 8100}, /*Unicode: U+f067 ()*/ + {.w_px = 18, .glyph_index = 8460}, /*Unicode: U+f068 ()*/ + {.w_px = 20, .glyph_index = 8820}, /*Unicode: U+f071 ()*/ + {.w_px = 20, .glyph_index = 9220}, /*Unicode: U+f074 ()*/ + {.w_px = 18, .glyph_index = 9620}, /*Unicode: U+f077 ()*/ + {.w_px = 18, .glyph_index = 9980}, /*Unicode: U+f078 ()*/ + {.w_px = 18, .glyph_index = 10340}, /*Unicode: U+f079 ()*/ + {.w_px = 20, .glyph_index = 10700}, /*Unicode: U+f07b ()*/ + {.w_px = 18, .glyph_index = 11100}, /*Unicode: U+f093 ()*/ + {.w_px = 25, .glyph_index = 11460}, /*Unicode: U+f095 ()*/ + {.w_px = 18, .glyph_index = 11960}, /*Unicode: U+f0c4 ()*/ + {.w_px = 16, .glyph_index = 12320}, /*Unicode: U+f0c5 ()*/ + {.w_px = 17, .glyph_index = 12640}, /*Unicode: U+f0c7 ()*/ + {.w_px = 8, .glyph_index = 12980}, /*Unicode: U+f0e7 ()*/ + {.w_px = 12, .glyph_index = 13140}, /*Unicode: U+f0f3 ()*/ + {.w_px = 23, .glyph_index = 13380}, /*Unicode: U+f11c ()*/ + {.w_px = 18, .glyph_index = 13840}, /*Unicode: U+f124 ()*/ + {.w_px = 13, .glyph_index = 14200}, /*Unicode: U+f15b ()*/ + {.w_px = 20, .glyph_index = 14460}, /*Unicode: U+f1eb ()*/ + {.w_px = 26, .glyph_index = 14860}, /*Unicode: U+f240 ()*/ + {.w_px = 26, .glyph_index = 15380}, /*Unicode: U+f241 ()*/ + {.w_px = 26, .glyph_index = 15900}, /*Unicode: U+f242 ()*/ + {.w_px = 26, .glyph_index = 16420}, /*Unicode: U+f243 ()*/ + {.w_px = 26, .glyph_index = 16940}, /*Unicode: U+f244 ()*/ + {.w_px = 20, .glyph_index = 17460}, /*Unicode: U+f293 ()*/ + +#endif +}; + +lv_font_t hekate_symbol_20 = +{ + .unicode_first = LV_SYMBOL_GLYPH_FIRST, /*First Unicode letter in this font*/ + .unicode_last = LV_SYMBOL_GLYPH_LAST, /*Last Unicode letter in this font*/ + .h_px = 20, /*Font height in pixels*/ + //.glyph_bitmap = hekate_symbol_20_glyph_bitmap, /*Bitmap of glyphs*/ + .glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0xFC00), + .glyph_dsc = hekate_symbol_20_glyph_dsc, /*Description of glyphs*/ + .glyph_cnt = 50, /*Number of glyphs in the font*/ + .unicode_list = NULL, /*List of unicode characters*/ + .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ + .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ +#if USE_HEKATE_SYMBOL_20 == 4 + .bpp = 4, /*Bit per pixel*/ +#elif USE_HEKATE_SYMBOL_20 == 8 + .bpp = 8, /*Bit per pixel*/ +#endif + .monospace = 0, /*Fix width (0: if not used)*/ + .next_page = NULL, /*Pointer to a font extension*/ +}; + +#endif /*USE_HEKATE_SYMBOL_20*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_30.c b/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_30.c new file mode 100644 index 0000000..f8df9b0 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/hekate_symbol_30.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../lv_misc/lv_font.h" + +#if USE_HEKATE_SYMBOL_30 != 0 /*Can be enabled in lv_conf.h*/ + +/*********************************************************************************** + * hekate-symbols.ttf 30 px Font in U+f000 () .. U+f2ee () range with all bpp + * Sparse font with only these characters:  +***********************************************************************************/ + +/*Store the glyph descriptions*/ +static const lv_font_glyph_dsc_t hekate_symbol_30_glyph_dsc[] = +{ +#if USE_HEKATE_SYMBOL_30 == 4 + {.w_px = 7, .glyph_index = 0}, /*Unicode: U+f001 ()*/ + {.w_px = 25, .glyph_index = 120}, /*Unicode: U+f008 ()*/ + {.w_px = 27, .glyph_index = 510}, /*Unicode: U+f00b ()*/ + {.w_px = 31, .glyph_index = 930}, /*Unicode: U+f00c ()*/ + {.w_px = 22, .glyph_index = 1410}, /*Unicode: U+f00d ()*/ + {.w_px = 25, .glyph_index = 1740}, /*Unicode: U+f011 ()*/ + {.w_px = 25, .glyph_index = 2130}, /*Unicode: U+f013 ()*/ + {.w_px = 23, .glyph_index = 2520}, /*Unicode: U+f014 ()*/ + {.w_px = 34, .glyph_index = 2880}, /*Unicode: U+f015 ()*/ + {.w_px = 25, .glyph_index = 3390}, /*Unicode: U+f019 ()*/ + {.w_px = 32, .glyph_index = 3780}, /*Unicode: U+f01c ()*/ + {.w_px = 25, .glyph_index = 4260}, /*Unicode: U+f021 ()*/ + {.w_px = 25, .glyph_index = 4650}, /*Unicode: U+f026 ()*/ + {.w_px = 25, .glyph_index = 5040}, /*Unicode: U+f027 ()*/ + {.w_px = 20, .glyph_index = 5430}, /*Unicode: U+f028 ()*/ + {.w_px = 20, .glyph_index = 5730}, /*Unicode: U+f03e ()*/ + {.w_px = 25, .glyph_index = 6030}, /*Unicode: U+f040 ()*/ + {.w_px = 20, .glyph_index = 6420}, /*Unicode: U+f048 ()*/ + {.w_px = 20, .glyph_index = 6720}, /*Unicode: U+f04b ()*/ + {.w_px = 20, .glyph_index = 7020}, /*Unicode: U+f04c ()*/ + {.w_px = 13, .glyph_index = 7320}, /*Unicode: U+f04d ()*/ + {.w_px = 32, .glyph_index = 7530}, /*Unicode: U+f051 ()*/ + {.w_px = 30, .glyph_index = 8010}, /*Unicode: U+f052 ()*/ + {.w_px = 16, .glyph_index = 8460}, /*Unicode: U+f053 ()*/ + {.w_px = 16, .glyph_index = 8700}, /*Unicode: U+f054 ()*/ + {.w_px = 25, .glyph_index = 8940}, /*Unicode: U+f067 ()*/ + {.w_px = 25, .glyph_index = 9330}, /*Unicode: U+f068 ()*/ + {.w_px = 27, .glyph_index = 9720}, /*Unicode: U+f071 ()*/ + {.w_px = 29, .glyph_index = 10140}, /*Unicode: U+f074 ()*/ + {.w_px = 26, .glyph_index = 10590}, /*Unicode: U+f077 ()*/ + {.w_px = 26, .glyph_index = 10980}, /*Unicode: U+f078 ()*/ + {.w_px = 25, .glyph_index = 11370}, /*Unicode: U+f079 ()*/ + {.w_px = 29, .glyph_index = 11760}, /*Unicode: U+f07b ()*/ + {.w_px = 25, .glyph_index = 12210}, /*Unicode: U+f093 ()*/ + {.w_px = 37, .glyph_index = 12600}, /*Unicode: U+f095 ()*/ + {.w_px = 25, .glyph_index = 13170}, /*Unicode: U+f0c4 ()*/ + {.w_px = 23, .glyph_index = 13560}, /*Unicode: U+f0c5 ()*/ + {.w_px = 24, .glyph_index = 13920}, /*Unicode: U+f0c7 ()*/ + {.w_px = 13, .glyph_index = 14280}, /*Unicode: U+f0e7 ()*/ + {.w_px = 18, .glyph_index = 14490}, /*Unicode: U+f0f3 ()*/ + {.w_px = 33, .glyph_index = 14760}, /*Unicode: U+f11c ()*/ + {.w_px = 25, .glyph_index = 15270}, /*Unicode: U+f124 ()*/ + {.w_px = 20, .glyph_index = 15660}, /*Unicode: U+f15b ()*/ + {.w_px = 29, .glyph_index = 15960}, /*Unicode: U+f1eb ()*/ + {.w_px = 38, .glyph_index = 16410}, /*Unicode: U+f240 ()*/ + {.w_px = 38, .glyph_index = 16980}, /*Unicode: U+f241 ()*/ + {.w_px = 38, .glyph_index = 17550}, /*Unicode: U+f242 ()*/ + {.w_px = 38, .glyph_index = 18120}, /*Unicode: U+f243 ()*/ + {.w_px = 38, .glyph_index = 18690}, /*Unicode: U+f244 ()*/ + {.w_px = 29, .glyph_index = 19260}, /*Unicode: U+f293 ()*/ + +#elif USE_HEKATE_SYMBOL_30 == 8 + {.w_px = 7, .glyph_index = 0}, /*Unicode: U+f001 ()*/ + {.w_px = 25, .glyph_index = 210}, /*Unicode: U+f008 ()*/ + {.w_px = 27, .glyph_index = 960}, /*Unicode: U+f00b ()*/ + {.w_px = 31, .glyph_index = 1770}, /*Unicode: U+f00c ()*/ + {.w_px = 22, .glyph_index = 2700}, /*Unicode: U+f00d ()*/ + {.w_px = 25, .glyph_index = 3360}, /*Unicode: U+f011 ()*/ + {.w_px = 25, .glyph_index = 4110}, /*Unicode: U+f013 ()*/ + {.w_px = 23, .glyph_index = 4860}, /*Unicode: U+f014 ()*/ + {.w_px = 34, .glyph_index = 5550}, /*Unicode: U+f015 ()*/ + {.w_px = 25, .glyph_index = 6570}, /*Unicode: U+f019 ()*/ + {.w_px = 32, .glyph_index = 7320}, /*Unicode: U+f01c ()*/ + {.w_px = 25, .glyph_index = 8280}, /*Unicode: U+f021 ()*/ + {.w_px = 25, .glyph_index = 9030}, /*Unicode: U+f026 ()*/ + {.w_px = 25, .glyph_index = 9780}, /*Unicode: U+f027 ()*/ + {.w_px = 20, .glyph_index = 10530}, /*Unicode: U+f028 ()*/ + {.w_px = 20, .glyph_index = 11130}, /*Unicode: U+f03e ()*/ + {.w_px = 25, .glyph_index = 11730}, /*Unicode: U+f040 ()*/ + {.w_px = 20, .glyph_index = 12480}, /*Unicode: U+f048 ()*/ + {.w_px = 20, .glyph_index = 13080}, /*Unicode: U+f04b ()*/ + {.w_px = 20, .glyph_index = 13680}, /*Unicode: U+f04c ()*/ + {.w_px = 13, .glyph_index = 14280}, /*Unicode: U+f04d ()*/ + {.w_px = 32, .glyph_index = 14670}, /*Unicode: U+f051 ()*/ + {.w_px = 30, .glyph_index = 15630}, /*Unicode: U+f052 ()*/ + {.w_px = 16, .glyph_index = 16530}, /*Unicode: U+f053 ()*/ + {.w_px = 16, .glyph_index = 17010}, /*Unicode: U+f054 ()*/ + {.w_px = 25, .glyph_index = 17490}, /*Unicode: U+f067 ()*/ + {.w_px = 25, .glyph_index = 18240}, /*Unicode: U+f068 ()*/ + {.w_px = 27, .glyph_index = 18990}, /*Unicode: U+f071 ()*/ + {.w_px = 29, .glyph_index = 19800}, /*Unicode: U+f074 ()*/ + {.w_px = 26, .glyph_index = 20670}, /*Unicode: U+f077 ()*/ + {.w_px = 26, .glyph_index = 21450}, /*Unicode: U+f078 ()*/ + {.w_px = 25, .glyph_index = 22230}, /*Unicode: U+f079 ()*/ + {.w_px = 29, .glyph_index = 22980}, /*Unicode: U+f07b ()*/ + {.w_px = 25, .glyph_index = 23850}, /*Unicode: U+f093 ()*/ + {.w_px = 37, .glyph_index = 24600}, /*Unicode: U+f095 ()*/ + {.w_px = 25, .glyph_index = 25710}, /*Unicode: U+f0c4 ()*/ + {.w_px = 23, .glyph_index = 26460}, /*Unicode: U+f0c5 ()*/ + {.w_px = 24, .glyph_index = 27150}, /*Unicode: U+f0c7 ()*/ + {.w_px = 13, .glyph_index = 27870}, /*Unicode: U+f0e7 ()*/ + {.w_px = 18, .glyph_index = 28260}, /*Unicode: U+f0f3 ()*/ + {.w_px = 33, .glyph_index = 28800}, /*Unicode: U+f11c ()*/ + {.w_px = 25, .glyph_index = 29790}, /*Unicode: U+f124 ()*/ + {.w_px = 20, .glyph_index = 30540}, /*Unicode: U+f15b ()*/ + {.w_px = 29, .glyph_index = 31140}, /*Unicode: U+f1eb ()*/ + {.w_px = 38, .glyph_index = 32010}, /*Unicode: U+f240 ()*/ + {.w_px = 38, .glyph_index = 33150}, /*Unicode: U+f241 ()*/ + {.w_px = 38, .glyph_index = 34290}, /*Unicode: U+f242 ()*/ + {.w_px = 38, .glyph_index = 35430}, /*Unicode: U+f243 ()*/ + {.w_px = 38, .glyph_index = 36570}, /*Unicode: U+f244 ()*/ + {.w_px = 29, .glyph_index = 37710}, /*Unicode: U+f293 ()*/ + +#endif +}; + +lv_font_t hekate_symbol_30 = +{ + .unicode_first = LV_SYMBOL_GLYPH_FIRST, /*First Unicode letter in this font*/ + .unicode_last = LV_SYMBOL_GLYPH_LAST, /*Last Unicode letter in this font*/ + .h_px = 30, /*Font height in pixels*/ + //.glyph_bitmap = hekate_symbol_30_glyph_bitmap, /*Bitmap of glyphs*/ + .glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x14200), + .glyph_dsc = hekate_symbol_30_glyph_dsc, /*Description of glyphs*/ + .glyph_cnt = 50, /*Number of glyphs in the font*/ + .unicode_list = NULL, /*List of unicode characters*/ + .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ + .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ +#if USE_HEKATE_SYMBOL_30 == 4 + .bpp = 4, /*Bit per pixel*/ + #elif USE_HEKATE_SYMBOL_30 == 8 + .bpp = 8, /*Bit per pixel*/ +#endif + .monospace = 0, /*Fix width (0: if not used)*/ + .next_page = NULL, /*Pointer to a font extension*/ +}; + +#endif /*USE_HEKATE_SYMBOL_30*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/interui_20.c b/nyx/nyx_gui/libs/lvgl/lv_fonts/interui_20.c new file mode 100644 index 0000000..1789ae5 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/interui_20.c @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../lv_misc/lv_font.h" + +#if USE_INTERUI_20 != 0 /*Can be enabled in lv_conf.h*/ + +/*********************************************************************************** + * Inter-UI-Regular-stretched.ttf 20 px Font in U+0020 ( ) .. U+007e (~) range with all bpp +***********************************************************************************/ + +/*Store the glyph descriptions*/ +static const lv_font_glyph_dsc_t interui_20_glyph_dsc[] = +{ +#if USE_INTERUI_20 == 4 + {.w_px = 6, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ + {.w_px = 3, .glyph_index = 60}, /*Unicode: U+0021 (!)*/ + {.w_px = 5, .glyph_index = 100}, /*Unicode: U+0022 (")*/ + {.w_px = 8, .glyph_index = 160}, /*Unicode: U+0023 (#)*/ + {.w_px = 9, .glyph_index = 240}, /*Unicode: U+0024 ($)*/ + {.w_px = 14, .glyph_index = 340}, /*Unicode: U+0025 (%)*/ + {.w_px = 12, .glyph_index = 480}, /*Unicode: U+0026 (&)*/ + {.w_px = 3, .glyph_index = 600}, /*Unicode: U+0027 (')*/ + {.w_px = 5, .glyph_index = 640}, /*Unicode: U+0028 (()*/ + {.w_px = 5, .glyph_index = 700}, /*Unicode: U+0029 ())*/ + {.w_px = 7, .glyph_index = 760}, /*Unicode: U+002a (*)*/ + {.w_px = 10, .glyph_index = 840}, /*Unicode: U+002b (+)*/ + {.w_px = 3, .glyph_index = 940}, /*Unicode: U+002c (,)*/ + {.w_px = 5, .glyph_index = 980}, /*Unicode: U+002d (-)*/ + {.w_px = 3, .glyph_index = 1040}, /*Unicode: U+002e (.)*/ + {.w_px = 8, .glyph_index = 1080}, /*Unicode: U+002f (/)*/ + {.w_px = 10, .glyph_index = 1160}, /*Unicode: U+0030 (0)*/ + {.w_px = 5, .glyph_index = 1260}, /*Unicode: U+0031 (1)*/ + {.w_px = 9, .glyph_index = 1320}, /*Unicode: U+0032 (2)*/ + {.w_px = 10, .glyph_index = 1420}, /*Unicode: U+0033 (3)*/ + {.w_px = 9, .glyph_index = 1520}, /*Unicode: U+0034 (4)*/ + {.w_px = 9, .glyph_index = 1620}, /*Unicode: U+0035 (5)*/ + {.w_px = 10, .glyph_index = 1720}, /*Unicode: U+0036 (6)*/ + {.w_px = 8, .glyph_index = 1820}, /*Unicode: U+0037 (7)*/ + {.w_px = 10, .glyph_index = 1900}, /*Unicode: U+0038 (8)*/ + {.w_px = 10, .glyph_index = 2000}, /*Unicode: U+0039 (9)*/ + {.w_px = 3, .glyph_index = 2100}, /*Unicode: U+003a (:)*/ + {.w_px = 3, .glyph_index = 2140}, /*Unicode: U+003b (;)*/ + {.w_px = 12, .glyph_index = 2180}, /*Unicode: U+003c (<)*/ + {.w_px = 10, .glyph_index = 2300}, /*Unicode: U+003d (=)*/ + {.w_px = 12, .glyph_index = 2400}, /*Unicode: U+003e (>)*/ + {.w_px = 8, .glyph_index = 2520}, /*Unicode: U+003f (?)*/ + {.w_px = 14, .glyph_index = 2600}, /*Unicode: U+0040 (@)*/ + {.w_px = 12, .glyph_index = 2740}, /*Unicode: U+0041 (A)*/ + {.w_px = 10, .glyph_index = 2860}, /*Unicode: U+0042 (B)*/ + {.w_px = 11, .glyph_index = 2960}, /*Unicode: U+0043 (C)*/ + {.w_px = 12, .glyph_index = 3080}, /*Unicode: U+0044 (D)*/ + {.w_px = 9, .glyph_index = 3200}, /*Unicode: U+0045 (E)*/ + {.w_px = 8, .glyph_index = 3300}, /*Unicode: U+0046 (F)*/ + {.w_px = 12, .glyph_index = 3380}, /*Unicode: U+0047 (G)*/ + {.w_px = 10, .glyph_index = 3500}, /*Unicode: U+0048 (H)*/ + {.w_px = 3, .glyph_index = 3600}, /*Unicode: U+0049 (I)*/ + {.w_px = 7, .glyph_index = 3640}, /*Unicode: U+004a (J)*/ + {.w_px = 10, .glyph_index = 3720}, /*Unicode: U+004b (K)*/ + {.w_px = 7, .glyph_index = 3820}, /*Unicode: U+004c (L)*/ + {.w_px = 15, .glyph_index = 3900}, /*Unicode: U+004d (M)*/ + {.w_px = 12, .glyph_index = 4060}, /*Unicode: U+004e (N)*/ + {.w_px = 14, .glyph_index = 4180}, /*Unicode: U+004f (O)*/ + {.w_px = 9, .glyph_index = 4320}, /*Unicode: U+0050 (P)*/ + {.w_px = 14, .glyph_index = 4420}, /*Unicode: U+0051 (Q)*/ + {.w_px = 9, .glyph_index = 4560}, /*Unicode: U+0052 (R)*/ + {.w_px = 9, .glyph_index = 4660}, /*Unicode: U+0053 (S)*/ + {.w_px = 9, .glyph_index = 4760}, /*Unicode: U+0054 (T)*/ + {.w_px = 12, .glyph_index = 4860}, /*Unicode: U+0055 (U)*/ + {.w_px = 12, .glyph_index = 4980}, /*Unicode: U+0056 (V)*/ + {.w_px = 18, .glyph_index = 5100}, /*Unicode: U+0057 (W)*/ + {.w_px = 10, .glyph_index = 5280}, /*Unicode: U+0058 (X)*/ + {.w_px = 10, .glyph_index = 5380}, /*Unicode: U+0059 (Y)*/ + {.w_px = 10, .glyph_index = 5480}, /*Unicode: U+005a (Z)*/ + {.w_px = 5, .glyph_index = 5580}, /*Unicode: U+005b ([)*/ + {.w_px = 8, .glyph_index = 5640}, /*Unicode: U+005c (\)*/ + {.w_px = 5, .glyph_index = 5720}, /*Unicode: U+005d (])*/ + {.w_px = 9, .glyph_index = 5780}, /*Unicode: U+005e (^)*/ + {.w_px = 8, .glyph_index = 5880}, /*Unicode: U+005f (_)*/ + {.w_px = 4, .glyph_index = 5960}, /*Unicode: U+0060 (`)*/ + {.w_px = 9, .glyph_index = 6000}, /*Unicode: U+0061 (a)*/ + {.w_px = 10, .glyph_index = 6100}, /*Unicode: U+0062 (b)*/ + {.w_px = 8, .glyph_index = 6200}, /*Unicode: U+0063 (c)*/ + {.w_px = 10, .glyph_index = 6280}, /*Unicode: U+0064 (d)*/ + {.w_px = 9, .glyph_index = 6380}, /*Unicode: U+0065 (e)*/ + {.w_px = 4, .glyph_index = 6480}, /*Unicode: U+0066 (f)*/ + {.w_px = 9, .glyph_index = 6520}, /*Unicode: U+0067 (g)*/ + {.w_px = 9, .glyph_index = 6620}, /*Unicode: U+0068 (h)*/ + {.w_px = 3, .glyph_index = 6720}, /*Unicode: U+0069 (i)*/ + {.w_px = 5, .glyph_index = 6760}, /*Unicode: U+006a (j)*/ + {.w_px = 8, .glyph_index = 6820}, /*Unicode: U+006b (k)*/ + {.w_px = 4, .glyph_index = 6900}, /*Unicode: U+006c (l)*/ + {.w_px = 13, .glyph_index = 6940}, /*Unicode: U+006d (m)*/ + {.w_px = 9, .glyph_index = 7080}, /*Unicode: U+006e (n)*/ + {.w_px = 10, .glyph_index = 7180}, /*Unicode: U+006f (o)*/ + {.w_px = 10, .glyph_index = 7280}, /*Unicode: U+0070 (p)*/ + {.w_px = 10, .glyph_index = 7380}, /*Unicode: U+0071 (q)*/ + {.w_px = 5, .glyph_index = 7480}, /*Unicode: U+0072 (r)*/ + {.w_px = 8, .glyph_index = 7540}, /*Unicode: U+0073 (s)*/ + {.w_px = 5, .glyph_index = 7620}, /*Unicode: U+0074 (t)*/ + {.w_px = 9, .glyph_index = 7680}, /*Unicode: U+0075 (u)*/ + {.w_px = 8, .glyph_index = 7780}, /*Unicode: U+0076 (v)*/ + {.w_px = 14, .glyph_index = 7860}, /*Unicode: U+0077 (w)*/ + {.w_px = 8, .glyph_index = 8000}, /*Unicode: U+0078 (x)*/ + {.w_px = 8, .glyph_index = 8080}, /*Unicode: U+0079 (y)*/ + {.w_px = 7, .glyph_index = 8160}, /*Unicode: U+007a (z)*/ + {.w_px = 4, .glyph_index = 8240}, /*Unicode: U+007b ({)*/ + {.w_px = 3, .glyph_index = 8280}, /*Unicode: U+007c (|)*/ + {.w_px = 4, .glyph_index = 8320}, /*Unicode: U+007d (})*/ + {.w_px = 6, .glyph_index = 8360}, /*Unicode: U+007e (~)*/ + +#elif USE_INTERUI_20 == 8 + {.w_px = 6, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ + {.w_px = 3, .glyph_index = 120}, /*Unicode: U+0021 (!)*/ + {.w_px = 5, .glyph_index = 180}, /*Unicode: U+0022 (")*/ + {.w_px = 8, .glyph_index = 280}, /*Unicode: U+0023 (#)*/ + {.w_px = 9, .glyph_index = 440}, /*Unicode: U+0024 ($)*/ + {.w_px = 14, .glyph_index = 620}, /*Unicode: U+0025 (%)*/ + {.w_px = 12, .glyph_index = 900}, /*Unicode: U+0026 (&)*/ + {.w_px = 3, .glyph_index = 1140}, /*Unicode: U+0027 (')*/ + {.w_px = 5, .glyph_index = 1200}, /*Unicode: U+0028 (()*/ + {.w_px = 5, .glyph_index = 1300}, /*Unicode: U+0029 ())*/ + {.w_px = 7, .glyph_index = 1400}, /*Unicode: U+002a (*)*/ + {.w_px = 10, .glyph_index = 1540}, /*Unicode: U+002b (+)*/ + {.w_px = 3, .glyph_index = 1740}, /*Unicode: U+002c (,)*/ + {.w_px = 5, .glyph_index = 1800}, /*Unicode: U+002d (-)*/ + {.w_px = 3, .glyph_index = 1900}, /*Unicode: U+002e (.)*/ + {.w_px = 8, .glyph_index = 1960}, /*Unicode: U+002f (/)*/ + {.w_px = 10, .glyph_index = 2120}, /*Unicode: U+0030 (0)*/ + {.w_px = 5, .glyph_index = 2320}, /*Unicode: U+0031 (1)*/ + {.w_px = 9, .glyph_index = 2420}, /*Unicode: U+0032 (2)*/ + {.w_px = 10, .glyph_index = 2600}, /*Unicode: U+0033 (3)*/ + {.w_px = 9, .glyph_index = 2800}, /*Unicode: U+0034 (4)*/ + {.w_px = 9, .glyph_index = 2980}, /*Unicode: U+0035 (5)*/ + {.w_px = 10, .glyph_index = 3160}, /*Unicode: U+0036 (6)*/ + {.w_px = 8, .glyph_index = 3360}, /*Unicode: U+0037 (7)*/ + {.w_px = 10, .glyph_index = 3520}, /*Unicode: U+0038 (8)*/ + {.w_px = 10, .glyph_index = 3720}, /*Unicode: U+0039 (9)*/ + {.w_px = 3, .glyph_index = 3920}, /*Unicode: U+003a (:)*/ + {.w_px = 3, .glyph_index = 3980}, /*Unicode: U+003b (;)*/ + {.w_px = 12, .glyph_index = 4040}, /*Unicode: U+003c (<)*/ + {.w_px = 10, .glyph_index = 4280}, /*Unicode: U+003d (=)*/ + {.w_px = 12, .glyph_index = 4480}, /*Unicode: U+003e (>)*/ + {.w_px = 8, .glyph_index = 4720}, /*Unicode: U+003f (?)*/ + {.w_px = 14, .glyph_index = 4880}, /*Unicode: U+0040 (@)*/ + {.w_px = 12, .glyph_index = 5160}, /*Unicode: U+0041 (A)*/ + {.w_px = 10, .glyph_index = 5400}, /*Unicode: U+0042 (B)*/ + {.w_px = 11, .glyph_index = 5600}, /*Unicode: U+0043 (C)*/ + {.w_px = 12, .glyph_index = 5820}, /*Unicode: U+0044 (D)*/ + {.w_px = 9, .glyph_index = 6060}, /*Unicode: U+0045 (E)*/ + {.w_px = 8, .glyph_index = 6240}, /*Unicode: U+0046 (F)*/ + {.w_px = 12, .glyph_index = 6400}, /*Unicode: U+0047 (G)*/ + {.w_px = 10, .glyph_index = 6640}, /*Unicode: U+0048 (H)*/ + {.w_px = 3, .glyph_index = 6840}, /*Unicode: U+0049 (I)*/ + {.w_px = 7, .glyph_index = 6900}, /*Unicode: U+004a (J)*/ + {.w_px = 10, .glyph_index = 7040}, /*Unicode: U+004b (K)*/ + {.w_px = 7, .glyph_index = 7240}, /*Unicode: U+004c (L)*/ + {.w_px = 15, .glyph_index = 7380}, /*Unicode: U+004d (M)*/ + {.w_px = 12, .glyph_index = 7680}, /*Unicode: U+004e (N)*/ + {.w_px = 14, .glyph_index = 7920}, /*Unicode: U+004f (O)*/ + {.w_px = 9, .glyph_index = 8200}, /*Unicode: U+0050 (P)*/ + {.w_px = 14, .glyph_index = 8380}, /*Unicode: U+0051 (Q)*/ + {.w_px = 9, .glyph_index = 8660}, /*Unicode: U+0052 (R)*/ + {.w_px = 9, .glyph_index = 8840}, /*Unicode: U+0053 (S)*/ + {.w_px = 9, .glyph_index = 9020}, /*Unicode: U+0054 (T)*/ + {.w_px = 12, .glyph_index = 9200}, /*Unicode: U+0055 (U)*/ + {.w_px = 12, .glyph_index = 9440}, /*Unicode: U+0056 (V)*/ + {.w_px = 18, .glyph_index = 9680}, /*Unicode: U+0057 (W)*/ + {.w_px = 10, .glyph_index = 10040}, /*Unicode: U+0058 (X)*/ + {.w_px = 10, .glyph_index = 10240}, /*Unicode: U+0059 (Y)*/ + {.w_px = 10, .glyph_index = 10440}, /*Unicode: U+005a (Z)*/ + {.w_px = 5, .glyph_index = 10640}, /*Unicode: U+005b ([)*/ + {.w_px = 8, .glyph_index = 10740}, /*Unicode: U+005c (\)*/ + {.w_px = 5, .glyph_index = 10900}, /*Unicode: U+005d (])*/ + {.w_px = 9, .glyph_index = 11000}, /*Unicode: U+005e (^)*/ + {.w_px = 8, .glyph_index = 11180}, /*Unicode: U+005f (_)*/ + {.w_px = 4, .glyph_index = 11340}, /*Unicode: U+0060 (`)*/ + {.w_px = 9, .glyph_index = 11420}, /*Unicode: U+0061 (a)*/ + {.w_px = 10, .glyph_index = 11600}, /*Unicode: U+0062 (b)*/ + {.w_px = 8, .glyph_index = 11800}, /*Unicode: U+0063 (c)*/ + {.w_px = 10, .glyph_index = 11960}, /*Unicode: U+0064 (d)*/ + {.w_px = 9, .glyph_index = 12160}, /*Unicode: U+0065 (e)*/ + {.w_px = 4, .glyph_index = 12340}, /*Unicode: U+0066 (f)*/ + {.w_px = 9, .glyph_index = 12420}, /*Unicode: U+0067 (g)*/ + {.w_px = 9, .glyph_index = 12600}, /*Unicode: U+0068 (h)*/ + {.w_px = 3, .glyph_index = 12780}, /*Unicode: U+0069 (i)*/ + {.w_px = 5, .glyph_index = 12840}, /*Unicode: U+006a (j)*/ + {.w_px = 8, .glyph_index = 12940}, /*Unicode: U+006b (k)*/ + {.w_px = 4, .glyph_index = 13100}, /*Unicode: U+006c (l)*/ + {.w_px = 13, .glyph_index = 13180}, /*Unicode: U+006d (m)*/ + {.w_px = 9, .glyph_index = 13440}, /*Unicode: U+006e (n)*/ + {.w_px = 10, .glyph_index = 13620}, /*Unicode: U+006f (o)*/ + {.w_px = 10, .glyph_index = 13820}, /*Unicode: U+0070 (p)*/ + {.w_px = 10, .glyph_index = 14020}, /*Unicode: U+0071 (q)*/ + {.w_px = 5, .glyph_index = 14220}, /*Unicode: U+0072 (r)*/ + {.w_px = 8, .glyph_index = 14320}, /*Unicode: U+0073 (s)*/ + {.w_px = 5, .glyph_index = 14480}, /*Unicode: U+0074 (t)*/ + {.w_px = 9, .glyph_index = 14580}, /*Unicode: U+0075 (u)*/ + {.w_px = 8, .glyph_index = 14760}, /*Unicode: U+0076 (v)*/ + {.w_px = 14, .glyph_index = 14920}, /*Unicode: U+0077 (w)*/ + {.w_px = 8, .glyph_index = 15200}, /*Unicode: U+0078 (x)*/ + {.w_px = 8, .glyph_index = 15360}, /*Unicode: U+0079 (y)*/ + {.w_px = 7, .glyph_index = 15520}, /*Unicode: U+007a (z)*/ + {.w_px = 4, .glyph_index = 15660}, /*Unicode: U+007b ({)*/ + {.w_px = 3, .glyph_index = 15740}, /*Unicode: U+007c (|)*/ + {.w_px = 4, .glyph_index = 15800}, /*Unicode: U+007d (})*/ + {.w_px = 6, .glyph_index = 15880}, /*Unicode: U+007e (~)*/ + +#endif +}; + +lv_font_t interui_20 = +{ + .unicode_first = 32, /*First Unicode letter in this font*/ + .unicode_last = 126, /*Last Unicode letter in this font*/ + .h_px = 20, /*Font height in pixels*/ + //.glyph_bitmap = interui_20_glyph_bitmap, /*Bitmap of glyphs*/ + .glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x3A00), + .glyph_dsc = interui_20_glyph_dsc, /*Description of glyphs*/ + .glyph_cnt = 95, /*Number of glyphs in the font*/ + .unicode_list = NULL, /*Every character in the font from 'unicode_first' to 'unicode_last'*/ + .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ + .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ +#if USE_INTERUI_20 == 4 + .bpp = 4, /*Bit per pixel*/ +#elif USE_INTERUI_20 == 8 + .bpp = 8, /*Bit per pixel*/ +#endif + .monospace = 0, /*Fix width (0: if not used)*/ + .next_page = NULL, /*Pointer to a font extension*/ +}; + +#endif /*USE_INTERUI_20*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/interui_30.c b/nyx/nyx_gui/libs/lvgl/lv_fonts/interui_30.c new file mode 100644 index 0000000..111e078 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/interui_30.c @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../lv_misc/lv_font.h" + +#if USE_INTERUI_30 != 0 /*Can be enabled in lv_conf.h*/ + +/*********************************************************************************** + * Inter-UI-Regular-stretched.ttf 30 px Font in U+0020 ( ) .. U+007e (~) range with all bpp +***********************************************************************************/ + +/*Store the glyph descriptions*/ +static const lv_font_glyph_dsc_t interui_30_glyph_dsc[] = +{ +#if USE_INTERUI_30 == 4 + {.w_px = 8, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ + {.w_px = 3, .glyph_index = 120}, /*Unicode: U+0021 (!)*/ + {.w_px = 6, .glyph_index = 180}, /*Unicode: U+0022 (")*/ + {.w_px = 13, .glyph_index = 270}, /*Unicode: U+0023 (#)*/ + {.w_px = 12, .glyph_index = 480}, /*Unicode: U+0024 ($)*/ + {.w_px = 18, .glyph_index = 660}, /*Unicode: U+0025 (%)*/ + {.w_px = 16, .glyph_index = 930}, /*Unicode: U+0026 (&)*/ + {.w_px = 3, .glyph_index = 1170}, /*Unicode: U+0027 (')*/ + {.w_px = 6, .glyph_index = 1230}, /*Unicode: U+0028 (()*/ + {.w_px = 7, .glyph_index = 1320}, /*Unicode: U+0029 ())*/ + {.w_px = 9, .glyph_index = 1440}, /*Unicode: U+002a (*)*/ + {.w_px = 16, .glyph_index = 1590}, /*Unicode: U+002b (+)*/ + {.w_px = 3, .glyph_index = 1830}, /*Unicode: U+002c (,)*/ + {.w_px = 8, .glyph_index = 1890}, /*Unicode: U+002d (-)*/ + {.w_px = 3, .glyph_index = 2010}, /*Unicode: U+002e (.)*/ + {.w_px = 11, .glyph_index = 2070}, /*Unicode: U+002f (/)*/ + {.w_px = 13, .glyph_index = 2250}, /*Unicode: U+0030 (0)*/ + {.w_px = 7, .glyph_index = 2460}, /*Unicode: U+0031 (1)*/ + {.w_px = 13, .glyph_index = 2580}, /*Unicode: U+0032 (2)*/ + {.w_px = 14, .glyph_index = 2790}, /*Unicode: U+0033 (3)*/ + {.w_px = 13, .glyph_index = 3000}, /*Unicode: U+0034 (4)*/ + {.w_px = 14, .glyph_index = 3210}, /*Unicode: U+0035 (5)*/ + {.w_px = 13, .glyph_index = 3420}, /*Unicode: U+0036 (6)*/ + {.w_px = 13, .glyph_index = 3630}, /*Unicode: U+0037 (7)*/ + {.w_px = 13, .glyph_index = 3840}, /*Unicode: U+0038 (8)*/ + {.w_px = 13, .glyph_index = 4050}, /*Unicode: U+0039 (9)*/ + {.w_px = 3, .glyph_index = 4260}, /*Unicode: U+003a (:)*/ + {.w_px = 3, .glyph_index = 4320}, /*Unicode: U+003b (;)*/ + {.w_px = 18, .glyph_index = 4380}, /*Unicode: U+003c (<)*/ + {.w_px = 16, .glyph_index = 4650}, /*Unicode: U+003d (=)*/ + {.w_px = 18, .glyph_index = 4890}, /*Unicode: U+003e (>)*/ + {.w_px = 12, .glyph_index = 5160}, /*Unicode: U+003f (?)*/ + {.w_px = 18, .glyph_index = 5340}, /*Unicode: U+0040 (@)*/ + {.w_px = 17, .glyph_index = 5610}, /*Unicode: U+0041 (A)*/ + {.w_px = 13, .glyph_index = 5880}, /*Unicode: U+0042 (B)*/ + {.w_px = 15, .glyph_index = 6090}, /*Unicode: U+0043 (C)*/ + {.w_px = 17, .glyph_index = 6330}, /*Unicode: U+0044 (D)*/ + {.w_px = 12, .glyph_index = 6600}, /*Unicode: U+0045 (E)*/ + {.w_px = 11, .glyph_index = 6780}, /*Unicode: U+0046 (F)*/ + {.w_px = 17, .glyph_index = 6960}, /*Unicode: U+0047 (G)*/ + {.w_px = 14, .glyph_index = 7230}, /*Unicode: U+0048 (H)*/ + {.w_px = 3, .glyph_index = 7440}, /*Unicode: U+0049 (I)*/ + {.w_px = 11, .glyph_index = 7500}, /*Unicode: U+004a (J)*/ + {.w_px = 14, .glyph_index = 7680}, /*Unicode: U+004b (K)*/ + {.w_px = 9, .glyph_index = 7890}, /*Unicode: U+004c (L)*/ + {.w_px = 23, .glyph_index = 8040}, /*Unicode: U+004d (M)*/ + {.w_px = 16, .glyph_index = 8400}, /*Unicode: U+004e (N)*/ + {.w_px = 19, .glyph_index = 8640}, /*Unicode: U+004f (O)*/ + {.w_px = 11, .glyph_index = 8940}, /*Unicode: U+0050 (P)*/ + {.w_px = 19, .glyph_index = 9120}, /*Unicode: U+0051 (Q)*/ + {.w_px = 13, .glyph_index = 9420}, /*Unicode: U+0052 (R)*/ + {.w_px = 12, .glyph_index = 9630}, /*Unicode: U+0053 (S)*/ + {.w_px = 14, .glyph_index = 9810}, /*Unicode: U+0054 (T)*/ + {.w_px = 16, .glyph_index = 10020}, /*Unicode: U+0055 (U)*/ + {.w_px = 18, .glyph_index = 10260}, /*Unicode: U+0056 (V)*/ + {.w_px = 27, .glyph_index = 10530}, /*Unicode: U+0057 (W)*/ + {.w_px = 15, .glyph_index = 10950}, /*Unicode: U+0058 (X)*/ + {.w_px = 15, .glyph_index = 11190}, /*Unicode: U+0059 (Y)*/ + {.w_px = 15, .glyph_index = 11430}, /*Unicode: U+005a (Z)*/ + {.w_px = 6, .glyph_index = 11670}, /*Unicode: U+005b ([)*/ + {.w_px = 11, .glyph_index = 11760}, /*Unicode: U+005c (\)*/ + {.w_px = 7, .glyph_index = 11940}, /*Unicode: U+005d (])*/ + {.w_px = 13, .glyph_index = 12060}, /*Unicode: U+005e (^)*/ + {.w_px = 12, .glyph_index = 12270}, /*Unicode: U+005f (_)*/ + {.w_px = 6, .glyph_index = 12450}, /*Unicode: U+0060 (`)*/ + {.w_px = 12, .glyph_index = 12540}, /*Unicode: U+0061 (a)*/ + {.w_px = 13, .glyph_index = 12720}, /*Unicode: U+0062 (b)*/ + {.w_px = 11, .glyph_index = 12930}, /*Unicode: U+0063 (c)*/ + {.w_px = 13, .glyph_index = 13110}, /*Unicode: U+0064 (d)*/ + {.w_px = 12, .glyph_index = 13320}, /*Unicode: U+0065 (e)*/ + {.w_px = 6, .glyph_index = 13500}, /*Unicode: U+0066 (f)*/ + {.w_px = 12, .glyph_index = 13590}, /*Unicode: U+0067 (g)*/ + {.w_px = 11, .glyph_index = 13770}, /*Unicode: U+0068 (h)*/ + {.w_px = 3, .glyph_index = 13950}, /*Unicode: U+0069 (i)*/ + {.w_px = 7, .glyph_index = 14010}, /*Unicode: U+006a (j)*/ + {.w_px = 12, .glyph_index = 14130}, /*Unicode: U+006b (k)*/ + {.w_px = 4, .glyph_index = 14310}, /*Unicode: U+006c (l)*/ + {.w_px = 19, .glyph_index = 14370}, /*Unicode: U+006d (m)*/ + {.w_px = 11, .glyph_index = 14670}, /*Unicode: U+006e (n)*/ + {.w_px = 14, .glyph_index = 14850}, /*Unicode: U+006f (o)*/ + {.w_px = 13, .glyph_index = 15060}, /*Unicode: U+0070 (p)*/ + {.w_px = 13, .glyph_index = 15270}, /*Unicode: U+0071 (q)*/ + {.w_px = 7, .glyph_index = 15480}, /*Unicode: U+0072 (r)*/ + {.w_px = 11, .glyph_index = 15600}, /*Unicode: U+0073 (s)*/ + {.w_px = 8, .glyph_index = 15780}, /*Unicode: U+0074 (t)*/ + {.w_px = 11, .glyph_index = 15900}, /*Unicode: U+0075 (u)*/ + {.w_px = 12, .glyph_index = 16080}, /*Unicode: U+0076 (v)*/ + {.w_px = 21, .glyph_index = 16260}, /*Unicode: U+0077 (w)*/ + {.w_px = 13, .glyph_index = 16590}, /*Unicode: U+0078 (x)*/ + {.w_px = 13, .glyph_index = 16800}, /*Unicode: U+0079 (y)*/ + {.w_px = 10, .glyph_index = 17010}, /*Unicode: U+007a (z)*/ + {.w_px = 6, .glyph_index = 17160}, /*Unicode: U+007b ({)*/ + {.w_px = 3, .glyph_index = 17250}, /*Unicode: U+007c (|)*/ + {.w_px = 5, .glyph_index = 17310}, /*Unicode: U+007d (})*/ + {.w_px = 8, .glyph_index = 17400}, /*Unicode: U+007e (~)*/ + +#elif USE_INTERUI_30 == 8 + {.w_px = 8, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ + {.w_px = 3, .glyph_index = 240}, /*Unicode: U+0021 (!)*/ + {.w_px = 6, .glyph_index = 330}, /*Unicode: U+0022 (")*/ + {.w_px = 13, .glyph_index = 510}, /*Unicode: U+0023 (#)*/ + {.w_px = 12, .glyph_index = 900}, /*Unicode: U+0024 ($)*/ + {.w_px = 18, .glyph_index = 1260}, /*Unicode: U+0025 (%)*/ + {.w_px = 16, .glyph_index = 1800}, /*Unicode: U+0026 (&)*/ + {.w_px = 3, .glyph_index = 2280}, /*Unicode: U+0027 (')*/ + {.w_px = 6, .glyph_index = 2370}, /*Unicode: U+0028 (()*/ + {.w_px = 7, .glyph_index = 2550}, /*Unicode: U+0029 ())*/ + {.w_px = 9, .glyph_index = 2760}, /*Unicode: U+002a (*)*/ + {.w_px = 16, .glyph_index = 3030}, /*Unicode: U+002b (+)*/ + {.w_px = 3, .glyph_index = 3510}, /*Unicode: U+002c (,)*/ + {.w_px = 8, .glyph_index = 3600}, /*Unicode: U+002d (-)*/ + {.w_px = 3, .glyph_index = 3840}, /*Unicode: U+002e (.)*/ + {.w_px = 11, .glyph_index = 3930}, /*Unicode: U+002f (/)*/ + {.w_px = 13, .glyph_index = 4260}, /*Unicode: U+0030 (0)*/ + {.w_px = 7, .glyph_index = 4650}, /*Unicode: U+0031 (1)*/ + {.w_px = 13, .glyph_index = 4860}, /*Unicode: U+0032 (2)*/ + {.w_px = 14, .glyph_index = 5250}, /*Unicode: U+0033 (3)*/ + {.w_px = 13, .glyph_index = 5670}, /*Unicode: U+0034 (4)*/ + {.w_px = 14, .glyph_index = 6060}, /*Unicode: U+0035 (5)*/ + {.w_px = 13, .glyph_index = 6480}, /*Unicode: U+0036 (6)*/ + {.w_px = 13, .glyph_index = 6870}, /*Unicode: U+0037 (7)*/ + {.w_px = 13, .glyph_index = 7260}, /*Unicode: U+0038 (8)*/ + {.w_px = 13, .glyph_index = 7650}, /*Unicode: U+0039 (9)*/ + {.w_px = 3, .glyph_index = 8040}, /*Unicode: U+003a (:)*/ + {.w_px = 3, .glyph_index = 8130}, /*Unicode: U+003b (;)*/ + {.w_px = 18, .glyph_index = 8220}, /*Unicode: U+003c (<)*/ + {.w_px = 16, .glyph_index = 8760}, /*Unicode: U+003d (=)*/ + {.w_px = 18, .glyph_index = 9240}, /*Unicode: U+003e (>)*/ + {.w_px = 12, .glyph_index = 9780}, /*Unicode: U+003f (?)*/ + {.w_px = 18, .glyph_index = 10140}, /*Unicode: U+0040 (@)*/ + {.w_px = 17, .glyph_index = 10680}, /*Unicode: U+0041 (A)*/ + {.w_px = 13, .glyph_index = 11190}, /*Unicode: U+0042 (B)*/ + {.w_px = 15, .glyph_index = 11580}, /*Unicode: U+0043 (C)*/ + {.w_px = 17, .glyph_index = 12030}, /*Unicode: U+0044 (D)*/ + {.w_px = 12, .glyph_index = 12540}, /*Unicode: U+0045 (E)*/ + {.w_px = 11, .glyph_index = 12900}, /*Unicode: U+0046 (F)*/ + {.w_px = 17, .glyph_index = 13230}, /*Unicode: U+0047 (G)*/ + {.w_px = 14, .glyph_index = 13740}, /*Unicode: U+0048 (H)*/ + {.w_px = 3, .glyph_index = 14160}, /*Unicode: U+0049 (I)*/ + {.w_px = 11, .glyph_index = 14250}, /*Unicode: U+004a (J)*/ + {.w_px = 14, .glyph_index = 14580}, /*Unicode: U+004b (K)*/ + {.w_px = 9, .glyph_index = 15000}, /*Unicode: U+004c (L)*/ + {.w_px = 23, .glyph_index = 15270}, /*Unicode: U+004d (M)*/ + {.w_px = 16, .glyph_index = 15960}, /*Unicode: U+004e (N)*/ + {.w_px = 19, .glyph_index = 16440}, /*Unicode: U+004f (O)*/ + {.w_px = 11, .glyph_index = 17010}, /*Unicode: U+0050 (P)*/ + {.w_px = 19, .glyph_index = 17340}, /*Unicode: U+0051 (Q)*/ + {.w_px = 13, .glyph_index = 17910}, /*Unicode: U+0052 (R)*/ + {.w_px = 12, .glyph_index = 18300}, /*Unicode: U+0053 (S)*/ + {.w_px = 14, .glyph_index = 18660}, /*Unicode: U+0054 (T)*/ + {.w_px = 16, .glyph_index = 19080}, /*Unicode: U+0055 (U)*/ + {.w_px = 18, .glyph_index = 19560}, /*Unicode: U+0056 (V)*/ + {.w_px = 27, .glyph_index = 20100}, /*Unicode: U+0057 (W)*/ + {.w_px = 15, .glyph_index = 20910}, /*Unicode: U+0058 (X)*/ + {.w_px = 15, .glyph_index = 21360}, /*Unicode: U+0059 (Y)*/ + {.w_px = 15, .glyph_index = 21810}, /*Unicode: U+005a (Z)*/ + {.w_px = 6, .glyph_index = 22260}, /*Unicode: U+005b ([)*/ + {.w_px = 11, .glyph_index = 22440}, /*Unicode: U+005c (\)*/ + {.w_px = 7, .glyph_index = 22770}, /*Unicode: U+005d (])*/ + {.w_px = 13, .glyph_index = 22980}, /*Unicode: U+005e (^)*/ + {.w_px = 12, .glyph_index = 23370}, /*Unicode: U+005f (_)*/ + {.w_px = 6, .glyph_index = 23730}, /*Unicode: U+0060 (`)*/ + {.w_px = 12, .glyph_index = 23910}, /*Unicode: U+0061 (a)*/ + {.w_px = 13, .glyph_index = 24270}, /*Unicode: U+0062 (b)*/ + {.w_px = 11, .glyph_index = 24660}, /*Unicode: U+0063 (c)*/ + {.w_px = 13, .glyph_index = 24990}, /*Unicode: U+0064 (d)*/ + {.w_px = 12, .glyph_index = 25380}, /*Unicode: U+0065 (e)*/ + {.w_px = 6, .glyph_index = 25740}, /*Unicode: U+0066 (f)*/ + {.w_px = 12, .glyph_index = 25920}, /*Unicode: U+0067 (g)*/ + {.w_px = 11, .glyph_index = 26280}, /*Unicode: U+0068 (h)*/ + {.w_px = 3, .glyph_index = 26610}, /*Unicode: U+0069 (i)*/ + {.w_px = 7, .glyph_index = 26700}, /*Unicode: U+006a (j)*/ + {.w_px = 12, .glyph_index = 26910}, /*Unicode: U+006b (k)*/ + {.w_px = 4, .glyph_index = 27270}, /*Unicode: U+006c (l)*/ + {.w_px = 19, .glyph_index = 27390}, /*Unicode: U+006d (m)*/ + {.w_px = 11, .glyph_index = 27960}, /*Unicode: U+006e (n)*/ + {.w_px = 14, .glyph_index = 28290}, /*Unicode: U+006f (o)*/ + {.w_px = 13, .glyph_index = 28710}, /*Unicode: U+0070 (p)*/ + {.w_px = 13, .glyph_index = 29100}, /*Unicode: U+0071 (q)*/ + {.w_px = 7, .glyph_index = 29490}, /*Unicode: U+0072 (r)*/ + {.w_px = 11, .glyph_index = 29700}, /*Unicode: U+0073 (s)*/ + {.w_px = 8, .glyph_index = 30030}, /*Unicode: U+0074 (t)*/ + {.w_px = 11, .glyph_index = 30270}, /*Unicode: U+0075 (u)*/ + {.w_px = 12, .glyph_index = 30600}, /*Unicode: U+0076 (v)*/ + {.w_px = 21, .glyph_index = 30960}, /*Unicode: U+0077 (w)*/ + {.w_px = 13, .glyph_index = 31590}, /*Unicode: U+0078 (x)*/ + {.w_px = 13, .glyph_index = 31980}, /*Unicode: U+0079 (y)*/ + {.w_px = 10, .glyph_index = 32370}, /*Unicode: U+007a (z)*/ + {.w_px = 6, .glyph_index = 32670}, /*Unicode: U+007b ({)*/ + {.w_px = 3, .glyph_index = 32850}, /*Unicode: U+007c (|)*/ + {.w_px = 5, .glyph_index = 32940}, /*Unicode: U+007d (})*/ + {.w_px = 8, .glyph_index = 33090}, /*Unicode: U+007e (~)*/ + +#endif +}; + +lv_font_t interui_30 = +{ + .unicode_first = 32, /*First Unicode letter in this font*/ + .unicode_last = 126, /*Last Unicode letter in this font*/ + .h_px = 30, /*Font height in pixels*/ + //.glyph_bitmap = interui_30_glyph_bitmap, /*Bitmap of glyphs*/ + .glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x7900), + .glyph_dsc = interui_30_glyph_dsc, /*Description of glyphs*/ + .glyph_cnt = 95, /*Number of glyphs in the font*/ + .unicode_list = NULL, /*Every character in the font from 'unicode_first' to 'unicode_last'*/ + .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ + .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ +#if USE_INTERUI_30 == 4 + .bpp = 4, /*Bit per pixel*/ +#elif USE_INTERUI_30 == 8 + .bpp = 8, /*Bit per pixel*/ +#endif + .monospace = 0, /*Fix width (0: if not used)*/ + .next_page = NULL, /*Pointer to a font extension*/ +}; + +#endif /*USE_INTERUI_30*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_font_builtin.c b/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_font_builtin.c new file mode 100644 index 0000000..16cbaea --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_font_builtin.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_font_built_in.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_font_builtin.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the built-in fonts + */ +void lv_font_builtin_init(void) +{ + /*InterUI 20*/ +#if USE_INTERUI_20 != 0 + lv_font_add(&interui_20, NULL); +#endif + + /*SYMBOL 20*/ +#if USE_HEKATE_SYMBOL_20 != 0 +#if USE_INTERUI_20 != 0 + lv_font_add(&hekate_symbol_20, &interui_20); +#else + lv_font_add(&hekate_symbol_20, NULL); +#endif +#endif + + /*InterUI 30*/ +#if USE_INTERUI_30 != 0 + lv_font_add(&interui_30, NULL); +#endif + + /*SYMBOL 30*/ +#if USE_HEKATE_SYMBOL_30 != 0 +#if USE_INTERUI_30 != 0 + lv_font_add(&hekate_symbol_30, &interui_30); +#else + lv_font_add(&hekate_symbol_30, NULL); +#endif +#endif + + /*MONO 12*/ +#if USE_UBUNTU_MONO != 0 + lv_font_add(&ubuntu_mono, NULL); +#if USE_INTERUI_20 != 0 + lv_font_add(&hekate_symbol_20, &ubuntu_mono); +#endif +#endif + + /*Symbol 120*/ +#if USE_HEKATE_SYMBOL_120 != 0 + lv_font_add(&hekate_symbol_120, NULL); +#endif +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_font_builtin.h b/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_font_builtin.h new file mode 100644 index 0000000..519471f --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_font_builtin.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_font_builtin.h + * + */ + +#ifndef LV_FONT_BUILTIN_H +#define LV_FONT_BUILTIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include "../lv_misc/lv_font.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the built-in fonts + */ +void lv_font_builtin_init(void); + +/********************** + * MACROS + **********************/ + +/********************** + * FONT DECLARATIONS + **********************/ + +/*20 px */ +#if USE_INTERUI_20 +LV_FONT_DECLARE(interui_20); +#endif + +#if USE_HEKATE_SYMBOL_20 +LV_FONT_DECLARE(hekate_symbol_20); +#endif + +/*30 px */ +#if USE_INTERUI_30 +LV_FONT_DECLARE(interui_30); +#endif + +#if USE_HEKATE_SYMBOL_30 +LV_FONT_DECLARE(hekate_symbol_30); +#endif + +#if USE_UBUNTU_MONO +LV_FONT_DECLARE(ubuntu_mono); +#endif + +#if USE_HEKATE_SYMBOL_120 +LV_FONT_DECLARE(hekate_symbol_120); +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_FONT_BUILTIN_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_fonts.mk b/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_fonts.mk new file mode 100644 index 0000000..d288f8a --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/lv_fonts.mk @@ -0,0 +1,14 @@ +CSRCS += lv_font_builtin.c +CSRCS += hekate_symbol_10.c +CSRCS += hekate_symbol_20.c +CSRCS += hekate_symbol_30.c +CSRCS += hekate_symbol_40.c +CSRCS += interui_12.c +CSRCS += interui_20.c +CSRCS += interui_30.c +CSRCS += interui_40.c + +DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_fonts +VPATH += :$(LVGL_DIR)/lvgl/lv_fonts + +CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_fonts" diff --git a/nyx/nyx_gui/libs/lvgl/lv_fonts/ubuntu_mono.c b/nyx/nyx_gui/libs/lvgl/lv_fonts/ubuntu_mono.c new file mode 100644 index 0000000..2b1c96c --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_fonts/ubuntu_mono.c @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../lv_misc/lv_font.h" + +#if USE_UBUNTU_MONO != 0 /*Can be enabled in lv_conf.h*/ + +/*********************************************************************************** + * UbuntuMono-B.ttf 20 px Font in U+0020 ( ) .. U+007e (~) range with all bpp +***********************************************************************************/ + +/*Store the glyph descriptions*/ +static const lv_font_glyph_dsc_t ubuntu_mono_glyph_dsc[] = +{ +#if USE_UBUNTU_MONO == 4 + {.w_px = 6, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ + {.w_px = 2, .glyph_index = 60}, /*Unicode: U+0021 (!)*/ + {.w_px = 5, .glyph_index = 80}, /*Unicode: U+0022 (")*/ + {.w_px = 10, .glyph_index = 140}, /*Unicode: U+0023 (#)*/ + {.w_px = 8, .glyph_index = 240}, /*Unicode: U+0024 ($)*/ + {.w_px = 10, .glyph_index = 320}, /*Unicode: U+0025 (%)*/ + {.w_px = 10, .glyph_index = 420}, /*Unicode: U+0026 (&)*/ + {.w_px = 2, .glyph_index = 520}, /*Unicode: U+0027 (')*/ + {.w_px = 6, .glyph_index = 540}, /*Unicode: U+0028 (()*/ + {.w_px = 6, .glyph_index = 600}, /*Unicode: U+0029 ())*/ + {.w_px = 9, .glyph_index = 660}, /*Unicode: U+002a (*)*/ + {.w_px = 8, .glyph_index = 760}, /*Unicode: U+002b (+)*/ + {.w_px = 4, .glyph_index = 840}, /*Unicode: U+002c (,)*/ + {.w_px = 5, .glyph_index = 880}, /*Unicode: U+002d (-)*/ + {.w_px = 4, .glyph_index = 940}, /*Unicode: U+002e (.)*/ + {.w_px = 8, .glyph_index = 980}, /*Unicode: U+002f (/)*/ + {.w_px = 8, .glyph_index = 1060}, /*Unicode: U+0030 (0)*/ + {.w_px = 7, .glyph_index = 1140}, /*Unicode: U+0031 (1)*/ + {.w_px = 8, .glyph_index = 1220}, /*Unicode: U+0032 (2)*/ + {.w_px = 8, .glyph_index = 1300}, /*Unicode: U+0033 (3)*/ + {.w_px = 8, .glyph_index = 1380}, /*Unicode: U+0034 (4)*/ + {.w_px = 8, .glyph_index = 1460}, /*Unicode: U+0035 (5)*/ + {.w_px = 8, .glyph_index = 1540}, /*Unicode: U+0036 (6)*/ + {.w_px = 7, .glyph_index = 1620}, /*Unicode: U+0037 (7)*/ + {.w_px = 8, .glyph_index = 1700}, /*Unicode: U+0038 (8)*/ + {.w_px = 8, .glyph_index = 1780}, /*Unicode: U+0039 (9)*/ + {.w_px = 4, .glyph_index = 1860}, /*Unicode: U+003a (:)*/ + {.w_px = 4, .glyph_index = 1900}, /*Unicode: U+003b (;)*/ + {.w_px = 9, .glyph_index = 1940}, /*Unicode: U+003c (<)*/ + {.w_px = 8, .glyph_index = 2040}, /*Unicode: U+003d (=)*/ + {.w_px = 8, .glyph_index = 2120}, /*Unicode: U+003e (>)*/ + {.w_px = 8, .glyph_index = 2200}, /*Unicode: U+003f (?)*/ + {.w_px = 9, .glyph_index = 2280}, /*Unicode: U+0040 (@)*/ + {.w_px = 10, .glyph_index = 2380}, /*Unicode: U+0041 (A)*/ + {.w_px = 8, .glyph_index = 2480}, /*Unicode: U+0042 (B)*/ + {.w_px = 8, .glyph_index = 2560}, /*Unicode: U+0043 (C)*/ + {.w_px = 8, .glyph_index = 2640}, /*Unicode: U+0044 (D)*/ + {.w_px = 8, .glyph_index = 2720}, /*Unicode: U+0045 (E)*/ + {.w_px = 8, .glyph_index = 2800}, /*Unicode: U+0046 (F)*/ + {.w_px = 8, .glyph_index = 2880}, /*Unicode: U+0047 (G)*/ + {.w_px = 8, .glyph_index = 2960}, /*Unicode: U+0048 (H)*/ + {.w_px = 8, .glyph_index = 3040}, /*Unicode: U+0049 (I)*/ + {.w_px = 8, .glyph_index = 3120}, /*Unicode: U+004a (J)*/ + {.w_px = 9, .glyph_index = 3200}, /*Unicode: U+004b (K)*/ + {.w_px = 8, .glyph_index = 3300}, /*Unicode: U+004c (L)*/ + {.w_px = 9, .glyph_index = 3380}, /*Unicode: U+004d (M)*/ + {.w_px = 8, .glyph_index = 3480}, /*Unicode: U+004e (N)*/ + {.w_px = 8, .glyph_index = 3560}, /*Unicode: U+004f (O)*/ + {.w_px = 8, .glyph_index = 3640}, /*Unicode: U+0050 (P)*/ + {.w_px = 8, .glyph_index = 3720}, /*Unicode: U+0051 (Q)*/ + {.w_px = 8, .glyph_index = 3800}, /*Unicode: U+0052 (R)*/ + {.w_px = 8, .glyph_index = 3880}, /*Unicode: U+0053 (S)*/ + {.w_px = 8, .glyph_index = 3960}, /*Unicode: U+0054 (T)*/ + {.w_px = 8, .glyph_index = 4040}, /*Unicode: U+0055 (U)*/ + {.w_px = 9, .glyph_index = 4120}, /*Unicode: U+0056 (V)*/ + {.w_px = 9, .glyph_index = 4220}, /*Unicode: U+0057 (W)*/ + {.w_px = 10, .glyph_index = 4320}, /*Unicode: U+0058 (X)*/ + {.w_px = 10, .glyph_index = 4420}, /*Unicode: U+0059 (Y)*/ + {.w_px = 8, .glyph_index = 4520}, /*Unicode: U+005a (Z)*/ + {.w_px = 6, .glyph_index = 4600}, /*Unicode: U+005b ([)*/ + {.w_px = 8, .glyph_index = 4660}, /*Unicode: U+005c (\)*/ + {.w_px = 6, .glyph_index = 4740}, /*Unicode: U+005d (])*/ + {.w_px = 10, .glyph_index = 4800}, /*Unicode: U+005e (^)*/ + {.w_px = 10, .glyph_index = 4900}, /*Unicode: U+005f (_)*/ + {.w_px = 4, .glyph_index = 5000}, /*Unicode: U+0060 (`)*/ + {.w_px = 8, .glyph_index = 5040}, /*Unicode: U+0061 (a)*/ + {.w_px = 8, .glyph_index = 5120}, /*Unicode: U+0062 (b)*/ + {.w_px = 8, .glyph_index = 5200}, /*Unicode: U+0063 (c)*/ + {.w_px = 8, .glyph_index = 5280}, /*Unicode: U+0064 (d)*/ + {.w_px = 9, .glyph_index = 5360}, /*Unicode: U+0065 (e)*/ + {.w_px = 9, .glyph_index = 5460}, /*Unicode: U+0066 (f)*/ + {.w_px = 8, .glyph_index = 5560}, /*Unicode: U+0067 (g)*/ + {.w_px = 8, .glyph_index = 5640}, /*Unicode: U+0068 (h)*/ + {.w_px = 9, .glyph_index = 5720}, /*Unicode: U+0069 (i)*/ + {.w_px = 7, .glyph_index = 5820}, /*Unicode: U+006a (j)*/ + {.w_px = 9, .glyph_index = 5900}, /*Unicode: U+006b (k)*/ + {.w_px = 8, .glyph_index = 6000}, /*Unicode: U+006c (l)*/ + {.w_px = 8, .glyph_index = 6080}, /*Unicode: U+006d (m)*/ + {.w_px = 8, .glyph_index = 6160}, /*Unicode: U+006e (n)*/ + {.w_px = 8, .glyph_index = 6240}, /*Unicode: U+006f (o)*/ + {.w_px = 8, .glyph_index = 6320}, /*Unicode: U+0070 (p)*/ + {.w_px = 8, .glyph_index = 6400}, /*Unicode: U+0071 (q)*/ + {.w_px = 7, .glyph_index = 6480}, /*Unicode: U+0072 (r)*/ + {.w_px = 8, .glyph_index = 6560}, /*Unicode: U+0073 (s)*/ + {.w_px = 8, .glyph_index = 6640}, /*Unicode: U+0074 (t)*/ + {.w_px = 8, .glyph_index = 6720}, /*Unicode: U+0075 (u)*/ + {.w_px = 9, .glyph_index = 6800}, /*Unicode: U+0076 (v)*/ + {.w_px = 10, .glyph_index = 6900}, /*Unicode: U+0077 (w)*/ + {.w_px = 10, .glyph_index = 7000}, /*Unicode: U+0078 (x)*/ + {.w_px = 9, .glyph_index = 7100}, /*Unicode: U+0079 (y)*/ + {.w_px = 8, .glyph_index = 7200}, /*Unicode: U+007a (z)*/ + {.w_px = 7, .glyph_index = 7280}, /*Unicode: U+007b ({)*/ + {.w_px = 2, .glyph_index = 7360}, /*Unicode: U+007c (|)*/ + {.w_px = 8, .glyph_index = 7380}, /*Unicode: U+007d (})*/ + {.w_px = 9, .glyph_index = 7460}, /*Unicode: U+007e (~)*/ + +#elif USE_UBUNTU_MONO == 8 + {.w_px = 6, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ + {.w_px = 2, .glyph_index = 120}, /*Unicode: U+0021 (!)*/ + {.w_px = 5, .glyph_index = 160}, /*Unicode: U+0022 (")*/ + {.w_px = 10, .glyph_index = 260}, /*Unicode: U+0023 (#)*/ + {.w_px = 8, .glyph_index = 460}, /*Unicode: U+0024 ($)*/ + {.w_px = 10, .glyph_index = 620}, /*Unicode: U+0025 (%)*/ + {.w_px = 10, .glyph_index = 820}, /*Unicode: U+0026 (&)*/ + {.w_px = 2, .glyph_index = 1020}, /*Unicode: U+0027 (')*/ + {.w_px = 6, .glyph_index = 1060}, /*Unicode: U+0028 (()*/ + {.w_px = 6, .glyph_index = 1180}, /*Unicode: U+0029 ())*/ + {.w_px = 9, .glyph_index = 1300}, /*Unicode: U+002a (*)*/ + {.w_px = 8, .glyph_index = 1480}, /*Unicode: U+002b (+)*/ + {.w_px = 4, .glyph_index = 1640}, /*Unicode: U+002c (,)*/ + {.w_px = 5, .glyph_index = 1720}, /*Unicode: U+002d (-)*/ + {.w_px = 4, .glyph_index = 1820}, /*Unicode: U+002e (.)*/ + {.w_px = 8, .glyph_index = 1900}, /*Unicode: U+002f (/)*/ + {.w_px = 8, .glyph_index = 2060}, /*Unicode: U+0030 (0)*/ + {.w_px = 7, .glyph_index = 2220}, /*Unicode: U+0031 (1)*/ + {.w_px = 8, .glyph_index = 2360}, /*Unicode: U+0032 (2)*/ + {.w_px = 8, .glyph_index = 2520}, /*Unicode: U+0033 (3)*/ + {.w_px = 8, .glyph_index = 2680}, /*Unicode: U+0034 (4)*/ + {.w_px = 8, .glyph_index = 2840}, /*Unicode: U+0035 (5)*/ + {.w_px = 8, .glyph_index = 3000}, /*Unicode: U+0036 (6)*/ + {.w_px = 7, .glyph_index = 3160}, /*Unicode: U+0037 (7)*/ + {.w_px = 8, .glyph_index = 3300}, /*Unicode: U+0038 (8)*/ + {.w_px = 8, .glyph_index = 3460}, /*Unicode: U+0039 (9)*/ + {.w_px = 4, .glyph_index = 3620}, /*Unicode: U+003a (:)*/ + {.w_px = 4, .glyph_index = 3700}, /*Unicode: U+003b (;)*/ + {.w_px = 9, .glyph_index = 3780}, /*Unicode: U+003c (<)*/ + {.w_px = 8, .glyph_index = 3960}, /*Unicode: U+003d (=)*/ + {.w_px = 8, .glyph_index = 4120}, /*Unicode: U+003e (>)*/ + {.w_px = 8, .glyph_index = 4280}, /*Unicode: U+003f (?)*/ + {.w_px = 9, .glyph_index = 4440}, /*Unicode: U+0040 (@)*/ + {.w_px = 10, .glyph_index = 4620}, /*Unicode: U+0041 (A)*/ + {.w_px = 8, .glyph_index = 4820}, /*Unicode: U+0042 (B)*/ + {.w_px = 8, .glyph_index = 4980}, /*Unicode: U+0043 (C)*/ + {.w_px = 8, .glyph_index = 5140}, /*Unicode: U+0044 (D)*/ + {.w_px = 8, .glyph_index = 5300}, /*Unicode: U+0045 (E)*/ + {.w_px = 8, .glyph_index = 5460}, /*Unicode: U+0046 (F)*/ + {.w_px = 8, .glyph_index = 5620}, /*Unicode: U+0047 (G)*/ + {.w_px = 8, .glyph_index = 5780}, /*Unicode: U+0048 (H)*/ + {.w_px = 8, .glyph_index = 5940}, /*Unicode: U+0049 (I)*/ + {.w_px = 8, .glyph_index = 6100}, /*Unicode: U+004a (J)*/ + {.w_px = 9, .glyph_index = 6260}, /*Unicode: U+004b (K)*/ + {.w_px = 8, .glyph_index = 6440}, /*Unicode: U+004c (L)*/ + {.w_px = 9, .glyph_index = 6600}, /*Unicode: U+004d (M)*/ + {.w_px = 8, .glyph_index = 6780}, /*Unicode: U+004e (N)*/ + {.w_px = 8, .glyph_index = 6940}, /*Unicode: U+004f (O)*/ + {.w_px = 8, .glyph_index = 7100}, /*Unicode: U+0050 (P)*/ + {.w_px = 8, .glyph_index = 7260}, /*Unicode: U+0051 (Q)*/ + {.w_px = 8, .glyph_index = 7420}, /*Unicode: U+0052 (R)*/ + {.w_px = 8, .glyph_index = 7580}, /*Unicode: U+0053 (S)*/ + {.w_px = 8, .glyph_index = 7740}, /*Unicode: U+0054 (T)*/ + {.w_px = 8, .glyph_index = 7900}, /*Unicode: U+0055 (U)*/ + {.w_px = 9, .glyph_index = 8060}, /*Unicode: U+0056 (V)*/ + {.w_px = 9, .glyph_index = 8240}, /*Unicode: U+0057 (W)*/ + {.w_px = 10, .glyph_index = 8420}, /*Unicode: U+0058 (X)*/ + {.w_px = 10, .glyph_index = 8620}, /*Unicode: U+0059 (Y)*/ + {.w_px = 8, .glyph_index = 8820}, /*Unicode: U+005a (Z)*/ + {.w_px = 6, .glyph_index = 8980}, /*Unicode: U+005b ([)*/ + {.w_px = 8, .glyph_index = 9100}, /*Unicode: U+005c (\)*/ + {.w_px = 6, .glyph_index = 9260}, /*Unicode: U+005d (])*/ + {.w_px = 10, .glyph_index = 9380}, /*Unicode: U+005e (^)*/ + {.w_px = 10, .glyph_index = 9580}, /*Unicode: U+005f (_)*/ + {.w_px = 4, .glyph_index = 9780}, /*Unicode: U+0060 (`)*/ + {.w_px = 8, .glyph_index = 9860}, /*Unicode: U+0061 (a)*/ + {.w_px = 8, .glyph_index = 10020}, /*Unicode: U+0062 (b)*/ + {.w_px = 8, .glyph_index = 10180}, /*Unicode: U+0063 (c)*/ + {.w_px = 8, .glyph_index = 10340}, /*Unicode: U+0064 (d)*/ + {.w_px = 9, .glyph_index = 10500}, /*Unicode: U+0065 (e)*/ + {.w_px = 9, .glyph_index = 10680}, /*Unicode: U+0066 (f)*/ + {.w_px = 8, .glyph_index = 10860}, /*Unicode: U+0067 (g)*/ + {.w_px = 8, .glyph_index = 11020}, /*Unicode: U+0068 (h)*/ + {.w_px = 9, .glyph_index = 11180}, /*Unicode: U+0069 (i)*/ + {.w_px = 7, .glyph_index = 11360}, /*Unicode: U+006a (j)*/ + {.w_px = 9, .glyph_index = 11500}, /*Unicode: U+006b (k)*/ + {.w_px = 8, .glyph_index = 11680}, /*Unicode: U+006c (l)*/ + {.w_px = 8, .glyph_index = 11840}, /*Unicode: U+006d (m)*/ + {.w_px = 8, .glyph_index = 12000}, /*Unicode: U+006e (n)*/ + {.w_px = 8, .glyph_index = 12160}, /*Unicode: U+006f (o)*/ + {.w_px = 8, .glyph_index = 12320}, /*Unicode: U+0070 (p)*/ + {.w_px = 8, .glyph_index = 12480}, /*Unicode: U+0071 (q)*/ + {.w_px = 7, .glyph_index = 12640}, /*Unicode: U+0072 (r)*/ + {.w_px = 8, .glyph_index = 12780}, /*Unicode: U+0073 (s)*/ + {.w_px = 8, .glyph_index = 12940}, /*Unicode: U+0074 (t)*/ + {.w_px = 8, .glyph_index = 13100}, /*Unicode: U+0075 (u)*/ + {.w_px = 9, .glyph_index = 13260}, /*Unicode: U+0076 (v)*/ + {.w_px = 10, .glyph_index = 13440}, /*Unicode: U+0077 (w)*/ + {.w_px = 10, .glyph_index = 13640}, /*Unicode: U+0078 (x)*/ + {.w_px = 9, .glyph_index = 13840}, /*Unicode: U+0079 (y)*/ + {.w_px = 8, .glyph_index = 14020}, /*Unicode: U+007a (z)*/ + {.w_px = 7, .glyph_index = 14180}, /*Unicode: U+007b ({)*/ + {.w_px = 2, .glyph_index = 14320}, /*Unicode: U+007c (|)*/ + {.w_px = 8, .glyph_index = 14360}, /*Unicode: U+007d (})*/ + {.w_px = 9, .glyph_index = 14520}, /*Unicode: U+007e (~)*/ + +#endif +}; + +lv_font_t ubuntu_mono = +{ + .unicode_first = 32, /*First Unicode letter in this font*/ + .unicode_last = 126, /*Last Unicode letter in this font*/ + .h_px = 20, /*Font height in pixels*/ + //.glyph_bitmap = ubuntu_mono_glyph_bitmap, /*Bitmap of glyphs*/ + .glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR), + .glyph_dsc = ubuntu_mono_glyph_dsc, /*Description of glyphs*/ + .glyph_cnt = 95, /*Number of glyphs in the font*/ + .unicode_list = NULL, /*Every character in the font from 'unicode_first' to 'unicode_last'*/ + .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ + .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ +#if USE_UBUNTU_MONO == 4 + .bpp = 4, /*Bit per pixel*/ +#elif USE_UBUNTU_MONO == 8 + .bpp = 8, /*Bit per pixel*/ +#endif + .monospace = 10, /*Fix width (0: if not used)*/ + .next_page = NULL, /*Pointer to a font extension*/ +}; + +#endif /*USE_UBUNTU_MONO*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.h b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.h new file mode 100644 index 0000000..5ab28f2 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.h @@ -0,0 +1,40 @@ +/** + * @file hal.h + * + */ + +#ifndef HAL_H +#define HAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_hal_disp.h" +#include "lv_hal_indev.h" +#include "lv_hal_tick.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.mk b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.mk new file mode 100644 index 0000000..83f4bf1 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal.mk @@ -0,0 +1,8 @@ +CSRCS += lv_hal_disp.c +CSRCS += lv_hal_indev.c +CSRCS += lv_hal_tick.c + +DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_hal +VPATH += :$(LVGL_DIR)/lvgl/lv_hal + +CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal" diff --git a/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.c b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.c new file mode 100644 index 0000000..3be8b92 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.c @@ -0,0 +1,242 @@ + +/** + * @file hal_disp.c + * + * @description HAL layer for display driver + * + */ + +/********************* + * INCLUDES + *********************/ +#include +#include +#include "../lv_hal/lv_hal_disp.h" +#include "../lv_misc/lv_mem.h" +#include "../lv_core/lv_obj.h" +#include "../lv_misc/lv_gc.h" + +#if defined(LV_GC_INCLUDE) +# include LV_GC_INCLUDE +#endif /* LV_ENABLE_GC */ + + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static lv_disp_t * active; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize a display driver with default values. + * It is used to surly have known values in the fields ant not memory junk. + * After it you can set the fields. + * @param driver pointer to driver variable to initialize + */ +void lv_disp_drv_init(lv_disp_drv_t * driver) +{ + driver->disp_fill = NULL; + driver->disp_map = NULL; + driver->disp_flush = NULL; + +#if USE_LV_GPU + driver->mem_blend = NULL; + driver->mem_fill = NULL; +#endif + +#if LV_VDB_SIZE + driver->vdb_wr = NULL; +#endif +} + +/** + * Register an initialized display driver. + * Automatically set the first display as active. + * @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable) + * @return pointer to the new display or NULL on error + */ +lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) +{ + lv_disp_t * node; + + node = lv_mem_alloc(sizeof(lv_disp_t)); + lv_mem_assert(node); + if(node == NULL) return NULL; + + memcpy(&node->driver, driver, sizeof(lv_disp_drv_t)); + node->next = NULL; + + /* Set first display as active by default */ + if(LV_GC_ROOT(_lv_disp_list) == NULL) { + LV_GC_ROOT(_lv_disp_list) = node; + active = node; + lv_obj_invalidate(lv_scr_act()); + } else { + ((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next = node; + } + + return node; +} + + +/** + * Set the active display + * @param disp pointer to a display (return value of 'lv_disp_register') + */ +void lv_disp_set_active(lv_disp_t * disp) +{ + active = disp; + lv_obj_invalidate(lv_scr_act()); +} + +/** + * Get a pointer to the active display + * @return pointer to the active display + */ +lv_disp_t * lv_disp_get_active(void) +{ + return active; +} + +/** + * Get the next display. + * @param disp pointer to the current display. NULL to initialize. + * @return the next display or NULL if no more. Give the first display when the parameter is NULL + */ +lv_disp_t * lv_disp_next(lv_disp_t * disp) +{ + if(disp == NULL) { + return LV_GC_ROOT(_lv_disp_list); + } else { + if(((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next == NULL) return NULL; + else return ((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next; + } +} + +/** + * Write the content of the internal buffer (VDB) to the display + * @param x1 left coordinate of the rectangle + * @param x2 right coordinate of the rectangle + * @param y1 top coordinate of the rectangle + * @param y2 bottom coordinate of the rectangle + * @param color_p fill color + */ +void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color) +{ + if(active == NULL) return; + if(active->driver.disp_fill != NULL) active->driver.disp_fill(x1, y1, x2, y2, color); +} + +/** + * Fill a rectangular area with a color on the active display + * @param x1 left coordinate of the rectangle + * @param x2 right coordinate of the rectangle + * @param y1 top coordinate of the rectangle + * @param y2 bottom coordinate of the rectangle + * @param color_p pointer to an array of colors + */ +void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t * color_p) +{ + if(active == NULL) return; + if(active->driver.disp_flush != NULL) { + + LV_LOG_TRACE("disp flush started"); + active->driver.disp_flush(x1, y1, x2, y2, color_p); + LV_LOG_TRACE("disp flush ready"); + + } else { + LV_LOG_WARN("disp flush function registered"); + } +} + +/** + * Put a color map to a rectangular area on the active display + * @param x1 left coordinate of the rectangle + * @param x2 right coordinate of the rectangle + * @param y1 top coordinate of the rectangle + * @param y2 bottom coordinate of the rectangle + * @param color_map pointer to an array of colors + */ +void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map) +{ + if(active == NULL) return; + if(active->driver.disp_map != NULL) active->driver.disp_map(x1, y1, x2, y2, color_map); +} + +#if USE_LV_GPU + +/** + * Blend pixels to a destination memory from a source memory + * In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available) + * @param dest a memory address. Blend 'src' here. + * @param src pointer to pixel map. Blend it to 'dest'. + * @param length number of pixels in 'src' + * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) + */ +void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa) +{ + if(active == NULL) return; + if(active->driver.mem_blend != NULL) active->driver.mem_blend(dest, src, length, opa); +} + +/** + * Fill a memory with a color (GPUs may support it) + * In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available) + * @param dest a memory address. Copy 'src' here. + * @param src pointer to pixel map. Copy it to 'dest'. + * @param length number of pixels in 'src' + * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) + */ +void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color) +{ + if(active == NULL) return; + if(active->driver.mem_fill != NULL) active->driver.mem_fill(dest, length, color); +} + +/** + * Shows if memory blending (by GPU) is supported or not + * @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver + */ +bool lv_disp_is_mem_blend_supported(void) +{ + if(active == NULL) return false; + if(active->driver.mem_blend) return true; + else return false; +} + +/** + * Shows if memory fill (by GPU) is supported or not + * @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver + */ +bool lv_disp_is_mem_fill_supported(void) +{ + if(active == NULL) return false; + if(active->driver.mem_fill) return true; + else return false; +} + +#endif + +/********************** + * STATIC FUNCTIONS + **********************/ + diff --git a/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.h b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.h new file mode 100644 index 0000000..95b7ab5 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_disp.h @@ -0,0 +1,173 @@ +/** + * @file hal_disp.h + * + * @description Display Driver HAL interface header file + * + */ + +#ifndef HAL_DISP_H +#define HAL_DISP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_hal.h" +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Display Driver structure to be registered by HAL + */ +typedef struct _disp_drv_t { + /*Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has to be called when finished*/ + void (*disp_flush)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); + + /*Fill an area with a color on the display*/ + void (*disp_fill)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); + + /*Write pixel map (e.g. image) to the display*/ + void (*disp_map)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); + + /*Optional interface functions to use GPU*/ +#if USE_LV_GPU + /*Blend two memories using opacity (GPU only)*/ + void (*mem_blend)(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa); + + /*Fill a memory with a color (GPU only)*/ + void (*mem_fill)(lv_color_t * dest, uint32_t length, lv_color_t color); +#endif + +#if LV_VDB_SIZE + /*Optional: Set a pixel in a buffer according to the requirements of the display*/ + void (*vdb_wr)(uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa); +#endif +} lv_disp_drv_t; + +typedef struct _disp_t { + lv_disp_drv_t driver; + struct _disp_t *next; +} lv_disp_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize a display driver with default values. + * It is used to surly have known values in the fields ant not memory junk. + * After it you can set the fields. + * @param driver pointer to driver variable to initialize + */ +void lv_disp_drv_init(lv_disp_drv_t *driver); + +/** + * Register an initialized display driver. + * Automatically set the first display as active. + * @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable) + * @return pointer to the new display or NULL on error + */ +lv_disp_t * lv_disp_drv_register(lv_disp_drv_t *driver); + +/** + * Set the active display + * @param disp pointer to a display (return value of 'lv_disp_register') + */ +void lv_disp_set_active(lv_disp_t * disp); + +/** + * Get a pointer to the active display + * @return pointer to the active display + */ +lv_disp_t * lv_disp_get_active(void); + +/** + * Get the next display. + * @param disp pointer to the current display. NULL to initialize. + * @return the next display or NULL if no more. Give the first display when the parameter is NULL + */ +lv_disp_t * lv_disp_next(lv_disp_t * disp); + +/** + * Fill a rectangular area with a color on the active display + * @param x1 left coordinate of the rectangle + * @param x2 right coordinate of the rectangle + * @param y1 top coordinate of the rectangle + * @param y2 bottom coordinate of the rectangle + * @param color_p pointer to an array of colors + */ +void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p); + +/** + * Fill a rectangular area with a color on the active display + * @param x1 left coordinate of the rectangle + * @param x2 right coordinate of the rectangle + * @param y1 top coordinate of the rectangle + * @param y2 bottom coordinate of the rectangle + * @param color fill color + */ +void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); + +/** + * Put a color map to a rectangular area on the active display + * @param x1 left coordinate of the rectangle + * @param x2 right coordinate of the rectangle + * @param y1 top coordinate of the rectangle + * @param y2 bottom coordinate of the rectangle + * @param color_map pointer to an array of colors + */ +void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map); + +#if USE_LV_GPU +/** + * Blend pixels to a destination memory from a source memory + * In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available) + * @param dest a memory address. Blend 'src' here. + * @param src pointer to pixel map. Blend it to 'dest'. + * @param length number of pixels in 'src' + * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) + */ +void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa); + +/** + * Fill a memory with a color (GPUs may support it) + * In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available) + * @param dest a memory address. Copy 'src' here. + * @param src pointer to pixel map. Copy it to 'dest'. + * @param length number of pixels in 'src' + * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) + */ +void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color); +/** + * Shows if memory blending (by GPU) is supported or not + * @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver + */ +bool lv_disp_is_mem_blend_supported(void); + +/** + * Shows if memory fill (by GPU) is supported or not + * @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver + */ +bool lv_disp_is_mem_fill_supported(void); +#endif +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.c b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.c new file mode 100644 index 0000000..6083c3f --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.c @@ -0,0 +1,135 @@ +/** + * @file hal_indev.c + * + * @description Input device HAL interface + * + */ + +/********************* + * INCLUDES + *********************/ +#include "../lv_hal/lv_hal_indev.h" +#include "../lv_misc/lv_mem.h" +#include "../lv_misc/lv_gc.h" + +#if defined(LV_GC_INCLUDE) +# include LV_GC_INCLUDE +#endif /* LV_ENABLE_GC */ + + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize an input device driver with default values. + * It is used to surly have known values in the fields ant not memory junk. + * After it you can set the fields. + * @param driver pointer to driver variable to initialize + */ +void lv_indev_drv_init(lv_indev_drv_t * driver) +{ + driver->read = NULL; + driver->type = LV_INDEV_TYPE_NONE; + driver->user_data = NULL; +} + +/** + * Register an initialized input device driver. + * @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable) + * @return pointer to the new input device or NULL on error + */ +lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver) +{ + lv_indev_t * node; + + node = lv_mem_alloc(sizeof(lv_indev_t)); + if(!node) return NULL; + + memset(node, 0, sizeof(lv_indev_t)); + memcpy(&node->driver, driver, sizeof(lv_indev_drv_t)); + + node->next = NULL; + node->proc.reset_query = 1; + node->cursor = NULL; + node->group = NULL; + node->btn_points = NULL; + + if(LV_GC_ROOT(_lv_indev_list) == NULL) { + LV_GC_ROOT(_lv_indev_list) = node; + } else { + lv_indev_t * last = LV_GC_ROOT(_lv_indev_list); + while(last->next) + last = last->next; + + last->next = node; + } + + return node; +} + +/** + * Get the next input device. + * @param indev pointer to the current input device. NULL to initialize. + * @return the next input devise or NULL if no more. Give the first input device when the parameter is NULL + */ +lv_indev_t * lv_indev_next(lv_indev_t * indev) +{ + + if(indev == NULL) { + return LV_GC_ROOT(_lv_indev_list); + } else { + if(indev->next == NULL) return NULL; + else return indev->next; + } +} + +/** + * Read data from an input device. + * @param indev pointer to an input device + * @param data input device will write its data here + * @return false: no more data; true: there more data to read (buffered) + */ +bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) +{ + bool cont = false; + + memset(data, 0, sizeof(lv_indev_data_t)); + data->state = LV_INDEV_STATE_REL; + + if(indev->driver.read) { + data->user_data = indev->driver.user_data; + + LV_LOG_TRACE("idnev read started"); + cont = indev->driver.read(data); + LV_LOG_TRACE("idnev read finished"); + } else { + LV_LOG_WARN("indev function registered"); + } + + return cont; +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.h b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.h new file mode 100644 index 0000000..b9d4255 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_indev.h @@ -0,0 +1,166 @@ +/** + * @file hal_indev.h + * + * @description Input Device HAL interface layer header file + * + */ + +#ifndef HAL_INDEV_H +#define HAL_INDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_hal.h" +#include "../../../utils/types.h" +#include "../lv_misc/lv_area.h" +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Possible input device types*/ +enum { + LV_INDEV_TYPE_NONE, /*Show uninitialized state*/ + LV_INDEV_TYPE_POINTER, /*Touch pad, mouse, external button*/ + LV_INDEV_TYPE_KEYPAD, /*Keypad or keyboard*/ + LV_INDEV_TYPE_BUTTON, /*External (hardware button) which is assinged to a specific point of the screen*/ + LV_INDEV_TYPE_ENCODER, /*Encoder with only Left, Right turn and a Button*/ +}; +typedef uint8_t lv_hal_indev_type_t; + +/*States for input devices*/ +enum { + LV_INDEV_STATE_REL = 0, + LV_INDEV_STATE_PR +}; +typedef uint8_t lv_indev_state_t; + +/*Data type when an input device is read */ +typedef struct { + union { + lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/ + uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ + uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/ + int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/ + }; + void *user_data; /*'lv_indev_drv_t.priv' for this driver*/ + lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ +} lv_indev_data_t; + +/*Initialized by the user and registered by 'lv_indev_add()'*/ +typedef struct { + lv_hal_indev_type_t type; /*Input device type*/ + bool (*read)(lv_indev_data_t *data); /*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/ + void *user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/ +} lv_indev_drv_t; + +struct _lv_obj_t; + +/*Run time data of input devices*/ +typedef struct _lv_indev_proc_t { + lv_indev_state_t state; + union { + struct { /*Pointer and button data*/ + lv_point_t act_point; + lv_point_t last_point; + lv_point_t vect; + lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DRAG_LIMIT*/ + struct _lv_obj_t * act_obj; + struct _lv_obj_t * last_obj; + + /*Flags*/ + uint8_t drag_range_out :1; + uint8_t drag_in_prog :1; + uint8_t wait_unil_release :1; + }; + struct { /*Keypad data*/ + lv_indev_state_t last_state; + uint32_t last_key; + }; + }; + + uint32_t pr_timestamp; /*Pressed time stamp*/ + uint32_t longpr_rep_timestamp; /*Long press repeat time stamp*/ + + /*Flags*/ + uint8_t long_pr_sent :1; + uint8_t reset_query :1; + uint8_t disabled :1; +} lv_indev_proc_t; + +struct _lv_indev_t; + +typedef void (*lv_indev_feedback_t)(struct _lv_indev_t *, lv_signal_t); + +struct _lv_obj_t; +struct _lv_group_t; + +/*The main input device descriptor with driver, runtime data ('proc') and some additional information*/ +typedef struct _lv_indev_t { + lv_indev_drv_t driver; + lv_indev_proc_t proc; + lv_indev_feedback_t feedback; + uint32_t last_activity_time; + union { + struct _lv_obj_t *cursor; /*Cursor for LV_INPUT_TYPE_POINTER*/ + struct _lv_group_t *group; /*Keypad destination group*/ + const lv_point_t * btn_points; /*Array points assigned to the button ()screen will be pressed here by the buttons*/ + + }; + struct _lv_indev_t *next; +} lv_indev_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize an input device driver with default values. + * It is used to surly have known values in the fields ant not memory junk. + * After it you can set the fields. + * @param driver pointer to driver variable to initialize + */ +void lv_indev_drv_init(lv_indev_drv_t *driver); + +/** + * Register an initialized input device driver. + * @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable) + * @return pointer to the new input device or NULL on error + */ +lv_indev_t * lv_indev_drv_register(lv_indev_drv_t *driver); + +/** + * Get the next input device. + * @param indev pointer to the current input device. NULL to initialize. + * @return the next input devise or NULL if no more. Gives the first input device when the parameter is NULL + */ +lv_indev_t * lv_indev_next(lv_indev_t * indev); + +/** + * Read data from an input device. + * @param indev pointer to an input device + * @param data input device will write its data here + * @return false: no more data; true: there more data to read (buffered) + */ +bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t *data); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.c b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.c new file mode 100644 index 0000000..0310092 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.c @@ -0,0 +1,100 @@ +/** + * @file systick.c + * Provide access to the system tick with 1 millisecond resolution + */ + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include "lv_hal_tick.h" +#include + +#if LV_TICK_CUSTOM == 1 +#include LV_TICK_CUSTOM_INCLUDE +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static uint32_t sys_time = 0; +static volatile uint8_t tick_irq_flag; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * You have to call this function periodically + * @param tick_period the call period of this function in milliseconds + */ +LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period) +{ + tick_irq_flag = 0; + sys_time += tick_period; +} + +/** + * Get the elapsed milliseconds since start up + * @return the elapsed milliseconds + */ +uint32_t lv_tick_get(void) +{ +#if LV_TICK_CUSTOM == 0 + uint32_t result; + do { + tick_irq_flag = 1; + result = sys_time; + } while(!tick_irq_flag); /*'lv_tick_inc()' clears this flag which can be in an interrupt. Continue until make a non interrupted cycle */ + + return result; +#else + return LV_TICK_CUSTOM_SYS_TIME_EXPR; +#endif +} + +/** + * Get the elapsed milliseconds since a previous time stamp + * @param prev_tick a previous time stamp (return value of systick_get() ) + * @return the elapsed milliseconds since 'prev_tick' + */ +uint32_t lv_tick_elaps(uint32_t prev_tick) +{ + uint32_t act_time = lv_tick_get(); + + /*If there is no overflow in sys_time simple subtract*/ + if(act_time >= prev_tick) { + prev_tick = act_time - prev_tick; + } else { + prev_tick = UINT32_MAX - prev_tick + 1; + prev_tick += act_time; + } + + return prev_tick; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + diff --git a/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.h b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.h new file mode 100644 index 0000000..af3d8ea --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_hal/lv_hal_tick.h @@ -0,0 +1,65 @@ +/** + * @file lv_hal_tick.h + * Provide access to the system tick with 1 millisecond resolution + */ + +#ifndef LV_HAL_TICK_H +#define LV_HAL_TICK_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif +#include + +/********************* + * DEFINES + *********************/ +#ifndef LV_ATTRIBUTE_TICK_INC +#define LV_ATTRIBUTE_TICK_INC +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * You have to call this function periodically + * @param tick_period the call period of this function in milliseconds + */ +LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period); + +/** + * Get the elapsed milliseconds since start up + * @return the elapsed milliseconds + */ +uint32_t lv_tick_get(void); + +/** + * Get the elapsed milliseconds since a previous time stamp + * @param prev_tick a previous time stamp (return value of systick_get() ) + * @return the elapsed milliseconds since 'prev_tick' + */ +uint32_t lv_tick_elaps(uint32_t prev_tick); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_HAL_TICK_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.c new file mode 100644 index 0000000..578c556 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.c @@ -0,0 +1,445 @@ +/** + * @file anim.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_anim.h" + +#if USE_LV_ANIMATION +#include +#include +#include "../lv_hal/lv_hal_tick.h" +#include "lv_task.h" +#include "lv_math.h" +#include "lv_gc.h" + +#if defined(LV_GC_INCLUDE) +# include LV_GC_INCLUDE +#endif /* LV_ENABLE_GC */ + + +/********************* + * DEFINES + *********************/ +#define LV_ANIM_RESOLUTION 1024 +#define LV_ANIM_RES_SHIFT 10 + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void anim_task(void * param); +static bool anim_ready_handler(lv_anim_t * a); + +/********************** + * STATIC VARIABLES + **********************/ +static uint32_t last_task_run; +static bool anim_list_changed; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Init. the animation module + */ +void lv_anim_init(void) +{ + lv_ll_init(&LV_GC_ROOT(_lv_anim_ll), sizeof(lv_anim_t)); + last_task_run = lv_tick_get(); + lv_task_create(anim_task, LV_REFR_PERIOD, LV_TASK_PRIO_MID, NULL); +} + +/** + * Create an animation + * @param anim_p an initialized 'anim_t' variable. Not required after call. + */ +void lv_anim_create(lv_anim_t * anim_p) +{ + LV_LOG_TRACE("animation create started") + /* Do not let two animations for the same 'var' with the same 'fp'*/ + if(anim_p->fp != NULL) lv_anim_del(anim_p->var, anim_p->fp); /*fp == NULL would delete all animations of var*/ + + /*Add the new animation to the animation linked list*/ + lv_anim_t * new_anim = lv_ll_ins_head(&LV_GC_ROOT(_lv_anim_ll)); + lv_mem_assert(new_anim); + if(new_anim == NULL) return; + + /*Initialize the animation descriptor*/ + anim_p->playback_now = 0; + memcpy(new_anim, anim_p, sizeof(lv_anim_t)); + + /*Set the start value*/ + if(new_anim->fp != NULL) new_anim->fp(new_anim->var, new_anim->start); + + /* Creating an animation changed the linked list. + * It's important if it happens in a ready callback. (see `anim_task`)*/ + anim_list_changed = true; + + LV_LOG_TRACE("animation created") +} + +/** + * Delete an animation for a variable with a given animator function + * @param var pointer to variable + * @param fp a function pointer which is animating 'var', + * or NULL to delete all animations of 'var' + * @return true: at least 1 animation is deleted, false: no animation is deleted + */ +bool lv_anim_del(void * var, lv_anim_fp_t fp) +{ + lv_anim_t * a; + lv_anim_t * a_next; + bool del = false; + a = lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll)); + while(a != NULL) { + /*'a' might be deleted, so get the next object while 'a' is valid*/ + a_next = lv_ll_get_next(&LV_GC_ROOT(_lv_anim_ll), a); + + if(a->var == var && (a->fp == fp || fp == NULL)) { + lv_ll_rem(&LV_GC_ROOT(_lv_anim_ll), a); + lv_mem_free(a); + anim_list_changed = true; /*Read by `anim_task`. It need to know if a delete occurred in the linked list*/ + del = true; + } + + a = a_next; + } + + return del; +} + +/** + * Get the number of currently running animations + * @return the number of running animations + */ +uint16_t lv_anim_count_running(void) +{ + uint16_t cnt = 0; + lv_anim_t * a; + LL_READ(LV_GC_ROOT(_lv_anim_ll), a) cnt++; + + return cnt++; +} + +/** + * Calculate the time of an animation with a given speed and the start and end values + * @param speed speed of animation in unit/sec + * @param start start value of the animation + * @param end end value of the animation + * @return the required time [ms] for the animation with the given parameters + */ +uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end) +{ + int32_t d = LV_MATH_ABS((int32_t) start - end); + uint32_t time = (int32_t)((int32_t)(d * 1000) / speed); + + if(time > UINT16_MAX) time = UINT16_MAX; + + if(time == 0) { + time++; + } + + return time; +} + +/** + * Calculate the current value of an animation applying linear characteristic + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_linear(const lv_anim_t * a) +{ + /*Calculate the current step*/ + uint16_t step; + if(a->time == a->act_time) step = LV_ANIM_RESOLUTION; /*Use the last value if the time fully elapsed*/ + else step = (a->act_time * LV_ANIM_RESOLUTION) / a->time; + + /* Get the new value which will be proportional to `step` + * and the `start` and `end` values*/ + int32_t new_value; + new_value = (int32_t) step * (a->end - a->start); + new_value = new_value >> LV_ANIM_RES_SHIFT; + new_value += a->start; + + return new_value; +} + +/** + * Calculate the current value of an animation slowing down the start phase + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_in(const lv_anim_t * a) +{ + /*Calculate the current step*/ + uint32_t t; + if(a->time == a->act_time) t = 1024; + else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time; + + int32_t step = lv_bezier3(t, 0, 1, 1, 1024); + + int32_t new_value; + new_value = (int32_t) step * (a->end - a->start); + new_value = new_value >> 10; + new_value += a->start; + + + return new_value; +} + +/** + * Calculate the current value of an animation slowing down the end phase + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_out(const lv_anim_t * a) +{ + /*Calculate the current step*/ + + uint32_t t; + if(a->time == a->act_time) t = 1024; + else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time; + + int32_t step = lv_bezier3(t, 0, 1023, 1023, 1024); + + int32_t new_value; + new_value = (int32_t) step * (a->end - a->start); + new_value = new_value >> 10; + new_value += a->start; + + + return new_value; +} + +/** + * Calculate the current value of an animation applying an "S" characteristic (cosine) + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_in_out(const lv_anim_t * a) +{ + /*Calculate the current step*/ + + uint32_t t; + if(a->time == a->act_time) t = 1024; + else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time; + + int32_t step = lv_bezier3(t, 0, 100, 924, 1024); + + int32_t new_value; + new_value = (int32_t) step * (a->end - a->start); + new_value = new_value >> 10; + new_value += a->start; + + + return new_value; +} + +/** + * Calculate the current value of an animation with overshoot at the end + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_overshoot(const lv_anim_t * a) +{ + /*Calculate the current step*/ + + uint32_t t; + if(a->time == a->act_time) t = 1024; + else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time; + + int32_t step = lv_bezier3(t, 0, 600, 1300, 1024); + + int32_t new_value; + new_value = (int32_t) step * (a->end - a->start); + new_value = new_value >> 10; + new_value += a->start; + + + return new_value; +} + +/** + * Calculate the current value of an animation with 3 bounces + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_bounce(const lv_anim_t * a) +{ + /*Calculate the current step*/ + uint32_t t; + if(a->time == a->act_time) t = 1024; + else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time; + + int32_t diff = (a->end - a->start); + + /*3 bounces has 5 parts: 3 down and 2 up. One part is t / 5 long*/ + + if(t < 408){ + /*Go down*/ + t = (t * 2500) >> 10; /*[0..1024] range*/ + } + else if(t >= 408 && t < 614) { + /*First bounce back*/ + t -= 408; + t = t * 5; /*to [0..1024] range*/ + t = 1024 - t; + diff = diff / 6; + } + else if(t >= 614 && t < 819) { + /*Fall back*/ + t -= 614; + t = t * 5; /*to [0..1024] range*/ + diff = diff / 6; + } + else if(t >= 819 && t < 921) { + /*Second bounce back*/ + t -= 819; + t = t * 10; /*to [0..1024] range*/ + t = 1024 - t; + diff = diff / 16; + } + else if(t >= 921 && t <= 1024) { + /*Fall back*/ + t -= 921; + t = t * 10; /*to [0..1024] range*/ + diff = diff / 16; + } + + if(t > 1024) t = 1024; + + int32_t step = lv_bezier3(t, 1024, 1024, 800, 0); + + int32_t new_value; + + new_value = (int32_t) step * diff; + new_value = new_value >> 10; + new_value = a->end - new_value; + + + return new_value; +} + +/** + * Calculate the current value of an animation applying step characteristic. + * (Set end value on the end of the animation) + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_step(const lv_anim_t * a) +{ + if(a->act_time >= a->time) return a->end; + else return a->start; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Periodically handle the animations. + * @param param unused + */ +static void anim_task(void * param) +{ + (void)param; + + lv_anim_t * a; + LL_READ(LV_GC_ROOT(_lv_anim_ll), a) { + a->has_run = 0; + } + + uint32_t elaps = lv_tick_elaps(last_task_run); + a = lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll)); + + while(a != NULL) { + /*It can be set by `lv_anim_del()` typically in `end_cb`. If set then an animation delete happened in `anim_ready_handler` + * which could make this linked list reading corrupt because the list is changed meanwhile + */ + anim_list_changed = false; + + if(!a->has_run) { + a->has_run = 1; /*The list readying might be reseted so need to know which anim has run already*/ + a->act_time += elaps; + if(a->act_time >= 0) { + if(a->act_time > a->time) a->act_time = a->time; + + int32_t new_value; + new_value = a->path(a); + + if(a->fp != NULL) a->fp(a->var, new_value); /*Apply the calculated value*/ + + /*If the time is elapsed the animation is ready*/ + if(a->act_time >= a->time) { + anim_ready_handler(a); + } + } + } + + /* If the linked list changed due to anim. delete then it's not safe to continue + * the reading of the list from here -> start from the head*/ + if(anim_list_changed) a = lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll)); + else a = lv_ll_get_next(&LV_GC_ROOT(_lv_anim_ll), a); + } + + last_task_run = lv_tick_get(); +} + +/** + * Called when an animation is ready to do the necessary thinks + * e.g. repeat, play back, delete etc. + * @param a pointer to an animation descriptor + * @return true: animation delete occurred nnd the `LV_GC_ROOT(_lv_anim_ll)` has changed + * */ +static bool anim_ready_handler(lv_anim_t * a) +{ + + /*Delete the animation if + * - no repeat and no play back (simple one shot animation) + * - no repeat, play back is enabled and play back is ready */ + if((a->repeat == 0 && a->playback == 0) || + (a->repeat == 0 && a->playback == 1 && a->playback_now == 1)) { + void (*cb)(void *) = a->end_cb; + void * p = a->var; + lv_ll_rem(&LV_GC_ROOT(_lv_anim_ll), a); + lv_mem_free(a); + anim_list_changed = true; + + /* Call the callback function at the end*/ + /* Check if an animation is deleted in the cb function + * if yes then the caller function has to know this*/ + if(cb != NULL) cb(p); + } + /*If the animation is not deleted then restart it*/ + else { + a->act_time = - a->repeat_pause; /*Restart the animation*/ + /*Swap the start and end values in play back mode*/ + if(a->playback != 0) { + /*If now turning back use the 'playback_pause*/ + if(a->playback_now == 0) a->act_time = - a->playback_pause; + + /*Toggle the play back state*/ + a->playback_now = a->playback_now == 0 ? 1 : 0; + /*Swap the start and end values*/ + int32_t tmp; + tmp = a->start; + a->start = a->end; + a->end = tmp; + } + } + + return anim_list_changed; +} +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.h new file mode 100644 index 0000000..6625ae2 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_anim.h @@ -0,0 +1,176 @@ +/** + * @file anim.h + * + */ + +#ifndef ANIM_H +#define ANIM_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_ANIMATION + +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_anim_t; + +typedef int32_t(*lv_anim_path_t)(const struct _lv_anim_t*); + +typedef void (*lv_anim_fp_t)(void *, int32_t); +typedef void (*lv_anim_cb_t)(void *); + +typedef struct _lv_anim_t +{ + void * var; /*Variable to animate*/ + lv_anim_fp_t fp; /*Animator function*/ + lv_anim_cb_t end_cb; /*Call it when the animation is ready*/ + lv_anim_path_t path; /*An array with the steps of animations*/ + int32_t start; /*Start value*/ + int32_t end; /*End value*/ + uint16_t time; /*Animation time in ms*/ + int16_t act_time; /*Current time in animation. Set to negative to make delay.*/ + uint16_t playback_pause; /*Wait before play back*/ + uint16_t repeat_pause; /*Wait before repeat*/ + uint8_t playback :1; /*When the animation is ready play it back*/ + uint8_t repeat :1; /*Repeat the animation infinitely*/ + /*Animation system use these - user shouldn't set*/ + uint8_t playback_now :1; /*Play back is in progress*/ + uint32_t has_run :1; /*Indicates the animation has run it this round*/ +} lv_anim_t; + +/*Example initialization +lv_anim_t a; +a.var = obj; +a.start = lv_obj_get_height(obj); +a.end = new_height; +a.fp = (lv_anim_fp_t)lv_obj_set_height; +a.path = lv_anim_path_linear; +a.end_cb = NULL; +a.act_time = 0; +a.time = 200; +a.playback = 0; +a.playback_pause = 0; +a.repeat = 0; +a.repeat_pause = 0; +lv_anim_create(&a); + */ +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Init. the animation module + */ +void lv_anim_init(void); + +/** + * Create an animation + * @param anim_p an initialized 'anim_t' variable. Not required after call. + */ +void lv_anim_create(lv_anim_t * anim_p); + +/** + * Delete an animation for a variable with a given animatior function + * @param var pointer to variable + * @param fp a function pointer which is animating 'var', + * or NULL to ignore it and delete all animation with 'var + * @return true: at least 1 animation is deleted, false: no animation is deleted + */ +bool lv_anim_del(void * var, lv_anim_fp_t fp); + +/** + * Get the number of currently running animations + * @return the number of running animations + */ +uint16_t lv_anim_count_running(void); + +/** + * Calculate the time of an animation with a given speed and the start and end values + * @param speed speed of animation in unit/sec + * @param start start value of the animation + * @param end end value of the animation + * @return the required time [ms] for the animation with the given parameters + */ +uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end); + +/** + * Calculate the current value of an animation applying linear characteristic + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_linear(const lv_anim_t *a); + +/** + * Calculate the current value of an animation slowing down the start phase + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_in(const lv_anim_t * a); + +/** + * Calculate the current value of an animation slowing down the end phase + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_out(const lv_anim_t * a); + +/** + * Calculate the current value of an animation applying an "S" characteristic (cosine) + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_in_out(const lv_anim_t *a); + +/** + * Calculate the current value of an animation with overshoot at the end + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_overshoot(const lv_anim_t * a); + +/** + * Calculate the current value of an animation with 3 bounces + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_bounce(const lv_anim_t * a); + +/** + * Calculate the current value of an animation applying step characteristic. + * (Set end value on the end of the animation) + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_step(const lv_anim_t *a); +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_ANIMATION == 0*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_ANIM_H*/ + diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.c new file mode 100644 index 0000000..f340690 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.c @@ -0,0 +1,200 @@ +/** + * @file lv_area.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_area.h" +#include "lv_math.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize an area + * @param area_p pointer to an area + * @param x1 left coordinate of the area + * @param y1 top coordinate of the area + * @param x2 right coordinate of the area + * @param y2 bottom coordinate of the area + */ +void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2) +{ + area_p->x1 = x1; + area_p->y1 = y1; + area_p->x2 = x2; + area_p->y2 = y2; +} + +/** + * Set the width of an area + * @param area_p pointer to an area + * @param w the new width of the area (w == 1 makes x1 == x2) + */ +void lv_area_set_width(lv_area_t * area_p, lv_coord_t w) +{ + area_p->x2 = area_p->x1 + w - 1; +} + +/** + * Set the height of an area + * @param area_p pointer to an area + * @param h the new height of the area (h == 1 makes y1 == y2) + */ +void lv_area_set_height(lv_area_t * area_p, lv_coord_t h) +{ + area_p->y2 = area_p->y1 + h - 1; +} + +/** + * Set the position of an area (width and height will be kept) + * @param area_p pointer to an area + * @param x the new x coordinate of the area + * @param y the new y coordinate of the area + */ +void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y) +{ + lv_coord_t w = lv_area_get_width(area_p); + lv_coord_t h = lv_area_get_height(area_p); + area_p->x1 = x; + area_p->y1 = y; + lv_area_set_width(area_p, w); + lv_area_set_height(area_p, h); +} + +/** + * Return with area of an area (x * y) + * @param area_p pointer to an area + * @return size of area + */ +uint32_t lv_area_get_size(const lv_area_t * area_p) +{ + uint32_t size; + + size = (uint32_t)(area_p->x2 - area_p->x1 + 1) * + (area_p->y2 - area_p->y1 + 1); + + return size; +} + +/** + * Get the common parts of two areas + * @param res_p pointer to an area, the result will be stored here + * @param a1_p pointer to the first area + * @param a2_p pointer to the second area + * @return false: the two area has NO common parts, res_p is invalid + */ +bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p) +{ + /* Get the smaller area from 'a1_p' and 'a2_p' */ + res_p->x1 = LV_MATH_MAX(a1_p->x1, a2_p->x1); + res_p->y1 = LV_MATH_MAX(a1_p->y1, a2_p->y1); + res_p->x2 = LV_MATH_MIN(a1_p->x2, a2_p->x2); + res_p->y2 = LV_MATH_MIN(a1_p->y2, a2_p->y2); + + /*If x1 or y1 greater then x2 or y2 then the areas union is empty*/ + bool union_ok = true; + if((res_p->x1 > res_p->x2) || + (res_p->y1 > res_p->y2)) { + union_ok = false; + } + + return union_ok; +} +/** + * Join two areas into a third which involves the other two + * @param res_p pointer to an area, the result will be stored here + * @param a1_p pointer to the first area + * @param a2_p pointer to the second area + */ +void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p) +{ + a_res_p->x1 = LV_MATH_MIN(a1_p->x1, a2_p->x1); + a_res_p->y1 = LV_MATH_MIN(a1_p->y1, a2_p->y1); + a_res_p->x2 = LV_MATH_MAX(a1_p->x2, a2_p->x2); + a_res_p->y2 = LV_MATH_MAX(a1_p->y2, a2_p->y2); +} + +/** + * Check if a point is on an area + * @param a_p pointer to an area + * @param p_p pointer to a point + * @return false:the point is out of the area + */ +bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p) +{ + bool is_on = false; + + if((p_p->x >= a_p->x1 && p_p->x <= a_p->x2) && + ((p_p->y >= a_p->y1 && p_p->y <= a_p->y2))) { + is_on = true; + } + + return is_on; +} + +/** + * Check if two area has common parts + * @param a1_p pointer to an area. + * @param a2_p pointer to an other area + * @return false: a1_p and a2_p has no common parts + */ +bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p) +{ + if((a1_p->x1 <= a2_p->x2) && + (a1_p->x2 >= a2_p->x1) && + (a1_p->y1 <= a2_p->y2) && + (a1_p->y2 >= a2_p->y1)) { + return true; + } else { + return false; + } + +} + +/** + * Check if an area is fully on an other + * @param ain_p pointer to an area which could be in 'aholder_p' + * @param aholder pointer to an area which could involve 'ain_p' + * @return + */ +bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p) +{ + bool is_in = false; + + if(ain_p->x1 >= aholder_p->x1 && + ain_p->y1 >= aholder_p->y1 && + ain_p->x2 <= aholder_p->x2 && + ain_p->y2 <= aholder_p->y2) { + is_in = true; + } + + return is_in; +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.h new file mode 100644 index 0000000..bae0753 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_area.h @@ -0,0 +1,168 @@ +/** + * @file lv_area.h + * + */ + +#ifndef LV_AREA_H +#define LV_AREA_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#include +#include "../../../utils/types.h" + +/********************* + * DEFINES + *********************/ +#define LV_COORD_MAX (16383) /*To avoid overflow don't let the max [-32,32k] range */ +#define LV_COORD_MIN (-16384) + +/********************** + * TYPEDEFS + **********************/ +typedef int16_t lv_coord_t; + +typedef struct +{ + lv_coord_t x; + lv_coord_t y; +} lv_point_t; + +typedef struct +{ + lv_coord_t x1; + lv_coord_t y1; + lv_coord_t x2; + lv_coord_t y2; +} lv_area_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize an area + * @param area_p pointer to an area + * @param x1 left coordinate of the area + * @param y1 top coordinate of the area + * @param x2 right coordinate of the area + * @param y2 bottom coordinate of the area + */ +void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2); + +/** + * Copy an area + * @param dest pointer to the destination area + * @param src pointer to the source area + */ +inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src) +{ + memcpy(dest, src, sizeof(lv_area_t)); +} + +/** + * Get the width of an area + * @param area_p pointer to an area + * @return the width of the area (if x1 == x2 -> width = 1) + */ +static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p) +{ + return area_p->x2 - area_p->x1 + 1; +} + +/** + * Get the height of an area + * @param area_p pointer to an area + * @return the height of the area (if y1 == y2 -> height = 1) + */ +static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p) +{ + return area_p->y2 - area_p->y1 + 1; +} + +/** + * Set the width of an area + * @param area_p pointer to an area + * @param w the new width of the area (w == 1 makes x1 == x2) + */ +void lv_area_set_width(lv_area_t * area_p, lv_coord_t w); + +/** + * Set the height of an area + * @param area_p pointer to an area + * @param h the new height of the area (h == 1 makes y1 == y2) + */ +void lv_area_set_height(lv_area_t * area_p, lv_coord_t h); + +/** + * Set the position of an area (width and height will be kept) + * @param area_p pointer to an area + * @param x the new x coordinate of the area + * @param y the new y coordinate of the area + */ +void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y); + +/** + * Return with area of an area (x * y) + * @param area_p pointer to an area + * @return size of area + */ +uint32_t lv_area_get_size(const lv_area_t * area_p); + +/** + * Get the common parts of two areas + * @param res_p pointer to an area, the result will be stored her + * @param a1_p pointer to the first area + * @param a2_p pointer to the second area + * @return false: the two area has NO common parts, res_p is invalid + */ +bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Join two areas into a third which involves the other two + * @param res_p pointer to an area, the result will be stored here + * @param a1_p pointer to the first area + * @param a2_p pointer to the second area + */ +void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Check if a point is on an area + * @param a_p pointer to an area + * @param p_p pointer to a point + * @return false:the point is out of the area + */ +bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p); + +/** + * Check if two area has common parts + * @param a1_p pointer to an area. + * @param a2_p pointer to an other area + * @return false: a1_p and a2_p has no common parts + */ +bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Check if an area is fully on an other + * @param ain_p pointer to an area which could be on aholder_p + * @param aholder pointer to an area which could involve ain_p + * @return + */ +bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.c new file mode 100644 index 0000000..d89d833 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.c @@ -0,0 +1,79 @@ +/** + * @file lv_circ.c + * Circle drawing algorithm (with Bresenham) + * Only a 1/8 circle is calculated. Use CIRC_OCT1_X, CIRC_OCT1_Y macros to get + * the other octets. + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_circ.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the circle drawing + * @param c pointer to a point. The coordinates will be calculated here + * @param tmp point to a variable. It will store temporary data + * @param radius radius of the circle + */ +void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius) +{ + c->x = radius; + c->y = 0; + *tmp = 1 - radius; +} + +/** + * Test the circle drawing is ready or not + * @param c same as in circ_init + * @return true if the circle is not ready yet + */ +bool lv_circ_cont(lv_point_t * c) +{ + return c->y <= c->x ? true : false; +} + +/** + * Get the next point from the circle + * @param c same as in circ_init. The next point stored here. + * @param tmp same as in circ_init. + */ +void lv_circ_next(lv_point_t * c, lv_coord_t * tmp) +{ + c->y++; + + if(*tmp <= 0) { + (*tmp) += 2 * c->y + 1; // Change in decision criterion for y -> y+1 + } else { + c->x--; + (*tmp) += 2 * (c->y - c->x) + 1; // Change for y -> y+1, x -> x-1 + } +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.h new file mode 100644 index 0000000..f0fbb3f --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_circ.h @@ -0,0 +1,80 @@ +/** + * @file lv_circ.h + * + */ + +#ifndef LV_CIRC_H +#define LV_CIRC_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_area.h" +#include "../../../utils/types.h" + +/********************* + * DEFINES + *********************/ +#define LV_CIRC_OCT1_X(p) (p.x) +#define LV_CIRC_OCT1_Y(p) (p.y) +#define LV_CIRC_OCT2_X(p) (p.y) +#define LV_CIRC_OCT2_Y(p) (p.x) +#define LV_CIRC_OCT3_X(p) (-p.y) +#define LV_CIRC_OCT3_Y(p) (p.x) +#define LV_CIRC_OCT4_X(p) (-p.x) +#define LV_CIRC_OCT4_Y(p) (p.y) +#define LV_CIRC_OCT5_X(p) (-p.x) +#define LV_CIRC_OCT5_Y(p) (-p.y) +#define LV_CIRC_OCT6_X(p) (-p.y) +#define LV_CIRC_OCT6_Y(p) (-p.x) +#define LV_CIRC_OCT7_X(p) (p.y) +#define LV_CIRC_OCT7_Y(p) (-p.x) +#define LV_CIRC_OCT8_X(p) (p.x) +#define LV_CIRC_OCT8_Y(p) (-p.y) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the circle drawing + * @param c pointer to a point. The coordinates will be calculated here + * @param tmp point to a variable. It will store temporary data + * @param radius radius of the circle + */ +void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius); + +/** + * Test the circle drawing is ready or not + * @param c same as in circ_init + * @return true if the circle is not ready yet + */ +bool lv_circ_cont(lv_point_t * c); + +/** + * Get the next point from the circle + * @param c same as in circ_init. The next point stored here. + * @param tmp same as in circ_init. + */ +void lv_circ_next(lv_point_t * c, lv_coord_t * tmp); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.c new file mode 100644 index 0000000..f6001eb --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.c @@ -0,0 +1,143 @@ +/** + * @file lv_color.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_color.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Convert a HSV color to RGB + * @param h hue [0..359] + * @param s saturation [0..100] + * @param v value [0..100] + * @return the given RGB color in RGB (with LV_COLOR_DEPTH depth) + */ +lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v) +{ + h = (uint32_t)((uint32_t)h * 255) / 360; + s = (uint16_t)((uint16_t)s * 255) / 100; + v = (uint16_t)((uint16_t)v * 255) / 100; + + uint8_t r, g, b; + + uint8_t region, remainder, p, q, t; + + if(s == 0) { + r = v; + g = v; + b = v; + return LV_COLOR_MAKE(v, v, v); + } + + region = h / 43; + remainder = (h - (region * 43)) * 6; + + p = (v * (255 - s)) >> 8; + q = (v * (255 - ((s * remainder) >> 8))) >> 8; + t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8; + + switch(region) { + case 0: + r = v; + g = t; + b = p; + break; + case 1: + r = q; + g = v; + b = p; + break; + case 2: + r = p; + g = v; + b = t; + break; + case 3: + r = p; + g = q; + b = v; + break; + case 4: + r = t; + g = p; + b = v; + break; + default: + r = v; + g = p; + b = q; + break; + } + + lv_color_t result = LV_COLOR_MAKE(r, g, b); + return result; +} + +/** + * Convert an RGB color to HSV + * @param r red + * @param g green + * @param b blue + * @return the given RGB color n HSV + */ +lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r, uint8_t g, uint8_t b) +{ + lv_color_hsv_t hsv; + uint8_t rgbMin, rgbMax; + + rgbMin = r < g ? (r < b ? r : b) : (g < b ? g : b); + rgbMax = r > g ? (r > b ? r : b) : (g > b ? g : b); + + hsv.v = rgbMax; + if(hsv.v == 0) { + hsv.h = 0; + hsv.s = 0; + return hsv; + } + + hsv.s = 255 * (long)(rgbMax - rgbMin) / hsv.v; + if(hsv.s == 0) { + hsv.h = 0; + return hsv; + } + + if(rgbMax == r) + hsv.h = 0 + 43 * (g - b) / (rgbMax - rgbMin); + else if(rgbMax == g) + hsv.h = 85 + 43 * (b - r) / (rgbMax - rgbMin); + else + hsv.h = 171 + 43 * (r - g) / (rgbMax - rgbMin); + + return hsv; +} diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.h new file mode 100644 index 0000000..bfaee8a --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_color.h @@ -0,0 +1,448 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_color.h + * + */ + +#ifndef LV_COLOR_H +#define LV_COLOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +/*Error checking*/ +#if LV_COLOR_DEPTH == 24 +#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)" +#endif + +#if LV_COLOR_DEPTH != 32 && LV_COLOR_SCREEN_TRANSP != 0 +#error "LV_COLOR_SCREEN_TRANSP requires LV_COLOR_DEPTH == 32. Set it in lv_conf.h" +#endif + +#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0 +#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h" +#endif + + +#include + +/********************* + * DEFINES + *********************/ +#define LV_COLOR_WHITE LV_COLOR_MAKE(0xFF,0xFF,0xFF) +#define LV_COLOR_SILVER LV_COLOR_MAKE(0xC0,0xC0,0xC0) +#define LV_COLOR_GRAY LV_COLOR_MAKE(0x80,0x80,0x80) +#define LV_COLOR_BLACK LV_COLOR_MAKE(0x00,0x00,0x00) +#define LV_COLOR_RED LV_COLOR_MAKE(0xFF,0x00,0x00) +#define LV_COLOR_MAROON LV_COLOR_MAKE(0x80,0x00,0x00) +#define LV_COLOR_YELLOW LV_COLOR_MAKE(0xFF,0xFF,0x00) +#define LV_COLOR_OLIVE LV_COLOR_MAKE(0x80,0x80,0x00) +#define LV_COLOR_LIME LV_COLOR_MAKE(0x00,0xFF,0x00) +#define LV_COLOR_GREEN LV_COLOR_MAKE(0x00,0x80,0x00) +#define LV_COLOR_CYAN LV_COLOR_MAKE(0x00,0xFF,0xFF) +#define LV_COLOR_AQUA LV_COLOR_CYAN +#define LV_COLOR_TEAL LV_COLOR_MAKE(0x00,0x80,0x80) +#define LV_COLOR_BLUE LV_COLOR_MAKE(0x00,0x00,0xFF) +#define LV_COLOR_NAVY LV_COLOR_MAKE(0x00,0x00,0x80) +#define LV_COLOR_MAGENTA LV_COLOR_MAKE(0xFF,0x00,0xFF) +#define LV_COLOR_PURPLE LV_COLOR_MAKE(0x80,0x00,0x80) +#define LV_COLOR_ORANGE LV_COLOR_MAKE(0xFF,0xA5,0x00) + +enum { + LV_OPA_TRANSP = 0, + LV_OPA_0 = 0, + LV_OPA_10 = 25, + LV_OPA_20 = 51, + LV_OPA_30 = 76, + LV_OPA_40 = 102, + LV_OPA_50 = 127, + LV_OPA_60 = 153, + LV_OPA_70 = 178, + LV_OPA_80 = 204, + LV_OPA_90 = 229, + LV_OPA_100 = 255, + LV_OPA_COVER = 255, +}; + +#define LV_OPA_MIN 16 /*Opacities below this will be transparent*/ +#define LV_OPA_MAX 251 /*Opacities above this will fully cover*/ + +#if LV_COLOR_DEPTH == 1 +#define LV_COLOR_SIZE 8 +#elif LV_COLOR_DEPTH == 8 +#define LV_COLOR_SIZE 8 +#elif LV_COLOR_DEPTH == 16 +#define LV_COLOR_SIZE 16 +#elif LV_COLOR_DEPTH == 32 +#define LV_COLOR_SIZE 32 +#else +#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!" +#endif + +/********************** + * TYPEDEFS + **********************/ + +typedef union +{ + uint8_t blue :1; + uint8_t green :1; + uint8_t red :1; + uint8_t full :1; +} lv_color1_t; + +typedef union +{ + struct + { + uint8_t blue :2; + uint8_t green :3; + uint8_t red :3; + }; + uint8_t full; +} lv_color8_t; + +typedef union +{ + struct + { +#if LV_COLOR_16_SWAP == 0 + uint16_t blue :5; + uint16_t green :6; + uint16_t red :5; +#else + uint16_t green_h :3; + uint16_t red :5; + uint16_t blue :5; + uint16_t green_l :3; +#endif + }; + uint16_t full; +} lv_color16_t; + +typedef union +{ + struct + { + uint8_t blue; + uint8_t green; + uint8_t red; + uint8_t alpha; + }; + uint32_t full; +} lv_color32_t; + +#if LV_COLOR_DEPTH == 1 +typedef uint8_t lv_color_int_t; +typedef lv_color1_t lv_color_t; +#elif LV_COLOR_DEPTH == 8 +typedef uint8_t lv_color_int_t; +typedef lv_color8_t lv_color_t; +#elif LV_COLOR_DEPTH == 16 +typedef uint16_t lv_color_int_t; +typedef lv_color16_t lv_color_t; +#elif LV_COLOR_DEPTH == 32 +typedef uint32_t lv_color_int_t; +typedef lv_color32_t lv_color_t; +#else +#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!" +#endif + +typedef uint8_t lv_opa_t; + +typedef struct +{ + uint16_t h; + uint8_t s; + uint8_t v; +} lv_color_hsv_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*In color conversations: + * - When converting to bigger color type the LSB weight of 1 LSB is calculated + * E.g. 16 bit Red has 5 bits + * 8 bit Red has 2 bits + * ---------------------- + * 8 bit red LSB = (2^5 - 1) / (2^2 - 1) = 31 / 3 = 10 + * + * - When calculating to smaller color type simply shift out the LSBs + * E.g. 8 bit Red has 2 bits + * 16 bit Red has 5 bits + * ---------------------- + * Shift right with 5 - 3 = 2 + */ + +static inline uint8_t lv_color_to1(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + return color.full; +#elif LV_COLOR_DEPTH == 8 + if((color.red & 0x4) || + (color.green & 0x4) || + (color.blue & 0x2)) { + return 1; + } else { + return 0; + } +#elif LV_COLOR_DEPTH == 16 +# if LV_COLOR_16_SWAP == 0 + if((color.red & 0x10) || + (color.green & 0x20) || + (color.blue & 0x10)) { + return 1; +# else + if((color.red & 0x10) || + (color.green_h & 0x20) || + (color.blue & 0x10)) { + return 1; +# endif + } else { + return 0; + } +#elif LV_COLOR_DEPTH == 32 + if((color.red & 0x80) || + (color.green & 0x80) || + (color.blue & 0x80)) { + return 1; + } else { + return 0; + } +#endif +} + +static inline uint8_t lv_color_to8(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) return 0; + else return 0xFF; +#elif LV_COLOR_DEPTH == 8 + return color.full; +#elif LV_COLOR_DEPTH == 16 + +# if LV_COLOR_16_SWAP == 0 + lv_color8_t ret; + ret.red = color.red >> 2; /* 5 - 3 = 2*/ + ret.green = color.green >> 3; /* 6 - 3 = 3*/ + ret.blue = color.blue >> 3; /* 5 - 2 = 3*/ + return ret.full; +# else + lv_color8_t ret; + ret.red = color.red >> 2; /* 5 - 3 = 2*/ + ret.green = color.green_h; /* 6 - 3 = 3*/ + ret.blue = color.blue >> 3; /* 5 - 2 = 3*/ + return ret.full; +# endif +#elif LV_COLOR_DEPTH == 32 + lv_color8_t ret; + ret.red = color.red >> 5; /* 8 - 3 = 5*/ + ret.green = color.green >> 5; /* 8 - 3 = 5*/ + ret.blue = color.blue >> 6; /* 8 - 2 = 6*/ + return ret.full; +#endif +} + +static inline uint16_t lv_color_to16(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) return 0; + else return 0xFFFF; +#elif LV_COLOR_DEPTH == 8 + lv_color16_t ret; +# if LV_COLOR_16_SWAP == 0 + ret.red = color.red * 4; /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/ + ret.green = color.green * 9; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/ + ret.blue = color.blue * 10; /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/ +# else + ret.red = color.red * 4; + uint8_t g_tmp = color.green * 9; + ret.green_h = (g_tmp & 0x1F) >> 3; + ret.green_l = g_tmp & 0x07; + ret.blue = color.blue * 10; +# endif + return ret.full; +#elif LV_COLOR_DEPTH == 16 + return color.full; +#elif LV_COLOR_DEPTH == 32 + lv_color16_t ret; +# if LV_COLOR_16_SWAP == 0 + ret.red = color.red >> 3; /* 8 - 5 = 3*/ + ret.green = color.green >> 2; /* 8 - 6 = 2*/ + ret.blue = color.blue >> 3; /* 8 - 5 = 3*/ +# else + ret.red = color.red >> 3; + ret.green_h = (color.green & 0xE0) >> 5; + ret.green_l = (color.green & 0x1C) >> 2; + ret.blue = color.blue >> 3; +# endif + return ret.full; +#endif +} + +static inline uint32_t lv_color_to32(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) return 0; + else return 0xFFFFFFFF; +#elif LV_COLOR_DEPTH == 8 + lv_color32_t ret; + ret.red = color.red * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ + ret.green = color.green * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ + ret.blue = color.blue * 85; /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/ + ret.alpha = 0xFF; + return ret.full; +#elif LV_COLOR_DEPTH == 16 +# if LV_COLOR_16_SWAP == 0 + lv_color32_t ret; + ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ + ret.green = color.green * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/ + ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ + ret.alpha = 0xFF; + return ret.full; +# else + lv_color32_t ret; + ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ + ret.green = ((color.green_h << 3) + color.green_l) * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/ + ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ + ret.alpha = 0xFF; + return ret.full; +# endif +#elif LV_COLOR_DEPTH == 32 + return color.full; +#endif +} + +static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix) +{ + lv_color_t ret; +#if LV_COLOR_DEPTH != 1 + /*LV_COLOR_DEPTH == 8, 16 or 32*/ + ret.red = (uint16_t)((uint16_t) c1.red * mix + (c2.red * (255 - mix))) >> 8; +# if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP + /*If swapped Green is in 2 parts*/ + uint16_t g_1 = (c1.green_h << 3) + c1.green_l; + uint16_t g_2 = (c2.green_h << 3) + c2.green_l; + uint16_t g_out = (uint16_t)((uint16_t) g_1 * mix + (g_2 * (255 - mix))) >> 8; + ret.green_h = g_out >> 3; + ret.green_l = g_out & 0x7; +# else + ret.green = (uint16_t)((uint16_t) c1.green * mix + (c2.green * (255 - mix))) >> 8; +# endif + ret.blue = (uint16_t)((uint16_t) c1.blue * mix + (c2.blue * (255 - mix))) >> 8; +# if LV_COLOR_DEPTH == 32 + ret.alpha = 0xFF; +# endif +#else + /*LV_COLOR_DEPTH == 1*/ + ret.full = mix > LV_OPA_50 ? c1.full : c2.full; +#endif + + return ret; +} + +/** + * Get the brightness of a color + * @param color a color + * @return the brightness [0..255] + */ +static inline uint8_t lv_color_brightness(lv_color_t color) +{ + lv_color32_t c32; + c32.full = lv_color_to32(color); + uint16_t bright = 3 * c32.red + c32.blue + 4 * c32.green; + return (uint16_t) bright >> 3; +} + +/* The most simple macro to create a color from R,G and B values + * The order of bit field is different on Big-endian and Little-endian machines*/ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#if LV_COLOR_DEPTH == 1 +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(b8 >> 7 | g8 >> 7 | r8 >> 7)}) +#elif LV_COLOR_DEPTH == 8 +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 6, g8 >> 5, r8 >> 5}}) +#elif LV_COLOR_DEPTH == 16 +# if LV_COLOR_16_SWAP == 0 +# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 3, g8 >> 2, r8 >> 3}}) +# else +# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{g8 >> 5, r8 >> 3, b8 >> 3, (g8 >> 2) & 0x7}}) +# endif +#elif LV_COLOR_DEPTH == 32 +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/ +#endif +#else +#if LV_COLOR_DEPTH == 1 +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(r8 >> 7 | g8 >> 7 | b8 >> 7)}) +#elif LV_COLOR_DEPTH == 8 +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 6, g8 >> 5, b8 >> 5}}) +#elif LV_COLOR_DEPTH == 16 +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 3, g8 >> 2, b8 >> 3}}) +#elif LV_COLOR_DEPTH == 32 +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{0xff, r8, g8, b8}}) /*Fix 0xff alpha*/ +#endif +#endif + +#define LV_COLOR_HEX(c) LV_COLOR_MAKE(((uint32_t)((uint32_t)c >> 16) & 0xFF), \ + ((uint32_t)((uint32_t)c >> 8) & 0xFF), \ + ((uint32_t) c & 0xFF)) + +/*Usage LV_COLOR_HEX3(0x16C) which means LV_COLOR_HEX(0x1166CC)*/ +#define LV_COLOR_HEX3(c) LV_COLOR_MAKE((((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), \ + ((uint32_t)(c & 0xF0) | ((c & 0xF0) >> 4)), \ + ((uint32_t)(c & 0xF) | ((c & 0xF) << 4))) + + +/** + * Convert a HSV color to RGB + * @param h hue [0..359] + * @param s saturation [0..100] + * @param v value [0..100] + * @return the given RGB color in RGB (with LV_COLOR_DEPTH depth) + */ +lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v); + +/** + * Convert an RGB color to HSV + * @param r red + * @param g green + * @param b blue + * @return the given RGB color n HSV + */ +lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r, uint8_t g, uint8_t b); + + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*USE_COLOR*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.c new file mode 100644 index 0000000..0aa7fe2 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.c @@ -0,0 +1,269 @@ +/** + * @file lv_font.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_font.h" +#include "lv_log.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the fonts + */ +void lv_font_init(void) +{ + lv_font_builtin_init(); +} + +/** + * Add a font to an other to extend the character set. + * @param child the font to add + * @param parent this font will be extended. Using it later will contain the characters from `child` + */ +void lv_font_add(lv_font_t * child, lv_font_t * parent) +{ + if(parent == NULL) return; + + while(parent->next_page != NULL) { + parent = parent->next_page; /*Got to the last page and add the new font there*/ + } + + parent->next_page = child; + +} + +/** + * Remove a font from a character set. + * @param child the font to remove + * @param parent remove `child` from here + */ +void lv_font_remove(lv_font_t * child, lv_font_t * parent) +{ + if(parent == NULL) return; + if(child == NULL) return; + + while(parent->next_page != child) { + parent = parent->next_page; /*Got to the last page and add the new font there*/ + } + + parent->next_page = child->next_page; +} + + +/** + * Tells if font which contains `letter` is monospace or not + * @param font_p point to font + * @param letter an UNICODE character code + * @return true: the letter is monospace; false not monospace + */ +bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter) +{ + const lv_font_t * font_i = font_p; + int16_t w; + while(font_i != NULL) { + w = font_i->get_width(font_i, letter); + if(w >= 0) { + /*Glyph found*/ + if(font_i->monospace) return true; + return false; + } + + font_i = font_i->next_page; + } + + return 0; +} + +/** + * Return with the bitmap of a font. + * @param font_p pointer to a font + * @param letter an UNICODE character code + * @return pointer to the bitmap of the letter + */ +const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter) +{ + const lv_font_t * font_i = font_p; + while(font_i != NULL) { + const uint8_t * bitmap = font_i->get_bitmap(font_i, letter); + if(bitmap) return bitmap; + + font_i = font_i->next_page; + } + + return NULL; +} + +/** + * Get the width of a letter in a font. If `monospace` is set then return with it. + * @param font_p pointer to a font + * @param letter an UNICODE character code + * @return the width of a letter + */ +uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter) +{ + const lv_font_t * font_i = font_p; + int16_t w; + while(font_i != NULL) { + w = font_i->get_width(font_i, letter); + if(w >= 0) { + /*Glyph found*/ + uint8_t m = font_i->monospace; + if(m) w = m; + return w; + } + + font_i = font_i->next_page; + } + + return 0; + +} + +/** + * Get the width of the letter without overwriting it with the `monospace` attribute + * @param font_p pointer to a font + * @param letter an UNICODE character code + * @return the width of a letter + */ +uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter) +{ + const lv_font_t * font_i = font_p; + int16_t w; + while(font_i != NULL) { + w = font_i->get_width(font_i, letter); + if(w >= 0) return w; + + font_i = font_i->next_page; + } + + return 0; +} + +/** + * Get the bit-per-pixel of font + * @param font pointer to font + * @param letter a letter from font (font extensions can have different bpp) + * @return bpp of the font (or font extension) + */ +uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter) +{ + const lv_font_t * font_i = font; + while(font_i != NULL) { + if(letter >= font_i->unicode_first && letter <= font_i->unicode_last) { + return font_i->bpp; + } + font_i = font_i->next_page; + } + + return 0; + +} + +/** + * Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range + * @param font pointer to font + * @param unicode_letter an unicode letter which bitmap should be get + * @return pointer to the bitmap or NULL if not found + */ +const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter) +{ + /*Check the range*/ + if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL; + + uint32_t index = (unicode_letter - font->unicode_first); + return &font->glyph_bitmap[font->glyph_dsc[index].glyph_index]; +} + +/** + * Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse) + * @param font pointer to font + * @param unicode_letter an unicode letter which bitmap should be get + * @return pointer to the bitmap or NULL if not found + */ +const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter) +{ + /*Check the range*/ + if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL; + + uint32_t i; + for(i = 0; font->unicode_list[i] != 0; i++) { + if(font->unicode_list[i] == unicode_letter) { + return &font->glyph_bitmap[font->glyph_dsc[i].glyph_index]; + } + } + + return NULL; +} + +/** + * Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range + * @param font pointer to font + * @param unicode_letter an unicode letter which width should be get + * @return width of the gylph or -1 if not found + */ +int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter) +{ + /*Check the range*/ + if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) { + return -1; + } + + uint32_t index = (unicode_letter - font->unicode_first); + return font->glyph_dsc[index].w_px; +} + +/** + * Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse) + * @param font pointer to font + * @param unicode_letter an unicode letter which width should be get + * @return width of the glyph or -1 if not found + */ +int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter) +{ + /*Check the range*/ + if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return -1; + + uint32_t i; + for(i = 0; font->unicode_list[i] != 0; i++) { + if(font->unicode_list[i] == unicode_letter) { + return font->glyph_dsc[i].w_px; + } + } + + return -1; +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.h new file mode 100644 index 0000000..047de22 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_font.h @@ -0,0 +1,191 @@ +/** + * @file lv_font.h + * + */ + +#ifndef LV_FONT_H +#define LV_FONT_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include +#include + +#include "lv_symbol_def.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct +{ + uint32_t w_px :8; + uint32_t glyph_index :24; +} lv_font_glyph_dsc_t; + +typedef struct +{ + uint32_t unicode :21; + uint32_t glyph_dsc_index :11; +} lv_font_unicode_map_t; + +typedef struct _lv_font_struct +{ + uint32_t unicode_first; + uint32_t unicode_last; + const uint8_t * glyph_bitmap; + const lv_font_glyph_dsc_t * glyph_dsc; + const uint32_t * unicode_list; + const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's bitmap from a font*/ + int16_t (*get_width)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's with with a given font*/ + struct _lv_font_struct * next_page; /*Pointer to a font extension*/ + uint32_t h_px :8; + uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/ + uint32_t monospace :8; /*Fix width (0: normal width)*/ + uint16_t glyph_cnt; /*Number of glyphs (letters) in the font*/ +} lv_font_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the fonts + */ +void lv_font_init(void); + +/** + * Add a font to an other to extend the character set. + * @param child the font to add + * @param parent this font will be extended. Using it later will contain the characters from `child` + */ +void lv_font_add(lv_font_t *child, lv_font_t *parent); + +/** + * Remove a font from a character set. + * @param child the font to remove + * @param parent remove `child` from here + */ +void lv_font_remove(lv_font_t * child, lv_font_t * parent); + +/** + * Tells if font which contains `letter` is monospace or not + * @param font_p point to font + * @param letter an UNICODE character code + * @return true: the letter is monospace; false not monospace + */ +bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter); + +/** + * Return with the bitmap of a font. + * @param font_p pointer to a font + * @param letter an UNICODE character code + * @return pointer to the bitmap of the letter + */ +const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter); + +/** + * Get the width of a letter in a font. If `monospace` is set then return with it. + * @param font_p pointer to a font + * @param letter an UNICODE character code + * @return the width of a letter + */ +uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter); + + +/** + * Get the width of the letter without overwriting it with the `monospace` attribute + * @param font_p pointer to a font + * @param letter an UNICODE character code + * @return the width of a letter + */ +uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter); + +/** + * Get the height of a font + * @param font_p pointer to a font + * @return the height of a font + */ +static inline uint8_t lv_font_get_height(const lv_font_t * font_p) +{ + return font_p->h_px; +} + +/** + * Get the bit-per-pixel of font + * @param font pointer to font + * @param letter a letter from font (font extensions can have different bpp) + * @return bpp of the font (or font extension) + */ +uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter); + +/** + * Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range + * @param font pointer to font + * @param unicode_letter an unicode letter which bitmap should be get + * @return pointer to the bitmap or NULL if not found + */ +const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter); + +/** + * Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse) + * @param font pointer to font + * @param unicode_letter an unicode letter which bitmap should be get + * @return pointer to the bitmap or NULL if not found + */ +const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter); +/** + * Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range + * @param font pointer to font + * @param unicode_letter an unicode letter which width should be get + * @return width of the gylph or -1 if not found + */ +int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter); + +/** + * Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse) + * @param font pointer to font + * @param unicode_letter an unicode letter which width should be get + * @return width of the glyph or -1 if not found + */ +int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter); + +/********************** + * MACROS + **********************/ + +#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name; + + +/********************** + * ADD BUILT IN FONTS + **********************/ +#include "../lv_fonts/lv_font_builtin.h" + +/*Declare the custom (user defined) fonts*/ +#ifdef LV_FONT_CUSTOM_DECLARE +LV_FONT_CUSTOM_DECLARE +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*USE_FONT*/ + diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.c new file mode 100644 index 0000000..1828e39 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.c @@ -0,0 +1,627 @@ +/** + * @file lv_fs.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_fs.h" +#if USE_LV_FILESYSTEM + +#include "lv_ll.h" +#include +#include "lv_gc.h" + +#if defined(LV_GC_INCLUDE) +# include LV_GC_INCLUDE +#endif /* LV_ENABLE_GC */ + +/********************* + * DEFINES + *********************/ + +/* "free" is used as a function pointer (in lv_fs_drv_t). + * We must make sure "free" was not defined to a platform specific + * free function, otherwise compilation would fail. + */ +#ifdef free +#undef free +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static const char * lv_fs_get_real_path(const char * path); +static lv_fs_drv_t * lv_fs_get_drv(char letter); + + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the File system interface + */ +void lv_fs_init(void) +{ + lv_ll_init(&LV_GC_ROOT(_lv_drv_ll), sizeof(lv_fs_drv_t)); +} + +/** + * Test if a drive is rady or not. If the `ready` function was not initialized `true` will be returned. + * @param letter letter of the drive + * @return true: drive is ready; false: drive is not ready + */ +bool lv_fs_is_ready(char letter) +{ + lv_fs_drv_t * drv = lv_fs_get_drv(letter); + + if(drv == NULL) return false; /*An unknown driver in not ready*/ + + if(drv->ready == NULL) return true; /*Assume the driver is always ready if no handler provided*/ + + return drv->ready(); +} + +/** + * Open a file + * @param file_p pointer to a lv_fs_file_t variable + * @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt) + * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode) +{ + file_p->drv = NULL; + file_p->file_d = NULL; + + if(path == NULL) return LV_FS_RES_INV_PARAM; + + char letter = path[0]; + + file_p->drv = lv_fs_get_drv(letter); + + if(file_p->drv == NULL) { + file_p->file_d = NULL; + return LV_FS_RES_NOT_EX; + } + + if(file_p->drv->ready != NULL) { + if(file_p->drv->ready() == false) { + file_p->drv = NULL; + file_p->file_d = NULL; + return LV_FS_RES_HW_ERR; + } + } + + file_p->file_d = lv_mem_alloc(file_p->drv->file_size); + lv_mem_assert(file_p->file_d); + if(file_p->file_d == NULL) { + file_p->drv = NULL; + return LV_FS_RES_OUT_OF_MEM; /* Out of memory */ + } + + if(file_p->drv->open == NULL) { + return LV_FS_RES_NOT_IMP; + } + + const char * real_path = lv_fs_get_real_path(path); + lv_fs_res_t res = file_p->drv->open(file_p->file_d, real_path, mode); + + if(res != LV_FS_RES_OK) { + lv_mem_free(file_p->file_d); + file_p->file_d = NULL; + file_p->drv = NULL; + } + + return res; +} + +/** + * Close an already opened file + * @param file_p pointer to a lv_fs_file_t variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_close(lv_fs_file_t * file_p) +{ + if(file_p->drv == NULL) { + return LV_FS_RES_INV_PARAM; + } + + if(file_p->drv->close == NULL) { + return LV_FS_RES_NOT_IMP; + } + + lv_fs_res_t res = file_p->drv->close(file_p->file_d); + + lv_mem_free(file_p->file_d); /*Clean up*/ + file_p->file_d = NULL; + file_p->drv = NULL; + file_p->file_d = NULL; + + return res; +} + +/** + * Delete a file + * @param path path of the file to delete + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_remove(const char * path) +{ + if(path == NULL) return LV_FS_RES_INV_PARAM; + lv_fs_drv_t * drv = NULL; + + char letter = path[0]; + + drv = lv_fs_get_drv(letter); + if(drv == NULL) return LV_FS_RES_NOT_EX; + if(drv->ready != NULL) { + if(drv->ready() == false) return LV_FS_RES_HW_ERR; + } + + if(drv->remove == NULL) return LV_FS_RES_NOT_IMP; + + const char * real_path = lv_fs_get_real_path(path); + lv_fs_res_t res = drv->remove(real_path); + + return res; +} + +/** + * Read from a file + * @param file_p pointer to a lv_fs_file_t variable + * @param buf pointer to a buffer where the read bytes are stored + * @param btr Bytes To Read + * @param br the number of real read bytes (Bytes Read). NULL if unused. + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_read(lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br) +{ + if(br != NULL) *br = 0; + if(file_p->drv == NULL) return LV_FS_RES_INV_PARAM; + if(file_p->drv->read == NULL) return LV_FS_RES_NOT_IMP; + + uint32_t br_tmp = 0; + lv_fs_res_t res = file_p->drv->read(file_p->file_d, buf, btr, &br_tmp); + if(br != NULL) *br = br_tmp; + + return res; +} + +/** + * Write into a file + * @param file_p pointer to a lv_fs_file_t variable + * @param buf pointer to a buffer with the bytes to write + * @param btr Bytes To Write + * @param br the number of real written bytes (Bytes Written). NULL if unused. + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_write(lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw) +{ + if(bw != NULL) *bw = 0; + + if(file_p->drv == NULL) { + return LV_FS_RES_INV_PARAM; + } + + if(file_p->drv->write == NULL) { + return LV_FS_RES_NOT_IMP; + } + + uint32_t bw_tmp = 0; + lv_fs_res_t res = file_p->drv->write(file_p->file_d, buf, btw, &bw_tmp); + if(bw != NULL) *bw = bw_tmp; + + return res; +} + +/** + * Set the position of the 'cursor' (read write pointer) in a file + * @param file_p pointer to a lv_fs_file_t variable + * @param pos the new position expressed in bytes index (0: start of file) + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_seek(lv_fs_file_t * file_p, uint32_t pos) +{ + if(file_p->drv == NULL) { + return LV_FS_RES_INV_PARAM; + } + + if(file_p->drv->seek == NULL) { + return LV_FS_RES_NOT_IMP; + } + + lv_fs_res_t res = file_p->drv->seek(file_p->file_d, pos); + + return res; +} + +/** + * Give the position of the read write pointer + * @param file_p pointer to a lv_fs_file_t variable + * @param pos_p pointer to store the position of the read write pointer + * @return LV_FS_RES_OK or any error from 'fs_res_t' + */ +lv_fs_res_t lv_fs_tell(lv_fs_file_t * file_p, uint32_t * pos) +{ + if(file_p->drv == NULL) { + pos = 0; + return LV_FS_RES_INV_PARAM; + } + + if(file_p->drv->tell == NULL) { + pos = 0; + return LV_FS_RES_NOT_IMP; + } + + lv_fs_res_t res = file_p->drv->tell(file_p->file_d, pos); + + return res; +} + +/** + * Truncate the file size to the current position of the read write pointer + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open ) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_trunc(lv_fs_file_t * file_p) +{ + if(file_p->drv == NULL) { + return LV_FS_RES_INV_PARAM; + } + + if(file_p->drv->tell == NULL) { + return LV_FS_RES_NOT_IMP; + } + + lv_fs_res_t res = file_p->drv->trunc(file_p->file_d); + + return res; +} +/** + * Give the size of a file bytes + * @param file_p pointer to a lv_fs_file_t variable + * @param size pointer to a variable to store the size + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_size(lv_fs_file_t * file_p, uint32_t * size) +{ + if(file_p->drv == NULL) { + return LV_FS_RES_INV_PARAM; + } + + if(file_p->drv->size == NULL) return LV_FS_RES_NOT_IMP; + + + if(size == NULL) return LV_FS_RES_INV_PARAM; + + lv_fs_res_t res = file_p->drv->size(file_p->file_d, size); + + return res; +} + +/** + * Rename a file + * @param oldname path to the file + * @param newname path with the new name + * @return LV_FS_RES_OK or any error from 'fs_res_t' + */ +lv_fs_res_t lv_fs_rename(const char * oldname, const char * newname) +{ + if(!oldname || !newname) return LV_FS_RES_INV_PARAM; + + char letter = oldname[0]; + + lv_fs_drv_t * drv = lv_fs_get_drv(letter); + + if(!drv) { + return LV_FS_RES_NOT_EX; + } + + if(drv->ready != NULL) { + if(drv->ready() == false) { + return LV_FS_RES_HW_ERR; + } + } + + if(drv->rename == NULL) return LV_FS_RES_NOT_IMP; + + const char * old_real = lv_fs_get_real_path(oldname); + const char * new_real = lv_fs_get_real_path(newname); + lv_fs_res_t res = drv->rename(old_real, new_real); + + return res; +} + + +/** + * Initialize a 'fs_read_dir_t' variable for directory reading + * @param rddir_p pointer to a 'fs_read_dir_t' variable + * @param path path to a directory + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path) +{ + if(path == NULL) return LV_FS_RES_INV_PARAM; + + char letter = path[0]; + + rddir_p->drv = lv_fs_get_drv(letter); + + if(rddir_p->drv == NULL) { + rddir_p->dir_d = NULL; + return LV_FS_RES_NOT_EX; + } + + rddir_p->dir_d = lv_mem_alloc(rddir_p->drv->rddir_size); + lv_mem_assert(rddir_p->dir_d); + if(rddir_p->dir_d == NULL) { + rddir_p->dir_d = NULL; + return LV_FS_RES_OUT_OF_MEM; /* Out of memory */ + } + + if(rddir_p->drv->dir_open == NULL) { + return LV_FS_RES_NOT_IMP; + } + + const char * real_path = lv_fs_get_real_path(path); + lv_fs_res_t res = rddir_p->drv->dir_open(rddir_p->dir_d, real_path); + + return res; +} + +/** + * Read the next filename form a directory. + * The name of the directories will begin with '/' + * @param rddir_p pointer to an initialized 'fs_read_dir_t' variable + * @param fn pointer to a buffer to store the filename + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t * rddir_p, char * fn) +{ + if(rddir_p->drv == NULL || rddir_p->dir_d == NULL) { + fn[0] = '\0'; + return LV_FS_RES_INV_PARAM; + } + + if(rddir_p->drv->dir_read == NULL) { + return LV_FS_RES_NOT_IMP; + } + + lv_fs_res_t res = rddir_p->drv->dir_read(rddir_p->dir_d, fn); + + return res; +} + +/** + * Close the directory reading + * @param rddir_p pointer to an initialized 'fs_read_dir_t' variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p) +{ + if(rddir_p->drv == NULL || rddir_p->dir_d == NULL) { + return LV_FS_RES_INV_PARAM; + } + + lv_fs_res_t res; + + if(rddir_p->drv->dir_close == NULL) { + res = LV_FS_RES_NOT_IMP; + } else { + res = rddir_p->drv->dir_close(rddir_p->dir_d); + } + + lv_mem_free(rddir_p->dir_d); /*Clean up*/ + rddir_p->dir_d = NULL; + rddir_p->drv = NULL; + rddir_p->dir_d = NULL; + + return res; +} + +/** + * Get the free and total size of a driver in kB + * @param letter the driver letter + * @param total_p pointer to store the total size [kB] + * @param free_p pointer to store the free size [kB] + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_free(char letter, uint32_t * total_p, uint32_t * free_p) +{ + lv_fs_drv_t * drv = lv_fs_get_drv(letter); + + if(drv == NULL) { + return LV_FS_RES_INV_PARAM; + } + + lv_fs_res_t res; + + if(drv->free == NULL) { + res = LV_FS_RES_NOT_IMP; + } else { + uint32_t total_tmp = 0; + uint32_t free_tmp = 0; + res = drv->free(&total_tmp, &free_tmp); + + if(total_p != NULL) *total_p = total_tmp; + if(free_p != NULL) *free_p = free_tmp; + } + + return res; +} + +/** + * Add a new drive + * @param drv_p pointer to an lv_fs_drv_t structure which is inited with the + * corresponding function pointers. The data will be copied so the variable can be local. + */ +void lv_fs_add_drv(lv_fs_drv_t * drv_p) +{ + /*Save the new driver*/ + lv_fs_drv_t * new_drv; + new_drv = lv_ll_ins_head(&LV_GC_ROOT(_lv_drv_ll)); + lv_mem_assert(new_drv); + if(new_drv == NULL) return; + + memcpy(new_drv, drv_p, sizeof(lv_fs_drv_t)); +} + +/** + * Fill a buffer with the letters of existing drivers + * @param buf buffer to store the letters ('\0' added after the last letter) + * @return the buffer + */ +char * lv_fs_get_letters(char * buf) +{ + lv_fs_drv_t * drv; + uint8_t i = 0; + + LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) { + buf[i] = drv->letter; + i++; + } + + buf[i] = '\0'; + + return buf; +} + + +/** + * Return with the extension of the filename + * @param fn string with a filename + * @return pointer to the beginning extension or empty string if no extension + */ +const char * lv_fs_get_ext(const char * fn) +{ + uint16_t i; + for(i = strlen(fn); i > 0; i --) { + if(fn[i] == '.') { + return &fn[i + 1]; + } else if(fn[i] == '/' || fn[i] == '\\') { + return ""; /*No extension if a '\' or '/' found*/ + } + } + + return ""; /*Empty string if no '.' in the file name. */ +} + +/** + * Step up one level + * @param path pointer to a file name + * @return the truncated file name + */ +char * lv_fs_up(char * path) +{ + uint16_t len = strlen(path); + if(len == 0) return path; + + len --; /*Go before the trailing '\0'*/ + + /*Ignore trailing '/' or '\'*/ + while(path[len] == '/' || path[len] == '\\') { + path[len] = '\0'; + if(len > 0) len --; + else return path; + } + + uint16_t i; + for(i = len; i > 0; i --) { + if(path[i] == '/' || path[i] == '\\') break; + } + + if(i > 0) path[i] = '\0'; + + return path; +} + +/** + * Get the last element of a path (e.g. U:/folder/file -> file) + * @param path a character sting with the path to search in + * @return pointer to the beginning of the last element in the path + */ +const char * lv_fs_get_last(const char * path) +{ + uint16_t len = strlen(path); + if(len == 0) return path; + + len --; /*Go before the trailing '\0'*/ + + /*Ignore trailing '/' or '\'*/ + while(path[len] == '/' || path[len] == '\\') { + if(len > 0) len --; + else return path; + } + + uint16_t i; + for(i = len; i > 0; i --) { + if(path[i] == '/' || path[i] == '\\') break; + } + + /*No '/' or '\' in the path so return with path itself*/ + if(i == 0) return path; + + return &path[i + 1]; +} +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Leave the driver letters and / or \ letters from beginning of the path + * @param path path string (E.g. S:/folder/file.txt) + * @return pointer to the beginning of the real path (E.g. folder/file.txt) + */ +static const char * lv_fs_get_real_path(const char * path) +{ + /* Example path: "S:/folder/file.txt" + * Leave the letter and the : / \ characters*/ + + path ++; /*Ignore the driver letter*/ + + while(*path != '\0') { + if(*path == ':' || *path == '\\' || *path == '/') { + path ++; + } else { + break; + } + } + + return path; +} + +/** + * Give a pointer to a driver from its letter + * @param letter the driver letter + * @return pointer to a driver or NULL if not found + */ +static lv_fs_drv_t * lv_fs_get_drv(char letter) +{ + lv_fs_drv_t * drv; + + LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) { + if(drv->letter == letter) { + return drv; + } + } + + return NULL; +} + +#endif /*USE_LV_FILESYSTEM*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.h new file mode 100644 index 0000000..1eb2bfa --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_fs.h @@ -0,0 +1,276 @@ +/** + * @file lv_fs.h + * + */ + +#ifndef LV_FS_H +#define LV_FS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_FILESYSTEM + +#include +#include "lv_mem.h" + +/********************* + * DEFINES + *********************/ +#define LV_FS_MAX_FN_LENGTH 64 + +/********************** + * TYPEDEFS + **********************/ +enum +{ + LV_FS_RES_OK = 0, + LV_FS_RES_HW_ERR, /*Low level hardware error*/ + LV_FS_RES_FS_ERR, /*Error in the file system structure */ + LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/ + LV_FS_RES_FULL, /*Disk full*/ + LV_FS_RES_LOCKED, /*The file is already opened*/ + LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/ + LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/ + LV_FS_RES_TOUT, /*Process time outed*/ + LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/ + LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/ + LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/ + LV_FS_RES_UNKNOWN, /*Other unknown error*/ +}; +typedef uint8_t lv_fs_res_t; + +struct __lv_fs_drv_t; + +typedef struct +{ + void * file_d; + struct __lv_fs_drv_t* drv; +} lv_fs_file_t; + + +typedef struct +{ + void * dir_d; + struct __lv_fs_drv_t * drv; +} lv_fs_dir_t; + +enum +{ + LV_FS_MODE_WR = 0x01, + LV_FS_MODE_RD = 0x02, +}; +typedef uint8_t lv_fs_mode_t; + +typedef struct __lv_fs_drv_t +{ + char letter; + uint16_t file_size; + uint16_t rddir_size; + bool (*ready) (void); + + lv_fs_res_t (*open) (void * file_p, const char * path, lv_fs_mode_t mode); + lv_fs_res_t (*close) (void * file_p); + lv_fs_res_t (*remove) (const char * fn); + lv_fs_res_t (*read) (void * file_p, void * buf, uint32_t btr, uint32_t * br); + lv_fs_res_t (*write) (void * file_p, const void * buf, uint32_t btw, uint32_t * bw); + lv_fs_res_t (*seek) (void * file_p, uint32_t pos); + lv_fs_res_t (*tell) (void * file_p, uint32_t * pos_p); + lv_fs_res_t (*trunc) (void * file_p); + lv_fs_res_t (*size) (void * file_p, uint32_t * size_p); + lv_fs_res_t (*rename) (const char * oldname, const char * newname); + lv_fs_res_t (*free) (uint32_t * total_p, uint32_t * free_p); + + lv_fs_res_t (*dir_open) (void * rddir_p, const char * path); + lv_fs_res_t (*dir_read) (void * rddir_p, char * fn); + lv_fs_res_t (*dir_close) (void * rddir_p); +} lv_fs_drv_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the File system interface + */ +void lv_fs_init(void); + +/** + * Add a new drive + * @param drv_p pointer to an lv_fs_drv_t structure which is inited with the + * corresponding function pointers. The data will be copied so the variable can be local. + */ +void lv_fs_add_drv(lv_fs_drv_t * drv_p); + +/** + * Test if a drive is rady or not. If the `ready` function was not initialized `true` will be returned. + * @param letter letter of the drive + * @return true: drive is ready; false: drive is not ready + */ +bool lv_fs_is_ready(char letter); + +/** + * Open a file + * @param file_p pointer to a lv_fs_file_t variable + * @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt) + * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_open (lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode); + +/** + * Close an already opened file + * @param file_p pointer to a lv_fs_file_t variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_close (lv_fs_file_t * file_p); + +/** + * Delete a file + * @param path path of the file to delete + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_remove (const char * path); + +/** + * Read from a file + * @param file_p pointer to a lv_fs_file_t variable + * @param buf pointer to a buffer where the read bytes are stored + * @param btr Bytes To Read + * @param br the number of real read bytes (Bytes Read). NULL if unused. + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_read (lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br); + +/** + * Write into a file + * @param file_p pointer to a lv_fs_file_t variable + * @param buf pointer to a buffer with the bytes to write + * @param btr Bytes To Write + * @param br the number of real written bytes (Bytes Written). NULL if unused. + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_write (lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw); + +/** + * Set the position of the 'cursor' (read write pointer) in a file + * @param file_p pointer to a lv_fs_file_t variable + * @param pos the new position expressed in bytes index (0: start of file) + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_seek (lv_fs_file_t * file_p, uint32_t pos); + +/** + * Give the position of the read write pointer + * @param file_p pointer to a lv_fs_file_t variable + * @param pos_p pointer to store the position of the read write pointer + * @return LV_FS_RES_OK or any error from 'fs_res_t' + */ +lv_fs_res_t lv_fs_tell (lv_fs_file_t * file_p, uint32_t * pos); + +/** + * Truncate the file size to the current position of the read write pointer + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open ) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_trunc (lv_fs_file_t * file_p); + +/** + * Give the size of a file bytes + * @param file_p pointer to a lv_fs_file_t variable + * @param size pointer to a variable to store the size + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_size (lv_fs_file_t * file_p, uint32_t * size); + +/** + * Rename a file + * @param oldname path to the file + * @param newname path with the new name + * @return LV_FS_RES_OK or any error from 'fs_res_t' + */ +lv_fs_res_t lv_fs_rename (const char * oldname, const char * newname); + +/** + * Initialize a 'fs_dir_t' variable for directory reading + * @param rddir_p pointer to a 'fs_read_dir_t' variable + * @param path path to a directory + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path); + +/** + * Read the next filename form a directory. + * The name of the directories will begin with '/' + * @param rddir_p pointer to an initialized 'fs_rdir_t' variable + * @param fn pointer to a buffer to store the filename + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_read (lv_fs_dir_t * rddir_p, char * fn); + +/** + * Close the directory reading + * @param rddir_p pointer to an initialized 'fs_dir_t' variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_close (lv_fs_dir_t * rddir_p); + +/** + * Get the free and total size of a driver in kB + * @param letter the driver letter + * @param total_p pointer to store the total size [kB] + * @param free_p pointer to store the free size [kB] + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_free (char letter, uint32_t * total_p, uint32_t * free_p); + +/** + * Fill a buffer with the letters of existing drivers + * @param buf buffer to store the letters ('\0' added after the last letter) + * @return the buffer + */ +char * lv_fs_get_letters(char * buf); + +/** + * Return with the extension of the filename + * @param fn string with a filename + * @return pointer to the beginning extension or empty string if no extension + */ +const char * lv_fs_get_ext(const char * fn); + +/** + * Step up one level + * @param path pointer to a file name + * @return the truncated file name + */ +char * lv_fs_up(char * path); + +/** + * Get the last element of a path (e.g. U:/folder/file -> file) + * @param buf buffer to store the letters ('\0' added after the last letter) + * @return pointer to the beginning of the last element in the path + */ +const char * lv_fs_get_last(const char * path); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_FILESYSTEM*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_FS_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.c new file mode 100644 index 0000000..71effb6 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.c @@ -0,0 +1,40 @@ +/** + * @file lv_gc.c + * + */ + +/********************* + * INCLUDES + *********************/ + +#include "lv_gc.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +#if (!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0 +LV_ROOTS +#endif /* LV_ENABLE_GC */ +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.h new file mode 100644 index 0000000..78e4ef5 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_gc.h @@ -0,0 +1,76 @@ +/** + * @file lv_gc.h + * + */ + +#ifndef LV_GC_H +#define LV_GC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include +#include "lv_mem.h" +#include "lv_ll.h" + +/********************* + * DEFINES + *********************/ + +#define LV_GC_ROOTS(prefix) \ + prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \ + prefix lv_ll_t _lv_scr_ll; /*Linked list of screens*/ \ + prefix lv_ll_t _lv_drv_ll;\ + prefix lv_ll_t _lv_file_ll;\ + prefix lv_ll_t _lv_anim_ll;\ + prefix void * _lv_def_scr;\ + prefix void * _lv_act_scr;\ + prefix void * _lv_top_layer;\ + prefix void * _lv_sys_layer;\ + prefix void * _lv_task_act;\ + prefix void * _lv_indev_list;\ + prefix void * _lv_disp_list;\ + + +#define LV_NO_PREFIX +#define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX) + +#if LV_ENABLE_GC == 1 +# if LV_MEM_CUSTOM != 1 +# error "GC requires CUSTOM_MEM" +# endif /* LV_MEM_CUSTOM */ +#else /* LV_ENABLE_GC */ +# define LV_GC_ROOT(x) x + LV_GC_ROOTS(extern) +#endif /* LV_ENABLE_GC */ + + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_GC_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.c new file mode 100644 index 0000000..43d8847 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.c @@ -0,0 +1,376 @@ +/** + * @file lv_ll.c + * Handle linked lists. + * The nodes are dynamically allocated by the 'lv_mem' module, + */ + +/********************* + * INCLUDES + *********************/ +#include +#include + +#include "lv_ll.h" +#include "lv_mem.h" + +/********************* + * DEFINES + *********************/ +#define LL_NODE_META_SIZE (sizeof(lv_ll_node_t*) + sizeof(lv_ll_node_t*)) +#define LL_PREV_P_OFFSET(ll_p) (ll_p->n_size) +#define LL_NEXT_P_OFFSET(ll_p) (ll_p->n_size + sizeof(lv_ll_node_t*)) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void node_set_prev(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * prev); +static void node_set_next(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * next); + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize linked list + * @param ll_dsc pointer to ll_dsc variable + * @param node_size the size of 1 node in bytes + */ +void lv_ll_init(lv_ll_t * ll_p, uint32_t node_size) +{ + ll_p->head = NULL; + ll_p->tail = NULL; +#ifdef LV_MEM_ENV64 + /*Round the size up to 8*/ + if(node_size & 0x7) { + node_size = node_size & (~0x7); + node_size += 8; + } +#else + /*Round the size up to 4*/ + if(node_size & 0x3) { + node_size = node_size & (~0x3); + node_size += 4; + } +#endif + + ll_p->n_size = node_size; +} + +/** + * Add a new head to a linked list + * @param ll_p pointer to linked list + * @return pointer to the new head + */ +void * lv_ll_ins_head(lv_ll_t * ll_p) +{ + lv_ll_node_t * n_new; + + n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE); + + if(n_new != NULL) { + node_set_prev(ll_p, n_new, NULL); /*No prev. before the new head*/ + node_set_next(ll_p, n_new, ll_p->head); /*After new comes the old head*/ + + if(ll_p->head != NULL) { /*If there is old head then before it goes the new*/ + node_set_prev(ll_p, ll_p->head, n_new); + } + + ll_p->head = n_new; /*Set the new head in the dsc.*/ + if(ll_p->tail == NULL) {/*If there is no tail (1. node) set the tail too*/ + ll_p->tail = n_new; + } + } + + return n_new; +} + +/** + * Insert a new node in front of the n_act node + * @param ll_p pointer to linked list + * @param n_act pointer a node + * @return pointer to the new head + */ +void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act) +{ + lv_ll_node_t * n_new; + lv_ll_node_t * n_prev; + + if(NULL == ll_p || NULL == n_act) return NULL; + + if(lv_ll_get_head(ll_p) == n_act) { + n_new = lv_ll_ins_head(ll_p); + if(n_new == NULL) return NULL; + } else { + n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE); + if(n_new == NULL) return NULL; + + n_prev = lv_ll_get_prev(ll_p, n_act); + node_set_next(ll_p, n_prev, n_new); + node_set_prev(ll_p, n_new, n_prev); + node_set_prev(ll_p, n_act, n_new); + node_set_next(ll_p, n_new, n_act); + } + + return n_new; +} + +/** + * Add a new tail to a linked list + * @param ll_p pointer to linked list + * @return pointer to the new tail + */ +void * lv_ll_ins_tail(lv_ll_t * ll_p) +{ + lv_ll_node_t * n_new; + + n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE); + if(n_new == NULL) return NULL; + + if(n_new != NULL) { + node_set_next(ll_p, n_new, NULL); /*No next after the new tail*/ + node_set_prev(ll_p, n_new, ll_p->tail); /*The prev. before new is tho old tail*/ + if(ll_p->tail != NULL) { /*If there is old tail then the new comes after it*/ + node_set_next(ll_p, ll_p->tail, n_new); + } + + ll_p->tail = n_new; /*Set the new tail in the dsc.*/ + if(ll_p->head == NULL) { /*If there is no head (1. node) set the head too*/ + ll_p->head = n_new; + } + } + + return n_new; +} + + +/** + * Remove the node 'node_p' from 'll_p' linked list. + * It does not free the the memory of node. + * @param ll_p pointer to the linked list of 'node_p' + * @param node_p pointer to node in 'll_p' linked list + */ +void lv_ll_rem(lv_ll_t * ll_p, void * node_p) +{ + if(lv_ll_get_head(ll_p) == node_p) { + /*The new head will be the node after 'n_act'*/ + ll_p->head = lv_ll_get_next(ll_p, node_p); + if(ll_p->head == NULL) { + ll_p->tail = NULL; + } else { + node_set_prev(ll_p, ll_p->head, NULL); + } + } else if(lv_ll_get_tail(ll_p) == node_p) { + /*The new tail will be the node before 'n_act'*/ + ll_p->tail = lv_ll_get_prev(ll_p, node_p); + if(ll_p->tail == NULL) { + ll_p->head = NULL; + } else { + node_set_next(ll_p, ll_p->tail, NULL); + } + } else { + lv_ll_node_t * n_prev = lv_ll_get_prev(ll_p, node_p); + lv_ll_node_t * n_next = lv_ll_get_next(ll_p, node_p); + + node_set_next(ll_p, n_prev, n_next); + node_set_prev(ll_p, n_next, n_prev); + } +} + +/** + * Remove and free all elements from a linked list. The list remain valid but become empty. + * @param ll_p pointer to linked list + */ +void lv_ll_clear(lv_ll_t * ll_p) +{ + void * i; + void * i_next; + + i = lv_ll_get_head(ll_p); + i_next = NULL; + + while(i != NULL) { + i_next = lv_ll_get_next(ll_p, i); + + lv_ll_rem(ll_p, i); + lv_mem_free(i); + + i = i_next; + } +} + +/** + * Move a node to a new linked list + * @param ll_ori_p pointer to the original (old) linked list + * @param ll_new_p pointer to the new linked list + * @param node pointer to a node + */ +void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node) +{ + lv_ll_rem(ll_ori_p, node); + + /*Set node as head*/ + node_set_prev(ll_new_p, node, NULL); + node_set_next(ll_new_p, node, ll_new_p->head); + + if(ll_new_p->head != NULL) { /*If there is old head then before it goes the new*/ + node_set_prev(ll_new_p, ll_new_p->head, node); + } + + ll_new_p->head = node; /*Set the new head in the dsc.*/ + if(ll_new_p->tail == NULL) { /*If there is no tail (first node) set the tail too*/ + ll_new_p->tail = node; + } +} + +/** + * Return with head node of the linked list + * @param ll_p pointer to linked list + * @return pointer to the head of 'll_p' + */ +void * lv_ll_get_head(const lv_ll_t * ll_p) +{ + void * head = NULL; + + if(ll_p != NULL) { + head = ll_p->head; + } + + return head; +} + +/** + * Return with tail node of the linked list + * @param ll_p pointer to linked list + * @return pointer to the head of 'll_p' + */ +void * lv_ll_get_tail(const lv_ll_t * ll_p) +{ + void * tail = NULL; + + if(ll_p != NULL) { + tail = ll_p->tail; + } + + return tail; +} + +/** + * Return with the pointer of the next node after 'n_act' + * @param ll_p pointer to linked list + * @param n_act pointer a node + * @return pointer to the next node + */ +void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act) +{ + void * next = NULL; + + if(ll_p != NULL) { + const lv_ll_node_t * n_act_d = n_act; + memcpy(&next, n_act_d + LL_NEXT_P_OFFSET(ll_p), sizeof(void *)); + } + + return next; +} + +/** + * Return with the pointer of the previous node after 'n_act' + * @param ll_p pointer to linked list + * @param n_act pointer a node + * @return pointer to the previous node + */ +void * lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act) +{ + void * prev = NULL; + + if(ll_p != NULL) { + const lv_ll_node_t * n_act_d = n_act; + memcpy(&prev, n_act_d + LL_PREV_P_OFFSET(ll_p), sizeof(void *)); + } + + return prev; +} + +void lv_ll_swap(lv_ll_t * ll_p, void * n1_p, void * n2_p) +{ + (void)(ll_p); + (void)(n1_p); + (void)(n2_p); + /*TODO*/ +} + +/** + * Move a nodw before an other node in the same linked list + * @param ll_p pointer to a linked list + * @param n_act pointer to node to move + * @param n_after pointer to a node which should be after `n_act` + */ +void lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after) +{ + if(n_act == n_after) return; /*Can't move before itself*/ + + + void * n_before; + if(n_after != NULL) n_before = lv_ll_get_prev(ll_p, n_after); + else n_before = lv_ll_get_tail(ll_p); /*if `n_after` is NULL `n_act` should be the new tail*/ + + if(n_act == n_before) return; /*Already before `n_after`*/ + + /*It's much easier to remove from the list and add again*/ + lv_ll_rem(ll_p, n_act); + + /*Add again by setting the prev. and next nodes*/ + node_set_next(ll_p, n_before, n_act); + node_set_prev(ll_p, n_act, n_before); + node_set_prev(ll_p, n_after, n_act); + node_set_next(ll_p, n_act, n_after); + + /*If `n_act` was moved before NULL then it become the new tail*/ + if(n_after == NULL) ll_p->tail = n_act; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Set the 'pervious node pointer' of a node + * @param ll_p pointer to linked list + * @param act pointer to a node which prev. node pointer should be set + * @param prev pointer to a node which should be the previous node before 'act' + */ +static void node_set_prev(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * prev) +{ + if(act == NULL) return; /*Can't set the prev node of `NULL`*/ + + uint32_t node_p_size = sizeof(lv_ll_node_t *); + if(prev) memcpy(act + LL_PREV_P_OFFSET(ll_p), &prev, node_p_size); + else memset(act + LL_PREV_P_OFFSET(ll_p), 0, node_p_size); +} + +/** + * Set the 'next node pointer' of a node + * @param ll_p pointer to linked list + * @param act pointer to a node which next node pointer should be set + * @param next pointer to a node which should be the next node before 'act' + */ +static void node_set_next(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * next) +{ + if(act == NULL) return; /*Can't set the next node of `NULL`*/ + + uint32_t node_p_size = sizeof(lv_ll_node_t *); + if(next) memcpy(act + LL_NEXT_P_OFFSET(ll_p), &next, node_p_size); + else memset(act + LL_NEXT_P_OFFSET(ll_p), 0, node_p_size); +} + diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.h new file mode 100644 index 0000000..086ba40 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ll.h @@ -0,0 +1,145 @@ +/** + * @file lv_ll.c + * Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module. + */ + +#ifndef LV_LL_H +#define LV_LL_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#include "lv_mem.h" +#include +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Dummy type to make handling easier*/ +typedef uint8_t lv_ll_node_t; + +/*Description of a linked list*/ +typedef struct +{ + uint32_t n_size; + lv_ll_node_t* head; + lv_ll_node_t* tail; +} lv_ll_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize linked list + * @param ll_dsc pointer to ll_dsc variable + * @param node_size the size of 1 node in bytes + */ +void lv_ll_init(lv_ll_t * ll_p, uint32_t node_size); + +/** + * Add a new head to a linked list + * @param ll_p pointer to linked list + * @return pointer to the new head + */ +void * lv_ll_ins_head(lv_ll_t * ll_p); + +/** + * Insert a new node in front of the n_act node + * @param ll_p pointer to linked list + * @param n_act pointer a node + * @return pointer to the new head + */ +void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act); + +/** + * Add a new tail to a linked list + * @param ll_p pointer to linked list + * @return pointer to the new tail + */ +void * lv_ll_ins_tail(lv_ll_t * ll_p); + +/** + * Remove the node 'node_p' from 'll_p' linked list. + * It does not free the the memory of node. + * @param ll_p pointer to the linked list of 'node_p' + * @param node_p pointer to node in 'll_p' linked list + */ +void lv_ll_rem(lv_ll_t * ll_p, void * node_p); + +/** + * Remove and free all elements from a linked list. The list remain valid but become empty. + * @param ll_p pointer to linked list + */ +void lv_ll_clear(lv_ll_t * ll_p); + +/** + * Move a node to a new linked list + * @param ll_ori_p pointer to the original (old) linked list + * @param ll_new_p pointer to the new linked list + * @param node pointer to a node + */ +void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node); + +/** + * Return with head node of the linked list + * @param ll_p pointer to linked list + * @return pointer to the head of 'll_p' + */ +void * lv_ll_get_head(const lv_ll_t * ll_p); + +/** + * Return with tail node of the linked list + * @param ll_p pointer to linked list + * @return pointer to the head of 'll_p' + */ +void * lv_ll_get_tail(const lv_ll_t * ll_p); + +/** + * Return with the pointer of the next node after 'n_act' + * @param ll_p pointer to linked list + * @param n_act pointer a node + * @return pointer to the next node + */ +void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act); + +/** + * Return with the pointer of the previous node after 'n_act' + * @param ll_p pointer to linked list + * @param n_act pointer a node + * @return pointer to the previous node + */ +void * lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act); + +/** + * Move a nodw before an other node in the same linked list + * @param ll_p pointer to a linked list + * @param n_act pointer to node to move + * @param n_after pointer to a node which should be after `n_act` + */ +void lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after); + +/********************** + * MACROS + **********************/ + +#define LL_READ(list, i) for(i = lv_ll_get_head(&list); i != NULL; i = lv_ll_get_next(&list, i)) + +#define LL_READ_BACK(list, i) for(i = lv_ll_get_tail(&list); i != NULL; i = lv_ll_get_prev(&list, i)) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.c new file mode 100644 index 0000000..79f8113 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.c @@ -0,0 +1,82 @@ +/** + * @file lv_log.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_log.h" +#if USE_LV_LOG + +#if LV_LOG_PRINTF +#include +#include "../../../mem/heap.h" +#include "../../../soc/uart.h" +#include "../../../utils/sprintf.h" +#endif +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static void (*print_cb)(lv_log_level_t, const char *, uint32_t, const char *); + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Register custom print (or anything else) function to call when log is added + * @param f a function pointer: + * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` + */ +void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)) +{ + print_cb = f; +} + +/** + * Add a log + * @param level the level of log. (From `lv_log_level_t` enum) + * @param file name of the file when the log added + * @param line line number in the source code where the log added + * @param dsc description of the log + */ +void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc) +{ + if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/ + + if(level >= LV_LOG_LEVEL) { + +#if LV_LOG_PRINTF + static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"}; + char *log = (char *)malloc(0x1000); + s_printf(log, "%s: %s \t(%s #%d)\r\n", lvl_prefix[level], dsc, file, line); + uart_send(UART_B, (u8 *)log, strlen(log) + 1); + //gfx_printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line); +#else + if(print_cb) print_cb(level, file, line, dsc); +#endif + } +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif /*USE_LV_LOG*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.h new file mode 100644 index 0000000..8e99763 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_log.h @@ -0,0 +1,86 @@ +/** + * @file lv_log.h + * + */ + +#ifndef LV_LOG_H +#define LV_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif +#include + +/********************* + * DEFINES + *********************/ + +/*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/ + +#define LV_LOG_LEVEL_TRACE 0 /*A lot of logs to give detailed information*/ +#define LV_LOG_LEVEL_INFO 1 /*Log important events*/ +#define LV_LOG_LEVEL_WARN 2 /*Log if something unwanted happened but didn't caused problem*/ +#define LV_LOG_LEVEL_ERROR 3 /*Only critical issue, when the system may fail*/ +#define _LV_LOG_LEVEL_NUM 4 + +typedef int8_t lv_log_level_t; + +#if USE_LV_LOG +/********************** + * TYPEDEFS + **********************/ + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Register custom print (or anything else) function to call when log is added + * @param f a function pointer: + * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` + */ +void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)); + +/** + * Add a log + * @param level the level of log. (From `lv_log_level_t` enum) + * @param file name of the file when the log added + * @param line line number in the source code where the log added + * @param dsc description of the log + */ +void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc); + +/********************** + * MACROS + **********************/ + +#define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc); +#define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc); +#define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc); +#define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc); + +#else /*USE_LV_LOG*/ + +/*Do nothing if `USE_LV_LOG 0`*/ +#define lv_log_add(level, file, line, dsc) {;} +#define LV_LOG_TRACE(dsc) {;} +#define LV_LOG_INFO(dsc) {;} +#define LV_LOG_WARN(dsc) {;} +#define LV_LOG_ERROR(dsc) {;} +#endif /*USE_LV_LOG*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_LOG_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.c new file mode 100644 index 0000000..a0d2605 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.c @@ -0,0 +1,165 @@ +/** + * @file lv_math.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_math.h" +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static int16_t sin0_90_table[] = { + 0, 572, 1144, 1715, 2286, 2856, 3425, 3993, 4560, 5126, + 5690, 6252, 6813, 7371, 7927, 8481, 9032, 9580, 10126, 10668, + 11207, 11743, 12275, 12803, 13328, 13848, 14364, 14876, 15383, 15886, + 16383, 16876, 17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621, + 21062, 21497, 21925, 22347, 22762, 23170, 23571, 23964, 24351, 24730, + 25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087, + 28377, 28659, 28932, 29196, 29451, 29697, 29934, 30162, 30381, 30591, + 30791, 30982, 31163, 31335, 31498, 31650, 31794, 31927, 32051, 32165, + 32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762, + 32767 +}; + + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Convert a number to string + * @param num a number + * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) + * @return same as `buf` (just for convenience) + */ +char * lv_math_num_to_str(int32_t num, char * buf) +{ + char * buf_ori = buf; + if(num == 0) { + buf[0] = '0'; + buf[1] = '\0'; + return buf; + } else if(num < 0) { + (*buf) = '-'; + buf++; + num = LV_MATH_ABS(num); + } + uint32_t output = 0; + int8_t i; + + for(i = 31; i >= 0; i--) { + if((output & 0xF) >= 5) + output += 3; + if(((output & 0xF0) >> 4) >= 5) + output += (3 << 4); + if(((output & 0xF00) >> 8) >= 5) + output += (3 << 8); + if(((output & 0xF000) >> 12) >= 5) + output += (3 << 12); + if(((output & 0xF0000) >> 16) >= 5) + output += (3 << 16); + if(((output & 0xF00000) >> 20) >= 5) + output += (3 << 20); + if(((output & 0xF000000) >> 24) >= 5) + output += (3 << 24); + if(((output & 0xF0000000) >> 28) >= 5) + output += (3 << 28); + output = (output << 1) | ((num >> i) & 1); + } + + uint8_t digit; + bool leading_zero_ready = false; + for(i = 28; i >= 0; i -= 4) { + digit = ((output >> i) & 0xF) + '0'; + if(digit == '0' && leading_zero_ready == false) continue; + + leading_zero_ready = true; + (*buf) = digit; + buf++; + } + + (*buf) = '\0'; + + return buf_ori; +} + +/** + * Return with sinus of an angle + * @param angle + * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 + */ +int16_t lv_trigo_sin(int16_t angle) +{ + int16_t ret = 0; + angle = angle % 360; + + if(angle < 0) angle = 360 + angle; + + if(angle < 90) { + ret = sin0_90_table[angle]; + } else if(angle >= 90 && angle < 180) { + angle = 180 - angle; + ret = sin0_90_table[angle]; + } else if(angle >= 180 && angle < 270) { + angle = angle - 180; + ret = - sin0_90_table[angle]; + } else { /*angle >=270*/ + angle = 360 - angle; + ret = - sin0_90_table[angle]; + } + + return ret; +} + +/** + * Calculate a value of a Cubic Bezier function. + * @param t time in range of [0..LV_BEZIER_VAL_MAX] + * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] + * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] + * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] + * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] + * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] + */ +int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3) +{ + uint32_t t_rem = 1024 - t; + uint32_t t_rem2 = (t_rem * t_rem) >> 10; + uint32_t t_rem3 = (t_rem2 * t_rem) >> 10; + uint32_t t2 = (t * t) >> 10; + uint32_t t3 = (t2 * t) >> 10; + + + uint32_t v1 = ((uint32_t)t_rem3 * u0) >> 10; + uint32_t v2 = ((uint32_t)3 * t_rem2 * t * u1) >> 20; + uint32_t v3 = ((uint32_t)3 * t_rem * t2 * u2) >> 20; + uint32_t v4 = ((uint32_t)t3 * u3) >> 10; + + return v1 + v2 + v3 + v4; + +} + +/********************** + * STATIC FUNCTIONS + **********************/ + + diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.h new file mode 100644 index 0000000..a0229eb --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_math.h @@ -0,0 +1,73 @@ +/** + * @file math_base.h + * + */ + +#ifndef LV_MATH_H +#define LV_MATH_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#include + +/********************* + * DEFINES + *********************/ +#define LV_MATH_MIN(a,b) ((a) < (b) ? (a) : (b)) +#define LV_MATH_MAX(a,b) ((a) > (b) ? (a) : (b)) +#define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x))) + +#define LV_TRIGO_SIN_MAX 32767 +#define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/ + +#define LV_BEZIER_VAL_MAX 1024 /*Max time in Bezier functions (not [0..1] to use integers) */ +#define LV_BEZIER_VAL_SHIFT 10 /*log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +/** + * Convert a number to string + * @param num a number + * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) + * @return same as `buf` (just for convenience) + */ +char * lv_math_num_to_str(int32_t num, char * buf); + +/** + * Return with sinus of an angle + * @param angle + * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 + */ +int16_t lv_trigo_sin(int16_t angle); + +/** + * Calculate a value of a Cubic Bezier function. + * @param t time in range of [0..LV_BEZIER_VAL_MAX] + * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] + * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] + * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] + * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] + * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] + */ +int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.c new file mode 100644 index 0000000..cfe4ed6 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.c @@ -0,0 +1,464 @@ +/** + * @file lv_mem.c + * General and portable implementation of malloc and free. + * The dynamic memory monitoring is also supported. + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_mem.h" +#include "lv_math.h" +#include + +#if LV_MEM_CUSTOM != 0 +#include LV_MEM_CUSTOM_INCLUDE +#endif + +/********************* + * DEFINES + *********************/ +#define LV_MEM_ADD_JUNK 0 /*Add memory junk on alloc (0xaa) and free(0xbb) (just for testing purposes)*/ + + +#ifdef LV_MEM_ENV64 +# define MEM_UNIT uint64_t +#else +# define MEM_UNIT uint32_t +#endif + + +/********************** + * TYPEDEFS + **********************/ + +#if LV_ENABLE_GC == 0 /*gc custom allocations must not include header*/ + +/*The size of this union must be 4 bytes (uint32_t)*/ +typedef union { + struct { + MEM_UNIT used: 1; //1: if the entry is used + MEM_UNIT d_size: 31; //Size off the data (1 means 4 bytes) + }; + MEM_UNIT header; //The header (used + d_size) +} lv_mem_header_t; + +typedef struct { + lv_mem_header_t header; + uint8_t first_data; /*First data byte in the allocated data (Just for easily create a pointer)*/ +} lv_mem_ent_t; + +#endif /* LV_ENABLE_GC */ + +/********************** + * STATIC PROTOTYPES + **********************/ +#if LV_MEM_CUSTOM == 0 +static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e); +static void * ent_alloc(lv_mem_ent_t * e, uint32_t size); +static void ent_trunc(lv_mem_ent_t * e, uint32_t size); +#endif + +/********************** + * STATIC VARIABLES + **********************/ +#if LV_MEM_CUSTOM == 0 +static uint8_t * work_mem; +#endif + +static uint32_t zero_mem; /*Give the address of this variable if 0 byte should be allocated*/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initiaiize the dyn_mem module (work memory and other variables) + */ +void lv_mem_init(void) +{ +#if LV_MEM_CUSTOM == 0 + +#if LV_MEM_ADR == 0 + /*Allocate a large array to store the dynamically allocated data*/ + static LV_MEM_ATTR MEM_UNIT work_mem_int[LV_MEM_SIZE / sizeof(MEM_UNIT)]; + work_mem = (uint8_t *) work_mem_int; +#else + work_mem = (uint8_t *) LV_MEM_ADR; +#endif + + lv_mem_ent_t * full = (lv_mem_ent_t *)work_mem; + full->header.used = 0; + /*The total mem size id reduced by the first header and the close patterns */ + full->header.d_size = LV_MEM_SIZE - sizeof(lv_mem_header_t); +#endif +} + +/** + * Allocate a memory dynamically + * @param size size of the memory to allocate in bytes + * @return pointer to the allocated memory + */ +void * lv_mem_alloc(uint32_t size) +{ + if(size == 0) { + return &zero_mem; + } + +#ifdef LV_MEM_ENV64 + /*Round the size up to 8*/ + if(size & 0x7) { + size = size & (~0x7); + size += 8; + } +#else + /*Round the size up to 4*/ + if(size & 0x3) { + size = size & (~0x3); + size += 4; + } +#endif + void * alloc = NULL; + +#if LV_MEM_CUSTOM == 0 /*Use the allocation from dyn_mem*/ + lv_mem_ent_t * e = NULL; + + //Search for a appropriate entry + do { + //Get the next entry + e = ent_get_next(e); + + /*If there is next entry then try to allocate there*/ + if(e != NULL) { + alloc = ent_alloc(e, size); + } + //End if there is not next entry OR the alloc. is successful + } while(e != NULL && alloc == NULL); + + +#else /*Use custom, user defined malloc function*/ +#if LV_ENABLE_GC == 1 /*gc must not include header*/ + alloc = LV_MEM_CUSTOM_ALLOC(size); +#else /* LV_ENABLE_GC */ + /*Allocate a header too to store the size*/ + alloc = LV_MEM_CUSTOM_ALLOC(size + sizeof(lv_mem_header_t)); + if(alloc != NULL) { + ((lv_mem_ent_t *) alloc)->header.d_size = size; + ((lv_mem_ent_t *) alloc)->header.used = 1; + alloc = &((lv_mem_ent_t *) alloc)->first_data; + } +#endif /* LV_ENABLE_GC */ +#endif /* LV_MEM_CUSTOM */ + +#if LV_MEM_ADD_JUNK + if(alloc != NULL) memset(alloc, 0xaa, size); +#endif + + if(alloc == NULL) LV_LOG_WARN("Couldn't allocate memory"); + + return alloc; +} + +/** + * Free an allocated data + * @param data pointer to an allocated memory + */ +void lv_mem_free(const void * data) +{ + if(data == &zero_mem) return; + if(data == NULL) return; + + +#if LV_MEM_ADD_JUNK + memset((void *)data, 0xbb, lv_mem_get_size(data)); +#endif + +#if LV_ENABLE_GC==0 + /*e points to the header*/ + lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data - sizeof(lv_mem_header_t)); + e->header.used = 0; +#endif + +#if LV_MEM_CUSTOM == 0 +#if LV_MEM_AUTO_DEFRAG + /* Make a simple defrag. + * Join the following free entries after this*/ + lv_mem_ent_t * e_next; + e_next = ent_get_next(e); + while(e_next != NULL) { + if(e_next->header.used == 0) { + e->header.d_size += e_next->header.d_size + sizeof(e->header); + } else { + break; + } + e_next = ent_get_next(e_next); + } +#endif +#else /*Use custom, user defined free function*/ +#if LV_ENABLE_GC==0 + LV_MEM_CUSTOM_FREE(e); +#else + LV_MEM_CUSTOM_FREE((void*)data); +#endif /*LV_ENABLE_GC*/ +#endif +} + +/** + * Reallocate a memory with a new size. The old content will be kept. + * @param data pointer to an allocated memory. + * Its content will be copied to the new memory block and freed + * @param new_size the desired new size in byte + * @return pointer to the new memory + */ + +#if LV_ENABLE_GC==0 + +void * lv_mem_realloc(void * data_p, uint32_t new_size) +{ + /*data_p could be previously freed pointer (in this case it is invalid)*/ + if(data_p != NULL) { + lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data_p - sizeof(lv_mem_header_t)); + if(e->header.used == 0) { + data_p = NULL; + } + } + + uint32_t old_size = lv_mem_get_size(data_p); + if(old_size == new_size) return data_p; /*Also avoid reallocating the same memory*/ + +#if LV_MEM_CUSTOM == 0 + /* Only truncate the memory is possible + * If the 'old_size' was extended by a header size in 'ent_trunc' it avoids reallocating this same memory */ + if(new_size < old_size) { + lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data_p - sizeof(lv_mem_header_t)); + ent_trunc(e, new_size); + return &e->first_data; + } +#endif + + void * new_p; + new_p = lv_mem_alloc(new_size); + + if(new_p != NULL && data_p != NULL) { + /*Copy the old data to the new. Use the smaller size*/ + if(old_size != 0) { + memcpy(new_p, data_p, LV_MATH_MIN(new_size, old_size)); + lv_mem_free(data_p); + } + } + + + if(new_p == NULL) LV_LOG_WARN("Couldn't allocate memory"); + + return new_p; +} + +#else /* LV_ENABLE_GC */ + +void * lv_mem_realloc(void * data_p, uint32_t new_size) +{ + void * new_p = LV_MEM_CUSTOM_REALLOC(data_p, new_size); + if(new_p == NULL) LV_LOG_WARN("Couldn't allocate memory"); + return new_p; +} + +#endif /* lv_enable_gc */ + +/** + * Join the adjacent free memory blocks + */ +void lv_mem_defrag(void) +{ +#if LV_MEM_CUSTOM == 0 + lv_mem_ent_t * e_free; + lv_mem_ent_t * e_next; + e_free = ent_get_next(NULL); + + while(1) { + /*Search the next free entry*/ + while(e_free != NULL) { + if(e_free->header.used != 0) { + e_free = ent_get_next(e_free); + } else { + break; + } + } + + if(e_free == NULL) return; + + /*Joint the following free entries to the free*/ + e_next = ent_get_next(e_free); + while(e_next != NULL) { + if(e_next->header.used == 0) { + e_free->header.d_size += e_next->header.d_size + sizeof(e_next->header); + } else { + break; + } + + e_next = ent_get_next(e_next); + } + + if(e_next == NULL) return; + + /*Continue from the lastly checked entry*/ + e_free = e_next; + } +#endif +} + +/** + * Give information about the work memory of dynamic allocation + * @param mon_p pointer to a dm_mon_p variable, + * the result of the analysis will be stored here + */ +void lv_mem_monitor(lv_mem_monitor_t * mon_p) +{ + /*Init the data*/ + memset(mon_p, 0, sizeof(lv_mem_monitor_t)); +#if LV_MEM_CUSTOM == 0 + lv_mem_ent_t * e; + e = NULL; + + e = ent_get_next(e); + + while(e != NULL) { + if(e->header.used == 0) { + mon_p->free_cnt++; + mon_p->free_size += e->header.d_size; + if(e->header.d_size > mon_p->free_biggest_size) { + mon_p->free_biggest_size = e->header.d_size; + } + } else { + mon_p->used_cnt++; + } + + e = ent_get_next(e); + } + mon_p->total_size = LV_MEM_SIZE; + mon_p->used_pct = 100 - (100U * mon_p->free_size) / mon_p->total_size; + mon_p->frag_pct = (uint32_t)mon_p->free_biggest_size * 100U / mon_p->free_size; + mon_p->frag_pct = 100 - mon_p->frag_pct; +#endif +} + +/** + * Give the size of an allocated memory + * @param data pointer to an allocated memory + * @return the size of data memory in bytes + */ + +#if LV_ENABLE_GC==0 + +uint32_t lv_mem_get_size(const void * data) +{ + if(data == NULL) return 0; + if(data == &zero_mem) return 0; + + lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data - sizeof(lv_mem_header_t)); + + return e->header.d_size; +} + +#else /* LV_ENABLE_GC */ + +uint32_t lv_mem_get_size(const void * data) +{ + return LV_MEM_CUSTOM_GET_SIZE(data); +} + +#endif /*LV_ENABLE_GC*/ + +/********************** + * STATIC FUNCTIONS + **********************/ + +#if LV_MEM_CUSTOM == 0 +/** + * Give the next entry after 'act_e' + * @param act_e pointer to an entry + * @return pointer to an entry after 'act_e' + */ +static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e) +{ + lv_mem_ent_t * next_e = NULL; + + if(act_e == NULL) { /*NULL means: get the first entry*/ + next_e = (lv_mem_ent_t *) work_mem; + } else { /*Get the next entry */ + uint8_t * data = &act_e->first_data; + next_e = (lv_mem_ent_t *)&data[act_e->header.d_size]; + + if(&next_e->first_data >= &work_mem[LV_MEM_SIZE]) next_e = NULL; + } + + return next_e; +} + + +/** + * Try to do the real allocation with a given size + * @param e try to allocate to this entry + * @param size size of the new memory in bytes + * @return pointer to the allocated memory or NULL if not enough memory in the entry + */ +static void * ent_alloc(lv_mem_ent_t * e, uint32_t size) +{ + void * alloc = NULL; + + /*If the memory is free and big enough then use it */ + if(e->header.used == 0 && e->header.d_size >= size) { + /*Truncate the entry to the desired size */ + ent_trunc(e, size), + + e->header.used = 1; + + /*Save the allocated data*/ + alloc = &e->first_data; + } + + return alloc; +} + +/** + * Truncate the data of entry to the given size + * @param e Pointer to an entry + * @param size new size in bytes + */ +static void ent_trunc(lv_mem_ent_t * e, uint32_t size) +{ +#ifdef LV_MEM_ENV64 + /*Round the size up to 8*/ + if(size & 0x7) { + size = size & (~0x7); + size += 8; + } +#else + /*Round the size up to 4*/ + if(size & 0x3) { + size = size & (~0x3); + size += 4; + } +#endif + + /*Don't let empty space only for a header without data*/ + if(e->header.d_size == size + sizeof(lv_mem_header_t)) { + size = e->header.d_size; + } + + /* Create the new entry after the current if there is space for it */ + if(e->header.d_size != size) { + uint8_t * e_data = &e->first_data; + lv_mem_ent_t * after_new_e = (lv_mem_ent_t *)&e_data[size]; + after_new_e->header.used = 0; + after_new_e->header.d_size = e->header.d_size - size - sizeof(lv_mem_header_t); + } + + /* Set the new size for the original entry */ + e->header.d_size = size; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.h new file mode 100644 index 0000000..c33caa4 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_mem.h @@ -0,0 +1,127 @@ +/** + * @file lv_mem.h + * + */ + +#ifndef LV_MEM_H +#define LV_MEM_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include +#include +#include "lv_log.h" + +/********************* + * DEFINES + *********************/ +// Check windows +#ifdef __WIN64 +//# define LV_MEM_ENV64 +#endif + +// Check GCC +#ifdef __GNUC__ +# if defined(__x86_64__) || defined(__ppc64__) +//# define LV_MEM_ENV64 +# endif +#endif + +/********************** + * TYPEDEFS + **********************/ + +typedef struct +{ + uint32_t total_size; + uint32_t free_cnt; + uint32_t free_size; + uint32_t free_biggest_size; + uint32_t used_cnt; + uint8_t used_pct; + uint8_t frag_pct; +} lv_mem_monitor_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + + +/** + * Initiaize the dyn_mem module (work memory and other variables) + */ +void lv_mem_init(void); + +/** + * Allocate a memory dynamically + * @param size size of the memory to allocate in bytes + * @return pointer to the allocated memory + */ +void * lv_mem_alloc(uint32_t size); + +/** + * Free an allocated data + * @param data pointer to an allocated memory + */ +void lv_mem_free(const void * data); + +/** + * Reallocate a memory with a new size. The old content will be kept. + * @param data pointer to an allocated memory. + * Its content will be copied to the new memory block and freed + * @param new_size the desired new size in byte + * @return pointer to the new memory + */ +void * lv_mem_realloc(void * data_p, uint32_t new_size); + +/** + * Join the adjacent free memory blocks + */ +void lv_mem_defrag(void); + +/** + * Give information about the work memory of dynamic allocation + * @param mon_p pointer to a dm_mon_p variable, + * the result of the analysis will be stored here + */ +void lv_mem_monitor(lv_mem_monitor_t * mon_p); + +/** + * Give the size of an allocated memory + * @param data pointer to an allocated memory + * @return the size of data memory in bytes + */ +uint32_t lv_mem_get_size(const void * data); + + +/********************** + * MACROS + **********************/ + +/** + * Halt on NULL pointer + * p pointer to a memory + */ +#if USE_LV_LOG == 0 +# define lv_mem_assert(p) {if(p == NULL) while(1); } +#else +# define lv_mem_assert(p) {if(p == NULL) {LV_LOG_ERROR("Out of memory!"); while(1); }} +#endif +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_MEM_H*/ + diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_misc.mk b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_misc.mk new file mode 100644 index 0000000..470f123 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_misc.mk @@ -0,0 +1,19 @@ +CSRCS += lv_font.c +CSRCS += lv_circ.c +CSRCS += lv_area.c +CSRCS += lv_task.c +CSRCS += lv_fs.c +CSRCS += lv_anim.c +CSRCS += lv_mem.c +CSRCS += lv_ll.c +CSRCS += lv_color.c +CSRCS += lv_txt.c +CSRCS += lv_ufs.c +CSRCS += lv_math.c +CSRCS += lv_log.c +CSRCS += lv_gc.c + +DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_misc +VPATH += :$(LVGL_DIR)/lvgl/lv_misc + +CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc" diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_symbol_def.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_symbol_def.h new file mode 100644 index 0000000..762bab9 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_symbol_def.h @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LV_SYMBOL_DEF_H +#define LV_SYMBOL_DEF_H + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +/* + * With no UTF-8 support (192- 255) (192..241 is used) + * + * With UTF-8 support (in Supplemental Private Use Area-A): 0xF800 .. 0xF831 + * - Basic symbols: 0xE000..0xE01F + * - File symbols: 0xE020..0xE03F + * - Feedback symbols: 0xE040..0xE05F + * - Reserved: 0xE060..0xE07F + */ + +#if LV_TXT_UTF8 == 0 +#define LV_SYMBOL_GLYPH_FIRST 0xC0 +#define SYMBOL_DOT _SYMBOL_VALUE1(C0) +#define SYMBOL_CLOCK _SYMBOL_VALUE1(C1) +#define SYMBOL_LIST _SYMBOL_VALUE1(C2) +#define SYMBOL_OK _SYMBOL_VALUE1(C3) +#define SYMBOL_CLOSE _SYMBOL_VALUE1(C4) +#define SYMBOL_POWER _SYMBOL_VALUE1(C5) +#define SYMBOL_SETTINGS _SYMBOL_VALUE1(C6) +#define SYMBOL_TRASH _SYMBOL_VALUE1(C7) +#define SYMBOL_HOME _SYMBOL_VALUE1(C8) +#define SYMBOL_DOWNLOAD _SYMBOL_VALUE1(C9) +#define SYMBOL_DRIVE _SYMBOL_VALUE1(CA) +#define SYMBOL_REFRESH _SYMBOL_VALUE1(CB) +#define SYMBOL_REBOOT _SYMBOL_VALUE1(CC) +#define SYMBOL_CHIP _SYMBOL_VALUE1(CD) +#define SYMBOL_SD _SYMBOL_VALUE1(CE) +#define SYMBOL_CIRCUIT _SYMBOL_VALUE1(CF) +#define SYMBOL_EDIT _SYMBOL_VALUE1(D0) +#define SYMBOL_FILE_ALT _SYMBOL_VALUE1(D1) +#define SYMBOL_FILE_CODE _SYMBOL_VALUE1(D2) +#define SYMBOL_FILE_ARC _SYMBOL_VALUE1(D3) +#define SYMBOL_TEMPERATURE _SYMBOL_VALUE1(D4) +#define SYMBOL_MODULES _SYMBOL_VALUE1(D5) +#define SYMBOL_MODULES_ALT _SYMBOL_VALUE1(D6) +#define SYMBOL_LEFT _SYMBOL_VALUE1(D7) +#define SYMBOL_RIGHT _SYMBOL_VALUE1(D8) +#define SYMBOL_KEY _SYMBOL_VALUE1(D9) +#define SYMBOL_INFO _SYMBOL_VALUE1(DA) +#define SYMBOL_WARNING _SYMBOL_VALUE1(DB) +#define SYMBOL_SHUFFLE _SYMBOL_VALUE1(DC) +#define SYMBOL_UP _SYMBOL_VALUE1(DD) +#define SYMBOL_DOWN _SYMBOL_VALUE1(DE) +#define SYMBOL_BRIGHTNESS _SYMBOL_VALUE1(DF) +#define SYMBOL_DIRECTORY _SYMBOL_VALUE1(E0) +#define SYMBOL_UPLOAD _SYMBOL_VALUE1(E1) +#define SYMBOL_USB _SYMBOL_VALUE1(E2) +#define SYMBOL_TOOLS _SYMBOL_VALUE1(E3) +#define SYMBOL_COPY _SYMBOL_VALUE1(E4) +#define SYMBOL_SAVE _SYMBOL_VALUE1(E5) +#define SYMBOL_CHARGE _SYMBOL_VALUE1(E6) +#define SYMBOL_HINT _SYMBOL_VALUE1(E7) +#define SYMBOL_KEYBOARD _SYMBOL_VALUE1(E8) +#define SYMBOL_GPS _SYMBOL_VALUE1(E9) +#define SYMBOL_FILE _SYMBOL_VALUE1(EA) +#define SYMBOL_CAMERA _SYMBOL_VALUE1(EB) +#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE1(EC) +#define SYMBOL_BATTERY_3 _SYMBOL_VALUE1(ED) +#define SYMBOL_BATTERY_2 _SYMBOL_VALUE1(EE) +#define SYMBOL_BATTERY_1 _SYMBOL_VALUE1(EF) +#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE1(F0) +#define SYMBOL_SHRK _SYMBOL_VALUE1(F1) +#define LV_SYMBOL_GLYPH_LAST 0xF1 +#define SYMBOL_DUMMY _SYMBOL_VALUE1(FF) /*Invalid symbol. If written before a string then `lv_img` will show it as a label*/ + +#else +#define LV_SYMBOL_GLYPH_FIRST 0xF800 +#define SYMBOL_DOT _SYMBOL_VALUE3(EF,A0,80) +#define SYMBOL_CLOCK _SYMBOL_VALUE3(EF,A0,81) +#define SYMBOL_LIST _SYMBOL_VALUE3(EF,A0,82) +#define SYMBOL_OK _SYMBOL_VALUE3(EF,A0,83) +#define SYMBOL_CLOSE _SYMBOL_VALUE3(EF,A0,84) +#define SYMBOL_POWER _SYMBOL_VALUE3(EF,A0,85) +#define SYMBOL_SETTINGS _SYMBOL_VALUE3(EF,A0,86) +#define SYMBOL_TRASH _SYMBOL_VALUE3(EF,A0,87) +#define SYMBOL_HOME _SYMBOL_VALUE3(EF,A0,88) +#define SYMBOL_DOWNLOAD _SYMBOL_VALUE3(EF,A0,89) +#define SYMBOL_DRIVE _SYMBOL_VALUE3(EF,A0,8A) +#define SYMBOL_REFRESH _SYMBOL_VALUE3(EF,A0,8B) +#define SYMBOL_REBOOT _SYMBOL_VALUE3(EF,A0,8C) +#define SYMBOL_CHIP _SYMBOL_VALUE3(EF,A0,8D) +#define SYMBOL_SD _SYMBOL_VALUE3(EF,A0,8E) +#define SYMBOL_CIRCUIT _SYMBOL_VALUE3(EF,A0,8F) +#define SYMBOL_EDIT _SYMBOL_VALUE3(EF,A0,90) +#define SYMBOL_FILE_ALT _SYMBOL_VALUE3(EF,A0,91) +#define SYMBOL_FILE_CODE _SYMBOL_VALUE3(EF,A0,92) +#define SYMBOL_FILE_ARC _SYMBOL_VALUE3(EF,A0,93) +#define SYMBOL_TEMPERATURE _SYMBOL_VALUE3(EF,A0,94) +#define SYMBOL_MODULES _SYMBOL_VALUE3(EF,A0,95) +#define SYMBOL_MODULES_ALT _SYMBOL_VALUE3(EF,A0,96) +#define SYMBOL_LEFT _SYMBOL_VALUE3(EF,A0,97) +#define SYMBOL_RIGHT _SYMBOL_VALUE3(EF,A0,98) +#define SYMBOL_KEY _SYMBOL_VALUE3(EF,A0,99) +#define SYMBOL_INFO _SYMBOL_VALUE3(EF,A0,9A) +#define SYMBOL_WARNING _SYMBOL_VALUE3(EF,A0,9B) +#define SYMBOL_SHUFFLE _SYMBOL_VALUE3(EF,A0,9C) +#define SYMBOL_UP _SYMBOL_VALUE3(EF,A0,9D) +#define SYMBOL_DOWN _SYMBOL_VALUE3(EF,A0,9E) +#define SYMBOL_BRIGHTNESS _SYMBOL_VALUE3(EF,A0,9F) +#define SYMBOL_DIRECTORY _SYMBOL_VALUE3(EF,A0,A0) +#define SYMBOL_UPLOAD _SYMBOL_VALUE3(EF,A0,A1) +#define SYMBOL_USB _SYMBOL_VALUE3(EF,A0,A2) +#define SYMBOL_TOOLS _SYMBOL_VALUE3(EF,A0,A3) +#define SYMBOL_COPY _SYMBOL_VALUE3(EF,A0,A4) +#define SYMBOL_SAVE _SYMBOL_VALUE3(EF,A0,A5) +#define SYMBOL_CHARGE _SYMBOL_VALUE3(EF,A0,A6) +#define SYMBOL_HINT _SYMBOL_VALUE3(EF,A0,A7) +#define SYMBOL_KEYBOARD _SYMBOL_VALUE3(EF,A0,A8) +#define SYMBOL_GPS _SYMBOL_VALUE3(EF,A0,A9) +#define SYMBOL_FILE _SYMBOL_VALUE3(EF,A0,AA) +#define SYMBOL_CAMERA _SYMBOL_VALUE3(EF,A0,AB) +#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE3(EF,A0,AC) +#define SYMBOL_BATTERY_3 _SYMBOL_VALUE3(EF,A0,AD) +#define SYMBOL_BATTERY_2 _SYMBOL_VALUE3(EF,A0,AE) +#define SYMBOL_BATTERY_1 _SYMBOL_VALUE3(EF,A0,AF) +#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE3(EF,A0,B0) +#define SYMBOL_SHRK _SYMBOL_VALUE3(EF,A0,B1) +#define LV_SYMBOL_GLYPH_LAST 0xF831 +#define SYMBOL_DUMMY _SYMBOL_VALUE3(EF,A3,BF) /*Invalid symbol at (U+F831). If written before a string then `lv_img` will show it as a label*/ +#endif + +#define _SYMBOL_VALUE1(x) (0x ## x) +#define _SYMBOL_VALUE3(x, y, z) (0x ## z ## y ## x) +#define _SYMBOL_NUMSTR(sym) LV_ ## sym ## _NUMSTR = sym + +enum +{ + _SYMBOL_NUMSTR(SYMBOL_DOT), + _SYMBOL_NUMSTR(SYMBOL_CLOCK), + _SYMBOL_NUMSTR(SYMBOL_LIST), + _SYMBOL_NUMSTR(SYMBOL_OK), + _SYMBOL_NUMSTR(SYMBOL_CLOSE), + _SYMBOL_NUMSTR(SYMBOL_POWER), + _SYMBOL_NUMSTR(SYMBOL_SETTINGS), + _SYMBOL_NUMSTR(SYMBOL_TRASH), + _SYMBOL_NUMSTR(SYMBOL_HOME), + _SYMBOL_NUMSTR(SYMBOL_DOWNLOAD), + _SYMBOL_NUMSTR(SYMBOL_DRIVE), + _SYMBOL_NUMSTR(SYMBOL_REFRESH), + _SYMBOL_NUMSTR(SYMBOL_REBOOT), + _SYMBOL_NUMSTR(SYMBOL_CHIP), + _SYMBOL_NUMSTR(SYMBOL_SD), + _SYMBOL_NUMSTR(SYMBOL_CIRCUIT), + _SYMBOL_NUMSTR(SYMBOL_EDIT), + _SYMBOL_NUMSTR(SYMBOL_FILE_ALT), + _SYMBOL_NUMSTR(SYMBOL_FILE_CODE), + _SYMBOL_NUMSTR(SYMBOL_FILE_ARC), + _SYMBOL_NUMSTR(SYMBOL_TEMPERATURE), + _SYMBOL_NUMSTR(SYMBOL_MODULES), + _SYMBOL_NUMSTR(SYMBOL_MODULES_ALT), + _SYMBOL_NUMSTR(SYMBOL_LEFT), + _SYMBOL_NUMSTR(SYMBOL_RIGHT), + _SYMBOL_NUMSTR(SYMBOL_KEY), + _SYMBOL_NUMSTR(SYMBOL_INFO), + _SYMBOL_NUMSTR(SYMBOL_WARNING), + _SYMBOL_NUMSTR(SYMBOL_SHUFFLE), + _SYMBOL_NUMSTR(SYMBOL_UP), + _SYMBOL_NUMSTR(SYMBOL_DOWN), + _SYMBOL_NUMSTR(SYMBOL_BRIGHTNESS), + _SYMBOL_NUMSTR(SYMBOL_DIRECTORY), + _SYMBOL_NUMSTR(SYMBOL_UPLOAD), + _SYMBOL_NUMSTR(SYMBOL_USB), + _SYMBOL_NUMSTR(SYMBOL_TOOLS), + _SYMBOL_NUMSTR(SYMBOL_COPY), + _SYMBOL_NUMSTR(SYMBOL_SAVE), + _SYMBOL_NUMSTR(SYMBOL_CHARGE), + _SYMBOL_NUMSTR(SYMBOL_HINT), + _SYMBOL_NUMSTR(SYMBOL_KEYBOARD), + _SYMBOL_NUMSTR(SYMBOL_GPS), + _SYMBOL_NUMSTR(SYMBOL_FILE), + _SYMBOL_NUMSTR(SYMBOL_CAMERA), + _SYMBOL_NUMSTR(SYMBOL_BATTERY_FULL), + _SYMBOL_NUMSTR(SYMBOL_BATTERY_3), + _SYMBOL_NUMSTR(SYMBOL_BATTERY_2), + _SYMBOL_NUMSTR(SYMBOL_BATTERY_1), + _SYMBOL_NUMSTR(SYMBOL_BATTERY_EMPTY), + _SYMBOL_NUMSTR(SYMBOL_SHRK), + _SYMBOL_NUMSTR(SYMBOL_DUMMY), +}; + +#undef _SYMBOL_VALUE1 +#undef _SYMBOL_VALUE3 + +#define _SYMBOL_STR_(x) #x +#define _SYMBOL_STR(x) _SYMBOL_STR_(x) +#define _SYMBOL_CHAR(c) \x ## c +#define _SYMBOL_VALUE1(x) _SYMBOL_STR(_SYMBOL_CHAR(x)) +#define _SYMBOL_VALUE3(x, y, z) _SYMBOL_STR(_SYMBOL_CHAR(x)_SYMBOL_CHAR(y)_SYMBOL_CHAR(z)) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /*LV_SYMBOL_DEF_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.c new file mode 100644 index 0000000..aac9c12 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.c @@ -0,0 +1,332 @@ +/** + * @file lv_task.c + * An 'lv_task' is a void (*fp) (void* param) type function which will be called periodically. + * A priority (5 levels + disable) can be assigned to lv_tasks. + */ + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_task.h" +#include "../lv_hal/lv_hal_tick.h" +#include "lv_gc.h" + +#if defined(LV_GC_INCLUDE) +# include LV_GC_INCLUDE +#endif /* LV_ENABLE_GC */ + +/********************* + * DEFINES + *********************/ +#define IDLE_MEAS_PERIOD 500 /*[ms]*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_task_exec(lv_task_t * lv_task_p); + +/********************** + * STATIC VARIABLES + **********************/ +static bool lv_task_run = false; +static uint8_t idle_last = 0; +static bool task_deleted; +static bool task_created; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Init the lv_task module + */ +void lv_task_init(void) +{ + lv_ll_init(&LV_GC_ROOT(_lv_task_ll), sizeof(lv_task_t)); + + /*Initially enable the lv_task handling*/ + lv_task_enable(true); +} + +/** + * Call it periodically to handle lv_tasks. + */ +LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void) +{ + LV_LOG_TRACE("lv_task_handler started"); + + /*Avoid concurrent running of the task handler*/ + static bool task_handler_mutex = false; + if(task_handler_mutex) return; + task_handler_mutex = true; + + static uint32_t idle_period_start = 0; + static uint32_t handler_start = 0; + static uint32_t busy_time = 0; + + if(lv_task_run == false) return; + + handler_start = lv_tick_get(); + + /* Run all task from the highest to the lowest priority + * If a lower priority task is executed check task again from the highest priority + * but on the priority of executed tasks don't run tasks before the executed*/ + lv_task_t * task_interrupter = NULL; + lv_task_t * next; + bool end_flag; + do { + end_flag = true; + task_deleted = false; + task_created = false; + LV_GC_ROOT(_lv_task_act) = lv_ll_get_head(&LV_GC_ROOT(_lv_task_ll)); + while(LV_GC_ROOT(_lv_task_act)) { + /* The task might be deleted if it runs only once ('once = 1') + * So get next element until the current is surely valid*/ + next = lv_ll_get_next(&LV_GC_ROOT(_lv_task_ll), LV_GC_ROOT(_lv_task_act)); + + /*We reach priority of the turned off task. There is nothing more to do.*/ + if(((lv_task_t *)LV_GC_ROOT(_lv_task_act))->prio == LV_TASK_PRIO_OFF) { + break; + } + + /*Here is the interrupter task. Don't execute it again.*/ + if(LV_GC_ROOT(_lv_task_act) == task_interrupter) { + task_interrupter = NULL; /*From this point only task after the interrupter comes, so the interrupter is not interesting anymore*/ + LV_GC_ROOT(_lv_task_act) = next; + continue; /*Load the next task*/ + } + + /*Just try to run the tasks with highest priority.*/ + if(((lv_task_t *)LV_GC_ROOT(_lv_task_act))->prio == LV_TASK_PRIO_HIGHEST) { + lv_task_exec(LV_GC_ROOT(_lv_task_act)); + } + /*Tasks with higher priority then the interrupted shall be run in every case*/ + else if(task_interrupter) { + if(((lv_task_t *)LV_GC_ROOT(_lv_task_act))->prio > task_interrupter->prio) { + if(lv_task_exec(LV_GC_ROOT(_lv_task_act))) { + task_interrupter = LV_GC_ROOT(_lv_task_act); /*Check all tasks again from the highest priority */ + end_flag = false; + break; + } + } + } + /* It is no interrupter task or we already reached it earlier. + * Just run the remaining tasks*/ + else { + if(lv_task_exec(LV_GC_ROOT(_lv_task_act))) { + task_interrupter = LV_GC_ROOT(_lv_task_act); /*Check all tasks again from the highest priority */ + end_flag = false; + break; + } + } + + if(task_deleted) break; /*If a task was deleted then this or the next item might be corrupted*/ + if(task_created) break; /*If a task was deleted then this or the next item might be corrupted*/ + + LV_GC_ROOT(_lv_task_act) = next; /*Load the next task*/ + } + } while(!end_flag); + + busy_time += lv_tick_elaps(handler_start); + uint32_t idle_period_time = lv_tick_elaps(idle_period_start); + if(idle_period_time >= IDLE_MEAS_PERIOD) { + + idle_last = (uint32_t)((uint32_t)busy_time * 100) / IDLE_MEAS_PERIOD; /*Calculate the busy percentage*/ + idle_last = idle_last > 100 ? 0 : 100 - idle_last; /*But we need idle time*/ + busy_time = 0; + idle_period_start = lv_tick_get(); + + + } + + task_handler_mutex = false; /*Release the mutex*/ + + LV_LOG_TRACE("lv_task_handler ready"); +} + +/** + * Create a new lv_task + * @param task a function which is the task itself + * @param period call period in ms unit + * @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped) + * @param param free parameter + * @return pointer to the new task + */ +lv_task_t * lv_task_create(void (*task)(void *), uint32_t period, lv_task_prio_t prio, void * param) +{ + lv_task_t * new_lv_task = NULL; + lv_task_t * tmp; + + /*Create task lists in order of priority from high to low*/ + tmp = lv_ll_get_head(&LV_GC_ROOT(_lv_task_ll)); + if(NULL == tmp) { /*First task*/ + new_lv_task = lv_ll_ins_head(&LV_GC_ROOT(_lv_task_ll)); + lv_mem_assert(new_lv_task); + if(new_lv_task == NULL) return NULL; + } else { + do { + if(tmp->prio <= prio) { + new_lv_task = lv_ll_ins_prev(&LV_GC_ROOT(_lv_task_ll), tmp); + lv_mem_assert(new_lv_task); + if(new_lv_task == NULL) return NULL; + break; + } + tmp = lv_ll_get_next(&LV_GC_ROOT(_lv_task_ll), tmp); + } while(tmp != NULL); + + if(tmp == NULL) { /*Only too high priority tasks were found*/ + new_lv_task = lv_ll_ins_tail(&LV_GC_ROOT(_lv_task_ll)); + lv_mem_assert(new_lv_task); + if(new_lv_task == NULL) return NULL; + } + } + + new_lv_task->period = period; + new_lv_task->task = task; + new_lv_task->prio = prio; + new_lv_task->param = param; + new_lv_task->once = 0; + new_lv_task->last_run = lv_tick_get(); + + task_created = true; + + return new_lv_task; +} + +/** + * Delete a lv_task + * @param lv_task_p pointer to task created by lv_task_p + */ +void lv_task_del(lv_task_t * lv_task_p) +{ + lv_ll_rem(&LV_GC_ROOT(_lv_task_ll), lv_task_p); + + lv_mem_free(lv_task_p); + + if(LV_GC_ROOT(_lv_task_act) == lv_task_p) task_deleted = true; /*The active task was deleted*/ +} + +/** + * Set new priority for a lv_task + * @param lv_task_p pointer to a lv_task + * @param prio the new priority + */ +void lv_task_set_prio(lv_task_t * lv_task_p, lv_task_prio_t prio) +{ + /*Find the tasks with new priority*/ + lv_task_t * i; + LL_READ(LV_GC_ROOT(_lv_task_ll), i) { + if(i->prio <= prio) { + if(i != lv_task_p) lv_ll_move_before(&LV_GC_ROOT(_lv_task_ll), lv_task_p, i); + break; + } + } + + /*There was no such a low priority so far then add the node to the tail*/ + if(i == NULL) { + lv_ll_move_before(&LV_GC_ROOT(_lv_task_ll), lv_task_p, NULL); + } + + + lv_task_p->prio = prio; +} + +/** + * Set new period for a lv_task + * @param lv_task_p pointer to a lv_task + * @param period the new period + */ +void lv_task_set_period(lv_task_t * lv_task_p, uint32_t period) +{ + lv_task_p->period = period; +} + +/** + * Make a lv_task ready. It will not wait its period. + * @param lv_task_p pointer to a lv_task. + */ +void lv_task_ready(lv_task_t * lv_task_p) +{ + lv_task_p->last_run = lv_tick_get() - lv_task_p->period - 1; +} + +/** + * Delete the lv_task after one call + * @param lv_task_p pointer to a lv_task. + */ +void lv_task_once(lv_task_t * lv_task_p) +{ + lv_task_p->once = 1; +} + +/** + * Reset a lv_task. + * It will be called the previously set period milliseconds later. + * @param lv_task_p pointer to a lv_task. + */ +void lv_task_reset(lv_task_t * lv_task_p) +{ + lv_task_p->last_run = lv_tick_get(); +} + +/** + * Enable or disable the whole lv_task handling + * @param en: true: lv_task handling is running, false: lv_task handling is suspended + */ +void lv_task_enable(bool en) +{ + lv_task_run = en; +} + +/** + * Get idle percentage + * @return the lv_task idle in percentage + */ +uint8_t lv_task_get_idle(void) +{ + return idle_last; +} + + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Execute task if its the priority is appropriate + * @param lv_task_p pointer to lv_task + * @return true: execute, false: not executed + */ +static bool lv_task_exec(lv_task_t * lv_task_p) +{ + bool exec = false; + + /*Execute if at least 'period' time elapsed*/ + uint32_t elp = lv_tick_elaps(lv_task_p->last_run); + if(elp >= lv_task_p->period) { + lv_task_p->last_run = lv_tick_get(); + task_deleted = false; + task_created = false; + lv_task_p->task(lv_task_p->param); + + /*Delete if it was a one shot lv_task*/ + if(task_deleted == false) { /*The task might be deleted by itself as well*/ + if(lv_task_p->once != 0) { + lv_task_del(lv_task_p); + } + } + exec = true; + } + + return exec; +} + diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.h new file mode 100644 index 0000000..51c1a77 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_task.h @@ -0,0 +1,148 @@ +/** + * @file lv_task.c + * An 'lv_task' is a void (*fp) (void* param) type function which will be called periodically. + * A priority (5 levels + disable) can be assigned to lv_tasks. + */ + +#ifndef LV_TASK_H +#define LV_TASK_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include +#include "lv_mem.h" +#include "lv_ll.h" + +/********************* + * DEFINES + *********************/ +#ifndef LV_ATTRIBUTE_TASK_HANDLER +#define LV_ATTRIBUTE_TASK_HANDLER +#endif +/********************** + * TYPEDEFS + **********************/ +/** + * Possible priorities for lv_tasks + */ +enum +{ + LV_TASK_PRIO_OFF = 0, + LV_TASK_PRIO_LOWEST, + LV_TASK_PRIO_LOW, + LV_TASK_PRIO_MID, + LV_TASK_PRIO_HIGH, + LV_TASK_PRIO_HIGHEST, + LV_TASK_PRIO_NUM, +}; +typedef uint8_t lv_task_prio_t; + +/** + * Descriptor of a lv_task + */ +typedef struct +{ + uint32_t period; + uint32_t last_run; + void (*task) (void*); + void * param; + uint8_t prio:3; + uint8_t once:1; +} lv_task_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Init the lv_task module + */ +void lv_task_init(void); + +/** + * Call it periodically to handle lv_tasks. + */ +LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void); + +/** + * Create a new lv_task + * @param task a function which is the task itself + * @param period call period in ms unit + * @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped) + * @param param free parameter + * @return pointer to the new task + */ +lv_task_t* lv_task_create(void (*task) (void *), uint32_t period, lv_task_prio_t prio, void * param); + +/** + * Delete a lv_task + * @param lv_task_p pointer to task created by lv_task_p + */ +void lv_task_del(lv_task_t* lv_task_p); + +/** + * Set new priority for a lv_task + * @param lv_task_p pointer to a lv_task + * @param prio the new priority + */ +void lv_task_set_prio(lv_task_t* lv_task_p, lv_task_prio_t prio); + +/** + * Set new period for a lv_task + * @param lv_task_p pointer to a lv_task + * @param period the new period + */ +void lv_task_set_period(lv_task_t* lv_task_p, uint32_t period); + +/** + * Make a lv_task ready. It will not wait its period. + * @param lv_task_p pointer to a lv_task. + */ +void lv_task_ready(lv_task_t* lv_task_p); + + +/** + * Delete the lv_task after one call + * @param lv_task_p pointer to a lv_task. + */ +void lv_task_once(lv_task_t * lv_task_p); + +/** + * Reset a lv_task. + * It will be called the previously set period milliseconds later. + * @param lv_task_p pointer to a lv_task. + */ +void lv_task_reset(lv_task_t* lv_task_p); + +/** + * Enable or disable the whole lv_task handling + * @param en: true: lv_task handling is running, false: lv_task handling is suspended + */ +void lv_task_enable(bool en); + +/** + * Get idle percentage + * @return the lv_task idle in percentage + */ +uint8_t lv_task_get_idle(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.c new file mode 100644 index 0000000..11478b7 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.c @@ -0,0 +1,36 @@ +/** + * @file lv_templ.c + * + */ + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.h new file mode 100644 index 0000000..a5459e8 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_templ.h @@ -0,0 +1,38 @@ +/** + * @file lv_templ.h + * + */ + +#ifndef LV_TEMPL_H +#define LV_TEMPL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TEMPL_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.c new file mode 100644 index 0000000..09c3186 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.c @@ -0,0 +1,793 @@ +/** + * @file lv_text.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_txt.h" +#include "lv_math.h" + +/********************* + * DEFINES + *********************/ +#define NO_BREAK_FOUND UINT32_MAX + +#ifndef LV_TXT_LINE_BREAK_LONG_LEN +#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */ +#endif + +#ifndef LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN +#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */ +#endif + +#ifndef LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN +#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */ +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool is_break_char(uint32_t letter); + +#if LV_TXT_UTF8 +static uint8_t lv_txt_utf8_size(const char * str); +static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni); +static uint32_t lv_txt_utf8_conv_wc(uint32_t c); +static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i); +static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i_start); +static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id); +static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id); +static uint32_t lv_txt_utf8_get_length(const char * txt); +#else +static uint8_t lv_txt_ascii_size(const char * str); +static uint32_t lv_txt_unicode_to_ascii(uint32_t letter_uni); +static uint32_t lv_txt_ascii_conv_wc(uint32_t c); +static uint32_t lv_txt_ascii_next(const char * txt, uint32_t * i); +static uint32_t lv_txt_ascii_prev(const char * txt, uint32_t * i_start); +static uint32_t lv_txt_ascii_get_byte_id(const char * txt, uint32_t utf8_id); +static uint32_t lv_txt_ascii_get_char_id(const char * txt, uint32_t byte_id); +static uint32_t lv_txt_ascii_get_length(const char * txt); +#endif + +/********************** + * STATIC VARIABLES + **********************/ + + +/********************** + * GLOBAL VARIABLES + **********************/ +#if LV_TXT_UTF8 +uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_utf8_size; +uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_utf8; +uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_utf8_conv_wc; +uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_utf8_next; +uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_utf8_prev; +uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_utf8_get_byte_id; +uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id; +uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_utf8_get_length; +#else +uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_ascii_size; +uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_ascii; +uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_ascii_conv_wc; +uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_ascii_next; +uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_ascii_prev; +uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_ascii_get_byte_id; +uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t) = lv_txt_ascii_get_char_id; +uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_ascii_get_length; +#endif +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Get size of a text + * @param size_res pointer to a 'point_t' variable to store the result + * @param text pointer to a text + * @param font pinter to font of the text + * @param letter_space letter space of the text + * @param txt.line_space line space of the text + * @param flags settings for the text from 'txt_flag_t' enum + * @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks + */ +void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, + lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag) +{ + size_res->x = 0; + size_res->y = 0; + + if(text == NULL) return; + if(font == NULL) return; + + if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX; + + uint32_t line_start = 0; + uint32_t new_line_start = 0; + lv_coord_t act_line_length; + uint8_t letter_height = lv_font_get_height(font); + + /*Calc. the height and longest line*/ + while(text[line_start] != '\0') { + new_line_start += lv_txt_get_next_line(&text[line_start], font, letter_space, max_width, flag); + size_res->y += letter_height ; + size_res->y += line_space; + + /*Calculate the the longest line*/ + act_line_length = lv_txt_get_width(&text[line_start], new_line_start - line_start, + font, letter_space, flag); + + size_res->x = LV_MATH_MAX(act_line_length, size_res->x); + line_start = new_line_start; + } + + /*Make the text one line taller if the last character is '\n' or '\r'*/ + if((line_start != 0) && (text[line_start - 1] == '\n' || text[line_start - 1] == '\r')) { + size_res->y += letter_height + line_space; + } + + /*Correction with the last line space or set the height manually if the text is empty*/ + if(size_res->y == 0) size_res->y = letter_height; + else size_res->y -= line_space; + +} + +/** + * Get the next line of text. Check line length and break chars too. + * @param txt a '\0' terminated string + * @param font pointer to a font + * @param letter_space letter space + * @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks + * @param flags settings for the text from 'txt_flag_type' enum + * @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different) + */ +uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, + lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag) +{ + if(txt == NULL) return 0; + if(font == NULL) return 0; + + if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX; + + uint32_t i = 0; + lv_coord_t cur_w = 0; + lv_coord_t w_at_last_break = 0; + uint32_t n_char_since_last_break = 0; /* Used count word length of long words */ + uint32_t last_break = NO_BREAK_FOUND; + lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT; + uint32_t letter = 0; + + while(txt[i] != '\0') { + lv_coord_t letter_width; + letter = lv_txt_encoded_next(txt, &i); + + /*Handle the recolor command*/ + if((flag & LV_TXT_FLAG_RECOLOR) != 0) { + if(lv_txt_is_cmd(&cmd_state, letter) != false) { + continue; /*Skip the letter is it is part of a command*/ + } + } + + + /*Check for new line chars*/ + if(letter == '\n' || letter == '\r') { + uint32_t i_tmp = i; + uint32_t letter_next = lv_txt_encoded_next(txt, &i_tmp); + if(letter == '\r' && letter_next == '\n') i = i_tmp; + + return i; /*Return with the first letter of the next line*/ + + } else { /*Check the actual length*/ + n_char_since_last_break++; + letter_width = lv_font_get_width(font, letter); + cur_w += letter_width; + + /* Get the length of the current work and determine best place + * to break the line. */ + if(cur_w > max_width) { + if( last_break != NO_BREAK_FOUND ) { + /* Continue searching for next breakable character to see if the next word will fit */ + uint32_t n_char_fit = n_char_since_last_break - 1; + if( n_char_since_last_break <= LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN ) { + i = last_break; + } + else { + uint32_t i_tmp = i; + cur_w -= w_at_last_break + letter_space; /*ignore the first letter_space after the break char */ + bool other = true; + while(txt[i_tmp] != '\0') { + letter = lv_txt_encoded_next(txt, &i_tmp); + + /*Handle the recolor command*/ + if((flag & LV_TXT_FLAG_RECOLOR) != 0) { + if(lv_txt_is_cmd(&cmd_state, letter) != false) { + continue; /*Skip the letter is it is part of a command*/ + } + } + + /*Check for new line chars*/ + if(letter == '\n' || letter == '\r' || is_break_char(letter)) { + if(n_char_since_last_break >= LV_TXT_LINE_BREAK_LONG_LEN) { + /* Figure out the prettiest place to break */ + uint32_t char_remain; + lv_txt_encoded_prev(txt, &i); + for(char_remain=n_char_since_last_break - n_char_fit; + char_remain < LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN; + char_remain++) { + lv_txt_encoded_prev(txt, &i); + } + } + else{ + i = last_break; + } + other = false; + break; + } + n_char_since_last_break++; + lv_coord_t letter_width2 = lv_font_get_width(font, letter); + cur_w += letter_width2; + if(cur_w > max_width) { + /* Current letter already exceeds, return previous */ + lv_txt_encoded_prev(txt, &i); + other = false; + break; + } + if(letter_width2 > 0){ + cur_w += letter_space; + } + } + if( other ) { + if(n_char_since_last_break >= LV_TXT_LINE_BREAK_LONG_LEN) { + /* Figure out the prettiest place to break */ + uint32_t char_remain; + lv_txt_encoded_prev(txt, &i); + for(char_remain=n_char_since_last_break - n_char_fit; + char_remain < LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN; + char_remain++){ + lv_txt_encoded_prev(txt, &i); + } + } + else{ + i = last_break; + } + } + } + } else { + /* Now this character is out of the area so it will be first character of the next line*/ + /* But 'i' already points to the next character (because of lv_txt_utf8_next) step beck one*/ + lv_txt_encoded_prev(txt, &i); + } + + /* Do not let to return without doing nothing. + * Find at least one character (Avoid infinite loop )*/ + if(i == 0) lv_txt_encoded_next(txt, &i); + + return i; + } + /*If this char still can fit to this line then check if + * txt can be broken here later */ + else if(is_break_char(letter)) { + last_break = i; /*Save the first char index after break*/ + w_at_last_break = cur_w; + if(letter_width > 0) { + w_at_last_break += letter_space; + } + n_char_since_last_break = 0; + } + } + + if(letter_width > 0) { + cur_w += letter_space; + } + } + + return i; +} + +/** + * Give the length of a text with a given font + * @param txt a '\0' terminate string + * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8) + * @param font pointer to a font + * @param letter_space letter space + * @param flags settings for the text from 'txt_flag_t' enum + * @return length of a char_num long text + */ +lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, + const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag) +{ + if(txt == NULL) return 0; + if(font == NULL) return 0; + + uint32_t i = 0; + lv_coord_t width = 0; + lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT; + uint32_t letter; + + if(length != 0) { + while(i< length){ + letter = lv_txt_encoded_next(txt, &i); + if((flag & LV_TXT_FLAG_RECOLOR) != 0) { + if(lv_txt_is_cmd(&cmd_state, letter) != false) { + continue; + } + } + + lv_coord_t char_width = lv_font_get_width(font, letter); + if(char_width > 0){ + width += char_width; + width += letter_space; + } + } + + if(width > 0) { + width -= letter_space; /*Trim the last letter space. Important if the text is center aligned */ + } + } + + return width; +} + +/** + * Check next character in a string and decide if the character is part of the command or not + * @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing + * (Initied. to TXT_CMD_STATE_WAIT ) + * @param c the current character + * @return true: the character is part of a command and should not be written, + * false: the character should be written + */ +bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c) +{ + bool ret = false; + + if(c == (uint32_t)LV_TXT_COLOR_CMD[0]) { + if(*state == LV_TXT_CMD_STATE_WAIT) { /*Start char*/ + *state = LV_TXT_CMD_STATE_PAR; + ret = true; + } else if(*state == LV_TXT_CMD_STATE_PAR) { /*Other start char in parameter is escaped cmd. char */ + *state = LV_TXT_CMD_STATE_WAIT; + } else if(*state == LV_TXT_CMD_STATE_IN) { /*Command end */ + *state = LV_TXT_CMD_STATE_WAIT; + ret = true; + } + } + + /*Skip the color parameter and wait the space after it*/ + if(*state == LV_TXT_CMD_STATE_PAR) { + if(c == ' ') { + *state = LV_TXT_CMD_STATE_IN; /*After the parameter the text is in the command*/ + } + ret = true; + } + + return ret; +} + +/** + * Insert a string into an other + * @param txt_buf the original text (must be big enough for the result text) + * @param pos position to insert. Expressed in character index and not byte index (Different in UTF-8) + * 0: before the original text, 1: after the first char etc. + * @param ins_txt text to insert + */ +void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt) +{ + uint32_t old_len = strlen(txt_buf); + uint32_t ins_len = strlen(ins_txt); + uint32_t new_len = ins_len + old_len; +#if LV_TXT_UTF8 != 0 + pos = lv_txt_encoded_get_byte_id(txt_buf, pos); /*Convert to byte index instead of letter index*/ +#endif + /*Copy the second part into the end to make place to text to insert*/ + uint32_t i; + for(i = new_len; i >= pos + ins_len; i--) { + txt_buf[i] = txt_buf[i - ins_len]; + } + + /* Copy the text into the new space*/ + memcpy(txt_buf + pos, ins_txt, ins_len); +} + +/** + * Delete a part of a string + * @param txt string to modify + * @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.) + * @param len number of characters to delete + */ +void lv_txt_cut(char * txt, uint32_t pos, uint32_t len) +{ + + uint32_t old_len = strlen(txt); +#if LV_TXT_UTF8 != 0 + pos = lv_txt_encoded_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/ + len = lv_txt_encoded_get_byte_id(&txt[pos], len); +#endif + + /*Copy the second part into the end to make place to text to insert*/ + uint32_t i; + for(i = pos; i <= old_len - len; i++) { + txt[i] = txt[i + len]; + } +} + + +/******************************* + * UTF-8 ENCODER/DECOER + ******************************/ + +#if LV_TXT_UTF8 + +/** + * Give the size of an UTF-8 coded character + * @param str pointer to a character in a string + * @return length of the UTF-8 character (1,2,3 or 4). O on invalid code + */ +static uint8_t lv_txt_utf8_size(const char * str) +{ + if((str[0] & 0x80) == 0) return 1; + else if((str[0] & 0xE0) == 0xC0) return 2; + else if((str[0] & 0xF0) == 0xE0) return 3; + else if((str[0] & 0xF8) == 0xF0) return 4; + return 0; +} + + +/** + * Convert an Unicode letter to UTF-8. + * @param letter_uni an Unicode letter + * @return UTF-8 coded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ű') + */ +static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni) +{ + if(letter_uni < 128) return letter_uni; + uint8_t bytes[4]; + + if(letter_uni < 0x0800) { + bytes[0] = ((letter_uni >> 6) & 0x1F) | 0xC0; + bytes[1] = ((letter_uni >> 0) & 0x3F) | 0x80; + bytes[2] = 0; + bytes[3] = 0; + } else if(letter_uni < 0x010000) { + bytes[0] = ((letter_uni >> 12) & 0x0F) | 0xE0; + bytes[1] = ((letter_uni >> 6) & 0x3F) | 0x80; + bytes[2] = ((letter_uni >> 0) & 0x3F) | 0x80; + bytes[3] = 0; + } else if(letter_uni < 0x110000) { + bytes[0] = ((letter_uni >> 18) & 0x07) | 0xF0; + bytes[1] = ((letter_uni >> 12) & 0x3F) | 0x80; + bytes[2] = ((letter_uni >> 6) & 0x3F) | 0x80; + bytes[3] = ((letter_uni >> 0) & 0x3F) | 0x80; + } + + uint32_t * res_p = (uint32_t *)bytes; + return *res_p; +} + +/** + * Convert a wide character, e.g. 'Á' little endian to be UTF-8 compatible + * @param c a wide character or a Little endian number + * @return `c` in big endian + */ +static uint32_t lv_txt_utf8_conv_wc(uint32_t c) +{ + /*Swap the bytes (UTF-8 is big endian, but the MCUs are little endian)*/ + if((c & 0x80) != 0) { + uint32_t swapped; + uint8_t c8[4]; + memcpy(c8, &c, 4); + swapped = (c8[0] << 24) + (c8[1] << 16) + (c8[2] << 8) + (c8[3]); + uint8_t i; + for(i = 0; i < 4; i++) { + if((swapped & 0xFF) == 0) swapped = (swapped >> 8); /*Ignore leading zeros (they were in the end originally)*/ + } + c = swapped; + } + + return c; +} + +/** + * Decode an UTF-8 character from a string. + * @param txt pointer to '\0' terminated string + * @param i start byte index in 'txt' where to start. + * After call it will point to the next UTF-8 char in 'txt'. + * NULL to use txt[0] as index + * @return the decoded Unicode character or 0 on invalid UTF-8 code + */ +static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i) +{ + /* Unicode to UTF-8 + * 00000000 00000000 00000000 0xxxxxxx -> 0xxxxxxx + * 00000000 00000000 00000yyy yyxxxxxx -> 110yyyyy 10xxxxxx + * 00000000 00000000 zzzzyyyy yyxxxxxx -> 1110zzzz 10yyyyyy 10xxxxxx + * 00000000 000wwwzz zzzzyyyy yyxxxxxx -> 11110www 10zzzzzz 10yyyyyy 10xxxxxx + * */ + + uint32_t result = 0; + + /*Dummy 'i' pointer is required*/ + uint32_t i_tmp = 0; + if(i == NULL) i = &i_tmp; + + /*Normal ASCII*/ + if((txt[*i] & 0x80) == 0) { + result = txt[*i]; + (*i)++; + } + /*Real UTF-8 decode*/ + else { + /*2 bytes UTF-8 code*/ + if((txt[*i] & 0xE0) == 0xC0) { + result = (uint32_t)(txt[*i] & 0x1F) << 6; + (*i)++; + if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/ + result += (txt[*i] & 0x3F); + (*i)++; + } + /*3 bytes UTF-8 code*/ + else if((txt[*i] & 0xF0) == 0xE0) { + result = (uint32_t)(txt[*i] & 0x0F) << 12; + (*i)++; + + if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/ + result += (uint32_t)(txt[*i] & 0x3F) << 6; + (*i)++; + + if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/ + result += (txt[*i] & 0x3F); + (*i)++; + } + /*4 bytes UTF-8 code*/ + else if((txt[*i] & 0xF8) == 0xF0) { + result = (uint32_t)(txt[*i] & 0x07) << 18; + (*i)++; + + if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/ + result += (uint32_t)(txt[*i] & 0x3F) << 12; + (*i)++; + + if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/ + result += (uint32_t)(txt[*i] & 0x3F) << 6; + (*i)++; + + if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/ + result += txt[*i] & 0x3F; + (*i)++; + } else { + (*i)++; /*Not UTF-8 char. Go the next.*/ + } + } + return result; +} + +/** + * Get previous UTF-8 character form a string. + * @param txt pointer to '\0' terminated string + * @param i start byte index in 'txt' where to start. After the call it will point to the previous UTF-8 char in 'txt'. + * @return the decoded Unicode character or 0 on invalid UTF-8 code + */ +static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i) +{ + uint8_t c_size; + uint8_t cnt = 0; + + /*Try to find a !0 long UTF-8 char by stepping one character back*/ + (*i)--; + do { + if(cnt >= 4) return 0; /*No UTF-8 char found before the initial*/ + + c_size = lv_txt_encoded_size(&txt[*i]); + if(c_size == 0) { + if(*i != 0)(*i)--; + else return 0; + } + cnt++; + } while(c_size == 0); + + uint32_t i_tmp = *i; + uint32_t letter = lv_txt_encoded_next(txt, &i_tmp); /*Character found, get it*/ + + return letter; + +} + +/** + * Convert a character index (in an UTF-8 text) to byte index. + * E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param utf8_id character index + * @return byte index of the 'utf8_id'th letter + */ +static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id) +{ + uint32_t i; + uint32_t byte_cnt = 0; + for(i = 0; i < utf8_id; i++) { + byte_cnt += lv_txt_encoded_size(&txt[byte_cnt]); + } + + return byte_cnt; + +} + + +/** + * Convert a byte index (in an UTF-8 text) to character index. + * E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param byte_id byte index + * @return character index of the letter at 'byte_id'th position + */ +static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id) +{ + uint32_t i = 0; + uint32_t char_cnt = 0; + + while(i < byte_id) { + lv_txt_encoded_next(txt, &i); /*'i' points to the next letter so use the prev. value*/ + char_cnt++; + } + + return char_cnt; +} + +/** + * Get the number of characters (and NOT bytes) in a string. Decode it with UTF-8 if enabled. + * E.g.: "ÁBC" is 3 characters (but 4 bytes) + * @param txt a '\0' terminated char string + * @return number of characters + */ +static uint32_t lv_txt_utf8_get_length(const char * txt) +{ +#if LV_TXT_UTF8 == 0 + return strlen(txt); +#else + uint32_t len = 0; + uint32_t i = 0; + + while(txt[i] != '\0') { + lv_txt_encoded_next(txt, &i); + len++; + } + + return len; +#endif +} + +#else +/** + * Give the size of an UTF-8 coded character + * @param str pointer to a character in a string + * @return length of the UTF-8 character (1,2,3 or 4). O on invalid code + */ +static uint8_t lv_txt_ascii_size(const char * str) +{ + return 1; +} + + +/** + * Convert an Unicode letter to UTF-8. + * @param letter_uni an Unicode letter + * @return UTF-8 coded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ű') + */ +static uint32_t lv_txt_unicode_to_ascii(uint32_t letter_uni) +{ + if(letter_uni < 128) return letter_uni; + else return ' '; +} + +/** + * Convert wide characters to ASCII, however wide characters in ASCII range (e.g. 'A') are ASCII compatible by default. + * So this function does nothing just returns with `c`. + * @param c a character, e.g. 'A' + * @return same as `c` + */ +static uint32_t lv_txt_ascii_conv_wc(uint32_t c) +{ + return c; +} + +/** + * Decode an UTF-8 character from a string. + * @param txt pointer to '\0' terminated string + * @param i start byte index in 'txt' where to start. + * After call it will point to the next UTF-8 char in 'txt'. + * NULL to use txt[0] as index + * @return the decoded Unicode character or 0 on invalid UTF-8 code + */ +static uint32_t lv_txt_ascii_next(const char * txt, uint32_t * i) +{ + if(i == NULL) return txt[1]; /*Get the next char */ + + uint8_t letter = txt[*i] ; + (*i)++; + return letter; +} + +/** + * Get previous UTF-8 character form a string. + * @param txt pointer to '\0' terminated string + * @param i start byte index in 'txt' where to start. After the call it will point to the previous UTF-8 char in 'txt'. + * @return the decoded Unicode character or 0 on invalid UTF-8 code + */ +static uint32_t lv_txt_ascii_prev(const char * txt, uint32_t * i) +{ + if(i == NULL) return *(txt - 1); /*Get the prev. char */ + + (*i)--; + uint8_t letter = txt[*i] ; + + return letter; +} + +/** + * Convert a character index (in an UTF-8 text) to byte index. + * E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param utf8_id character index + * @return byte index of the 'utf8_id'th letter + */ +static uint32_t lv_txt_ascii_get_byte_id(const char * txt, uint32_t utf8_id) +{ + return utf8_id; /*In Non encoded no difference*/ +} + + +/** + * Convert a byte index (in an UTF-8 text) to character index. + * E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param byte_id byte index + * @return character index of the letter at 'byte_id'th position + */ +static uint32_t lv_txt_ascii_get_char_id(const char * txt, uint32_t byte_id) +{ + return byte_id; /*In Non encoded no difference*/ +} + +/** + * Get the number of characters (and NOT bytes) in a string. Decode it with UTF-8 if enabled. + * E.g.: "ÁBC" is 3 characters (but 4 bytes) + * @param txt a '\0' terminated char string + * @return number of characters + */ +static uint32_t lv_txt_ascii_get_length(const char * txt) +{ + return strlen(txt); +} +#endif +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Test if char is break char or not (a text can broken here or not) + * @param letter a letter + * @return false: 'letter' is not break char + */ +static bool is_break_char(uint32_t letter) +{ + uint8_t i; + bool ret = false; + + /*Compare the letter to TXT_BREAK_CHARS*/ + for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) { + if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) { + ret = true; /*If match then it is break char*/ + break; + } + } + + return ret; +} + diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.h new file mode 100644 index 0000000..81b55f9 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_txt.h @@ -0,0 +1,197 @@ +/** + * @file lv_text.h + * + */ + +#ifndef LV_TXT_H +#define LV_TXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include "lv_area.h" +#include "lv_font.h" +#include "lv_area.h" + +/********************* + * DEFINES + *********************/ +#define LV_TXT_COLOR_CMD "#" + +/********************** + * TYPEDEFS + **********************/ +enum +{ + LV_TXT_FLAG_NONE = 0x00, + LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/ + LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width to avoid automatic word wrapping*/ + LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/ + LV_TXT_FLAG_RIGHT = 0x08, /*Align the text to the right*/ +}; +typedef uint8_t lv_txt_flag_t; + +enum +{ + LV_TXT_CMD_STATE_WAIT, /*Waiting for command*/ + LV_TXT_CMD_STATE_PAR, /*Processing the parameter*/ + LV_TXT_CMD_STATE_IN, /*Processing the command*/ +}; +typedef uint8_t lv_txt_cmd_state_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Get size of a text + * @param size_res pointer to a 'point_t' variable to store the result + * @param text pointer to a text + * @param font pinter to font of the text + * @param letter_space letter space of the text + * @param line_space line space of the text + * @param flags settings for the text from 'txt_flag_t' enum + * @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks + */ +void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, + lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag); + +/** + * Get the next line of text. Check line length and break chars too. + * @param txt a '\0' terminated string + * @param font pointer to a font + * @param letter_space letter space + * @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks + * @param flags settings for the text from 'txt_flag_type' enum + * @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different) + */ +uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, + lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag); + +/** + * Give the length of a text with a given font + * @param txt a '\0' terminate string + * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8) + * @param font pointer to a font + * @param letter_space letter space + * @param flags settings for the text from 'txt_flag_t' enum + * @return length of a char_num long text + */ +lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, + const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag); + + +/** + * Check next character in a string and decide if te character is part of the command or not + * @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing + * @param c the current character + * @return true: the character is part of a command and should not be written, + * false: the character should be written + */ +bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c); + +/** + * Insert a string into an other + * @param txt_buf the original text (must be big enough for the result text) + * @param pos position to insert (0: before the original text, 1: after the first char etc.) + * @param ins_txt text to insert + */ +void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt); + +/** + * Delete a part of a string + * @param txt string to modify + * @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.) + * @param len number of characters to delete + */ +void lv_txt_cut(char * txt, uint32_t pos, uint32_t len); + +/*************************************************************** + * GLOBAL FUNCTION POINTERS FOR CAHRACTER ENCODING INTERFACE + ***************************************************************/ + +/** + * Give the size of an encoded character + * @param str pointer to a character in a string + * @return length of the encoded character (1,2,3 ...). O in invalid + */ +extern uint8_t (*lv_txt_encoded_size)(const char *); + + +/** + * Convert an Unicode letter to encoded + * @param letter_uni an Unicode letter + * @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü') + */ +extern uint32_t (*lv_txt_unicode_to_encoded)(uint32_t ); + +/** + * Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format. + * @param c a wide character + * @return `c` in the encoded format + */ +extern uint32_t (*lv_txt_encoded_conv_wc) (uint32_t c); + +/** + * Decode the next encoded character from a string. + * @param txt pointer to '\0' terminated string + * @param i start index in 'txt' where to start. + * After the call it will point to the next encoded char in 'txt'. + * NULL to use txt[0] as index + * @return the decoded Unicode character or 0 on invalid data code + */ +extern uint32_t (*lv_txt_encoded_next)(const char *, uint32_t * ); + +/** + * Get the previous encoded character form a string. + * @param txt pointer to '\0' terminated string + * @param i_start index in 'txt' where to start. After the call it will point to the previous encoded char in 'txt'. + * @return the decoded Unicode character or 0 on invalid data + */ +extern uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *); + +/** + * Convert a letter index (in an the encoded text) to byte index. + * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param enc_id letter index + * @return byte index of the 'enc_id'th letter + */ +extern uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t); + +/** + * Convert a byte index (in an encoded text) to character index. + * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param byte_id byte index + * @return character index of the letter at 'byte_id'th position + */ +extern uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t); + +/** + * Get the number of characters (and NOT bytes) in a string. + * E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes) + * @param txt a '\0' terminated char string + * @return number of characters + */ +extern uint32_t (*lv_txt_get_encoded_length)(const char *); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*USE_TXT*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.c b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.c new file mode 100644 index 0000000..ef1a165 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.c @@ -0,0 +1,516 @@ +/** + * @file lv_ufs.c + * Implementation of RAM file system which do NOT support directories. + * The API is compatible with the lv_fs_int module. + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_ufs.h" +#if USE_LV_FILESYSTEM + +#include "lv_ll.h" +#include +#include +#include +#include "lv_gc.h" + +#if defined(LV_GC_INCLUDE) +# include LV_GC_INCLUDE +#endif /* LV_ENABLE_GC */ + + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_ufs_ent_t * lv_ufs_ent_get(const char * fn); +static lv_ufs_ent_t * lv_ufs_ent_new(const char * fn); + +/********************** + * STATIC VARIABLES + **********************/ +static bool inited = false; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a driver for ufs and initialize it. + */ +void lv_ufs_init(void) +{ + lv_ll_init(&LV_GC_ROOT(_lv_file_ll), sizeof(lv_ufs_ent_t)); + + lv_fs_drv_t ufs_drv; + memset(&ufs_drv, 0, sizeof(lv_fs_drv_t)); /*Initialization*/ + + ufs_drv.file_size = sizeof(lv_ufs_file_t); + ufs_drv.rddir_size = sizeof(lv_ufs_dir_t); + ufs_drv.letter = UFS_LETTER; + ufs_drv.ready = lv_ufs_ready; + + ufs_drv.open = lv_ufs_open; + ufs_drv.close = lv_ufs_close; + ufs_drv.remove = lv_ufs_remove; + ufs_drv.read = lv_ufs_read; + ufs_drv.write = lv_ufs_write; + ufs_drv.seek = lv_ufs_seek; + ufs_drv.tell = lv_ufs_tell; + ufs_drv.size = lv_ufs_size; + ufs_drv.trunc = lv_ufs_trunc; + ufs_drv.free = lv_ufs_free; + + ufs_drv.dir_open = lv_ufs_dir_open; + ufs_drv.dir_read = lv_ufs_dir_read; + ufs_drv.dir_close = lv_ufs_dir_close; + + lv_fs_add_drv(&ufs_drv); + + inited = true; +} + +/** + * Give the state of the ufs + * @return true if ufs is initialized and can be used else false + */ +bool lv_ufs_ready(void) +{ + return inited; +} + +/** + * Open a file in ufs + * @param file_p pointer to a lv_ufs_file_t variable + * @param fn name of the file. There are no directories so e.g. "myfile.txt" + * @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD) + * @return LV_FS_RES_OK: no error, the file is opened + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_open(void * file_p, const char * fn, lv_fs_mode_t mode) +{ + lv_ufs_file_t * fp = file_p; /*Convert type*/ + lv_ufs_ent_t * ent = lv_ufs_ent_get(fn); + + fp->ent = NULL; + + /*If the file not exists ...*/ + if(ent == NULL) { + if((mode & LV_FS_MODE_WR) != 0) { /*Create the file if opened for write*/ + ent = lv_ufs_ent_new(fn); + if(ent == NULL) return LV_FS_RES_FULL; /*No space for the new file*/ + } else { + return LV_FS_RES_NOT_EX; /*Can not read not existing file*/ + } + } + + /*Can not write already opened and const data files*/ + if((mode & LV_FS_MODE_WR) != 0) { + if(ent->oc != 0) return LV_FS_RES_LOCKED; + if(ent->const_data != 0) return LV_FS_RES_DENIED; + } + + /*No error, the file can be opened*/ + fp->ent = ent; + fp->ar = mode & LV_FS_MODE_RD ? 1 : 0; + fp->aw = mode & LV_FS_MODE_WR ? 1 : 0; + fp->rwp = 0; + ent->oc ++; + + return LV_FS_RES_OK; +} + + +/** + * Create a file with a constant data + * @param fn name of the file (directories are not supported) + * @param const_p pointer to a constant data + * @param len length of the data pointed by 'const_p' in bytes + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len) +{ + lv_ufs_file_t file; + lv_fs_res_t res; + + /*Error if the file already exists*/ + res = lv_ufs_open(&file, fn, LV_FS_MODE_RD); + if(res == LV_FS_RES_OK) { + lv_ufs_close(&file); + return LV_FS_RES_DENIED; + } + + lv_ufs_close(&file); + + res = lv_ufs_open(&file, fn, LV_FS_MODE_WR); + if(res != LV_FS_RES_OK) return res; + + lv_ufs_ent_t * ent = file.ent; + + if(ent->data_d != NULL) return LV_FS_RES_DENIED; + + ent->data_d = (void *) const_p; + ent->size = len; + ent->const_data = 1; + + res = lv_ufs_close(&file); + if(res != LV_FS_RES_OK) return res; + + return LV_FS_RES_OK; +} + +/** + * Close an opened file + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_close(void * file_p) +{ + lv_ufs_file_t * fp = file_p; /*Convert type*/ + + if(fp->ent == NULL) return LV_FS_RES_OK; + + /*Decrement the Open counter*/ + if(fp->ent->oc > 0) { + fp->ent->oc--; + } + + return LV_FS_RES_OK; +} + +/** + * Remove a file. The file can not be opened. + * @param fn '\0' terminated string + * @return LV_FS_RES_OK: no error, the file is removed + * LV_FS_RES_DENIED: the file was opened, remove failed + */ +lv_fs_res_t lv_ufs_remove(const char * fn) +{ + lv_ufs_ent_t * ent = lv_ufs_ent_get(fn); + if(ent == NULL) return LV_FS_RES_DENIED; /*File not exists*/ + + /*Can not be deleted is opened*/ + if(ent->oc != 0) return LV_FS_RES_DENIED; + + lv_ll_rem(&LV_GC_ROOT(_lv_file_ll), ent); + lv_mem_free(ent->fn_d); + ent->fn_d = NULL; + if(ent->const_data == 0) { + lv_mem_free(ent->data_d); + ent->data_d = NULL; + } + + lv_mem_free(ent); + + return LV_FS_RES_OK; +} + +/** + * Read data from an opened file + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @param buf pointer to a memory block where to store the read data + * @param btr number of Bytes To Read + * @param br the real number of read bytes (Byte Read) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_read(void * file_p, void * buf, uint32_t btr, uint32_t * br) +{ + lv_ufs_file_t * fp = file_p; /*Convert type*/ + + lv_ufs_ent_t * ent = fp->ent; + *br = 0; + + if(ent->data_d == NULL || ent->size == 0) { /*Don't read empty files*/ + return LV_FS_RES_OK; + } else if(fp->ar == 0) { /*The file is not opened for read*/ + return LV_FS_RES_DENIED; + } + + /*No error, read the file*/ + if(fp->rwp + btr > ent->size) { /*Check too much bytes read*/ + *br = ent->size - fp->rwp; + } else { + *br = btr; + } + + /*Read the data*/ + uint8_t * data8_p; + if(ent->const_data == 0) { + data8_p = (uint8_t *) ent->data_d; + } else { + data8_p = ent->data_d; + } + + data8_p += fp->rwp; + memcpy(buf, data8_p, *br); + + fp->rwp += *br; /*Refresh the read write pointer*/ + + return LV_FS_RES_OK; +} + +/** + * Write data to an opened file + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open) + * @param buf pointer to a memory block which content will be written + * @param btw the number Bytes To Write + * @param bw The real number of written bytes (Byte Written) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_write(void * file_p, const void * buf, uint32_t btw, uint32_t * bw) +{ + lv_ufs_file_t * fp = file_p; /*Convert type*/ + *bw = 0; + + if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/ + + lv_ufs_ent_t * ent = fp->ent; + + /*Reallocate data array if it necessary*/ + uint32_t new_size = fp->rwp + btw; + if(new_size > ent->size) { + uint8_t * new_data = lv_mem_realloc(ent->data_d, new_size); + lv_mem_assert(new_data); + if(new_data == NULL) return LV_FS_RES_FULL; /*Cannot allocate the new memory*/ + + ent->data_d = new_data; + ent->size = new_size; + } + + /*Write the file*/ + uint8_t * data8_p = (uint8_t *) ent->data_d; + data8_p += fp->rwp; + memcpy(data8_p, buf, btw); + *bw = btw; + fp->rwp += *bw; + + return LV_FS_RES_OK; +} + +/** + * Set the read write pointer. Also expand the file size if necessary. + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @param pos the new position of read write pointer + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_seek(void * file_p, uint32_t pos) +{ + lv_ufs_file_t * fp = file_p; /*Convert type*/ + lv_ufs_ent_t * ent = fp->ent; + + /*Simply move the rwp before EOF*/ + if(pos < ent->size) { + fp->rwp = pos; + } else { /*Expand the file size*/ + if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/ + + uint8_t * new_data = lv_mem_realloc(ent->data_d, pos); + lv_mem_assert(new_data); + if(new_data == NULL) return LV_FS_RES_FULL; /*Out of memory*/ + + ent->data_d = new_data; + ent->size = pos; + fp->rwp = pos; + } + + return LV_FS_RES_OK; +} + +/** + * Give the position of the read write pointer + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @param pos_p pointer to to store the result + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_tell(void * file_p, uint32_t * pos_p) +{ + lv_ufs_file_t * fp = file_p; /*Convert type*/ + + *pos_p = fp->rwp; + + return LV_FS_RES_OK; +} + +/** + * Truncate the file size to the current position of the read write pointer + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_trunc(void * file_p) +{ + lv_ufs_file_t * fp = file_p; /*Convert type*/ + lv_ufs_ent_t * ent = fp->ent; + + if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/ + + void * new_data = lv_mem_realloc(ent->data_d, fp->rwp); + lv_mem_assert(new_data); + if(new_data == NULL) return LV_FS_RES_FULL; /*Out of memory*/ + + ent->data_d = new_data; + ent->size = fp->rwp; + + return LV_FS_RES_OK; +} + +/** + * Give the size of the file in bytes + * @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @param size_p pointer to store the size + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_size(void * file_p, uint32_t * size_p) +{ + lv_ufs_file_t * fp = file_p; /*Convert type*/ + lv_ufs_ent_t * ent = fp->ent; + + *size_p = ent->size; + + return LV_FS_RES_OK; +} + +/** + * Initialize a lv_ufs_read_dir_t variable to directory reading + * @param rddir_p pointer to a 'ufs_dir_t' variable + * @param path uFS doesn't support folders so it has to be "" + * @return LV_FS_RES_OK or any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path) +{ + lv_ufs_dir_t * lv_ufs_rddir_p = rddir_p; + + lv_ufs_rddir_p->last_ent = NULL; + + if(path[0] != '\0') return LV_FS_RES_NOT_EX; /*Must be "" */ + else return LV_FS_RES_OK; +} + +/** + * Read the next file name + * @param dir_p pointer to an initialized 'ufs_dir_t' variable + * @param fn pointer to buffer to sore the file name + * @return LV_FS_RES_OK or any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn) +{ + lv_ufs_dir_t * ufs_dir_p = dir_p; + + if(ufs_dir_p->last_ent == NULL) { + ufs_dir_p->last_ent = lv_ll_get_head(&LV_GC_ROOT(_lv_file_ll)); + } else { + ufs_dir_p->last_ent = lv_ll_get_next(&LV_GC_ROOT(_lv_file_ll), ufs_dir_p->last_ent); + } + + if(ufs_dir_p->last_ent != NULL) { + strcpy(fn, ufs_dir_p->last_ent->fn_d); + } else { + fn[0] = '\0'; + } + + return LV_FS_RES_OK; +} + +/** + * Close the directory reading + * @param rddir_p pointer to an initialized 'ufs_dir_t' variable + * @return LV_FS_RES_OK or any error from lv__fs_res_t enum + */ +lv_fs_res_t lv_ufs_dir_close(void * rddir_p) +{ + (void)rddir_p; + return LV_FS_RES_OK; +} + +/** + * Give the size of a drive + * @param total_p pointer to store the total size [kB] + * @param free_p pointer to store the free site [kB] + * @return LV_FS_RES_OK or any error from 'lv_fs_res_t' + */ +lv_fs_res_t lv_ufs_free(uint32_t * total_p, uint32_t * free_p) +{ + +#if LV_MEM_CUSTOM == 0 + lv_mem_monitor_t mon; + + lv_mem_monitor(&mon); + *total_p = LV_MEM_SIZE >> 10; /*Convert bytes to kB*/ + *free_p = mon.free_size >> 10; +#else + *free_p = 0; +#endif + return LV_FS_RES_OK; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Gives the lv_ufs_entry from a filename + * @param fn filename ('\0' terminated string) + * @return pointer to the dynamically allocated entry with 'fn' filename. + * NULL if no entry found with that name. + */ +static lv_ufs_ent_t * lv_ufs_ent_get(const char * fn) +{ + lv_ufs_ent_t * fp; + + LL_READ(LV_GC_ROOT(_lv_file_ll), fp) { + if(strcmp(fp->fn_d, fn) == 0) { + return fp; + } + } + + return NULL; +} + +/** + * Create a new entry with 'fn' filename + * @param fn filename ('\0' terminated string) + * @return pointer to the dynamically allocated new entry. + * NULL if no space for the entry. + */ +static lv_ufs_ent_t * lv_ufs_ent_new(const char * fn) +{ + lv_ufs_ent_t * new_ent = NULL; + new_ent = lv_ll_ins_head(&LV_GC_ROOT(_lv_file_ll)); /*Create a new file*/ + lv_mem_assert(new_ent); + if(new_ent == NULL) return NULL; + + new_ent->fn_d = lv_mem_alloc(strlen(fn) + 1); /*Save the name*/ + lv_mem_assert(new_ent->fn_d); + if(new_ent->fn_d == NULL) return NULL; + + strcpy(new_ent->fn_d, fn); + new_ent->data_d = NULL; + new_ent->size = 0; + new_ent->oc = 0; + new_ent->const_data = 0; + + return new_ent; +} + +#endif /*USE_LV_FILESYSTEM*/ + diff --git a/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.h b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.h new file mode 100644 index 0000000..543104f --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_misc/lv_ufs.h @@ -0,0 +1,213 @@ +/** + * @file lv_ufs.h + * Implementation of RAM file system which do NOT support directories. + * The API is compatible with the lv_fs_int module. + */ + +#ifndef LV_UFS_H +#define LV_UFS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_FILESYSTEM + +#include "lv_fs.h" +#include "lv_mem.h" + +/********************* + * DEFINES + *********************/ +#define UFS_LETTER 'U' + +/********************** + * TYPEDEFS + **********************/ +/*Description of a file entry */ +typedef struct +{ + char * fn_d; + void * data_d; + uint32_t size; /*Data length in bytes*/ + uint16_t oc; /*Open Count*/ + uint8_t const_data :1; +} lv_ufs_ent_t; + +/*File descriptor, used to handle opening an entry more times simultaneously + Contains unique informations about the specific opening*/ +typedef struct +{ + lv_ufs_ent_t* ent; /*Pointer to the entry*/ + uint32_t rwp; /*Read Write Pointer*/ + uint8_t ar :1; /*1: Access for read is enabled */ + uint8_t aw :1; /*1: Access for write is enabled */ +} lv_ufs_file_t; + +/* Read directory descriptor. + * It is used to to iterate through the entries in a directory*/ +typedef struct +{ + lv_ufs_ent_t * last_ent; +} lv_ufs_dir_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a driver for ufs and initialize it. + */ +void lv_ufs_init(void); + +/** + * Give the state of the ufs + * @return true if ufs is initialized and can be used else false + */ +bool lv_ufs_ready(void); + +/** + * Open a file in ufs + * @param file_p pointer to a lv_ufs_file_t variable + * @param fn name of the file. There are no directories so e.g. "myfile.txt" + * @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD) + * @return LV_FS_RES_OK: no error, the file is opened + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode); + +/** + * Create a file with a constant data + * @param fn name of the file (directories are not supported) + * @param const_p pointer to a constant data + * @param len length of the data pointed by 'const_p' in bytes + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len); + +/** + * Close an opened file + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_close (void * file_p); + +/** + * Remove a file. The file can not be opened. + * @param fn '\0' terminated string + * @return LV_FS_RES_OK: no error, the file is removed + * LV_FS_RES_DENIED: the file was opened, remove failed + */ +lv_fs_res_t lv_ufs_remove(const char * fn); + +/** + * Read data from an opened file + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @param buf pointer to a memory block where to store the read data + * @param btr number of Bytes To Read + * @param br the real number of read bytes (Byte Read) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br); + +/** + * Write data to an opened file + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open) + * @param buf pointer to a memory block which content will be written + * @param btw the number Bytes To Write + * @param bw The real number of written bytes (Byte Written) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw); + +/** + * Set the read write pointer. Also expand the file size if necessary. + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @param pos the new position of read write pointer + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos); + +/** + * Give the position of the read write pointer + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @param pos_p pointer to to store the result + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p); + +/** + * Truncate the file size to the current position of the read write pointer + * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_trunc (void * file_p); + +/** + * Give the size of the file in bytes + * @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) + * @param size_p pointer to store the size + * @return LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p); + +/** + * Initialize a lv_ufs_read_dir_t variable to directory reading + * @param rddir_p pointer to a 'ufs_read_dir_t' variable + * @param path uFS doesn't support folders so it has to be "" + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path); + +/** + * Read the next file name + * @param dir_p pointer to an initialized 'ufs_read_dir_t' variable + * @param fn pointer to buffer to sore the file name + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn); + +/** + * Close the directory reading + * @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_ufs_dir_close(void * rddir_p); + +/** + * Give the size of a drive + * @param total_p pointer to store the total size [kB] + * @param free_p pointer to store the free site [kB] + * @return LV_FS_RES_OK or any error from 'fs_res_t' + */ +lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_FILESYSTEM*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.c new file mode 100644 index 0000000..683d343 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.c @@ -0,0 +1,310 @@ +/** + * @file lv_arc.c + * + */ + + +/********************* + * INCLUDES + *********************/ +#include "lv_arc.h" +#if USE_LV_ARC != 0 + +#include "../lv_misc/lv_math.h" +#include "../lv_draw/lv_draw_arc.h" +#include "../lv_themes/lv_theme.h" + + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_arc_design(lv_obj_t * arc, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_arc_signal(lv_obj_t * arc, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a arc object + * @param par pointer to an object, it will be the parent of the new arc + * @param copy pointer to a arc object, if not NULL then the new object will be copied from it + * @return pointer to the created arc + */ +lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy) +{ + + LV_LOG_TRACE("arc create started"); + + /*Create the ancestor of arc*/ + lv_obj_t * new_arc = lv_obj_create(par, copy); + lv_mem_assert(new_arc); + if(new_arc == NULL) return NULL; + + /*Allocate the arc type specific extended data*/ + lv_arc_ext_t * ext = lv_obj_allocate_ext_attr(new_arc, sizeof(lv_arc_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_arc); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_arc); + + /*Initialize the allocated 'ext' */ + ext->angle_start = 45; + ext->angle_end = 315; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_arc, lv_arc_signal); + lv_obj_set_design_func(new_arc, lv_arc_design); + + /*Init the new arc arc*/ + if(copy == NULL) { + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_arc_set_style(new_arc, LV_ARC_STYLE_MAIN, th->arc); + } else { + lv_arc_set_style(new_arc, LV_ARC_STYLE_MAIN, &lv_style_plain_color); + } + + } + /*Copy an existing arc*/ + else { + lv_arc_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->angle_start = copy_ext->angle_start; + ext->angle_end = copy_ext->angle_end; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_arc); + } + + LV_LOG_INFO("arc created"); + + return new_arc; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/* + * New object specific "add" or "remove" functions come here + */ + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc. + * @param arc pointer to an arc object + * @param start the start angle [0..360] + * @param end the end angle [0..360] + */ +void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end) +{ + lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); + + if(start > 360) start = 360; + if(end > 360) end = 360; + + ext->angle_start = start; + ext->angle_end = end; + + lv_obj_invalidate(arc); +} + +/** + * Set a style of a arc. + * @param arc pointer to arc object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_arc_set_style(lv_obj_t * arc, lv_arc_style_t type, lv_style_t * style) +{ + switch(type) { + case LV_ARC_STYLE_MAIN: + lv_obj_set_style(arc, style); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the start angle of an arc. + * @param arc pointer to an arc object + * @return the start angle [0..360] + */ +uint16_t lv_arc_get_angle_start(lv_obj_t * arc) +{ + lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); + + return ext->angle_start; +} + +/** + * Get the end angle of an arc. + * @param arc pointer to an arc object + * @return the end angle [0..360] + */ +uint16_t lv_arc_get_angle_end(lv_obj_t * arc) +{ + lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); + + return ext->angle_end; +} + +/** + * Get style of a arc. + * @param arc pointer to arc object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_arc_get_style(const lv_obj_t * arc, lv_arc_style_t type) +{ + lv_style_t * style = NULL; + + switch(type) { + case LV_ARC_STYLE_MAIN: + style = lv_obj_get_style(arc); + break; + default: + style = NULL; + break; + } + + return style; +} + +/*===================== + * Other functions + *====================*/ + +/* + * New object specific "other" functions come here + */ + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the arcs + * @param arc pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_arc_design(lv_obj_t * arc, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); + lv_style_t * style = lv_arc_get_style(arc, LV_ARC_STYLE_MAIN); + + lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(arc), lv_obj_get_height(arc))) / 2; + lv_coord_t x = arc->coords.x1 + lv_obj_get_width(arc) / 2; + lv_coord_t y = arc->coords.y1 + lv_obj_get_height(arc) / 2; + lv_opa_t opa_scale = lv_obj_get_opa_scale(arc); + lv_draw_arc(x, y, r, mask, ext->angle_start, ext->angle_end, style, opa_scale); + + + /*Draw circle on the ends if enabled */ + if(style->line.rounded) { + lv_coord_t thick_half = style->line.width / 2; + lv_coord_t cir_x = ((r - thick_half) * lv_trigo_sin(ext->angle_start) >> LV_TRIGO_SHIFT); + lv_coord_t cir_y = ((r - thick_half) * lv_trigo_sin(ext->angle_start + 90) >> LV_TRIGO_SHIFT); + + lv_style_t cir_style; + lv_style_copy(&cir_style, &lv_style_plain); + cir_style.body.grad_color = style->line.color; + cir_style.body.main_color = cir_style.body.grad_color; + cir_style.body.radius = LV_RADIUS_CIRCLE; + lv_area_t cir_area; + cir_area.x1 = cir_x + x - thick_half; + cir_area.y1 = cir_y + y - thick_half; + cir_area.x2 = cir_x + x + thick_half; + cir_area.y2 = cir_y + y + thick_half; + + lv_draw_rect(&cir_area, mask, &cir_style, opa_scale); + + cir_x = ((r - thick_half) * lv_trigo_sin(ext->angle_end) >> LV_TRIGO_SHIFT); + cir_y = ((r - thick_half) * lv_trigo_sin(ext->angle_end + 90) >> LV_TRIGO_SHIFT); + + cir_area.x1 = cir_x + x - thick_half; + cir_area.y1 = cir_y + y - thick_half; + cir_area.x2 = cir_x + x + thick_half; + cir_area.y2 = cir_y + y + thick_half; + + lv_draw_rect(&cir_area, mask, &cir_style, opa_scale); + } + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the arc + * @param arc pointer to a arc object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_arc_signal(lv_obj_t * arc, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(arc, sign, param); + if(res != LV_RES_OK) return res; + + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_arc"; + } + + return res; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.h new file mode 100644 index 0000000..76231d8 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_arc.h @@ -0,0 +1,127 @@ +/** + * @file lv_arc.h + * + */ + + +#ifndef LV_ARC_H +#define LV_ARC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_ARC != 0 + +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of arc*/ +typedef struct { + /*New data for this type */ + lv_coord_t angle_start; + lv_coord_t angle_end; +} lv_arc_ext_t; + + +/*Styles*/ +enum { + LV_ARC_STYLE_MAIN, +}; +typedef uint8_t lv_arc_style_t; + + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a arc objects + * @param par pointer to an object, it will be the parent of the new arc + * @param copy pointer to a arc object, if not NULL then the new object will be copied from it + * @return pointer to the created arc + */ +lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc. + * @param arc pointer to an arc object + * @param start the start angle [0..360] + * @param end the end angle [0..360] + */ +void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end); + +/** + * Set a style of a arc. + * @param arc pointer to arc object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_arc_set_style(lv_obj_t * arc, lv_arc_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the start angle of an arc. + * @param arc pointer to an arc object + * @return the start angle [0..360] + */ +uint16_t lv_arc_get_angle_start(lv_obj_t * arc); + +/** + * Get the end angle of an arc. + * @param arc pointer to an arc object + * @return the end angle [0..360] + */ +uint16_t lv_arc_get_angle_end(lv_obj_t * arc); + +/** + * Get style of a arc. + * @param arc pointer to arc object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_arc_get_style(const lv_obj_t * arc, lv_arc_style_t type); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_ARC*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_ARC_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.c new file mode 100644 index 0000000..d83a609 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.c @@ -0,0 +1,429 @@ + + +/** + * @file lv_bar.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_bar.h" +#if USE_LV_BAR != 0 + +#include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_anim.h" +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_design_func_t ancestor_design_f; +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a bar objects + * @param par pointer to an object, it will be the parent of the new bar + * @param copy pointer to a bar object, if not NULL then the new object will be copied from it + * @return pointer to the created bar + */ +lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("lv_bar create started"); + + /*Create the ancestor basic object*/ + lv_obj_t * new_bar = lv_obj_create(par, copy); + lv_mem_assert(new_bar); + if(new_bar == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_bar); + if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_bar); + + /*Allocate the object type specific extended data*/ + lv_bar_ext_t * ext = lv_obj_allocate_ext_attr(new_bar, sizeof(lv_bar_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->min_value = 0; + ext->max_value = 100; + ext->cur_value = 0; + ext->sym = 0; + ext->style_indic = &lv_style_pretty_color; + + lv_obj_set_signal_func(new_bar, lv_bar_signal); + lv_obj_set_design_func(new_bar, lv_bar_design); + + /*Init the new bar object*/ + if(copy == NULL) { + lv_obj_set_click(new_bar, false); + lv_obj_set_size(new_bar, LV_DPI * 2, LV_DPI / 3); + lv_bar_set_value(new_bar, ext->cur_value); + + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_bar_set_style(new_bar, LV_BAR_STYLE_BG, th->bar.bg); + lv_bar_set_style(new_bar, LV_BAR_STYLE_INDIC, th->bar.indic); + } else { + lv_obj_set_style(new_bar, &lv_style_pretty); + } + } else { + lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy); + ext->min_value = ext_copy->min_value; + ext->max_value = ext_copy->max_value; + ext->cur_value = ext_copy->cur_value; + ext->style_indic = ext_copy->style_indic; + ext->sym = ext_copy->sym; + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_bar); + + lv_bar_set_value(new_bar, ext->cur_value); + } + + LV_LOG_INFO("bar created"); + + return new_bar; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the bar + * @param bar pointer to a bar object + * @param value new value + */ +void lv_bar_set_value(lv_obj_t * bar, int16_t value) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + if(ext->cur_value == value) return; + + ext->cur_value = value > ext->max_value ? ext->max_value : value; + ext->cur_value = ext->cur_value < ext->min_value ? ext->min_value : ext->cur_value; + lv_obj_invalidate(bar); +} + +#if USE_LV_ANIMATION +/** + * Set a new value with animation on the bar + * @param bar pointer to a bar object + * @param value new value + * @param anim_time animation time in milliseconds + */ +void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + if(ext->cur_value == value) return; + + int16_t new_value; + new_value = value > ext->max_value ? ext->max_value : value; + new_value = new_value < ext->min_value ? ext->min_value : new_value; + + lv_anim_t a; + a.var = bar; + a.start = ext->cur_value; + a.end = new_value; + a.fp = (lv_anim_fp_t)lv_bar_set_value; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = anim_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + + lv_anim_create(&a); +} +#endif + + +/** + * Set minimum and the maximum values of a bar + * @param bar pointer to the bar object + * @param min minimum value + * @param max maximum value + */ +void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + if(ext->min_value == min && ext->max_value == max) return; + + ext->max_value = max; + ext->min_value = min; + if(ext->cur_value > max) { + ext->cur_value = max; + lv_bar_set_value(bar, ext->cur_value); + } + if(ext->cur_value < min) { + ext->cur_value = min; + lv_bar_set_value(bar, ext->cur_value); + } + lv_obj_invalidate(bar); +} + +/** + * Make the bar symmetric to zero. The indicator will grow from zero instead of the minimum position. + * @param bar pointer to a bar object + * @param en true: enable disable symmetric behavior; false: disable + */ +void lv_bar_set_sym(lv_obj_t * bar, bool en) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + ext->sym = en ? 1 : 0; +} + +/** + * Set a style of a bar + * @param bar pointer to a bar object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_bar_set_style(lv_obj_t * bar, lv_bar_style_t type, lv_style_t * style) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + + switch(type) { + case LV_BAR_STYLE_BG: + lv_obj_set_style(bar, style); + break; + case LV_BAR_STYLE_INDIC: + ext->style_indic = style; + lv_obj_refresh_ext_size(bar); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a bar + * @param bar pointer to a bar object + * @return the value of the bar + */ +int16_t lv_bar_get_value(const lv_obj_t * bar) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + return ext->cur_value; +} + +/** + * Get the minimum value of a bar + * @param bar pointer to a bar object + * @return the minimum value of the bar + */ +int16_t lv_bar_get_min_value(const lv_obj_t * bar) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + return ext->min_value; +} + +/** + * Get the maximum value of a bar + * @param bar pointer to a bar object + * @return the maximum value of the bar + */ +int16_t lv_bar_get_max_value(const lv_obj_t * bar) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + return ext->max_value; +} + +/** + * Get whether the bar is symmetric or not. + * @param bar pointer to a bar object + * @return true: symmetric is enabled; false: disable + */ +bool lv_bar_get_sym(lv_obj_t * bar) +{ + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + return ext->sym ? true : false; +} + +/** + * Get a style of a bar + * @param bar pointer to a bar object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_bar_get_style(const lv_obj_t * bar, lv_bar_style_t type) +{ + lv_style_t * style = NULL; + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + + switch(type) { + case LV_BAR_STYLE_BG: + style = lv_obj_get_style(bar); + break; + case LV_BAR_STYLE_INDIC: + style = ext->style_indic; + break; + default: + style = NULL; + break; + } + + return style; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the bars + * @param bar pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + /*Return false if the object is not covers the mask area*/ + return ancestor_design_f(bar, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_opa_t opa_scale = lv_obj_get_opa_scale(bar); + +#if USE_LV_GROUP == 0 + ancestor_design_f(bar, mask, mode); +#else + /* Draw the borders later if the bar is focused. + * At value = 100% the indicator can cover to whole background and the focused style won't be visible*/ + if(lv_obj_is_focused(bar)) { + lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG); + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style_bg); + style_tmp.body.border.width = 0; + lv_draw_rect(&bar->coords, mask, &style_tmp, opa_scale); + } else { + ancestor_design_f(bar, mask, mode); + } +#endif + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + + if(ext->cur_value != ext->min_value || ext->sym) { + lv_style_t * style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC); + lv_area_t indic_area; + lv_area_copy(&indic_area, &bar->coords); + indic_area.x1 += style_indic->body.padding.hor; + indic_area.x2 -= style_indic->body.padding.hor; + indic_area.y1 += style_indic->body.padding.ver; + indic_area.y2 -= style_indic->body.padding.ver; + + lv_coord_t w = lv_area_get_width(&indic_area); + lv_coord_t h = lv_area_get_height(&indic_area); + + if(w >= h) { + /*Horizontal*/ + indic_area.x2 = (int32_t)((int32_t)w * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value); + indic_area.x2 = indic_area.x1 + indic_area.x2 - 1; + + if(ext->sym && ext->min_value < 0 && ext->max_value > 0) { + /*Calculate the coordinate of the zero point*/ + lv_coord_t zero; + zero = indic_area.x1 + (-ext->min_value * w) / (ext->max_value - ext->min_value); + if(indic_area.x2 > zero) indic_area.x1 = zero; + else { + indic_area.x1 = indic_area.x2; + indic_area.x2 = zero; + } + } + } else { + indic_area.y1 = (int32_t)((int32_t)h * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value); + indic_area.y1 = indic_area.y2 - indic_area.y1 + 1; + + if(ext->sym && ext->min_value < 0 && ext->max_value > 0) { + /*Calculate the coordinate of the zero point*/ + lv_coord_t zero; + zero = indic_area.y2 - (-ext->min_value * h) / (ext->max_value - ext->min_value); + if(indic_area.y1 < zero) indic_area.y2 = zero; + else { + indic_area.y2 = indic_area.y1; + indic_area.y1 = zero; + } + } + } + + + /*Draw the indicator*/ + lv_draw_rect(&indic_area, mask, style_indic, opa_scale); + } + } else if(mode == LV_DESIGN_DRAW_POST) { +#if USE_LV_GROUP + /*Draw the border*/ + if(lv_obj_is_focused(bar)) { + lv_opa_t opa_scale = lv_obj_get_opa_scale(bar); + lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG); + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style_bg); + style_tmp.body.empty = 1; + style_tmp.body.shadow.width = 0; + lv_draw_rect(&bar->coords, mask, &style_tmp, opa_scale); + } +#endif + + } + return true; +} + +/** + * Signal function of the bar + * @param bar pointer to a bar object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(bar, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + lv_style_t * style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC); + if(style_indic->body.shadow.width > bar->ext_size) bar->ext_size = style_indic->body.shadow.width; + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_bar"; + } + + return res; +} + + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.h new file mode 100644 index 0000000..2190384 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_bar.h @@ -0,0 +1,160 @@ +/** + * @file lv_bar.h + * + */ + +#ifndef LV_BAR_H +#define LV_BAR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_BAR != 0 + +#include "../lv_core/lv_obj.h" +#include "lv_cont.h" +#include "lv_btn.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of bar*/ +typedef struct +{ + /*No inherited ext*/ /*Ext. of ancestor*/ + /*New data for this type */ + int16_t cur_value; /*Current value of the bar*/ + int16_t min_value; /*Minimum value of the bar*/ + int16_t max_value; /*Maximum value of the bar*/ + uint8_t sym :1; /*Symmetric: means the center is around zero value*/ + lv_style_t *style_indic; /*Style of the indicator*/ +} lv_bar_ext_t; + +enum { + LV_BAR_STYLE_BG, + LV_BAR_STYLE_INDIC, +}; +typedef uint8_t lv_bar_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a bar objects + * @param par pointer to an object, it will be the parent of the new bar + * @param copy pointer to a bar object, if not NULL then the new object will be copied from it + * @return pointer to the created bar + */ +lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the bar + * @param bar pointer to a bar object + * @param value new value + */ +void lv_bar_set_value(lv_obj_t * bar, int16_t value); + +/** + * Set a new value with animation on the bar + * @param bar pointer to a bar object + * @param value new value + * @param anim_time animation time in milliseconds + */ +void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time); + + +/** + * Set minimum and the maximum values of a bar + * @param bar pointer to the bar object + * @param min minimum value + * @param max maximum value + */ +void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max); + +/** + * Make the bar symmetric to zero. The indicator will grow from zero instead of the minimum position. + * @param bar pointer to a bar object + * @param en true: enable disable symmetric behavior; false: disable + */ +void lv_bar_set_sym(lv_obj_t * bar, bool en); + +/** + * Set a style of a bar + * @param bar pointer to a bar object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_bar_set_style(lv_obj_t *bar, lv_bar_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a bar + * @param bar pointer to a bar object + * @return the value of the bar + */ +int16_t lv_bar_get_value(const lv_obj_t * bar); + +/** + * Get the minimum value of a bar + * @param bar pointer to a bar object + * @return the minimum value of the bar + */ +int16_t lv_bar_get_min_value(const lv_obj_t * bar); + +/** + * Get the maximum value of a bar + * @param bar pointer to a bar object + * @return the maximum value of the bar + */ +int16_t lv_bar_get_max_value(const lv_obj_t * bar); + +/** + * Get whether the bar is symmetric or not. + * @param bar pointer to a bar object + * @return true: symmetric is enabled; false: disable + */ +bool lv_bar_get_sym(lv_obj_t * bar); + +/** + * Get a style of a bar + * @param bar pointer to a bar object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_bar_get_style(const lv_obj_t *bar, lv_bar_style_t type); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_BAR*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_BAR_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.c new file mode 100644 index 0000000..f46250c --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.c @@ -0,0 +1,763 @@ +/** + * @file lv_btn.c + * + */ + +/********************* + * INCLUDES + *********************/ + +#include "lv_btn.h" +#if USE_LV_BTN != 0 + +#include +#include "../lv_core/lv_group.h" +#include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_area.h" +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define LV_BTN_INK_VALUE_MAX 256 +#define LV_BTN_INK_VALUE_MAX_SHIFT 8 + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_btn_design(lv_obj_t * btn, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param); + +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT +static void lv_btn_ink_effect_anim(lv_obj_t * btn, int32_t val); +static void lv_btn_ink_effect_anim_ready(void * p); +#endif + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; + +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT +static lv_coord_t ink_act_value; +static lv_obj_t * ink_obj; +static lv_btn_state_t ink_bg_state; +static lv_btn_state_t ink_top_state; +static bool ink_ready; +static bool ink_playback; +static lv_point_t ink_point; +#endif + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a button objects + * @param par pointer to an object, it will be the parent of the new button + * @param copy pointer to a button object, if not NULL then the new object will be copied from it + * @return pointer to the created button + */ +lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("button create started"); + + lv_obj_t * new_btn; + + new_btn = lv_cont_create(par, copy); + lv_mem_assert(new_btn); + if(new_btn == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_btn); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_btn); + + /*Allocate the extended data*/ + lv_btn_ext_t * ext = lv_obj_allocate_ext_attr(new_btn, sizeof(lv_btn_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->state = LV_BTN_STATE_REL; + + ext->actions[LV_BTN_ACTION_PR] = NULL; + ext->actions[LV_BTN_ACTION_CLICK] = NULL; + ext->actions[LV_BTN_ACTION_LONG_PR] = NULL; + ext->actions[LV_BTN_ACTION_LONG_PR_REPEAT] = NULL; + + ext->styles[LV_BTN_STATE_REL] = &lv_style_btn_rel; + ext->styles[LV_BTN_STATE_PR] = &lv_style_btn_pr; + ext->styles[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_rel; + ext->styles[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr; + ext->styles[LV_BTN_STATE_INA] = &lv_style_btn_ina; + + ext->long_pr_action_executed = 0; + ext->toggle = 0; + ext->idx = 0; +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + ext->ink_in_time = 0; + ext->ink_wait_time = 0; + ext->ink_out_time = 0; +#endif + + lv_obj_set_signal_func(new_btn, lv_btn_signal); + lv_obj_set_design_func(new_btn, lv_btn_design); + + /*If no copy do the basic initialization*/ + if(copy == NULL) { + /*Set layout if the button is not a screen*/ + if(par != NULL) { + lv_btn_set_layout(new_btn, LV_LAYOUT_CENTER); + } + + lv_obj_set_click(new_btn, true); /*Be sure the button is clickable*/ + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_btn_set_style(new_btn, LV_BTN_STYLE_REL, th->btn.rel); + lv_btn_set_style(new_btn, LV_BTN_STYLE_PR, th->btn.pr); + lv_btn_set_style(new_btn, LV_BTN_STYLE_TGL_REL, th->btn.tgl_rel); + lv_btn_set_style(new_btn, LV_BTN_STYLE_TGL_PR, th->btn.tgl_pr); + lv_btn_set_style(new_btn, LV_BTN_STYLE_INA, th->btn.ina); + } else { + lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_REL]); + } + } + /*Copy 'copy'*/ + else { + lv_btn_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->state = copy_ext->state; + ext->toggle = copy_ext->toggle; +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + ext->ink_in_time = copy_ext->ink_in_time; + ext->ink_wait_time = copy_ext->ink_wait_time; + ext->ink_out_time = copy_ext->ink_out_time; +#endif + memcpy(ext->actions, copy_ext->actions, sizeof(ext->actions)); + memcpy(ext->styles, copy_ext->styles, sizeof(ext->styles)); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_btn); + } + + LV_LOG_INFO("button created"); + + return new_btn; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Enable the toggled states + * @param btn pointer to a button object + * @param tgl true: enable toggled states, false: disable + */ +void lv_btn_set_toggle(lv_obj_t * btn, bool tgl) +{ + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + + ext->toggle = tgl != false ? 1 : 0; +} + +/** + * Set the state of the button + * @param btn pointer to a button object + * @param state the new state of the button (from lv_btn_state_t enum) + */ +void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state) +{ + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + if(ext->state != state) { + ext->state = state; + lv_obj_set_style(btn, ext->styles[state]); + } +} + +/** + * Toggle the state of the button (ON->OFF, OFF->ON) + * @param btn pointer to a button object + */ +void lv_btn_toggle(lv_obj_t * btn) +{ + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + switch(ext->state) { + case LV_BTN_STATE_REL: + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + break; + case LV_BTN_STATE_PR: + lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR); + break; + case LV_BTN_STATE_TGL_REL: + lv_btn_set_state(btn, LV_BTN_STATE_REL); + break; + case LV_BTN_STATE_TGL_PR: + lv_btn_set_state(btn, LV_BTN_STATE_PR); + break; + default: + break; + } +} + +/** + * Set a function to call when a button event happens + * @param btn pointer to a button object + * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) + */ +void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action) +{ + if(type >= LV_BTN_ACTION_NUM) return; + + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + ext->actions[type] = action; +} + +/** + * Set time of the ink effect (draw a circle on click to animate in the new state) + * @param btn pointer to a button object + * @param time the time of the ink animation + */ +void lv_btn_set_ink_in_time(lv_obj_t * btn, uint16_t time) +{ +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + ext->ink_in_time = time; +#else + (void)btn; /*Unused*/ + (void)time; /*Unused*/ + LV_LOG_WARN("`lv_btn_set_ink_ink_time` has no effect if LV_BTN_INK_EFEFCT or USE_LV_ANIMATION is disabled") +#endif +} + +/** + * Set the wait time before the ink disappears + * @param btn pointer to a button object + * @param time the time of the ink animation + */ +void lv_btn_set_ink_wait_time(lv_obj_t * btn, uint16_t time) +{ + +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + ext->ink_wait_time = time; +#else + (void)btn; /*Unused*/ + (void)time; /*Unused*/ + LV_LOG_WARN("`lv_btn_set_ink_wait_time` has no effect if LV_BTN_INK_EFEFCT or USE_LV_ANIMATION is disabled") +#endif +} + +/** + * Set time of the ink out effect (animate to the released state) + * @param btn pointer to a button object + * @param time the time of the ink animation + */ +void lv_btn_set_ink_out_time(lv_obj_t * btn, uint16_t time) +{ +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + ext->ink_out_time = time; +#else + (void)btn; /*Unused*/ + (void)time; /*Unused*/ + LV_LOG_WARN("`lv_btn_set_ink_out_time` has no effect if LV_BTN_INK_EFEFCT or USE_LV_ANIMATION is disabled") +#endif +} + +/** + * Set a style of a button + * @param btn pointer to a button object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_btn_set_style(lv_obj_t * btn, lv_btn_style_t type, lv_style_t * style) +{ + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + + switch(type) { + case LV_BTN_STYLE_REL: + ext->styles[LV_BTN_STATE_REL] = style; + break; + case LV_BTN_STYLE_PR: + ext->styles[LV_BTN_STATE_PR] = style; + break; + case LV_BTN_STYLE_TGL_REL: + ext->styles[LV_BTN_STATE_TGL_REL] = style; + break; + case LV_BTN_STYLE_TGL_PR: + ext->styles[LV_BTN_STATE_TGL_PR] = style; + break; + case LV_BTN_STYLE_INA: + ext->styles[LV_BTN_STATE_INA] = style; + break; + } + + /*Refresh the object with the new style*/ + lv_obj_set_style(btn, ext->styles[ext->state]); +} + + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current state of the button + * @param btn pointer to a button object + * @return the state of the button (from lv_btn_state_t enum) + */ +lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn) +{ + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + return ext->state; +} + +/** + * Get the toggle enable attribute of the button + * @param btn pointer to a button object + * @return ture: toggle enabled, false: disabled + */ +bool lv_btn_get_toggle(const lv_obj_t * btn) +{ + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + + return ext->toggle != 0 ? true : false; +} + +/** + * Get the release action of a button + * @param btn pointer to a button object + * @return pointer to the release action function + */ +lv_action_t lv_btn_get_action(const lv_obj_t * btn, lv_btn_action_t type) +{ + if(type >= LV_BTN_ACTION_NUM) return NULL; + + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + return ext->actions[type]; +} + +/** + * Get time of the ink in effect (draw a circle on click to animate in the new state) + * @param btn pointer to a button object + * @return the time of the ink animation + */ +uint16_t lv_btn_get_ink_in_time(const lv_obj_t * btn) +{ +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + return ext->ink_in_time; +#else + (void)btn; /*Unused*/ + return 0; +#endif +} + + +/** + * Get the wait time before the ink disappears + * @param btn pointer to a button object + * @return the time of the ink animation + */ +uint16_t lv_btn_get_ink_wait_time(const lv_obj_t * btn) +{ +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + return ext->ink_wait_time; +#else + (void)btn; /*Unused*/ + return 0; +#endif +} +/** + * Get time of the ink out effect (animate to the releases state) + * @param btn pointer to a button object + * @return the time of the ink animation + */ +uint16_t lv_btn_get_ink_out_time(const lv_obj_t * btn) +{ +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + return ext->ink_in_time; +#else + (void)btn; /*Unused*/ + return 0; +#endif +} + +/** + * Get a style of a button + * @param btn pointer to a button object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_btn_get_style(const lv_obj_t * btn, lv_btn_style_t type) +{ + lv_style_t * style = NULL; + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + + switch(type) { + case LV_BTN_STYLE_REL: + style = ext->styles[LV_BTN_STATE_REL]; + break; + case LV_BTN_STYLE_PR: + style = ext->styles[LV_BTN_STATE_PR]; + break; + case LV_BTN_STYLE_TGL_REL: + style = ext->styles[LV_BTN_STATE_TGL_REL]; + break; + case LV_BTN_STYLE_TGL_PR: + style = ext->styles[LV_BTN_STATE_TGL_PR]; + break; + case LV_BTN_STYLE_INA: + style = ext->styles[LV_BTN_STATE_INA]; + break; + default: + style = NULL; + break; + } + + return style; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + + +/** + * Handle the drawing related tasks of the drop down lists + * @param btn pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_btn_design(lv_obj_t * btn, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } else if(mode == LV_DESIGN_DRAW_MAIN) { + +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + if(btn != ink_obj) { + ancestor_design(btn, mask, mode); + } else { + lv_opa_t opa_scale = lv_obj_get_opa_scale(btn); + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + + /*Draw the normal button*/ + if(ink_playback == false) { + lv_style_t style_tmp; + lv_style_copy(&style_tmp, ext->styles[ink_bg_state]); + style_tmp.body.shadow.width = ext->styles[ink_top_state]->body.shadow.width; + lv_draw_rect(&btn->coords, mask, &style_tmp, opa_scale); + + lv_coord_t w = lv_obj_get_width(btn); + lv_coord_t h = lv_obj_get_height(btn); + lv_coord_t r_max = LV_MATH_MIN(w, h) / 2; + + /*In the first part of the animation increase the size of the circle (ink effect) */ + lv_area_t cir_area; + + lv_coord_t coord_state = ink_act_value < LV_BTN_INK_VALUE_MAX / 2 ? ink_act_value : LV_BTN_INK_VALUE_MAX / 2; + lv_point_t p_act; + p_act.x = ink_point.x; + p_act.y = ink_point.y; + lv_coord_t x_err = (btn->coords.x1 + w / 2) - p_act.x; + lv_coord_t y_err = (btn->coords.y1 + h / 2) - p_act.y; + + p_act.x += (x_err * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1); + p_act.y += (y_err * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1); + + lv_coord_t half_side = LV_MATH_MAX(w, h) / 2; + cir_area.x1 = p_act.x - ((half_side * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1)); + cir_area.y1 = p_act.y - ((half_side * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1)); + cir_area.x2 = p_act.x + ((half_side * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1)); + cir_area.y2 = p_act.y + ((half_side * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1)); + + lv_area_intersect(&cir_area, &btn->coords, &cir_area); /*Limit the area. (It might be too big on the smaller side)*/ + + /*In the second part animate the radius. Circle -> body.radius*/ + lv_coord_t r_state = ink_act_value > LV_BTN_INK_VALUE_MAX / 2 ? ink_act_value - LV_BTN_INK_VALUE_MAX / 2 : 0; + + lv_style_copy(&style_tmp, ext->styles[ink_top_state]); + style_tmp.body.radius = r_max + (((ext->styles[ink_bg_state]->body.radius - r_max) * r_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1)); + style_tmp.body.border.width = 0; + + /*Draw the circle*/ + lv_draw_rect(&cir_area, mask, &style_tmp, opa_scale); + } else { + lv_style_t res; + lv_style_copy(&res, ext->styles[ink_bg_state]); + lv_style_mix(ext->styles[ink_bg_state], ext->styles[ink_top_state], &res, ink_act_value); + lv_draw_rect(&btn->coords, mask, &res, opa_scale); + + } + } +#else + ancestor_design(btn, mask, mode); +#endif + } else if(mode == LV_DESIGN_DRAW_POST) { + ancestor_design(btn, mask, mode); + } + + return true; +} + +/** + * Signal function of the button + * @param btn pointer to a button object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(btn, sign, param); + if(res != LV_RES_OK) return res; + + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + lv_btn_state_t state = lv_btn_get_state(btn); + bool tgl = lv_btn_get_toggle(btn); + + if(sign == LV_SIGNAL_PRESSED) { + /*Refresh the state*/ + if(ext->state == LV_BTN_STATE_REL) { + lv_btn_set_state(btn, LV_BTN_STATE_PR); +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + ink_bg_state = LV_BTN_STATE_REL; + ink_top_state = LV_BTN_STATE_PR; +#endif + } else if(ext->state == LV_BTN_STATE_TGL_REL) { + lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR); +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + ink_bg_state = LV_BTN_STATE_TGL_REL; + ink_top_state = LV_BTN_STATE_TGL_PR; +#endif + } + + ext->long_pr_action_executed = 0; + +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + /*Forget the old inked button*/ + if(ink_obj != NULL && ink_obj != btn) { + lv_anim_del(ink_obj, (lv_anim_fp_t)lv_btn_ink_effect_anim); + lv_obj_invalidate(ink_obj); + ink_obj = NULL; + } + /*Save the new data for inking and start it's animation if enabled*/ + if(ext->ink_in_time > 0) { + ink_obj = btn; + ink_playback = false; + ink_ready = false; + lv_indev_get_point(lv_indev_get_act(), &ink_point); + + lv_anim_t a; + a.var = btn; + a.start = 0; + a.end = LV_BTN_INK_VALUE_MAX; + a.fp = (lv_anim_fp_t)lv_btn_ink_effect_anim; + a.path = lv_anim_path_linear; + a.end_cb = lv_btn_ink_effect_anim_ready; + a.act_time = 0; + a.time = ext->ink_in_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); + } +#endif + /*Call the press action, 'param' is the caller indev_proc*/ + if(ext->actions[LV_BTN_ACTION_PR] && state != LV_BTN_STATE_INA) { + res = ext->actions[LV_BTN_ACTION_PR](btn); + } + } else if(sign == LV_SIGNAL_PRESS_LOST) { + /*Refresh the state*/ + if(ext->state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); + else if(ext->state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } else if(sign == LV_SIGNAL_PRESSING) { + /*When the button begins to drag revert pressed states to released*/ + if(lv_indev_is_dragging(param) != false) { + if(ext->state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); + else if(ext->state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } + } else if(sign == LV_SIGNAL_RELEASED) { + /*If not dragged and it was not long press action then + *change state and run the action*/ + if(lv_indev_is_dragging(param) == false && ext->long_pr_action_executed == 0) { + if(ext->state == LV_BTN_STATE_PR && tgl == false) { + lv_btn_set_state(btn, LV_BTN_STATE_REL); + } else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == false) { + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } else if(ext->state == LV_BTN_STATE_PR && tgl == true) { + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == true) { + lv_btn_set_state(btn, LV_BTN_STATE_REL); + } + + if(ext->actions[LV_BTN_ACTION_CLICK] && state != LV_BTN_STATE_INA) { + res = ext->actions[LV_BTN_ACTION_CLICK](btn); + } + } else { /*If dragged change back the state*/ + if(ext->state == LV_BTN_STATE_PR) { + lv_btn_set_state(btn, LV_BTN_STATE_REL); + } else if(ext->state == LV_BTN_STATE_TGL_PR) { + lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } + } + +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + /*Draw the toggled state in the inking instead*/ + if(ext->toggle) { + ink_top_state = ext->state; + } + /*If not a toggle button and the "IN" inking is ready then start an "OUT" inking*/ + else if(ink_ready && ext->ink_out_time > 0) { + ink_obj = btn; + ink_playback = true; /*It is the playback. If not set `lv_btn_ink_effect_anim_ready` will start its own playback*/ + lv_indev_get_point(lv_indev_get_act(), &ink_point); + + lv_anim_t a; + a.var = ink_obj; + a.start = LV_BTN_INK_VALUE_MAX; + a.end = 0; + a.fp = (lv_anim_fp_t)lv_btn_ink_effect_anim; + a.path = lv_anim_path_linear; + a.end_cb = lv_btn_ink_effect_anim_ready; + a.act_time = 0; + a.time = ext->ink_out_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); + } +#endif + } else if(sign == LV_SIGNAL_LONG_PRESS) { + if(ext->actions[LV_BTN_ACTION_LONG_PR] && state != LV_BTN_STATE_INA) { + ext->long_pr_action_executed = 1; + res = ext->actions[LV_BTN_ACTION_LONG_PR](btn); + } + } else if(sign == LV_SIGNAL_LONG_PRESS_REP) { + if(ext->actions[LV_BTN_ACTION_LONG_PR_REPEAT] && state != LV_BTN_STATE_INA) { + res = ext->actions[LV_BTN_ACTION_LONG_PR_REPEAT](btn); + } + } else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char *)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { + if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + if(ext->actions[LV_BTN_ACTION_CLICK] && lv_btn_get_state(btn) != LV_BTN_STATE_INA) { + res = ext->actions[LV_BTN_ACTION_CLICK](btn); + } + } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { + if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_REL); + if(ext->actions[LV_BTN_ACTION_CLICK] && lv_btn_get_state(btn) != LV_BTN_STATE_INA) { + res = ext->actions[LV_BTN_ACTION_CLICK](btn); + } + } else if(c == LV_GROUP_KEY_ENTER) { + if(!ext->long_pr_action_executed) { + if(lv_btn_get_toggle(btn)) { + if(state == LV_BTN_STATE_REL || state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + else if(state == LV_BTN_STATE_TGL_REL || state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); + } else { + if(state == LV_BTN_STATE_REL || state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); + else if(state == LV_BTN_STATE_TGL_REL || state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } + if(ext->actions[LV_BTN_ACTION_CLICK] && state != LV_BTN_STATE_INA) { + res = ext->actions[LV_BTN_ACTION_CLICK](btn); + } + } + if(res != LV_RES_INV) { + ext->long_pr_action_executed = 0; + } + } + } else if(sign == LV_SIGNAL_CLEANUP) { +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + if(btn == ink_obj) { + lv_anim_del(ink_obj, (lv_anim_fp_t)lv_btn_ink_effect_anim); + ink_obj = NULL; + } +#endif + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_btn"; + } + + return res; +} + +#if USE_LV_ANIMATION && LV_BTN_INK_EFFECT + +/** + * The animator function of inking. CAlled to increase the radius of ink + * @param btn pointer to the animated button + * @param val the new radius + */ +static void lv_btn_ink_effect_anim(lv_obj_t * btn, int32_t val) +{ + if(btn) { + ink_act_value = val; + lv_obj_invalidate(btn); + } +} + +/** + * Called to clean up when the ink animation is ready + * @param p unused + */ +static void lv_btn_ink_effect_anim_ready(void * p) +{ + (void) p; /*Unused*/ + + lv_btn_ext_t * ext = lv_obj_get_ext_attr(ink_obj); + lv_btn_state_t state = lv_btn_get_state(ink_obj); + + lv_obj_invalidate(ink_obj); + ink_ready = true; + + if((state == LV_BTN_STATE_REL || state == LV_BTN_STATE_TGL_REL) && ext->toggle == 0 && ink_playback == false) { + lv_anim_t a; + a.var = ink_obj; + a.start = LV_BTN_INK_VALUE_MAX; + a.end = 0; + a.fp = (lv_anim_fp_t)lv_btn_ink_effect_anim; + a.path = lv_anim_path_linear; + a.end_cb = lv_btn_ink_effect_anim_ready; + a.act_time = -ext->ink_wait_time; + a.time = ext->ink_out_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); + + ink_playback = true; + } else { + ink_obj = NULL; + } +} +#endif /*USE_LV_ANIMATION*/ + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.h new file mode 100644 index 0000000..3a48b62 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btn.h @@ -0,0 +1,280 @@ +/** + * @file lv_btn.h + * + */ + +#ifndef LV_BTN_H +#define LV_BTN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_BTN != 0 + +/*Testing of dependencies*/ +#if USE_LV_CONT == 0 +#error "lv_btn: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " +#endif + +#include "lv_cont.h" +#include "../lv_core/lv_indev.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/* Button states + * It can be used not only by buttons but other button-like objects too*/ +enum +{ + LV_BTN_STATE_REL, + LV_BTN_STATE_PR, + LV_BTN_STATE_TGL_REL, + LV_BTN_STATE_TGL_PR, + LV_BTN_STATE_INA, + LV_BTN_STATE_NUM, +}; +typedef uint8_t lv_btn_state_t; + +enum +{ + LV_BTN_ACTION_CLICK, + LV_BTN_ACTION_PR, + LV_BTN_ACTION_LONG_PR, + LV_BTN_ACTION_LONG_PR_REPEAT, + LV_BTN_ACTION_NUM, +}; +typedef uint8_t lv_btn_action_t; + + +/*Data of button*/ +typedef struct +{ + lv_cont_ext_t cont; /*Ext. of ancestor*/ + /*New data for this type */ + lv_action_t actions[LV_BTN_ACTION_NUM]; + lv_style_t * styles[LV_BTN_STATE_NUM]; /*Styles in each state*/ + lv_btn_state_t state; /*Current state of the button from 'lv_btn_state_t' enum*/ + int idx; +#if LV_BTN_INK_EFFECT + uint16_t ink_in_time; /*[ms] Time of ink fill effect (0: disable ink effect)*/ + uint16_t ink_wait_time; /*[ms] Wait before the ink disappears */ + uint16_t ink_out_time; /*[ms] Time of ink disappearing*/ +#endif + uint8_t toggle :1; /*1: Toggle enabled*/ + uint8_t long_pr_action_executed :1; /*1: Long press action executed (Handled by the library)*/ +} lv_btn_ext_t; + +/*Styles*/ +enum { + LV_BTN_STYLE_REL, + LV_BTN_STYLE_PR, + LV_BTN_STYLE_TGL_REL, + LV_BTN_STYLE_TGL_PR, + LV_BTN_STYLE_INA, +}; +typedef uint8_t lv_btn_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a button objects + * @param par pointer to an object, it will be the parent of the new button + * @param copy pointer to a button object, if not NULL then the new object will be copied from it + * @return pointer to the created button + */ +lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Enable the toggled states. On release the button will change from/to toggled state. + * @param btn pointer to a button object + * @param tgl true: enable toggled states, false: disable + */ +void lv_btn_set_toggle(lv_obj_t * btn, bool tgl); + +/** + * Set the state of the button + * @param btn pointer to a button object + * @param state the new state of the button (from lv_btn_state_t enum) + */ +void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); + +/** + * Toggle the state of the button (ON->OFF, OFF->ON) + * @param btn pointer to a button object + */ +void lv_btn_toggle(lv_obj_t * btn); + +/** + * Set a function to call when a button event happens + * @param btn pointer to a button object + * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) + */ +void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action); + +/** + * Set the layout on a button + * @param btn pointer to a button object + * @param layout a layout from 'lv_cont_layout_t' + */ +static inline void lv_btn_set_layout(lv_obj_t * btn, lv_layout_t layout) +{ + lv_cont_set_layout(btn, layout); +} + +/** + * Enable the horizontal or vertical fit. + * The button size will be set to involve the children horizontally or vertically. + * @param btn pointer to a button object + * @param hor_en true: enable the horizontal fit + * @param ver_en true: enable the vertical fit + */ +static inline void lv_btn_set_fit(lv_obj_t * btn, bool hor_en, bool ver_en) +{ + lv_cont_set_fit(btn, hor_en, ver_en); +} + +/** + * Set time of the ink effect (draw a circle on click to animate in the new state) + * @param btn pointer to a button object + * @param time the time of the ink animation + */ +void lv_btn_set_ink_in_time(lv_obj_t * btn, uint16_t time); + +/** + * Set the wait time before the ink disappears + * @param btn pointer to a button object + * @param time the time of the ink animation + */ +void lv_btn_set_ink_wait_time(lv_obj_t * btn, uint16_t time); + +/** + * Set time of the ink out effect (animate to the released state) + * @param btn pointer to a button object + * @param time the time of the ink animation + */ +void lv_btn_set_ink_out_time(lv_obj_t * btn, uint16_t time); + +/** + * Set a style of a button. + * @param btn pointer to button object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_btn_set_style(lv_obj_t * btn, lv_btn_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current state of the button + * @param btn pointer to a button object + * @return the state of the button (from lv_btn_state_t enum) + */ +lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn); + +/** + * Get the toggle enable attribute of the button + * @param btn pointer to a button object + * @return ture: toggle enabled, false: disabled + */ +bool lv_btn_get_toggle(const lv_obj_t * btn); + +/** + * Get the release action of a button + * @param btn pointer to a button object + * @return pointer to the release action function + */ +lv_action_t lv_btn_get_action(const lv_obj_t * btn, lv_btn_action_t type); + +/** + * Get the layout of a button + * @param btn pointer to button object + * @return the layout from 'lv_cont_layout_t' + */ +static inline lv_layout_t lv_btn_get_layout(const lv_obj_t * btn) +{ + return lv_cont_get_layout(btn); +} + +/** + * Get horizontal fit enable attribute of a button + * @param btn pointer to a button object + * @return true: horizontal fit is enabled; false: disabled + */ +static inline bool lv_btn_get_hor_fit(const lv_obj_t * btn) +{ + return lv_cont_get_hor_fit(btn); +} + +/** + * Get vertical fit enable attribute of a container + * @param btn pointer to a button object + * @return true: vertical fit is enabled; false: disabled + */ +static inline bool lv_btn_get_ver_fit(const lv_obj_t * btn) +{ + return lv_cont_get_ver_fit(btn); +} + +/** + * Get time of the ink in effect (draw a circle on click to animate in the new state) + * @param btn pointer to a button object + * @return the time of the ink animation + */ +uint16_t lv_btn_get_ink_in_time(const lv_obj_t * btn); + +/** + * Get the wait time before the ink disappears + * @param btn pointer to a button object + * @return the time of the ink animation + */ +uint16_t lv_btn_get_ink_wait_time(const lv_obj_t * btn); + +/** + * Get time of the ink out effect (animate to the releases state) + * @param btn pointer to a button object + * @return the time of the ink animation + */ +uint16_t lv_btn_get_ink_out_time(const lv_obj_t * btn); + +/** + * Get style of a button. + * @param btn pointer to button object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_btn_get_style(const lv_obj_t * btn, lv_btn_style_t type); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_BUTTON*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_BTN_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.c new file mode 100644 index 0000000..68d04e1 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.c @@ -0,0 +1,881 @@ +/** + * @file lv_btnm.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_btnm.h" +#if USE_LV_BTNM != 0 + +#include "../lv_core/lv_group.h" +#include "../lv_draw/lv_draw.h" +#include "../lv_core/lv_refr.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_txt.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param); +static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mode_t mode); +static uint8_t get_button_width(const char * btn_str); +static bool button_is_hidden(const char * btn_str); +static bool button_is_repeat_disabled(const char * btn_str); +static bool button_is_inactive(const char * btn_str); +const char * cut_ctrl_byte(const char * btn_str); +static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p); +static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id); +static void allocate_btn_areas(lv_obj_t * btnm, const char ** map); + +/********************** + * STATIC VARIABLES + **********************/ +static const char * lv_btnm_def_map[] = {"Btn1", "Btn2", "Btn3", "\n", + "\002Btn4", "Btn5", "" + }; + +static lv_design_func_t ancestor_design_f; +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a button matrix objects + * @param par pointer to an object, it will be the parent of the new button matrix + * @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it + * @return pointer to the created button matrix + */ +lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("button matrix create started"); + + /*Create the ancestor object*/ + lv_obj_t * new_btnm = lv_obj_create(par, copy); + lv_mem_assert(new_btnm); + if(new_btnm == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_btnm); + + /*Allocate the object type specific extended data*/ + lv_btnm_ext_t * ext = lv_obj_allocate_ext_attr(new_btnm, sizeof(lv_btnm_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->btn_cnt = 0; + ext->btn_id_pr = LV_BTNM_PR_NONE; + ext->btn_id_tgl = LV_BTNM_PR_NONE; + ext->button_areas = NULL; + ext->action = NULL; + ext->map_p = NULL; + ext->toggle = 0; + ext->recolor = 0; + ext->styles_btn[LV_BTN_STATE_REL] = &lv_style_btn_rel; + ext->styles_btn[LV_BTN_STATE_PR] = &lv_style_btn_pr; + ext->styles_btn[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_rel; + ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr; + ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina; + + if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_btnm); + + lv_obj_set_signal_func(new_btnm, lv_btnm_signal); + lv_obj_set_design_func(new_btnm, lv_btnm_design); + + /*Init the new button matrix object*/ + if(copy == NULL) { + lv_obj_set_size(new_btnm, LV_HOR_RES / 2, LV_VER_RES / 4); + lv_btnm_set_map(new_btnm, lv_btnm_def_map); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BG, th->btnm.bg); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_REL, th->btnm.btn.rel); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_PR, th->btnm.btn.pr); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_REL, th->btnm.btn.tgl_rel); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_PR, th->btnm.btn.tgl_pr); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_INA, th->btnm.btn.ina); + } else { + lv_obj_set_style(new_btnm, &lv_style_pretty); + } + } + /*Copy an existing object*/ + else { + lv_btnm_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + memcpy(ext->styles_btn, copy_ext->styles_btn, sizeof(ext->styles_btn)); + ext->action = copy_ext->action; + ext->toggle = copy_ext->toggle; + ext->btn_id_tgl = copy_ext->btn_id_tgl; + lv_btnm_set_map(new_btnm, lv_btnm_get_map(copy)); + } + + LV_LOG_INFO("button matrix created"); + + return new_btnm; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new map. Buttons will be created/deleted according to the map. + * @param btnm pointer to a button matrix object + * @param map pointer a string array. The last string has to be: "". + * Use "\n" to begin a new line. + * The first byte can be a control data: + * - bit 7: always 1 + * - bit 6: always 0 + * - bit 5: inactive (disabled) (\24x) + * - bit 4: no repeat (on long press) (\22x) + * - bit 3: hidden (\21x) + * - bit 2..0: button relative width + * Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press + */ +void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) +{ + if(map == NULL) return; + + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + ext->map_p = map; + + /*Analyze the map and create the required number of buttons*/ + allocate_btn_areas(btnm, map); + + /*Set size and positions of the buttons*/ + lv_style_t * style_bg = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG); + lv_coord_t max_w = lv_obj_get_width(btnm) - 2 * style_bg->body.padding.hor; + lv_coord_t max_h = lv_obj_get_height(btnm) - 2 * style_bg->body.padding.ver; + lv_coord_t act_y = style_bg->body.padding.ver; + + /*Count the lines to calculate button height*/ + uint8_t line_cnt = 1; + uint8_t li; + for(li = 0; strlen(map[li]) != 0; li++) { + if(strcmp(map[li], "\n") == 0) line_cnt ++; + } + + lv_coord_t btn_h = max_h - ((line_cnt - 1) * style_bg->body.padding.inner); + btn_h = btn_h / line_cnt; + btn_h --; /*-1 because e.g. height = 100 means 101 pixels (0..100)*/ + + /* Count the units and the buttons in a line + * (A button can be 1,2,3... unit wide)*/ + uint16_t unit_cnt; /*Number of units in a row*/ + uint16_t unit_act_cnt; /*Number of units currently put in a row*/ + uint16_t btn_cnt; /*Number of buttons in a row*/ + uint16_t i_tot = 0; /*Act. index in the str map*/ + uint16_t btn_i = 0; /*Act. index of button areas*/ + const char ** map_p_tmp = map; + + /*Count the units and the buttons in a line*/ + while(1) { + unit_cnt = 0; + btn_cnt = 0; + /*Count the buttons in a line*/ + while(strcmp(map_p_tmp[btn_cnt], "\n") != 0 && + strlen(map_p_tmp[btn_cnt]) != 0) { /*Check a line*/ + unit_cnt += get_button_width(map_p_tmp[btn_cnt]); + btn_cnt ++; + } + + /*Make sure the last row is at the bottom of 'btnm'*/ + if(map_p_tmp[btn_cnt][0] == '\0') { /*Last row?*/ + btn_h = max_h - act_y + style_bg->body.padding.ver - 1; + } + + /*Only deal with the non empty lines*/ + if(btn_cnt != 0) { + /*Calculate the width of all units*/ + lv_coord_t all_unit_w = max_w - ((btn_cnt - 1) * style_bg->body.padding.inner); + + /*Set the button size and positions and set the texts*/ + uint16_t i; + lv_coord_t act_x = style_bg->body.padding.hor; + lv_coord_t act_unit_w; + unit_act_cnt = 0; + for(i = 0; i < btn_cnt; i++) { + /* one_unit_w = all_unit_w / unit_cnt + * act_unit_w = one_unit_w * button_width + * do this two operations but the multiply first to divide a greater number */ + act_unit_w = (all_unit_w * get_button_width(map_p_tmp[i])) / unit_cnt; + act_unit_w --; /*-1 because e.g. width = 100 means 101 pixels (0..100)*/ + + /*Always recalculate act_x because of rounding errors */ + act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * style_bg->body.padding.inner + style_bg->body.padding.hor; + + /* Set the button's area. + * If inner padding is zero then use the prev. button x2 as x1 to avoid rounding errors*/ + if(style_bg->body.padding.inner == 0 && act_x != style_bg->body.padding.hor) { + lv_area_set(&ext->button_areas[btn_i], ext->button_areas[btn_i - 1].x2, act_y, + act_x + act_unit_w, act_y + btn_h); + } else { + lv_area_set(&ext->button_areas[btn_i], act_x, act_y, + act_x + act_unit_w, act_y + btn_h); + } + + unit_act_cnt += get_button_width(map_p_tmp[i]); + + i_tot ++; + btn_i ++; + } + } + act_y += btn_h + style_bg->body.padding.inner; + + + if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/ + map_p_tmp = &map_p_tmp[btn_cnt + 1]; /*Set the map to the next line*/ + i_tot ++; /*Skip the '\n'*/ + } + + lv_obj_invalidate(btnm); +} + +/** + * Set a new callback function for the buttons (It will be called when a button is released) + * @param btnm: pointer to button matrix object + * @param cb pointer to a callback function + */ +void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + ext->action = action; +} + +/** + * Enable or disable button toggling + * @param btnm pointer to button matrix object + * @param en true: enable toggling; false: disable toggling + * @param id index of the currently toggled button (ignored if 'en' == false) + */ +void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + + ext->toggle = en == false ? 0 : 1; + if(ext->toggle != 0) { + if(id >= ext->btn_cnt) id = ext->btn_cnt - 1; + ext->btn_id_tgl = id; + } else { + ext->btn_id_tgl = LV_BTNM_PR_NONE; + } + + lv_obj_invalidate(btnm); +} + +/** + * Set a style of a button matrix + * @param btnm pointer to a button matrix object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_btnm_set_style(lv_obj_t * btnm, lv_btnm_style_t type, lv_style_t * style) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + + switch(type) { + case LV_BTNM_STYLE_BG: + lv_obj_set_style(btnm, style); + break; + case LV_BTNM_STYLE_BTN_REL: + ext->styles_btn[LV_BTN_STATE_REL] = style; + lv_obj_invalidate(btnm); + break; + case LV_BTNM_STYLE_BTN_PR: + ext->styles_btn[LV_BTN_STATE_PR] = style; + lv_obj_invalidate(btnm); + break; + case LV_BTNM_STYLE_BTN_TGL_REL: + ext->styles_btn[LV_BTN_STATE_TGL_REL] = style; + lv_obj_invalidate(btnm); + break; + case LV_BTNM_STYLE_BTN_TGL_PR: + ext->styles_btn[LV_BTN_STATE_TGL_PR] = style; + lv_obj_invalidate(btnm); + break; + case LV_BTNM_STYLE_BTN_INA: + ext->styles_btn[LV_BTN_STATE_INA] = style; + lv_obj_invalidate(btnm); + break; + } +} + +void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + + ext->recolor = en; + lv_obj_invalidate(btnm); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current map of a button matrix + * @param btnm pointer to a button matrix object + * @return the current map + */ +const char ** lv_btnm_get_map(const lv_obj_t * btnm) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + return ext->map_p; +} + +/** + * Get a the callback function of the buttons on a button matrix + * @param btnm: pointer to button matrix object + * @return pointer to the callback function + */ +lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + return ext->action; +} + +/** + * Get the pressed button + * @param btnm pointer to button matrix object + * @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset) + */ +uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + return ext->btn_id_pr; +} + +/** + * Get the toggled button + * @param btnm pointer to button matrix object + * @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset) + */ +uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + + if(ext->toggle == 0) return LV_BTNM_PR_NONE; + else return ext->btn_id_tgl; +} + +/** + * Get a style of a button matrix + * @param btnm pointer to a button matrix object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_btnm_get_style(const lv_obj_t * btnm, lv_btnm_style_t type) +{ + lv_style_t * style = NULL; + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + + switch(type) { + case LV_BTNM_STYLE_BG: + style = lv_obj_get_style(btnm); + break; + case LV_BTNM_STYLE_BTN_REL: + style = ext->styles_btn[LV_BTN_STATE_REL]; + break; + case LV_BTNM_STYLE_BTN_PR: + style = ext->styles_btn[LV_BTN_STATE_PR]; + break; + case LV_BTNM_STYLE_BTN_TGL_REL: + style = ext->styles_btn[LV_BTN_STATE_TGL_REL]; + break; + case LV_BTNM_STYLE_BTN_TGL_PR: + style = ext->styles_btn[LV_BTN_STATE_TGL_PR]; + break; + case LV_BTNM_STYLE_BTN_INA: + style = ext->styles_btn[LV_BTN_STATE_INA]; + break; + default: + style = NULL; + break; + } + + return style; +} + +bool lv_btnm_get_recolor(const lv_obj_t * btnm) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + + return ext->recolor; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the button matrixs + * @param btnm pointer to a button matrix object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + return ancestor_design_f(btnm, mask, mode); + /*Return false if the object is not covers the mask_p area*/ + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + ancestor_design_f(btnm, mask, mode); + + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + lv_style_t * bg_style = lv_obj_get_style(btnm); + lv_style_t * btn_style; + lv_opa_t opa_scale = lv_obj_get_opa_scale(btnm); + + lv_area_t area_btnm; + lv_obj_get_coords(btnm, &area_btnm); + + lv_area_t area_tmp; + lv_coord_t btn_w; + lv_coord_t btn_h; + + uint16_t btn_i = 0; + uint16_t txt_i = 0; + lv_style_t style_tmp; + lv_txt_flag_t txt_flag = LV_TXT_FLAG_NONE; + + if(ext->recolor) txt_flag = LV_TXT_FLAG_RECOLOR; + + for(btn_i = 0; btn_i < ext->btn_cnt; btn_i ++, txt_i ++) { + /*Search the next valid text in the map*/ + while(strcmp(ext->map_p[txt_i], "\n") == 0) { + txt_i ++; + } + + /*Skip hidden buttons*/ + if(button_is_hidden(ext->map_p[txt_i])) continue; + + lv_area_copy(&area_tmp, &ext->button_areas[btn_i]); + area_tmp.x1 += area_btnm.x1; + area_tmp.y1 += area_btnm.y1; + area_tmp.x2 += area_btnm.x1; + area_tmp.y2 += area_btnm.y1; + + btn_w = lv_area_get_width(&area_tmp); + btn_h = lv_area_get_height(&area_tmp); + + /*Load the style*/ + if(button_is_inactive(ext->map_p[txt_i])) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_INA); + else if(btn_i != ext->btn_id_pr && btn_i != ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL); + else if(btn_i == ext->btn_id_pr && btn_i != ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_PR); + else if(btn_i != ext->btn_id_pr && btn_i == ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_REL); + else if(btn_i == ext->btn_id_pr && btn_i == ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_PR); + else btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL); /*Not possible option, just to be sure*/ + + lv_style_copy(&style_tmp, btn_style); + + /*Remove borders on the edges if `LV_BORDER_INTERNAL`*/ + if(style_tmp.body.border.part & LV_BORDER_INTERNAL) { + if(area_tmp.y1 == btnm->coords.y1 + bg_style->body.padding.ver) { + style_tmp.body.border.part &= ~LV_BORDER_TOP; + } + if(area_tmp.y2 == btnm->coords.y2 - bg_style->body.padding.ver) { + style_tmp.body.border.part &= ~LV_BORDER_BOTTOM; + } + + if(txt_i == 0) { + style_tmp.body.border.part &= ~LV_BORDER_LEFT; + } + else if(strcmp(ext->map_p[txt_i - 1],"\n") == 0) { + style_tmp.body.border.part &= ~LV_BORDER_LEFT; + } + + if(ext->map_p[txt_i + 1][0] == '\0' || strcmp(ext->map_p[txt_i + 1], "\n") == 0) { + style_tmp.body.border.part &= ~LV_BORDER_RIGHT; + } + } + lv_draw_rect(&area_tmp, mask, &style_tmp, opa_scale); + + /*Calculate the size of the text*/ + if(btn_style->glass) btn_style = bg_style; + const lv_font_t * font = btn_style->text.font; + lv_point_t txt_size; + lv_txt_get_size(&txt_size, ext->map_p[txt_i], font, + btn_style->text.letter_space, btn_style->text.line_space, + lv_area_get_width(&area_btnm), txt_flag); + + area_tmp.x1 += (btn_w - txt_size.x) / 2; + area_tmp.y1 += (btn_h - txt_size.y) / 2; + area_tmp.x2 = area_tmp.x1 + txt_size.x; + area_tmp.y2 = area_tmp.y1 + txt_size.y; + + lv_draw_label(&area_tmp, mask, btn_style, opa_scale, ext->map_p[txt_i], txt_flag, NULL); + } + } + return true; +} + +/** + * Signal function of the button matrix + * @param btnm pointer to a button matrix object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(btnm, sign, param); + if(res != LV_RES_OK) return res; + + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + lv_area_t btnm_area; + lv_area_t btn_area; + lv_point_t p; + if(sign == LV_SIGNAL_CLEANUP) { + lv_mem_free(ext->button_areas); + } else if(sign == LV_SIGNAL_STYLE_CHG || sign == LV_SIGNAL_CORD_CHG) { + lv_btnm_set_map(btnm, ext->map_p); + } else if(sign == LV_SIGNAL_PRESSING) { + uint16_t btn_pr; + /*Search the pressed area*/ + lv_indev_get_point(param, &p); + btn_pr = get_button_from_point(btnm, &p); + /*Invalidate to old and the new areas*/; + lv_obj_get_coords(btnm, &btnm_area); + if(btn_pr != ext->btn_id_pr) { + lv_indev_reset_lpr(param); + if(ext->btn_id_pr != LV_BTNM_PR_NONE) { + lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]); + btn_area.x1 += btnm_area.x1; + btn_area.y1 += btnm_area.y1; + btn_area.x2 += btnm_area.x1; + btn_area.y2 += btnm_area.y1; + lv_inv_area(&btn_area); + } + if(btn_pr != LV_BTNM_PR_NONE) { + lv_area_copy(&btn_area, &ext->button_areas[btn_pr]); + btn_area.x1 += btnm_area.x1; + btn_area.y1 += btnm_area.y1; + btn_area.x2 += btnm_area.x1; + btn_area.y2 += btnm_area.y1; + lv_inv_area(&btn_area); + } + } + + ext->btn_id_pr = btn_pr; + } + + else if(sign == LV_SIGNAL_LONG_PRESS_REP) { + if(ext->action && ext->btn_id_pr != LV_BTNM_PR_NONE) { + uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr); + if(txt_i != LV_BTNM_PR_NONE) { + if(button_is_repeat_disabled(ext->map_p[txt_i]) == false && + button_is_inactive(ext->map_p[txt_i]) == false) { + res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); + } + } + } + } else if(sign == LV_SIGNAL_RELEASED) { + if(ext->btn_id_pr != LV_BTNM_PR_NONE) { + uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr); + if(button_is_inactive(ext->map_p[txt_i]) == false && txt_i != LV_BTNM_PR_NONE) { /*Ignore the inactive buttons anf click between the buttons*/ + if(ext->action) res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); + if(res == LV_RES_OK) { + + /*Invalidate to old pressed area*/; + lv_obj_get_coords(btnm, &btnm_area); + lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]); + btn_area.x1 += btnm_area.x1; + btn_area.y1 += btnm_area.y1; + btn_area.x2 += btnm_area.x1; + btn_area.y2 += btnm_area.y1; + lv_inv_area(&btn_area); + + if(ext->toggle != 0) { + /*Invalidate to old toggled area*/; + lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]); + btn_area.x1 += btnm_area.x1; + btn_area.y1 += btnm_area.y1; + btn_area.x2 += btnm_area.x1; + btn_area.y2 += btnm_area.y1; + lv_inv_area(&btn_area); + ext->btn_id_tgl = ext->btn_id_pr; + + } + + #if USE_LV_GROUP + /*Leave the clicked button when releases if this not the focused object in a group*/ + lv_group_t * g = lv_obj_get_group(btnm); + if(lv_group_get_focused(g) != btnm) { + ext->btn_id_pr = LV_BTNM_PR_NONE; + } + #else + ext->btn_id_pr = LV_BTNM_PR_NONE; + #endif + + } + } + } + } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) { + ext->btn_id_pr = LV_BTNM_PR_NONE; + lv_obj_invalidate(btnm); + } else if(sign == LV_SIGNAL_FOCUS) { +#if USE_LV_GROUP + lv_indev_t * indev = lv_indev_get_act(); + lv_hal_indev_type_t indev_type = lv_indev_get_type(indev); + if(indev_type == LV_INDEV_TYPE_POINTER) { + /*Select the clicked button*/ + lv_point_t p1; + lv_indev_get_point(indev, &p1); + uint16_t btn_i = get_button_from_point(btnm, &p1); + ext->btn_id_pr = btn_i; + } else if(indev_type == LV_INDEV_TYPE_ENCODER) { + /*In navigation mode don't select any button but in edit mode select the fist*/ + if(lv_group_get_editing(lv_obj_get_group(btnm))) ext->btn_id_pr = 0; + else ext->btn_id_pr = LV_BTNM_PR_NONE; + } else { + ext->btn_id_pr = 0; + } +#else + ext->btn_id_pr = 0; +#endif + lv_obj_invalidate(btnm); + } else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char *)param); + if(c == LV_GROUP_KEY_RIGHT) { + if(ext->btn_id_pr == LV_BTNM_PR_NONE) ext->btn_id_pr = 0; + else ext->btn_id_pr++; + if(ext->btn_id_pr >= ext->btn_cnt - 1) ext->btn_id_pr = ext->btn_cnt - 1; + lv_obj_invalidate(btnm); + } else if(c == LV_GROUP_KEY_LEFT) { + if(ext->btn_id_pr == LV_BTNM_PR_NONE) ext->btn_id_pr = 0; + if(ext->btn_id_pr > 0) ext->btn_id_pr--; + lv_obj_invalidate(btnm); + } else if(c == LV_GROUP_KEY_DOWN) { + lv_style_t * style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG); + /*Find the area below the the current*/ + if(ext->btn_id_pr == LV_BTNM_PR_NONE) { + ext->btn_id_pr = 0; + } else { + uint16_t area_below; + lv_coord_t pr_center = ext->button_areas[ext->btn_id_pr].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_pr]) >> 1); + + for(area_below = ext->btn_id_pr; area_below < ext->btn_cnt; area_below ++) { + if(ext->button_areas[area_below].y1 > ext->button_areas[ext->btn_id_pr].y1 && + pr_center >= ext->button_areas[area_below].x1 && + pr_center <= ext->button_areas[area_below].x2 + style->body.padding.hor) { + break; + } + } + + if(area_below < ext->btn_cnt) ext->btn_id_pr = area_below; + } + lv_obj_invalidate(btnm); + } else if(c == LV_GROUP_KEY_UP) { + lv_style_t * style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG); + /*Find the area below the the current*/ + if(ext->btn_id_pr == LV_BTNM_PR_NONE) { + ext->btn_id_pr = 0; + } else { + int16_t area_above; + lv_coord_t pr_center = ext->button_areas[ext->btn_id_pr].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_pr]) >> 1); + + for(area_above = ext->btn_id_pr; area_above >= 0; area_above --) { + if(ext->button_areas[area_above].y1 < ext->button_areas[ext->btn_id_pr].y1 && + pr_center >= ext->button_areas[area_above].x1 - style->body.padding.hor && + pr_center <= ext->button_areas[area_above].x2) { + break; + } + } + if(area_above >= 0) ext->btn_id_pr = area_above; + + } + lv_obj_invalidate(btnm); + } else if(c == LV_GROUP_KEY_ENTER) { + if(ext->action != NULL) { + uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr); + if(txt_i != LV_BTNM_PR_NONE) { + res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); + } + } + } + } else if(sign == LV_SIGNAL_GET_EDITABLE) { + bool * editable = (bool *)param; + *editable = true; + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_btnm"; + } + + + return res; +} + +/** + * Create the required number of buttons according to a map + * @param btnm pointer to button matrix object + * @param map_p pointer to a string array + */ +static void allocate_btn_areas(lv_obj_t * btnm, const char ** map) +{ + /*Count the buttons in the map*/ + uint16_t btn_cnt = 0; + uint16_t i = 0; + while(strlen(map[i]) != 0) { + if(strcmp(map[i], "\n") != 0) { /*Do not count line breaks*/ + btn_cnt ++; + } + i++; + } + + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + + if(ext->button_areas != NULL) { + lv_mem_free(ext->button_areas); + ext->button_areas = NULL; + } + + ext->button_areas = lv_mem_alloc(sizeof(lv_area_t) * btn_cnt); + lv_mem_assert(ext->button_areas); + if(ext->button_areas == NULL) btn_cnt = 0; + + ext->btn_cnt = btn_cnt; +} + +/** + * Get the width of a button in units. It comes from the first "letter". + * @param btn_str The descriptor string of a button. E.g. "apple" or "\004banana" + * @return the width of the button in units + */ +static uint8_t get_button_width(const char * btn_str) +{ + if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) { + return btn_str[0] & LV_BTNM_WIDTH_MASK; + } + + return 1; /*Default width is 1*/ +} + +static bool button_is_hidden(const char * btn_str) +{ + /*If control byte presents and hidden bit is '1' then the button is hidden*/ + if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) && + (btn_str[0] & LV_BTNM_HIDE_MASK)) { + return true; + } + + return false; +} + +static bool button_is_repeat_disabled(const char * btn_str) +{ + /*If control byte presents and hidden bit is '1' then the button is hidden*/ + if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) && + (btn_str[0] & LV_BTNM_REPEAT_DISABLE_MASK)) { + return true; + } + + return false; +} + +static bool button_is_inactive(const char * btn_str) +{ + /*If control byte presents and hidden bit is '1' then the button is hidden*/ + if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) && + (btn_str[0] & LV_BTNM_INACTIVE_MASK)) { + return true; + } + + return false; +} + + +const char * cut_ctrl_byte(const char * btn_str) +{ + /*Cut the control byte if present*/ + if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) return &btn_str[1]; + else return btn_str; +} + +/** + * Gives the button id of a button under a given point + * @param btnm pointer to a button matrix object + * @param p a point with absolute coordinates + * @return the id of the button or LV_BTNM_PR_NONE. + */ +static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p) +{ + lv_area_t btnm_cords; + lv_area_t btn_area; + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + uint16_t i; + lv_obj_get_coords(btnm, &btnm_cords); + + for(i = 0; i < ext->btn_cnt; i++) { + lv_area_copy(&btn_area, &ext->button_areas[i]); + btn_area.x1 += btnm_cords.x1; + btn_area.y1 += btnm_cords.y1; + btn_area.x2 += btnm_cords.x1; + btn_area.y2 += btnm_cords.y1; + if(lv_area_is_point_on(&btn_area, p) != false) { + break; + } + } + + if(i == ext->btn_cnt) i = LV_BTNM_PR_NONE; + + return i; +} + +/** + * Get the text of a button + * @param btnm pointer to a button matrix object + * @param btn_id button id + * @return text id in ext->map_p or LV_BTNM_PR_NONE if 'btn_id' was invalid + */ +static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + if(btn_id > ext->btn_cnt) return LV_BTNM_PR_NONE; + + uint16_t txt_i = 0; + uint16_t btn_i = 0; + + /* Search the text of ext->btn_pr the buttons text in the map + * Skip "\n"-s*/ + while(btn_i != btn_id) { + btn_i ++; + txt_i ++; + if(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++; + } + + if(btn_i == ext->btn_cnt) return LV_BTNM_PR_NONE; + + return txt_i; +} + + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.h new file mode 100644 index 0000000..de334b7 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_btnm.h @@ -0,0 +1,197 @@ +/** + * @file lv_btnm.h + * + */ + + +#ifndef LV_BTNM_H +#define LV_BTNM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_BTNM != 0 + +#include "../lv_core/lv_obj.h" +#include "lv_label.h" +#include "lv_btn.h" + +/********************* + * DEFINES + *********************/ + +/*Control byte*/ +#define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/ +#define LV_BTNM_CTRL_MASK 0xC0 +#define LV_BTNM_WIDTH_MASK 0x07 +#define LV_BTNM_HIDE_MASK 0x08 +#define LV_BTNM_REPEAT_DISABLE_MASK 0x10 +#define LV_BTNM_INACTIVE_MASK 0x20 + + +#define LV_BTNM_PR_NONE 0xFFFF +/********************** + * TYPEDEFS + **********************/ + +/* Type of callback function which is called when a button is released or long pressed on the button matrix + * Parameters: button matrix, text of the released button + * return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/ +typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt); + +/*Data of button matrix*/ +typedef struct +{ + /*No inherited ext.*/ /*Ext. of ancestor*/ + /*New data for this type */ + const char ** map_p; /*Pointer to the current map*/ + lv_area_t *button_areas; /*Array of areas of buttons*/ + lv_btnm_action_t action; /*A function to call when a button is releases*/ + lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/ + uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/ + uint16_t btn_id_pr; /*Index of the currently pressed button (in `button_areas`) or LV_BTNM_PR_NONE*/ + uint16_t btn_id_tgl; /*Index of the currently toggled button (in `button_areas`) or LV_BTNM_PR_NONE */ + uint8_t toggle :1; /*Enable toggling*/ + uint8_t recolor :1; /*Enable button recoloring*/ +} lv_btnm_ext_t; + +enum { + LV_BTNM_STYLE_BG, + LV_BTNM_STYLE_BTN_REL, + LV_BTNM_STYLE_BTN_PR, + LV_BTNM_STYLE_BTN_TGL_REL, + LV_BTNM_STYLE_BTN_TGL_PR, + LV_BTNM_STYLE_BTN_INA, +}; +typedef uint8_t lv_btnm_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a button matrix objects + * @param par pointer to an object, it will be the parent of the new button matrix + * @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it + * @return pointer to the created button matrix + */ +lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new map. Buttons will be created/deleted according to the map. + * @param btnm pointer to a button matrix object + * @param map pointer a string array. The last string has to be: "". + * Use "\n" to begin a new line. + * The first byte can be a control data: + * - bit 7: always 1 + * - bit 6: always 0 + * - bit 5: inactive (disabled) + * - bit 4: no repeat (on long press) + * - bit 3: hidden + * - bit 2..0: button relative width + * Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press + */ +void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); + +/** + * Set a new callback function for the buttons (It will be called when a button is released) + * @param btnm: pointer to button matrix object + * @param action pointer to a callback function + */ +void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action); + +/** + * Enable or disable button toggling + * @param btnm pointer to button matrix object + * @param en true: enable toggling; false: disable toggling + * @param id index of the currently toggled button (ignored if 'en' == false) + */ +void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id); + +/** + * Set a style of a button matrix + * @param btnm pointer to a button matrix object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_btnm_set_style(lv_obj_t *btnm, lv_btnm_style_t type, lv_style_t *style); + +/** + * Set whether recoloring is enabled + * @param btnm pointer to button matrix object + * @param en whether recoloring is enabled + */ +void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current map of a button matrix + * @param btnm pointer to a button matrix object + * @return the current map + */ +const char ** lv_btnm_get_map(const lv_obj_t * btnm); + +/** + * Get a the callback function of the buttons on a button matrix + * @param btnm: pointer to button matrix object + * @return pointer to the callback function + */ +lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm); + +/** + * Get the pressed button + * @param btnm pointer to button matrix object + * @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset) + */ +uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm); + +/** + * Get the toggled button + * @param btnm pointer to button matrix object + * @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset) + */ +uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm); + +/** + * Get a style of a button matrix + * @param btnm pointer to a button matrix object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_btnm_get_style(const lv_obj_t *btnm, lv_btnm_style_t type); + +/** + * Find whether recoloring is enabled + * @param btnm pointer to button matrix object + * @return whether recoloring is enabled + */ +bool lv_btnm_get_recolor(const lv_obj_t * btnm); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_BTNM*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_BTNM_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.c new file mode 100644 index 0000000..543c8d3 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.c @@ -0,0 +1,1038 @@ +/** + * @file lv_calendar.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_calendar.h" +#if USE_LV_CALENDAR != 0 + +#include "../lv_draw/lv_draw.h" +#include "../lv_hal/lv_hal_indev.h" +#include "../lv_misc/lv_math.h" +#include "../lv_core/lv_indev.h" +#include "../lv_themes/lv_theme.h" +//#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +enum { + DAY_DRAW_PREV_MONTH, + DAY_DRAW_ACT_MONTH, + DAY_DRAW_NEXT_MONTH, +}; +typedef uint8_t day_draw_state_t; + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_calendar_design(lv_obj_t * calendar, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * param); +static bool calculate_touched_day(lv_obj_t * calendar, const lv_point_t * touched_point); +static lv_coord_t get_header_height(lv_obj_t * calendar); +static lv_coord_t get_day_names_height(lv_obj_t * calendar); +static void draw_header(lv_obj_t * calendar, const lv_area_t * mask); +static void draw_day_names(lv_obj_t * calendar, const lv_area_t * mask); +static void draw_days(lv_obj_t * calendar, const lv_area_t * mask); +static uint8_t get_day_of_week(uint32_t year, uint32_t month, uint32_t day); +static bool is_highlighted(lv_obj_t * calendar, int32_t year, int32_t month, int32_t day); +static const char * get_day_name(lv_obj_t * calendar, uint8_t day); +static const char * get_month_name(lv_obj_t * calendar, int32_t month); +static uint8_t get_month_length(int32_t year, int32_t month); +static uint8_t is_leap_year(uint32_t year); + + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; +static const char * day_name[7] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}; +static const char * month_name[12] = {"January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December" +}; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a calendar object + * @param par pointer to an object, it will be the parent of the new calendar + * @param copy pointer to a calendar object, if not NULL then the new object will be copied from it + * @return pointer to the created calendar + */ +lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("calendar create started"); + + /*Create the ancestor of calendar*/ + lv_obj_t * new_calendar = lv_obj_create(par, copy); + lv_mem_assert(new_calendar); + if(new_calendar == NULL) return NULL; + + /*Allocate the calendar type specific extended data*/ + lv_calendar_ext_t * ext = lv_obj_allocate_ext_attr(new_calendar, sizeof(lv_calendar_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_calendar); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_calendar); + + /*Initialize the allocated 'ext' */ + ext->today.year = 2018; + ext->today.month = 1; + ext->today.day = 1; + + ext->showed_date.year = 2018; + ext->showed_date.month = 1; + ext->showed_date.day = 1; + + ext->pressed_date.year = 0; + ext->pressed_date.month = 0; + ext->pressed_date.day = 0; + + ext->highlighted_dates = NULL; + ext->highlighted_dates_num = 0; + ext->day_names = NULL; + ext->month_names = NULL; + ext->actions[LV_CALENDAR_ACTION_PR] = NULL; + ext->actions[LV_CALENDAR_ACTION_CLICK] = NULL; + ext->actions[LV_CALENDAR_ACTION_LONG_PR] = NULL; + ext->actions[LV_CALENDAR_ACTION_LONG_PR_REPEAT] = NULL; + ext->style_header = &lv_style_plain_color; + ext->style_header_pr = &lv_style_pretty_color; + ext->style_highlighted_days = &lv_style_plain_color; + ext->style_inactive_days = &lv_style_btn_ina; + ext->style_week_box = &lv_style_plain_color; + ext->style_today_box = &lv_style_pretty_color; + ext->style_day_names = &lv_style_pretty; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_calendar, lv_calendar_signal); + lv_obj_set_design_func(new_calendar, lv_calendar_design); + + /*Init the new calendar calendar*/ + if(copy == NULL) { + lv_obj_set_size(new_calendar, LV_DPI * 2, LV_DPI * 2); + lv_obj_set_style(new_calendar, &lv_style_pretty); + + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_BG, th->calendar.bg); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER, th->calendar.header); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER_PR, th->calendar.header_pr); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_DAY_NAMES, th->calendar.day_names); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_WEEK_BOX, th->calendar.week_box); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_TODAY_BOX, th->calendar.today_box); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS, th->calendar.highlighted_days); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_INACTIVE_DAYS, th->calendar.inactive_days); + } else { + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_BG, &lv_style_pretty); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER, ext->style_header); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER_PR, ext->style_header_pr); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_DAY_NAMES, ext->style_day_names); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_WEEK_BOX, ext->style_week_box); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_TODAY_BOX, ext->style_today_box); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS, ext->style_highlighted_days); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_INACTIVE_DAYS, ext->style_inactive_days); + + } + + } + /*Copy an existing calendar*/ + else { + lv_calendar_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->today.year = copy_ext->today.year; + ext->today.month = copy_ext->today.month; + ext->today.day = copy_ext->today.day; + + ext->showed_date.year = copy_ext->showed_date.year; + ext->showed_date.month = copy_ext->showed_date.month; + ext->showed_date.day = copy_ext->showed_date.day; + + ext->highlighted_dates = copy_ext->highlighted_dates; + ext->highlighted_dates_num = copy_ext->highlighted_dates_num; + ext->day_names = copy_ext->day_names; + + memcpy(ext->actions, copy_ext->actions, sizeof(ext->actions)); + + ext->month_names = copy_ext->month_names; + ext->style_header = copy_ext->style_header; + ext->style_header_pr = copy_ext->style_header_pr; + ext->style_highlighted_days = copy_ext->style_highlighted_days; + ext->style_inactive_days = copy_ext->style_inactive_days; + ext->style_week_box = copy_ext->style_week_box; + ext->style_today_box = copy_ext->style_today_box; + ext->style_day_names = copy_ext->style_day_names; + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_calendar); + } + + LV_LOG_INFO("calendar created"); + + return new_calendar; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/* + * New object specific "add" or "remove" functions come here + */ + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a function to call when a calendar event happens + * @param calendar pointer to a calendar object + * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) + */ +void lv_calendar_set_action(lv_obj_t * calendar, lv_calendar_action_t type, lv_action_t action) +{ + if(type >= LV_CALENDAR_ACTION_NUM) return; + + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + ext->actions[type] = action; +} + +/** + * Set the today's date + * @param calendar pointer to a calendar object + * @param today pointer to an `lv_calendar_date_t` variable containing the date of today. The value will be saved it can be local variable too. + */ +void lv_calendar_set_today_date(lv_obj_t * calendar, lv_calendar_date_t * today) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + ext->today.year = today->year; + ext->today.month = today->month; + ext->today.day = today->day; + + lv_obj_invalidate(calendar); +} + +/** + * Set the currently showed + * @param calendar pointer to a calendar object + * @param showed pointer to an `lv_calendar_date_t` variable containing the date to show. The value will be saved it can be local variable too. + */ +void lv_calendar_set_showed_date(lv_obj_t * calendar, lv_calendar_date_t * showed) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + ext->showed_date.year = showed->year; + ext->showed_date.month = showed->month; + ext->showed_date.day = showed->day; + + lv_obj_invalidate(calendar); +} + +/** + * Set the the highlighted dates + * @param calendar pointer to a calendar object + * @param highlighted pointer to an `lv_calendar_date_t` array containing the dates. ONLY A POINTER WILL BE SAVED! CAN'T BE LOCAL ARRAY. + * @param date_num number of dates in the array + */ +void lv_calendar_set_highlighted_dates(lv_obj_t * calendar, lv_calendar_date_t * highlighted, uint16_t date_num) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + ext->highlighted_dates = highlighted; + ext->highlighted_dates_num = date_num; + + lv_obj_invalidate(calendar); +} + + +/** + * Set the name of the days + * @param calendar pointer to a calendar object + * @param day_names pointer to an array with the names. E.g. `const char * days[7] = {"Sun", "Mon", ...}` + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + */ +void lv_calendar_set_day_names(lv_obj_t * calendar, const char ** day_names) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + ext->day_names = day_names; + lv_obj_invalidate(calendar); +} + +/** + * Set the name of the month + * @param calendar pointer to a calendar object + * @param day_names pointer to an array with the names. E.g. `const char * days[12] = {"Jan", "Feb", ...}` + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + */ +void lv_calendar_set_month_names(lv_obj_t * calendar, const char ** day_names) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + ext->month_names = day_names; + lv_obj_invalidate(calendar); +} + +/** + * Set a style of a calendar. + * @param calendar pointer to calendar object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_calendar_set_style(lv_obj_t * calendar, lv_calendar_style_t type, lv_style_t * style) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + + switch(type) { + case LV_CALENDAR_STYLE_BG: + lv_obj_set_style(calendar, style); + break; + case LV_CALENDAR_STYLE_DAY_NAMES: + ext->style_day_names = style; + break; + case LV_CALENDAR_STYLE_HEADER: + ext->style_header = style; + break; + case LV_CALENDAR_STYLE_HEADER_PR: + ext->style_header_pr = style; + break; + case LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS: + ext->style_highlighted_days = style; + break; + case LV_CALENDAR_STYLE_INACTIVE_DAYS: + ext->style_inactive_days = style; + break; + case LV_CALENDAR_STYLE_TODAY_BOX: + ext->style_today_box = style; + break; + case LV_CALENDAR_STYLE_WEEK_BOX: + ext->style_week_box = style; + break; + } + + lv_obj_invalidate(calendar); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the action of a calendar + * @param calendar pointer to a calendar object + * @return pointer to the action function + */ +lv_action_t lv_calendar_get_action(const lv_obj_t * calendar, lv_calendar_action_t type) +{ + if(type >= LV_CALENDAR_ACTION_NUM) return NULL; + + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + return ext->actions[type]; +} + +/** + * Get the today's date + * @param calendar pointer to a calendar object + * @return return pointer to an `lv_calendar_date_t` variable containing the date of today. + */ +lv_calendar_date_t * lv_calendar_get_today_date(const lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + return &ext->today; +} + +/** + * Get the currently showed + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` variable containing the date is being shown. + */ +lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + return &ext->showed_date; +} + +/** + * Get the the pressed date. + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` variable containing the pressed date. + */ +lv_calendar_date_t * lv_calendar_get_pressed_date(const lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + return &ext->pressed_date; +} + +/** + * Get the the highlighted dates + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` array containing the dates. + */ +lv_calendar_date_t * lv_calendar_get_highlighted_dates(const lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + return ext->highlighted_dates; +} + +/** + * Get the number of the highlighted dates + * @param calendar pointer to a calendar object + * @return number of highlighted days + */ +uint16_t lv_calendar_get_highlighted_dates_num(const lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + return ext->highlighted_dates_num; +} + +/** + * Get the name of the days + * @param calendar pointer to a calendar object + * @return pointer to the array of day names + */ +const char ** lv_calendar_get_day_names(const lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + return ext->day_names; +} + +/** + * Get the name of the month + * @param calendar pointer to a calendar object + * @return pointer to the array of month names + */ +const char ** lv_calendar_get_month_names(const lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + return ext->month_names; +} + +/** + * Get style of a calendar. + * @param calendar pointer to calendar object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_calendar_get_style(const lv_obj_t * calendar, lv_calendar_style_t type) +{ + lv_style_t * style = NULL; + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + + switch(type) { + case LV_CALENDAR_STYLE_BG: + style = lv_obj_get_style(calendar); + break; + case LV_CALENDAR_STYLE_HEADER: + style = ext->style_header; + break; + case LV_CALENDAR_STYLE_HEADER_PR: + style = ext->style_header_pr; + break; + case LV_CALENDAR_STYLE_DAY_NAMES: + style = ext->style_day_names; + break; + case LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS: + style = ext->style_highlighted_days; + break; + case LV_CALENDAR_STYLE_INACTIVE_DAYS: + style = ext->style_inactive_days; + break; + case LV_CALENDAR_STYLE_WEEK_BOX: + style = ext->style_week_box; + break; + case LV_CALENDAR_STYLE_TODAY_BOX: + style = ext->style_today_box; + break; + default: + style = NULL; + break; + } + + return style; +} + +/*===================== + * Other functions + *====================*/ + +/* + * New object specific "other" functions come here + */ + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the calendars + * @param calendar pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_calendar_design(lv_obj_t * calendar, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_opa_t opa_scale = lv_obj_get_opa_scale(calendar); + lv_draw_rect(&calendar->coords, mask, lv_calendar_get_style(calendar, LV_CALENDAR_STYLE_BG), opa_scale); + + draw_header(calendar, mask); + draw_day_names(calendar, mask); + draw_days(calendar, mask); + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the calendar + * @param calendar pointer to a calendar object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(calendar, sign, param); + if(res != LV_RES_OK) return res; + + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_PRESSED) { + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + /*Call the press action, 'param' is the caller indev_proc*/ + if(ext->actions[LV_CALENDAR_ACTION_PR]) { + lv_indev_t * indev = lv_indev_get_act(); + lv_point_t p; + lv_indev_get_point(indev, &p); + + if(calculate_touched_day(calendar, &p)){ + if(ext->btn_pressing != 0) lv_obj_invalidate(calendar); + ext->btn_pressing = 0; + res = ext->actions[LV_CALENDAR_ACTION_PR](calendar); + } + } + } else if(sign == LV_SIGNAL_PRESSING) { + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + lv_area_t header_area; + lv_area_copy(&header_area, &calendar->coords); + header_area.y2 = header_area.y1 + get_header_height(calendar); + + lv_indev_t * indev = lv_indev_get_act(); + lv_point_t p; + lv_indev_get_point(indev, &p); + + if(lv_area_is_point_on(&header_area, &p)) { + if(p.x < header_area.x1 + lv_area_get_width(&header_area) / 2) { + if(ext->btn_pressing != -1) lv_obj_invalidate(calendar); + ext->btn_pressing = -1; + } else { + if(ext->btn_pressing != 1) lv_obj_invalidate(calendar); + ext->btn_pressing = 1; + } + + ext->pressed_date.year = 0; + } else if(calculate_touched_day(calendar, &p)) { + if(ext->btn_pressing != 0) lv_obj_invalidate(calendar); + ext->btn_pressing = 0; + } else { + if(ext->btn_pressing != 0) lv_obj_invalidate(calendar); + ext->btn_pressing = 0; + ext->pressed_date.year = 0; + } + } else if(sign == LV_SIGNAL_PRESS_LOST) { + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + ext->pressed_date.year = 0; + ext->btn_pressing = 0; + lv_obj_invalidate(calendar); + + } else if(sign == LV_SIGNAL_RELEASED) { + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + if(ext->btn_pressing < 0) { + if(ext->showed_date.month <= 1) { + ext->showed_date.month = 12; + ext->showed_date.year --; + } else { + ext->showed_date.month --; + } + } else if(ext->btn_pressing > 0) { + if(ext->showed_date.month >= 12) { + ext->showed_date.month = 1; + ext->showed_date.year ++; + } else { + ext->showed_date.month ++; + } + } + else if(ext->pressed_date.year != 0) + { + if(ext->actions[LV_CALENDAR_ACTION_CLICK]) { + res = ext->actions[LV_CALENDAR_ACTION_CLICK](calendar); + } + } + + ext->pressed_date.year = 0; + ext->btn_pressing = 0; + lv_obj_invalidate(calendar); + + + } else if(sign == LV_SIGNAL_LONG_PRESS) { + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + if(ext->actions[LV_CALENDAR_ACTION_LONG_PR] && (ext->pressed_date.year != 0)) { + res = ext->actions[LV_CALENDAR_ACTION_LONG_PR](calendar); + } + } else if(sign == LV_SIGNAL_LONG_PRESS_REP) { + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + if(ext->actions[LV_CALENDAR_ACTION_LONG_PR_REPEAT] && (ext->pressed_date.year != 0)) { + res = ext->actions[LV_CALENDAR_ACTION_LONG_PR_REPEAT](calendar); + } + } else if(sign == LV_SIGNAL_CONTROLL) { + uint8_t c = *((uint8_t *) param); + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { + if(ext->showed_date.month >= 12) { + ext->showed_date.month = 1; + ext->showed_date.year ++; + } else { + ext->showed_date.month ++; + } + lv_obj_invalidate(calendar); + } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { + if(ext->showed_date.month <= 1) { + ext->showed_date.month = 12; + ext->showed_date.year --; + } else { + ext->showed_date.month --; + } + lv_obj_invalidate(calendar); + } + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set date*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_calendar"; + } + + return res; +} + +/** + * It will check if the days part of calendar is touched + * and if it is, it will calculate the day and put it in pressed_date of calendar object. + * @param calendar pointer to a calendar object + * @param pointer to a point + * @return true: days part of calendar is touched and its related date is put in pressed date + * false: the point is out of days part area. + */ +static bool calculate_touched_day(lv_obj_t * calendar, const lv_point_t * touched_point) +{ + lv_area_t days_area; + lv_area_copy(&days_area, &calendar->coords); + lv_style_t * style_bg = lv_calendar_get_style(calendar, LV_CALENDAR_STYLE_BG); + days_area.x1 += style_bg->body.padding.hor; + days_area.x2 -= style_bg->body.padding.hor; + days_area.y1 = calendar->coords.y1 + get_header_height(calendar) + get_day_names_height(calendar) - style_bg->body.padding.ver; + + if(lv_area_is_point_on(&days_area, touched_point)) { + lv_coord_t w = (days_area.x2 - days_area.x1 + 1) / 7; + lv_coord_t h = (days_area.y2 - days_area.y1 + 1) / 6; + uint8_t x_pos = 0; + x_pos = (touched_point->x - days_area.x1) / w; + if(x_pos > 6) x_pos = 6; + uint8_t y_pos = 0; + y_pos = (touched_point->y - days_area.y1) / h; + if(y_pos > 5) y_pos = 5; + + uint8_t i_pos = 0; + i_pos = (y_pos * 7) + x_pos; + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + if(i_pos < get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) ) { + ext->pressed_date.year = ext->showed_date.year - (ext->showed_date.month == 1 ? 1 : 0); + ext->pressed_date.month = ext->showed_date.month == 1 ? 12 : (ext->showed_date.month - 1); + ext->pressed_date.day = get_month_length(ext->pressed_date.year, ext->pressed_date.month) - + get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + 1 + i_pos; + } + else if(i_pos < (get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + + get_month_length(ext->showed_date.year, ext->showed_date.month))) { + ext->pressed_date.year = ext->showed_date.year; + ext->pressed_date.month = ext->showed_date.month; + ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1); + } + else if(i_pos < 42) { + ext->pressed_date.year = ext->showed_date.year + (ext->showed_date.month == 12 ? 1 : 0); + ext->pressed_date.month = ext->showed_date.month == 12 ? 1 : (ext->showed_date.month + 1); + ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + - get_month_length(ext->showed_date.year, ext->showed_date.month); + } + return true; + }else { + return false; + } +} + +/** + * Get the height of a calendar's header based on it's style + * @param calendar point to a calendar + * @return the header's height + */ +static lv_coord_t get_header_height(lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + + return lv_font_get_height(ext->style_header->text.font) + ext->style_header->body.padding.ver * 2; +} + +/** + * Get the height of a calendar's day_names based on it's style + * @param calendar point to a calendar + * @return the day_names's height + */ +static lv_coord_t get_day_names_height(lv_obj_t * calendar) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + + return lv_font_get_height(ext->style_day_names->text.font) + ext->style_day_names->body.padding.ver * 2; +} + +/** + * Draw the calendar header with month name and arrows + * @param calendar point to a calendar + * @param mask a mask for drawing + */ +static void draw_header(lv_obj_t * calendar, const lv_area_t * mask) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + lv_opa_t opa_scale = lv_obj_get_opa_scale(calendar); + + lv_area_t header_area; + header_area.x1 = calendar->coords.x1; + header_area.x2 = calendar->coords.x2; + header_area.y1 = calendar->coords.y1; + header_area.y2 = calendar->coords.y1 + get_header_height(calendar); + + lv_draw_rect(&header_area, mask, ext->style_header, opa_scale); + + /*Add the year + month name*/ + char txt_buf[64]; + lv_math_num_to_str(ext->showed_date.year, txt_buf); + txt_buf[4] = ' '; + txt_buf[5] = '\0'; + strcpy(&txt_buf[5], get_month_name(calendar, ext->showed_date.month)); + header_area.y1 += ext->style_header->body.padding.ver; + lv_draw_label(&header_area, mask, ext->style_header, opa_scale, txt_buf, LV_TXT_FLAG_CENTER, NULL); + + /*Add the left arrow*/ + lv_style_t * arrow_style = ext->btn_pressing < 0 ? ext->style_header_pr : ext->style_header; + header_area.x1 += ext->style_header->body.padding.hor; + lv_draw_label(&header_area, mask, arrow_style, opa_scale, SYMBOL_LEFT, LV_TXT_FLAG_NONE, NULL); + + /*Add the right arrow*/ + arrow_style = ext->btn_pressing > 0 ? ext->style_header_pr : ext->style_header; + header_area.x1 = header_area.x2 - ext->style_header->body.padding.hor - + lv_txt_get_width(SYMBOL_RIGHT, strlen(SYMBOL_RIGHT), arrow_style->text.font, + arrow_style->text.line_space, LV_TXT_FLAG_NONE); + lv_draw_label(&header_area, mask, arrow_style, opa_scale, SYMBOL_RIGHT, LV_TXT_FLAG_NONE, NULL); + +} + +/** + * Draw the day's name below the header + * @param calendar point to a calendar + * @param mask a mask for drawing + */ +static void draw_day_names(lv_obj_t * calendar, const lv_area_t * mask) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + lv_opa_t opa_scale = lv_obj_get_opa_scale(calendar); + + lv_coord_t hpad = ext->style_day_names->body.padding.hor; + lv_coord_t w = lv_obj_get_width(calendar) - 2 * hpad; + lv_coord_t box_w = w / 7; + lv_area_t label_area; + label_area.y1 = calendar->coords.y1 + get_header_height(calendar) + ext->style_day_names->body.padding.ver; + label_area.y2 = label_area.y1 + lv_font_get_height(ext->style_day_names->text.font); + uint32_t i; + for(i = 0; i < 7; i++) { + label_area.x1 = calendar->coords.x1 + (w * i) / 7 + hpad; + label_area.x2 = label_area.x1 + box_w; + lv_draw_label(&label_area, mask, ext->style_day_names, opa_scale, get_day_name(calendar, i), LV_TXT_FLAG_CENTER, NULL); + } + +} + +/** + * Draw the date numbers in a matrix + * @param calendar point to a calendar + * @param mask a mask for drawing + */ +static void draw_days(lv_obj_t * calendar, const lv_area_t * mask) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + lv_style_t * style_bg = lv_calendar_get_style(calendar, LV_CALENDAR_STYLE_BG); + lv_coord_t hpad = style_bg->body.padding.hor; + lv_area_t label_area; + lv_opa_t opa_scale = lv_obj_get_opa_scale(calendar); + label_area.y1 = calendar->coords.y1 + get_header_height(calendar) + + ext->style_day_names->body.padding.ver + lv_font_get_height(ext->style_day_names->text.font) + + ext->style_day_names->body.padding.ver; + label_area.y2 = label_area.y1 + lv_font_get_height(style_bg->text.font); + + lv_coord_t w = lv_obj_get_width(calendar) - 2 * hpad; + lv_coord_t h = calendar->coords.y2 - label_area.y1 - style_bg->body.padding.ver; + lv_coord_t box_w = w / 7; + lv_coord_t vert_space = (h - (6 * lv_font_get_height(style_bg->text.font))) / 5; + + uint32_t week; + uint8_t day_cnt; + uint8_t month_start_day = get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1); + day_draw_state_t draw_state; /*true: Not the prev. or next month is drawn*/ + lv_style_t * act_style; + + /*If starting with the first day of the week then the previous month is not visible*/ + if(month_start_day == 0) { + day_cnt = 1; + draw_state = DAY_DRAW_ACT_MONTH; + act_style = style_bg; + } else { + draw_state = DAY_DRAW_PREV_MONTH; + day_cnt = get_month_length(ext->showed_date.year, ext->showed_date.month - 1); /*Length of the previous month*/ + day_cnt -= month_start_day - 1; /*First visible number of the previous month*/ + act_style = ext->style_inactive_days; + } + + + bool month_of_today_shown = false; + if(ext->showed_date.year == ext->today.year && + ext->showed_date.month == ext->today.month) { + month_of_today_shown = true; + } + + char buf[3]; + bool in_week_box = false; + + /*Draw 6 weeks*/ + for(week = 0; week < 6; week++) { + + /*Draw the "week box"*/ + if(month_of_today_shown && + ((draw_state == DAY_DRAW_ACT_MONTH && ext->today.day >= day_cnt && ext->today.day < day_cnt + 7) || + (draw_state == DAY_DRAW_PREV_MONTH && ext->today.day <= 7 - month_start_day && week == 0))) { + lv_area_t week_box_area; + lv_area_copy(&week_box_area, &label_area); /*'label_area' is already set for this row*/ + week_box_area.x1 = calendar->coords.x1 + style_bg->body.padding.hor - ext->style_week_box->body.padding.hor; + week_box_area.x2 = calendar->coords.x2 - style_bg->body.padding.hor + ext->style_week_box->body.padding.hor; + + week_box_area.y1 -= ext->style_week_box->body.padding.ver; + week_box_area.y2 += ext->style_week_box->body.padding.ver; + lv_draw_rect(&week_box_area, mask, ext->style_week_box, opa_scale); + + in_week_box = true; + } else { + in_week_box = false; + } + + /*Draw the 7 days of a week*/ + uint32_t day; + for(day = 0; day < 7; day++) { + /*The previous month is over*/ + if(draw_state == DAY_DRAW_PREV_MONTH && day == month_start_day) { + draw_state = DAY_DRAW_ACT_MONTH; + day_cnt = 1; + act_style = style_bg; + } + /*The current month is over*/ + if(draw_state == DAY_DRAW_ACT_MONTH && + day_cnt > get_month_length(ext->showed_date.year, ext->showed_date.month)) { + draw_state = DAY_DRAW_NEXT_MONTH; + day_cnt = 1; + act_style = ext->style_inactive_days; + } + + label_area.x1 = calendar->coords.x1 + (w * day) / 7 + hpad; + label_area.x2 = label_area.x1 + box_w; + + /*Draw the "today box"*/ + if(draw_state == DAY_DRAW_ACT_MONTH && month_of_today_shown && ext->today.day == day_cnt) { + lv_area_t today_box_area; + lv_area_copy(&today_box_area, &label_area); + today_box_area.x1 = label_area.x1; + today_box_area.x2 = label_area.x2; + + today_box_area.y1 = label_area.y1 - ext->style_today_box->body.padding.ver; + today_box_area.y2 = label_area.y2 + ext->style_today_box->body.padding.ver; + lv_draw_rect(&today_box_area, mask, ext->style_today_box, opa_scale); + } + + /*Get the final style : highlighted/week box/today box/normal*/ + lv_style_t * final_style; + if(draw_state == DAY_DRAW_PREV_MONTH && + is_highlighted(calendar, ext->showed_date.year - (ext->showed_date.month == 1 ? 1 : 0), + ext->showed_date.month == 1 ? 12 : ext->showed_date.month - 1, + day_cnt)) { + final_style = ext->style_highlighted_days; + } else if(draw_state == DAY_DRAW_ACT_MONTH && + is_highlighted(calendar, ext->showed_date.year, + ext->showed_date.month, + day_cnt)) { + final_style = ext->style_highlighted_days; + } else if(draw_state == DAY_DRAW_NEXT_MONTH && + is_highlighted(calendar, ext->showed_date.year + (ext->showed_date.month == 12 ? 1 : 0), + ext->showed_date.month == 12 ? 1 : ext->showed_date.month + 1, + day_cnt)) { + final_style = ext->style_highlighted_days; + } else if(month_of_today_shown && day_cnt == ext->today.day && draw_state == DAY_DRAW_ACT_MONTH) final_style = ext->style_today_box; + else if(in_week_box && draw_state == DAY_DRAW_ACT_MONTH) final_style = ext->style_week_box; + else final_style = act_style; + + /*Write the day's number*/ + lv_math_num_to_str(day_cnt, buf); + lv_draw_label(&label_area, mask, final_style, opa_scale, buf, LV_TXT_FLAG_CENTER, NULL); + + /*Go to the next day*/ + day_cnt ++; + + } + + /*Got to the next weeks row*/ + label_area.y1 += vert_space + lv_font_get_height(style_bg->text.font); + label_area.y2 += vert_space + lv_font_get_height(style_bg->text.font); + } +} + +/** + * Check weather a date is highlighted or not + * @param calendar pointer to a calendar object + * @param year a year + * @param month a month [1..12] + * @param day a day [1..31] + * @return true: highlighted + */ +static bool is_highlighted(lv_obj_t * calendar, int32_t year, int32_t month, int32_t day) +{ + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + + if(ext->highlighted_dates == NULL || ext->highlighted_dates_num == 0) return false; + + uint32_t i; + for(i = 0; i < ext->highlighted_dates_num; i++) { + if(ext->highlighted_dates[i].year == year && + ext->highlighted_dates[i].month == month && + ext->highlighted_dates[i].day == day) { + return true; + } + } + + return false; +} + +/** + * Get the day name + * @param calendar pointer to a calendar object + * @param day a day in [0..6] + * @return + */ +static const char * get_day_name(lv_obj_t * calendar, uint8_t day) +{ + + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + if(ext->day_names) return ext->day_names[day]; + else return day_name[day]; +} + +/** + * Get the month name + * @param calendar pointer to a calendar object + * @param month a month. The range is basically [1..12] but [-11..1] is also supported to handle previous year + * @return + */ +static const char * get_month_name(lv_obj_t * calendar, int32_t month) +{ + month --; /*Range of months id [1..12] but range of indexes is [0..11]*/ + if(month < 0) month = 12 + month; + + lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); + if(ext->month_names) return ext->month_names[month]; + else return month_name[month]; +} + +/** + * Get the number of days in a month + * @param year a year + * @param month a month. The range is basically [1..12] but [-11..1] is also supported to handle previous year + * @return [28..31] + */ +static uint8_t get_month_length(int32_t year, int32_t month) +{ + month --; /*Range of months id [1..12] but range of indexes is [0..11]*/ + if(month < 0) { + year--; /*Already in the previous year (won't be less then -12 to skip a whole year)*/ + month = 12 + month; /*`month` is negative, the result will be < 12*/ + } + if(month >= 12) { + year ++; + month -= 12; + } + + /*month == 1 is february*/ + return (month == 1) ? (28 + is_leap_year(year)) : 31 - month % 7 % 2; + + +} + +/** + * Tells whether a year is leap year or not + * @param year a year + * @return 0: not leap year; 1: leap year + */ +static uint8_t is_leap_year(uint32_t year) +{ + return (year % 4) || ((year % 100 == 0) && (year % 400)) ? 0 : 1; +} + +/** + * Get the day of the week + * @param year a year + * @param month a month + * @param day a day + * @return [0..6] which means [Sun..Sat] + */ +static uint8_t get_day_of_week(uint32_t year, uint32_t month, uint32_t day) +{ + uint32_t a = month < 3 ? 1 : 0; + uint32_t b = year - a; + + uint32_t day_of_week = (day + (31 * (month - 2 + 12 * a) / 12) + + b + (b / 4) - (b / 100) + (b / 400)) % 7; + + return day_of_week; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.h new file mode 100644 index 0000000..e573ae5 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_calendar.h @@ -0,0 +1,246 @@ +/** + * @file lv_calendar.h + * + */ + +#ifndef LV_CALENDAR_H +#define LV_CALENDAR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_CALENDAR != 0 + +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + uint16_t year; + int8_t month; + int8_t day; +} lv_calendar_date_t; + +enum +{ + LV_CALENDAR_ACTION_CLICK, + LV_CALENDAR_ACTION_PR, + LV_CALENDAR_ACTION_LONG_PR, + LV_CALENDAR_ACTION_LONG_PR_REPEAT, + LV_CALENDAR_ACTION_NUM, +}; +typedef uint8_t lv_calendar_action_t; + +/*Data of calendar*/ +typedef struct { + /*None*/ /*Ext. of ancestor*/ + /*New data for this type */ + lv_calendar_date_t today; /*Date of today*/ + lv_calendar_date_t showed_date; /*Currently visible month (day is ignored)*/ + lv_calendar_date_t * highlighted_dates; /*Apply different style on these days (pointer to an array defined by the user)*/ + uint8_t highlighted_dates_num; /*Number of elements in `highlighted_days`*/ + int8_t btn_pressing; /*-1: prev month pressing, +1 next month pressing on the header*/ + lv_calendar_date_t pressed_date; + const char ** day_names; /*Pointer to an array with the name of the days (NULL: use default names)*/ + const char ** month_names; /*Pointer to an array with the name of the month (NULL. use default names)*/ + lv_action_t actions[LV_CALENDAR_ACTION_NUM]; + + /*Styles*/ + lv_style_t * style_header; + lv_style_t * style_header_pr; + lv_style_t * style_day_names; + lv_style_t * style_highlighted_days; + lv_style_t * style_inactive_days; + lv_style_t * style_week_box; + lv_style_t * style_today_box; +} lv_calendar_ext_t; + +/*Styles*/ +enum { + LV_CALENDAR_STYLE_BG, /*Also the style of the "normal" date numbers*/ + LV_CALENDAR_STYLE_HEADER, + LV_CALENDAR_STYLE_HEADER_PR, + LV_CALENDAR_STYLE_DAY_NAMES, + LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS, + LV_CALENDAR_STYLE_INACTIVE_DAYS, + LV_CALENDAR_STYLE_WEEK_BOX, + LV_CALENDAR_STYLE_TODAY_BOX, +}; +typedef uint8_t lv_calendar_style_t; + + + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a calendar objects + * @param par pointer to an object, it will be the parent of the new calendar + * @param copy pointer to a calendar object, if not NULL then the new object will be copied from it + * @return pointer to the created calendar + */ +lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + + +/*===================== + * Setter functions + *====================*/ +/** + * Set a function to call when a calendar event happens + * @param calendar pointer to a calendar object + * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) + */ +void lv_calendar_set_action(lv_obj_t * calendar, lv_calendar_action_t type, lv_action_t action); + +/** + * Set the today's date + * @param calendar pointer to a calendar object + * @param today pointer to an `lv_calendar_date_t` variable containing the date of today. The value will be saved it can be local variable too. + */ +void lv_calendar_set_today_date(lv_obj_t * calendar, lv_calendar_date_t * today); + +/** + * Set the currently showed + * @param calendar pointer to a calendar object + * @param showed pointer to an `lv_calendar_date_t` variable containing the date to show. The value will be saved it can be local variable too. + */ +void lv_calendar_set_showed_date(lv_obj_t * calendar, lv_calendar_date_t * showed); + +/** + * Set the the highlighted dates + * @param calendar pointer to a calendar object + * @param highlighted pointer to an `lv_calendar_date_t` array containing the dates. ONLY A POINTER WILL BE SAVED! CAN'T BE LOCAL ARRAY. + * @param date_num number of dates in the array + */ +void lv_calendar_set_highlighted_dates(lv_obj_t * calendar, lv_calendar_date_t * highlighted, uint16_t date_num); + + +/** + * Set the name of the days + * @param calendar pointer to a calendar object + * @param day_names pointer to an array with the names. E.g. `const char * days[7] = {"Sun", "Mon", ...}` + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + */ +void lv_calendar_set_day_names(lv_obj_t * calendar, const char ** day_names); + +/** + * Set the name of the month + * @param calendar pointer to a calendar object + * @param day_names pointer to an array with the names. E.g. `const char * days[12] = {"Jan", "Feb", ...}` + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + */ +void lv_calendar_set_month_names(lv_obj_t * calendar, const char ** day_names); + +/** + * Set a style of a calendar. + * @param calendar pointer to calendar object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_calendar_set_style(lv_obj_t * calendar, lv_calendar_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ +/** + * Get the action of a calendar + * @param calendar pointer to a calendar object + * @return pointer to the action function + */ +lv_action_t lv_calendar_get_action(const lv_obj_t * calendar, lv_calendar_action_t type); + +/** + * Get the today's date + * @param calendar pointer to a calendar object + * @return return pointer to an `lv_calendar_date_t` variable containing the date of today. + */ +lv_calendar_date_t * lv_calendar_get_today_date(const lv_obj_t * calendar); + +/** + * Get the currently showed + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` variable containing the date is being shown. + */ +lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar); + +/** + * Get the the pressed date. + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` variable containing the pressed date. + */ +lv_calendar_date_t * lv_calendar_get_pressed_date(const lv_obj_t * calendar); + +/** + * Get the the highlighted dates + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` array containing the dates. + */ +lv_calendar_date_t * lv_calendar_get_highlighted_dates(const lv_obj_t * calendar); + +/** + * Get the number of the highlighted dates + * @param calendar pointer to a calendar object + * @return number of highlighted days + */ +uint16_t lv_calendar_get_highlighted_dates_num(const lv_obj_t * calendar); + + +/** + * Get the name of the days + * @param calendar pointer to a calendar object + * @return pointer to the array of day names + */ +const char ** lv_calendar_get_day_names(const lv_obj_t * calendar); + +/** + * Get the name of the month + * @param calendar pointer to a calendar object + * @return pointer to the array of month names + */ +const char ** lv_calendar_get_month_names(const lv_obj_t * calendar); + +/** + * Get style of a calendar. + * @param calendar pointer to calendar object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_calendar_get_style(const lv_obj_t * calendar, lv_calendar_style_t type); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_CALENDAR*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_CALENDAR_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.c new file mode 100644 index 0000000..b28f238 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.c @@ -0,0 +1,593 @@ +/** + * @file lv_canvas.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_canvas.h" +#if USE_LV_CANVAS != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a canvas object + * @param par pointer to an object, it will be the parent of the new canvas + * @param copy pointer to a canvas object, if not NULL then the new object will be copied from it + * @return pointer to the created canvas + */ +lv_obj_t * lv_canvas_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("canvas create started"); + + /*Create the ancestor of canvas*/ + lv_obj_t * new_canvas = lv_img_create(par, copy); + lv_mem_assert(new_canvas); + if(new_canvas == NULL) return NULL; + + /*Allocate the canvas type specific extended data*/ + lv_canvas_ext_t * ext = lv_obj_allocate_ext_attr(new_canvas, sizeof(lv_canvas_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_canvas); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_canvas); + + /*Initialize the allocated 'ext' */ + ext->dsc.header.always_zero = 0; + ext->dsc.header.cf = LV_IMG_CF_TRUE_COLOR; + ext->dsc.header.h = 0; + ext->dsc.header.w = 0; + ext->dsc.data_size = 0; + ext->dsc.data = NULL; + + lv_img_set_src(new_canvas, &ext->dsc); + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_canvas, lv_canvas_signal); + + /*Init the new canvas canvas*/ + if(copy == NULL) { + + } + /*Copy an existing canvas*/ + else { + //lv_canvas_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_canvas); + } + + LV_LOG_INFO("canvas created"); + + return new_canvas; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a buffer for the canvas. + * @param buf a buffer where the content of the canvas will be. + * The required size is (lv_img_color_format_get_px_size(cf) * w * h) / 8) + * It can be allocated with `lv_mem_alloc()` or + * it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or + * it can be an address in RAM or external SRAM + * @param canvas pointer to a canvas object + * @param w width of the canvas + * @param h height of the canvas + * @param cf color format. The following formats are supported: + * LV_IMG_CF_TRUE_COLOR, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, LV_IMG_CF_INDEXES_1/2/4/8BIT + * + */ +void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf) +{ + lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas); + + ext->dsc.header.cf = cf; + ext->dsc.header.w = w; + ext->dsc.header.h = h; + ext->dsc.data = buf; + ext->dsc.data_size = (lv_img_color_format_get_px_size(cf) * w * h) / 8; + + lv_img_set_src(canvas, &ext->dsc); +} +/** + * Set the color of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param c color of the point + */ +void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c) +{ + + lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas); + if(x >= ext->dsc.header.w || y >= ext->dsc.header.h) { + LV_LOG_WARN("lv_canvas_set_px: x or y out of the canvas"); + return; + } + + uint8_t * buf_u8 = (uint8_t *) ext->dsc.data; + + if(ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR || + ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) + { + uint32_t px = ext->dsc.header.w * y * sizeof(lv_color_t) + x * sizeof(lv_color_t); + + memcpy(&buf_u8[px], &c, sizeof(lv_color_t)); + } + else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_1BIT) { + buf_u8 += 4 * 2; + uint8_t bit = x & 0x7; + x = x >> 3; + + uint32_t px = (ext->dsc.header.w >> 3) * y + x; + buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit)); + buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit)); + } + else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_2BIT) { + buf_u8 += 4 * 4; + uint8_t bit = (x & 0x3) * 2; + x = x >> 2; + + uint32_t px = (ext->dsc.header.w >> 2) * y + x; + + buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit)); + buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit)); + } + else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_4BIT) { + buf_u8 += 4 * 16; + uint8_t bit = (x & 0x1) * 4; + x = x >> 1; + + uint32_t px = (ext->dsc.header.w >> 1) * y + x; + + buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit)); + buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit)); + } + else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_8BIT) { + buf_u8 += 4 * 256; + uint32_t px = ext->dsc.header.w * y + x; + buf_u8[px] = c.full; + } +} + +/** + * Set a style of a canvas. + * @param canvas pointer to canvas object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, lv_style_t * style) +{ + switch(type) { + case LV_CANVAS_STYLE_MAIN: + lv_img_set_style(canvas, style); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the color of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @return color of the point + */ +lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y) +{ + lv_color_t p_color = LV_COLOR_BLACK; + lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas); + if(x >= ext->dsc.header.w || y >= ext->dsc.header.h) { + LV_LOG_WARN("lv_canvas_get_px: x or y out of the canvas"); + return p_color; + } + + uint8_t * buf_u8 = (uint8_t *) ext->dsc.data; + + if(ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR || + ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) + { + uint32_t px = ext->dsc.header.w * y * sizeof(lv_color_t) + x * sizeof(lv_color_t); + memcpy(&p_color, &buf_u8[px], sizeof(lv_color_t)); + } + else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_1BIT) { + buf_u8 += 4 * 2; + uint8_t bit = x & 0x7; + x = x >> 3; + + uint32_t px = (ext->dsc.header.w >> 3) * y + x; + p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit); + } + else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_2BIT) { + buf_u8 += 4 * 4; + uint8_t bit = (x & 0x3) * 2; + x = x >> 2; + + uint32_t px = (ext->dsc.header.w >> 2) * y + x; + p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit); + } + else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_4BIT) { + buf_u8 += 4 * 16; + uint8_t bit = (x & 0x1) * 4; + x = x >> 1; + + uint32_t px = (ext->dsc.header.w >> 1) * y + x; + p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit); + } + else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_8BIT) { + buf_u8 += 4 * 256; + uint32_t px = ext->dsc.header.w * y + x; + p_color.full = buf_u8[px]; + } + return p_color; +} + +/** + * Get style of a canvas. + * @param canvas pointer to canvas object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type) +{ + // lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas); + lv_style_t * style = NULL; + + switch(type) { + case LV_CANVAS_STYLE_MAIN: + style = lv_img_get_style(canvas); + break; + default: + style = NULL; + } + + return style; +} + +/*===================== + * Other functions + *====================*/ + +/** + * Copy a buffer to the canvas + * @param canvas pointer to a canvas object + * @param to_copy buffer to copy. The color format has to match with the canvas's buffer color format + * @param w width of the buffer to copy + * @param h height of the buffer to copy + * @param x left side of the destination position + * @param y top side of the destination position + */ +void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y) +{ + lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas); + if(x + w >= ext->dsc.header.w || y + h >= ext->dsc.header.h) { + LV_LOG_WARN("lv_canvas_copy_buf: x or y out of the canvas"); + return; + } + + uint32_t px_size = lv_img_color_format_get_px_size(ext->dsc.header.cf) >> 3; + uint32_t px = ext->dsc.header.w * y * px_size + x * px_size; + uint8_t * to_copy8 = (uint8_t *) to_copy; + lv_coord_t i; + for(i = 0; i < h; i++) { + memcpy((void*)&ext->dsc.data[px], to_copy8, w * px_size); + px += ext->dsc.header.w * px_size; + to_copy8 += w * px_size; + } +} + +/** + * Multiply a buffer with the canvas + * @param canvas pointer to a canvas object + * @param to_copy buffer to copy (multiply). LV_IMG_CF_TRUE_COLOR_ALPHA is not supported + * @param w width of the buffer to copy + * @param h height of the buffer to copy + * @param x left side of the destination position + * @param y top side of the destination position + */ +void lv_canvas_mult_buf(lv_obj_t * canvas, void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y) +{ + lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas); + if(x + w >= ext->dsc.header.w || y + h >= ext->dsc.header.h) { + LV_LOG_WARN("lv_canvas_mult_buf: x or y out of the canvas"); + return; + } + + if(ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { + LV_LOG_WARN("lv_canvas_mult_buf: LV_IMG_CF_TRUE_COLOR_ALPHA is not supported"); + return; + } + + uint32_t px_size = lv_img_color_format_get_px_size(ext->dsc.header.cf) >> 3; + uint32_t px = ext->dsc.header.w * y * px_size + x * px_size; + lv_color_t * copy_buf_color = (lv_color_t *) to_copy; + lv_color_t * canvas_buf_color = (lv_color_t *) &ext->dsc.data[px]; + + lv_coord_t i; + lv_coord_t j; + for(i = 0; i < h; i++) { + for(j = 0; j < w; j++) { +#if LV_COLOR_DEPTH == 32 + canvas_buf_color[j].red = (uint16_t) ((uint16_t) canvas_buf_color[j].red * copy_buf_color[j].red) >> 8; + canvas_buf_color[j].green = (uint16_t) ((uint16_t) canvas_buf_color[j].green * copy_buf_color[j].green) >> 8; + canvas_buf_color[j].blue = (uint16_t) ((uint16_t) canvas_buf_color[j].blue * copy_buf_color[j].blue) >> 8; +#elif LV_COLOR_DEPTH == 16 + + canvas_buf_color[j].red = (uint16_t) ((uint16_t) canvas_buf_color[j].red * copy_buf_color[j].red) >> 5; + canvas_buf_color[j].blue = (uint16_t) ((uint16_t) canvas_buf_color[j].blue * copy_buf_color[j].blue) >> 5; +# if LV_COLOR_16_SWAP == 0 + canvas_buf_color[j].green = (uint16_t) ((uint16_t) canvas_buf_color[j].green * copy_buf_color[j].green) >> 6; +# else + uint8_t green_canvas = (canvas_buf_color[j].green_h << 3) + (canvas_buf_color[j].green_l); + uint8_t green_buf = (copy_buf_color[j].green_h << 3) + (copy_buf_color[j].green_l); + uint8_t green_res = (uint16_t)((uint16_t)green_canvas * green_buf) >> 6; + canvas_buf_color[j].green_h = (green_res >> 3) & 0x07; + canvas_buf_color[j].green_l = green_res & 0x07; +# endif /*LV_COLOR_16_SWAP*/ + +#elif LV_COLOR_DEPTH == 8 + canvas_buf_color[j].red = (uint16_t) ((uint16_t) canvas_buf_color[j].red * copy_buf_color[j].red) >> 3; + canvas_buf_color[j].green = (uint16_t) ((uint16_t) canvas_buf_color[j].green * copy_buf_color[j].green) >> 3; + canvas_buf_color[j].blue = (uint16_t) ((uint16_t) canvas_buf_color[j].blue * copy_buf_color[j].blue) >> 2; +#endif + } + copy_buf_color += w; + canvas_buf_color += ext->dsc.header.w; + } +} + +/** + * Draw circle function of the canvas + * @param canvas pointer to a canvas object + * @param x0 x coordinate of the circle + * @param y0 y coordinate of the circle + * @param radius radius of the circle + * @param color border color of the circle + */ +void lv_canvas_draw_circle(lv_obj_t * canvas, lv_coord_t x0, lv_coord_t y0, lv_coord_t radius, lv_color_t color) +{ + int x = radius; + int y = 0; + int err = 0; + + while (x >= y) + { + lv_canvas_set_px(canvas, x0 + x, y0 + y, color); + lv_canvas_set_px(canvas, x0 + y, y0 + x, color); + lv_canvas_set_px(canvas, x0 - y, y0 + x, color); + lv_canvas_set_px(canvas, x0 - x, y0 + y, color); + lv_canvas_set_px(canvas, x0 - x, y0 - y, color); + lv_canvas_set_px(canvas, x0 - y, y0 - x, color); + lv_canvas_set_px(canvas, x0 + y, y0 - x, color); + lv_canvas_set_px(canvas, x0 + x, y0 - y, color); + + if (err <= 0) + { + y += 1; + err += 2*y + 1; + } + + if (err > 0) + { + x -= 1; + err -= 2*x + 1; + } + } +} + +/** + * Draw line function of the canvas + * @param canvas pointer to a canvas object + * @param point1 start point of the line + * @param point2 end point of the line + * @param color color of the line + * + * NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c. + */ +/* + * NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c. + */ +void lv_canvas_draw_line(lv_obj_t * canvas, lv_point_t point1, lv_point_t point2, lv_color_t color) +{ + lv_coord_t x0, y0, x1, y1; + + x0 = point1.x; + y0 = point1.y; + x1 = point2.x; + y1 = point2.y; + + int dx = abs(x1-x0), sx = x0dy ? dx : -dy)/2, e2; + + for(;;){ + lv_canvas_set_px(canvas, x0, y0, color); + + if (x0==x1 && y0==y1) break; + e2 = err; + if (e2 >-dx) { err -= dy; x0 += sx; } + if (e2 < dy) { err += dx; y0 += sy; } + } +} + +/** + * Draw triangle function of the canvas + * @param canvas pointer to a canvas object + * @param points edge points of the triangle + * @param color line color of the triangle + */ +void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color) +{ + lv_canvas_draw_polygon(canvas, points, 3, color); +} + +/** + * Draw rectangle function of the canvas + * @param canvas pointer to a canvas object + * @param points edge points of the rectangle + * @param color line color of the rectangle + */ +void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color) +{ + lv_canvas_draw_polygon(canvas, points, 4, color); +} + +/** + * Draw polygon function of the canvas + * @param canvas pointer to a canvas object + * @param points edge points of the polygon + * @param size edge count of the polygon + * @param color line color of the polygon + */ +void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color) +{ + uint8_t i; + + for(i=0; i < (size - 1); i++) { + lv_canvas_draw_line(canvas, points[i], points[i + 1], color); + } + + lv_canvas_draw_line(canvas, points[size - 1], points[0], color); +} + +/** + * Fill polygon function of the canvas + * @param canvas pointer to a canvas object + * @param points edge points of the polygon + * @param size edge count of the polygon + * @param boundary_color line color of the polygon + * @param fill_color fill color of the polygon + */ +void lv_canvas_fill_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t boundary_color, lv_color_t fill_color) +{ + uint32_t x = 0, y = 0; + uint8_t i; + + for(i=0; itype[i] == NULL) break; + } + buf->type[i] = "lv_canvas"; + } + + return res; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.h new file mode 100644 index 0000000..74e1134 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_canvas.h @@ -0,0 +1,229 @@ +/** + * @file lv_canvas.h + * + */ + +#ifndef LV_CANVAS_H +#define LV_CANVAS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_CANVAS != 0 + +#include "../lv_core/lv_obj.h" +#include "../lv_objx/lv_img.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of canvas*/ +typedef struct { + lv_img_ext_t img; /*Ext. of ancestor*/ + /*New data for this type */ + lv_img_dsc_t dsc; +} lv_canvas_ext_t; + + +/*Styles*/ +enum { + LV_CANVAS_STYLE_MAIN, +}; +typedef uint8_t lv_canvas_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a canvas object + * @param par pointer to an object, it will be the parent of the new canvas + * @param copy pointer to a canvas object, if not NULL then the new object will be copied from it + * @return pointer to the created canvas + */ +lv_obj_t * lv_canvas_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a buffer for the canvas. + * @param buf a buffer where the content of the canvas will be. + * The required size is (lv_img_color_format_get_px_size(cf) * w * h) / 8) + * It can be allocated with `lv_mem_alloc()` or + * it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or + * it can be an address in RAM or external SRAM + * @param canvas pointer to a canvas object + * @param w width of the canvas + * @param h height of the canvas + * @param cf color format. The following formats are supported: + * LV_IMG_CF_TRUE_COLOR, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, LV_IMG_CF_INDEXES_1/2/4/8BIT + */ +void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); + +/** + * Set the color of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param c color of the point + */ +void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c); + +/** + * Set a style of a canvas. + * @param canvas pointer to canvas object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, lv_style_t * style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the color of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @return color of the point + */ +lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y); + +/** + * Get style of a canvas. + * @param canvas pointer to canvas object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type); + +/*===================== + * Other functions + *====================*/ + +/** + * Copy a buffer to the canvas + * @param canvas pointer to a canvas object + * @param to_copy buffer to copy. The color format has to match with the canvas's buffer color format + * @param w width of the buffer to copy + * @param h height of the buffer to copy + * @param x left side of the destination position + * @param y top side of the destination position + */ +void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y); + +/** + * Multiply a buffer with the canvas + * @param canvas pointer to a canvas object + * @param to_copy buffer to copy (multiply). LV_IMG_CF_TRUE_COLOR_ALPHA is not supported + * @param w width of the buffer to copy + * @param h height of the buffer to copy + * @param x left side of the destination position + * @param y top side of the destination position + */ +void lv_canvas_mult_buf(lv_obj_t * canvas, void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y); + +/** + * Draw circle function of the canvas + * @param canvas pointer to a canvas object + * @param x0 x coordinate of the circle + * @param y0 y coordinate of the circle + * @param radius radius of the circle + * @param color border color of the circle + */ +void lv_canvas_draw_circle(lv_obj_t * canvas, lv_coord_t x0, lv_coord_t y0, lv_coord_t radius, lv_color_t color); + +/** + * Draw line function of the canvas + * @param canvas pointer to a canvas object + * @param point1 start point of the line + * @param point2 end point of the line + * @param color color of the line + * + * NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c. + */ +void lv_canvas_draw_line(lv_obj_t * canvas, lv_point_t point1, lv_point_t point2, lv_color_t color); + +/** + * Draw triangle function of the canvas + * @param canvas pointer to a canvas object + * @param points edge points of the triangle + * @param color line color of the triangle + */ +void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color); + +/** + * Draw rectangle function of the canvas + * @param canvas pointer to a canvas object + * @param points edge points of the rectangle + * @param color line color of the rectangle + */ +void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color); + +/** + * Draw polygon function of the canvas + * @param canvas pointer to a canvas object + * @param points edge points of the polygon + * @param size edge count of the polygon + * @param color line color of the polygon + */ +void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color); + +/** + * Fill polygon function of the canvas + * @param canvas pointer to a canvas object + * @param points edge points of the polygon + * @param size edge count of the polygon + * @param boundary_color line color of the polygon + * @param fill_color fill color of the polygon + */ +void lv_canvas_fill_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t boundary_color, lv_color_t fill_color); +/** + * Boundary fill function of the canvas + * @param canvas pointer to a canvas object + * @param x x coordinate of the start position (seed) + * @param y y coordinate of the start position (seed) + * @param boundary_color edge/boundary color of the area + * @param fill_color fill color of the area + */ +void lv_canvas_boundary_fill4(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t boundary_color, lv_color_t fill_color); + +/** + * Flood fill function of the canvas + * @param canvas pointer to a canvas object + * @param x x coordinate of the start position (seed) + * @param y y coordinate of the start position (seed) + * @param fill_color fill color of the area + * @param bg_color background color of the area + */ +void lv_canvas_flood_fill(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t fill_color, lv_color_t bg_color); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_CANVAS*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_CANVAS_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.c new file mode 100644 index 0000000..6b0277e --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.c @@ -0,0 +1,347 @@ +/** + * @file lv_cb.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_cb.h" +#if USE_LV_CB != 0 + +#include "../lv_core/lv_group.h" +#include "../lv_themes/lv_theme.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_cb_design(lv_obj_t * cb, const lv_area_t * mask, lv_design_mode_t mode); +static bool lv_bullet_design(lv_obj_t * bullet, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_design_func_t ancestor_bg_design; +static lv_design_func_t ancestor_bullet_design; +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a check box objects + * @param par pointer to an object, it will be the parent of the new check box + * @param copy pointer to a check box object, if not NULL then the new object will be copied from it + * @return pointer to the created check box + */ +lv_obj_t * lv_cb_create(lv_obj_t * par, const lv_obj_t * copy) +{ + + LV_LOG_TRACE("check box create started"); + + /*Create the ancestor basic object*/ + lv_obj_t * new_cb = lv_btn_create(par, copy); + lv_mem_assert(new_cb); + if(new_cb == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_cb); + if(ancestor_bg_design == NULL) ancestor_bg_design = lv_obj_get_design_func(new_cb); + + lv_cb_ext_t * ext = lv_obj_allocate_ext_attr(new_cb, sizeof(lv_cb_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->bullet = NULL; + ext->label = NULL; + + lv_obj_set_signal_func(new_cb, lv_cb_signal); + lv_obj_set_design_func(new_cb, lv_cb_design); + + /*Init the new checkbox object*/ + if(copy == NULL) { + ext->bullet = lv_btn_create(new_cb, NULL); + if(ancestor_bullet_design == NULL) ancestor_bullet_design = lv_obj_get_design_func(ext->bullet); + lv_obj_set_click(ext->bullet, false); + + ext->label = lv_label_create(new_cb, NULL); + + lv_cb_set_text(new_cb, "Check box"); + lv_btn_set_layout(new_cb, LV_LAYOUT_ROW_M); + lv_btn_set_fit(new_cb, true, true); + lv_btn_set_toggle(new_cb, true); + lv_obj_set_protect(new_cb, LV_PROTECT_PRESS_LOST); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_cb_set_style(new_cb, LV_CB_STYLE_BG, th->cb.bg); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_REL, th->cb.box.rel); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_PR, th->cb.box.pr); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_TGL_REL, th->cb.box.tgl_rel); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_TGL_PR, th->cb.box.tgl_pr); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_INA, th->cb.box.ina); + } else { + lv_cb_set_style(new_cb, LV_CB_STYLE_BG, &lv_style_transp); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_REL, &lv_style_pretty); + } + } else { + lv_cb_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->bullet = lv_btn_create(new_cb, copy_ext->bullet); + ext->label = lv_label_create(new_cb, copy_ext->label); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_cb); + } + + lv_obj_set_design_func(ext->bullet, lv_bullet_design); + + + LV_LOG_INFO("check box created"); + + return new_cb; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of a check box + * @param cb pointer to a check box + * @param txt the text of the check box + */ +void lv_cb_set_text(lv_obj_t * cb, const char * txt) +{ + lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb); + lv_label_set_text(ext->label, txt); +} + +/** + * Set a style of a check box + * @param cb pointer to check box object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_cb_set_style(lv_obj_t * cb, lv_cb_style_t type, lv_style_t * style) +{ + lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb); + + switch(type) { + case LV_CB_STYLE_BG: + lv_btn_set_style(cb, LV_BTN_STYLE_REL, style); + lv_btn_set_style(cb, LV_BTN_STYLE_PR, style); + lv_btn_set_style(cb, LV_BTN_STYLE_TGL_REL, style); + lv_btn_set_style(cb, LV_BTN_STYLE_TGL_PR, style); + lv_btn_set_style(cb, LV_BTN_STYLE_INA, style); + break; + case LV_CB_STYLE_BOX_REL: + lv_btn_set_style(ext->bullet, LV_BTN_STYLE_REL, style); + break; + case LV_CB_STYLE_BOX_PR: + lv_btn_set_style(ext->bullet, LV_BTN_STYLE_PR, style); + break; + case LV_CB_STYLE_BOX_TGL_REL: + lv_btn_set_style(ext->bullet, LV_BTN_STYLE_TGL_REL, style); + break; + case LV_CB_STYLE_BOX_TGL_PR: + lv_btn_set_style(ext->bullet, LV_BTN_STYLE_TGL_PR, style); + break; + case LV_CB_STYLE_BOX_INA: + lv_btn_set_style(ext->bullet, LV_BTN_STYLE_INA, style); + break; + } +} + + + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a check box + * @param cb pointer to check box object + * @return pointer to the text of the check box + */ +const char * lv_cb_get_text(const lv_obj_t * cb) +{ + lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb); + return lv_label_get_text(ext->label); +} + + +/** + * Get a style of a button + * @param cb pointer to check box object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_cb_get_style(const lv_obj_t * cb, lv_cb_style_t type) +{ + lv_style_t * style = NULL; + lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb); + + switch(type) { + case LV_CB_STYLE_BOX_REL: + style = lv_btn_get_style(ext->bullet, LV_BTN_STYLE_REL); + break; + case LV_CB_STYLE_BOX_PR: + style = lv_btn_get_style(ext->bullet, LV_BTN_STYLE_PR); + break; + case LV_CB_STYLE_BOX_TGL_REL: + style = lv_btn_get_style(ext->bullet, LV_BTN_STYLE_TGL_REL); + break; + case LV_CB_STYLE_BOX_TGL_PR: + style = lv_btn_get_style(ext->bullet, LV_BTN_STYLE_TGL_PR); + break; + case LV_CB_STYLE_BOX_INA: + style = lv_btn_get_style(ext->bullet, LV_BTN_STYLE_INA); + break; + default: + style = NULL; + break; + } + + return style; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the check boxes + * @param cb pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_cb_design(lv_obj_t * cb, const lv_area_t * mask, lv_design_mode_t mode) +{ + bool result = true; + + if(mode == LV_DESIGN_COVER_CHK) { + /*Return false if the object is not covers the mask_p area*/ + result = ancestor_bg_design(cb, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN || mode == LV_DESIGN_DRAW_POST) { + lv_cb_ext_t * cb_ext = lv_obj_get_ext_attr(cb); + lv_btn_ext_t * bullet_ext = lv_obj_get_ext_attr(cb_ext->bullet); + + /*Be sure the state of the bullet is the same as the parent button*/ + bullet_ext->state = cb_ext->bg_btn.state; + + result = ancestor_bg_design(cb, mask, mode); + + } else { + result = ancestor_bg_design(cb, mask, mode); + } + + return result; +} + +/** + * Handle the drawing related tasks of the check boxes + * @param bullet pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_bullet_design(lv_obj_t * bullet, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + return ancestor_bullet_design(bullet, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { +#if USE_LV_GROUP + /* If the check box is the active in a group and + * the background is not visible (transparent or empty) + * then activate the style of the bullet*/ + lv_style_t * style_ori = lv_obj_get_style(bullet); + lv_obj_t * bg = lv_obj_get_parent(bullet); + lv_style_t * style_page = lv_obj_get_style(bg); + lv_group_t * g = lv_obj_get_group(bg); + if(style_page->body.empty != 0 || style_page->body.opa == LV_OPA_TRANSP) { /*Background is visible?*/ + if(lv_group_get_focused(g) == bg) { + lv_style_t * style_mod; + style_mod = lv_group_mod_style(g, style_ori); + bullet->style_p = style_mod; /*Temporally change the style to the activated */ + } + } +#endif + ancestor_bullet_design(bullet, mask, mode); + +#if USE_LV_GROUP + bullet->style_p = style_ori; /*Revert the style*/ +#endif + } else if(mode == LV_DESIGN_DRAW_POST) { + ancestor_bullet_design(bullet, mask, mode); + } + + return true; +} + + +/** + * Signal function of the check box + * @param cb pointer to a check box object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(cb, sign, param); + if(res != LV_RES_OK) return res; + + lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb); + + if(sign == LV_SIGNAL_STYLE_CHG) { + lv_style_t * label_style = lv_label_get_style(ext->label); + lv_obj_set_size(ext->bullet, lv_font_get_height(label_style->text.font), lv_font_get_height(label_style->text.font)); + lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); + } else if(sign == LV_SIGNAL_PRESSED || + sign == LV_SIGNAL_RELEASED || + sign == LV_SIGNAL_PRESS_LOST) { + lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); + } else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char *)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN || + c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP || + c == LV_GROUP_KEY_ENTER) { + lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); + } + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_cb"; + } + + return res; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.h new file mode 100644 index 0000000..b587733 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cb.h @@ -0,0 +1,174 @@ +/** + * @file lv_cb.h + * + */ + +#ifndef LV_CB_H +#define LV_CB_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_CB != 0 + +/*Testing of dependencies*/ +#if USE_LV_BTN == 0 +#error "lv_cb: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " +#endif + +#if USE_LV_LABEL == 0 +#error "lv_cb: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_btn.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of check box*/ +typedef struct +{ + lv_btn_ext_t bg_btn; /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t * bullet; /*Pointer to button*/ + lv_obj_t * label; /*Pointer to label*/ +} lv_cb_ext_t; + +enum { + LV_CB_STYLE_BG, + LV_CB_STYLE_BOX_REL, + LV_CB_STYLE_BOX_PR, + LV_CB_STYLE_BOX_TGL_REL, + LV_CB_STYLE_BOX_TGL_PR, + LV_CB_STYLE_BOX_INA, +}; +typedef uint8_t lv_cb_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a check box objects + * @param par pointer to an object, it will be the parent of the new check box + * @param copy pointer to a check box object, if not NULL then the new object will be copied from it + * @return pointer to the created check box + */ +lv_obj_t * lv_cb_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of a check box + * @param cb pointer to a check box + * @param txt the text of the check box + */ +void lv_cb_set_text(lv_obj_t * cb, const char * txt); + +/** + * Set the state of the check box + * @param cb pointer to a check box object + * @param checked true: make the check box checked; false: make it unchecked + */ +static inline void lv_cb_set_checked(lv_obj_t * cb, bool checked) +{ + lv_btn_set_state(cb, checked ? LV_BTN_STATE_TGL_REL : LV_BTN_STATE_REL); +} + +/** + * Make the check box inactive (disabled) + * @param cb pointer to a check box object + */ +static inline void lv_cb_set_inactive(lv_obj_t * cb) +{ + lv_btn_set_state(cb, LV_BTN_STATE_INA); +} + +/** + * Set a function to call when the check box is clicked + * @param cb pointer to a check box object + */ +static inline void lv_cb_set_action(lv_obj_t * cb, lv_action_t action) +{ + lv_btn_set_action(cb, LV_BTN_ACTION_CLICK, action); +} + + +/** + * Set a style of a check box + * @param cb pointer to check box object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_cb_set_style(lv_obj_t * cb, lv_cb_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a check box + * @param cb pointer to check box object + * @return pointer to the text of the check box + */ +const char * lv_cb_get_text(const lv_obj_t * cb); + +/** + * Get the current state of the check box + * @param cb pointer to a check box object + * @return true: checked; false: not checked + */ +static inline bool lv_cb_is_checked(const lv_obj_t * cb) +{ + return lv_btn_get_state(cb) == LV_BTN_STATE_REL ? false : true; +} + +/** + * Get the action of a check box + * @param cb pointer to a button object + * @return pointer to the action function + */ +static inline lv_action_t lv_cb_get_action(const lv_obj_t * cb) +{ + return lv_btn_get_action(cb, LV_BTN_ACTION_CLICK); +} + + +/** + * Get a style of a button + * @param cb pointer to check box object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_cb_get_style(const lv_obj_t * cb, lv_cb_style_t type); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_CB*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_CB_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.c new file mode 100644 index 0000000..0060c14 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.c @@ -0,0 +1,824 @@ +/** + * @file lv_chart.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_chart.h" +#if USE_LV_CHART != 0 + +#include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" + +/********************* + * DEFINES + *********************/ +#define LV_CHART_YMIN_DEF 0 +#define LV_CHART_YMAX_DEF 100 +#define LV_CHART_HDIV_DEF 3 +#define LV_CHART_VDIV_DEF 5 +#define LV_CHART_PNUM_DEF 10 + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_chart_design(lv_obj_t * chart, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param); +static void lv_chart_draw_div(lv_obj_t * chart, const lv_area_t * mask); +static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask); +static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask); +static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask); +static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mask); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_design_func_t ancestor_design_f; +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a chart background objects + * @param par pointer to an object, it will be the parent of the new chart background + * @param copy pointer to a chart background object, if not NULL then the new object will be copied from it + * @return pointer to the created chart background + */ +lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("chart create started"); + + /*Create the ancestor basic object*/ + lv_obj_t * new_chart = lv_obj_create(par, copy); + lv_mem_assert(new_chart); + if(new_chart == NULL) return NULL; + + /*Allocate the object type specific extended data*/ + lv_chart_ext_t * ext = lv_obj_allocate_ext_attr(new_chart, sizeof(lv_chart_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + lv_ll_init(&ext->series_ll, sizeof(lv_chart_series_t)); + ext->series.num = 0; + ext->ymin = LV_CHART_YMIN_DEF; + ext->ymax = LV_CHART_YMAX_DEF; + ext->hdiv_cnt = LV_CHART_HDIV_DEF; + ext->vdiv_cnt = LV_CHART_VDIV_DEF; + ext->point_cnt = LV_CHART_PNUM_DEF; + ext->type = LV_CHART_TYPE_LINE; + ext->series.opa = LV_OPA_COVER; + ext->series.dark = LV_OPA_50; + ext->series.width = 2; + + if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_chart); + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_chart); + + lv_obj_set_signal_func(new_chart, lv_chart_signal); + lv_obj_set_design_func(new_chart, lv_chart_design); + + /*Init the new chart background object*/ + if(copy == NULL) { + lv_obj_set_size(new_chart, LV_HOR_RES / 3, LV_VER_RES / 3); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_chart_set_style(new_chart, th->chart); + } else { + lv_chart_set_style(new_chart, &lv_style_pretty); + } + + } else { + lv_chart_ext_t * ext_copy = lv_obj_get_ext_attr(copy); + ext->type = ext_copy->type; + ext->ymin = ext_copy->ymin; + ext->ymax = ext_copy->ymax; + ext->hdiv_cnt = ext_copy->hdiv_cnt; + ext->vdiv_cnt = ext_copy->vdiv_cnt; + ext->point_cnt = ext_copy->point_cnt; + ext->series.opa = ext_copy->series.opa; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_chart); + } + + LV_LOG_INFO("chart created"); + + + return new_chart; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Allocate and add a data series to the chart + * @param chart pointer to a chart object + * @param color color of the data series + * @return pointer to the allocated data series + */ +lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + lv_chart_series_t * ser = lv_ll_ins_head(&ext->series_ll); + lv_mem_assert(ser); + if(ser == NULL) return NULL; + + lv_coord_t def = LV_CHART_POINT_DEF; + + if(ser == NULL) return NULL; + + ser->color = color; + + ser->points = lv_mem_alloc(sizeof(lv_coord_t) * ext->point_cnt); + lv_mem_assert(ser->points); + if(ser->points == NULL) { + lv_ll_rem(&ext->series_ll, ser); + lv_mem_free(ser); + return NULL; + } + + ser->start_point = 0; + + uint16_t i; + lv_coord_t * p_tmp = ser->points; + for(i = 0; i < ext->point_cnt; i++) { + *p_tmp = def; + p_tmp++; + } + + ext->series.num++; + + return ser; +} + +/** + * Clear the point of a serie + * @param chart pointer to a chart object + * @param serie pointer to the chart's serie to clear + */ +void lv_chart_clear_serie(lv_obj_t * chart, lv_chart_series_t * serie) +{ + if(chart == NULL || serie == NULL) + return; + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + if(ext == NULL) return; + + uint32_t i; + for(i = 0; i < ext->point_cnt; i++) + { + serie->points[i] = LV_CHART_POINT_DEF; + } + + serie->start_point = 0; + +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the number of horizontal and vertical division lines + * @param chart pointer to a graph background object + * @param hdiv number of horizontal division lines + * @param vdiv number of vertical division lines + */ +void lv_chart_set_div_line_count(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + if(ext->hdiv_cnt == hdiv && ext->vdiv_cnt == vdiv) return; + + ext->hdiv_cnt = hdiv; + ext->vdiv_cnt = vdiv; + + lv_obj_invalidate(chart); +} + +/** + * Set the minimal and maximal y values + * @param chart pointer to a graph background object + * @param ymin y minimum value + * @param ymax y maximum value + */ +void lv_chart_set_range(lv_obj_t * chart, lv_coord_t ymin, lv_coord_t ymax) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + if(ext->ymin == ymin && ext->ymax == ymax) return; + + ext->ymin = ymin; + ext->ymax = ymax; + + lv_chart_refresh(chart); +} + +/** + * Set a new type for a chart + * @param chart pointer to a chart object + * @param type new type of the chart (from 'lv_chart_type_t' enum) + */ +void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + if(ext->type == type) return; + + ext->type = type; + + lv_chart_refresh(chart); +} + +/** + * Set the number of points on a data line on a chart + * @param chart pointer r to chart object + * @param point_cnt new number of points on the data lines + */ +void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + if(ext->point_cnt == point_cnt) return; + + lv_chart_series_t * ser; + uint16_t point_cnt_old = ext->point_cnt; + uint16_t i; + lv_coord_t def = LV_CHART_POINT_DEF; + + if(point_cnt < 1) point_cnt = 1; + + LL_READ_BACK(ext->series_ll, ser) { + if(ser->start_point != 0) { + lv_coord_t * new_points = lv_mem_alloc(sizeof(lv_coord_t) * point_cnt); + lv_mem_assert(new_points); + if(new_points == NULL) return; + + if(point_cnt >= point_cnt_old) { + for(i = 0; i < point_cnt_old; i++) { + new_points[i] = ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/ + } + for(i = point_cnt_old; i < point_cnt; i++) { + new_points[i] = def; /*Fill up the rest with default value*/ + } + } else { + for(i = 0; i < point_cnt; i++) { + new_points[i] = ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/ + } + } + + /*Switch over pointer from old to new*/ + lv_mem_free(ser->points); + ser->points = new_points; + } else { + ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * point_cnt); + lv_mem_assert(ser->points); + if(ser->points == NULL) return; + /*Initialize the new points*/ + if(point_cnt > point_cnt_old) { + for(i = point_cnt_old - 1; i < point_cnt; i++) { + ser->points[i] = def; + } + } + } + + ser->start_point = 0; + } + + ext->point_cnt = point_cnt; + + lv_chart_refresh(chart); +} + +/** + * Set the opacity of the data series + * @param chart pointer to a chart object + * @param opa opacity of the data series + */ +void lv_chart_set_series_opa(lv_obj_t * chart, lv_opa_t opa) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + if(ext->series.opa == opa) return; + + ext->series.opa = opa; + lv_obj_invalidate(chart); +} + +/** + * Set the line width or point radius of the data series + * @param chart pointer to a chart object + * @param width the new width + */ +void lv_chart_set_series_width(lv_obj_t * chart, lv_coord_t width) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + if(ext->series.width == width) return; + + ext->series.width = width; + lv_obj_invalidate(chart); +} +/** + * Set the dark effect on the bottom of the points or columns + * @param chart pointer to a chart object + * @param dark_eff dark effect level (LV_OPA_TRANSP to turn off) + */ +void lv_chart_set_series_darking(lv_obj_t * chart, lv_opa_t dark_eff) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + if(ext->series.dark == dark_eff) return; + + ext->series.dark = dark_eff; + lv_obj_invalidate(chart); +} + +/** + * Initialize all data points with a value + * @param chart pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param y the new value for all points + */ +void lv_chart_init_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + uint16_t i; + for(i = 0; i < ext->point_cnt; i++) { + ser->points[i] = y; + } + ser->start_point = 0; + lv_chart_refresh(chart); +} + +/** + * Set the value s of points from an array + * @param chart pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param y_array array of 'lv_coord_t' points (with 'points count' elements ) + */ +void lv_chart_set_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t * y_array) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + memcpy(ser->points, y_array, ext->point_cnt * (sizeof(lv_coord_t))); + ser->start_point = 0; + lv_chart_refresh(chart); +} + +/** + * Shift all data left and set the rightmost data on a data line + * @param chart pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param y the new value of the rightmost data + */ +void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + + ser->points[ser->start_point] = y; /*This was the place of the former left most value, after shifting it is the rightmost*/ + ser->start_point = (ser->start_point + 1) % ext->point_cnt; + + lv_chart_refresh(chart); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the type of a chart + * @param chart pointer to chart object + * @return type of the chart (from 'lv_chart_t' enum) + */ +lv_chart_type_t lv_chart_get_type(const lv_obj_t * chart) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + return ext->type; +} + +/** + * Get the data point number per data line on chart + * @param chart pointer to chart object + * @return point number on each data line + */ +uint16_t lv_chart_get_point_cnt(const lv_obj_t * chart) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + return ext->point_cnt; +} + +/** + * Get the opacity of the data series + * @param chart pointer to chart object + * @return the opacity of the data series + */ +lv_opa_t lv_chart_get_series_opa(const lv_obj_t * chart) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + return ext->series.opa; +} + +/** + * Get the data series width + * @param chart pointer to chart object + * @return the width the data series (lines or points) + */ +lv_coord_t lv_chart_get_series_width(const lv_obj_t * chart) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + return ext->series.width; +} + +/** + * Get the dark effect level on the bottom of the points or columns + * @param chart pointer to chart object + * @return dark effect level (LV_OPA_TRANSP to turn off) + */ +lv_opa_t lv_chart_get_series_darking(const lv_obj_t * chart) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + return ext->series.dark; +} + +/*===================== + * Other functions + *====================*/ + +/** + * Refresh a chart if its data line has changed + * @param chart pointer to chart object + */ +void lv_chart_refresh(lv_obj_t * chart) +{ + lv_obj_invalidate(chart); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the chart backgrounds + * @param chart pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_chart_design(lv_obj_t * chart, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + /*Return false if the object is not covers the mask_p area*/ + return ancestor_design_f(chart, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { + /*Draw the background*/ + lv_draw_rect(&chart->coords, mask, lv_obj_get_style(chart), lv_obj_get_opa_scale(chart)); + + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + + lv_chart_draw_div(chart, mask); + + if(ext->type & LV_CHART_TYPE_LINE) lv_chart_draw_lines(chart, mask); + if(ext->type & LV_CHART_TYPE_COLUMN) lv_chart_draw_cols(chart, mask); + if(ext->type & LV_CHART_TYPE_POINT) lv_chart_draw_points(chart, mask); + if(ext->type & LV_CHART_TYPE_VERTICAL_LINE) lv_chart_draw_vertical_lines(chart, mask); + } + return true; +} + +/** + * Signal function of the chart background + * @param chart pointer to a chart background object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + */ +static lv_res_t lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(chart, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_CLEANUP) { + lv_coord_t ** datal; + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + LL_READ(ext->series_ll, datal) { + lv_mem_free(*datal); + } + lv_ll_clear(&ext->series_ll); + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_chart"; + } + + return res; +} + +/** + * Draw the division lines on chart background + * @param chart pointer to chart object + * @param mask mask, inherited from the design function + */ +static void lv_chart_draw_div(lv_obj_t * chart, const lv_area_t * mask) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + lv_style_t * style = lv_obj_get_style(chart); + lv_opa_t opa_scale = lv_obj_get_opa_scale(chart); + + uint8_t div_i; + uint8_t div_i_end; + uint8_t div_i_start; + lv_point_t p1; + lv_point_t p2; + lv_coord_t w = lv_obj_get_width(chart); + lv_coord_t h = lv_obj_get_height(chart); + lv_coord_t x_ofs = chart->coords.x1; + lv_coord_t y_ofs = chart->coords.y1; + + if(ext->hdiv_cnt != 0) { + /*Draw slide lines if no border*/ + if(style->body.border.width != 0) { + div_i_start = 1; + div_i_end = ext->hdiv_cnt; + } else { + div_i_start = 0; + div_i_end = ext->hdiv_cnt + 1; + } + + p1.x = 0 + x_ofs; + p2.x = w + x_ofs; + for(div_i = div_i_start; div_i <= div_i_end; div_i++) { + p1.y = (int32_t)((int32_t)h * div_i) / (ext->hdiv_cnt + 1); + p1.y += y_ofs; + if(div_i == div_i_start) p1.y += (style->line.width >> 1) + 1; /*The first line might not be visible*/ + if(div_i == div_i_end) p1.y -= (style->line.width >> 1) + 1; /*The last line might not be visible*/ + + p2.y = p1.y; + lv_draw_line(&p1, &p2, mask, style, opa_scale); + } + } + + if(ext->vdiv_cnt != 0) { + /*Draw slide lines if no border*/ + if(style->body.border.width != 0) { + div_i_start = 1; + div_i_end = ext->vdiv_cnt; + } else { + div_i_start = 0; + div_i_end = ext->vdiv_cnt + 1; + } + + p1.y = 0 + y_ofs; + p2.y = h + y_ofs; + for(div_i = div_i_start; div_i <= div_i_end; div_i ++) { + p1.x = (int32_t)((int32_t)w * div_i) / (ext->vdiv_cnt + 1); + p1.x += x_ofs; + if(div_i == div_i_start) p1.x += (style->line.width >> 1) + 1; /*The first line might not be visible*/ + if(div_i == div_i_end) p1.x -= (style->line.width >> 1) + 1; /*The last line might not be visible*/ + p2.x = p1.x; + lv_draw_line(&p1, &p2, mask, style, opa_scale); + } + } +} + +/** + * Draw the data lines as lines on a chart + * @param obj pointer to chart object + */ +static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + + uint16_t i; + lv_point_t p1; + lv_point_t p2; + lv_coord_t w = lv_obj_get_width(chart); + lv_coord_t h = lv_obj_get_height(chart); + lv_coord_t x_ofs = chart->coords.x1; + lv_coord_t y_ofs = chart->coords.y1; + int32_t y_tmp; + lv_coord_t p_prev; + lv_coord_t p_act; + lv_chart_series_t * ser; + lv_opa_t opa_scale = lv_obj_get_opa_scale(chart); + lv_style_t style; + lv_style_copy(&style, &lv_style_plain); + style.line.opa = ext->series.opa; + style.line.width = ext->series.width; + + /*Go through all data lines*/ + LL_READ_BACK(ext->series_ll, ser) { + style.line.color = ser->color; + + p1.x = 0 + x_ofs; + p2.x = 0 + x_ofs; + + p_prev = ser->start_point; + y_tmp = (int32_t)((int32_t) ser->points[p_prev] - ext->ymin) * h; + y_tmp = y_tmp / (ext->ymax - ext->ymin); + p2.y = h - y_tmp + y_ofs; + + for(i = 1; i < ext->point_cnt; i ++) { + p1.x = p2.x; + p1.y = p2.y; + + p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs; + + p_act = (ser->start_point + i) % ext->point_cnt; + + y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h; + y_tmp = y_tmp / (ext->ymax - ext->ymin); + p2.y = h - y_tmp + y_ofs; + + if(ser->points[p_prev] != LV_CHART_POINT_DEF && ser->points[p_act] != LV_CHART_POINT_DEF) + lv_draw_line(&p1, &p2, mask, &style, opa_scale); + + p_prev = p_act; + } + } +} + +/** + * Draw the data lines as points on a chart + * @param chart pointer to chart object + * @param mask mask, inherited from the design function + */ +static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + + uint16_t i; + lv_area_t cir_a; + lv_coord_t w = lv_obj_get_width(chart); + lv_coord_t h = lv_obj_get_height(chart); + lv_coord_t x_ofs = chart->coords.x1; + lv_coord_t y_ofs = chart->coords.y1; + int32_t y_tmp; + lv_coord_t p_act; + lv_chart_series_t * ser; + uint8_t series_cnt = 0; + lv_style_t style_point; + lv_style_copy(&style_point, &lv_style_plain); + + style_point.body.border.width = 0; + style_point.body.empty = 0; + style_point.body.radius = LV_RADIUS_CIRCLE; + style_point.body.opa = ext->series.opa; + style_point.body.radius = ext->series.width; + + /*Go through all data lines*/ + LL_READ_BACK(ext->series_ll, ser) { + style_point.body.main_color = ser->color; + style_point.body.grad_color = lv_color_mix(LV_COLOR_BLACK, ser->color, ext->series.dark); + + for(i = 0; i < ext->point_cnt; i ++) { + cir_a.x1 = ((w * i) / (ext->point_cnt - 1)) + x_ofs; + cir_a.x2 = cir_a.x1 + style_point.body.radius; + cir_a.x1 -= style_point.body.radius; + p_act = (ser->start_point + i) % ext->point_cnt; + y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h; + y_tmp = y_tmp / (ext->ymax - ext->ymin); + cir_a.y1 = h - y_tmp + y_ofs; + cir_a.y2 = cir_a.y1 + style_point.body.radius; + cir_a.y1 -= style_point.body.radius; + + if(ser->points[p_act] != LV_CHART_POINT_DEF) + lv_draw_rect(&cir_a, mask, &style_point, lv_obj_get_opa_scale(chart)); + } + series_cnt++; + } +} + +/** + * Draw the data lines as columns on a chart + * @param chart pointer to chart object + * @param mask mask, inherited from the design function + */ +static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask) +{ + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + + uint16_t i; + lv_area_t col_a; + lv_area_t col_mask; + bool mask_ret; + lv_coord_t w = lv_obj_get_width(chart); + lv_coord_t h = lv_obj_get_height(chart); + int32_t y_tmp; + lv_chart_series_t * ser; + lv_style_t rects; + lv_coord_t col_w = w / ((ext->series.num + 1) * ext->point_cnt); /* Suppose + 1 series as separator*/ + lv_coord_t x_ofs = col_w / 2; /*Shift with a half col.*/ + + lv_style_copy(&rects, &lv_style_plain); + rects.body.border.width = 0; + rects.body.empty = 0; + rects.body.radius = 0; + rects.body.opa = ext->series.opa; + + col_a.y2 = chart->coords.y2; + + lv_coord_t x_act; + + /*Go through all points*/ + for(i = 0; i < ext->point_cnt; i ++) { + x_act = (int32_t)((int32_t) w * i) / ext->point_cnt; + x_act += chart->coords.x1 + x_ofs; + + /*Draw the current point of all data line*/ + LL_READ_BACK(ext->series_ll, ser) { + rects.body.main_color = ser->color; + rects.body.grad_color = lv_color_mix(LV_COLOR_BLACK, ser->color, ext->series.dark); + col_a.x1 = x_act; + col_a.x2 = col_a.x1 + col_w; + x_act += col_w; + + lv_coord_t p_act = (ser->start_point + i) % ext->point_cnt; + y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h; + y_tmp = y_tmp / (ext->ymax - ext->ymin); + col_a.y1 = h - y_tmp + chart->coords.y1; + + mask_ret = lv_area_intersect(&col_mask, mask, &col_a); + if(mask_ret != false && ser->points[p_act] != LV_CHART_POINT_DEF) { + lv_draw_rect(&chart->coords, &col_mask, &rects, lv_obj_get_opa_scale(chart)); + } + } + } +} + +/** + * Draw the data lines as vertical lines on a chart if there is only 1px between point + * @param obj pointer to chart object + */ +static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mask) +{ + + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + lv_coord_t w = lv_obj_get_width(chart); + /*Vertical lines works only if the width == point count. Else use the normal line type*/ + if(ext->point_cnt != w) { + lv_chart_draw_lines(chart, mask); + return; + } + + uint16_t i; + lv_point_t p1; + lv_point_t p2; + lv_coord_t h = lv_obj_get_height(chart); + lv_coord_t x_ofs = chart->coords.x1; + lv_coord_t y_ofs = chart->coords.y1; + int32_t y_tmp; + lv_chart_series_t * ser; + lv_opa_t opa_scale = lv_obj_get_opa_scale(chart); + lv_style_t style; + lv_style_copy(&style, &lv_style_plain); + style.line.opa = ext->series.opa; + style.line.width = ext->series.width; + + /*Go through all data lines*/ + LL_READ_BACK(ext->series_ll, ser) { + style.line.color = ser->color; + + p1.x = 0 + x_ofs; + p2.x = 0 + x_ofs; + y_tmp = (int32_t)((int32_t) ser->points[0] - ext->ymin) * h; + y_tmp = y_tmp / (ext->ymax - ext->ymin); + p2.y = h - y_tmp + y_ofs; + p1.y = p2.y; + + for(i = 0; i < ext->point_cnt; i++) + { + + y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h; + y_tmp = y_tmp / (ext->ymax - ext->ymin); + p2.y = h - y_tmp + y_ofs; + + if(p1.y == p2.y) + { + p2.x++; + } + + if(ser->points[i] != LV_CHART_POINT_DEF) { + lv_draw_line(&p1, &p2, mask, &style, opa_scale); + } + + p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs; + p1.x = p2.x; + p1.y = p2.y; + } + } +} +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.h new file mode 100644 index 0000000..baea9d0 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_chart.h @@ -0,0 +1,262 @@ +/** + * @file lv_chart.h + * + */ + +#ifndef LV_CHART_H +#define LV_CHART_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_CHART != 0 + +#include "../lv_core/lv_obj.h" +#include "lv_line.h" + +/********************* + * DEFINES + *********************/ +#define LV_CHART_POINT_DEF (LV_COORD_MIN) + +/********************** + * TYPEDEFS + **********************/ +typedef struct +{ + lv_coord_t * points; + lv_color_t color; + uint16_t start_point; +} lv_chart_series_t; + +/*Data of chart */ +typedef struct +{ + /*No inherited ext*/ /*Ext. of ancestor*/ + /*New data for this type */ + lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/ + lv_coord_t ymin; /*y min value (used to scale the data)*/ + lv_coord_t ymax; /*y max value (used to scale the data)*/ + uint8_t hdiv_cnt; /*Number of horizontal division lines*/ + uint8_t vdiv_cnt; /*Number of vertical division lines*/ + uint16_t point_cnt; /*Point number in a data line*/ + uint8_t type :4; /*Line, column or point chart (from 'lv_chart_type_t')*/ + struct { + lv_coord_t width; /*Line width or point radius*/ + uint8_t num; /*Number of data lines in dl_ll*/ + lv_opa_t opa; /*Opacity of data lines*/ + lv_opa_t dark; /*Dark level of the point/column bottoms*/ + } series; +} lv_chart_ext_t; + +/*Chart types*/ +enum +{ + LV_CHART_TYPE_LINE = 0x01, /*Connect the points with lines*/ + LV_CHART_TYPE_COLUMN = 0x02, /*Draw columns*/ + LV_CHART_TYPE_POINT = 0x04, /*Draw circles on the points*/ + LV_CHART_TYPE_VERTICAL_LINE = 0x08, /*Draw vertical lines on points (useful when chart width == point count)*/ +}; +typedef uint8_t lv_chart_type_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a chart background objects + * @param par pointer to an object, it will be the parent of the new chart background + * @param copy pointer to a chart background object, if not NULL then the new object will be copied from it + * @return pointer to the created chart background + */ +lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Allocate and add a data series to the chart + * @param chart pointer to a chart object + * @param color color of the data series + * @return pointer to the allocated data series + */ +lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color); + +/** + * Clear the point of a serie + * @param chart pointer to a chart object + * @param serie pointer to the chart's serie to clear + */ +void lv_chart_clear_serie(lv_obj_t * chart, lv_chart_series_t * serie); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the number of horizontal and vertical division lines + * @param chart pointer to a graph background object + * @param hdiv number of horizontal division lines + * @param vdiv number of vertical division lines + */ +void lv_chart_set_div_line_count(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv); + +/** + * Set the minimal and maximal y values + * @param chart pointer to a graph background object + * @param ymin y minimum value + * @param ymax y maximum value + */ +void lv_chart_set_range(lv_obj_t * chart, lv_coord_t ymin, lv_coord_t ymax); + +/** + * Set a new type for a chart + * @param chart pointer to a chart object + * @param type new type of the chart (from 'lv_chart_type_t' enum) + */ +void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type); + +/** + * Set the number of points on a data line on a chart + * @param chart pointer r to chart object + * @param point_cnt new number of points on the data lines + */ +void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt); + +/** + * Set the opacity of the data series + * @param chart pointer to a chart object + * @param opa opacity of the data series + */ +void lv_chart_set_series_opa(lv_obj_t * chart, lv_opa_t opa); + +/** + * Set the line width or point radius of the data series + * @param chart pointer to a chart object + * @param width the new width + */ +void lv_chart_set_series_width(lv_obj_t * chart, lv_coord_t width); + +/** + * Set the dark effect on the bottom of the points or columns + * @param chart pointer to a chart object + * @param dark_eff dark effect level (LV_OPA_TRANSP to turn off) + */ +void lv_chart_set_series_darking(lv_obj_t * chart, lv_opa_t dark_eff); + +/** + * Initialize all data points with a value + * @param chart pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param y the new value for all points + */ +void lv_chart_init_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y); + +/** + * Set the value s of points from an array + * @param chart pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param y_array array of 'lv_coord_t' points (with 'points count' elements ) + */ +void lv_chart_set_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t * y_array); + +/** + * Shift all data right and set the most right data on a data line + * @param chart pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param y the new value of the most right data + */ +void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y); + +/** + * Set the style of a chart + * @param chart pointer to a chart object + * @param style pointer to a style + */ +static inline void lv_chart_set_style(lv_obj_t *chart, lv_style_t *style) +{ + lv_obj_set_style(chart, style); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the type of a chart + * @param chart pointer to chart object + * @return type of the chart (from 'lv_chart_t' enum) + */ +lv_chart_type_t lv_chart_get_type(const lv_obj_t * chart); + +/** + * Get the data point number per data line on chart + * @param chart pointer to chart object + * @return point number on each data line + */ +uint16_t lv_chart_get_point_cnt(const lv_obj_t * chart); + +/** + * Get the opacity of the data series + * @param chart pointer to chart object + * @return the opacity of the data series + */ +lv_opa_t lv_chart_get_series_opa(const lv_obj_t * chart); + +/** + * Get the data series width + * @param chart pointer to chart object + * @return the width the data series (lines or points) + */ +lv_coord_t lv_chart_get_series_width(const lv_obj_t * chart); + +/** + * Get the dark effect level on the bottom of the points or columns + * @param chart pointer to chart object + * @return dark effect level (LV_OPA_TRANSP to turn off) + */ +lv_opa_t lv_chart_get_series_darking(const lv_obj_t * chart); + +/** + * Get the style of an chart object + * @param chart pointer to an chart object + * @return pointer to the chart's style + */ +static inline lv_style_t* lv_chart_get_style(const lv_obj_t *chart) +{ + return lv_obj_get_style(chart); +} + +/*===================== + * Other functions + *====================*/ + +/** + * Refresh a chart if its data line has changed + * @param chart pointer to chart object + */ +void lv_chart_refresh(lv_obj_t * chart); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_CHART*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_CHART_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.c new file mode 100644 index 0000000..bd84cd9 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.c @@ -0,0 +1,642 @@ +/** + * @file lv_cont.c + * + */ + +/********************* + * INCLUDES + *********************/ + +#include "lv_cont.h" +#if USE_LV_CONT != 0 + +#include +#include + +#include "../lv_draw/lv_draw.h" +#include "../lv_draw/lv_draw_vbasic.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_area.h" +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param); +static void lv_cont_refr_layout(lv_obj_t * cont); +static void lv_cont_layout_col(lv_obj_t * cont); +static void lv_cont_layout_row(lv_obj_t * cont); +static void lv_cont_layout_center(lv_obj_t * cont); +static void lv_cont_layout_pretty(lv_obj_t * cont); +static void lv_cont_layout_grid(lv_obj_t * cont); +static void lv_cont_refr_autofit(lv_obj_t * cont); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a container objects + * @param par pointer to an object, it will be the parent of the new container + * @param copy pointer to a container object, if not NULL then the new object will be copied from it + * @return pointer to the created container + */ +lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy) +{ + + + LV_LOG_TRACE("container create started"); + + /*Create a basic object*/ + lv_obj_t * new_cont = lv_obj_create(par, copy); + lv_mem_assert(new_cont); + if(new_cont == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_cont); + + lv_obj_allocate_ext_attr(new_cont, sizeof(lv_cont_ext_t)); + lv_cont_ext_t * ext = lv_obj_get_ext_attr(new_cont); + if(ext == NULL) return NULL; + + lv_mem_assert(ext); + ext->hor_fit = 0; + ext->ver_fit = 0; + ext->layout = LV_LAYOUT_OFF; + + lv_obj_set_signal_func(new_cont, lv_cont_signal); + + /*Init the new container*/ + if(copy == NULL) { + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_cont_set_style(new_cont, th->cont); + } else { + lv_cont_set_style(new_cont, &lv_style_pretty); + } + } + /*Copy an existing object*/ + else { + lv_cont_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->hor_fit = copy_ext->hor_fit; + ext->ver_fit = copy_ext->ver_fit; + ext->layout = copy_ext->layout; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_cont); + } + + LV_LOG_INFO("container created"); + + + return new_cont; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a layout on a container + * @param cont pointer to a container object + * @param layout a layout from 'lv_cont_layout_t' + */ +void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout) +{ + lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); + if(ext->layout == layout) return; + + ext->layout = layout; + + /*Send a signal to refresh the layout*/ + cont->signal_func(cont, LV_SIGNAL_CHILD_CHG, NULL); +} + + +/** + * Enable the horizontal or vertical fit. + * The container size will be set to involve the children horizontally or vertically. + * @param cont pointer to a container object + * @param hor_en true: enable the horizontal fit + * @param ver_en true: enable the vertical fit + */ +void lv_cont_set_fit(lv_obj_t * cont, bool hor_en, bool ver_en) +{ + lv_obj_invalidate(cont); + lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); + if(ext->hor_fit == hor_en && ext->ver_fit == ver_en) return; + + ext->hor_fit = hor_en == false ? 0 : 1; + ext->ver_fit = ver_en == false ? 0 : 1; + + /*Send a signal to refresh the layout*/ + cont->signal_func(cont, LV_SIGNAL_CHILD_CHG, NULL); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the layout of a container + * @param cont pointer to container object + * @return the layout from 'lv_cont_layout_t' + */ +lv_layout_t lv_cont_get_layout(const lv_obj_t * cont) +{ + lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); + return ext->layout; +} + +/** + * Get horizontal fit enable attribute of a container + * @param cont pointer to a container object + * @return true: horizontal fit is enabled; false: disabled + */ +bool lv_cont_get_hor_fit(const lv_obj_t * cont) +{ + lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); + return ext->hor_fit == 0 ? false : true; +} + +/** + * Get vertical fit enable attribute of a container + * @param cont pointer to a container object + * @return true: vertical fit is enabled; false: disabled + */ +bool lv_cont_get_ver_fit(const lv_obj_t * cont) +{ + lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); + return ext->ver_fit == 0 ? false : true; +} + +/** + * Get that width reduced by the horizontal padding. Useful if a layout is used. + * @param cont pointer to a container object + * @return the width which still fits into the container + */ +lv_coord_t lv_cont_get_fit_width(lv_obj_t * cont) +{ + lv_style_t * style = lv_cont_get_style(cont); + + return lv_obj_get_width(cont) - 2 * style->body.padding.hor; +} + +/** + * Get that height reduced by the vertical padding. Useful if a layout is used. + * @param cont pointer to a container object + * @return the height which still fits into the container + */ +lv_coord_t lv_cont_get_fit_height(lv_obj_t * cont) +{ + lv_style_t * style = lv_cont_get_style(cont); + + return lv_obj_get_height(cont) - 2 * style->body.padding.ver; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the container + * @param cont pointer to a container object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(cont, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_STYLE_CHG) { /*Recalculate the padding if the style changed*/ + lv_cont_refr_layout(cont); + lv_cont_refr_autofit(cont); + } else if(sign == LV_SIGNAL_CHILD_CHG) { + lv_cont_refr_layout(cont); + lv_cont_refr_autofit(cont); + } else if(sign == LV_SIGNAL_CORD_CHG) { + if(lv_obj_get_width(cont) != lv_area_get_width(param) || + lv_obj_get_height(cont) != lv_area_get_height(param)) { + lv_cont_refr_layout(cont); + lv_cont_refr_autofit(cont); + } + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_cont"; + } + + return res; +} + + +/** + * Refresh the layout of a container + * @param cont pointer to an object which layout should be refreshed + */ +static void lv_cont_refr_layout(lv_obj_t * cont) +{ + lv_layout_t type = lv_cont_get_layout(cont); + + /*'cont' has to be at least 1 child*/ + if(lv_obj_get_child(cont, NULL) == NULL) return; + + if(type == LV_LAYOUT_OFF) return; + + if(type == LV_LAYOUT_CENTER) { + lv_cont_layout_center(cont); + } else if(type == LV_LAYOUT_COL_L || type == LV_LAYOUT_COL_M || type == LV_LAYOUT_COL_R) { + lv_cont_layout_col(cont); + } else if(type == LV_LAYOUT_ROW_T || type == LV_LAYOUT_ROW_M || type == LV_LAYOUT_ROW_B) { + lv_cont_layout_row(cont); + } else if(type == LV_LAYOUT_PRETTY) { + lv_cont_layout_pretty(cont); + } else if(type == LV_LAYOUT_GRID) { + lv_cont_layout_grid(cont); + } +} + +/** + * Handle column type layouts + * @param cont pointer to an object which layout should be handled + */ +static void lv_cont_layout_col(lv_obj_t * cont) +{ + lv_layout_t type = lv_cont_get_layout(cont); + lv_obj_t * child; + + /*Adjust margin and get the alignment type*/ + lv_align_t align; + lv_style_t * style = lv_obj_get_style(cont); + lv_coord_t hpad_corr; + + switch(type) { + case LV_LAYOUT_COL_L: + hpad_corr = style->body.padding.hor; + align = LV_ALIGN_IN_TOP_LEFT; + break; + case LV_LAYOUT_COL_M: + hpad_corr = 0; + align = LV_ALIGN_IN_TOP_MID; + break; + case LV_LAYOUT_COL_R: + hpad_corr = -style->body.padding.hor; + align = LV_ALIGN_IN_TOP_RIGHT; + break; + default: + hpad_corr = 0; + align = LV_ALIGN_IN_TOP_LEFT; + break; + } + + /* Disable child change action because the children will be moved a lot + * an unnecessary child change signals could be sent*/ + lv_obj_set_protect(cont, LV_PROTECT_CHILD_CHG); + /* Align the children */ + lv_coord_t last_cord = style->body.padding.ver; + LL_READ_BACK(cont->child_ll, child) { + if(lv_obj_get_hidden(child) != false || + lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; + + lv_obj_align(child, cont, align, hpad_corr, last_cord); + last_cord += lv_obj_get_height(child) + style->body.padding.inner; + } + + lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG); +} + +/** + * Handle row type layouts + * @param cont pointer to an object which layout should be handled + */ +static void lv_cont_layout_row(lv_obj_t * cont) +{ + lv_layout_t type = lv_cont_get_layout(cont); + lv_obj_t * child; + + /*Adjust margin and get the alignment type*/ + lv_align_t align; + lv_style_t * style = lv_obj_get_style(cont); + lv_coord_t vpad_corr = style->body.padding.ver; + + switch(type) { + case LV_LAYOUT_ROW_T: + vpad_corr = style->body.padding.ver; + align = LV_ALIGN_IN_TOP_LEFT; + break; + case LV_LAYOUT_ROW_M: + vpad_corr = 0; + align = LV_ALIGN_IN_LEFT_MID; + break; + case LV_LAYOUT_ROW_B: + vpad_corr = -style->body.padding.ver; + align = LV_ALIGN_IN_BOTTOM_LEFT; + break; + default: + vpad_corr = 0; + align = LV_ALIGN_IN_TOP_LEFT; + break; + } + + /* Disable child change action because the children will be moved a lot + * an unnecessary child change signals could be sent*/ + lv_obj_set_protect(cont, LV_PROTECT_CHILD_CHG); + + /* Align the children */ + lv_coord_t last_cord = style->body.padding.hor; + LL_READ_BACK(cont->child_ll, child) { + if(lv_obj_get_hidden(child) != false || + lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; + + lv_obj_align(child, cont, align, last_cord, vpad_corr); + last_cord += lv_obj_get_width(child) + style->body.padding.inner; + } + + lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG); +} + +/** + * Handle the center layout + * @param cont pointer to an object which layout should be handled + */ +static void lv_cont_layout_center(lv_obj_t * cont) +{ + lv_obj_t * child; + lv_style_t * style = lv_obj_get_style(cont); + uint32_t obj_num = 0; + lv_coord_t h_tot = 0; + + LL_READ(cont->child_ll, child) { + if(lv_obj_get_hidden(child) != false || + lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; + h_tot += lv_obj_get_height(child) + style->body.padding.inner; + obj_num ++; + } + + if(obj_num == 0) return; + + h_tot -= style->body.padding.inner; + + /* Disable child change action because the children will be moved a lot + * an unnecessary child change signals could be sent*/ + lv_obj_set_protect(cont, LV_PROTECT_CHILD_CHG); + + /* Align the children */ + lv_coord_t last_cord = - (h_tot / 2); + LL_READ_BACK(cont->child_ll, child) { + if(lv_obj_get_hidden(child) != false || + lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; + + lv_obj_align(child, cont, LV_ALIGN_CENTER, 0, last_cord + lv_obj_get_height(child) / 2); + last_cord += lv_obj_get_height(child) + style->body.padding.inner; + } + + lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG); +} + +/** + * Handle the pretty layout. Put as many object as possible in row + * then begin a new row + * @param cont pointer to an object which layout should be handled + */ +static void lv_cont_layout_pretty(lv_obj_t * cont) +{ + lv_obj_t * child_rs; /* Row starter child */ + lv_obj_t * child_rc; /* Row closer child */ + lv_obj_t * child_tmp; /* Temporary child */ + lv_style_t * style = lv_obj_get_style(cont); + lv_coord_t w_obj = lv_obj_get_width(cont); + lv_coord_t act_y = style->body.padding.ver; + /* Disable child change action because the children will be moved a lot + * an unnecessary child change signals could be sent*/ + + child_rs = lv_ll_get_tail(&cont->child_ll); /*Set the row starter child*/ + if(child_rs == NULL) return; /*Return if no child*/ + + lv_obj_set_protect(cont, LV_PROTECT_CHILD_CHG); + + child_rc = child_rs; /*Initially the the row starter and closer is the same*/ + while(child_rs != NULL) { + lv_coord_t h_row = 0; + lv_coord_t w_row = style->body.padding.hor * 2; /*The width is at least the left+right hpad*/ + uint32_t obj_num = 0; + + /*Find the row closer object and collect some data*/ + do { + if(lv_obj_get_hidden(child_rc) == false && + lv_obj_is_protected(child_rc, LV_PROTECT_POS) == false) { + /*If this object is already not fit then break*/ + if(w_row + lv_obj_get_width(child_rc) > w_obj) { + /*Step back one child because the last already not fit, so the previous is the closer*/ + if(child_rc != NULL && obj_num != 0) { + child_rc = lv_ll_get_next(&cont->child_ll, child_rc); + } + break; + } + w_row += lv_obj_get_width(child_rc) + style->body.padding.inner; /*Add the object width + opad*/ + h_row = LV_MATH_MAX(h_row, lv_obj_get_height(child_rc)); /*Search the highest object*/ + obj_num ++; + if(lv_obj_is_protected(child_rc, LV_PROTECT_FOLLOW)) break; /*If can not be followed by an other object then break here*/ + + } + child_rc = lv_ll_get_prev(&cont->child_ll, child_rc); /*Load the next object*/ + if(obj_num == 0) child_rs = child_rc; /*If the first object was hidden (or too long) then set the next as first */ + } while(child_rc != NULL); + + /*If the object is too long then align it to the middle*/ + if(obj_num == 0) { + if(child_rc != NULL) { + lv_obj_align(child_rc, cont, LV_ALIGN_IN_TOP_MID, 0, act_y); + h_row = lv_obj_get_height(child_rc); /*Not set previously because of the early break*/ + } + } + /*If there is only one object in the row then align it to the middle*/ + else if(obj_num == 1) { + lv_obj_align(child_rs, cont, LV_ALIGN_IN_TOP_MID, 0, act_y); + } + /*If there are two object in the row then align them proportionally*/ + else if(obj_num == 2) { + lv_obj_t * obj1 = child_rs; + lv_obj_t * obj2 = lv_ll_get_prev(&cont->child_ll, child_rs); + w_row = lv_obj_get_width(obj1) + lv_obj_get_width(obj2); + lv_coord_t pad = (w_obj - w_row) / 3; + lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y + (h_row - lv_obj_get_height(obj1)) / 2); + lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y + (h_row - lv_obj_get_height(obj2)) / 2); + } + /* Align the children (from child_rs to child_rc)*/ + else { + w_row -= style->body.padding.inner * obj_num; + lv_coord_t new_opad = (w_obj - w_row) / (obj_num - 1); + lv_coord_t act_x = style->body.padding.hor; /*x init*/ + child_tmp = child_rs; + while(child_tmp != NULL) { + if(lv_obj_get_hidden(child_tmp) == false && + lv_obj_is_protected(child_tmp, LV_PROTECT_POS) == false) { + lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, act_y + (h_row - lv_obj_get_height(child_tmp)) / 2); + act_x += lv_obj_get_width(child_tmp) + new_opad; + } + if(child_tmp == child_rc) break; + child_tmp = lv_ll_get_prev(&cont->child_ll, child_tmp); + } + + } + + if(child_rc == NULL) break; + act_y += style->body.padding.inner + h_row; /*y increment*/ + child_rs = lv_ll_get_prev(&cont->child_ll, child_rc); /*Go to the next object*/ + child_rc = child_rs; + } + lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG); +} + +/** + * Handle the grid layout. Align same-sized objects in a grid + * @param cont pointer to an object which layout should be handled + */ +static void lv_cont_layout_grid(lv_obj_t * cont) +{ + lv_obj_t * child; + lv_style_t * style = lv_obj_get_style(cont); + lv_coord_t w_tot = lv_obj_get_width(cont); + lv_coord_t w_obj = lv_obj_get_width(lv_obj_get_child(cont, NULL)); + lv_coord_t h_obj = lv_obj_get_height(lv_obj_get_child(cont, NULL)); + uint16_t obj_row = (w_tot - (2 * style->body.padding.hor)) / (w_obj + style->body.padding.inner); /*Obj. num. in a row*/ + lv_coord_t x_ofs; + if(obj_row > 1) { + x_ofs = w_obj + (w_tot - (2 * style->body.padding.hor) - (obj_row * w_obj)) / (obj_row - 1); + } else { + x_ofs = w_tot / 2 - w_obj / 2; + } + lv_coord_t y_ofs = h_obj + style->body.padding.inner; + + /* Disable child change action because the children will be moved a lot + * an unnecessary child change signals could be sent*/ + lv_obj_set_protect(cont, LV_PROTECT_CHILD_CHG); + + /* Align the children */ + lv_coord_t act_x = style->body.padding.hor; + lv_coord_t act_y = style->body.padding.ver; + uint16_t obj_cnt = 0; + LL_READ_BACK(cont->child_ll, child) { + if(lv_obj_get_hidden(child) != false || + lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; + + if(obj_row > 1) { + lv_obj_set_pos(child, act_x, act_y); + act_x += x_ofs; + } else { + lv_obj_set_pos(child, x_ofs, act_y); + } + obj_cnt ++; + + if(obj_cnt >= obj_row) { + obj_cnt = 0; + act_x = style->body.padding.hor; + act_y += y_ofs; + } + } + + lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG); +} + +/** + * Handle auto fit. Set the size of the object to involve all children. + * @param cont pointer to an object which size will be modified + */ +static void lv_cont_refr_autofit(lv_obj_t * cont) +{ + lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); + + if(ext->hor_fit == 0 && + ext->ver_fit == 0) { + return; + } + + lv_area_t new_cords; + lv_area_t ori; + lv_style_t * style = lv_obj_get_style(cont); + lv_obj_t * i; + lv_coord_t hpad = style->body.padding.hor; + lv_coord_t vpad = style->body.padding.ver; + + /*Search the side coordinates of the children*/ + lv_obj_get_coords(cont, &ori); + lv_obj_get_coords(cont, &new_cords); + + new_cords.x1 = LV_COORD_MAX; + new_cords.y1 = LV_COORD_MAX; + new_cords.x2 = LV_COORD_MIN; + new_cords.y2 = LV_COORD_MIN; + + LL_READ(cont->child_ll, i) { + if(lv_obj_get_hidden(i) != false) continue; + new_cords.x1 = LV_MATH_MIN(new_cords.x1, i->coords.x1); + new_cords.y1 = LV_MATH_MIN(new_cords.y1, i->coords.y1); + new_cords.x2 = LV_MATH_MAX(new_cords.x2, i->coords.x2); + new_cords.y2 = LV_MATH_MAX(new_cords.y2, i->coords.y2); + } + + /*If the value is not the init value then the page has >=1 child.*/ + if(new_cords.x1 != LV_COORD_MAX) { + if(ext->hor_fit != 0) { + new_cords.x1 -= hpad; + new_cords.x2 += hpad; + } else { + new_cords.x1 = cont->coords.x1; + new_cords.x2 = cont->coords.x2; + } + if(ext->ver_fit != 0) { + new_cords.y1 -= vpad; + new_cords.y2 += vpad; + } else { + new_cords.y1 = cont->coords.y1; + new_cords.y2 = cont->coords.y2; + } + + /*Do nothing if the coordinates are not changed*/ + if(cont->coords.x1 != new_cords.x1 || + cont->coords.y1 != new_cords.y1 || + cont->coords.x2 != new_cords.x2 || + cont->coords.y2 != new_cords.y2) { + + lv_obj_invalidate(cont); + lv_area_copy(&cont->coords, &new_cords); + lv_obj_invalidate(cont); + + /*Notify the object about its new coordinates*/ + cont->signal_func(cont, LV_SIGNAL_CORD_CHG, &ori); + + /*Inform the parent about the new coordinates*/ + lv_obj_t * par = lv_obj_get_parent(cont); + par->signal_func(par, LV_SIGNAL_CHILD_CHG, cont); + } + } +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.h new file mode 100644 index 0000000..3259c77 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_cont.h @@ -0,0 +1,163 @@ +/** + * @file lv_cont.h + * + */ + +#ifndef LV_CONT_H +#define LV_CONT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_CONT != 0 + +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Layout options*/ +enum +{ + LV_LAYOUT_OFF = 0, + LV_LAYOUT_CENTER, + LV_LAYOUT_COL_L, /*Column left align*/ + LV_LAYOUT_COL_M, /*Column middle align*/ + LV_LAYOUT_COL_R, /*Column right align*/ + LV_LAYOUT_ROW_T, /*Row top align*/ + LV_LAYOUT_ROW_M, /*Row middle align*/ + LV_LAYOUT_ROW_B, /*Row bottom align*/ + LV_LAYOUT_PRETTY, /*Put as many object as possible in row and begin a new row*/ + LV_LAYOUT_GRID, /*Align same-sized object into a grid*/ +}; +typedef uint8_t lv_layout_t; + +typedef struct +{ + /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/ + /*New data for this type */ + uint8_t layout :4; /*A layout from 'lv_cont_layout_t' enum*/ + uint8_t hor_fit :1; /*1: Enable horizontal fit to involve all children*/ + uint8_t ver_fit :1; /*1: Enable horizontal fit to involve all children*/ +} lv_cont_ext_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a container objects + * @param par pointer to an object, it will be the parent of the new container + * @param copy pointer to a container object, if not NULL then the new object will be copied from it + * @return pointer to the created container + */ +lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a layout on a container + * @param cont pointer to a container object + * @param layout a layout from 'lv_cont_layout_t' + */ +void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout); + + +/** + * Enable the horizontal or vertical fit. + * The container size will be set to involve the children horizontally or vertically. + * @param cont pointer to a container object + * @param hor_en true: enable the horizontal fit + * @param ver_en true: enable the vertical fit + */ +void lv_cont_set_fit(lv_obj_t * cont, bool hor_en, bool ver_en); + +/** + * Set the style of a container + * @param cont pointer to a container object + * @param style pointer to the new style + */ +static inline void lv_cont_set_style(lv_obj_t *cont, lv_style_t * style) +{ + lv_obj_set_style(cont, style); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the layout of a container + * @param cont pointer to container object + * @return the layout from 'lv_cont_layout_t' + */ +lv_layout_t lv_cont_get_layout(const lv_obj_t * cont); + +/** + * Get horizontal fit enable attribute of a container + * @param cont pointer to a container object + * @return true: horizontal fit is enabled; false: disabled + */ +bool lv_cont_get_hor_fit(const lv_obj_t * cont); + +/** + * Get vertical fit enable attribute of a container + * @param cont pointer to a container object + * @return true: vertical fit is enabled; false: disabled + */ +bool lv_cont_get_ver_fit(const lv_obj_t * cont); + + +/** + * Get that width reduced by the horizontal padding. Useful if a layout is used. + * @param cont pointer to a container object + * @return the width which still fits into the container + */ +lv_coord_t lv_cont_get_fit_width(lv_obj_t * cont); + +/** + * Get that height reduced by the vertical padding. Useful if a layout is used. + * @param cont pointer to a container object + * @return the height which still fits into the container + */ +lv_coord_t lv_cont_get_fit_height(lv_obj_t * cont); + +/** + * Get the style of a container + * @param cont pointer to a container object + * @return pointer to the container's style + */ +static inline lv_style_t * lv_cont_get_style(const lv_obj_t *cont) +{ + return lv_obj_get_style(cont); +} + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_CONT*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_CONT_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.c new file mode 100644 index 0000000..c3a0de9 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.c @@ -0,0 +1,981 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_ddlist.c + * + */ + + +/********************* + * INCLUDES + *********************/ +#include "lv_ddlist.h" +#if USE_LV_DDLIST != 0 + +#include "../lv_draw/lv_draw.h" +#include "../lv_core/lv_group.h" +#include "../lv_core/lv_indev.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_symbol_def.h" +#include "../lv_misc/lv_anim.h" +//#include + +/********************* + * DEFINES + *********************/ +#if USE_LV_ANIMATION +# ifndef LV_DDLIST_ANIM_TIME +# define LV_DDLIST_ANIM_TIME 200 /*ms*/ +# endif +#else +# undef LV_DDLIST_ANIM_TIME +# define LV_DDLIST_ANIM_TIME 0 /*No animation*/ +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param); +static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); +static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist); +static lv_res_t lv_ddlist_press_action(lv_obj_t * ddlist); +static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en); +static void lv_ddlist_pos_current_option(lv_obj_t * ddlist); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_signal_func_t ancestor_scrl_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a drop down list objects + * @param par pointer to an object, it will be the parent of the new drop down list + * @param copy pointer to a drop down list object, if not NULL then the new object will be copied from it + * @return pointer to the created drop down list + */ +lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("drop down list create started"); + + /*Create the ancestor drop down list*/ + lv_obj_t * new_ddlist = lv_page_create(par, copy); + lv_mem_assert(new_ddlist); + if(new_ddlist == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_ddlist); + if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_ddlist)); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_ddlist); + + /*Allocate the drop down list type specific extended data*/ + lv_ddlist_ext_t * ext = lv_obj_allocate_ext_attr(new_ddlist, sizeof(lv_ddlist_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + /*Initialize the allocated 'ext' */ + ext->label = NULL; + ext->action = NULL; + ext->opened = 0; + ext->fix_height = 0; + ext->sel_opt_id = 0; + ext->sel_opt_id_ori = 0; + ext->option_cnt = 0; + ext->anim_time = LV_DDLIST_ANIM_TIME; + ext->sel_style = &lv_style_plain_color; + ext->draw_arrow = 0; /*Do not draw arrow by default*/ + ext->direction_up = 0; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_ddlist, lv_ddlist_signal); + lv_obj_set_signal_func(lv_page_get_scrl(new_ddlist), lv_ddlist_scrl_signal); + lv_obj_set_design_func(new_ddlist, lv_ddlist_design); + + /*Init the new drop down list drop down list*/ + if(copy == NULL) { + lv_obj_t * scrl = lv_page_get_scrl(new_ddlist); + lv_obj_set_drag(scrl, false); + lv_page_set_scrl_fit(new_ddlist, true, true); + + ext->label = lv_label_create(new_ddlist, NULL); + lv_cont_set_fit(new_ddlist, true, false); + lv_page_set_rel_action(new_ddlist, lv_ddlist_release_action); + lv_page_set_pr_action(new_ddlist, lv_ddlist_press_action); + lv_page_set_sb_mode(new_ddlist, LV_SB_MODE_DRAG); + lv_page_set_sb_mode(new_ddlist, LV_SB_MODE_HIDE); + lv_page_set_style(new_ddlist, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); + + lv_ddlist_set_options(new_ddlist, "Option 1\nOption 2\nOption 3"); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, th->ddlist.bg); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BGO, th->ddlist.bgo); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_PR, th->ddlist.pr); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, th->ddlist.sel); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, th->ddlist.sb); + } else { + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, &lv_style_pretty); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BGO, &lv_style_pretty); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_PR, &lv_style_pretty); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, &lv_style_plain_color); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, &lv_style_pretty_color); + } + } + /*Copy an existing drop down list*/ + else { + lv_ddlist_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->label = lv_label_create(new_ddlist, copy_ext->label); + lv_label_set_text(ext->label, lv_label_get_text(copy_ext->label)); + ext->sel_opt_id = copy_ext->sel_opt_id; + ext->fix_height = copy_ext->fix_height; + ext->action = copy_ext->action; + ext->option_cnt = copy_ext->option_cnt; + ext->sel_style = copy_ext->sel_style; + ext->anim_time = copy_ext->anim_time; + ext->draw_arrow = copy_ext->draw_arrow; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_ddlist); + } + + LV_LOG_INFO("drop down list created"); + + + return new_ddlist; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set arrow draw in a drop down list + * @param ddlist pointer to drop down list object + * @param en enable/disable a arrow draw. E.g. "true" for draw. + */ +void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + /*Set the flag*/ + ext->draw_arrow = en; +} + +/** + * Set the options in a drop down list from a string + * @param ddlist pointer to drop down list object + * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" + */ +void lv_ddlist_set_options(lv_obj_t * ddlist, const char * options) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + /*Count the '\n'-s to determine the number of options*/ + ext->option_cnt = 0; + uint16_t i; + for(i = 0; options[i] != '\0'; i++) { + if(options[i] == '\n') ext->option_cnt++; + } + ext->option_cnt++; /*Last option in the at row*/ + + lv_label_set_text(ext->label, options); + lv_ddlist_refr_size(ddlist, false); +} + +/** + * Set the selected option + * @param ddlist pointer to drop down list object + * @param sel_opt id of the selected option (0 ... number of option - 1); + */ +void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + if(ext->sel_opt_id == sel_opt) return; + + ext->sel_opt_id = sel_opt < ext->option_cnt ? sel_opt : ext->option_cnt - 1; + ext->sel_opt_id_ori = ext->sel_opt_id; + /*Move the list to show the current option*/ + if(ext->opened == 0) { + lv_ddlist_pos_current_option(ddlist); + } else { + lv_obj_invalidate(ddlist); + } +} + +/** + * Set a function to call when a new option is chosen + * @param ddlist pointer to a drop down list + * @param action pointer to a call back function + */ +void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t action) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + ext->action = action; +} + +/** + * Set the fix height for the drop down list + * If 0 then the opened ddlist will be auto. sized else the set height will be applied. + * @param ddlist pointer to a drop down list + * @param h the height when the list is opened (0: auto size) + */ +void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + if(ext->fix_height == h) return; + + ext->fix_height = h; + + lv_ddlist_refr_size(ddlist, false); +} + +/** + * Enable or disable the horizontal fit to the content + * @param ddlist pointer to a drop down list + * @param en true: enable auto fit; false: disable auto fit + */ +void lv_ddlist_set_hor_fit(lv_obj_t * ddlist, bool en) +{ + lv_cont_set_fit(ddlist, en, lv_cont_get_ver_fit(ddlist)); + lv_page_set_scrl_fit(ddlist, en, lv_page_get_scrl_fit_ver(ddlist)); + + lv_ddlist_refr_size(ddlist, false); +} + +/** + * Set the open/close animation time. + * @param ddlist pointer to a drop down list + * @param anim_time: open/close animation time [ms] + */ +void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); +#if USE_LV_ANIMATION == 0 + anim_time = 0; +#endif + + ext->anim_time = anim_time; +} + +/** + * Set a style of a drop down list + * @param ddlist pointer to a drop down list object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_ddlist_set_style(lv_obj_t * ddlist, lv_ddlist_style_t type, lv_style_t * style) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + switch(type) { + case LV_DDLIST_STYLE_BG: + lv_page_set_style(ddlist, LV_PAGE_STYLE_BG, style); + break; + case LV_DDLIST_STYLE_BGO: + lv_page_set_style(ddlist, LV_PAGE_STYLE_BGO, style); + break; + case LV_DDLIST_STYLE_PR: + lv_page_set_style(ddlist, LV_PAGE_STYLE_PR, style); + break; + case LV_DDLIST_STYLE_SB: + lv_page_set_style(ddlist, LV_PAGE_STYLE_SB, style); + break; + case LV_DDLIST_STYLE_SEL: + ext->sel_style = style; + lv_obj_t * scrl = lv_page_get_scrl(ddlist); + lv_obj_refresh_ext_size(scrl); /*Because of the wider selected rectangle*/ + break; + } +} + +void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + lv_label_set_align(ext->label, align); +} + +void lv_ddlist_set_direction_up(lv_obj_t *ddlist, bool enable) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + ext->direction_up = enable; +} +/*===================== + * Getter functions + *====================*/ + +/** + * Get arrow draw in a drop down list + * @param ddlist pointer to drop down list object + */ +bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + return ext->draw_arrow; +} + +/** + * Get the options of a drop down list + * @param ddlist pointer to drop down list object + * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") + */ +const char * lv_ddlist_get_options(const lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + return lv_label_get_text(ext->label); +} + +/** + * Get the selected option + * @param ddlist pointer to drop down list object + * @return id of the selected option (0 ... number of option - 1); + */ +uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + return ext->sel_opt_id; +} + +/** + * Get the current selected option as a string + * @param ddlist pointer to ddlist object + * @param buf pointer to an array to store the string + */ +void lv_ddlist_get_selected_str(const lv_obj_t * ddlist, char * buf) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + uint16_t i; + uint16_t line = 0; + const char * opt_txt = lv_label_get_text(ext->label); + uint16_t txt_len = strlen(opt_txt); + + + for(i = 0; i < txt_len && line != ext->sel_opt_id; i++) { + if(opt_txt[i] == '\n') line ++; + } + + uint16_t c; + for(c = 0; opt_txt[i] != '\n' && i < txt_len; c++, i++) buf[c] = opt_txt[i]; + + buf[c] = '\0'; +} + +/** + * Get the "option selected" callback function + * @param ddlist pointer to a drop down list + * @return pointer to the call back function + */ +lv_action_t lv_ddlist_get_action(const lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + return ext->action; +} + +/** + * Get the fix height value. + * @param ddlist pointer to a drop down list object + * @return the height if the ddlist is opened (0: auto size) + */ +lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + return ext->fix_height; +} + +/** + * Get the open/close animation time. + * @param ddlist pointer to a drop down list + * @return open/close animation time [ms] + */ +uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + return ext->anim_time; +} + +/** + * Get a style of a drop down list + * @param ddlist pointer to a drop down list object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_ddlist_get_style(const lv_obj_t * ddlist, lv_ddlist_style_t type) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + switch(type) { + case LV_DDLIST_STYLE_BG: + return lv_page_get_style(ddlist, LV_PAGE_STYLE_BG); + case LV_DDLIST_STYLE_BGO: + return lv_page_get_style(ddlist, LV_PAGE_STYLE_BGO); + case LV_DDLIST_STYLE_PR: + return lv_page_get_style(ddlist, LV_PAGE_STYLE_PR); + case LV_DDLIST_STYLE_SB: + return lv_page_get_style(ddlist, LV_PAGE_STYLE_SB); + case LV_DDLIST_STYLE_SEL: + return ext->sel_style; + default: + return NULL; + } + + /*To avoid warning*/ + return NULL; +} + +lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + return lv_label_get_align(ext->label); +} + +/*===================== + * Other functions + *====================*/ + +/** + * Open the drop down list with or without animation + * @param ddlist pointer to drop down list object + * @param anim_en true: use animation; false: not use animations + */ +void lv_ddlist_open(lv_obj_t * ddlist, bool anim_en) +{ +#if USE_LV_ANIMATION == 0 + anim_en = false; +#endif + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + ext->opened = 1; + lv_obj_set_drag(lv_page_get_scrl(ddlist), true); + lv_ddlist_refr_size(ddlist, anim_en); +} + +/** + * Close (Collapse) the drop down list + * @param ddlist pointer to drop down list object + * @param anim_en true: use animation; false: not use animations + */ +void lv_ddlist_close(lv_obj_t * ddlist, bool anim_en) +{ +#if USE_LV_ANIMATION == 0 + anim_en = false; +#endif + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + ext->opened = 0; + lv_obj_set_drag(lv_page_get_scrl(ddlist), false); + lv_ddlist_refr_size(ddlist, anim_en); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Get the text alignment flag for a drop down list. + * @param ddlist drop down list + * @return text alignment flag + */ +static lv_txt_flag_t lv_ddlist_get_txt_flag(const lv_obj_t *ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + /*The label might be already deleted so just return with some value*/ + if(!ext->label) return LV_TXT_FLAG_CENTER; + + lv_label_align_t align = lv_label_get_align(ext->label); + + switch(align) + { + default: + case LV_LABEL_ALIGN_LEFT: + return LV_TXT_FLAG_NONE; + case LV_LABEL_ALIGN_CENTER: + return LV_TXT_FLAG_CENTER; + case LV_LABEL_ALIGN_RIGHT: + return LV_TXT_FLAG_RIGHT; + } +} + +/** + * Handle the drawing related tasks of the drop down lists + * @param ddlist pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return ancestor_design(ddlist, mask, mode); + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + ancestor_design(ddlist, mask, mode); + + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + lv_opa_t opa_scale = lv_obj_get_opa_scale(ddlist); + /*If the list is opened draw a rectangle under the selected item*/ + if(ext->opened != 0) { + lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); + const lv_font_t * font = style->text.font; + lv_coord_t font_h = lv_font_get_height(font); + + /*Draw the selected*/ + lv_area_t rect_area; + rect_area.y1 = ext->label->coords.y1; + rect_area.y1 += ext->sel_opt_id * (font_h + style->text.line_space); + rect_area.y1 -= style->text.line_space / 2; + + rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1; + rect_area.x1 = ddlist->coords.x1; + rect_area.x2 = ddlist->coords.x2; + + lv_draw_rect(&rect_area, mask, ext->sel_style, opa_scale); + } + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + /*Redraw the text on the selected area with a different color*/ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + lv_opa_t opa_scale = lv_obj_get_opa_scale(ddlist); + + /*Redraw only in opened state*/ + if(ext->opened) { + lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); + const lv_font_t * font = style->text.font; + lv_coord_t font_h = lv_font_get_height(font); + + lv_area_t area_sel; + area_sel.y1 = ext->label->coords.y1; + area_sel.y1 += ext->sel_opt_id * (font_h + style->text.line_space); + area_sel.y1 -= style->text.line_space / 2; + + area_sel.y2 = area_sel.y1 + font_h + style->text.line_space - 1; + area_sel.x1 = ddlist->coords.x1; + area_sel.x2 = ddlist->coords.x2; + lv_area_t mask_sel; + bool area_ok; + area_ok = lv_area_intersect(&mask_sel, mask, &area_sel); + if(area_ok) { + lv_style_t * sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_SEL); + lv_style_t new_style; + lv_style_copy(&new_style, style); + new_style.text.color = sel_style->text.color; + new_style.text.opa = sel_style->text.opa; + lv_txt_flag_t flag = lv_ddlist_get_txt_flag(ddlist); + lv_draw_label(&ext->label->coords, &mask_sel, &new_style, opa_scale, + lv_label_get_text(ext->label), flag, NULL); + } + } + + /*Add a down symbol in ddlist when closed*/ + else + { + /*Draw a arrow in ddlist if enabled*/ + if(ext->draw_arrow) + { + lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); + const lv_font_t * font = style->text.font; + lv_style_t * sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); + lv_coord_t font_h = lv_font_get_height(font); + lv_style_t new_style; + lv_style_copy(&new_style, style); + new_style.text.color = sel_style->text.color; + new_style.text.opa = sel_style->text.opa; + lv_area_t area_arrow; + area_arrow.x2 = ddlist->coords.x2 - style->body.padding.hor; + if (!ext->direction_up) + area_arrow.x1 = area_arrow.x2 - lv_txt_get_width(SYMBOL_DOWN, strlen(SYMBOL_DOWN), sel_style->text.font, 0, 0); + else + area_arrow.x1 = area_arrow.x2 - lv_txt_get_width(SYMBOL_UP, strlen(SYMBOL_UP), sel_style->text.font, 0, 0); + + area_arrow.y1 = ddlist->coords.y1 + style->text.line_space; + area_arrow.y2 = area_arrow.y1 + font_h; + + + lv_area_t mask_arrow; + bool area_ok; + area_ok = lv_area_intersect(&mask_arrow, mask, &area_arrow); + if (area_ok) + { + if (!ext->direction_up) + lv_draw_label(&area_arrow, &mask_arrow, &new_style, opa_scale, + SYMBOL_DOWN, LV_TXT_FLAG_NONE, NULL); /*Use a down arrow in ddlist, you can replace it with your custom symbol*/ + else + lv_draw_label(&area_arrow, &mask_arrow, &new_style, opa_scale, + SYMBOL_UP, LV_TXT_FLAG_NONE, NULL); /*Use a down arrow in ddlist, you can replace it with your custom symbol*/ + } + } + } + /*Draw the scrollbar in the ancestor page design function*/ + ancestor_design(ddlist, mask, mode); + } + + return true; +} + +/** + * Signal function of the drop down list + * @param ddlist pointer to a drop down list object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) +{ + lv_res_t res; + /* Include the ancient signal function */ + res = ancestor_signal(ddlist, sign, param); + if(res != LV_RES_OK) return res; + + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + if(sign == LV_SIGNAL_STYLE_CHG) { + //! lv_ddlist_refr_size(ddlist, 0); // uncommented in OG + } else if(sign == LV_SIGNAL_CLEANUP) { + ext->label = NULL; + } else if(sign == LV_SIGNAL_FOCUS) { +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(ddlist); + bool editing = lv_group_get_editing(g); + lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + + /*Encoders need special handling*/ + if(indev_type == LV_INDEV_TYPE_ENCODER) { + /*Open the list if editing*/ + if(editing) { + ext->opened = true; + ext->sel_opt_id_ori = ext->sel_opt_id; + lv_ddlist_refr_size(ddlist, true); + } + /*Close the lift if navigating*/ + else { + ext->opened = false; + ext->sel_opt_id = ext->sel_opt_id_ori; + lv_ddlist_refr_size(ddlist, true); + + } + } else { + /*Open the list if closed*/ + if(!ext->opened) { + ext->opened = true; + ext->sel_opt_id_ori = ext->sel_opt_id; /*Save the current value. Used to revert this state if ENER wont't be pressed*/ + lv_ddlist_refr_size(ddlist, true); + } + } +#endif + } else if(sign == LV_SIGNAL_DEFOCUS) { + if(ext->opened) { + ext->opened = false; + ext->sel_opt_id = ext->sel_opt_id_ori; + lv_ddlist_refr_size(ddlist, true); + } + } else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char *)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) { + if(!ext->opened) { + ext->opened = 1; + lv_ddlist_refr_size(ddlist, true); + } + + if(ext->sel_opt_id + 1 < ext->option_cnt) { + ext->sel_opt_id ++; + lv_ddlist_pos_current_option(ddlist); + lv_obj_invalidate(ddlist); + } + } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) { + if(!ext->opened) { + ext->opened = 1; + lv_ddlist_refr_size(ddlist, true); + } + if(ext->sel_opt_id > 0) { + ext->sel_opt_id --; + lv_ddlist_pos_current_option(ddlist); + lv_obj_invalidate(ddlist); + } + } else if(c == LV_GROUP_KEY_ENTER) { + if(ext->opened) { + ext->sel_opt_id_ori = ext->sel_opt_id; + ext->opened = 0; + if(ext->action) ext->action(ddlist); + +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(ddlist); + bool editing = lv_group_get_editing(g); + if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ +#endif + } else { + ext->opened = 1; + } + + lv_ddlist_refr_size(ddlist, true); + } else if(c == LV_GROUP_KEY_ESC) { + if(ext->opened) { + ext->opened = 0; + ext->sel_opt_id = ext->sel_opt_id_ori; + lv_ddlist_refr_size(ddlist, true); + } + } + } else if(sign == LV_SIGNAL_GET_EDITABLE) { + bool * editable = (bool *)param; + *editable = true; + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_ddlist"; + } + + return res; +} + +/** + * Signal function of the drop down list's scrollable part + * @param scrl pointer to a drop down list's scrollable part + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_scrl_signal(scrl, sign, param); + if(res != LV_RES_OK) return res; + + lv_obj_t * ddlist = lv_obj_get_parent(scrl); + + if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + /* Because of the wider selected rectangle ext. size + * In this way by dragging the scrollable part the wider rectangle area can be redrawn too*/ + lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); + if(scrl->ext_size < style->body.padding.hor) scrl->ext_size = style->body.padding.hor; + } else if(sign == LV_SIGNAL_CLEANUP) { + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + ext->label = NULL; /*The label is already deleted*/ + } + + return res; +} + +/** + * Called when a drop down list is released to open it or set new option + * @param ddlist pointer to a drop down list object + * @return LV_ACTION_RES_INV if the ddlist it deleted in the user callback else LV_ACTION_RES_OK + */ +static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + if (!lv_obj_get_click(ddlist)) return LV_RES_OK; + + if(ext->opened == 0) { /*Open the list*/ + ext->opened = 1; + lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_BG, lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BGO)); + lv_obj_set_drag(lv_page_get_scrl(ddlist), true); + } else { + ext->opened = 0; + //lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_BG, lv_ddlist_get_style(ddlist, lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_PR))); + lv_obj_set_drag(lv_page_get_scrl(ddlist), false); + + /*Search the clicked option*/ + lv_indev_t * indev = lv_indev_get_act(); + lv_point_t p; + lv_indev_get_point(indev, &p); + p.x -= ext->label->coords.x1; + p.y -= ext->label->coords.y1; + uint16_t letter_i; + letter_i = lv_label_get_letter_on(ext->label, &p); + + uint16_t new_opt = 0; + const char * txt = lv_label_get_text(ext->label); + uint32_t i = 0; + uint32_t line_cnt = 0; + uint32_t letter; + for(line_cnt = 0; line_cnt < letter_i; line_cnt++) { + letter = lv_txt_encoded_next(txt, &i); + if(letter == '\n') new_opt ++; + } + + ext->sel_opt_id = new_opt; + + if(ext->action != NULL) { + ext->action(ddlist); + } + } + lv_ddlist_refr_size(ddlist, true); + + return LV_RES_OK; +} + +static lv_res_t lv_ddlist_press_action(lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + if (!lv_obj_get_click(ddlist)) return LV_RES_OK; + + if (ext->opened == 0) + { /*Open the list*/ + lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_BG, lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_PR)); + } + else + { + //lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_BG, lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BGO)); + //lv_obj_set_drag(lv_page_get_scrl(ddlist), false); + + ///*Search the clicked option*/ + //lv_indev_t * indev = lv_indev_get_act(); + //lv_point_t p; + //lv_indev_get_point(indev, &p); + //p.x -= ext->label->coords.x1; + //p.y -= ext->label->coords.y1; + //uint16_t letter_i; + //letter_i = lv_label_get_letter_on(ext->label, &p); + + //uint16_t new_opt = 0; + //const char * txt = lv_label_get_text(ext->label); + //uint32_t i = 0; + //uint32_t line_cnt = 0; + //uint32_t letter; + //for (line_cnt = 0; line_cnt < letter_i; line_cnt++) + //{ + // letter = lv_txt_encoded_next(txt, &i); + // if (letter == '\n') new_opt++; + //} + + //ext->sel_opt_id = new_opt; + + //if (ext->action != NULL) + //{ + // ext->action(ddlist); + //} + } + + return LV_RES_OK; +} + +/** + * Refresh the size of drop down list according to its status (open or closed) + * @param ddlist pointer to a drop down list object + * @param anim_en Change the size (open/close) with or without animation (true/false) + */ +static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) +{ +#if USE_LV_ANIMATION == 0 + anim_en = false; +#endif + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + lv_style_t * style = lv_obj_get_style(ddlist); + lv_coord_t new_height, full_height; + bool current_state = 0; + + if(ext->opened) { /*Open the list*/ + if(ext->fix_height == 0) new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->body.padding.ver; + else new_height = ext->fix_height; + current_state = 1; + + lv_page_set_sb_mode(ddlist, LV_SB_MODE_UNHIDE); + } else { /*Close the list*/ + const lv_font_t * font = style->text.font; + lv_style_t * label_style = lv_obj_get_style(ext->label); + lv_coord_t font_h = lv_font_get_height(font); + new_height = font_h + 2 * label_style->text.line_space; + //full_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->body.padding.ver; + current_state = 0; + + lv_page_set_sb_mode(ddlist, LV_SB_MODE_HIDE); + } + + if(anim_en == 0 || ext->direction_up) { + lv_obj_set_height(ddlist, new_height); + if (ext->direction_up) + { + full_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) - lv_font_get_height(style->text.font); + if (current_state) + lv_obj_set_y(ddlist, lv_obj_get_y(ddlist) - full_height); + else + lv_obj_set_y(ddlist, lv_obj_get_y(ddlist) + full_height); + } + + lv_ddlist_pos_current_option(ddlist); +#if USE_LV_ANIMATION + lv_anim_del(ddlist, (lv_anim_fp_t)lv_obj_set_height); /*If an animation is in progress then it will overwrite this changes*/ + } else { + lv_anim_t a; + a.var = ddlist; + a.start = lv_obj_get_height(ddlist); + a.end = new_height; + a.fp = (lv_anim_fp_t)lv_obj_set_height; + a.path = lv_anim_path_linear; + a.end_cb = (lv_anim_cb_t)lv_ddlist_pos_current_option; + a.act_time = 0; + a.time = ext->anim_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + + lv_anim_create(&a); +#endif + } +} + +/** + * Set the position of list when it is closed to show the selected item + * @param ddlist pointer to a drop down list + */ +static void lv_ddlist_pos_current_option(lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + lv_style_t * style = lv_obj_get_style(ddlist); + const lv_font_t * font = style->text.font; + lv_coord_t font_h = lv_font_get_height(font); + lv_style_t * label_style = lv_obj_get_style(ext->label); + lv_obj_t * scrl = lv_page_get_scrl(ddlist); + + lv_coord_t h = lv_obj_get_height(ddlist); + lv_coord_t line_y1 = ext->sel_opt_id * (font_h + label_style->text.line_space) + ext->label->coords.y1 - scrl->coords.y1; + + lv_obj_set_y(scrl, - line_y1 + (h - font_h) / 2); +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.h new file mode 100644 index 0000000..758e72e --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ddlist.h @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_ddlist.h + * + */ + +#ifndef LV_DDLIST_H +#define LV_DDLIST_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_DDLIST != 0 + +/*Testing of dependencies*/ +#if USE_LV_PAGE == 0 +#error "lv_ddlist: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " +#endif + +#if USE_LV_LABEL == 0 +#error "lv_ddlist: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "../lv_objx/lv_page.h" +#include "../lv_objx/lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of drop down list*/ +typedef struct +{ + lv_page_ext_t page; /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t *label; /*Label for the options*/ + lv_style_t * sel_style; /*Style of the selected option*/ + lv_action_t action; /*Pointer to function to call when an option is selected*/ + uint16_t option_cnt; /*Number of options*/ + uint16_t sel_opt_id; /*Index of the current option*/ + uint16_t sel_opt_id_ori; /*Store the original index on focus*/ + uint16_t anim_time; /*Open/Close animation time [ms]*/ + uint8_t opened :1; /*1: The list is opened (handled by the library)*/ + uint8_t draw_arrow :1; /*1: Draw arrow*/ + uint8_t direction_up : 1; /*1: Open direction*/ + + lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/ +} lv_ddlist_ext_t; + +enum { + LV_DDLIST_STYLE_BG, + LV_DDLIST_STYLE_BGO, + LV_DDLIST_STYLE_PR, + LV_DDLIST_STYLE_SEL, + LV_DDLIST_STYLE_SB, +}; +typedef uint8_t lv_ddlist_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ +/** + * Create a drop down list objects + * @param par pointer to an object, it will be the parent of the new drop down list + * @param copy pointer to a drop down list object, if not NULL then the new object will be copied from it + * @return pointer to the created drop down list + */ +lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set arrow draw in a drop down list + * @param ddlist pointer to drop down list object + * @param en enable/disable a arrow draw. E.g. "true" for draw. + */ +void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en); + +/** + * Set the options in a drop down list from a string + * @param ddlist pointer to drop down list object + * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" + */ +void lv_ddlist_set_options(lv_obj_t * ddlist, const char * options); + +/** + * Set the selected option + * @param ddlist pointer to drop down list object + * @param sel_opt id of the selected option (0 ... number of option - 1); + */ +void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt); + +/** + * Set a function to call when a new option is chosen + * @param ddlist pointer to a drop down list + * @param action pointer to a call back function + */ +void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t action); + +/** + * Set the fix height for the drop down list + * If 0 then the opened ddlist will be auto. sized else the set height will be applied. + * @param ddlist pointer to a drop down list + * @param h the height when the list is opened (0: auto size) + */ +void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h); + +/** + * Enable or disable the horizontal fit to the content + * @param ddlist pointer to a drop down list + * @param en true: enable auto fit; false: disable auto fit + */ +void lv_ddlist_set_hor_fit(lv_obj_t * ddlist, bool en); + +/** + * Set the scroll bar mode of a drop down list + * @param ddlist pointer to a drop down list object + * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum + */ +static inline void lv_ddlist_set_sb_mode(lv_obj_t * ddlist, lv_sb_mode_t mode) +{ + lv_page_set_sb_mode(ddlist, mode); +} + +/** + * Set the open/close animation time. + * @param ddlist pointer to a drop down list + * @param anim_time: open/close animation time [ms] + */ +void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time); + + +/** + * Set a style of a drop down list + * @param ddlist pointer to a drop down list object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style); + +/** + * Set the alignment of the labels in a drop down list + * @param ddlist pointer to a drop down list object + * @param align alignment of labels + */ +void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align); + +void lv_ddlist_set_direction_up(lv_obj_t *ddlist, bool enable); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get arrow draw in a drop down list + * @param ddlist pointer to drop down list object + */ +bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist); + +/** + * Get the options of a drop down list + * @param ddlist pointer to drop down list object + * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") + */ +const char * lv_ddlist_get_options(const lv_obj_t * ddlist); + +/** + * Get the selected option + * @param ddlist pointer to drop down list object + * @return id of the selected option (0 ... number of option - 1); + */ +uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist); + +/** + * Get the current selected option as a string + * @param ddlist pointer to ddlist object + * @param buf pointer to an array to store the string + */ +void lv_ddlist_get_selected_str(const lv_obj_t * ddlist, char * buf); + +/** + * Get the "option selected" callback function + * @param ddlist pointer to a drop down list + * @return pointer to the call back function + */ +lv_action_t lv_ddlist_get_action(const lv_obj_t * ddlist); + +/** + * Get the fix height value. + * @param ddlist pointer to a drop down list object + * @return the height if the ddlist is opened (0: auto size) + */ +lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist); + +/** + * Get the scroll bar mode of a drop down list + * @param ddlist pointer to a drop down list object + * @return scrollbar mode from 'lv_page_sb_mode_t' enum + */ +static inline lv_sb_mode_t lv_ddlist_get_sb_mode(const lv_obj_t * ddlist) +{ + return lv_page_get_sb_mode(ddlist); +} + +/** + * Get the open/close animation time. + * @param ddlist pointer to a drop down list + * @return open/close animation time [ms] + */ +uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist); + +/** + * Get a style of a drop down list + * @param ddlist pointer to a drop down list object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_ddlist_get_style(const lv_obj_t *ddlist, lv_ddlist_style_t type); + +/** + * Get the alignment of the labels in a drop down list + * @param ddlist pointer to a drop down list object + * @return alignment of labels + */ +lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist); + +/*===================== + * Other functions + *====================*/ + +/** + * Open the drop down list with or without animation + * @param ddlist pointer to drop down list object + * @param anim_en true: use animation; false: not use animations + */ +void lv_ddlist_open(lv_obj_t * ddlist, bool anim_en); + +/** + * Close (Collapse) the drop down list + * @param ddlist pointer to drop down list object + * @param anim_en true: use animation; false: not use animations + */ +void lv_ddlist_close(lv_obj_t * ddlist, bool anim_en); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_DDLIST*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DDLIST_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.c new file mode 100644 index 0000000..ad2ef8d --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.c @@ -0,0 +1,466 @@ +/** + * @file lv_gauge.c + * + */ + + +/********************* + * INCLUDES + *********************/ +#include "lv_gauge.h" +#if USE_LV_GAUGE != 0 + +#include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_txt.h" +#include "../lv_misc/lv_math.h" +#include +#include + +/********************* + * DEFINES + *********************/ +#define LV_GAUGE_DEF_NEEDLE_COLOR LV_COLOR_RED +#define LV_GAUGE_DEF_LABEL_COUNT 6 +#define LV_GAUGE_DEF_LINE_COUNT 21 /*Should be: ((label_cnt - 1) * internal_lines) + 1*/ +#define LV_GAUGE_DEF_ANGLE 220 +#define LV_GAUGE_INTERPOLATE_SHIFT 5 /*Interpolate the needle drawing between to degrees*/ +#define LV_GAUGE_INTERPOLATE_MASK 0x1F + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_gauge_design(lv_obj_t * gauge, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param); +static void lv_gauge_draw_scale(lv_obj_t * gauge, const lv_area_t * mask); +static void lv_gauge_draw_needle(lv_obj_t * gauge, const lv_area_t * mask); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_design_func_t ancestor_design; +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a gauge objects + * @param par pointer to an object, it will be the parent of the new gauge + * @param copy pointer to a gauge object, if not NULL then the new object will be copied from it + * @return pointer to the created gauge + */ +lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("gauge create started"); + + /*Create the ancestor gauge*/ + lv_obj_t * new_gauge = lv_lmeter_create(par, copy); + lv_mem_assert(new_gauge); + if(new_gauge == NULL) return NULL; + + /*Allocate the gauge type specific extended data*/ + lv_gauge_ext_t * ext = lv_obj_allocate_ext_attr(new_gauge, sizeof(lv_gauge_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + /*Initialize the allocated 'ext' */ + ext->needle_count = 0; + ext->values = NULL; + ext->needle_colors = NULL; + ext->label_count = LV_GAUGE_DEF_LABEL_COUNT; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_gauge); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_gauge); + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_gauge, lv_gauge_signal); + lv_obj_set_design_func(new_gauge, lv_gauge_design); + + /*Init the new gauge gauge*/ + if(copy == NULL) { + lv_gauge_set_scale(new_gauge, LV_GAUGE_DEF_ANGLE, LV_GAUGE_DEF_LINE_COUNT, LV_GAUGE_DEF_LABEL_COUNT); + lv_gauge_set_needle_count(new_gauge, 1, NULL); + lv_gauge_set_critical_value(new_gauge, 80); + lv_obj_set_size(new_gauge, 2 * LV_DPI, 2 * LV_DPI); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_gauge_set_style(new_gauge, th->gauge); + } else { + lv_gauge_set_style(new_gauge, &lv_style_pretty_color); + } + } + /*Copy an existing gauge*/ + else { + lv_gauge_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + lv_gauge_set_needle_count(new_gauge, copy_ext->needle_count, copy_ext->needle_colors); + + uint8_t i; + for(i = 0; i < ext->needle_count; i++) { + ext->values[i] = copy_ext->values[i]; + } + ext->label_count = copy_ext->label_count; + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_gauge); + } + + LV_LOG_INFO("gauge created"); + + return new_gauge; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the number of needles + * @param gauge pointer to gauge object + * @param needle_cnt new count of needles + * @param colors an array of colors for needles (with 'num' elements) + */ +void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t * colors) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + + if(ext->needle_count != needle_cnt) { + if(ext->values != NULL) { + lv_mem_free(ext->values); + ext->values = NULL; + } + + ext->values = lv_mem_realloc(ext->values, needle_cnt * sizeof(int16_t)); + lv_mem_assert(ext->values); + if(ext->values == NULL) return; + + int16_t min = lv_gauge_get_min_value(gauge); + uint8_t n; + for(n = ext->needle_count; n < needle_cnt; n++) { + ext->values[n] = min; + } + + ext->needle_count = needle_cnt; + } + + ext->needle_colors = colors; + lv_obj_invalidate(gauge); +} + +/** + * Set the value of a needle + * @param gauge pointer to a gauge + * @param needle_id the id of the needle + * @param value the new value + */ +void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int16_t value) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + + if(needle_id >= ext->needle_count) return; + if(ext->values[needle_id] == value) return; + + + int16_t min = lv_gauge_get_min_value(gauge); + int16_t max = lv_gauge_get_max_value(gauge); + + if(value > max) value = max; + else if(value < min) value = min; + + ext->values[needle_id] = value; + + + lv_obj_invalidate(gauge); +} + + +/** + * Set the scale settings of a gauge + * @param gauge pointer to a gauge object + * @param angle angle of the scale (0..360) + * @param line_cnt count of scale lines. + * The get a given "subdivision" lines between label, `line_cnt` = (sub_div + 1) * (label_cnt - 1) + 1 + * @param label_cnt count of scale labels. + */ +void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt) +{ + /*TODO v6.0: change `line_cnt` to `subdiv_cnt`*/ + + lv_lmeter_set_scale(gauge, angle, line_cnt); + + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + ext->label_count = label_cnt; + lv_obj_invalidate(gauge); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a needle + * @param gauge pointer to gauge object + * @param needle the id of the needle + * @return the value of the needle [min,max] + */ +int16_t lv_gauge_get_value(const lv_obj_t * gauge, uint8_t needle) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + int16_t min = lv_gauge_get_min_value(gauge); + + if(needle >= ext->needle_count) return min; + + return ext->values[needle]; +} + +/** + * Get the count of needles on a gauge + * @param gauge pointer to gauge + * @return count of needles + */ +uint8_t lv_gauge_get_needle_count(const lv_obj_t * gauge) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + return ext->needle_count; +} + +/** + * Set the number of labels (and the thicker lines too) + * @param gauge pointer to a gauge object + * @return count of labels + */ +uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + return ext->label_count; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the gauges + * @param gauge pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_gauge_design(lv_obj_t * gauge, const lv_area_t * mask, lv_design_mode_t mode) +{ + + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + /* Store the real pointer because of 'lv_group' + * If the object is in focus 'lv_obj_get_style()' will give a pointer to tmp style + * and to the real object style. It is important because of style change tricks below*/ + lv_style_t * style_ori_p = gauge->style_p; + lv_style_t * style = lv_obj_get_style(gauge); + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + + lv_gauge_draw_scale(gauge, mask); + + /*Draw the ancestor line meter with max value to show the rainbow like line colors*/ + uint16_t line_cnt_tmp = ext->lmeter.line_cnt; + ancestor_design(gauge, mask, mode); /*To draw lines*/ + + /*Temporally modify the line meter to draw thicker and longer lines where labels are*/ + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style); + ext->lmeter.line_cnt = ext->label_count; /*Only to labels*/ + style_tmp.line.width = style_tmp.line.width * 2; /*Ticker lines*/ + style_tmp.body.padding.hor = style_tmp.body.padding.hor * 2; /*Longer lines*/ + gauge->style_p = &style_tmp; + + ancestor_design(gauge, mask, mode); /*To draw lines*/ + + ext->lmeter.line_cnt = line_cnt_tmp; /*Restore the parameters*/ + gauge->style_p = style_ori_p; /*Restore the ORIGINAL style pointer*/ + + lv_gauge_draw_needle(gauge, mask); + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + ancestor_design(gauge, mask, mode); + } + + return true; +} + +/** + * Signal function of the gauge + * @param gauge pointer to a gauge object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(gauge, sign, param); + if(res != LV_RES_OK) return res; + + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + if(sign == LV_SIGNAL_CLEANUP) { + lv_mem_free(ext->values); + ext->values = NULL; + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_gauge"; + } + + return res; +} + +/** + * Draw the scale on a gauge + * @param gauge pointer to gauge object + * @param mask mask of drawing + */ +static void lv_gauge_draw_scale(lv_obj_t * gauge, const lv_area_t * mask) +{ + char scale_txt[16]; + + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + lv_style_t * style = lv_obj_get_style(gauge); + lv_opa_t opa_scale = lv_obj_get_opa_scale(gauge); + lv_coord_t r = lv_obj_get_width(gauge) / 2 - (3 * style->body.padding.hor) - style->body.padding.inner; + lv_coord_t x_ofs = lv_obj_get_width(gauge) / 2 + gauge->coords.x1; + lv_coord_t y_ofs = lv_obj_get_height(gauge) / 2 + gauge->coords.y1; + int16_t scale_angle = lv_lmeter_get_scale_angle(gauge); + uint16_t label_num = ext->label_count; + int16_t angle_ofs = 90 + (360 - scale_angle) / 2; + int16_t min = lv_gauge_get_min_value(gauge); + int16_t max = lv_gauge_get_max_value(gauge); + + uint8_t i; + for(i = 0; i < label_num; i++) { + /*Calculate the position a scale label*/ + int16_t angle = (i * scale_angle) / (label_num - 1) + angle_ofs; + + lv_coord_t y = (int32_t)((int32_t)lv_trigo_sin(angle) * r) / LV_TRIGO_SIN_MAX; + y += y_ofs; + + lv_coord_t x = (int32_t)((int32_t)lv_trigo_sin(angle + 90) * r) / LV_TRIGO_SIN_MAX; + x += x_ofs; + + int16_t scale_act = (int32_t)((int32_t)(max - min) * i) / (label_num - 1); + scale_act += min; + lv_math_num_to_str(scale_act, scale_txt); + + lv_area_t label_cord; + lv_point_t label_size; + lv_txt_get_size(&label_size, scale_txt, style->text.font, + style->text.letter_space, style->text.line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); + + /*Draw the label*/ + label_cord.x1 = x - label_size.x / 2; + label_cord.y1 = y - label_size.y / 2; + label_cord.x2 = label_cord.x1 + label_size.x; + label_cord.y2 = label_cord.y1 + label_size.y; + + lv_draw_label(&label_cord, mask, style, opa_scale, scale_txt, LV_TXT_FLAG_NONE, NULL); + } +} +/** + * Draw the needles of a gauge + * @param gauge pointer to gauge object + * @param mask mask of drawing + */ +static void lv_gauge_draw_needle(lv_obj_t * gauge, const lv_area_t * mask) +{ + lv_style_t style_needle; + lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); + lv_style_t * style = lv_gauge_get_style(gauge); + lv_opa_t opa_scale = lv_obj_get_opa_scale(gauge); + + lv_coord_t r = lv_obj_get_width(gauge) / 2 - style->body.padding.hor; + lv_coord_t x_ofs = lv_obj_get_width(gauge) / 2 + gauge->coords.x1; + lv_coord_t y_ofs = lv_obj_get_height(gauge) / 2 + gauge->coords.y1; + uint16_t angle = lv_lmeter_get_scale_angle(gauge); + int16_t angle_ofs = 90 + (360 - angle) / 2; + int16_t min = lv_gauge_get_min_value(gauge); + int16_t max = lv_gauge_get_max_value(gauge); + lv_point_t p_mid; + lv_point_t p_end; + lv_point_t p_end_low; + lv_point_t p_end_high; + uint8_t i; + + lv_style_copy(&style_needle, style); + + p_mid.x = x_ofs; + p_mid.y = y_ofs; + for(i = 0; i < ext->needle_count; i++) { + /*Calculate the end point of a needle*/ + int16_t needle_angle = (ext->values[i] - min) * angle * (1 << LV_GAUGE_INTERPOLATE_SHIFT) / (max - min); //+ angle_ofs; + + + int16_t needle_angle_low = (needle_angle >> LV_GAUGE_INTERPOLATE_SHIFT) + angle_ofs; + int16_t needle_angle_high = needle_angle_low + 1; + + + p_end_low.y = (lv_trigo_sin(needle_angle_low) * r) / LV_TRIGO_SIN_MAX + y_ofs; + p_end_low.x = (lv_trigo_sin(needle_angle_low + 90) * r) / LV_TRIGO_SIN_MAX + x_ofs; + + p_end_high.y = (lv_trigo_sin(needle_angle_high) * r) / LV_TRIGO_SIN_MAX + y_ofs; + p_end_high.x = (lv_trigo_sin(needle_angle_high + 90) * r) / LV_TRIGO_SIN_MAX + x_ofs; + + uint16_t rem = needle_angle & ((1 << LV_GAUGE_INTERPOLATE_SHIFT) - 1); + int16_t x_mod = ((LV_MATH_ABS(p_end_high.x - p_end_low.x)) * rem) >> LV_GAUGE_INTERPOLATE_SHIFT; + int16_t y_mod = ((LV_MATH_ABS(p_end_high.y - p_end_low.y)) * rem) >> LV_GAUGE_INTERPOLATE_SHIFT; + + if(p_end_high.x < p_end_low.x) x_mod = -x_mod; + if(p_end_high.y < p_end_low.y) y_mod = -y_mod; + + p_end.x = p_end_low.x + x_mod; + p_end.y = p_end_low.y + y_mod; + + /*Draw the needle with the corresponding color*/ + if(ext->needle_colors == NULL) style_needle.line.color = LV_GAUGE_DEF_NEEDLE_COLOR; + else style_needle.line.color = ext->needle_colors[i]; + + lv_draw_line(&p_mid, &p_end, mask, &style_needle, opa_scale); + } + + /*Draw the needle middle area*/ + lv_style_t style_neddle_mid; + lv_style_copy(&style_neddle_mid, &lv_style_plain); + style_neddle_mid.body.main_color = style->body.border.color; + style_neddle_mid.body.grad_color = style->body.border.color; + style_neddle_mid.body.radius = LV_RADIUS_CIRCLE; + + lv_area_t nm_cord; + nm_cord.x1 = x_ofs - style->body.padding.ver; + nm_cord.y1 = y_ofs - style->body.padding.ver; + nm_cord.x2 = x_ofs + style->body.padding.ver; + nm_cord.y2 = y_ofs + style->body.padding.ver; + + lv_draw_rect(&nm_cord, mask, &style_neddle_mid, lv_obj_get_opa_scale(gauge)); +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.h new file mode 100644 index 0000000..beef9dc --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_gauge.h @@ -0,0 +1,222 @@ +/** + * @file lv_gauge.h + * + */ + +#ifndef LV_GAUGE_H +#define LV_GAUGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_GAUGE != 0 + +/*Testing of dependencies*/ +#if USE_LV_LMETER == 0 +#error "lv_gauge: lv_lmeter is required. Enable it in lv_conf.h (USE_LV_LMETER 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_lmeter.h" +#include "lv_label.h" +#include "lv_line.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of gauge*/ +typedef struct +{ + lv_lmeter_ext_t lmeter; /*Ext. of ancestor*/ + /*New data for this type */ + int16_t * values; /*Array of the set values (for needles) */ + const lv_color_t * needle_colors; /*Color of the needles (lv_color_t my_colors[needle_num])*/ + uint8_t needle_count; /*Number of needles*/ + uint8_t label_count; /*Number of labels on the scale*/ +} lv_gauge_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a gauge objects + * @param par pointer to an object, it will be the parent of the new gauge + * @param copy pointer to a gauge object, if not NULL then the new object will be copied from it + * @return pointer to the created gauge + */ +lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the number of needles + * @param gauge pointer to gauge object + * @param needle_cnt new count of needles + * @param colors an array of colors for needles (with 'num' elements) + */ +void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t * colors); + +/** + * Set the value of a needle + * @param gauge pointer to a gauge + * @param needle_id the id of the needle + * @param value the new value + */ +void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int16_t value); + +/** + * Set minimum and the maximum values of a gauge + * @param gauge pointer to he gauge object + * @param min minimum value + * @param max maximum value + */ +static inline void lv_gauge_set_range(lv_obj_t *gauge, int16_t min, int16_t max) +{ + lv_lmeter_set_range(gauge, min, max); +} + +/** + * Set a critical value on the scale. After this value 'line.color' scale lines will be drawn + * @param gauge pointer to a gauge object + * @param value the critical value + */ +static inline void lv_gauge_set_critical_value(lv_obj_t * gauge, int16_t value) +{ + lv_lmeter_set_value(gauge, value); +} + +/** + * Set the scale settings of a gauge + * @param gauge pointer to a gauge object + * @param angle angle of the scale (0..360) + * @param line_cnt count of scale lines. + * The get a given "subdivision" lines between label, `line_cnt` = (sub_div + 1) * (label_cnt - 1) + 1 + * @param label_cnt count of scale labels. + */ +void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt); + +/** + * Set the styles of a gauge + * @param gauge pointer to a gauge object + * @param bg set the style of the gauge + * */ +static inline void lv_gauge_set_style(lv_obj_t *gauge, lv_style_t *bg) +{ + lv_obj_set_style(gauge, bg); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a needle + * @param gauge pointer to gauge object + * @param needle the id of the needle + * @return the value of the needle [min,max] + */ +int16_t lv_gauge_get_value(const lv_obj_t * gauge, uint8_t needle); + +/** + * Get the count of needles on a gauge + * @param gauge pointer to gauge + * @return count of needles + */ +uint8_t lv_gauge_get_needle_count(const lv_obj_t * gauge); + +/** + * Get the minimum value of a gauge + * @param gauge pointer to a gauge object + * @return the minimum value of the gauge + */ +static inline int16_t lv_gauge_get_min_value(const lv_obj_t * lmeter) +{ + return lv_lmeter_get_min_value(lmeter); +} + +/** + * Get the maximum value of a gauge + * @param gauge pointer to a gauge object + * @return the maximum value of the gauge + */ +static inline int16_t lv_gauge_get_max_value(const lv_obj_t * lmeter) +{ + return lv_lmeter_get_max_value(lmeter); +} + +/** + * Get a critical value on the scale. + * @param gauge pointer to a gauge object + * @return the critical value + */ +static inline int16_t lv_gauge_get_critical_value(const lv_obj_t * gauge) +{ + return lv_lmeter_get_value(gauge); +} + +/** + * Set the number of labels (and the thicker lines too) + * @param gauge pointer to a gauge object + * @return count of labels + */ +uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge); + +/** + * Get the scale number of a gauge + * @param gauge pointer to a gauge object + * @return number of the scale units + */ +static inline uint8_t lv_gauge_get_line_count(const lv_obj_t * gauge) +{ + return lv_lmeter_get_line_count(gauge); +} + +/** + * Get the scale angle of a gauge + * @param gauge pointer to a gauge object + * @return angle of the scale + */ +static inline uint16_t lv_gauge_get_scale_angle(const lv_obj_t * gauge) +{ + return lv_lmeter_get_scale_angle(gauge); +} + +/** + * Get the style of a gauge + * @param gauge pointer to a gauge object + * @return pointer to the gauge's style + */ +static inline lv_style_t * lv_gauge_get_style(const lv_obj_t *gauge) +{ + return lv_obj_get_style(gauge); +} + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_GAUGE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_GAUGE_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.c new file mode 100644 index 0000000..c9fb428 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.c @@ -0,0 +1,408 @@ +/** + * @file lv_img.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_img.h" +#if USE_LV_IMG != 0 + +/*Testing of dependencies*/ +#if USE_LV_LABEL == 0 +#error "lv_img: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#endif + +#include "../lv_core/lv_lang.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_fs.h" +#include "../lv_misc/lv_ufs.h" +#include "../lv_misc/lv_txt.h" +#include "../lv_misc/lv_log.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_img_design(lv_obj_t * img, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create an image objects + * @param par pointer to an object, it will be the parent of the new button + * @param copy pointer to a image object, if not NULL then the new object will be copied from it + * @return pointer to the created image + */ +lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("image create started"); + + lv_obj_t * new_img = NULL; + + /*Create a basic object*/ + new_img = lv_obj_create(par, copy); + lv_mem_assert(new_img); + if(new_img == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_img); + + /*Extend the basic object to image object*/ + lv_img_ext_t * ext = lv_obj_allocate_ext_attr(new_img, sizeof(lv_img_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->src = NULL; + ext->src_type = LV_IMG_SRC_UNKNOWN; + ext->cf = LV_IMG_CF_UNKOWN; + ext->w = lv_obj_get_width(new_img); + ext->h = lv_obj_get_height(new_img); + ext->auto_size = 1; +#if USE_LV_MULTI_LANG + ext->lang_txt_id = LV_LANG_TXT_ID_NONE; +#endif + + /*Init the new object*/ + lv_obj_set_signal_func(new_img, lv_img_signal); + lv_obj_set_design_func(new_img, lv_img_design); + + if(copy == NULL) { + lv_obj_set_click(new_img, false); + /* Enable auto size for non screens + * because image screens are wallpapers + * and must be screen sized*/ + if(par != NULL) { + ext->auto_size = 1; + lv_obj_set_style(new_img, NULL); /*Inherit the style by default*/ + } else { + ext->auto_size = 0; + lv_obj_set_style(new_img, &lv_style_plain); /*Set a style for screens*/ + } + } else { + lv_img_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->auto_size = copy_ext->auto_size; + lv_img_set_src(new_img, copy_ext->src); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_img); + } + + + LV_LOG_INFO("image created"); + + return new_img; +} + + +/*===================== + * Setter functions + *====================*/ + + +/** + * Set the pixel map to display by the image + * @param img pointer to an image object + * @param data the image data + */ +void lv_img_set_src(lv_obj_t * img, const void * src_img) +{ + lv_img_src_t src_type = lv_img_src_get_type(src_img); + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + +#if LV_LOG_LEVEL >= LV_LOG_LEVEL_INFO + switch(src_type) { + case LV_IMG_SRC_FILE: + LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_FILE` type found"); + break; + case LV_IMG_SRC_VARIABLE: + LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_VARIABLE` type found"); + break; + case LV_IMG_SRC_SYMBOL: + LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_SYMBOL` type found"); + break; + default: + LV_LOG_WARN("lv_img_set_src: unknown type"); + } +#endif + + /*If the new source type is unknown free the memories of the old source*/ + if(src_type == LV_IMG_SRC_UNKNOWN) { + LV_LOG_WARN("lv_img_set_src: unknown image type"); + if(ext->src_type == LV_IMG_SRC_SYMBOL || ext->src_type == LV_IMG_SRC_FILE) { + lv_mem_free(ext->src); + } + ext->src = NULL; + ext->src_type = LV_IMG_SRC_UNKNOWN; + return; + } + + lv_img_header_t header; + lv_img_dsc_get_info(src_img, &header); + + + + /*Save the source*/ + if(src_type == LV_IMG_SRC_VARIABLE) { + LV_LOG_INFO("lv_img_set_src: `LV_IMG_SRC_VARIABLE` type found"); + + /*If memory was allocated because of the previous `src_type` then free it*/ + if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) { + lv_mem_free(ext->src); + } + ext->src = src_img; + } else if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_SYMBOL) { + /* If the new and the old src are the same then it was only a refresh.*/ + if(ext->src != src_img) { + /*If memory was allocated because of the previous `src_type` then free it*/ + if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) { + lv_mem_free(ext->src); + } + char * new_str = lv_mem_alloc(strlen(src_img) + 1); + lv_mem_assert(new_str); + if(new_str == NULL) return; + strcpy(new_str, src_img); + ext->src = new_str; + } + } + + if(src_type == LV_IMG_SRC_SYMBOL) { + /*`lv_img_dsc_get_info` couldn't set the with and height of a font so set it here*/ + lv_style_t * style = lv_img_get_style(img); + lv_point_t size; + lv_txt_get_size(&size, src_img, style->text.font, style->text.letter_space, style->text.line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); + header.w = size.x; + header.h = size.y; + } + + ext->src_type = src_type; + ext->w = header.w; + ext->h = header.h; + ext->cf = header.cf; + + if(lv_img_get_auto_size(img) != false) { + lv_obj_set_size(img, ext->w, ext->h); + } + + lv_obj_invalidate(img); +} + +#if USE_LV_MULTI_LANG +/** + * Set an ID which means a the same source but in different languages + * @param img pointer to an image object + * @param src_id ID of the source + */ +void lv_img_set_src_id(lv_obj_t * img, uint32_t src_id) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + ext->lang_txt_id = src_id; + + /*Apply the new language*/ + img->signal_func(img, LV_SIGNAL_LANG_CHG, NULL); +} +#endif + +/** + * Enable the auto size feature. + * If enabled the object size will be same as the picture size. + * @param img pointer to an image + * @param en true: auto size enable, false: auto size disable + */ +void lv_img_set_auto_size(lv_obj_t * img, bool en) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + ext->auto_size = (en == false ? 0 : 1); +} + + +/*===================== + * Getter functions + *====================*/ + + +/** + * Get the source of the image + * @param img pointer to an image object + * @return the image source (symbol, file name or C array) + */ +const void * lv_img_get_src(lv_obj_t * img) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + return ext->src; +} + +/** + * Get the name of the file set for an image + * @param img pointer to an image + * @return file name + */ +const char * lv_img_get_file_name(const lv_obj_t * img) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + if(ext->src_type == LV_IMG_SRC_FILE) return ext->src; + else return ""; +} + +#if USE_LV_MULTI_LANG +/** + * Get the source ID of the image. (Used by the multi-language feature) + * @param img pointer to an image + * @return ID of the source + */ +uint16_t lv_img_get_src_id(lv_obj_t * img) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + return ext->lang_txt_id; +} +#endif + +/** + * Get the auto size enable attribute + * @param img pointer to an image + * @return true: auto size is enabled, false: auto size is disabled + */ +bool lv_img_get_auto_size(const lv_obj_t * img) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + return ext->auto_size == 0 ? false : true; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the images + * @param img pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_img_design(lv_obj_t * img, const lv_area_t * mask, lv_design_mode_t mode) +{ + lv_style_t * style = lv_obj_get_style(img); + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + if(mode == LV_DESIGN_COVER_CHK) { + bool cover = false; + if(ext->src_type == LV_IMG_SRC_UNKNOWN || ext->src_type == LV_IMG_SRC_SYMBOL) return false; + + if(ext->cf == LV_IMG_CF_TRUE_COLOR || ext->cf == LV_IMG_CF_RAW) cover = lv_area_is_in(mask, &img->coords); + + return cover; + } else if(mode == LV_DESIGN_DRAW_MAIN) { + if(ext->h == 0 || ext->w == 0) return true; + lv_area_t coords; + lv_opa_t opa_scale = lv_obj_get_opa_scale(img); + + lv_obj_get_coords(img, &coords); + + if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_VARIABLE) { + LV_LOG_TRACE("lv_img_design: start to draw image"); + lv_area_t cords_tmp; + cords_tmp.y1 = coords.y1; + cords_tmp.y2 = coords.y1 + ext->h - 1; + + for(; cords_tmp.y1 < coords.y2; cords_tmp.y1 += ext->h, cords_tmp.y2 += ext->h) { + cords_tmp.x1 = coords.x1; + cords_tmp.x2 = coords.x1 + ext->w - 1; + for(; cords_tmp.x1 < coords.x2; cords_tmp.x1 += ext->w, cords_tmp.x2 += ext->w) { + lv_draw_img(&cords_tmp, mask, ext->src, style, opa_scale); + } + } + } else if(ext->src_type == LV_IMG_SRC_SYMBOL) { + LV_LOG_TRACE("lv_img_design: start to draw symbol"); + lv_style_t style_mod; + lv_style_copy(&style_mod, style); + style_mod.text.color = style->image.color; + lv_draw_label(&coords, mask, &style_mod, opa_scale, ext->src, LV_TXT_FLAG_NONE, NULL); + } else { + /*Trigger the error handler of image drawer*/ + LV_LOG_WARN("lv_img_design: image source type is unknown"); + lv_draw_img(&img->coords, mask, NULL, style, opa_scale); + } + } + + return true; +} + + +/** + * Signal function of the image + * @param img pointer to an image object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(img, sign, param); + if(res != LV_RES_OK) return res; + + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + if(sign == LV_SIGNAL_CLEANUP) { + if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) { + lv_mem_free(ext->src); + ext->src = NULL; + ext->src_type = LV_IMG_SRC_UNKNOWN; + } + } else if(sign == LV_SIGNAL_STYLE_CHG) { + /*Refresh the file name to refresh the symbol text size*/ + if(ext->src_type == LV_IMG_SRC_SYMBOL) { + lv_img_set_src(img, ext->src); + + } + } else if(sign == LV_SIGNAL_LANG_CHG) { +#if USE_LV_MULTI_LANG + if(ext->lang_txt_id != LV_LANG_TXT_ID_NONE) { + const char * lang_src = lv_lang_get_text(ext->lang_txt_id); + if(lang_src) { + lv_img_set_src(img, lang_src); + } else { + LV_LOG_WARN("lv_lang_get_text return NULL for an image's source"); + } + } +#endif + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_img"; + } + + return res; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.h new file mode 100644 index 0000000..8ee8616 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_img.h @@ -0,0 +1,195 @@ +/** + * @file lv_img.h + * + */ + +#ifndef LV_IMG_H +#define LV_IMG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_IMG != 0 + +#include "../lv_core/lv_obj.h" +#include "../lv_misc/lv_fs.h" +#include "../lv_misc/lv_symbol_def.h" +#include "lv_label.h" +#include "../lv_draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of image*/ +typedef struct +{ + /*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/ + /*New data for this type */ + const void * src; /*Image source: Pointer to an array or a file or a symbol*/ + + lv_coord_t w; /*Width of the image (Handled by the library)*/ + lv_coord_t h; /*Height of the image (Handled by the library)*/ +#if USE_LV_MULTI_LANG + uint16_t lang_txt_id; /*The ID of the image to display. */ +#endif + uint8_t src_type :2; /*See: lv_img_src_t*/ + uint8_t auto_size :1; /*1: automatically set the object size to the image size*/ + uint8_t cf :5; /*Color format from `lv_img_color_format_t`*/ +} lv_img_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an image objects + * @param par pointer to an object, it will be the parent of the new button + * @param copy pointer to a image object, if not NULL then the new object will be copied from it + * @return pointer to the created image + */ +lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the pixel map to display by the image + * @param img pointer to an image object + * @param data the image data + */ +void lv_img_set_src(lv_obj_t * img, const void * src_img); + +#if USE_LV_MULTI_LANG +/** + * Set an ID which means a the same source but on different languages + * @param img pointer to an image object + * @param src_id ID of the source + */ +void lv_img_set_src_id(lv_obj_t * img, uint32_t txt_id); +#endif + +/** + * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0. + * Use 'lv_img_set_src()' instead. + * @param img - + * @param fn - + */ +static inline void lv_img_set_file(lv_obj_t * img, const char * fn) +{ + (void) img; + (void) fn; +} + +/** + * Enable the auto size feature. + * If enabled the object size will be same as the picture size. + * @param img pointer to an image + * @param en true: auto size enable, false: auto size disable + */ +void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en); + +/** + * Set the style of an image + * @param img pointer to an image object + * @param style pointer to a style + */ +static inline void lv_img_set_style(lv_obj_t *img, lv_style_t *style) +{ + lv_obj_set_style(img, style); +} + +/** + * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 + * @param img - + * @param upscale - + */ +static inline void lv_img_set_upscale(lv_obj_t * img, bool upcale) +{ + (void) img; + (void) upcale; +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the source of the image + * @param img pointer to an image object + * @return the image source (symbol, file name or C array) + */ +const void * lv_img_get_src(lv_obj_t * img); + +/** + * Get the name of the file set for an image + * @param img pointer to an image + * @return file name + */ +const char * lv_img_get_file_name(const lv_obj_t * img); + +#if USE_LV_MULTI_LANG +/** + * Get the source ID of the image. (Used by the multi-language feature) + * @param img pointer to an image + * @return ID of the source + */ +uint16_t lv_img_get_src_id(lv_obj_t * img); +#endif + +/** + * Get the auto size enable attribute + * @param img pointer to an image + * @return true: auto size is enabled, false: auto size is disabled + */ +bool lv_img_get_auto_size(const lv_obj_t * img); + +/** + * Get the style of an image object + * @param img pointer to an image object + * @return pointer to the image's style + */ +static inline lv_style_t* lv_img_get_style(const lv_obj_t *img) +{ + return lv_obj_get_style(img); +} + +/** + * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 + * @param img - + * @return false + */ +static inline bool lv_img_get_upscale(const lv_obj_t * img) +{ + (void)img; + return false; +} + +/********************** + * MACROS + **********************/ + +/*Use this macro to declare an image in a c file*/ +#define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name; + +#endif /*USE_LV_IMG*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_IMG_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.c new file mode 100644 index 0000000..ed1d72b --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.c @@ -0,0 +1,391 @@ +/** + * @file lv_imgbtn.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_imgbtn.h" +#if USE_LV_IMGBTN != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_imgbtn_signal(lv_obj_t * imgbtn, lv_signal_t sign, void * param); +static void refr_img(lv_obj_t * imgbtn); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a image button object + * @param par pointer to an object, it will be the parent of the new image button + * @param copy pointer to a image button object, if not NULL then the new object will be copied from it + * @return pointer to the created image button + */ +lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("image button create started"); + + /*Create the ancestor of image button*/ + lv_obj_t * new_imgbtn = lv_btn_create(par, copy); + lv_mem_assert(new_imgbtn); + if(new_imgbtn == NULL) return NULL; + + /*Allocate the image button type specific extended data*/ + lv_imgbtn_ext_t * ext = lv_obj_allocate_ext_attr(new_imgbtn, sizeof(lv_imgbtn_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_imgbtn); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_imgbtn); + + /*Initialize the allocated 'ext' */ +#if LV_IMGBTN_TILED == 0 + memset(ext->img_src, 0, sizeof(ext->img_src)); +#else + memset(ext->img_src_left, 0, sizeof(ext->img_src_left)); + memset(ext->img_src_mid, 0, sizeof(ext->img_src_mid)); + memset(ext->img_src_right, 0, sizeof(ext->img_src_right)); +#endif + + ext->act_cf = LV_IMG_CF_UNKOWN; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_imgbtn, lv_imgbtn_signal); + lv_obj_set_design_func(new_imgbtn, lv_imgbtn_design); + + /*Init the new image button image button*/ + if(copy == NULL) { + + } + /*Copy an existing image button*/ + else { + lv_imgbtn_ext_t * copy_ext = lv_obj_get_ext_attr(copy); +#if LV_IMGBTN_TILED == 0 + memcpy(ext->img_src, copy_ext->img_src, sizeof(ext->img_src)); +#else + memcpy(ext->img_src_left, copy_ext->img_src_left, sizeof(ext->img_src_left)); + memcpy(ext->img_src_mid, copy_ext->img_src_mid, sizeof(ext->img_src_mid)); + memcpy(ext->img_src_right, copy_ext->img_src_right, sizeof(ext->img_src_right)); +#endif + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_imgbtn); + } + + LV_LOG_INFO("image button created"); + + return new_imgbtn; +} + +/*===================== + * Setter functions + *====================*/ + +#if LV_IMGBTN_TILED == 0 +/** + * Set images for a state of the image button + * @param imgbtn pointer to an image button object + * @param state for which state set the new image (from `lv_btn_state_t`) ` + * @param src pointer to an image source (a C array or path to a file) + */ +void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + + ext->img_src[state] = src; + + refr_img(imgbtn); +} + +#else +/** + * Set images for a state of the image button + * @param imgbtn pointer to an image button object + * @param state for which state set the new image (from `lv_btn_state_t`) ` + * @param src_left pointer to an image source for the left side of the button (a C array or path to a file) + * @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C array or path to a file) + * @param src_right pointer to an image source for the right side of the button (a C array or path to a file) + */ +void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid, const void * src_right) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + + ext->img_src_left[state] = src_left; + ext->img_src_mid[state] = src_mid; + ext->img_src_right[state] = src_right; + + refr_img(imgbtn); +} + +#endif + +/** + * Set a style of a image button. + * @param imgbtn pointer to image button object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_imgbtn_set_style(lv_obj_t * imgbtn, lv_imgbtn_style_t type, lv_style_t * style) +{ + lv_btn_set_style(imgbtn, type, style); +} + +/*===================== + * Getter functions + *====================*/ + +#if LV_IMGBTN_TILED == 0 +/** + * Get the images in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to an image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + + return ext->img_src[state]; +} +#else + +/** + * Get the left image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the left image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_btn_state_t state) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + + return ext->img_src_left[state]; +} + +/** + * Get the middle image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the middle image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_btn_state_t state) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + + return ext->img_src_mid[state]; +} + +/** + * Get the right image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the left image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_btn_state_t state) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + + return ext->img_src_right[state]; +} + +#endif + +/** + * Get style of a image button. + * @param imgbtn pointer to image button object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_imgbtn_get_style(const lv_obj_t * imgbtn, lv_imgbtn_style_t type) +{ + return lv_btn_get_style(imgbtn, type); +} + +/*===================== + * Other functions + *====================*/ + +/* + * New object specific "other" functions come here + */ + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the image buttons + * @param imgbtn pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + bool cover = false; + if(ext->act_cf == LV_IMG_CF_TRUE_COLOR || ext->act_cf == LV_IMG_CF_RAW) { + cover = lv_area_is_in(mask, &imgbtn->coords); + } + + return cover; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + /*Just draw an image*/ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + lv_btn_state_t state = lv_imgbtn_get_state(imgbtn); + lv_style_t * style = lv_imgbtn_get_style(imgbtn, state); + lv_opa_t opa_scale = lv_obj_get_opa_scale(imgbtn); + +#if LV_IMGBTN_TILED == 0 + const void * src = ext->img_src[state]; + lv_draw_img(&imgbtn->coords, mask, src, style, opa_scale); +#else + const void * src; + lv_img_header_t header; + lv_area_t coords; + lv_coord_t left_w = 0; + lv_coord_t right_w = 0; + + src = ext->img_src_left[state]; + if(src) { + lv_img_dsc_get_info(src, &header); + left_w = header.w; + coords.x1 = imgbtn->coords.x1; + coords.y1 = imgbtn->coords.y1; + coords.x2 = coords.x1 + header.w - 1; + coords.y2 = coords.y1 + header.h - 1; + lv_draw_img(&coords, mask, src, style, opa_scale); + } + + src = ext->img_src_right[state]; + if(src) { + lv_img_dsc_get_info(src, &header); + right_w = header.w; + coords.x1 = imgbtn->coords.x2 - header.w + 1; + coords.y1 = imgbtn->coords.y1; + coords.x2 = imgbtn->coords.x2; + coords.y2 = imgbtn->coords.y1 + header.h - 1; + lv_draw_img(&coords, mask, src, style, opa_scale); + } + + src = ext->img_src_mid[state]; + if(src) { + lv_coord_t obj_w = lv_obj_get_width(imgbtn); + lv_coord_t i; + lv_img_dsc_get_info(src, &header); + + coords.x1 = imgbtn->coords.x1 + left_w ; + coords.y1 = imgbtn->coords.y1; + coords.x2 = coords.x1 + header.w - 1; + coords.y2 = imgbtn->coords.y1 + header.h - 1; + + for(i = 0; i < obj_w - right_w - left_w; i += header.w) { + lv_draw_img(&coords, mask, src, style, opa_scale); + coords.x1 = coords.x2 + 1; + coords.x2 += header.w; + } + } + + +#endif + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the image button + * @param imgbtn pointer to a image button object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_imgbtn_signal(lv_obj_t * imgbtn, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(imgbtn, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_STYLE_CHG) { + /* If the style changed then the button was clicked, released etc. so probably the state was changed as well + * Set the new image for the new state.*/ + refr_img(imgbtn); + } else if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_imgbtn"; + } + + return res; +} + + +static void refr_img(lv_obj_t * imgbtn) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + lv_btn_state_t state = lv_imgbtn_get_state(imgbtn); + lv_img_header_t header; + +#if LV_IMGBTN_TILED == 0 + const void * src = ext->img_src[state]; +#else + const void * src = ext->img_src_mid[state]; +#endif + + lv_res_t info_res; + info_res = lv_img_dsc_get_info(src, &header); + if(info_res == LV_RES_OK) { + ext->act_cf = header.cf; +#if LV_IMGBTN_TILED == 0 + lv_obj_set_size(imgbtn, header.w, header.h); +#else + lv_obj_set_height(imgbtn, header.h); +#endif + } else { + ext->act_cf = LV_IMG_CF_UNKOWN; + } + + lv_obj_invalidate(imgbtn); +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.h new file mode 100644 index 0000000..300e7b8 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_imgbtn.h @@ -0,0 +1,249 @@ +/** + * @file lv_imgbtn.h + * + */ + +#ifndef LV_IMGBTN_H +#define LV_IMGBTN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_IMGBTN != 0 + +/*Testing of dependencies*/ +#if USE_LV_BTN == 0 +#error "lv_imgbtn: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_btn.h" +#include "../lv_draw/lv_draw_img.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of image button*/ +typedef struct { + lv_btn_ext_t btn; /*Ext. of ancestor*/ + /*New data for this type */ + int idx; +#if LV_IMGBTN_TILED == 0 + const void * img_src[LV_BTN_STATE_NUM]; /*Store images to each state*/ +#else + const void * img_src_left[LV_BTN_STATE_NUM]; /*Store left side images to each state*/ + const void * img_src_mid[LV_BTN_STATE_NUM]; /*Store center images to each state*/ + const void * img_src_right[LV_BTN_STATE_NUM]; /*Store right side images to each state*/ +#endif + lv_img_cf_t act_cf; /*Color format of the currently active image*/ +} lv_imgbtn_ext_t; + + +/*Styles*/ +enum { + LV_IMGBTN_STYLE_REL, + LV_IMGBTN_STYLE_PR, + LV_IMGBTN_STYLE_TGL_REL, + LV_IMGBTN_STYLE_TGL_PR, + LV_IMGBTN_STYLE_INA, +}; +typedef uint8_t lv_imgbtn_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a image button objects + * @param par pointer to an object, it will be the parent of the new image button + * @param copy pointer to a image button object, if not NULL then the new object will be copied from it + * @return pointer to the created image button + */ +lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + + +/*===================== + * Setter functions + *====================*/ + +#if LV_IMGBTN_TILED == 0 +/** + * Set images for a state of the image button + * @param imgbtn pointer to an image button object + * @param state for which state set the new image (from `lv_btn_state_t`) ` + * @param src pointer to an image source (a C array or path to a file) + */ +void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src); +#else +/** + * Set images for a state of the image button + * @param imgbtn pointer to an image button object + * @param state for which state set the new image (from `lv_btn_state_t`) ` + * @param src_left pointer to an image source for the left side of the button (a C array or path to a file) + * @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C array or path to a file) + * @param src_right pointer to an image source for the right side of the button (a C array or path to a file) + */ +void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid, const void * src_right); + +#endif + +/** + * Enable the toggled states. On release the button will change from/to toggled state. + * @param imgbtn pointer to an image button object + * @param tgl true: enable toggled states, false: disable + */ +static inline void lv_imgbtn_set_toggle(lv_obj_t * imgbtn, bool tgl) +{ + lv_btn_set_toggle(imgbtn, tgl); +} + +/** + * Set the state of the image button + * @param imgbtn pointer to an image button object + * @param state the new state of the button (from lv_btn_state_t enum) + */ +static inline void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_btn_state_t state) +{ + lv_btn_set_state(imgbtn, state); +} + +/** + * Toggle the state of the image button (ON->OFF, OFF->ON) + * @param imgbtn pointer to a image button object + */ +static inline void lv_imgbtn_toggle(lv_obj_t * imgbtn) +{ + lv_btn_toggle(imgbtn); +} + +/** + * Set a function to call when a button event happens + * @param imgbtn pointer to an image button object + * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) + */ +static inline void lv_imgbtn_set_action(lv_obj_t * imgbtn, lv_btn_action_t type, lv_action_t action) +{ + lv_btn_set_action(imgbtn, type, action); +} + +/** + * Set a style of a image button. + * @param imgbtn pointer to image button object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_imgbtn_set_style(lv_obj_t * imgbtn, lv_imgbtn_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + + +#if LV_IMGBTN_TILED == 0 +/** + * Get the images in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to an image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state); + +#else + +/** + * Get the left image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the left image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_btn_state_t state); + +/** + * Get the middle image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the middle image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_btn_state_t state); + +/** + * Get the right image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the left image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_btn_state_t state); + +#endif +/** + * Get the current state of the image button + * @param imgbtn pointer to a image button object + * @return the state of the button (from lv_btn_state_t enum) + */ +static inline lv_btn_state_t lv_imgbtn_get_state(const lv_obj_t * imgbtn) +{ + return lv_btn_get_state(imgbtn); +} + +/** + * Get the toggle enable attribute of the image button + * @param imgbtn pointer to a image button object + * @return ture: toggle enabled, false: disabled + */ +static inline bool lv_imgbtn_get_toggle(const lv_obj_t * imgbtn) +{ + return lv_btn_get_toggle(imgbtn); +} + +/** + * Get the release action of a image button + * @param imgbtn pointer to a image button object + * @return pointer to the release action function + */ +static inline lv_action_t lv_imgbtn_get_action(const lv_obj_t * imgbtn, lv_btn_action_t type) +{ + return lv_btn_get_action(imgbtn, type); +} + +/** + * Get style of a image button. + * @param imgbtn pointer to image button object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_imgbtn_get_style(const lv_obj_t * imgbtn, lv_imgbtn_style_t type); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_IMGBTN*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_IMGBTN_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.c new file mode 100644 index 0000000..395fc8d --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.c @@ -0,0 +1,465 @@ + +/** + * @file lv_kb.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_kb.h" +#if USE_LV_KB != 0 + +#include "lv_ta.h" +#include "../lv_themes/lv_theme.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param); +static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +static const char * kb_map_lc[] = { + "\2051#", "\204q", "\204w", "\204e", "\204r", "\204t", "\204y", "\204u", "\204i", "\204o", "\204p", "\207Bksp", "\n", + "\226ABC", "\203a", "\203s", "\203d", "\203f", "\203g", "\203h", "\203j", "\203k", "\203l", "\207Enter", "\n", + "_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n", + "\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, "" +}; + +static const char * kb_map_uc[] = { + "\2051#", "\204Q", "\204W", "\204E", "\204R", "\204T", "\204Y", "\204U", "\204I", "\204O", "\204P", "\207Bksp", "\n", + "\226abc", "\203A", "\203S", "\203D", "\203F", "\203G", "\203H", "\203J", "\203K", "\203L", "\207Enter", "\n", + "_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n", + "\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, "" +}; + +static const char * kb_map_spec[] = { + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\202Bksp", "\n", + "\222abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", + "\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n", + "\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, "" +}; + +static const char * kb_map_num[] = { + "1", "2", "3", "\202"SYMBOL_CLOSE, "\n", + "4", "5", "6", "\202"SYMBOL_OK, "\n", + "7", "8", "9", "\202Bksp", "\n", + "+/-", "0", ".", SYMBOL_LEFT, SYMBOL_RIGHT, "" +}; +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a keyboard objects + * @param par pointer to an object, it will be the parent of the new keyboard + * @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it + * @return pointer to the created keyboard + */ +lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("keyboard create started"); + + /*Create the ancestor of keyboard*/ + lv_obj_t * new_kb = lv_btnm_create(par, copy); + lv_mem_assert(new_kb); + if(new_kb == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_kb); + + /*Allocate the keyboard type specific extended data*/ + lv_kb_ext_t * ext = lv_obj_allocate_ext_attr(new_kb, sizeof(lv_kb_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + /*Initialize the allocated 'ext' */ + + ext->ta = NULL; + ext->mode = LV_KB_MODE_TEXT; + ext->cursor_mng = 0; + ext->hide_action = NULL; + ext->ok_action = NULL; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_kb, lv_kb_signal); + + /*Init the new keyboard keyboard*/ + if(copy == NULL) { + lv_obj_set_size(new_kb, LV_HOR_RES, LV_VER_RES / 2); + lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_btnm_set_action(new_kb, lv_kb_def_action); + lv_btnm_set_map(new_kb, kb_map_lc); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_kb_set_style(new_kb, LV_KB_STYLE_BG, th->kb.bg); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_REL, th->kb.btn.rel); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_PR, th->kb.btn.pr); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_REL, th->kb.btn.tgl_rel); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_PR, th->kb.btn.tgl_pr); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_INA, th->kb.btn.ina); + } else { + /*Let the button matrix's styles*/ + } + } + /*Copy an existing keyboard*/ + else { + lv_kb_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->ta = NULL; + ext->ta = copy_ext->ta; + ext->mode = copy_ext->mode; + ext->cursor_mng = copy_ext->cursor_mng; + ext->hide_action = copy_ext->hide_action; + ext->ok_action = copy_ext->ok_action; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_kb); + } + + + LV_LOG_INFO("keyboard created"); + + + return new_kb; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @param ta pointer to a Text Area object to write there + */ +void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + lv_cursor_type_t cur_type; + + /*Hide the cursor of the old Text area if cursor management is enabled*/ + if(ext->ta && ext->cursor_mng) { + cur_type = lv_ta_get_cursor_type(ext->ta); + lv_ta_set_cursor_type(ext->ta, cur_type | LV_CURSOR_HIDDEN); + } + + ext->ta = ta; + + /*Show the cursor of the new Text area if cursor management is enabled*/ + if(ext->ta && ext->cursor_mng) { + cur_type = lv_ta_get_cursor_type(ext->ta); + lv_ta_set_cursor_type(ext->ta, cur_type & (~LV_CURSOR_HIDDEN)); + } +} + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @param mode the mode from 'lv_kb_mode_t' + */ +void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + if(ext->mode == mode) return; + + ext->mode = mode; + if(mode == LV_KB_MODE_TEXT) lv_btnm_set_map(kb, kb_map_lc); + else if(mode == LV_KB_MODE_NUM) lv_btnm_set_map(kb, kb_map_num); +} + + +/** + * Automatically hide or show the cursor of Text Area + * @param kb pointer to a Keyboard object + * @param en true: show cursor on the current text area, false: hide cursor + */ +void lv_kb_set_cursor_manage(lv_obj_t * kb, bool en) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + if(ext->cursor_mng == en) return; + + ext->cursor_mng = en == false ? 0 : 1; + + if(ext->ta) { + lv_cursor_type_t cur_type; + cur_type = lv_ta_get_cursor_type(ext->ta); + + if(ext->cursor_mng) { + lv_ta_set_cursor_type(ext->ta, cur_type & (~LV_CURSOR_HIDDEN)); + } else { + lv_ta_set_cursor_type(ext->ta, cur_type | LV_CURSOR_HIDDEN); + } + } +} + +/** + * Set call back to call when the "Ok" button is pressed + * @param kb pointer to Keyboard object + * @param action a callback with 'lv_action_t' type + */ +void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + ext->ok_action = action; +} + +/** + * Set call back to call when the "Hide" button is pressed + * @param kb pointer to Keyboard object + * @param action a callback with 'lv_action_t' type + */ +void lv_kb_set_hide_action(lv_obj_t * kb, lv_action_t action) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + ext->hide_action = action; +} + +/** + * Set a style of a keyboard + * @param kb pointer to a keyboard object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_kb_set_style(lv_obj_t * kb, lv_kb_style_t type, lv_style_t * style) +{ + switch(type) { + case LV_KB_STYLE_BG: + lv_btnm_set_style(kb, LV_BTNM_STYLE_BG, style); + break; + case LV_KB_STYLE_BTN_REL: + lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_REL, style); + break; + case LV_KB_STYLE_BTN_PR: + lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_PR, style); + break; + case LV_KB_STYLE_BTN_TGL_REL: + lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_REL, style); + break; + case LV_KB_STYLE_BTN_TGL_PR: + lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_PR, style); + break; + case LV_KB_STYLE_BTN_INA: + lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_INA, style); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @return pointer to the assigned Text Area object + */ +lv_obj_t * lv_kb_get_ta(const lv_obj_t * kb) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + return ext->ta; +} + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @return the current mode from 'lv_kb_mode_t' + */ +lv_kb_mode_t lv_kb_get_mode(const lv_obj_t * kb) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + return ext->mode; +} + + +/** + * Get the current cursor manage mode. + * @param kb pointer to a Keyboard object + * @return true: show cursor on the current text area, false: hide cursor + */ +bool lv_kb_get_cursor_manage(const lv_obj_t * kb) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + return ext->cursor_mng == 0 ? false : true; +} + +/** + * Get the callback to call when the "Ok" button is pressed + * @param kb pointer to Keyboard object + * @return the ok callback + */ +lv_action_t lv_kb_get_ok_action(const lv_obj_t * kb) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + return ext->ok_action; +} + +/** + * Get the callback to call when the "Hide" button is pressed + * @param kb pointer to Keyboard object + * @return the close callback + */ +lv_action_t lv_kb_get_hide_action(const lv_obj_t * kb) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + return ext->hide_action; +} + +/** + * Get a style of a keyboard + * @param kb pointer to a keyboard object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_kb_get_style(const lv_obj_t * kb, lv_kb_style_t type) +{ + lv_style_t * style = NULL; + + switch(type) { + case LV_KB_STYLE_BG: + style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BG); + break; + case LV_KB_STYLE_BTN_REL: + style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_REL); + break; + case LV_KB_STYLE_BTN_PR: + style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_PR); + break; + case LV_KB_STYLE_BTN_TGL_REL: + style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_REL); + break; + case LV_KB_STYLE_BTN_TGL_PR: + style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_PR); + break; + case LV_KB_STYLE_BTN_INA: + style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_INA); + break; + default: + style = NULL; + break; + } + + return style; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the keyboard + * @param kb pointer to a keyboard object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(kb, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_kb"; + } + + return res; +} + +/** + * Called when a button of 'kb_btnm' is released + * @param btnm pointer to 'kb_btnm' + * @param i the index of the released button from the current btnm map + * @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK + */ +static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt) +{ + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + lv_res_t res = LV_RES_OK; + + /*Do the corresponding action according to the text of the button*/ + if(strcmp(txt, "abc") == 0) { + lv_btnm_set_map(kb, kb_map_lc); + return LV_RES_OK; + } else if(strcmp(txt, "ABC") == 0) { + lv_btnm_set_map(kb, kb_map_uc); + return LV_RES_OK; + } else if(strcmp(txt, "1#") == 0) { + lv_btnm_set_map(kb, kb_map_spec); + return LV_RES_OK; + } else if(strcmp(txt, SYMBOL_CLOSE) == 0) { + if(ext->hide_action) res = ext->hide_action(kb); + else { + lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ + lv_obj_del(kb); + } + return res; + } else if(strcmp(txt, SYMBOL_OK) == 0) { + if(ext->ok_action) res = ext->ok_action(kb); + else { + lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ + res = lv_obj_del(kb); + } + return res; + } + + if(res != LV_RES_OK) return res; /*The keyboard might be deleted in the actions*/ + + /*Add the characters to the text area if set*/ + if(ext->ta == NULL) return res; + + if(strcmp(txt, "Enter") == 0)lv_ta_add_char(ext->ta, '\n'); + else if(strcmp(txt, SYMBOL_LEFT) == 0) lv_ta_cursor_left(ext->ta); + else if(strcmp(txt, SYMBOL_RIGHT) == 0) lv_ta_cursor_right(ext->ta); + else if(strcmp(txt, "Bksp") == 0) lv_ta_del_char(ext->ta); + else if(strcmp(txt, "+/-") == 0) { + uint16_t cur = lv_ta_get_cursor_pos(ext->ta); + const char * ta_txt = lv_ta_get_text(ext->ta); + if(ta_txt[0] == '-') { + lv_ta_set_cursor_pos(ext->ta, 1); + lv_ta_del_char(ext->ta); + lv_ta_add_char(ext->ta, '+'); + lv_ta_set_cursor_pos(ext->ta, cur); + } else if(ta_txt[0] == '+') { + lv_ta_set_cursor_pos(ext->ta, 1); + lv_ta_del_char(ext->ta); + lv_ta_add_char(ext->ta, '-'); + lv_ta_set_cursor_pos(ext->ta, cur); + } else { + lv_ta_set_cursor_pos(ext->ta, 0); + lv_ta_add_char(ext->ta, '-'); + lv_ta_set_cursor_pos(ext->ta, cur + 1); + } + } else { + lv_ta_add_text(ext->ta, txt); + } + return LV_RES_OK; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.h new file mode 100644 index 0000000..c729a4e --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_kb.h @@ -0,0 +1,199 @@ +/** + * @file lv_kb.h + * + */ + +#ifndef LV_KB_H +#define LV_KB_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_KB != 0 + +/*Testing of dependencies*/ +#if USE_LV_BTNM == 0 +#error "lv_kb: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " +#endif + +#if USE_LV_TA == 0 +#error "lv_kb: lv_ta is required. Enable it in lv_conf.h (USE_LV_TA 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_btnm.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_KB_MODE_TEXT, + LV_KB_MODE_NUM, +}; +typedef uint8_t lv_kb_mode_t; + +/*Data of keyboard*/ +typedef struct { + lv_btnm_ext_t btnm; /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t *ta; /*Pointer to the assigned text area*/ + lv_kb_mode_t mode; /*Key map type*/ + uint8_t cursor_mng :1; /*1: automatically show/hide cursor when a text area is assigned or left*/ + lv_action_t ok_action; /*Called when the "Ok" button is clicked*/ + lv_action_t hide_action; /*Called when the "Hide" button is clicked*/ +} lv_kb_ext_t; + +enum { + LV_KB_STYLE_BG, + LV_KB_STYLE_BTN_REL, + LV_KB_STYLE_BTN_PR, + LV_KB_STYLE_BTN_TGL_REL, + LV_KB_STYLE_BTN_TGL_PR, + LV_KB_STYLE_BTN_INA, +}; +typedef uint8_t lv_kb_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a keyboard objects + * @param par pointer to an object, it will be the parent of the new keyboard + * @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it + * @return pointer to the created keyboard + */ +lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @param ta pointer to a Text Area object to write there + */ +void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta); + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @param mode the mode from 'lv_kb_mode_t' + */ +void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode); + +/** + * Automatically hide or show the cursor of the current Text Area + * @param kb pointer to a Keyboard object + * @param en true: show cursor on the current text area, false: hide cursor + */ +void lv_kb_set_cursor_manage(lv_obj_t * kb, bool en); + +/** + * Set call back to call when the "Ok" button is pressed + * @param kb pointer to Keyboard object + * @param action a callback with 'lv_action_t' type + */ +void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action); + +/** + * Set call back to call when the "Hide" button is pressed + * @param kb pointer to Keyboard object + * @param action a callback with 'lv_action_t' type + */ +void lv_kb_set_hide_action(lv_obj_t * kb, lv_action_t action); + +/** + * Set a new map for the keyboard + * @param kb pointer to a Keyboard object + * @param map pointer to a string array to describe the map. + * See 'lv_btnm_set_map()' for more info. + */ +static inline void lv_kb_set_map(lv_obj_t *kb, const char ** map) +{ + lv_btnm_set_map(kb, map); +} + +/** + * Set a style of a keyboard + * @param kb pointer to a keyboard object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_kb_set_style(lv_obj_t *kb, lv_kb_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @return pointer to the assigned Text Area object + */ +lv_obj_t * lv_kb_get_ta(const lv_obj_t * kb); + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @return the current mode from 'lv_kb_mode_t' + */ +lv_kb_mode_t lv_kb_get_mode(const lv_obj_t * kb); + +/** + * Get the current cursor manage mode. + * @param kb pointer to a Keyboard object + * @return true: show cursor on the current text area, false: hide cursor + */ +bool lv_kb_get_cursor_manage(const lv_obj_t * kb); + +/** + * Get the callback to call when the "Ok" button is pressed + * @param kb pointer to Keyboard object + * @return the ok callback + */ +lv_action_t lv_kb_get_ok_action(const lv_obj_t * kb); + +/** + * Get the callback to call when the "Hide" button is pressed + * @param kb pointer to Keyboard object + * @return the close callback + */ +lv_action_t lv_kb_get_hide_action(const lv_obj_t * kb); + +/** + * Get a style of a keyboard + * @param kb pointer to a keyboard object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_kb_get_style(const lv_obj_t *kb, lv_kb_style_t type); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_KB*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_KB_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.c new file mode 100644 index 0000000..77b087a --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.c @@ -0,0 +1,987 @@ +/** + * @file lv_rect.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_label.h" +#if USE_LV_LABEL != 0 + +#include "../lv_core/lv_obj.h" +#include "../lv_core/lv_group.h" +#include "../lv_core/lv_lang.h" +#include "../lv_draw/lv_draw.h" +#include "../lv_misc/lv_color.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +/*Test configurations*/ +#ifndef LV_LABEL_SCROLL_SPEED +#define LV_LABEL_SCROLL_SPEED (25) /*Hor, or ver. scroll speed (px/sec) in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/ +#endif + +#define ANIM_WAIT_CHAR_COUNT 3 + +#define LV_LABEL_DOT_END_INV 0xFFFF + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param); +static bool lv_label_design(lv_obj_t * label, const lv_area_t * mask, lv_design_mode_t mode); +static void lv_label_refr_text(lv_obj_t * label); +static void lv_label_revert_dots(lv_obj_t * label); + +#if USE_LV_ANIMATION +static void lv_label_set_offset_x(lv_obj_t * label, lv_coord_t x); +static void lv_label_set_offset_y(lv_obj_t * label, lv_coord_t y); +#endif +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a label objects + * @param par pointer to an object, it will be the parent of the new label + * @param copy pointer to a button object, if not NULL then the new object will be copied from it + * @return pointer to the created button + */ +lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("label create started"); + + /*Create a basic object*/ + lv_obj_t * new_label = lv_obj_create(par, copy); + lv_mem_assert(new_label); + if(new_label == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_label); + + /*Extend the basic object to a label object*/ + lv_obj_allocate_ext_attr(new_label, sizeof(lv_label_ext_t)); + + lv_label_ext_t * ext = lv_obj_get_ext_attr(new_label); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->text = NULL; + ext->static_txt = 0; + ext->recolor = 0; + ext->body_draw = 0; + ext->align = LV_LABEL_ALIGN_LEFT; + ext->dot_end = LV_LABEL_DOT_END_INV; + ext->long_mode = LV_LABEL_LONG_EXPAND; + ext->anim_speed = LV_LABEL_SCROLL_SPEED; + ext->offset.x = 0; + ext->offset.y = 0; +#if USE_LV_MULTI_LANG + ext->lang_txt_id = LV_LANG_TXT_ID_NONE; +#endif + lv_obj_set_design_func(new_label, lv_label_design); + lv_obj_set_signal_func(new_label, lv_label_signal); + + /*Init the new label*/ + if(copy == NULL) { + lv_obj_set_click(new_label, false); + lv_label_set_long_mode(new_label, LV_LABEL_LONG_EXPAND); + lv_label_set_text(new_label, "Text"); + lv_label_set_style(new_label, NULL); /*Inherit parent's style*/ + } + /*Copy 'copy' if not NULL*/ + else { + lv_label_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + lv_label_set_long_mode(new_label, lv_label_get_long_mode(copy)); + lv_label_set_recolor(new_label, lv_label_get_recolor(copy)); + lv_label_set_body_draw(new_label, lv_label_get_body_draw(copy)); + lv_label_set_align(new_label, lv_label_get_align(copy)); + if(copy_ext->static_txt == 0) lv_label_set_text(new_label, lv_label_get_text(copy)); + else lv_label_set_static_text(new_label, lv_label_get_text(copy)); + + /*In DOT mode save the text byte-to-byte because a '\0' can be in the middle*/ + if(copy_ext->long_mode == LV_LABEL_LONG_DOT) { + ext->text = lv_mem_realloc(ext->text, lv_mem_get_size(copy_ext->text)); + lv_mem_assert(ext->text); + if(ext->text == NULL) return NULL; + memcpy(ext->text, copy_ext->text, lv_mem_get_size(copy_ext->text)); + } + + memcpy(ext->dot_tmp, copy_ext->dot_tmp, sizeof(ext->dot_tmp)); + ext->dot_end = copy_ext->dot_end; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_label); + } + + + LV_LOG_INFO("label created"); + + return new_label; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new text for a label. Memory will be allocated to store the text by the label. + * @param label pointer to a label object + * @param text '\0' terminated character string. NULL to refresh with the current text. + */ +void lv_label_set_text(lv_obj_t * label, const char * text) +{ + lv_obj_invalidate(label); + + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + + /*If text is NULL then refresh */ + if(text == NULL) { + lv_label_refr_text(label); + return; + } + + if(ext->text == text) { + /*If set its own text then reallocate it (maybe its size changed)*/ + ext->text = lv_mem_realloc(ext->text, strlen(ext->text) + 1); + lv_mem_assert(ext->text); + if(ext->text == NULL) return; + } else { + /*Allocate space for the new text*/ + uint32_t len = strlen(text) + 1; + if(ext->text != NULL && ext->static_txt == 0) { + lv_mem_free(ext->text); + ext->text = NULL; + } + + ext->text = lv_mem_alloc(len); + lv_mem_assert(ext->text); + if(ext->text == NULL) return; + + strcpy(ext->text, text); + ext->static_txt = 0; /*Now the text is dynamically allocated*/ + } + + lv_label_refr_text(label); +} + +/** + * Set a new text for a label from a character array. The array don't has to be '\0' terminated. + * Memory will be allocated to store the array by the label. + * @param label pointer to a label object + * @param array array of characters or NULL to refresh the label + * @param size the size of 'array' in bytes + */ +void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size) +{ + lv_obj_invalidate(label); + + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + + /*If trying to set its own text or the array is NULL then refresh */ + if(array == ext->text || array == NULL) { + lv_label_refr_text(label); + return; + } + + /*Allocate space for the new text*/ + if(ext->text != NULL && ext->static_txt == 0) { + lv_mem_free(ext->text); + ext->text = NULL; + } + ext->text = lv_mem_alloc(size + 1); + lv_mem_assert(ext->text); + if(ext->text == NULL) return; + + memcpy(ext->text, array, size); + ext->text[size] = '\0'; + ext->static_txt = 0; /*Now the text is dynamically allocated*/ + + lv_label_refr_text(label); +} + +/** + * Set a static text. It will not be saved by the label so the 'text' variable + * has to be 'alive' while the label exist. + * @param label pointer to a label object + * @param text pointer to a text. NULL to refresh with the current text. + */ +void lv_label_set_static_text(lv_obj_t * label, const char * text) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + if(ext->static_txt == 0 && ext->text != NULL) { + lv_mem_free(ext->text); + ext->text = NULL; + } + + if(text != NULL) { + ext->static_txt = 1; + ext->text = (char *) text; + } + + lv_label_refr_text(label); +} + +#if USE_LV_MULTI_LANG +/** + *Set a text ID which refers a the same text but in a different languages + * @param label pointer to a label object + * @param txt_id ID of the text + */ +void lv_label_set_text_id(lv_obj_t * label, uint32_t txt_id) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + ext->lang_txt_id = txt_id; + + /*Apply the new language*/ + label->signal_func(label, LV_SIGNAL_LANG_CHG, NULL); +} +#endif + +/** + * Set the behavior of the label with longer text then the object size + * @param label pointer to a label object + * @param long_mode the new mode from 'lv_label_long_mode' enum. + * In LV_LONG_BREAK/LONG/ROLL the size of the label should be set AFTER this function + */ +void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + +#if USE_LV_ANIMATION + /*Delete the old animation (if exists)*/ + lv_anim_del(label, (lv_anim_fp_t) lv_obj_set_x); + lv_anim_del(label, (lv_anim_fp_t) lv_obj_set_y); + lv_anim_del(label, (lv_anim_fp_t) lv_label_set_offset_x); + lv_anim_del(label, (lv_anim_fp_t) lv_label_set_offset_y); +#endif + ext->offset.x = 0; + ext->offset.y = 0; + + if(long_mode == LV_LABEL_LONG_ROLL || long_mode == LV_LABEL_LONG_CROP) ext->expand = 1; + else ext->expand = 0; + + /*Restore the character under the dots*/ + if(ext->long_mode == LV_LABEL_LONG_DOT && ext->dot_end != LV_LABEL_DOT_END_INV) { + lv_label_revert_dots(label); + } + + ext->long_mode = long_mode; + lv_label_refr_text(label); +} + +/** + * Set the align of the label (left or center) + * @param label pointer to a label object + * @param align 'LV_LABEL_ALIGN_LEFT' or 'LV_LABEL_ALIGN_LEFT' + */ +void lv_label_set_align(lv_obj_t * label, lv_label_align_t align) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + if(ext->align == align) return; + + ext->align = align; + + lv_obj_invalidate(label); /*Enough to invalidate because alignment is only drawing related (lv_refr_label_text() not required)*/ +} + +/** + * Enable the recoloring by in-line commands + * @param label pointer to a label object + * @param en true: enable recoloring, false: disable + */ +void lv_label_set_recolor(lv_obj_t * label, bool en) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + if(ext->recolor == en) return; + + ext->recolor = en == false ? 0 : 1; + + lv_label_refr_text(label); /*Refresh the text because the potential colo codes in text needs to be hided or revealed*/ +} + +/** + * Set the label to draw (or not draw) background specified in its style's body + * @param label pointer to a label object + * @param en true: draw body; false: don't draw body + */ +void lv_label_set_body_draw(lv_obj_t * label, bool en) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + if(ext->body_draw == en) return; + + ext->body_draw = en == false ? 0 : 1; + + lv_obj_refresh_ext_size(label); + + lv_obj_invalidate(label); +} + +/** + * Set the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes + * @param label pointer to a label object + * @param anim_speed speed of animation in px/sec unit + */ +void lv_label_set_anim_speed(lv_obj_t * label, uint16_t anim_speed) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + if(ext->anim_speed == anim_speed) return; + + ext->anim_speed = anim_speed; + + if(ext->long_mode == LV_LABEL_LONG_ROLL || ext->long_mode == LV_LABEL_LONG_SCROLL) { + lv_label_refr_text(label); + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a label + * @param label pointer to a label object + * @return the text of the label + */ +char * lv_label_get_text(const lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + + return ext->text; +} + +#if USE_LV_MULTI_LANG +/** + * Get the text ID of the label. (Used by the multi-language feature) + * @param label pointer to a label object + * @return ID of the text + */ +uint16_t lv_label_get_text_id(lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + return ext->lang_txt_id; +} +#endif + +/** + * Get the long mode of a label + * @param label pointer to a label object + * @return the long mode + */ +lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + return ext->long_mode; +} + +/** + * Get the align attribute + * @param label pointer to a label object + * @return LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER + */ +lv_label_align_t lv_label_get_align(const lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + return ext->align; +} + +/** + * Get the recoloring attribute + * @param label pointer to a label object + * @return true: recoloring is enabled, false: disable + */ +bool lv_label_get_recolor(const lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + return ext->recolor == 0 ? false : true; +} + +/** + * Get the body draw attribute + * @param label pointer to a label object + * @return true: draw body; false: don't draw body + */ +bool lv_label_get_body_draw(const lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + return ext->body_draw == 0 ? false : true; +} + +/** + * Get the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes + * @param label pointer to a label object + * @return speed of animation in px/sec unit + */ +uint16_t lv_label_get_anim_speed(const lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + return ext->anim_speed; +} + +/** + * Get the relative x and y coordinates of a letter + * @param label pointer to a label object + * @param index index of the letter [0 ... text length]. Expressed in character index, not byte index (different in UTF-8) + * @param pos store the result here (E.g. index = 0 gives 0;0 coordinates) + */ +void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t * pos) +{ + const char * txt = lv_label_get_text(label); + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + uint32_t line_start = 0; + uint32_t new_line_start = 0; + lv_coord_t max_w = lv_obj_get_width(label); + lv_style_t * style = lv_obj_get_style(label); + const lv_font_t * font = style->text.font; + uint8_t letter_height = lv_font_get_height(font); + lv_coord_t y = 0; + lv_txt_flag_t flag = LV_TXT_FLAG_NONE; + + if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR; + if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND; + if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER; + + /*If the width will be expanded the set the max length to very big */ + if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) { + max_w = LV_COORD_MAX; + } + + index = lv_txt_encoded_get_byte_id(txt, index); + + /*Search the line of the index letter */; + while(txt[new_line_start] != '\0') { + new_line_start += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, max_w, flag); + if(index < new_line_start || txt[new_line_start] == '\0') break; /*The line of 'index' letter begins at 'line_start'*/ + + y += letter_height + style->text.line_space; + line_start = new_line_start; + } + + /*If the last character is line break then go to the next line*/ + if(index > 0) { + if((txt[index - 1] == '\n' || txt[index - 1] == '\r') && txt[index] == '\0') { + y += letter_height + style->text.line_space; + line_start = index; + } + } + + /*Calculate the x coordinate*/ + lv_coord_t x = lv_txt_get_width(&txt[line_start], index - line_start, + font, style->text.letter_space, flag); + + if(index != line_start) x += style->text.letter_space; + + if(ext->align == LV_LABEL_ALIGN_CENTER) { + lv_coord_t line_w; + line_w = lv_txt_get_width(&txt[line_start], new_line_start - line_start, + font, style->text.letter_space, flag); + x += lv_obj_get_width(label) / 2 - line_w / 2; + + } else if(ext->align == LV_LABEL_ALIGN_RIGHT) { + lv_coord_t line_w; + line_w = lv_txt_get_width(&txt[line_start], new_line_start - line_start, + font, style->text.letter_space, flag); + + x += lv_obj_get_width(label) - line_w; + } + pos->x = x; + pos->y = y; +} + +/** + * Get the index of letter on a relative point of a label + * @param label pointer to label object + * @param pos pointer to point with coordinates on a the label + * @return the index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter) + * Expressed in character index and not byte index (different in UTF-8) + */ +uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) +{ + const char * txt = lv_label_get_text(label); + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + uint32_t line_start = 0; + uint32_t new_line_start = 0; + lv_coord_t max_w = lv_obj_get_width(label); + lv_style_t * style = lv_obj_get_style(label); + const lv_font_t * font = style->text.font; + uint8_t letter_height = lv_font_get_height(font); + lv_coord_t y = 0; + lv_txt_flag_t flag = LV_TXT_FLAG_NONE; + + if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR; + if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND; + if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER; + + /*If the width will be expanded set the max length to very big */ + if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) { + max_w = LV_COORD_MAX; + } + + /*Search the line of the index letter */; + while(txt[line_start] != '\0') { + new_line_start += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, max_w, flag); + + if(pos->y <= y + letter_height) break; /*The line is found (stored in 'line_start')*/ + y += letter_height + style->text.line_space; + + line_start = new_line_start; + } + + /*Calculate the x coordinate*/ + lv_coord_t x = 0; + if(ext->align == LV_LABEL_ALIGN_CENTER) { + lv_coord_t line_w; + line_w = lv_txt_get_width(&txt[line_start], new_line_start - line_start, + font, style->text.letter_space, flag); + x += lv_obj_get_width(label) / 2 - line_w / 2; + } + + lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT; + uint32_t i = line_start; + uint32_t i_current = i; + uint32_t letter; + while(i < new_line_start - 1) { + letter = lv_txt_encoded_next(txt, &i); /*Be careful 'i' already points to the next character*/ + /*Handle the recolor command*/ + if((flag & LV_TXT_FLAG_RECOLOR) != 0) { + if(lv_txt_is_cmd(&cmd_state, txt[i]) != false) { + continue; /*Skip the letter is it is part of a command*/ + } + } + + x += lv_font_get_width(font, letter); + if(pos->x < x) { + i = i_current; + break; + } + x += style->text.letter_space; + i_current = i; + } + + return lv_encoded_get_char_id(txt, i); +} + + +/*===================== + * Other functions + *====================*/ + +/** + * Insert a text to the label. The label text can not be static. + * @param label pointer to a label object + * @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8) + * 0: before first char. + * LV_LABEL_POS_LAST: after last char. + * @param txt pointer to the text to insert + */ +void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + + /*Can not append to static text*/ + if(ext->static_txt != 0) return; + + lv_obj_invalidate(label); + + /*Allocate space for the new text*/ + uint32_t old_len = strlen(ext->text); + uint32_t ins_len = strlen(txt); + uint32_t new_len = ins_len + old_len; + ext->text = lv_mem_realloc(ext->text, new_len + 1); + lv_mem_assert(ext->text); + if(ext->text == NULL) return; + + if(pos == LV_LABEL_POS_LAST) { +#if LV_TXT_UTF8 == 0 + pos = old_len; +#else + pos = lv_txt_get_encoded_length(ext->text); +#endif + } + + lv_txt_ins(ext->text, pos, txt); + + lv_label_refr_text(label); +} + +/** + * Delete characters from a label. The label text can not be static. + * @param label pointer to a label object + * @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8) + * 0: before first char. + * @param cnt number of characters to cut + */ +void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + + /*Can not append to static text*/ + if(ext->static_txt != 0) return; + + lv_obj_invalidate(label); + + char * label_txt = lv_label_get_text(label); + /*Delete the characters*/ + lv_txt_cut(label_txt, pos, cnt); + + /*Refresh the label*/ + lv_label_refr_text(label); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the labels + * @param label pointer to a label object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_label_design(lv_obj_t * label, const lv_area_t * mask, lv_design_mode_t mode) +{ + /* A label never covers an area */ + if(mode == LV_DESIGN_COVER_CHK) return false; + else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_area_t coords; + lv_style_t * style = lv_obj_get_style(label); + lv_opa_t opa_scale = lv_obj_get_opa_scale(label); + lv_obj_get_coords(label, &coords); + +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(label); + if(lv_group_get_focused(g) == label) { + lv_draw_rect(&coords, mask, style, opa_scale); + } +#endif + + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + + if(ext->body_draw) { + lv_area_t bg; + lv_obj_get_coords(label, &bg); + bg.x1 -= style->body.padding.hor; + bg.x2 += style->body.padding.hor; + bg.y1 -= style->body.padding.ver; + bg.y2 += style->body.padding.ver; + + lv_draw_rect(&bg, mask, style, lv_obj_get_opa_scale(label)); + } + + /*TEST: draw a background for the label*/ + //lv_draw_rect(&label->coords, mask, &lv_style_plain_color, LV_OPA_COVER); + + lv_txt_flag_t flag = LV_TXT_FLAG_NONE; + if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR; + if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND; + if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER; + if(ext->align == LV_LABEL_ALIGN_RIGHT) flag |= LV_TXT_FLAG_RIGHT; + + /* In ROLL mode the CENTER and RIGHT are pointless so remove them. + * (In addition they will result mis-alignment is this case)*/ + if((ext->long_mode == LV_LABEL_LONG_ROLL) && + (ext->align == LV_LABEL_ALIGN_CENTER || ext->align == LV_LABEL_ALIGN_RIGHT)) { + lv_point_t size; + lv_txt_get_size(&size, ext->text, style->text.font, style->text.letter_space, style->text.line_space, LV_COORD_MAX, flag); + if(size.x > lv_obj_get_width(label)) { + flag &= ~LV_TXT_FLAG_RIGHT; + flag &= ~LV_TXT_FLAG_CENTER; + } + } + + lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ext->offset); + } + return true; +} + + + +/** + * Signal function of the label + * @param label pointer to a label object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(label, sign, param); + if(res != LV_RES_OK) return res; + + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + if(sign == LV_SIGNAL_CLEANUP) { + if(ext->static_txt == 0) { + lv_mem_free(ext->text); + ext->text = NULL; + } + } else if(sign == LV_SIGNAL_STYLE_CHG) { + /*Revert dots for proper refresh*/ + lv_label_revert_dots(label); + + lv_label_refr_text(label); + } else if(sign == LV_SIGNAL_CORD_CHG) { + if(lv_area_get_width(&label->coords) != lv_area_get_width(param) || + lv_area_get_height(&label->coords) != lv_area_get_height(param)) { + lv_label_revert_dots(label); + lv_label_refr_text(label); + } + } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + if(ext->body_draw) { + lv_style_t * style = lv_label_get_style(label); + label->ext_size = LV_MATH_MAX(label->ext_size, style->body.padding.hor); + label->ext_size = LV_MATH_MAX(label->ext_size, style->body.padding.ver); + } + } else if(sign == LV_SIGNAL_LANG_CHG) { +#if USE_LV_MULTI_LANG + if(ext->lang_txt_id != LV_LANG_TXT_ID_NONE) { + const char * lang_txt = lv_lang_get_text(ext->lang_txt_id); + if(lang_txt) { + lv_label_set_text(label, lang_txt); + } else { + LV_LOG_WARN("lv_lang_get_text return NULL for a label's text"); + } + } +#endif + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_label"; + } + + return res; +} + +/** + * Refresh the label with its text stored in its extended data + * @param label pointer to a label object + */ +static void lv_label_refr_text(lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + + if(ext->text == NULL) return; + + lv_coord_t max_w = lv_obj_get_width(label); + lv_style_t * style = lv_obj_get_style(label); + const lv_font_t * font = style->text.font; + + /*If the width will be expanded set the max length to very big */ + if(ext->long_mode == LV_LABEL_LONG_EXPAND || + ext->long_mode == LV_LABEL_LONG_SCROLL) { + max_w = LV_COORD_MAX; + } + + /*Calc. the height and longest line*/ + lv_point_t size; + lv_txt_flag_t flag = LV_TXT_FLAG_NONE; + if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR; + if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND; + lv_txt_get_size(&size, ext->text, font, style->text.letter_space, style->text.line_space, max_w, flag); + + /*Set the full size in expand mode*/ + if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) { + lv_obj_set_size(label, size.x, size.y); + + /*Start scrolling if the label is greater then its parent*/ + if(ext->long_mode == LV_LABEL_LONG_SCROLL) { +#if USE_LV_ANIMATION + lv_obj_t * parent = lv_obj_get_parent(label); + + /*Delete the potential previous scroller animations*/ + lv_anim_del(label, (lv_anim_fp_t) lv_obj_set_x); + lv_anim_del(label, (lv_anim_fp_t) lv_obj_set_y); + + lv_anim_t anim; + anim.var = label; + anim.repeat = 1; + anim.playback = 1; + anim.start = 0; + anim.act_time = 0; + anim.end_cb = NULL; + anim.path = lv_anim_path_linear; + + anim.playback_pause = (((lv_font_get_width(style->text.font, ' ') + + style->text.letter_space) * 1000) / ext->anim_speed) * ANIM_WAIT_CHAR_COUNT; + anim.repeat_pause = anim.playback_pause; + + if(lv_obj_get_width(label) > lv_obj_get_width(parent)) { + anim.end = lv_obj_get_width(parent) - lv_obj_get_width(label); + anim.fp = (lv_anim_fp_t) lv_obj_set_x; + anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end); + lv_anim_create(&anim); + } else if(lv_obj_get_height(label) > lv_obj_get_height(parent)) { + anim.end = lv_obj_get_height(parent) - lv_obj_get_height(label) - lv_font_get_height(font); + anim.fp = (lv_anim_fp_t)lv_obj_set_y; + anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end); + lv_anim_create(&anim); + } +#endif + } + } + /*In roll mode keep the size but start offset animations*/ + else if(ext->long_mode == LV_LABEL_LONG_ROLL) { +#if USE_LV_ANIMATION + lv_anim_t anim; + anim.var = label; + anim.repeat = 1; + anim.playback = 1; + anim.start = 0; + anim.act_time = 0; + anim.end_cb = NULL; + anim.path = lv_anim_path_linear; + anim.playback_pause = (((lv_font_get_width(style->text.font, ' ') + style->text.letter_space) * 1000) / ext->anim_speed) * ANIM_WAIT_CHAR_COUNT; + anim.repeat_pause = anim.playback_pause; + + bool hor_anim = false; + if(size.x > lv_obj_get_width(label)) { + anim.end = lv_obj_get_width(label) - size.x; + anim.fp = (lv_anim_fp_t) lv_label_set_offset_x; + anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end); + lv_anim_create(&anim); + hor_anim = true; + } else { + /*Delete the offset animation if not required*/ + lv_anim_del(label, (lv_anim_fp_t) lv_label_set_offset_x); + ext->offset.x = 0; + } + + if(size.y > lv_obj_get_height(label) && hor_anim == false) { + anim.end = lv_obj_get_height(label) - size.y - (lv_font_get_height(font)); + anim.fp = (lv_anim_fp_t)lv_label_set_offset_y; + anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end); + lv_anim_create(&anim); + } else { + /*Delete the offset animation if not required*/ + lv_anim_del(label, (lv_anim_fp_t) lv_label_set_offset_y); + ext->offset.y = 0; + } +#endif + } else if(ext->long_mode == LV_LABEL_LONG_DOT) { + if(size.y <= lv_obj_get_height(label)) { /*No dots are required, the text is short enough*/ + ext->dot_end = LV_LABEL_DOT_END_INV; + } else if(lv_txt_get_encoded_length(ext->text) <= LV_LABEL_DOT_NUM) { /*Don't turn to dots all the characters*/ + ext->dot_end = LV_LABEL_DOT_END_INV; + } else { + lv_point_t p; + p.x = lv_obj_get_width(label) - (lv_font_get_width(style->text.font, '.') + style->text.letter_space) * LV_LABEL_DOT_NUM; /*Shrink with dots*/ + p.y = lv_obj_get_height(label); + p.y -= p.y % (lv_font_get_height(style->text.font) + style->text.line_space); /*Round down to the last line*/ + p.y -= style->text.line_space; /*Trim the last line space*/ + uint32_t letter_id = lv_label_get_letter_on(label, &p); + + +#if LV_TXT_UTF8 == 0 + /*Save letters under the dots and replace them with dots*/ + uint8_t i; + for(i = 0; i < LV_LABEL_DOT_NUM; i++) { + ext->dot_tmp[i] = ext->text[letter_id + i]; + ext->text[letter_id + i] = '.'; + } + + ext->dot_tmp[LV_LABEL_DOT_NUM] = ext->text[letter_id + LV_LABEL_DOT_NUM]; + ext->text[letter_id + LV_LABEL_DOT_NUM] = '\0'; + + ext->dot_end = letter_id + LV_LABEL_DOT_NUM; +#else + /*Save letters under the dots and replace them with dots*/ + uint32_t i; + uint32_t byte_id = lv_txt_encoded_get_byte_id(ext->text, letter_id); + uint32_t byte_id_ori = byte_id; + uint8_t len = 0; + for(i = 0; i <= LV_LABEL_DOT_NUM; i++) { + len += lv_txt_encoded_size(&ext->text[byte_id]); + lv_txt_encoded_next(ext->text, &byte_id); + } + + memcpy(ext->dot_tmp, &ext->text[byte_id_ori], len); + ext->dot_tmp[len] = '\0'; /*Close with a zero*/ + + for(i = 0; i < LV_LABEL_DOT_NUM; i++) { + ext->text[byte_id_ori + i] = '.'; + } + ext->text[byte_id_ori + LV_LABEL_DOT_NUM] = '\0'; + + ext->dot_end = letter_id + LV_LABEL_DOT_NUM; +#endif + + } + } + /*In break mode only the height can change*/ + else if(ext->long_mode == LV_LABEL_LONG_BREAK) { + lv_obj_set_height(label, size.y); + } + /*Do not set the size in Clip mode*/ + else if(ext->long_mode == LV_LABEL_LONG_CROP) { + /*Do nothing*/ + } + + + lv_obj_invalidate(label); +} + +static void lv_label_revert_dots(lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + if(ext->long_mode != LV_LABEL_LONG_DOT) return; + if(ext->dot_end == LV_LABEL_DOT_END_INV) return; +#if LV_TXT_UTF8 == 0 + uint32_t i; + for(i = 0; i <= LV_LABEL_DOT_NUM; i++) { + ext->text[ext->dot_end - i] = ext->dot_tmp[LV_LABEL_DOT_NUM - i]; + } +#else + uint32_t letter_i = ext->dot_end - LV_LABEL_DOT_NUM; + uint32_t byte_i = lv_txt_encoded_get_byte_id(ext->text, letter_i); + + /*Restore the characters*/ + uint8_t i = 0; + while(ext->dot_tmp[i] != '\0') { + ext->text[byte_i + i] = ext->dot_tmp[i]; + i++; + } +#endif + + ext->dot_end = LV_LABEL_DOT_END_INV; +} + +#if USE_LV_ANIMATION +static void lv_label_set_offset_x(lv_obj_t * label, lv_coord_t x) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + ext->offset.x = x; + lv_obj_invalidate(label); +} + +static void lv_label_set_offset_y(lv_obj_t * label, lv_coord_t y) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + ext->offset.y = y; + lv_obj_invalidate(label); +} +#endif +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.h new file mode 100644 index 0000000..a2ee126 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_label.h @@ -0,0 +1,295 @@ +/** + * @file lv_rect.h + * + */ + +#ifndef LV_LABEL_H +#define LV_LABEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_LABEL != 0 + +#include "../lv_core/lv_obj.h" +#include "../lv_misc/lv_font.h" +#include "../lv_misc/lv_txt.h" +#include "../lv_misc/lv_symbol_def.h" + +/********************* + * DEFINES + *********************/ +#define LV_LABEL_DOT_NUM 3 +#define LV_LABEL_POS_LAST 0xFFFF + +/********************** + * TYPEDEFS + **********************/ + +/*Long mode behaviors. Used in 'lv_label_ext_t' */ +enum +{ + LV_LABEL_LONG_EXPAND, /*Expand the object size to the text size*/ + LV_LABEL_LONG_BREAK, /*Keep the object width, break the too long lines and expand the object height*/ + LV_LABEL_LONG_SCROLL, /*Expand the object size and scroll the text on the parent (move the label object)*/ + LV_LABEL_LONG_DOT, /*Keep the size and write dots at the end if the text is too long*/ + LV_LABEL_LONG_ROLL, /*Keep the size and roll the text infinitely*/ + LV_LABEL_LONG_CROP, /*Keep the size and crop the text out of it*/ +}; +typedef uint8_t lv_label_long_mode_t; + +/*Label align policy*/ +enum { + LV_LABEL_ALIGN_LEFT, + LV_LABEL_ALIGN_CENTER, + LV_LABEL_ALIGN_RIGHT, +}; +typedef uint8_t lv_label_align_t; + +/*Data of label*/ +typedef struct +{ + /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ + /*New data for this type */ + char * text; /*Text of the label*/ + lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/ +#if LV_TXT_UTF8 == 0 + char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ +#else + char dot_tmp[LV_LABEL_DOT_NUM * 4 + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ +#endif + +#if USE_LV_MULTI_LANG + uint16_t lang_txt_id; /*The ID of the text to display*/ +#endif + uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/ + uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/ + lv_point_t offset; /*Text draw position offset*/ + uint8_t static_txt :1; /*Flag to indicate the text is static*/ + uint8_t align :2; /*Align type from 'lv_label_align_t'*/ + uint8_t recolor :1; /*Enable in-line letter re-coloring*/ + uint8_t expand :1; /*Ignore real width (used by the library with LV_LABEL_LONG_ROLL)*/ + uint8_t body_draw :1; /*Draw background body*/ +} lv_label_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + + +/** + * Create a label objects + * @param par pointer to an object, it will be the parent of the new label + * @param copy pointer to a button object, if not NULL then the new object will be copied from it + * @return pointer to the created button + */ +lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new text for a label. Memory will be allocated to store the text by the label. + * @param label pointer to a label object + * @param text '\0' terminated character string. NULL to refresh with the current text. + */ +void lv_label_set_text(lv_obj_t * label, const char * text); + +/** + * Set a new text for a label from a character array. The array don't has to be '\0' terminated. + * Memory will be allocated to store the array by the label. + * @param label pointer to a label object + * @param array array of characters or NULL to refresh the label + * @param size the size of 'array' in bytes + */ +void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size); + +/** + * Set a static text. It will not be saved by the label so the 'text' variable + * has to be 'alive' while the label exist. + * @param label pointer to a label object + * @param text pointer to a text. NULL to refresh with the current text. + */ +void lv_label_set_static_text(lv_obj_t * label, const char * text); + +/** + *Set a text ID which means a the same text but on different languages + * @param label pointer to a label object + * @param txt_id ID of the text + */ +#if USE_LV_MULTI_LANG +void lv_label_set_text_id(lv_obj_t * label, uint32_t txt_id); +#endif + +/** + * Set the behavior of the label with longer text then the object size + * @param label pointer to a label object + * @param long_mode the new mode from 'lv_label_long_mode' enum. + * In LV_LONG_BREAK/LONG/ROLL the size of the label should be set AFTER this function + */ +void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode); + +/** + * Set the align of the label (left or center) + * @param label pointer to a label object + * @param align 'LV_LABEL_ALIGN_LEFT' or 'LV_LABEL_ALIGN_LEFT' + */ +void lv_label_set_align(lv_obj_t *label, lv_label_align_t align); + +/** + * Enable the recoloring by in-line commands + * @param label pointer to a label object + * @param en true: enable recoloring, false: disable + */ +void lv_label_set_recolor(lv_obj_t * label, bool en); + +/** + * Set the label to draw (or not draw) background specified in its style's body + * @param label pointer to a label object + * @param en true: draw body; false: don't draw body + */ +void lv_label_set_body_draw(lv_obj_t *label, bool en); + +/** + * Set the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes + * @param label pointer to a label object + * @param anim_speed speed of animation in px/sec unit + */ +void lv_label_set_anim_speed(lv_obj_t *label, uint16_t anim_speed); + +/** + * Set the style of an label + * @param label pointer to an label object + * @param style pointer to a style + */ +static inline void lv_label_set_style(lv_obj_t *label, lv_style_t *style) +{ + lv_obj_set_style(label, style); +} +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a label + * @param label pointer to a label object + * @return the text of the label + */ +char * lv_label_get_text(const lv_obj_t * label); + +#if USE_LV_MULTI_LANG +/** + * Get the text ID of the label. (Used by the multi-language feature) + * @param label pointer to a label object + * @return ID of the text + */ +uint16_t lv_label_get_text_id(lv_obj_t * label); +#endif + +/** + * Get the long mode of a label + * @param label pointer to a label object + * @return the long mode + */ +lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * label); + +/** + * Get the align attribute + * @param label pointer to a label object + * @return LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER + */ +lv_label_align_t lv_label_get_align(const lv_obj_t * label); + +/** + * Get the recoloring attribute + * @param label pointer to a label object + * @return true: recoloring is enabled, false: disable + */ +bool lv_label_get_recolor(const lv_obj_t * label); + +/** + * Get the body draw attribute + * @param label pointer to a label object + * @return true: draw body; false: don't draw body + */ +bool lv_label_get_body_draw(const lv_obj_t *label); + +/** + * Get the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes + * @param label pointer to a label object + * @return speed of animation in px/sec unit + */ +uint16_t lv_label_get_anim_speed(const lv_obj_t *label); + +/** + * Get the relative x and y coordinates of a letter + * @param label pointer to a label object + * @param index index of the letter [0 ... text length]. Expressed in character index, not byte index (different in UTF-8) + * @param pos store the result here (E.g. index = 0 gives 0;0 coordinates) + */ +void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t * pos); + +/** + * Get the index of letter on a relative point of a label + * @param label pointer to label object + * @param pos pointer to point with coordinates on a the label + * @return the index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter) + * Expressed in character index and not byte index (different in UTF-8) + */ +uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos); + +/** + * Get the style of an label object + * @param label pointer to an label object + * @return pointer to the label's style + */ +static inline lv_style_t* lv_label_get_style(const lv_obj_t *label) +{ + return lv_obj_get_style(label); +} + +/*===================== + * Other functions + *====================*/ + +/** + * Insert a text to the label. The label text can not be static. + * @param label pointer to a label object + * @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8) + * 0: before first char. + * LV_LABEL_POS_LAST: after last char. + * @param txt pointer to the text to insert + */ +void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt); + +/** + * Delete characters from a label. The label text can not be static. + * @param label pointer to a label object + * @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8) + * 0: before first char. + * @param cnt number of characters to cut + */ +void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_LABEL*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_LABEL_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.c new file mode 100644 index 0000000..29fc967 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.c @@ -0,0 +1,244 @@ +/** + * @file lv_led.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_led.h" +#if USE_LV_LED != 0 + +#include "../lv_themes/lv_theme.h" +#include "../lv_draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ +#define LV_LED_WIDTH_DEF (LV_DPI / 3) +#define LV_LED_HEIGHT_DEF (LV_DPI / 3) +#define LV_LED_BRIGHT_OFF 100 +#define LV_LED_BRIGHT_ON 255 + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_led_design(lv_obj_t * led, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_led_signal(lv_obj_t * led, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_design_func_t ancestor_design_f; +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a led objects + * @param par pointer to an object, it will be the parent of the new led + * @param copy pointer to a led object, if not NULL then the new object will be copied from it + * @return pointer to the created led + */ +lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("led create started"); + + /*Create the ancestor basic object*/ + lv_obj_t * new_led = lv_obj_create(par, copy); + lv_mem_assert(new_led); + if(new_led == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_led); + if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_led); + + /*Allocate the object type specific extended data*/ + lv_led_ext_t * ext = lv_obj_allocate_ext_attr(new_led, sizeof(lv_led_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->bright = LV_LED_BRIGHT_ON; + + lv_obj_set_signal_func(new_led, lv_led_signal); + lv_obj_set_design_func(new_led, lv_led_design); + + /*Init the new led object*/ + if(copy == NULL) { + lv_obj_set_size(new_led, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_led_set_style(new_led, th->led); + } else { + lv_led_set_style(new_led, &lv_style_pretty_color); + } + } + /*Copy an existing object*/ + else { + lv_led_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->bright = copy_ext->bright; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_led); + } + + + LV_LOG_INFO("led created"); + + return new_led; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the brightness of a LED object + * @param led pointer to a LED object + * @param bright 0 (max. dark) ... 255 (max. light) + */ +void lv_led_set_bright(lv_obj_t * led, uint8_t bright) +{ + /*Set the brightness*/ + lv_led_ext_t * ext = lv_obj_get_ext_attr(led); + if(ext->bright == bright) return; + + ext->bright = bright; + + /*Invalidate the object there fore it will be redrawn*/ + lv_obj_invalidate(led); +} + +/** + * Light on a LED + * @param led pointer to a LED object + */ +void lv_led_on(lv_obj_t * led) +{ + lv_led_set_bright(led, LV_LED_BRIGHT_ON); +} + +/** + * Light off a LED + * @param led pointer to a LED object + */ +void lv_led_off(lv_obj_t * led) +{ + lv_led_set_bright(led, LV_LED_BRIGHT_OFF); +} + + +/** + * Toggle the state of a LED + * @param led pointer to a LED object + */ +void lv_led_toggle(lv_obj_t * led) +{ + uint8_t bright = lv_led_get_bright(led); + if(bright > (LV_LED_BRIGHT_OFF + LV_LED_BRIGHT_ON) >> 1) lv_led_off(led); + else lv_led_on(led); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the brightness of a LEd object + * @param led pointer to LED object + * @return bright 0 (max. dark) ... 255 (max. light) + */ +uint8_t lv_led_get_bright(const lv_obj_t * led) +{ + lv_led_ext_t * ext = lv_obj_get_ext_attr(led); + return ext->bright; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the leds + * @param led pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_led_design(lv_obj_t * led, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + /*Return false if the object is not covers the mask area*/ + return ancestor_design_f(led, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { + /*Make darker colors in a temporary style according to the brightness*/ + lv_led_ext_t * ext = lv_obj_get_ext_attr(led); + lv_style_t * style = lv_obj_get_style(led); + + /* Store the real pointer because of 'lv_group' + * If the object is in focus 'lv_obj_get_style()' will give a pointer to tmp style + * and to the real object style. It is important because of style change tricks below*/ + lv_style_t * style_ori_p = led->style_p; + + /*Create a temporal style*/ + lv_style_t leds_tmp; + memcpy(&leds_tmp, style, sizeof(leds_tmp)); + + /*Mix. the color with black proportionally with brightness*/ + leds_tmp.body.main_color = lv_color_mix(leds_tmp.body.main_color, LV_COLOR_BLACK, ext->bright); + leds_tmp.body.grad_color = lv_color_mix(leds_tmp.body.grad_color, LV_COLOR_BLACK, ext->bright); + leds_tmp.body.border.color = lv_color_mix(leds_tmp.body.border.color, LV_COLOR_BLACK, ext->bright); + + /*Set the current swidth according to brightness proportionally between LV_LED_BRIGHT_OFF and LV_LED_BRIGHT_ON*/ + uint16_t bright_tmp = ext->bright; + leds_tmp.body.shadow.width = ((bright_tmp - LV_LED_BRIGHT_OFF) * style->body.shadow.width) / (LV_LED_BRIGHT_ON - LV_LED_BRIGHT_OFF); + + led->style_p = &leds_tmp; + ancestor_design_f(led, mask, mode); + led->style_p = style_ori_p; /*Restore the ORIGINAL style pointer*/ + } + return true; +} + +/** + * Signal function of the led + * @param led pointer to a led object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_led_signal(lv_obj_t * led, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(led, sign, param); + if(res != LV_RES_OK) return res; + + + if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_led"; + } + + return res; +} +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.h new file mode 100644 index 0000000..25e48a7 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_led.h @@ -0,0 +1,116 @@ +/** + * @file lv_led.h + * + */ + +#ifndef LV_LED_H +#define LV_LED_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_LED != 0 + +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of led*/ +typedef struct +{ + /*No inherited ext.*/ + /*New data for this type */ + uint8_t bright; /*Current brightness of the LED (0..255)*/ +} lv_led_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a led objects + * @param par pointer to an object, it will be the parent of the new led + * @param copy pointer to a led object, if not NULL then the new object will be copied from it + * @return pointer to the created led + */ +lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy); + +/** + * Set the brightness of a LED object + * @param led pointer to a LED object + * @param bright 0 (max. dark) ... 255 (max. light) + */ +void lv_led_set_bright(lv_obj_t * led, uint8_t bright); + +/** + * Light on a LED + * @param led pointer to a LED object + */ +void lv_led_on(lv_obj_t * led); + +/** + * Light off a LED + * @param led pointer to a LED object + */ +void lv_led_off(lv_obj_t * led); + +/** + * Toggle the state of a LED + * @param led pointer to a LED object + */ +void lv_led_toggle(lv_obj_t * led); + +/** + * Set the style of a led + * @param led pointer to a led object + * @param style pointer to a style + */ +static inline void lv_led_set_style(lv_obj_t *led, lv_style_t *style) +{ + lv_obj_set_style(led, style); +} + +/** + * Get the brightness of a LEd object + * @param led pointer to LED object + * @return bright 0 (max. dark) ... 255 (max. light) + */ +uint8_t lv_led_get_bright(const lv_obj_t * led); + +/** + * Get the style of an led object + * @param led pointer to an led object + * @return pointer to the led's style + */ +static inline lv_style_t* lv_led_get_style(const lv_obj_t *led) +{ + return lv_obj_get_style(led); +} + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_LED*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_LED_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.c new file mode 100644 index 0000000..0e16337 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.c @@ -0,0 +1,301 @@ +/** + * @file lv_line.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_line.h" + +#if USE_LV_LINE != 0 +#include "../lv_draw/lv_draw.h" +#include "../lv_misc/lv_math.h" +#include +#include + + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_line_design(lv_obj_t * line, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a line objects + * @param par pointer to an object, it will be the parent of the new line + * @return pointer to the created line + */ +lv_obj_t * lv_line_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("line create started"); + + /*Create a basic object*/ + lv_obj_t * new_line = lv_obj_create(par, copy); + lv_mem_assert(new_line); + if(new_line == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_line); + + /*Extend the basic object to line object*/ + lv_line_ext_t * ext = lv_obj_allocate_ext_attr(new_line, sizeof(lv_line_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->point_num = 0; + ext->point_array = NULL; + ext->auto_size = 1; + ext->y_inv = 0; + + lv_obj_set_design_func(new_line, lv_line_design); + lv_obj_set_signal_func(new_line, lv_line_signal); + + /*Init the new line*/ + if(copy == NULL) { + lv_obj_set_size(new_line, LV_DPI, LV_DPI); /*Auto size is enables, but set default size until no points are added*/ + lv_obj_set_style(new_line, NULL); /*Inherit parent's style*/ + lv_obj_set_click(new_line, false); + } + /*Copy an existing object*/ + else { + lv_line_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + lv_line_set_auto_size(new_line, lv_line_get_auto_size(copy)); + lv_line_set_y_invert(new_line, lv_line_get_y_invert(copy)); + lv_line_set_auto_size(new_line, lv_line_get_auto_size(copy)); + lv_line_set_points(new_line, copy_ext->point_array, copy_ext->point_num); + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_line); + } + + + LV_LOG_INFO("line created"); + + return new_line; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set an array of points. The line object will connect these points. + * @param line pointer to a line object + * @param point_a an array of points. Only the address is saved, + * so the array can NOT be a local variable which will be destroyed + * @param point_num number of points in 'point_a' + */ +void lv_line_set_points(lv_obj_t * line, const lv_point_t * point_a, uint16_t point_num) +{ + lv_line_ext_t * ext = lv_obj_get_ext_attr(line); + ext->point_array = point_a; + ext->point_num = point_num; + + if(point_num > 0 && ext->auto_size != 0) { + uint16_t i; + lv_coord_t xmax = LV_COORD_MIN; + lv_coord_t ymax = LV_COORD_MIN; + for(i = 0; i < point_num; i++) { + xmax = LV_MATH_MAX(point_a[i].x, xmax); + ymax = LV_MATH_MAX(point_a[i].y, ymax); + } + + lv_style_t * style = lv_line_get_style(line); + lv_obj_set_size(line, xmax + style->line.width, ymax + style->line.width); + } + + lv_obj_invalidate(line); +} + +/** + * Enable (or disable) the auto-size option. The size of the object will fit to its points. + * (set width to x max and height to y max) + * @param line pointer to a line object + * @param en true: auto size is enabled, false: auto size is disabled + */ +void lv_line_set_auto_size(lv_obj_t * line, bool en) +{ + lv_line_ext_t * ext = lv_obj_get_ext_attr(line); + if(ext->auto_size == en) return; + + ext->auto_size = en == false ? 0 : 1; + + /*Refresh the object*/ + if(en) lv_line_set_points(line, ext->point_array, ext->point_num); +} + +/** + * Enable (or disable) the y coordinate inversion. + * If enabled then y will be subtracted from the height of the object, + * therefore the y=0 coordinate will be on the bottom. + * @param line pointer to a line object + * @param en true: enable the y inversion, false:disable the y inversion + */ +void lv_line_set_y_invert(lv_obj_t * line, bool en) +{ + lv_line_ext_t * ext = lv_obj_get_ext_attr(line); + if(ext->y_inv == en) return; + + ext->y_inv = en == false ? 0 : 1; + + lv_obj_invalidate(line); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the auto size attribute + * @param line pointer to a line object + * @return true: auto size is enabled, false: disabled + */ +bool lv_line_get_auto_size(const lv_obj_t * line) +{ + lv_line_ext_t * ext = lv_obj_get_ext_attr(line); + + return ext->auto_size == 0 ? false : true; +} + +/** + * Get the y inversion attribute + * @param line pointer to a line object + * @return true: y inversion is enabled, false: disabled + */ +bool lv_line_get_y_invert(const lv_obj_t * line) +{ + lv_line_ext_t * ext = lv_obj_get_ext_attr(line); + + return ext->y_inv == 0 ? false : true; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the lines + * @param line pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_line_design(lv_obj_t * line, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*A line never covers an area*/ + if(mode == LV_DESIGN_COVER_CHK) return false; + else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_line_ext_t * ext = lv_obj_get_ext_attr(line); + + if(ext->point_num == 0 || ext->point_array == NULL) return false; + + lv_style_t * style = lv_obj_get_style(line); + lv_opa_t opa_scale = lv_obj_get_opa_scale(line); + lv_area_t area; + lv_obj_get_coords(line, &area); + lv_coord_t x_ofs = area.x1; + lv_coord_t y_ofs = area.y1; + lv_point_t p1; + lv_point_t p2; + lv_coord_t h = lv_obj_get_height(line); + uint16_t i; + + lv_style_t circle_style; /*If rounded...*/ + lv_style_copy(&circle_style, style); + circle_style.body.radius = LV_RADIUS_CIRCLE; + circle_style.body.main_color = style->line.color; + circle_style.body.grad_color = style->line.color; + circle_style.body.opa = style->line.opa; + lv_area_t circle_area; + + /*Read all points and draw the lines*/ + for(i = 0; i < ext->point_num - 1; i++) { + + p1.x = ext->point_array[i].x + x_ofs; + p2.x = ext->point_array[i + 1].x + x_ofs; + + if(ext->y_inv == 0) { + p1.y = ext->point_array[i].y + y_ofs; + p2.y = ext->point_array[i + 1].y + y_ofs; + } else { + p1.y = h - ext->point_array[i].y + y_ofs; + p2.y = h - ext->point_array[i + 1].y + y_ofs; + } + lv_draw_line(&p1, &p2, mask, style, opa_scale); + + /*Draw circle on the joints if enabled*/ + if(style->line.rounded) { + circle_area.x1 = p1.x - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1); + circle_area.y1 = p1.y - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1); + circle_area.x2 = p1.x + ((style->line.width - 1) >> 1); + circle_area.y2 = p1.y + ((style->line.width - 1) >> 1); + lv_draw_rect(&circle_area, mask, &circle_style, opa_scale); + } + } + + /*Draw circle on the last point too if enabled*/ + if(style->line.rounded) { + circle_area.x1 = p2.x - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1); + circle_area.y1 = p2.y - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1); + circle_area.x2 = p2.x + ((style->line.width - 1) >> 1); + circle_area.y2 = p2.y + ((style->line.width - 1) >> 1); + lv_draw_rect(&circle_area, mask, &circle_style, opa_scale); + } + } + return true; +} + +/** + * Signal function of the line + * @param line pointer to a line object + * @param sign a signal type from lv_signal_t enum + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(line, sign, param); + if(res != LV_RES_OK) return res; + + + if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_line"; + } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + lv_style_t * style = lv_line_get_style(line); + if(line->ext_size < style->line.width) line->ext_size = style->line.width; + } + + + return res; +} +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.h new file mode 100644 index 0000000..377d399 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_line.h @@ -0,0 +1,158 @@ +/** + * @file lv_line.h + * + */ + +#ifndef LV_LINE_H +#define LV_LINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_LINE != 0 + +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of line*/ +typedef struct +{ + /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ + const lv_point_t * point_array; /*Pointer to an array with the points of the line*/ + uint16_t point_num; /*Number of points in 'point_array' */ + uint8_t auto_size :1; /*1: set obj. width to x max and obj. height to y max */ + uint8_t y_inv :1; /*1: y == 0 will be on the bottom*/ +} lv_line_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + + +/** + * Create a line objects + * @param par pointer to an object, it will be the parent of the new line + * @return pointer to the created line + */ +lv_obj_t * lv_line_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set an array of points. The line object will connect these points. + * @param line pointer to a line object + * @param point_a an array of points. Only the address is saved, + * so the array can NOT be a local variable which will be destroyed + * @param point_num number of points in 'point_a' + */ +void lv_line_set_points(lv_obj_t * line, const lv_point_t * point_a, uint16_t point_num); + +/** + * Enable (or disable) the auto-size option. The size of the object will fit to its points. + * (set width to x max and height to y max) + * @param line pointer to a line object + * @param en true: auto size is enabled, false: auto size is disabled + */ +void lv_line_set_auto_size(lv_obj_t * line, bool en); + +/** + * Enable (or disable) the y coordinate inversion. + * If enabled then y will be subtracted from the height of the object, + * therefore the y=0 coordinate will be on the bottom. + * @param line pointer to a line object + * @param en true: enable the y inversion, false:disable the y inversion + */ +void lv_line_set_y_invert(lv_obj_t * line, bool en); + +#define lv_line_set_y_inv lv_line_set_y_invert /*The name was inconsistent. In v.6.0 only `lv_line_set_y_invert`will work */ + +/** + * Set the style of a line + * @param line pointer to a line object + * @param style pointer to a style + */ +static inline void lv_line_set_style(lv_obj_t *line, lv_style_t *style) +{ + lv_obj_set_style(line, style); +} + +/** + * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 + * @param line - + * @param upscale - + */ +static inline void lv_line_set_upscale(lv_obj_t * line, bool upcale) +{ + (void) line; + (void) upcale; +} +/*===================== + * Getter functions + *====================*/ + +/** + * Get the auto size attribute + * @param line pointer to a line object + * @return true: auto size is enabled, false: disabled + */ +bool lv_line_get_auto_size(const lv_obj_t * line); + +/** + * Get the y inversion attribute + * @param line pointer to a line object + * @return true: y inversion is enabled, false: disabled + */ +bool lv_line_get_y_invert(const lv_obj_t * line); + +/** + * Get the style of an line object + * @param line pointer to an line object + * @return pointer to the line's style + */ +static inline lv_style_t* lv_line_get_style(const lv_obj_t *line) +{ + return lv_obj_get_style(line); +} + +/** + * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 + * @param line - + * @return false + */ +static inline bool lv_line_get_upscale(const lv_obj_t * line) +{ + (void) line; + return false; +} + + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_LINE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_LINE_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.c new file mode 100644 index 0000000..1f19215 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.c @@ -0,0 +1,1052 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_list.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_list.h" +#if USE_LV_LIST != 0 + +#include "../lv_core/lv_group.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_anim.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define LV_LIST_LAYOUT_DEF LV_LAYOUT_COL_M + +#if USE_LV_ANIMATION +# ifndef LV_LIST_FOCUS_TIME +# define LV_LIST_FOCUS_TIME 100 /*Animation time of focusing to the a list element [ms] (0: no animation) */ +# endif +#else +# undef LV_LIST_FOCUS_TIME +# define LV_LIST_FOCUS_TIME 0 /*No animations*/ +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param); +static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param); +static void refr_btn_width(lv_obj_t * list); +static void lv_list_btn_single_selected(lv_obj_t *btn); +static bool lv_list_is_list_btn(lv_obj_t * list_btn); +static bool lv_list_is_list_img(lv_obj_t * list_btn); +static bool lv_list_is_list_label(lv_obj_t * list_btn); + +/********************** + * STATIC VARIABLES + **********************/ +#if USE_LV_IMG +static lv_signal_func_t img_signal; +#endif +static lv_signal_func_t label_signal; +static lv_signal_func_t ancestor_page_signal; +static lv_signal_func_t ancestor_btn_signal; +#if USE_LV_GROUP +/*Used to make the last clicked button pressed (selected) when the list become focused and `click_focus == 1`*/ +static lv_obj_t * last_clicked_btn; +#endif + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a list objects + * @param par pointer to an object, it will be the parent of the new list + * @param copy pointer to a list object, if not NULL then the new object will be copied from it + * @return pointer to the created list + */ +lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("list create started"); + + /*Create the ancestor basic object*/ + lv_obj_t * new_list = lv_page_create(par, copy); + lv_mem_assert(new_list); + if(new_list == NULL) return NULL; + + if(ancestor_page_signal == NULL) ancestor_page_signal = lv_obj_get_signal_func(new_list); + + lv_list_ext_t * ext = lv_obj_allocate_ext_attr(new_list, sizeof(lv_list_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + // Important! + static lv_style_t img_btn_color; + lv_style_copy( &img_btn_color, &lv_style_plain); + img_btn_color.image.color = LV_COLOR_HEX(0xDDDDDD); + img_btn_color.image.intense = LV_OPA_50; + ext->style_img = &img_btn_color; + ext->styles_btn[LV_BTN_STATE_REL] = &lv_style_btn_rel; + ext->styles_btn[LV_BTN_STATE_PR] = &lv_style_btn_pr; + ext->styles_btn[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_rel; + ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr; + ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina; + ext->anim_time = LV_LIST_FOCUS_TIME; + ext->single_mode = false; + ext->size = 0; + +#if USE_LV_GROUP + ext->last_sel = NULL; + ext->selected_btn = NULL; +#endif + + lv_obj_set_signal_func(new_list, lv_list_signal); + + /*Init the new list object*/ + if(copy == NULL) { + lv_obj_set_size(new_list, 2 * LV_DPI, 3 * LV_DPI); + lv_page_set_scrl_layout(new_list, LV_LIST_LAYOUT_DEF); + lv_list_set_sb_mode(new_list, LV_SB_MODE_DRAG); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_list_set_style(new_list, LV_LIST_STYLE_BG, th->list.bg); + lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, th->list.scrl); + lv_list_set_style(new_list, LV_LIST_STYLE_SB, th->list.sb); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_REL, th->list.btn.rel); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_PR, th->list.btn.pr); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_REL, th->list.btn.tgl_rel); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_PR, th->list.btn.tgl_pr); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_INA, th->list.btn.ina); + } else { + lv_list_set_style(new_list, LV_LIST_STYLE_BG, &lv_style_transp_fit); + lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, &lv_style_pretty); + } + } else { + lv_list_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + + lv_obj_t * copy_btn = lv_list_get_next_btn(copy, NULL); + while(copy_btn) { + const void * img_src = NULL; +#if USE_LV_IMG + lv_obj_t * copy_img = lv_list_get_btn_img(copy_btn); + if(copy_img) img_src = lv_img_get_src(copy_img); +#endif + lv_list_add(new_list, img_src, lv_list_get_btn_text(copy_btn), lv_btn_get_action(copy_btn, LV_BTN_ACTION_CLICK)); + copy_btn = lv_list_get_next_btn(copy, copy_btn); + } + + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_REL, copy_ext->styles_btn[LV_BTN_STATE_REL]); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_PR, copy_ext->styles_btn[LV_BTN_STATE_PR]); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_REL, copy_ext->styles_btn[LV_BTN_STATE_TGL_REL]); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_PR, copy_ext->styles_btn[LV_BTN_STATE_TGL_REL]); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_INA, copy_ext->styles_btn[LV_BTN_STATE_INA]); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_list); + } + + + LV_LOG_INFO("list created"); + + + return new_list; +} + +/** + * Delete all children of the scrl object, without deleting scrl child. + * @param obj pointer to an object + */ +void lv_list_clean(lv_obj_t * obj) +{ + lv_obj_t * scrl = lv_page_get_scrl(obj); + lv_obj_clean(scrl); + lv_list_ext_t * ext = lv_obj_get_ext_attr(obj); + ext->size = 0; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add a list element to the list + * @param list pointer to list object + * @param img_fn file name of an image before the text (NULL if unused) + * @param txt text of the list element (NULL if unused) + * @param rel_action pointer to release action function (like with lv_btn) + * @return pointer to the new list element which can be customized (a button) + */ +lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, lv_action_t rel_action) +{ + lv_style_t * style = lv_obj_get_style(list); + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + ext->size ++; + /*Create a list element with the image an the text*/ + lv_obj_t * liste; + liste = lv_btn_create(list, NULL); + + /*Save the original signal function because it will be required in `lv_list_btn_signal`*/ + if(ancestor_btn_signal == NULL) ancestor_btn_signal = lv_obj_get_signal_func(liste); + + /*Set the default styles*/ + lv_btn_set_style(liste, LV_BTN_STYLE_REL, ext->styles_btn[LV_BTN_STATE_REL]); + lv_btn_set_style(liste, LV_BTN_STYLE_PR, ext->styles_btn[LV_BTN_STATE_PR]); + lv_btn_set_style(liste, LV_BTN_STYLE_TGL_REL, ext->styles_btn[LV_BTN_STATE_TGL_REL]); + lv_btn_set_style(liste, LV_BTN_STYLE_TGL_PR, ext->styles_btn[LV_BTN_STATE_TGL_PR]); + lv_btn_set_style(liste, LV_BTN_STYLE_INA, ext->styles_btn[LV_BTN_STATE_INA]); + + lv_btn_set_action(liste, LV_BTN_ACTION_CLICK, rel_action); + lv_page_glue_obj(liste, true); + lv_btn_set_layout(liste, LV_LAYOUT_ROW_M); + lv_btn_set_fit(liste, false, true); + lv_obj_set_protect(liste, LV_PROTECT_PRESS_LOST); + lv_obj_set_signal_func(liste, lv_list_btn_signal); + + /*Make the size adjustment*/ + lv_coord_t w = lv_obj_get_width(list); + lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(list)); + lv_coord_t pad_hor_tot = style->body.padding.hor + style_scrl->body.padding.hor; + w -= pad_hor_tot * 2; + + lv_obj_set_width(liste, w); +#if USE_LV_IMG != 0 + lv_obj_t * img = NULL; + if(img_src) { + img = lv_img_create(liste, NULL); + lv_img_set_src(img, img_src); + lv_obj_set_style(img, ext->style_img); + lv_obj_set_click(img, false); + if(img_signal == NULL) img_signal = lv_obj_get_signal_func(img); + } +#endif + if(txt != NULL) { + lv_coord_t btn_hor_pad = ext->styles_btn[LV_BTN_STYLE_REL]->body.padding.hor; + lv_obj_t * label = lv_label_create(liste, NULL); + lv_label_set_text(label, txt); + lv_obj_set_click(label, false); + lv_label_set_long_mode(label, LV_LABEL_LONG_ROLL); + lv_obj_set_width(label, liste->coords.x2 - label->coords.x1 - btn_hor_pad); + if(label_signal == NULL) label_signal = lv_obj_get_signal_func(label); + } +#if USE_LV_GROUP + /* If this is the first item to be added to the list and the list is + * focussed, select it */ + { + lv_group_t *g = lv_obj_get_group(list); + if(ext->size == 1 && lv_group_get_focused(g) == list) { + lv_list_set_btn_selected(list, liste); + } + } +#endif + + return liste; +} + +/** + * Remove the index of the button in the list + * @param list pointer to a list object + * @param index pointer to a the button's index in the list, index must be 0 <= index < lv_list_ext_t.size + * @return true: successfully deleted + */ +bool lv_list_remove(const lv_obj_t * list, uint32_t index) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + if(index >= ext->size) return false; + uint32_t count = 0; + lv_obj_t * e = lv_list_get_next_btn(list, NULL); + while(e != NULL) { + if(count == index) { + lv_obj_del(e); + ext->size --; + return true; + } + e = lv_list_get_next_btn(list, e); + count ++; + } + return false; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set single button selected mode, only one button will be selected if enabled. + * @param list pointer to the currently pressed list object + * @param mode, enable(true)/disable(false) single selected mode. + */ +void lv_list_set_single_mode(lv_obj_t *list, bool mode) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + + ext->single_mode = mode; +} + +#if USE_LV_GROUP + +/** + * Make a button selected + * @param list pointer to a list object + * @param btn pointer to a button to selectthe + */ +void lv_list_set_btn_selected(lv_obj_t * list, lv_obj_t * btn) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + + if(ext->selected_btn) { + lv_btn_state_t s = lv_btn_get_state(ext->selected_btn); + if(s == LV_BTN_STATE_PR) lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_REL); + else if(s == LV_BTN_STATE_TGL_PR) lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_TGL_REL); + } + + ext->selected_btn = btn; + if( btn != NULL ) { + ext->last_sel = btn; + } + + if(ext->selected_btn) { + lv_btn_state_t s = lv_btn_get_state(ext->selected_btn); + if(s == LV_BTN_STATE_REL) lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_PR); + else if(s == LV_BTN_STATE_TGL_REL) lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_TGL_PR); + + lv_page_focus(list, ext->selected_btn, ext->anim_time); + } +} + +#endif + +/** + * Set scroll animation duration on 'list_up()' 'list_down()' 'list_focus()' + * @param list pointer to a list object + * @param anim_time duration of animation [ms] + */ +void lv_list_set_anim_time(lv_obj_t * list, uint16_t anim_time) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); +#if USE_LV_ANIMATION == 0 + anim_time = 0; +#endif + + if(ext->anim_time == anim_time) return; + ext->anim_time = anim_time; +} + +/** + * Set a style of a list + * @param list pointer to a list object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_list_set_style(lv_obj_t * list, lv_list_style_t type, lv_style_t * style) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + lv_btn_style_t btn_style_refr = LV_BTN_STYLE_REL; + lv_obj_t * btn; + + switch(type) { + case LV_LIST_STYLE_BG: + lv_page_set_style(list, LV_PAGE_STYLE_BG, style); + /*style change signal will call 'refr_btn_width' */ + break; + case LV_LIST_STYLE_SCRL: + lv_page_set_style(list, LV_PAGE_STYLE_SCRL, style); + refr_btn_width(list); + break; + case LV_LIST_STYLE_SB: + lv_page_set_style(list, LV_PAGE_STYLE_SB, style); + break; + case LV_LIST_STYLE_EDGE_FLASH: + lv_page_set_style(list, LV_PAGE_STYLE_EDGE_FLASH, style); + break; + case LV_LIST_STYLE_BTN_REL: + ext->styles_btn[LV_BTN_STATE_REL] = style; + btn_style_refr = LV_BTN_STYLE_REL; + break; + case LV_LIST_STYLE_BTN_PR: + ext->styles_btn[LV_BTN_STATE_PR] = style; + btn_style_refr = LV_BTN_STYLE_PR; + break; + case LV_LIST_STYLE_BTN_TGL_REL: + ext->styles_btn[LV_BTN_STATE_TGL_REL] = style; + btn_style_refr = LV_BTN_STYLE_TGL_REL; + break; + case LV_LIST_STYLE_BTN_TGL_PR: + ext->styles_btn[LV_BTN_STATE_TGL_PR] = style; + btn_style_refr = LV_BTN_STYLE_TGL_PR; + break; + case LV_LIST_STYLE_BTN_INA: + ext->styles_btn[LV_BTN_STATE_INA] = style; + btn_style_refr = LV_BTN_STYLE_INA; + break; + } + + + /*Refresh existing buttons' style*/ + if(type == LV_LIST_STYLE_BTN_PR || type == LV_LIST_STYLE_BTN_REL || + type == LV_LIST_STYLE_BTN_TGL_REL || type == LV_LIST_STYLE_BTN_TGL_PR || + type == LV_LIST_STYLE_BTN_INA) { + btn = lv_list_get_prev_btn(list, NULL); + while(btn != NULL) { + lv_btn_set_style(btn, btn_style_refr, ext->styles_btn[btn_style_refr]); + btn = lv_list_get_prev_btn(list, btn); + } + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get single button selected mode. + * @param list pointer to the currently pressed list object. + */ +bool lv_list_get_single_mode(lv_obj_t *list) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + + return (ext->single_mode); +} + +/** + * Get the text of a list element + * @param btn pointer to list element + * @return pointer to the text + */ +const char * lv_list_get_btn_text(const lv_obj_t * btn) +{ + lv_obj_t * label = lv_list_get_btn_label(btn); + if(label == NULL) return ""; + return lv_label_get_text(label); +} + +/** + * Get the label object from a list element + * @param btn pointer to a list element (button) + * @return pointer to the label from the list element or NULL if not found + */ +lv_obj_t * lv_list_get_btn_label(const lv_obj_t * btn) +{ + lv_obj_t * label = lv_obj_get_child(btn, NULL); + if(label == NULL) return NULL; + + while(lv_list_is_list_label(label) == false) { + label = lv_obj_get_child(btn, label); + if(label == NULL) break; + } + + return label; +} + +/** + * Get the image object from a list element + * @param btn pointer to a list element (button) + * @return pointer to the image from the list element or NULL if not found + */ +lv_obj_t * lv_list_get_btn_img(const lv_obj_t * btn) +{ +#if USE_LV_IMG != 0 + lv_obj_t * img = lv_obj_get_child(btn, NULL); + if(img == NULL) return NULL; + + while(lv_list_is_list_img(img) == false) { + img = lv_obj_get_child(btn, img); + if(img == NULL) break; + } + + return img; +#else + return NULL; +#endif +} + +/** + * Get the previous button from list. (Starts from the top button) + * @param list pointer to a list object + * @param prev_btn pointer to button. Search the previous before it. + * @return pointer to the previous button or NULL when no more buttons + */ +lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn) +{ + /* Not a good practice but user can add/create objects to the lists manually. + * When getting the next button try to be sure that it is at least a button */ + + lv_obj_t * btn ; + lv_obj_t * scrl = lv_page_get_scrl(list); + + btn = lv_obj_get_child(scrl, prev_btn); + if(btn == NULL) return NULL; + + while(lv_list_is_list_btn(btn) == false) { + btn = lv_obj_get_child(scrl, btn); + if(btn == NULL) break; + } + + return btn; +} + + + + /** + * Get the next button from list. (Starts from the bottom button) + * @param list pointer to a list object + * @param prev_btn pointer to button. Search the next after it. + * @return pointer to the next button or NULL when no more buttons + */ +lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn) +{ + /* Not a good practice but user can add/create objects to the lists manually. + * When getting the next button try to be sure that it is at least a button */ + + lv_obj_t * btn ; + lv_obj_t * scrl = lv_page_get_scrl(list); + + btn = lv_obj_get_child_back(scrl, prev_btn); + if(btn == NULL) return NULL; + + while(lv_list_is_list_btn(btn) == false) { + btn = lv_obj_get_child_back(scrl, btn); + if(btn == NULL) break; + } + + return btn; +} + +/** + * Get the index of the button in the list + * @param list pointer to a list object. If NULL, assumes btn is part of a list. + * @param btn pointer to a list element (button) + * @return the index of the button in the list, or -1 of the button not in this list + */ +int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn) +{ + int index = 0; + if( list == NULL ){ + /* no list provided, assuming btn is part of a list */ + list = lv_obj_get_parent(lv_obj_get_parent(btn)); + } + lv_obj_t * e = lv_list_get_next_btn(list, NULL); + while(e != NULL) { + if(e == btn) { + return index; + } + index ++; + e = lv_list_get_next_btn(list, e); + } + return -1; +} + +/** + * Get the number of buttons in the list + * @param list pointer to a list object + * @return the number of buttons in the list + */ +uint32_t lv_list_get_size(const lv_obj_t * list) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + return ext->size; +} + +#if USE_LV_GROUP +/** + * Get the currently selected button + * @param list pointer to a list object + * @return pointer to the selected button + */ +lv_obj_t * lv_list_get_btn_selected(const lv_obj_t * list) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + return ext->selected_btn; +} + +#endif + +/** + * Get scroll animation duration + * @param list pointer to a list object + * @return duration of animation [ms] + */ +uint16_t lv_list_get_anim_time(const lv_obj_t * list) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + return ext->anim_time; +} + +/** + * Get a style of a list + * @param list pointer to a list object + * @param type which style should be get + * @return style pointer to a style + * */ +lv_style_t * lv_list_get_style(const lv_obj_t * list, lv_list_style_t type) +{ + lv_style_t * style = NULL; + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + + switch(type) { + case LV_LIST_STYLE_BG: + style = lv_page_get_style(list, LV_PAGE_STYLE_BG); + break; + case LV_LIST_STYLE_SCRL: + style = lv_page_get_style(list, LV_PAGE_STYLE_SB); + break; + case LV_LIST_STYLE_SB: + style = lv_page_get_style(list, LV_PAGE_STYLE_SCRL); + break; + case LV_LIST_STYLE_EDGE_FLASH: + style = lv_page_get_style(list, LV_PAGE_STYLE_EDGE_FLASH); + break; + case LV_LIST_STYLE_BTN_REL: + style = ext->styles_btn[LV_BTN_STATE_REL]; + break; + case LV_LIST_STYLE_BTN_PR: + style = ext->styles_btn[LV_BTN_STATE_PR]; + break; + case LV_LIST_STYLE_BTN_TGL_REL: + style = ext->styles_btn[LV_BTN_STATE_TGL_REL]; + break; + case LV_LIST_STYLE_BTN_TGL_PR: + style = ext->styles_btn[LV_BTN_STATE_TGL_PR]; + break; + case LV_LIST_STYLE_BTN_INA: + style = ext->styles_btn[LV_BTN_STATE_INA]; + break; + default: + style = NULL; + break; + } + + return style; +} +/*===================== + * Other functions + *====================*/ + +/** + * Move the list elements up by one + * @param list pointer a to list object + */ +void lv_list_up(const lv_obj_t * list) +{ + /*Search the first list element which 'y' coordinate is below the parent + * and position the list to show this element on the bottom*/ + lv_obj_t * scrl = lv_page_get_scrl(list); + lv_obj_t * e; + lv_obj_t * e_prev = NULL; + e = lv_list_get_prev_btn(list, NULL); + while(e != NULL) { + if(e->coords.y2 <= list->coords.y2) { + if(e_prev != NULL) { + lv_coord_t new_y = lv_obj_get_height(list) - (lv_obj_get_y(e_prev) + lv_obj_get_height(e_prev)); + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + if(ext->anim_time == 0) { + lv_obj_set_y(scrl, new_y); + } else { +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = scrl; + a.start = lv_obj_get_y(scrl); + a.end = new_y; + a.fp = (lv_anim_fp_t)lv_obj_set_y; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = LV_LIST_FOCUS_TIME; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#endif + } + } + break; + } + e_prev = e; + e = lv_list_get_prev_btn(list, e); + } +} + +/** + * Move the list elements down by one + * @param list pointer to a list object + */ +void lv_list_down(const lv_obj_t * list) +{ + /*Search the first list element which 'y' coordinate is above the parent + * and position the list to show this element on the top*/ + lv_obj_t * scrl = lv_page_get_scrl(list); + lv_obj_t * e; + e = lv_list_get_prev_btn(list, NULL); + while(e != NULL) { + if(e->coords.y1 < list->coords.y1) { + lv_coord_t new_y = -lv_obj_get_y(e); + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + if(ext->anim_time == 0) { + lv_obj_set_y(scrl, new_y); + } else { +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = scrl; + a.start = lv_obj_get_y(scrl); + a.end = new_y; + a.fp = (lv_anim_fp_t)lv_obj_set_y; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = LV_LIST_FOCUS_TIME; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); + +#endif + } + break; + } + e = lv_list_get_prev_btn(list, e); + } +} + +/** + * Focus on a list button. It ensures that the button will be visible on the list. + * @param btn pointer to a list button to focus + * @param anim_en true: scroll with animation, false: without animation + */ +void lv_list_focus(const lv_obj_t * btn, bool anim_en) +{ + +#if USE_LV_ANIMATION == 0 + anim_en = false; +#endif + + lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn)); + + lv_page_focus(list, btn, anim_en == false ? 0 : lv_list_get_anim_time(list)); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the list + * @param list pointer to a list object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_page_signal(list, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_CORD_CHG) { + /*Be sure the width of the buttons are correct*/ + lv_coord_t w = lv_obj_get_width(list); + if(w != lv_area_get_width(param)) { /*Width changed*/ + refr_btn_width(list); + } + } else if(sign == LV_SIGNAL_STYLE_CHG) { + /*Because of the possible change of horizontal and vertical padding refresh buttons width */ + refr_btn_width(list); + } else if(sign == LV_SIGNAL_FOCUS) { + +#if USE_LV_GROUP + lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + /*With ENCODER select the first button only in edit mode*/ + if(indev_type == LV_INDEV_TYPE_ENCODER) { + lv_group_t * g = lv_obj_get_group(list); + if(lv_group_get_editing(g)) { + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + if(ext->last_sel) { + /* Select the last used button */ + lv_list_set_btn_selected(list, ext->last_sel); + } + else { + /*Get the first button and mark it as selected*/ + lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL)); + } + } else { + lv_list_set_btn_selected(list, NULL); + } + } + /*Else select the clicked button*/ + else { + /*Mark the last clicked button (if any) as selected because it triggered the focus*/ + if(last_clicked_btn) { + lv_list_set_btn_selected(list, last_clicked_btn); + } else { + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + if(ext->last_sel) { + /* Select the last used button */ + lv_list_set_btn_selected(list, ext->last_sel); + } + else { + /*Get the first button and mark it as selected*/ + lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL)); + } + } + } +#endif + } else if(sign == LV_SIGNAL_DEFOCUS) { + +#if USE_LV_GROUP + /*De-select the selected btn*/ + lv_list_set_btn_selected(list, NULL); + last_clicked_btn = NULL; /*button click will be set if click happens before focus*/ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + ext->selected_btn = NULL; +#endif + } else if(sign == LV_SIGNAL_GET_EDITABLE) { + bool * editable = (bool *)param; + *editable = true; + } else if(sign == LV_SIGNAL_CONTROLL) { + +#if USE_LV_GROUP + char c = *((char *)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) { + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + /*If there is a valid selected button the make the previous selected*/ + if(ext->selected_btn) { + lv_obj_t * btn_prev = lv_list_get_next_btn(list, ext->selected_btn); + if(btn_prev) lv_list_set_btn_selected(list, btn_prev); + } + /*If there is no selected button the make the first selected*/ + else { + lv_obj_t * btn = lv_list_get_next_btn(list, NULL); + if(btn) lv_list_set_btn_selected(list, btn); /*If there are no buttons on the list then there is no first button*/ + } + } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) { + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + /*If there is a valid selected button the make the next selected*/ + if(ext->selected_btn != NULL) { + lv_obj_t * btn_next = lv_list_get_prev_btn(list, ext->selected_btn); + if(btn_next) lv_list_set_btn_selected(list, btn_next); + } + /*If there is no selected button the make the first selected*/ + else { + lv_obj_t * btn = lv_list_get_next_btn(list, NULL); + if(btn) lv_list_set_btn_selected(list, btn); + } + } else if(c == LV_GROUP_KEY_ENTER) { + /*Get the 'pressed' button*/ + lv_obj_t * btn = NULL; + btn = lv_list_get_prev_btn(list, btn); + while(btn != NULL) { + if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break; + btn = lv_list_get_prev_btn(list, btn); + } + + if(btn != NULL) { + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + ext->last_sel = btn; + lv_action_t rel_action; + rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_CLICK); + if(rel_action != NULL) rel_action(btn); + } + } +#endif + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_list"; + } + return res; +} + + +/** + * Signal function of the list buttons + * @param btn pointer to a button on the list + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_btn_signal(btn, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_RELEASED) { + lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn)); + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + ext->page.scroll_prop_ip = 0; + +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(list); + if(lv_group_get_focused(g) == list && lv_indev_is_dragging(lv_indev_get_act()) == false) { + /* Is the list is focused then be sure only the button being released + * has a pressed state to indicate the selected state on the list*/ + lv_obj_t * btn_i = lv_list_get_prev_btn(list, NULL); + while(btn_i) { + lv_btn_state_t s = lv_btn_get_state(btn_i); + if(s == LV_BTN_STATE_PR) lv_btn_set_state(btn_i, LV_BTN_STATE_REL); + else if(s == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn_i, LV_BTN_STATE_TGL_REL); + btn_i = lv_list_get_prev_btn(list, btn_i); + } + + /*Make the released button "selected"*/ + lv_list_set_btn_selected(list, btn); + } + + /* If `click_focus == 1` then LV_SIGNAL_FOCUS need to know which button triggered the focus + * to mark it as selected (pressed state)*/ + last_clicked_btn = btn; +#endif + if(lv_indev_is_dragging(lv_indev_get_act()) == false && ext->single_mode) + { + lv_list_btn_single_selected(btn); + } + } + else if(sign == LV_SIGNAL_PRESS_LOST) { + lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn)); + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + ext->page.scroll_prop_ip = 0; + } + else if(sign == LV_SIGNAL_CLEANUP) { + +#if USE_LV_GROUP + lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn)); + lv_obj_t * sel = lv_list_get_btn_selected(list); + if(sel == btn) lv_list_set_btn_selected(list, lv_list_get_next_btn(list, btn)); +#endif + } + + + return res; +} + +static void refr_btn_width(lv_obj_t * list) +{ + lv_style_t * style = lv_list_get_style(list, LV_LIST_STYLE_BG); + lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(list)); + lv_coord_t w = lv_obj_get_width(list); + lv_coord_t btn_w = w - (style->body.padding.hor + style_scrl->body.padding.hor) * 2; + + lv_obj_t * btn = lv_list_get_prev_btn(list, NULL); + while(btn) { + /*Make the size adjustment for each buttons*/ + if(lv_obj_get_width(btn) != btn_w) { + lv_obj_set_width(btn, btn_w); + /*Set the label size to roll its text*/ + lv_obj_t * label = lv_list_get_btn_label(btn); + lv_obj_set_width(label, btn->coords.x2 - label->coords.x1); + lv_label_set_text(label, NULL); + } + btn = lv_list_get_prev_btn(list, btn); + } +} + +/** + * Make a single button selected in the list, deselect others, should be called in list btns call back. + * @param btn pointer to the currently pressed list btn object + */ +static void lv_list_btn_single_selected(lv_obj_t *btn) +{ + lv_obj_t *list = lv_obj_get_parent(lv_obj_get_parent(btn)); + + lv_obj_t * e = lv_list_get_next_btn(list, NULL); + do + { + if(e == btn) + { + lv_btn_set_state(e, LV_BTN_STATE_TGL_REL); + } + else + { + lv_btn_set_state(e, LV_BTN_STATE_REL); + } + e = lv_list_get_next_btn(list, e); + } while (e != NULL); +} + +/** + * Check if this is really a list button or another object. + * @param list_btn List button + */ +static bool lv_list_is_list_btn(lv_obj_t * list_btn) +{ + lv_obj_type_t type; + + lv_obj_get_type(list_btn, &type); + uint8_t cnt; + for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) { + if(type.type[cnt] == NULL) break; + if(!strcmp(type.type[cnt], "lv_btn")) + return true; + } + return false; +} + +/** + * Check if this is really a list label or another object. + * @param list_label List label + */ +static bool lv_list_is_list_label(lv_obj_t * list_label) +{ + lv_obj_type_t type; + + lv_obj_get_type(list_label, &type); + uint8_t cnt; + for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) { + if(type.type[cnt] == NULL) break; + if(!strcmp(type.type[cnt], "lv_label")) + return true; + } + return false; +} + +/** + * Check if this is really a list image or another object. + * @param list_image List image + */ +static bool lv_list_is_list_img(lv_obj_t * list_img) +{ + lv_obj_type_t type; + + lv_obj_get_type(list_img, &type); + uint8_t cnt; + for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) { + if(type.type[cnt] == NULL) break; + if(!strcmp(type.type[cnt], "lv_img")) + return true; + } + return false; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.h new file mode 100644 index 0000000..a318770 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_list.h @@ -0,0 +1,336 @@ +/** + * @file lv_list.h + * + */ + +#ifndef LV_LIST_H +#define LV_LIST_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_LIST != 0 + +/*Testing of dependencies*/ +#if USE_LV_PAGE == 0 +#error "lv_list: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " +#endif + +#if USE_LV_BTN == 0 +#error "lv_list: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " +#endif + +#if USE_LV_LABEL == 0 +#error "lv_list: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#endif + + +#include "../lv_core/lv_obj.h" +#include "lv_page.h" +#include "lv_btn.h" +#include "lv_label.h" +#include "lv_img.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of list*/ +typedef struct +{ + lv_page_ext_t page; /*Ext. of ancestor*/ + /*New data for this type */ + uint16_t anim_time; /*Scroll animation time*/ + lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/ + lv_style_t *style_img; /*Style of the list element images on buttons*/ + uint32_t size; /*the number of items(buttons) in the list*/ + bool single_mode; /* whether single selected mode is enabled */ +#if USE_LV_GROUP + lv_obj_t * last_sel; /* The last selected button. It will be reverted when the list is focused again */ + lv_obj_t * selected_btn; /* The button is currently being selected*/ +#endif +} lv_list_ext_t; + +enum { + LV_LIST_STYLE_BG, + LV_LIST_STYLE_SCRL, + LV_LIST_STYLE_SB, + LV_LIST_STYLE_EDGE_FLASH, + LV_LIST_STYLE_BTN_REL, + LV_LIST_STYLE_BTN_PR, + LV_LIST_STYLE_BTN_TGL_REL, + LV_LIST_STYLE_BTN_TGL_PR, + LV_LIST_STYLE_BTN_INA, +}; +typedef uint8_t lv_list_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a list objects + * @param par pointer to an object, it will be the parent of the new list + * @param copy pointer to a list object, if not NULL then the new object will be copied from it + * @return pointer to the created list + */ +lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy); + +/** + * Delete all children of the scrl object, without deleting scrl child. + * @param obj pointer to an object + */ +void lv_list_clean(lv_obj_t *obj); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add a list element to the list + * @param list pointer to list object + * @param img_fn file name of an image before the text (NULL if unused) + * @param txt text of the list element (NULL if unused) + * @param rel_action pointer to release action function (like with lv_btn) + * @return pointer to the new list element which can be customized (a button) + */ +lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, lv_action_t rel_action); + +/** + * Remove the index of the button in the list + * @param list pointer to a list object + * @param index pointer to a the button's index in the list, index must be 0 <= index < lv_list_ext_t.size + * @return true: successfully deleted + */ +bool lv_list_remove(const lv_obj_t * list, uint32_t index); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set single button selected mode, only one button will be selected if enabled. + * @param list pointer to the currently pressed list object + * @param mode, enable(true)/disable(false) single selected mode. + */ +void lv_list_set_single_mode(lv_obj_t *list, bool mode); + +#if USE_LV_GROUP + +/** + * Make a button selected. Can be used while navigating in the list with a keypad. + * @param list pointer to a list object + * @param btn pointer to a button to select + */ +void lv_list_set_btn_selected(lv_obj_t * list, lv_obj_t * btn); +#endif + +/** + * Set scroll animation duration on 'list_up()' 'list_down()' 'list_focus()' + * @param list pointer to a list object + * @param anim_time duration of animation [ms] + */ +void lv_list_set_anim_time(lv_obj_t *list, uint16_t anim_time); + +/** + * Set the scroll bar mode of a list + * @param list pointer to a list object + * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum + */ +static inline void lv_list_set_sb_mode(lv_obj_t * list, lv_sb_mode_t mode) +{ + lv_page_set_sb_mode(list, mode); +} + +/** + * Enable the scroll propagation feature. If enabled then the List will move its parent if there is no more space to scroll. + * @param list pointer to a List + * @param en true or false to enable/disable scroll propagation + */ +static inline void lv_list_set_scroll_propagation(lv_obj_t * list, bool en) +{ + lv_page_set_scroll_propagation(list, en); +} + +/** + * Enable the edge flash effect. (Show an arc when the an edge is reached) + * @param list pointer to a List + * @param en true or false to enable/disable end flash + */ +static inline void lv_list_set_edge_flash(lv_obj_t * list, bool en) +{ + lv_page_set_edge_flash(list, en); +} + +/** + * Set a style of a list + * @param list pointer to a list object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_list_set_style(lv_obj_t *list, lv_list_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get single button selected mode. + * @param list pointer to the currently pressed list object. + */ +bool lv_list_get_single_mode(lv_obj_t *list); + +/** + * Get the text of a list element + * @param btn pointer to list element + * @return pointer to the text + */ +const char * lv_list_get_btn_text(const lv_obj_t * btn); +/** + * Get the label object from a list element + * @param btn pointer to a list element (button) + * @return pointer to the label from the list element or NULL if not found + */ +lv_obj_t * lv_list_get_btn_label(const lv_obj_t * btn); + +/** + * Get the image object from a list element + * @param btn pointer to a list element (button) + * @return pointer to the image from the list element or NULL if not found + */ +lv_obj_t * lv_list_get_btn_img(const lv_obj_t * btn); + +/** + * Get the next button from list. (Starts from the bottom button) + * @param list pointer to a list object + * @param prev_btn pointer to button. Search the next after it. + * @return pointer to the next button or NULL when no more buttons + */ +lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn); + +/** + * Get the previous button from list. (Starts from the top button) + * @param list pointer to a list object + * @param prev_btn pointer to button. Search the previous before it. + * @return pointer to the previous button or NULL when no more buttons + */ +lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn); + +/** + * Get the index of the button in the list + * @param list pointer to a list object. If NULL, assumes btn is part of a list. + * @param btn pointer to a list element (button) + * @return the index of the button in the list, or -1 of the button not in this list + */ +int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn); + +/** + * Get the number of buttons in the list + * @param list pointer to a list object + * @return the number of buttons in the list + */ +uint32_t lv_list_get_size(const lv_obj_t * list); + +#if USE_LV_GROUP +/** + * Get the currently selected button. Can be used while navigating in the list with a keypad. + * @param list pointer to a list object + * @return pointer to the selected button + */ +lv_obj_t * lv_list_get_btn_selected(const lv_obj_t * list); +#endif + + +/** + * Get scroll animation duration + * @param list pointer to a list object + * @return duration of animation [ms] + */ +uint16_t lv_list_get_anim_time(const lv_obj_t *list); + + +/** + * Get the scroll bar mode of a list + * @param list pointer to a list object + * @return scrollbar mode from 'lv_page_sb_mode_t' enum + */ +static inline lv_sb_mode_t lv_list_get_sb_mode(const lv_obj_t * list) +{ + return lv_page_get_sb_mode(list); +} + +/** + * Get the scroll propagation property + * @param list pointer to a List + * @return true or false + */ +static inline bool lv_list_get_scroll_propagation(lv_obj_t * list) +{ + return lv_page_get_scroll_propagation(list); +} + +/** + * Get the scroll propagation property + * @param list pointer to a List + * @return true or false + */ +static inline bool lv_list_get_edge_flash(lv_obj_t * list) +{ + return lv_page_get_edge_flash(list); +} + +/** + * Get a style of a list + * @param list pointer to a list object + * @param type which style should be get + * @return style pointer to a style + * */ +lv_style_t * lv_list_get_style(const lv_obj_t *list, lv_list_style_t type); + +/*===================== + * Other functions + *====================*/ + +/** + * Move the list elements up by one + * @param list pointer a to list object + */ +void lv_list_up(const lv_obj_t * list); +/** + * Move the list elements down by one + * @param list pointer to a list object + */ +void lv_list_down(const lv_obj_t * list); + +/** + * Focus on a list button. It ensures that the button will be visible on the list. + * @param btn pointer to a list button to focus + * @param anim_en true: scroll with animation, false: without animation + */ +void lv_list_focus(const lv_obj_t *btn, bool anim_en); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_LIST*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_LIST_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.c new file mode 100644 index 0000000..4d78d8e --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.c @@ -0,0 +1,382 @@ +/** + * @file lv_lmeter.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_lmeter.h" +#if USE_LV_LMETER != 0 + +#include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_core/lv_group.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define LV_LMETER_LINE_UPSCALE 5 /*2^x upscale of line to make rounding*/ +#define LV_LMETER_LINE_UPSCALE_MASK ((1 << LV_LMETER_LINE_UPSCALE) - 1) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_lmeter_design(lv_obj_t * lmeter, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_lmeter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * param); +static lv_coord_t lv_lmeter_coord_round(int32_t x); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a line meter objects + * @param par pointer to an object, it will be the parent of the new line meter + * @param copy pointer to a line meter object, if not NULL then the new object will be copied from it + * @return pointer to the created line meter + */ +lv_obj_t * lv_lmeter_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("line meter create started"); + + /*Create the ancestor of line meter*/ + lv_obj_t * new_lmeter = lv_obj_create(par, copy); + lv_mem_assert(new_lmeter); + if(new_lmeter == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_lmeter); + + /*Allocate the line meter type specific extended data*/ + lv_lmeter_ext_t * ext = lv_obj_allocate_ext_attr(new_lmeter, sizeof(lv_lmeter_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + /*Initialize the allocated 'ext' */ + ext->min_value = 0; + ext->max_value = 100; + ext->cur_value = 0; + ext->line_cnt = 21; /*Odd scale number looks better*/ + ext->scale_angle = 240; /*(scale_num - 1) * N looks better */ + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_lmeter, lv_lmeter_signal); + lv_obj_set_design_func(new_lmeter, lv_lmeter_design); + + /*Init the new line meter line meter*/ + if(copy == NULL) { + lv_obj_set_size(new_lmeter, LV_DPI, LV_DPI); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_lmeter_set_style(new_lmeter, th->lmeter); + } else { + lv_lmeter_set_style(new_lmeter, &lv_style_pretty_color); + } + } + /*Copy an existing line meter*/ + else { + lv_lmeter_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->scale_angle = copy_ext->scale_angle; + ext->line_cnt = copy_ext->line_cnt; + ext->min_value = copy_ext->min_value; + ext->max_value = copy_ext->max_value; + ext->cur_value = copy_ext->cur_value; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_lmeter); + } + + LV_LOG_INFO("line meter created"); + + return new_lmeter; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the line meter + * @param lmeter pointer to a line meter object + * @param value new value + */ +void lv_lmeter_set_value(lv_obj_t * lmeter, int16_t value) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + if(ext->cur_value == value) return; + + ext->cur_value = value > ext->max_value ? ext->max_value : value; + ext->cur_value = ext->cur_value < ext->min_value ? ext->min_value : ext->cur_value; + lv_obj_invalidate(lmeter); +} + +/** + * Set minimum and the maximum values of a line meter + * @param lmeter pointer to he line meter object + * @param min minimum value + * @param max maximum value + */ +void lv_lmeter_set_range(lv_obj_t * lmeter, int16_t min, int16_t max) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + if(ext->min_value == min && ext->max_value == max) return; + + ext->max_value = max; + ext->min_value = min; + if(ext->cur_value > max) { + ext->cur_value = max; + lv_lmeter_set_value(lmeter, ext->cur_value); + } + if(ext->cur_value < min) { + ext->cur_value = min; + lv_lmeter_set_value(lmeter, ext->cur_value); + } + lv_obj_invalidate(lmeter); +} + +/** + * Set the scale settings of a line meter + * @param lmeter pointer to a line meter object + * @param angle angle of the scale (0..360) + * @param line_cnt number of lines + */ +void lv_lmeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint8_t line_cnt) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + if(ext->scale_angle == angle && ext->line_cnt == line_cnt) return; + + ext->scale_angle = angle; + ext->line_cnt = line_cnt; + + lv_obj_invalidate(lmeter); +} + + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a line meter + * @param lmeter pointer to a line meter object + * @return the value of the line meter + */ +int16_t lv_lmeter_get_value(const lv_obj_t * lmeter) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + return ext->cur_value; +} + +/** + * Get the minimum value of a line meter + * @param lmeter pointer to a line meter object + * @return the minimum value of the line meter + */ +int16_t lv_lmeter_get_min_value(const lv_obj_t * lmeter) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + return ext->min_value; +} + +/** + * Get the maximum value of a line meter + * @param lmeter pointer to a line meter object + * @return the maximum value of the line meter + */ +int16_t lv_lmeter_get_max_value(const lv_obj_t * lmeter) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + return ext->max_value; +} + +/** + * Get the scale number of a line meter + * @param lmeter pointer to a line meter object + * @return number of the scale units + */ +uint8_t lv_lmeter_get_line_count(const lv_obj_t * lmeter) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + return ext->line_cnt ; +} + +/** + * Get the scale angle of a line meter + * @param lmeter pointer to a line meter object + * @return angle of the scale + */ +uint16_t lv_lmeter_get_scale_angle(const lv_obj_t * lmeter) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + return ext->scale_angle; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + + +/** + * Handle the drawing related tasks of the line meters + * @param lmeter pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_lmeter_design(lv_obj_t * lmeter, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + lv_style_t * style = lv_obj_get_style(lmeter); + lv_opa_t opa_scale = lv_obj_get_opa_scale(lmeter); + lv_style_t style_tmp; + memcpy(&style_tmp, style, sizeof(lv_style_t)); + + +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(lmeter); + if(lv_group_get_focused(g) == lmeter) { + style_tmp.line.width += 1; + } +#endif + + lv_coord_t r_out = lv_obj_get_width(lmeter) / 2; + lv_coord_t r_in = r_out - style->body.padding.hor; + if(r_in < 1) r_in = 1; + + lv_coord_t x_ofs = lv_obj_get_width(lmeter) / 2 + lmeter->coords.x1; + lv_coord_t y_ofs = lv_obj_get_height(lmeter) / 2 + lmeter->coords.y1; + int16_t angle_ofs = 90 + (360 - ext->scale_angle) / 2; + int16_t level = (int32_t)((int32_t)(ext->cur_value - ext->min_value) * ext->line_cnt) / (ext->max_value - ext->min_value); + uint8_t i; + + style_tmp.line.color = style->body.main_color; + + /*Calculate every coordinate in a bigger size to make rounding later*/ + r_out = r_out << LV_LMETER_LINE_UPSCALE; + r_in = r_in << LV_LMETER_LINE_UPSCALE; + + for(i = 0; i < ext->line_cnt; i++) { + /*Calculate the position a scale label*/ + int16_t angle = (i * ext->scale_angle) / (ext->line_cnt - 1) + angle_ofs; + + lv_coord_t y_out = (int32_t)((int32_t)lv_trigo_sin(angle) * r_out) >> LV_TRIGO_SHIFT; + lv_coord_t x_out = (int32_t)((int32_t)lv_trigo_sin(angle + 90) * r_out) >> LV_TRIGO_SHIFT; + lv_coord_t y_in = (int32_t)((int32_t)lv_trigo_sin(angle) * r_in) >> LV_TRIGO_SHIFT; + lv_coord_t x_in = (int32_t)((int32_t)lv_trigo_sin(angle + 90) * r_in) >> LV_TRIGO_SHIFT; + + /*Rounding*/ + x_out = lv_lmeter_coord_round(x_out); + x_in = lv_lmeter_coord_round(x_in); + y_out = lv_lmeter_coord_round(y_out); + y_in = lv_lmeter_coord_round(y_in); + + lv_point_t p1; + lv_point_t p2; + + p2.x = x_in + x_ofs; + p2.y = y_in + y_ofs; + + p1.x = x_out + x_ofs; + p1.y = y_out + y_ofs; + + if(i >= level) style_tmp.line.color = style->line.color; + else { + style_tmp.line.color = lv_color_mix(style->body.grad_color, style->body.main_color, (255 * i) / ext->line_cnt); + } + + lv_draw_line(&p1, &p2, mask, &style_tmp, opa_scale); + } + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the line meter + * @param lmeter pointer to a line meter object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_lmeter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(lmeter, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_STYLE_CHG) { + lv_obj_refresh_ext_size(lmeter); + } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + lv_style_t * style = lv_lmeter_get_style(lmeter); + lmeter->ext_size = LV_MATH_MAX(lmeter->ext_size, style->line.width); + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_lmeter"; + } + + return res; +} + +/** + * Round a coordinate which is upscaled (>=x.5 -> x + 1; x) + * @param x a coordinate which is greater then it should be + * @return the downscaled and rounded coordinate (+-1) + */ +static lv_coord_t lv_lmeter_coord_round(int32_t x) +{ +#if LV_LMETER_LINE_UPSCALE > 0 + bool was_negative = false; + if(x < 0) { + was_negative = true; + x = -x; + } + + x = (x >> LV_LMETER_LINE_UPSCALE) + ((x & LV_LMETER_LINE_UPSCALE_MASK) >> (LV_LMETER_LINE_UPSCALE - 1)); + + if(was_negative) x = -x; + + return x; +#else + return x; +#endif +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.h new file mode 100644 index 0000000..0235d34 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_lmeter.h @@ -0,0 +1,153 @@ +/** + * @file lv_lmeter.h + * + */ + +#ifndef LV_LMETER_H +#define LV_LMETER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_LMETER != 0 + +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of line meter*/ +typedef struct +{ + /*No inherited ext.*/ /*Ext. of ancestor*/ + /*New data for this type */ + uint16_t scale_angle; /*Angle of the scale in deg. (0..360)*/ + uint8_t line_cnt; /*Count of lines */ + int16_t cur_value; + int16_t min_value; + int16_t max_value; +} lv_lmeter_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a line meter objects + * @param par pointer to an object, it will be the parent of the new line meter + * @param copy pointer to a line meter object, if not NULL then the new object will be copied from it + * @return pointer to the created line meter + */ +lv_obj_t * lv_lmeter_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the line meter + * @param lmeter pointer to a line meter object + * @param value new value + */ +void lv_lmeter_set_value(lv_obj_t *lmeter, int16_t value); + +/** + * Set minimum and the maximum values of a line meter + * @param lmeter pointer to he line meter object + * @param min minimum value + * @param max maximum value + */ +void lv_lmeter_set_range(lv_obj_t *lmeter, int16_t min, int16_t max); + +/** + * Set the scale settings of a line meter + * @param lmeter pointer to a line meter object + * @param angle angle of the scale (0..360) + * @param line_cnt number of lines + */ +void lv_lmeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint8_t line_cnt); + +/** + * Set the styles of a line meter + * @param lmeter pointer to a line meter object + * @param bg set the style of the line meter + */ +static inline void lv_lmeter_set_style(lv_obj_t *lmeter, lv_style_t *bg) +{ + lv_obj_set_style(lmeter, bg); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a line meter + * @param lmeter pointer to a line meter object + * @return the value of the line meter + */ +int16_t lv_lmeter_get_value(const lv_obj_t *lmeter); + +/** + * Get the minimum value of a line meter + * @param lmeter pointer to a line meter object + * @return the minimum value of the line meter + */ +int16_t lv_lmeter_get_min_value(const lv_obj_t * lmeter); + +/** + * Get the maximum value of a line meter + * @param lmeter pointer to a line meter object + * @return the maximum value of the line meter + */ +int16_t lv_lmeter_get_max_value(const lv_obj_t * lmeter); + +/** + * Get the scale number of a line meter + * @param lmeter pointer to a line meter object + * @return number of the scale units + */ +uint8_t lv_lmeter_get_line_count(const lv_obj_t * lmeter); + +/** + * Get the scale angle of a line meter + * @param lmeter pointer to a line meter object + * @return angle of the scale + */ +uint16_t lv_lmeter_get_scale_angle(const lv_obj_t * lmeter); + +/** + * Get the style of a line meter + * @param lmeter pointer to a line meter object + * @return pointer to the line meter's style + */ +static inline lv_style_t * lv_lmeter_get_style(const lv_obj_t * lmeter) +{ + return lv_obj_get_style(lmeter); +} + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_LMETER*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_LMETER_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.c new file mode 100644 index 0000000..4dcacdd --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.c @@ -0,0 +1,532 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_mbox.c + * + */ + + +/********************* + * INCLUDES + *********************/ +#include "lv_mbox.h" +#if USE_LV_MBOX != 0 + +#include "../lv_core/lv_group.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_anim.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ + +#if USE_LV_ANIMATION +# ifndef LV_MBOX_CLOSE_ANIM_TIME +# define LV_MBOX_CLOSE_ANIM_TIME 200 /*List close animation time) */ +# endif +#else +# undef LV_MBOX_CLOSE_ANIM_TIME +# define LV_MBOX_CLOSE_ANIM_TIME 0 /*No animations*/ +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param); +static void mbox_realign(lv_obj_t * mbox); +static lv_res_t lv_mbox_close_action(lv_obj_t * btn, const char * txt); +#if USE_LV_ANIMATION +static void lv_mbox_close_end_cb(lv_obj_t * mbox); +#endif + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a message box objects + * @param par pointer to an object, it will be the parent of the new message box + * @param copy pointer to a message box object, if not NULL then the new object will be copied from it + * @return pointer to the created message box + */ +lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("mesasge box create started"); + + /*Create the ancestor message box*/ + lv_obj_t * new_mbox = lv_cont_create(par, copy); + lv_mem_assert(new_mbox); + if(new_mbox == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_mbox); + + /*Allocate the message box type specific extended data*/ + lv_mbox_ext_t * ext = lv_obj_allocate_ext_attr(new_mbox, sizeof(lv_mbox_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->text = NULL; + ext->btnm = NULL; + ext->anim_time = LV_MBOX_CLOSE_ANIM_TIME; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_mbox, lv_mbox_signal); + + /*Init the new message box message box*/ + if(copy == NULL) { + ext->text = lv_label_create(new_mbox, NULL); + lv_label_set_align(ext->text, LV_LABEL_ALIGN_CENTER); + lv_label_set_long_mode(ext->text, LV_LABEL_LONG_BREAK); + lv_label_set_text(ext->text, "Message"); + + lv_cont_set_layout(new_mbox, LV_LAYOUT_COL_M); + lv_cont_set_fit(new_mbox, false, true); + lv_obj_set_width(new_mbox, LV_HOR_RES / 2); + lv_obj_align(new_mbox, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, th->mbox.bg); + } else { + lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, &lv_style_pretty); + } + + } + /*Copy an existing message box*/ + else { + lv_mbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + + ext->text = lv_label_create(new_mbox, copy_ext->text); + + /*Copy the buttons and the label on them*/ + if(copy_ext->btnm) ext->btnm = lv_btnm_create(new_mbox, copy_ext->btnm); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_mbox); + } + + + LV_LOG_INFO("mesasge box created"); + + return new_mbox; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add button to the message box + * @param mbox pointer to message box object + * @param btn_map button descriptor (button matrix map). + * E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable) + * @param action a function which will be called when a button is released + */ +void lv_mbox_add_btns(lv_obj_t * mbox, const char ** btn_map, lv_btnm_action_t action) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + /*Create a button matrix if not exists yet*/ + if(ext->btnm == NULL) { + ext->btnm = lv_btnm_create(mbox, NULL); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_BG, th->mbox.btn.bg); + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_REL, th->mbox.btn.rel); + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_PR, th->mbox.btn.pr); + } else { + lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, &lv_style_transp_fit); + } + } + + lv_btnm_set_map(ext->btnm, btn_map); + if(action == NULL) lv_btnm_set_action(ext->btnm, lv_mbox_close_action); /*Set a default action anyway*/ + else lv_btnm_set_action(ext->btnm, action); + + mbox_realign(mbox); +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of the message box + * @param mbox pointer to a message box + * @param txt a '\0' terminated character string which will be the message box text + */ +void lv_mbox_set_text(lv_obj_t * mbox, const char * txt) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + lv_label_set_text(ext->text, txt); + + mbox_realign(mbox); +} + + +/** + * Stop the action to call when button is released + * @param pointer to an 'lv_btnm_action_t' action. In the action you need to use `lv_mbox_get_from_btn()` to get the `mbox`. + * @param pointer to an 'lv_btnm_action_t' action + */ +void lv_mbox_set_action(lv_obj_t * mbox, lv_btnm_action_t action) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + lv_btnm_set_action(ext->btnm, action); +} + + +/** + * Set animation duration + * @param mbox pointer to a message box object + * @param anim_time animation length in milliseconds (0: no animation) + */ +void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); +#if USE_LV_ANIMATION == 0 + anim_time = 0; +#endif + + ext->anim_time = anim_time; +} + +/** + * Automatically delete the message box after a given time + * @param mbox pointer to a message box object + * @param delay a time (in milliseconds) to wait before delete the message box + */ +void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay) +{ +#if USE_LV_ANIMATION + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + if(ext->anim_time != 0) { + /*Add shrinking animations*/ + lv_obj_animate(mbox, LV_ANIM_GROW_H | LV_ANIM_OUT, ext->anim_time, delay, NULL); + lv_obj_animate(mbox, LV_ANIM_GROW_V | LV_ANIM_OUT, ext->anim_time, delay, lv_mbox_close_end_cb); + + /*Disable fit to let shrinking work*/ + lv_cont_set_fit(mbox, false, false); + } else { + lv_obj_animate(mbox, LV_ANIM_NONE, ext->anim_time, delay, lv_mbox_close_end_cb); + } +#else + (void)delay; /*Unused*/ + lv_obj_del(mbox); +#endif +} + +/** + * Stop the auto. closing of message box + * @param mbox pointer to a message box object + */ +void lv_mbox_stop_auto_close(lv_obj_t * mbox) +{ +#if USE_LV_ANIMATION + lv_anim_del(mbox, NULL); +#else + (void)mbox; /*Unused*/ +#endif +} + +/** + * Set a style of a message box + * @param mbox pointer to a message box object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_mbox_set_style(lv_obj_t * mbox, lv_mbox_style_t type, lv_style_t * style) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + switch(type) { + case LV_MBOX_STYLE_BG: + lv_obj_set_style(mbox, style); + break; + case LV_MBOX_STYLE_BTN_BG: + lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, style); + break; + case LV_MBOX_STYLE_BTN_REL: + lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_REL, style); + break; + case LV_MBOX_STYLE_BTN_PR: + lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_PR, style); + break; + case LV_MBOX_STYLE_BTN_TGL_REL: + lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_REL, style); + break; + case LV_MBOX_STYLE_BTN_TGL_PR: + lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_PR, style); + break; + case LV_MBOX_STYLE_BTN_INA: + lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_INA, style); + break; + } + + mbox_realign(mbox); + +} + +/** + * Set whether recoloring is enabled + * @param btnm pointer to button matrix object + * @param en whether recoloring is enabled + */ +void lv_mbox_set_recolor(lv_obj_t * mbox, bool en) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + if(ext->btnm) + lv_btnm_set_recolor(ext->btnm, en); +} + +void lv_mbox_set_recolor_text(lv_obj_t * mbox, bool en) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + if (ext->text) + lv_label_set_recolor(ext->text, en); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of the message box + * @param mbox pointer to a message box object + * @return pointer to the text of the message box + */ +const char * lv_mbox_get_text(const lv_obj_t * mbox) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + return lv_label_get_text(ext->text); +} + +/** + * Get the message box object from one of its button. + * It is useful in the button release actions where only the button is known + * @param btn pointer to a button of a message box + * @return pointer to the button's message box + */ +lv_obj_t * lv_mbox_get_from_btn(const lv_obj_t * btn) +{ + lv_obj_t * mbox = lv_obj_get_parent(btn); + + return mbox; +} + +/** + * Get the animation duration (close animation time) + * @param mbox pointer to a message box object + * @return animation length in milliseconds (0: no animation) + */ +uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + return ext->anim_time; +} + +/** + * Get a style of a message box + * @param mbox pointer to a message box object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_mbox_get_style(const lv_obj_t * mbox, lv_mbox_style_t type) +{ + lv_style_t * style = NULL; + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + switch(type) { + case LV_MBOX_STYLE_BG: + style = lv_obj_get_style(mbox); + break; + case LV_MBOX_STYLE_BTN_BG: + style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BG); + break; + case LV_MBOX_STYLE_BTN_REL: + style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_REL); + break; + case LV_MBOX_STYLE_BTN_PR: + style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_PR); + break; + case LV_MBOX_STYLE_BTN_TGL_REL: + style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_REL); + break; + case LV_MBOX_STYLE_BTN_TGL_PR: + style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_PR); + break; + case LV_MBOX_STYLE_BTN_INA: + style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_INA); + break; + default: + style = NULL; + break; + } + + return style; +} + +/** + * Get whether recoloring is enabled + * @param btnm pointer to button matrix object + * @return whether recoloring is enabled + */ +bool lv_mbox_get_recolor(const lv_obj_t * mbox) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + if(!ext->btnm) + return false; + + return lv_btnm_get_recolor(ext->btnm); +} + + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the message box + * @param mbox pointer to a message box object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /*Translate LV_GROUP_KEY_UP/DOWN to LV_GROUP_KEY_LEFT/RIGHT */ + char c_trans = 0; + if(sign == LV_SIGNAL_CONTROLL) { + c_trans = *((char *)param); + if(c_trans == LV_GROUP_KEY_DOWN) c_trans = LV_GROUP_KEY_LEFT; + if(c_trans == LV_GROUP_KEY_UP) c_trans = LV_GROUP_KEY_RIGHT; + + param = &c_trans; + } + + /* Include the ancient signal function */ + res = ancestor_signal(mbox, sign, param); + if(res != LV_RES_OK) return res; + + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + if(sign == LV_SIGNAL_CORD_CHG) { + if(lv_obj_get_width(mbox) != lv_area_get_width(param)) { + mbox_realign(mbox); + } + } else if(sign == LV_SIGNAL_STYLE_CHG) { + mbox_realign(mbox); + + } else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || + sign == LV_SIGNAL_CONTROLL || sign == LV_SIGNAL_GET_EDITABLE) { + if(ext->btnm) { + ext->btnm->signal_func(ext->btnm, sign, param); + } + + /* The button matrix with ENCODER input supposes it's in a group but in this case it isn't (Only the message box's container) + * So so some actions here instead*/ + if(sign == LV_SIGNAL_FOCUS) { +#if USE_LV_GROUP + lv_indev_t * indev = lv_indev_get_act(); + lv_hal_indev_type_t indev_type = lv_indev_get_type(indev); + if(indev_type == LV_INDEV_TYPE_ENCODER) { + /*In navigation mode don't select any button but in edit mode select the fist*/ + lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btnm); + if(lv_group_get_editing(lv_obj_get_group(mbox))) btnm_ext->btn_id_pr = 0; + else btnm_ext->btn_id_pr = LV_BTNM_PR_NONE; + } +#endif + } + + + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_mbox"; + } + + return res; +} + +/** + * Resize the button holder to fit + * @param mbox pointer to message box object + */ +static void mbox_realign(lv_obj_t * mbox) +{ + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + + lv_style_t * style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BG); + lv_coord_t w = lv_obj_get_width(mbox) - 2 * style->body.padding.hor; + + if(ext->text) { + lv_obj_set_width(ext->text, w); + } + + if(ext->btnm) { + lv_style_t * btn_bg_style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BTN_BG); + lv_style_t * btn_rel_style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BTN_REL); + lv_coord_t font_h = lv_font_get_height(btn_rel_style->text.font); + lv_obj_set_size(ext->btnm, w, font_h + 2 * btn_rel_style->body.padding.ver + 2 * btn_bg_style->body.padding.ver); + } +} + +static lv_res_t lv_mbox_close_action(lv_obj_t * btn, const char * txt) +{ + lv_obj_t * mbox = lv_mbox_get_from_btn(btn); + + if(txt[0] != '\0') { + lv_mbox_start_auto_close(mbox, 0); + return LV_RES_INV; + } + + return LV_RES_OK; +} + +#if USE_LV_ANIMATION +static void lv_mbox_close_end_cb(lv_obj_t * mbox) +{ + lv_obj_del(mbox); +} +#endif +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.h new file mode 100644 index 0000000..ae5c76a --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_mbox.h @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_mbox.h + * + */ + +#ifndef LV_MBOX_H +#define LV_MBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_MBOX != 0 + +/*Testing of dependencies*/ +#if USE_LV_CONT == 0 +#error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " +#endif + +#if USE_LV_BTNM == 0 +#error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " +#endif + +#if USE_LV_LABEL == 0 +#error "lv_mbox: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#endif + + +#include "../lv_core/lv_obj.h" +#include "lv_cont.h" +#include "lv_btnm.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of message box*/ +typedef struct +{ + lv_cont_ext_t bg; /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t *text; /*Text of the message box*/ + lv_obj_t *btnm; /*Button matrix for the buttons*/ + uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/ +} lv_mbox_ext_t; + +enum { + LV_MBOX_STYLE_BG, + LV_MBOX_STYLE_BTN_BG, + LV_MBOX_STYLE_BTN_REL, + LV_MBOX_STYLE_BTN_PR, + LV_MBOX_STYLE_BTN_TGL_REL, + LV_MBOX_STYLE_BTN_TGL_PR, + LV_MBOX_STYLE_BTN_INA, +}; +typedef uint8_t lv_mbox_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a message box objects + * @param par pointer to an object, it will be the parent of the new message box + * @param copy pointer to a message box object, if not NULL then the new object will be copied from it + * @return pointer to the created message box + */ +lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add button to the message box + * @param mbox pointer to message box object + * @param btn_map button descriptor (button matrix map). + * E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable) + * @param action a function which will be called when a button is released + */ +void lv_mbox_add_btns(lv_obj_t * mbox, const char **btn_map, lv_btnm_action_t action); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of the message box + * @param mbox pointer to a message box + * @param txt a '\0' terminated character string which will be the message box text + */ +void lv_mbox_set_text(lv_obj_t * mbox, const char * txt); + +/** + * Stop the action to call when button is released + * @param mbox pointer to a message box object + * @param pointer to an 'lv_btnm_action_t' action. In the action you need to use `lv_mbox_get_from_btn()` to get the `mbox`. + */ +void lv_mbox_set_action(lv_obj_t * mbox, lv_btnm_action_t action); + +/** + * Set animation duration + * @param mbox pointer to a message box object + * @param anim_time animation length in milliseconds (0: no animation) + */ +void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time); + +/** + * Automatically delete the message box after a given time + * @param mbox pointer to a message box object + * @param delay a time (in milliseconds) to wait before delete the message box + */ +void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay); + +/** + * Stop the auto. closing of message box + * @param mbox pointer to a message box object + */ +void lv_mbox_stop_auto_close(lv_obj_t * mbox); + +/** + * Set a style of a message box + * @param mbox pointer to a message box object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_mbox_set_style(lv_obj_t *mbox, lv_mbox_style_t type, lv_style_t *style); + +/** + * Set whether recoloring is enabled. Must be called after `lv_mbox_add_btns`. + * @param btnm pointer to button matrix object + * @param en whether recoloring is enabled + */ +void lv_mbox_set_recolor(lv_obj_t * mbox, bool en); + +void lv_mbox_set_recolor_text(lv_obj_t * mbox, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of the message box + * @param mbox pointer to a message box object + * @return pointer to the text of the message box + */ +const char * lv_mbox_get_text(const lv_obj_t * mbox); + +/** + * Get the message box object from one of its button. + * It is useful in the button release actions where only the button is known + * @param btn pointer to a button of a message box + * @return pointer to the button's message box + */ +lv_obj_t * lv_mbox_get_from_btn(const lv_obj_t * btn); + +/** + * Get the animation duration (close animation time) + * @param mbox pointer to a message box object + * @return animation length in milliseconds (0: no animation) + */ +uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox); + + +/** + * Get a style of a message box + * @param mbox pointer to a message box object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_mbox_get_style(const lv_obj_t *mbox, lv_mbox_style_t type); + +/** + * Get whether recoloring is enabled + * @param btnm pointer to button matrix object + * @return whether recoloring is enabled + */ +bool lv_mbox_get_recolor(const lv_obj_t * mbox); + +/********************** + * MACROS + **********************/ + + +#endif /*USE_LV_MBOX*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_MBOX_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx.mk b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx.mk new file mode 100644 index 0000000..d35252b --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx.mk @@ -0,0 +1,36 @@ +CSRCS += lv_arc.c +CSRCS += lv_bar.c +CSRCS += lv_cb.c +CSRCS += lv_ddlist.c +CSRCS += lv_kb.c +CSRCS += lv_line.c +CSRCS += lv_mbox.c +CSRCS += lv_preload.c +CSRCS += lv_roller.c +CSRCS += lv_table.c +CSRCS += lv_tabview.c +CSRCS += lv_tileview.c +CSRCS += lv_btn.c +CSRCS += lv_calendar.c +CSRCS += lv_chart.c +CSRCS += lv_canvas.c +CSRCS += lv_gauge.c +CSRCS += lv_label.c +CSRCS += lv_list.c +CSRCS += lv_slider.c +CSRCS += lv_ta.c +CSRCS += lv_spinbox.c +CSRCS += lv_btnm.c +CSRCS += lv_cont.c +CSRCS += lv_img.c +CSRCS += lv_imgbtn.c +CSRCS += lv_led.c +CSRCS += lv_lmeter.c +CSRCS += lv_page.c +CSRCS += lv_sw.c +CSRCS += lv_win.c + +DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_objx +VPATH += :$(LVGL_DIR)/lvgl/lv_objx + +CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_objx" diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.c new file mode 100644 index 0000000..f605450 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.c @@ -0,0 +1,231 @@ +/** + * @file lv_templ.c + * + */ + +/* TODO Remove these instructions + * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) + * templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) + * + */ + +/********************* + * INCLUDES + *********************/ +//#include "lv_templ.h" /*TODO uncomment this*/ +#if USE_LV_TEMPL != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_templ_design(lv_obj_t * templ, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a template object + * @param par pointer to an object, it will be the parent of the new template + * @param copy pointer to a template object, if not NULL then the new object will be copied from it + * @return pointer to the created template + */ +lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("template create started"); + + /*Create the ancestor of template*/ + /*TODO modify it to the ancestor create function */ + lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy); + lv_mem_assert(new_templ); + if(new_templ == NULL) return NULL; + + /*Allocate the template type specific extended data*/ + lv_templ_ext_t * ext = lv_obj_allocate_ext_attr(new_templ, sizeof(lv_templ_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_templ); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_templ); + + /*Initialize the allocated 'ext' */ + ext->xyz = 0; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_templ, lv_templ_signal); + lv_obj_set_design_func(new_templ, lv_templ_design); + + /*Init the new template template*/ + if(copy == NULL) { + + } + /*Copy an existing template*/ + else { + lv_templ_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_templ); + } + + LV_LOG_INFO("template created"); + + return new_templ; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/* + * New object specific "add" or "remove" functions come here + */ + + +/*===================== + * Setter functions + *====================*/ + +/* + * New object specific "set" functions come here + */ + + +/** + * Set a style of a template. + * @param templ pointer to template object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t * style) +{ + lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ); + + switch(type) { + case LV_TEMPL_STYLE_X: + break; + case LV_TEMPL_STYLE_Y: + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/* + * New object specific "get" functions come here + */ + +/** + * Get style of a template. + * @param templ pointer to template object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type) +{ + lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ); + lv_style_t * style = NULL; + + switch(type) { + case LV_TEMPL_STYLE_X: + style = NULL; /*Replace NULL with a pointer to the style*/ + case LV_TEMPL_STYLE_Y: + style = NULL; /*Replace NULL with a pointer to the style*/ + default: + style = NULL; + } + + return style; +} + +/*===================== + * Other functions + *====================*/ + +/* + * New object specific "other" functions come here + */ + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the templates + * @param templ pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_templ_design(lv_obj_t * templ, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the template + * @param templ pointer to a template object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(templ, sign, param); + if(res != LV_RES_OK) return res; + + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_templ"; + } + + return res; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.h new file mode 100644 index 0000000..ab6d090 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_objx_templ.h @@ -0,0 +1,111 @@ +/** + * @file lv_templ.h + * + */ + + +/* TODO Remove these instructions + * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) + * templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) + * + */ + +#ifndef LV_TEMPL_H +#define LV_TEMPL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_TEMPL != 0 + +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of template*/ +typedef struct { + lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ + /*New data for this type */ +} lv_templ_ext_t; + + +/*Styles*/ +enum { + LV_TEMPL_STYLE_X, + LV_TEMPL_STYLE_Y, +}; +typedef uint8_t lv_templ_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a template objects + * @param par pointer to an object, it will be the parent of the new template + * @param copy pointer to a template object, if not NULL then the new object will be copied from it + * @return pointer to the created template + */ +lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a style of a template. + * @param templ pointer to template object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get style of a template. + * @param templ pointer to template object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_TEMPL*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TEMPL_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.c new file mode 100644 index 0000000..65dcb35 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.c @@ -0,0 +1,1205 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_page.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "../lv_objx/lv_page.h" +#if USE_LV_PAGE != 0 + +#include "../lv_core/lv_group.h" +#include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_core/lv_refr.h" +#include "../lv_misc/lv_anim.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define LV_PAGE_SB_MIN_SIZE (LV_DPI / 8) +#define LV_PAGE_SCROLL_ANIM_TIME 200 /*[ms] Scroll anim time on `lv_page_scroll_up/down/left/rigth`*/ +#define LV_PAGE_END_FLASH_SIZE (LV_DPI / 4) +#define LV_PAGE_END_ANIM_TIME 300 +#define LV_PAGE_END_ANIM_WAIT_TIME 300 + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void lv_page_sb_refresh(lv_obj_t * page); +static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mode_t mode); +static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param); +static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); +#if USE_LV_ANIMATION +static void edge_flash_anim(void * page, int32_t v); +static void edge_flash_anim_end(void * page); +#endif + +/********************** + * STATIC VARIABLES + **********************/ +static lv_design_func_t ancestor_design; +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a page objects + * @param par pointer to an object, it will be the parent of the new page + * @param copy pointer to a page object, if not NULL then the new object will be copied from it + * @return pointer to the created page + */ +lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("page create started"); + + /*Create the ancestor object*/ + lv_obj_t * new_page = lv_cont_create(par, copy); + lv_mem_assert(new_page); + if(new_page == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_page); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_page); + + /*Allocate the object type specific extended data*/ + lv_page_ext_t * ext = lv_obj_allocate_ext_attr(new_page, sizeof(lv_page_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->scrl = NULL; + ext->pr_action = NULL; + ext->rel_action = NULL; + ext->sb.hor_draw = 0; + ext->sb.ver_draw = 0; + ext->bgo = NULL; + ext->pr = NULL; + ext->sb.style = &lv_style_pretty; + ext->sb.mode = LV_SB_MODE_AUTO; + ext->edge_flash.enabled = 0; + ext->edge_flash.bottom_ip = 0; + ext->edge_flash.top_ip = 0; + ext->edge_flash.left_ip = 0; + ext->edge_flash.right_ip = 0; + ext->edge_flash.state = 0; + ext->edge_flash.style = &lv_style_plain_color; + ext->arrow_scroll = 0; + ext->scroll_prop = 0; + ext->scroll_prop_ip = 0; + + /*Init the new page object*/ + if(copy == NULL) { + ext->scrl = lv_cont_create(new_page, NULL); + lv_obj_set_signal_func(ext->scrl, lv_page_scrollable_signal); + lv_obj_set_design_func(ext->scrl, lv_scrl_design); + lv_obj_set_drag(ext->scrl, true); + lv_obj_set_drag_throw(ext->scrl, true); + lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT | LV_PROTECT_PRESS_LOST); + lv_cont_set_fit(ext->scrl, false, true); + + /* Add the signal function only if 'scrolling' is created + * because everything has to be ready before any signal is received*/ + lv_obj_set_signal_func(new_page, lv_page_signal); + lv_obj_set_design_func(new_page, lv_page_design); + + lv_page_set_sb_mode(new_page, ext->sb.mode); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + if(par == NULL) { /*Different styles if it is screen*/ + lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->bg); + lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_transp); + } else { + lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->page.bg); + lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, th->page.scrl); + + } + lv_page_set_style(new_page, LV_PAGE_STYLE_SB, th->page.sb); + } else { + lv_page_set_style(new_page, LV_PAGE_STYLE_BG, &lv_style_pretty_color); + lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_pretty); + lv_page_set_style(new_page, LV_PAGE_STYLE_SB, &lv_style_pretty_color); + } + + } else { + lv_page_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->scrl = lv_cont_create(new_page, copy_ext->scrl); + ext->bgo = lv_page_get_style(copy, LV_PAGE_STYLE_BGO); + ext->pr = lv_page_get_style(copy, LV_PAGE_STYLE_PR); + lv_obj_set_signal_func(ext->scrl, lv_page_scrollable_signal); + + lv_page_set_pr_action(new_page, copy_ext->pr_action); + lv_page_set_rel_action(new_page, copy_ext->rel_action); + lv_page_set_sb_mode(new_page, copy_ext->sb.mode); + lv_page_set_arrow_scroll(new_page, copy_ext->arrow_scroll); + + + lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG)); + lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL)); + lv_page_set_style(new_page, LV_PAGE_STYLE_SB, lv_page_get_style(copy, LV_PAGE_STYLE_SB)); + + /* Add the signal function only if 'scrolling' is created + * because everything has to be ready before any signal is received*/ + lv_obj_set_signal_func(new_page, lv_page_signal); + lv_obj_set_design_func(new_page, lv_page_design); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_page); + } + + lv_page_sb_refresh(new_page); + + LV_LOG_INFO("page created"); + + return new_page; +} + +/** + * Delete all children of the scrl object, without deleting scrl child. + * @param obj pointer to an object + */ +void lv_page_clean(lv_obj_t * obj) +{ + lv_obj_t * scrl = lv_page_get_scrl(obj); + lv_obj_clean(scrl); +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a release action for the page + * @param page pointer to a page object + * @param rel_action a function to call when the page is release + */ +void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + ext->rel_action = rel_action; +} + +/** + * Set a press action for the page + * @param page pointer to a page object + * @param pr_action a function to call when the page is pressed + */ +void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + ext->pr_action = pr_action; +} + +/** + * Set the scroll bar mode on a page + * @param page pointer to a page object + * @param sb_mode the new mode from 'lv_page_sb.mode_t' enum + */ +void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + if(ext->sb.mode == sb_mode) return; + + if(sb_mode == LV_SB_MODE_HIDE) ext->sb.mode |= LV_SB_MODE_HIDE; /*Set the hidden flag*/ + else if(sb_mode == LV_SB_MODE_UNHIDE) ext->sb.mode &= (~LV_SB_MODE_HIDE); /*Clear the hidden flag*/ + else { + if(ext->sb.mode & LV_SB_MODE_HIDE) sb_mode |= LV_SB_MODE_HIDE; + ext->sb.mode = sb_mode; + } + + ext->sb.hor_draw = 0; + ext->sb.ver_draw = 0; + + lv_page_sb_refresh(page); + lv_obj_invalidate(page); +} + +/** + * Enable/Disable scrolling with arrows if the page is in group (arrows: LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) + * @param page pointer to a page object + * @param en true: enable scrolling with arrows + */ +void lv_page_set_arrow_scroll(lv_obj_t * page, bool en) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + ext->arrow_scroll = en ? 1 : 0; +} + +/** + * Enable the scroll propagation feature. If enabled then the page will move its parent if there is no more space to scroll. + * @param page pointer to a Page + * @param en true or false to enable/disable scroll propagation + */ +void lv_page_set_scroll_propagation(lv_obj_t * page, bool en) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + ext->scroll_prop = en ? 1 : 0; +} + +/** + * Enable the edge flash effect. (Show an arc when the an edge is reached) + * @param page pointer to a Page + * @param en true or false to enable/disable end flash + */ +void lv_page_set_edge_flash(lv_obj_t * page, bool en) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + ext->edge_flash.enabled = en ? 1 : 0; +} + +/** + * Set a style of a page + * @param page pointer to a page object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_page_set_style(lv_obj_t * page, lv_page_style_t type, lv_style_t * style) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + + switch(type) { + case LV_PAGE_STYLE_BG: + lv_obj_set_style(page, style); + break; + case LV_PAGE_STYLE_BGO: + ext->bgo = style; + break; + case LV_PAGE_STYLE_PR: + ext->pr = style; + break; + case LV_PAGE_STYLE_SCRL: + lv_obj_set_style(ext->scrl, style); + break; + case LV_PAGE_STYLE_SB: + ext->sb.style = style; + lv_area_set_height(&ext->sb.hor_area, ext->sb.style->body.padding.inner); + lv_area_set_width(&ext->sb.ver_area, ext->sb.style->body.padding.inner); + lv_page_sb_refresh(page); + lv_obj_refresh_ext_size(page); + lv_obj_invalidate(page); + break; + case LV_PAGE_STYLE_EDGE_FLASH: + ext->edge_flash.style = style; + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the scrollable object of a page + * @param page pointer to a page object + * @return pointer to a container which is the scrollable part of the page + */ +lv_obj_t * lv_page_get_scrl(const lv_obj_t * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + + return ext->scrl; +} + +/** + * Get the press action of the page + * @param page pointer to a page object + * @return a function to call when the page is pressed + */ +lv_action_t lv_page_get_pr_action(lv_obj_t * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + return ext->pr_action; +} + +/** + * Get the release action of the page + * @param page pointer to a page object + * @return a function to call when the page is released + */ +lv_action_t lv_page_get_rel_action(lv_obj_t * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + return ext->rel_action; +} + +/** + * Set the scroll bar mode on a page + * @param page pointer to a page object + * @return the mode from 'lv_page_sb.mode_t' enum + */ +lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + return ext->sb.mode; +} + +/** + * Get the the scrolling with arrows (LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) is enabled or not + * @param page pointer to a page object + * @return true: scrolling with arrows is enabled + */ +bool lv_page_get_arrow_scroll(const lv_obj_t * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + return ext->arrow_scroll ? true : false; +} + +/** + * Get the scroll propagation property + * @param page pointer to a Page + * @return true or false + */ +bool lv_page_get_scroll_propagation(lv_obj_t * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + return ext->scroll_prop == 0 ? false : true; +} + +/** + * Get the edge flash effect property. + * @param page pointer to a Page + * return true or false + */ +bool lv_page_get_edge_flash(lv_obj_t * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + return ext->edge_flash.enabled == 0 ? false : true; +} + +/** + * Get that width which can be set to the children to still not cause overflow (show scrollbars) + * @param page pointer to a page object + * @return the width which still fits into the page + */ +lv_coord_t lv_page_get_fit_width(lv_obj_t * page) +{ + lv_style_t * bg_style = lv_page_get_style(page, LV_PAGE_STYLE_BG); + lv_style_t * scrl_style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL); + + return lv_obj_get_width(page) - 2 * (bg_style->body.padding.hor + scrl_style->body.padding.hor); +} + +/** + * Get that height which can be set to the children to still not cause overflow (show scrollbars) + * @param page pointer to a page object + * @return the height which still fits into the page + */ +lv_coord_t lv_page_get_fit_height(lv_obj_t * page) +{ + lv_style_t * bg_style = lv_page_get_style(page, LV_PAGE_STYLE_BG); + lv_style_t * scrl_style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL); + + return lv_obj_get_height(page) - 2 * (bg_style->body.padding.ver + scrl_style->body.padding.ver); +} + +/** + * Get a style of a page + * @param page pointer to page object + * @param type which style should be get + * @return style pointer to a style + * */ +lv_style_t * lv_page_get_style(const lv_obj_t * page, lv_page_style_t type) +{ + lv_style_t * style = NULL; + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + + switch(type) { + case LV_PAGE_STYLE_BG: + style = lv_obj_get_style(page); + break; + case LV_PAGE_STYLE_BGO: + style = ext->bgo; + break; + case LV_PAGE_STYLE_PR: + style = ext->pr; + break; + case LV_PAGE_STYLE_SCRL: + style = lv_obj_get_style(ext->scrl); + break; + case LV_PAGE_STYLE_SB: + style = ext->sb.style; + break; + case LV_PAGE_STYLE_EDGE_FLASH: + style = ext->edge_flash.style; + break; + default: + style = NULL; + break; + } + + return style; +} + +/*===================== + * Other functions + *====================*/ + +/** + * Glue the object to the page. After it the page can be moved (dragged) with this object too. + * @param obj pointer to an object on a page + * @param glue true: enable glue, false: disable glue + */ +void lv_page_glue_obj(lv_obj_t * obj, bool glue) +{ + lv_obj_set_drag_parent(obj, glue); + lv_obj_set_drag(obj, glue); +} + +/** + * Focus on an object. It ensures that the object will be visible on the page. + * @param page pointer to a page object + * @param obj pointer to an object to focus (must be on the page) + * @param anim_time scroll animation time in milliseconds (0: no animation) + */ +void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + +#if USE_LV_ANIMATION == 0 + anim_time = 0; +#else + /* Be sure there is no position changing animation in progress + * because it can overide the current changes*/ + lv_anim_del(page, (lv_anim_fp_t)lv_obj_set_y); + lv_anim_del(page, (lv_anim_fp_t)lv_obj_set_pos); + lv_anim_del(ext->scrl, (lv_anim_fp_t)lv_obj_set_y); + lv_anim_del(ext->scrl, (lv_anim_fp_t)lv_obj_set_pos); +#endif + + lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG); + lv_style_t * style_scrl = lv_page_get_style(page, LV_PAGE_STYLE_SCRL); + + lv_coord_t obj_y = obj->coords.y1 - ext->scrl->coords.y1; + lv_coord_t obj_h = lv_obj_get_height(obj); + lv_coord_t scrlable_y = lv_obj_get_y(ext->scrl); + lv_coord_t page_h = lv_obj_get_height(page); + + lv_coord_t top_err = -(scrlable_y + obj_y); + lv_coord_t bot_err = scrlable_y + obj_y + obj_h - page_h; + + /*If obj is higher then the page focus where the "error" is smaller*/ + + /*Out of the page on the top*/ + if((obj_h <= page_h && top_err > 0) || + (obj_h > page_h && top_err < bot_err)) { + /*Calculate a new position and let some space above*/ + scrlable_y = -(obj_y - style_scrl->body.padding.ver - style->body.padding.ver); + scrlable_y += style_scrl->body.padding.ver; + } + /*Out of the page on the bottom*/ + else if((obj_h <= page_h && bot_err > 0) || + (obj_h > page_h && top_err >= bot_err)) { + /*Calculate a new position and let some space below*/ + scrlable_y = -(obj_y + style_scrl->body.padding.ver + style->body.padding.ver); + scrlable_y -= style_scrl->body.padding.ver; + scrlable_y += page_h - obj_h; + } else { + /*Already in focus*/ + return; + } + + if(anim_time == 0) { + lv_obj_set_y(ext->scrl, scrlable_y); +#if USE_LV_ANIMATION + } else { + lv_anim_t a; + a.act_time = 0; + a.start = lv_obj_get_y(ext->scrl); + a.end = scrlable_y; + a.time = anim_time; + a.end_cb = NULL; + a.playback = 0; + a.repeat = 0; + a.var = ext->scrl; + a.path = lv_anim_path_linear; + a.fp = (lv_anim_fp_t) lv_obj_set_y; + lv_anim_create(&a); +#endif + } +} + +/** + * Scroll the page horizontally + * @param page pointer to a page object + * @param dist the distance to scroll (< 0: scroll right; > 0 scroll left) + */ +void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist) +{ + lv_obj_t * scrl = lv_page_get_scrl(page); + +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = scrl; + a.start = lv_obj_get_x(scrl); + a.end = a.start + dist; + a.fp = (lv_anim_fp_t)lv_obj_set_x; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = LV_PAGE_SCROLL_ANIM_TIME; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#else + lv_obj_set_x(scrl, lv_obj_get_x(scrl) + dist); +#endif +} + +/** + * Scroll the page vertically + * @param page pointer to a page object + * @param dist the distance to scroll (< 0: scroll down; > 0 scroll up) + */ +void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist) +{ + lv_obj_t * scrl = lv_page_get_scrl(page); + +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = scrl; + a.start = lv_obj_get_y(scrl); + a.end = a.start + dist; + a.fp = (lv_anim_fp_t)lv_obj_set_y; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = LV_PAGE_SCROLL_ANIM_TIME; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#else + lv_obj_set_y(scrl, lv_obj_get_y(scrl) + dist); +#endif +} + +/** + * Not intended to use directly by the user but by other object types internally. + * Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set + * @param page + */ +void lv_page_start_edge_flash(lv_obj_t * page) +{ +#if USE_LV_ANIMATION + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + if(ext->edge_flash.enabled) { + lv_anim_t a; + a.var = page; + a.start = 0; + a.end = LV_PAGE_END_FLASH_SIZE; + a.fp = (lv_anim_fp_t)edge_flash_anim; + a.path = lv_anim_path_linear; + a.end_cb = edge_flash_anim_end; + a.act_time = 0; + a.time = LV_PAGE_END_ANIM_TIME; + a.playback = 1; + a.playback_pause = LV_PAGE_END_ANIM_WAIT_TIME; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); + } +#endif +} + + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the pages + * @param page pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + return ancestor_design(page, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { + /*Draw without border*/ + lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG); + lv_coord_t border_width_tmp = style->body.border.width; + style->body.border.width = 0; + lv_draw_rect(&page->coords, mask, style, lv_obj_get_opa_scale(page)); + style->body.border.width = border_width_tmp; + + } else if(mode == LV_DESIGN_DRAW_POST) { /*Draw the scroll bars finally*/ + + /*Draw only a border*/ + lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG); + lv_coord_t shadow_width_tmp = style->body.shadow.width; + uint8_t empty_tmp = style->body.empty; + style->body.shadow.width = 0; + style->body.empty = 1; + lv_draw_rect(&page->coords, mask, style, lv_obj_get_opa_scale(page)); + style->body.shadow.width = shadow_width_tmp; + style->body.empty = empty_tmp; + + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + + /*Draw the scrollbars*/ + lv_area_t sb_area; + if(ext->sb.hor_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) { + /*Convert the relative coordinates to absolute*/ + lv_area_copy(&sb_area, &ext->sb.hor_area); + sb_area.x1 += page->coords.x1; + sb_area.y1 += page->coords.y1; + sb_area.x2 += page->coords.x1; + sb_area.y2 += page->coords.y1; + lv_draw_rect(&sb_area, mask, ext->sb.style, lv_obj_get_opa_scale(page)); + } + + if(ext->sb.ver_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) { + /*Convert the relative coordinates to absolute*/ + lv_area_copy(&sb_area, &ext->sb.ver_area); + sb_area.x1 += page->coords.x1; + sb_area.y1 += page->coords.y1; + sb_area.x2 += page->coords.x1; + sb_area.y2 += page->coords.y1; + lv_draw_rect(&sb_area, mask, ext->sb.style, lv_obj_get_opa_scale(page)); + } + + + lv_coord_t page_w = lv_obj_get_width(page); + lv_coord_t page_h = lv_obj_get_height(page); + lv_area_t flash_area; + + if(ext->edge_flash.top_ip) { + flash_area.x1 = page->coords.x1 - page_w; + flash_area.x2 = page->coords.x2 + page_w; + flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state; + flash_area.y2 = page->coords.y1 + ext->edge_flash.state; + } + else if(ext->edge_flash.bottom_ip) { + flash_area.x1 = page->coords.x1 - page_w; + flash_area.x2 = page->coords.x2 + page_w; + flash_area.y1 = page->coords.y2 - ext->edge_flash.state; + flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state; + } + else if(ext->edge_flash.right_ip) { + flash_area.x1 = page->coords.x2 - ext->edge_flash.state; + flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state; + flash_area.y1 = page->coords.y1 - page_h; + flash_area.y2 = page->coords.y2 + page_h; + } + else if(ext->edge_flash.left_ip) { + flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state; + flash_area.x2 = page->coords.x1 + ext->edge_flash.state; + flash_area.y1 = page->coords.y1 - page_h; + flash_area.y2 = page->coords.y2 + page_h; + } + + if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip || ext->edge_flash.bottom_ip) { + lv_style_t flash_style; + lv_style_copy(&flash_style, ext->edge_flash.style); + flash_style.body.radius = LV_RADIUS_CIRCLE; + uint32_t opa = (flash_style.body.opa * ext->edge_flash.state) / LV_PAGE_END_FLASH_SIZE; + flash_style.body.opa = opa; + lv_draw_rect(&flash_area, mask, &flash_style, lv_obj_get_opa_scale(page)); + } + + } + + return true; +} + +/** + * Handle the drawing related tasks of the scrollable object + * @param scrl pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + return ancestor_design(scrl, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { +#if USE_LV_GROUP + /* If the page is focused in a group and + * the background object is not visible (transparent or empty) + * then "activate" the style of the scrollable*/ + lv_style_t * style_scrl_ori = lv_obj_get_style(scrl); + lv_obj_t * page = lv_obj_get_parent(scrl); + lv_style_t * style_page = lv_obj_get_style(page); + lv_group_t * g = lv_obj_get_group(page); + if((style_page->body.empty || style_page->body.opa == LV_OPA_TRANSP) && style_page->body.border.width == 0) { /*Is the background visible?*/ + if(lv_group_get_focused(g) == page) { + lv_style_t * style_mod; + style_mod = lv_group_mod_style(g, style_scrl_ori); + scrl->style_p = style_mod; /*Temporally change the style to the activated */ + } + } +#endif + ancestor_design(scrl, mask, mode); + +#if USE_LV_GROUP + scrl->style_p = style_scrl_ori; /*Revert the style*/ +#endif + } else if(mode == LV_DESIGN_DRAW_POST) { + ancestor_design(scrl, mask, mode); + } + + return true; +} + +/** + * Signal function of the page + * @param page pointer to a page object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(page, sign, param); + if(res != LV_RES_OK) return res; + + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + lv_style_t * style = lv_obj_get_style(page); + lv_obj_t * child; + if(sign == LV_SIGNAL_CHILD_CHG) { /*Automatically move children to the scrollable object*/ + child = lv_obj_get_child(page, NULL); + while(child != NULL) { + if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) { + lv_obj_t * tmp = child; + child = lv_obj_get_child(page, child); /*Get the next child before move this*/ + lv_obj_set_parent(tmp, ext->scrl); + } else { + child = lv_obj_get_child(page, child); + } + } + } else if(sign == LV_SIGNAL_STYLE_CHG) { + /*If no hor_fit enabled set the scrollable's width to the page's width*/ + if(lv_cont_get_hor_fit(ext->scrl) == false) { + lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor); + } else { + ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords); + } + + /*The scrollbars are important only if they are visible now*/ + if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page); + + /*Refresh the ext. size because the scrollbars might be positioned out of the page*/ + lv_obj_refresh_ext_size(page); + } else if(sign == LV_SIGNAL_CORD_CHG) { + /*Refresh the scrollbar and notify the scrl if the size is changed*/ + if(ext->scrl != NULL && (lv_obj_get_width(page) != lv_area_get_width(param) || + lv_obj_get_height(page) != lv_area_get_height(param))) { + /*If no hor_fit enabled set the scrollable's width to the page's width*/ + if(lv_cont_get_hor_fit(ext->scrl) == false) { + lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor); + } + + ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords); + + /*The scrollbars are important only if they are visible now*/ + if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page); + } + } else if(sign == LV_SIGNAL_PRESSED) { + if(ext->pr_action != NULL) { + res = ext->pr_action(page); + } + } else if(sign == LV_SIGNAL_RELEASED) { + if(lv_indev_is_dragging(lv_indev_get_act()) == false) { + if(ext->rel_action != NULL) { + res = ext->rel_action(page); + } + } + } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + /*Ensure ext. size for the scrollbars if they are out of the page*/ + if(page->ext_size < (-ext->sb.style->body.padding.hor)) page->ext_size = -ext->sb.style->body.padding.hor; + if(page->ext_size < (-ext->sb.style->body.padding.ver)) page->ext_size = -ext->sb.style->body.padding.ver; + } else if(sign == LV_SIGNAL_CONTROLL) { + uint32_t c = *((uint32_t *) param); + + if((c == LV_GROUP_KEY_DOWN) && ext->arrow_scroll) { + lv_page_scroll_ver(page, - lv_obj_get_height(page) / 4); + } else if((c == LV_GROUP_KEY_UP) && ext->arrow_scroll) { + lv_page_scroll_ver(page, lv_obj_get_height(page) / 4); + } else if((c == LV_GROUP_KEY_RIGHT) && ext->arrow_scroll) { + /*If the page can be scrolled horizontally because it's not wide enough then scroll it vertically*/ + if(lv_page_get_scrl_width(page) < lv_obj_get_width(page)) lv_page_scroll_ver(page, - lv_obj_get_height(page) / 4); + else lv_page_scroll_hor(page, - lv_obj_get_width(page) / 4); + } else if((c == LV_GROUP_KEY_LEFT) && ext->arrow_scroll) { + /*If the page can be scrolled horizontally because it's not wide enough then scroll it vertically*/ + if(lv_page_get_scrl_width(page) < lv_obj_get_width(page)) lv_page_scroll_ver(page, lv_obj_get_height(page) / 4); + else lv_page_scroll_hor(page, lv_obj_get_width(page) / 4); + } + } else if(sign == LV_SIGNAL_GET_EDITABLE) { + bool * editable = (bool *)param; + *editable = lv_page_get_arrow_scroll(page); + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_page"; + } + + return res; +} + +/** + * Signal function of the scrollable part of a page + * @param scrl pointer to the scrollable object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(scrl, sign, param); + if(res != LV_RES_OK) return res; + + lv_obj_t * page = lv_obj_get_parent(scrl); + lv_style_t * page_style = lv_obj_get_style(page); + lv_page_ext_t * page_ext = lv_obj_get_ext_attr(page); + + if(sign == LV_SIGNAL_CORD_CHG) { + /*Limit the position of the scrollable object to be always visible + * (Do not let its edge inner then its parent respective edge)*/ + lv_coord_t new_x = lv_obj_get_x(scrl); + lv_coord_t new_y = lv_obj_get_y(scrl); + bool refr_x = false; + bool refr_y = false; + lv_area_t page_coords; + lv_area_t scrl_coords; + lv_obj_get_coords(scrl, &scrl_coords); + lv_obj_get_coords(page, &page_coords); + + lv_area_t * ori_coords = (lv_area_t *) param; + lv_coord_t diff_x = scrl->coords.x1 - ori_coords->x1; + lv_coord_t diff_y = scrl->coords.y1 - ori_coords->y1; + lv_coord_t hpad = page_style->body.padding.hor; + lv_coord_t vpad = page_style->body.padding.ver; + lv_obj_t * page_parent = lv_obj_get_parent(page); + + lv_indev_t * indev = lv_indev_get_act(); + lv_point_t drag_vect; + lv_indev_get_vect(indev, &drag_vect); + + + /* Start the scroll propagation if there is drag vector on the indev, but the drag is not started yet + * and the scrollable is in a corner. It will enable the scroll propagation only when a new scroll begins and not + * when the scrollable is already being scrolled.*/ + if(page_ext->scroll_prop && page_ext->scroll_prop_ip == 0 && lv_indev_is_dragging(indev) == false) { + if(((drag_vect.y > 0 && scrl_coords.y1 == page_coords.y1 + vpad) || + (drag_vect.y < 0 && scrl_coords.y2 == page_coords.y2 - vpad)) && + ((drag_vect.x > 0 && scrl_coords.x1 == page_coords.x1 + hpad) || + (drag_vect.x < 0 && scrl_coords.x2 == page_coords.x2 - hpad))) { + + if(lv_obj_get_parent(page_parent) != NULL) { /*Do not propagate the scroll to a screen*/ + page_ext->scroll_prop_ip = 1; + } + } + } + + /*scrollable width smaller then page width? -> align to left*/ + if(lv_area_get_width(&scrl_coords) + 2 * hpad <= lv_area_get_width(&page_coords)) { + if(scrl_coords.x1 != page_coords.x1 + hpad) { + new_x = hpad; + refr_x = true; + } + } else { + /*If the scroll propagation is in progress revert the original coordinates (don't let the page scroll)*/ + if(page_ext->scroll_prop_ip) { + if(drag_vect.x == diff_x) { /*`scrl` is bouncing: drag pos. it somewhere and here it is reverted. Handle only the pos. because of drag*/ + new_x = ori_coords->x1 - page_coords.x1; + refr_x = true; + } + } + /*The edges of the scrollable can not be in the page (minus hpad) */ + else if(scrl_coords.x2 < page_coords.x2 - hpad) { + new_x = lv_area_get_width(&page_coords) - lv_area_get_width(&scrl_coords) - hpad; /* Right align */ + refr_x = true; + if(page_ext->edge_flash.enabled && + page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 && + page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) { + lv_page_start_edge_flash(page); + page_ext->edge_flash.right_ip = 1; + } + } + else if(scrl_coords.x1 > page_coords.x1 + hpad) { + new_x = hpad; /*Left align*/ + refr_x = true; + if(page_ext->edge_flash.enabled && + page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 && + page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) { + lv_page_start_edge_flash(page); + page_ext->edge_flash.left_ip = 1; + } + } + } + + /*scrollable height smaller then page height? -> align to left*/ + if(lv_area_get_height(&scrl_coords) + 2 * vpad <= lv_area_get_height(&page_coords)) { + if(scrl_coords.y1 != page_coords.y1 + vpad) { + new_y = vpad; + refr_y = true; + } + } else { + /*If the scroll propagation is in progress revert the original coordinates (don't let the page scroll)*/ + if(page_ext->scroll_prop_ip) { + if(drag_vect.y == diff_y) { /*`scrl` is bouncing: drag pos. it somewhere and here it is reverted. Handle only the pos. because of drag*/ + new_y = ori_coords->y1 - page_coords.y1; + refr_y = true; + } + } + /*The edges of the scrollable can not be in the page (minus vpad) */ + else if(scrl_coords.y2 < page_coords.y2 - vpad) { + new_y = lv_area_get_height(&page_coords) - lv_area_get_height(&scrl_coords) - vpad; /* Bottom align */ + refr_y = true; + if(page_ext->edge_flash.enabled && + page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 && + page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) { + lv_page_start_edge_flash(page); + page_ext->edge_flash.bottom_ip = 1; + } + } + else if(scrl_coords.y1 > page_coords.y1 + vpad) { + new_y = vpad; /*Top align*/ + refr_y = true; + if(page_ext->edge_flash.enabled && + page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 && + page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) { + lv_page_start_edge_flash(page); + page_ext->edge_flash.top_ip = 1; + } + } + } + + if(refr_x || refr_y) { + lv_obj_set_pos(scrl, new_x, new_y); + + if(page_ext->scroll_prop_ip) { + if(refr_y) lv_obj_set_y(page_parent, lv_obj_get_y(page_parent) + diff_y); + if(refr_x) lv_obj_set_x(page_parent, lv_obj_get_x(page_parent) + diff_x); + } + } + + lv_page_sb_refresh(page); + } + else if(sign == LV_SIGNAL_DRAG_END) { + + /*Scroll propagation is finished on drag end*/ + page_ext->scroll_prop_ip = 0; + + /*Hide scrollbars if required*/ + if(page_ext->sb.mode == LV_SB_MODE_DRAG) { + lv_area_t sb_area_tmp; + if(page_ext->sb.hor_draw) { + lv_area_copy(&sb_area_tmp, &page_ext->sb.hor_area); + sb_area_tmp.x1 += page->coords.x1; + sb_area_tmp.y1 += page->coords.y1; + sb_area_tmp.x2 += page->coords.x1; + sb_area_tmp.y2 += page->coords.y1; + lv_inv_area(&sb_area_tmp); + page_ext->sb.hor_draw = 0; + } + if(page_ext->sb.ver_draw) { + lv_area_copy(&sb_area_tmp, &page_ext->sb.ver_area); + sb_area_tmp.x1 += page->coords.x1; + sb_area_tmp.y1 += page->coords.y1; + sb_area_tmp.x2 += page->coords.x1; + sb_area_tmp.y2 += page->coords.y1; + lv_inv_area(&sb_area_tmp); + page_ext->sb.ver_draw = 0; + } + } + } else if(sign == LV_SIGNAL_PRESSED) { + if(page_ext->pr_action != NULL) { + res = page_ext->pr_action(page); + } + } else if(sign == LV_SIGNAL_RELEASED) { + if(lv_indev_is_dragging(lv_indev_get_act()) == false) { + if(page_ext->rel_action != NULL) { + res = page_ext->rel_action(page); + } + } + } + + return res; +} + + +/** + * Refresh the position and size of the scroll bars. + * @param page pointer to a page object + */ +static void lv_page_sb_refresh(lv_obj_t * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + lv_style_t * style = lv_obj_get_style(page); + lv_obj_t * scrl = ext->scrl; + lv_coord_t size_tmp; + lv_coord_t scrl_w = lv_obj_get_width(scrl); + lv_coord_t scrl_h = lv_obj_get_height(scrl); + lv_coord_t hpad = style->body.padding.hor; + lv_coord_t vpad = style->body.padding.ver; + lv_coord_t obj_w = lv_obj_get_width(page); + lv_coord_t obj_h = lv_obj_get_height(page); + + /*Always let 'scrollbar width' padding above, under, left and right to the scrollbars + * else: + * - horizontal and vertical scrollbars can overlap on the corners + * - if the page has radius the scrollbar can be out of the radius */ + lv_coord_t sb_hor_pad = LV_MATH_MAX(ext->sb.style->body.padding.inner, style->body.padding.hor); + lv_coord_t sb_ver_pad = LV_MATH_MAX(ext->sb.style->body.padding.inner, style->body.padding.ver); + + if(ext->sb.mode == LV_SB_MODE_OFF) return; + + if(ext->sb.mode == LV_SB_MODE_ON) { + ext->sb.hor_draw = 1; + ext->sb.ver_draw = 1; + } + + /*Invalidate the current (old) scrollbar areas*/ + lv_area_t sb_area_tmp; + if(ext->sb.hor_draw != 0) { + lv_area_copy(&sb_area_tmp, &ext->sb.hor_area); + sb_area_tmp.x1 += page->coords.x1; + sb_area_tmp.y1 += page->coords.y1; + sb_area_tmp.x2 += page->coords.x1; + sb_area_tmp.y2 += page->coords.y1; + lv_inv_area(&sb_area_tmp); + } + if(ext->sb.ver_draw != 0) { + lv_area_copy(&sb_area_tmp, &ext->sb.ver_area); + sb_area_tmp.x1 += page->coords.x1; + sb_area_tmp.y1 += page->coords.y1; + sb_area_tmp.x2 += page->coords.x1; + sb_area_tmp.y2 += page->coords.y1; + lv_inv_area(&sb_area_tmp); + } + + + if(ext->sb.mode == LV_SB_MODE_DRAG && lv_indev_is_dragging(lv_indev_get_act()) == false) { + ext->sb.hor_draw = 0; + ext->sb.ver_draw = 0; + return; + + } + + /*Horizontal scrollbar*/ + if(scrl_w <= obj_w - 2 * hpad) { /*Full sized scroll bar*/ + lv_area_set_width(&ext->sb.hor_area, obj_w - 2 * sb_hor_pad); + lv_area_set_pos(&ext->sb.hor_area, sb_hor_pad, obj_h - ext->sb.style->body.padding.inner - ext->sb.style->body.padding.ver); + if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.hor_draw = 0; + } else { + size_tmp = (obj_w * (obj_w - (2 * sb_hor_pad))) / (scrl_w + 2 * hpad); + if(size_tmp < LV_PAGE_SB_MIN_SIZE) size_tmp = LV_PAGE_SB_MIN_SIZE; + lv_area_set_width(&ext->sb.hor_area, size_tmp); + + lv_area_set_pos(&ext->sb.hor_area, sb_hor_pad + + (-(lv_obj_get_x(scrl) - hpad) * (obj_w - size_tmp - 2 * sb_hor_pad)) / + (scrl_w + 2 * hpad - obj_w), + obj_h - ext->sb.style->body.padding.inner - ext->sb.style->body.padding.ver); + + if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.hor_draw = 1; + } + + /*Vertical scrollbar*/ + if(scrl_h <= obj_h - 2 * vpad) { /*Full sized scroll bar*/ + lv_area_set_height(&ext->sb.ver_area, obj_h - 2 * sb_ver_pad); + lv_area_set_pos(&ext->sb.ver_area, obj_w - ext->sb.style->body.padding.inner - ext->sb.style->body.padding.hor, sb_ver_pad); + if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.ver_draw = 0; + } else { + size_tmp = (obj_h * (obj_h - (2 * sb_ver_pad))) / (scrl_h + 2 * vpad); + if(size_tmp < LV_PAGE_SB_MIN_SIZE) size_tmp = LV_PAGE_SB_MIN_SIZE; + lv_area_set_height(&ext->sb.ver_area, size_tmp); + + lv_area_set_pos(&ext->sb.ver_area, obj_w - ext->sb.style->body.padding.inner - ext->sb.style->body.padding.hor, + sb_ver_pad + + (-(lv_obj_get_y(scrl) - vpad) * (obj_h - size_tmp - 2 * sb_ver_pad)) / + (scrl_h + 2 * vpad - obj_h)); + + if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.ver_draw = 1; + } + + /*Invalidate the new scrollbar areas*/ + if(ext->sb.hor_draw != 0) { + lv_area_copy(&sb_area_tmp, &ext->sb.hor_area); + sb_area_tmp.x1 += page->coords.x1; + sb_area_tmp.y1 += page->coords.y1; + sb_area_tmp.x2 += page->coords.x1; + sb_area_tmp.y2 += page->coords.y1; + lv_inv_area(&sb_area_tmp); + } + if(ext->sb.ver_draw != 0) { + lv_area_copy(&sb_area_tmp, &ext->sb.ver_area); + sb_area_tmp.x1 += page->coords.x1; + sb_area_tmp.y1 += page->coords.y1; + sb_area_tmp.x2 += page->coords.x1; + sb_area_tmp.y2 += page->coords.y1; + lv_inv_area(&sb_area_tmp); + } +} + +#if USE_LV_ANIMATION +static void edge_flash_anim(void * page, int32_t v) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + ext->edge_flash.state = v; + lv_obj_invalidate(page); +} + +static void edge_flash_anim_end(void * page) +{ + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + ext->edge_flash.top_ip = 0; + ext->edge_flash.bottom_ip = 0; + ext->edge_flash.left_ip = 0; + ext->edge_flash.right_ip = 0; + lv_obj_invalidate(page); +} +#endif + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.h new file mode 100644 index 0000000..d95f169 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_page.h @@ -0,0 +1,402 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_page.h + * + */ + +#ifndef LV_PAGE_H +#define LV_PAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_PAGE != 0 + +/*Testing of dependencies*/ +#if USE_LV_CONT == 0 +#error "lv_page: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " +#endif + +#include "lv_cont.h" +#include "../lv_core/lv_indev.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Scrollbar modes: shows when should the scrollbars be visible*/ +enum +{ + LV_SB_MODE_OFF = 0x0, /*Never show scrollbars*/ + LV_SB_MODE_ON = 0x1, /*Always show scrollbars*/ + LV_SB_MODE_DRAG = 0x2, /*Show scrollbars when page is being dragged*/ + LV_SB_MODE_AUTO = 0x3, /*Show scrollbars when the scrollable container is large enough to be scrolled*/ + LV_SB_MODE_HIDE = 0x4, /*Hide the scroll bar temporally*/ + LV_SB_MODE_UNHIDE = 0x5, /*Unhide the previously hidden scrollbar. Recover it's type too*/ +}; +typedef uint8_t lv_sb_mode_t; + +/*Data of page*/ +typedef struct +{ + lv_cont_ext_t bg; /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t * scrl; /*The scrollable object on the background*/ + lv_style_t *bgo; /*The scrollable object on the background*/ + lv_style_t *pr; /*The scrollable object on the background*/ + lv_action_t rel_action; /*Function to call when the page is released*/ + lv_action_t pr_action; /*Function to call when the page is pressed*/ + struct { + lv_style_t *style; /*Style of scrollbars*/ + lv_area_t hor_area; /*Horizontal scrollbar area relative to the page. (Handled by the library) */ + lv_area_t ver_area; /*Vertical scrollbar area relative to the page (Handled by the library)*/ + uint8_t hor_draw :1; /*1: horizontal scrollbar is visible now (Handled by the library)*/ + uint8_t ver_draw :1; /*1: vertical scrollbar is visible now (Handled by the library)*/ + lv_sb_mode_t mode:3; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/ + } sb; + struct { + uint16_t state; /*Store the current size of the edge flash effect*/ + lv_style_t *style; /*Style of edge flash effect (usually homogeneous circle)*/ + uint8_t enabled :1; /*1: Show a flash animation on the edge*/ + uint8_t top_ip :1; /*Used internally to show that top most position is reached (flash is In Progress)*/ + uint8_t bottom_ip :1; /*Used internally to show that bottom most position is reached (flash is In Progress)*/ + uint8_t right_ip :1; /*Used internally to show that right most position is reached (flash is In Progress)*/ + uint8_t left_ip :1; /*Used internally to show that left most position is reached (flash is In Progress)*/ + }edge_flash; + + uint8_t arrow_scroll :1; /*1: Enable scrolling with LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN*/ + uint8_t scroll_prop :1; /*1: Propagate the scrolling the the parent if the edge is reached*/ + uint8_t scroll_prop_ip :1; /*1: Scroll propagation is in progress (used by the library)*/ +} lv_page_ext_t; + +enum { + LV_PAGE_STYLE_BG, + LV_PAGE_STYLE_BGO, + LV_PAGE_STYLE_PR, + LV_PAGE_STYLE_SCRL, + LV_PAGE_STYLE_SB, + LV_PAGE_STYLE_EDGE_FLASH, +}; +typedef uint8_t lv_page_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a page objects + * @param par pointer to an object, it will be the parent of the new page + * @param copy pointer to a page object, if not NULL then the new object will be copied from it + * @return pointer to the created page + */ +lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy); + +/** + * Delete all children of the scrl object, without deleting scrl child. + * @param obj pointer to an object + */ +void lv_page_clean(lv_obj_t *obj); + +/** + * Get the press action of the page + * @param page pointer to a page object + * @return a function to call when the page is pressed + */ +lv_action_t lv_page_get_pr_action(lv_obj_t * page); + +/** + * Get the release action of the page + * @param page pointer to a page object + * @return a function to call when the page is released + */ +lv_action_t lv_page_get_rel_action(lv_obj_t * page); + +/** + * Get the scrollable object of a page + * @param page pointer to a page object + * @return pointer to a container which is the scrollable part of the page + */ +lv_obj_t * lv_page_get_scrl(const lv_obj_t * page); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a release action for the page + * @param page pointer to a page object + * @param rel_action a function to call when the page is released + */ +void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action); + +/** + * Set a press action for the page + * @param page pointer to a page object + * @param pr_action a function to call when the page is pressed + */ +void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action); + +/** + * Set the scroll bar mode on a page + * @param page pointer to a page object + * @param sb_mode the new mode from 'lv_page_sb.mode_t' enum + */ +void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode); + +/** + * Enable/Disable scrolling with arrows if the page is in group (arrows: LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) + * @param page pointer to a page object + * @param en true: enable scrolling with arrows + */ +void lv_page_set_arrow_scroll(lv_obj_t * page, bool en); + +/** + * Enable the scroll propagation feature. If enabled then the page will move its parent if there is no more space to scroll. + * @param page pointer to a Page + * @param en true or false to enable/disable scroll propagation + */ +void lv_page_set_scroll_propagation(lv_obj_t * page, bool en); + +/** + * Enable the edge flash effect. (Show an arc when the an edge is reached) + * @param page pointer to a Page + * @param en true or false to enable/disable end flash + */ +void lv_page_set_edge_flash(lv_obj_t * page, bool en); + +/** + * Set the fit attribute of the scrollable part of a page. + * It means it can set its size automatically to involve all children. + * (Can be set separately horizontally and vertically) + * @param page pointer to a page object + * @param hor_en true: enable horizontal fit + * @param ver_en true: enable vertical fit + */ +static inline void lv_page_set_scrl_fit(lv_obj_t *page, bool hor_en, bool ver_en) +{ + lv_cont_set_fit(lv_page_get_scrl(page), hor_en, ver_en); +} + +/** + * Set width of the scrollable part of a page + * @param page pointer to a page object + * @param w the new width of the scrollable (it ha no effect is horizontal fit is enabled) + */ +static inline void lv_page_set_scrl_width(lv_obj_t *page, lv_coord_t w) +{ + lv_obj_set_width(lv_page_get_scrl(page), w); +} + +/** + * Set height of the scrollable part of a page + * @param page pointer to a page object + * @param h the new height of the scrollable (it ha no effect is vertical fit is enabled) + */ +static inline void lv_page_set_scrl_height(lv_obj_t *page, lv_coord_t h) +{ + lv_obj_set_height(lv_page_get_scrl(page), h); + +} + +/** +* Set the layout of the scrollable part of the page +* @param page pointer to a page object +* @param layout a layout from 'lv_cont_layout_t' +*/ +static inline void lv_page_set_scrl_layout(lv_obj_t * page, lv_layout_t layout) +{ + lv_cont_set_layout(lv_page_get_scrl(page), layout); +} + +/** + * Set a style of a page + * @param page pointer to a page object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_page_set_style(lv_obj_t *page, lv_page_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Set the scroll bar mode on a page + * @param page pointer to a page object + * @return the mode from 'lv_page_sb.mode_t' enum + */ +lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page); + + +/** + * Get the the scrolling with arrows (LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) is enabled or not + * @param page pointer to a page object + * @return true: scrolling with arrows is enabled + */ +bool lv_page_get_arrow_scroll(const lv_obj_t * page); + +/** + * Get the scroll propagation property + * @param page pointer to a Page + * @return true or false + */ +bool lv_page_get_scroll_propagation(lv_obj_t * page); + +/** + * Get the edge flash effect property. + * @param page pointer to a Page + * return true or false + */ +bool lv_page_get_edge_flash(lv_obj_t * page); + +/** + * Get that width which can be set to the children to still not cause overflow (show scrollbars) + * @param page pointer to a page object + * @return the width which still fits into the page + */ +lv_coord_t lv_page_get_fit_width(lv_obj_t * page); + +/** + * Get that height which can be set to the children to still not cause overflow (show scrollbars) + * @param page pointer to a page object + * @return the height which still fits into the page + */ +lv_coord_t lv_page_get_fit_height(lv_obj_t * page); + +/** + * Get width of the scrollable part of a page + * @param page pointer to a page object + * @return the width of the scrollable + */ +static inline lv_coord_t lv_page_get_scrl_width(const lv_obj_t *page) +{ + return lv_obj_get_width(lv_page_get_scrl(page)); +} + +/** + * Get height of the scrollable part of a page + * @param page pointer to a page object + * @return the height of the scrollable + */ +static inline lv_coord_t lv_page_get_scrl_height(const lv_obj_t *page) +{ + return lv_obj_get_height(lv_page_get_scrl(page)); +} + +/** +* Get the layout of the scrollable part of a page +* @param page pointer to page object +* @return the layout from 'lv_cont_layout_t' +*/ +static inline lv_layout_t lv_page_get_scrl_layout(const lv_obj_t * page) +{ + return lv_cont_get_layout(lv_page_get_scrl(page)); +} + +/** +* Get horizontal fit attribute of the scrollable part of a page +* @param page pointer to a page object +* @return true: horizontal fit is enabled; false: disabled +*/ +static inline bool lv_page_get_scrl_hor_fit(const lv_obj_t * page) +{ + return lv_cont_get_hor_fit(lv_page_get_scrl(page)); +} + +/** +* Get vertical fit attribute of the scrollable part of a page +* @param page pointer to a page object +* @return true: vertical fit is enabled; false: disabled +*/ +static inline bool lv_page_get_scrl_fit_ver(const lv_obj_t * page) +{ + return lv_cont_get_ver_fit(lv_page_get_scrl(page)); +} + +/** + * Get a style of a page + * @param page pointer to page object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_page_get_style(const lv_obj_t *page, lv_page_style_t type); + +/*===================== + * Other functions + *====================*/ + +/** + * Glue the object to the page. After it the page can be moved (dragged) with this object too. + * @param obj pointer to an object on a page + * @param glue true: enable glue, false: disable glue + */ +void lv_page_glue_obj(lv_obj_t * obj, bool glue); + +/** + * Focus on an object. It ensures that the object will be visible on the page. + * @param page pointer to a page object + * @param obj pointer to an object to focus (must be on the page) + * @param anim_time scroll animation time in milliseconds (0: no animation) + */ +void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time); + +/** + * Scroll the page horizontally + * @param page pointer to a page object + * @param dist the distance to scroll (< 0: scroll left; > 0 scroll right) + */ +void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist); + +/** + * Scroll the page vertically + * @param page pointer to a page object + * @param dist the distance to scroll (< 0: scroll down; > 0 scroll up) + */ +void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist); + +/** + * Not intended to use directly by the user but by other object types internally. + * Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set + * @param page + */ +void lv_page_start_edge_flash(lv_obj_t * page); +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_PAGE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_PAGE_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.c new file mode 100644 index 0000000..1700a4d --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.c @@ -0,0 +1,411 @@ +/** + * @file lv_preload.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_preload.h" +#if USE_LV_PRELOAD != 0 + +#include "../lv_misc/lv_math.h" +#include "../lv_draw/lv_draw_rect.h" +#include "../lv_draw/lv_draw_arc.h" +#include "../lv_themes/lv_theme.h" + +/********************* + * DEFINES + *********************/ +#ifndef LV_PRELOAD_DEF_ARC_LENGTH +# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/ +#endif + +#ifndef LV_PRELOAD_DEF_SPIN_TIME +# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/ +#endif + +#ifndef LV_PRELOAD_DEF_ANIM +# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC /*animation type*/ +#endif + + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_preload_design(lv_obj_t * preload, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_preload_signal(lv_obj_t * preload, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a pre loader object + * @param par pointer to an object, it will be the parent of the new pre loader + * @param copy pointer to a pre loader object, if not NULL then the new object will be copied from it + * @return pointer to the created pre loader + */ +lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("preload create started"); + + /*Create the ancestor of pre loader*/ + lv_obj_t * new_preload = lv_arc_create(par, copy); + lv_mem_assert(new_preload); + if(new_preload == NULL) return NULL; + + /*Allocate the pre loader type specific extended data*/ + lv_preload_ext_t * ext = lv_obj_allocate_ext_attr(new_preload, sizeof(lv_preload_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_preload); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_preload); + + /*Initialize the allocated 'ext' */ + ext->arc_length = LV_PRELOAD_DEF_ARC_LENGTH; + ext->anim_type = LV_PRELOAD_DEF_ANIM; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_preload, lv_preload_signal); + lv_obj_set_design_func(new_preload, lv_preload_design); + + + /*Init the new pre loader pre loader*/ + if(copy == NULL) { + lv_obj_set_size(new_preload, LV_DPI / 2, LV_DPI / 2); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_preload_set_style(new_preload, LV_PRELOAD_STYLE_MAIN, th->preload); + } else { + lv_obj_set_style(new_preload, &lv_style_pretty_color); + } + + ext->time = LV_PRELOAD_DEF_SPIN_TIME; + + } + /*Copy an existing pre loader*/ + else { + lv_preload_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->arc_length = copy_ext->arc_length; + ext->time = copy_ext->time; + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_preload); + } + + lv_preload_set_animation_type(new_preload, ext->anim_type); + + + LV_LOG_INFO("preload created"); + + return new_preload; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Set the length of the spinning arc in degrees + * @param preload pointer to a preload object + * @param deg length of the arc + */ +void lv_preload_set_arc_length(lv_obj_t * preload, uint16_t deg) +{ + lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); + + ext->arc_length = deg; +} + +/** + * Set the spin time of the arc + * @param preload pointer to a preload object + * @param time time of one round in milliseconds + */ +void lv_preload_set_spin_time(lv_obj_t * preload, uint16_t time) +{ + lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); + + ext->time = time; + lv_preload_set_animation_type(preload, ext->anim_type); +} +/*===================== + * Setter functions + *====================*/ + +/** + * Set a style of a pre loader. + * @param preload pointer to pre loader object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_preload_set_style(lv_obj_t * preload, lv_preload_style_t type, lv_style_t * style) +{ + switch(type) { + case LV_PRELOAD_STYLE_MAIN: + lv_arc_set_style(preload, LV_ARC_STYLE_MAIN, style); + break; + } +} + +/** + * Set the animation type of a preloadeer. + * @param preload pointer to pre loader object + * @param type animation type of the preload + * */ +void lv_preload_set_animation_type(lv_obj_t * preload, lv_preloader_type_t type) +{ +#if USE_LV_ANIMATION + lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); + + /*delete previous animation*/ + //lv_anim_del(preload, NULL); + switch(type) + { + case LV_PRELOAD_TYPE_FILLSPIN_ARC: + { + ext->anim_type = LV_PRELOAD_TYPE_FILLSPIN_ARC; + lv_anim_t a; + a.var = preload; + a.start = 0; + a.end = 360; + a.fp = (lv_anim_fp_t)lv_preload_spinner_animation; + a.path = lv_anim_path_ease_in_out; + a.end_cb = NULL; + a.act_time = 0; + a.time = ext->time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 1; + a.repeat_pause = 0; + lv_anim_create(&a); + + lv_anim_t b; + b.var = preload; + b.start = ext->arc_length; + b.end = 360 - ext->arc_length; + b.fp = (lv_anim_fp_t)lv_preload_set_arc_length; + b.path = lv_anim_path_ease_in_out; + b.end_cb = NULL; + b.act_time = 0; + b.time = ext->time; + b.playback = 1; + b.playback_pause = 0; + b.repeat = 1; + b.repeat_pause = 0; + lv_anim_create(&b); + break; + } + case LV_PRELOAD_TYPE_SPINNING_ARC: + default: + { + ext->anim_type = LV_PRELOAD_TYPE_SPINNING_ARC; + lv_anim_t a; + a.var = preload; + a.start = 0; + a.end = 360; + a.fp = (lv_anim_fp_t)lv_preload_spinner_animation; + a.path = lv_anim_path_ease_in_out; + a.end_cb = NULL; + a.act_time = 0; + a.time = ext->time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 1; + a.repeat_pause = 0; + lv_anim_create(&a); + break; + } + } + +#endif //USE_LV_ANIMATION +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the arc length [degree] of the a pre loader + * @param preload pointer to a pre loader object + */ +uint16_t lv_preload_get_arc_length(const lv_obj_t * preload) +{ + lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); + return ext->arc_length; + +} + +/** + * Get the spin time of the arc + * @param preload pointer to a pre loader object [milliseconds] + */ +uint16_t lv_preload_get_spin_time(const lv_obj_t * preload) +{ + lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); + return ext->time; +} + +/** + * Get style of a pre loader. + * @param preload pointer to pre loader object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_preload_get_style(const lv_obj_t * preload, lv_preload_style_t type) +{ + lv_style_t * style = NULL; + + switch(type) { + case LV_PRELOAD_STYLE_MAIN: + style = lv_arc_get_style(preload, LV_ARC_STYLE_MAIN); + break; + default: + style = NULL; + break; + } + + return style; +} + +/** + * Get the animation type of a preloadeer. + * @param preload pointer to pre loader object + * @return animation type + * */ +lv_preloader_type_t lv_preload_get_animation_type(lv_obj_t * preload) +{ + lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); + return ext->anim_type; +} + +/*===================== + * Other functions + *====================*/ + +/** + * Automatically in an animation to rotate the arc of spinner. + * @param ptr pointer to preloader + * @param val the current desired value [0..360] + */ +void lv_preload_spinner_animation(void * ptr, int32_t val) +{ + lv_obj_t * preload = ptr; + lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); + int16_t angle_start = val - ext->arc_length / 2 + 180; + int16_t angle_end = angle_start + ext->arc_length; + + angle_start = angle_start % 360; + angle_end = angle_end % 360; + + lv_arc_set_angles(preload, angle_start, angle_end); + +} + + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the pre loaders + * @param preload pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_preload_design(lv_obj_t * preload, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + /*Draw a circle as background*/ + lv_style_t * style = lv_arc_get_style(preload, LV_ARC_STYLE_MAIN); + if(style->body.border.width > 0) { + lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(preload), lv_obj_get_height(preload))) / 2; + r -= LV_MATH_MIN(style->body.padding.hor, style->body.padding.ver); + + lv_coord_t x = preload->coords.x1 + lv_obj_get_width(preload) / 2; + lv_coord_t y = preload->coords.y1 + lv_obj_get_height(preload) / 2; + + lv_style_t bg_style; + lv_style_copy(&bg_style, &lv_style_plain); + bg_style.body.empty = 1; + bg_style.body.radius = LV_RADIUS_CIRCLE; + bg_style.body.border.color = style->body.border.color; + bg_style.body.border.width = style->body.border.width; + + lv_area_t bg_area; + bg_area.x1 = x - r; + bg_area.y1 = y - r; + bg_area.x2 = x + r; + bg_area.y2 = y + r; + + lv_draw_rect(&bg_area, mask, &bg_style, lv_obj_get_opa_scale(preload)); + } + /*Draw the arc above the background circle */ + ancestor_design(preload, mask, mode); + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the pre loader + * @param preload pointer to a pre loader object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_preload_signal(lv_obj_t * preload, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(preload, sign, param); + if(res != LV_RES_OK) return res; + + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_preload"; + } + + return res; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.h new file mode 100644 index 0000000..4f12f02 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_preload.h @@ -0,0 +1,168 @@ +/** + * @file lv_preload.h + * + */ + +#ifndef LV_PRELOAD_H +#define LV_PRELOAD_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_PRELOAD != 0 + +/*Testing of dependencies*/ +#if USE_LV_ARC == 0 +#error "lv_preload: lv_arc is required. Enable it in lv_conf.h (USE_LV_ARC 1) " +#endif + +#if USE_LV_ANIMATION == 0 +#error "lv_preload: animations are required. Enable it in lv_conf.h (USE_LV_ANIMATION 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_arc.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_PRELOAD_TYPE_SPINNING_ARC, + LV_PRELOAD_TYPE_FILLSPIN_ARC, +}; +typedef uint8_t lv_preloader_type_t; + +/*Data of pre loader*/ +typedef struct { + lv_arc_ext_t arc; /*Ext. of ancestor*/ + /*New data for this type */ + uint16_t arc_length; /*Length of the spinning indicator in degree*/ + uint16_t time; /*Time of one round*/ + lv_preloader_type_t anim_type; /*Type of the arc animation*/ +} lv_preload_ext_t; + + +/*Styles*/ +enum { + LV_PRELOAD_STYLE_MAIN, +}; +typedef uint8_t lv_preload_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a pre loader objects + * @param par pointer to an object, it will be the parent of the new pre loader + * @param copy pointer to a pre loader object, if not NULL then the new object will be copied from it + * @return pointer to the created pre loader + */ +lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Set the length of the spinning arc in degrees + * @param preload pointer to a preload object + * @param deg length of the arc + */ +void lv_preload_set_arc_length(lv_obj_t * preload, uint16_t deg); + +/** + * Set the spin time of the arc + * @param preload pointer to a preload object + * @param time time of one round in milliseconds + */ +void lv_preload_set_spin_time(lv_obj_t * preload, uint16_t time); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a style of a pre loader. + * @param preload pointer to pre loader object + * @param type which style should be set + * @param style pointer to a style + * */ +void lv_preload_set_style(lv_obj_t * preload, lv_preload_style_t type, lv_style_t *style); + +/** + * Set the animation type of a preloadeer. + * @param preload pointer to pre loader object + * @param type animation type of the preload + * */ +void lv_preload_set_animation_type(lv_obj_t * preload, lv_preloader_type_t type); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the arc length [degree] of the a pre loader + * @param preload pointer to a pre loader object + */ +uint16_t lv_preload_get_arc_length(const lv_obj_t * preload); + +/** + * Get the spin time of the arc + * @param preload pointer to a pre loader object [milliseconds] + */ +uint16_t lv_preload_get_spin_time(const lv_obj_t * preload); + +/** + * Get style of a pre loader. + * @param preload pointer to pre loader object + * @param type which style should be get + * @return style pointer to the style + * */ +lv_style_t * lv_preload_get_style(const lv_obj_t * preload, lv_preload_style_t type); + +/** + * Get the animation type of a preloadeer. + * @param preload pointer to pre loader object + * @return animation type + * */ +lv_preloader_type_t lv_preload_get_animation_type(lv_obj_t * preload); + +/*===================== + * Other functions + *====================*/ + +/** + * Get style of a pre loader. + * @param preload pointer to pre loader object + * @param type which style should be get + * @return style pointer to the style + * */ +void lv_preload_spinner_animation(void * ptr, int32_t val); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_PRELOAD*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_PRELOAD_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.c new file mode 100644 index 0000000..28c8b80 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.c @@ -0,0 +1,582 @@ +/** + * @file lv_roller.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_roller.h" +#if USE_LV_ROLLER != 0 + +#include "../lv_draw/lv_draw.h" +#include "../lv_core/lv_group.h" +#include "../lv_themes/lv_theme.h" + +/********************* + * DEFINES + *********************/ +#if USE_LV_ANIMATION +# ifndef LV_ROLLER_ANIM_TIME +# define LV_ROLLER_ANIM_TIME 200 /*ms*/ +# endif +#else +# undef LV_ROLLER_ANIM_TIME +# define LV_ROLLER_ANIM_TIME 0 /*No animation*/ +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param); +static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param); +static void refr_position(lv_obj_t * roller, bool anim_en); +static void draw_bg(lv_obj_t * roller, const lv_area_t * mask); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_signal_func_t ancestor_scrl_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a roller object + * @param par pointer to an object, it will be the parent of the new roller + * @param copy pointer to a roller object, if not NULL then the new object will be copied from it + * @return pointer to the created roller + */ +lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("roller create started"); + + /*Create the ancestor of roller*/ + lv_obj_t * new_roller = lv_ddlist_create(par, copy); + lv_mem_assert(new_roller); + if(new_roller == NULL) return NULL; + + if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_roller)); + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_roller); + + /*Allocate the roller type specific extended data*/ + lv_roller_ext_t * ext = lv_obj_allocate_ext_attr(new_roller, sizeof(lv_roller_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->ddlist.draw_arrow = 0; /*Do not draw arrow by default*/ + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_roller, lv_roller_signal); + lv_obj_set_design_func(new_roller, lv_roller_design); + + /*Init the new roller roller*/ + if(copy == NULL) { + lv_obj_t * scrl = lv_page_get_scrl(new_roller); + lv_obj_set_drag(scrl, true); /*In ddlist is might be disabled*/ + lv_page_set_rel_action(new_roller, NULL); /*Roller don't uses it (like ddlist)*/ + lv_page_set_scrl_fit(new_roller, true, false); /*Height is specified directly*/ + lv_ddlist_open(new_roller, false); + lv_ddlist_set_anim_time(new_roller, LV_ROLLER_ANIM_TIME); + lv_roller_set_visible_row_count(new_roller, 3); + lv_label_set_align(ext->ddlist.label, LV_LABEL_ALIGN_CENTER); + + lv_obj_set_signal_func(scrl, lv_roller_scrl_signal); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->roller.bg); + lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->roller.sel); + } else { + /*Let the ddlist's style*/ + lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/ + } + } + /*Copy an existing roller*/ + else { + lv_obj_t * scrl = lv_page_get_scrl(new_roller); + lv_ddlist_open(new_roller, false); + lv_obj_set_signal_func(scrl, lv_roller_scrl_signal); + + lv_obj_refresh_style(new_roller); /*Refresh the style with new signal function*/ + } + + + LV_LOG_INFO("roller created"); + + + return new_roller; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the align of the roller's options (left or center) + * @param roller - pointer to a roller object + * @param align - one of lv_label_align_t values (left, right, center) + */ +void lv_roller_set_align(lv_obj_t * roller, lv_label_align_t align) +{ + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + lv_mem_assert(ext); + if(ext->ddlist.label == NULL) return; /*Probably the roller is being deleted if the label is NULL.*/ + lv_label_set_align(ext->ddlist.label, align); +} + +/** + * Set the selected option + * @param roller pointer to a roller object + * @param sel_opt id of the selected option (0 ... number of option - 1); + * @param anim_en true: set with animation; false set immediately + */ +void lv_roller_set_selected(lv_obj_t * roller, uint16_t sel_opt, bool anim_en) +{ +#if USE_LV_ANIMATION == 0 + anim_en = false; +#endif + + if(lv_roller_get_selected(roller) == sel_opt) return; + + lv_ddlist_set_selected(roller, sel_opt); + refr_position(roller, anim_en); +} + +/** + * Set the height to show the given number of rows (options) + * @param roller pointer to a roller object + * @param row_cnt number of desired visible rows + */ +void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt) +{ + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); + uint8_t n_line_space = (row_cnt > 1) ? row_cnt - 1 : 1; + lv_ddlist_set_fix_height(roller, lv_font_get_height(style_label->text.font) * row_cnt + style_label->text.line_space * n_line_space); +} + +/** + * Set a style of a roller + * @param roller pointer to a roller object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_roller_set_style(lv_obj_t * roller, lv_roller_style_t type, lv_style_t * style) +{ + switch(type) { + case LV_ROLLER_STYLE_BG: + lv_obj_set_style(roller, style); + break; + case LV_ROLLER_STYLE_SEL: + lv_ddlist_set_style(roller, LV_DDLIST_STYLE_SEL, style); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER + * @param roller pointer to a roller object + * @return LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER + */ +lv_label_align_t lv_roller_get_align(const lv_obj_t * roller) +{ + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + lv_mem_assert(ext); + lv_mem_assert(ext->ddlist.label); + return lv_label_get_align(ext->ddlist.label); +} + +/** + * Get the auto width set attribute + * @param roller pointer to a roller object + * @return true: auto size enabled; false: manual width settings enabled + */ +bool lv_roller_get_hor_fit(const lv_obj_t * roller) +{ + return lv_page_get_scrl_hor_fit(roller); +} + +/** + * Get a style of a roller + * @param roller pointer to a roller object + * @param type which style should be get + * @return style pointer to a style + * */ +lv_style_t * lv_roller_get_style(const lv_obj_t * roller, lv_roller_style_t type) +{ + switch(type) { + case LV_ROLLER_STYLE_BG: + return lv_obj_get_style(roller); + case LV_ROLLER_STYLE_SEL: + return lv_ddlist_get_style(roller, LV_DDLIST_STYLE_SEL); + default: + return NULL; + } + + /*To avoid warning*/ + return NULL; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the rollers + * @param roller pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + draw_bg(roller, mask); + + lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG); + lv_opa_t opa_scale = lv_obj_get_opa_scale(roller); + const lv_font_t * font = style->text.font; + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + lv_coord_t font_h = lv_font_get_height(font); + lv_area_t rect_area; + rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2; + if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1 --; /*Compensate the two rounding error*/ + rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1; + rect_area.x1 = roller->coords.x1; + rect_area.x2 = roller->coords.x2; + + lv_draw_rect(&rect_area, mask, ext->ddlist.sel_style, opa_scale); + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG); + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + const lv_font_t * font = style->text.font; + lv_coord_t font_h = lv_font_get_height(font); + lv_opa_t opa_scale = lv_obj_get_opa_scale(roller); + + /*Redraw the text on the selected area with a different color*/ + lv_area_t rect_area; + rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2; + if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1 --; /*Compensate the two rounding error*/ + rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1; + rect_area.x1 = roller->coords.x1; + rect_area.x2 = roller->coords.x2; + lv_area_t mask_sel; + bool area_ok; + area_ok = lv_area_intersect(&mask_sel, mask, &rect_area); + if(area_ok) { + lv_style_t * sel_style = lv_roller_get_style(roller, LV_ROLLER_STYLE_SEL); + lv_style_t new_style; + lv_txt_flag_t txt_align = LV_TXT_FLAG_NONE; + + { + lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label); + + if(LV_LABEL_ALIGN_CENTER == label_align) { + txt_align |= LV_TXT_FLAG_CENTER; + } else if(LV_LABEL_ALIGN_RIGHT == label_align) { + txt_align |= LV_TXT_FLAG_RIGHT; + } + } + + lv_style_copy(&new_style, style); + new_style.text.color = sel_style->text.color; + new_style.text.opa = sel_style->text.opa; + lv_draw_label(&ext->ddlist.label->coords, &mask_sel, &new_style, opa_scale, + lv_label_get_text(ext->ddlist.label), txt_align, NULL); + } + } + + return true; +} + +/** + * Signal function of the roller + * @param roller pointer to a roller object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param) +{ + lv_res_t res = LV_RES_OK; + + /*Don't let the drop down list to handle the control signals. It works differently*/ + if(sign != LV_SIGNAL_CONTROLL && sign != LV_SIGNAL_FOCUS && sign != LV_SIGNAL_DEFOCUS) { + /* Include the ancient signal function */ + res = ancestor_signal(roller, sign, param); + if(res != LV_RES_OK) return res; + } + + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + lv_align_t obj_align = LV_ALIGN_IN_LEFT_MID; + if(ext->ddlist.label) { + lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label); + if(LV_LABEL_ALIGN_CENTER == label_align) obj_align = LV_ALIGN_CENTER; + else if(LV_LABEL_ALIGN_RIGHT == label_align) obj_align = LV_ALIGN_IN_RIGHT_MID; + } + + if(sign == LV_SIGNAL_STYLE_CHG) { + lv_obj_set_height(lv_page_get_scrl(roller), + lv_obj_get_height(ext->ddlist.label) + lv_obj_get_height(roller)); + lv_obj_align(ext->ddlist.label, NULL, obj_align, 0, 0); + lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id); + refr_position(roller, false); + } else if(sign == LV_SIGNAL_CORD_CHG) { + + if(lv_obj_get_width(roller) != lv_area_get_width(param) || + lv_obj_get_height(roller) != lv_area_get_height(param)) { + + lv_ddlist_set_fix_height(roller, lv_obj_get_height(roller)); + lv_obj_set_height(lv_page_get_scrl(roller), + lv_obj_get_height(ext->ddlist.label) + lv_obj_get_height(roller)); + + lv_obj_align(ext->ddlist.label, NULL, obj_align, 0, 0); + lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id); + refr_position(roller, false); + } + } else if(sign == LV_SIGNAL_FOCUS) { +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(roller); + bool editing = lv_group_get_editing(g); + lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + + /*Encoders need special handling*/ + if(indev_type == LV_INDEV_TYPE_ENCODER) { + /*In navigate mode revert the original value*/ + if(!editing) { + if(ext->ddlist.sel_opt_id != ext->ddlist.sel_opt_id_ori) { + ext->ddlist.sel_opt_id = ext->ddlist.sel_opt_id_ori; + refr_position(roller, true); + } + } + /*Save the current state when entered to edit mode*/ + else { + ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; + } + } else { + ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Save the current value. Used to revert this state if ENER wont't be pressed*/ + + } +#endif + } else if(sign == LV_SIGNAL_DEFOCUS) { +#if USE_LV_GROUP + /*Revert the original state*/ + if(ext->ddlist.sel_opt_id != ext->ddlist.sel_opt_id_ori) { + ext->ddlist.sel_opt_id = ext->ddlist.sel_opt_id_ori; + refr_position(roller, true); + } +#endif + } else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char *)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) { + if(ext->ddlist.sel_opt_id + 1 < ext->ddlist.option_cnt) { + lv_roller_set_selected(roller, ext->ddlist.sel_opt_id + 1, true); + } + } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) { + if(ext->ddlist.sel_opt_id > 0) { + lv_roller_set_selected(roller, ext->ddlist.sel_opt_id - 1, true); + } + } else if(c == LV_GROUP_KEY_ENTER) { + ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Set the entered value as default*/ + if(ext->ddlist.action) ext->ddlist.action(roller); + +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(roller); + bool editing = lv_group_get_editing(g); + if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ +#endif + } + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_roller"; + } + + return res; +} + +/** + * Signal function of the scrollable part of the roller. + * @param roller_scrl ointer to the scrollable part of roller (page) + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_scrl_signal(roller_scrl, sign, param); + if(res != LV_RES_OK) return res; + + lv_indev_t * indev = lv_indev_get_act(); + int32_t id = -1; + lv_obj_t * roller = lv_obj_get_parent(roller_scrl); + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + + if(ext->ddlist.label == NULL) return LV_RES_INV; /*On delete the ddlist signal deletes the label so nothing left to do here*/ + + lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); + const lv_font_t * font = style_label->text.font; + lv_coord_t font_h = lv_font_get_height(font); + + if(sign == LV_SIGNAL_DRAG_END) { + /*If dragged then align the list to there be an element in the middle*/ + lv_coord_t label_y1 = ext->ddlist.label->coords.y1 - roller->coords.y1; + lv_coord_t label_unit = font_h + style_label->text.line_space; + lv_coord_t mid = (roller->coords.y2 - roller->coords.y1) / 2; + id = (mid - label_y1 + style_label->text.line_space / 2) / label_unit; + if(id < 0) id = 0; + if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; + ext->ddlist.sel_opt_id = id; + if(ext->ddlist.action) ext->ddlist.action(roller); + } else if(sign == LV_SIGNAL_RELEASED) { + /*If picked an option by clicking then set it*/ + if(!lv_indev_is_dragging(indev)) { + lv_point_t p; + lv_indev_get_point(indev, &p); + p.y = p.y - ext->ddlist.label->coords.y1; + id = p.y / (font_h + style_label->text.line_space); + if(id < 0) id = 0; + if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; + ext->ddlist.sel_opt_id = id; + if(ext->ddlist.action) ext->ddlist.action(roller); + } + } + + /*Position the scrollable according to the new selected option*/ + if(id != -1) { + refr_position(roller, true); + } + + return res; +} + +/** + * Draw a rectangle which has gradient on its top and bottom + * @param roller pointer to a roller object + * @param mask pointer to the current mask (from the design function) + */ +static void draw_bg(lv_obj_t * roller, const lv_area_t * mask) +{ + lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG); + lv_area_t half_mask; + lv_area_t half_roller; + lv_coord_t h = lv_obj_get_height(roller); + bool union_ok; + lv_area_copy(&half_roller, &roller->coords); + + half_roller.x1 -= roller->ext_size; /*Add ext size too (e.g. because of shadow draw) */ + half_roller.x2 += roller->ext_size; + half_roller.y1 -= roller->ext_size; + half_roller.y2 = roller->coords.y1 + h / 2; + + union_ok = lv_area_intersect(&half_mask, &half_roller, mask); + + half_roller.x1 += roller->ext_size; /*Revert ext. size adding*/ + half_roller.x2 -= roller->ext_size; + half_roller.y1 += roller->ext_size; + half_roller.y2 += style->body.radius; + + if(union_ok) { + lv_draw_rect(&half_roller, &half_mask, style, lv_obj_get_opa_scale(roller)); + } + + half_roller.x1 -= roller->ext_size; /*Add ext size too (e.g. because of shadow draw) */ + half_roller.x2 += roller->ext_size; + half_roller.y2 = roller->coords.y2 + roller->ext_size; + half_roller.y1 = roller->coords.y1 + h / 2; + if((h & 0x1) == 0) half_roller.y1++; /*With even height the pixels in the middle would be drawn twice*/ + + union_ok = lv_area_intersect(&half_mask, &half_roller, mask); + + half_roller.x1 += roller->ext_size; /*Revert ext. size adding*/ + half_roller.x2 -= roller->ext_size; + half_roller.y2 -= roller->ext_size; + half_roller.y1 -= style->body.radius; + + if(union_ok) { + lv_color_t main_tmp = style->body.main_color; + lv_color_t grad_tmp = style->body.grad_color; + + style->body.main_color = grad_tmp; + style->body.grad_color = main_tmp; + lv_draw_rect(&half_roller, &half_mask, style, lv_obj_get_opa_scale(roller)); + style->body.main_color = main_tmp; + style->body.grad_color = grad_tmp; + } +} + +/** + * Refresh the position of the roller. It uses the id stored in: ext->ddlist.selected_option_id + * @param roller pointer to a roller object + * @param anim_en true: refresh with animation; false: without animation + */ +static void refr_position(lv_obj_t * roller, bool anim_en) +{ +#if USE_LV_ANIMATION == 0 + anim_en = false; +#endif + lv_obj_t * roller_scrl = lv_page_get_scrl(roller); + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); + const lv_font_t * font = style_label->text.font; + lv_coord_t font_h = lv_font_get_height(font); + lv_coord_t h = lv_obj_get_height(roller); + int32_t id = ext->ddlist.sel_opt_id; + lv_coord_t line_y1 = id * (font_h + style_label->text.line_space) + ext->ddlist.label->coords.y1 - roller_scrl->coords.y1; + lv_coord_t new_y = - line_y1 + (h - font_h) / 2; + + if(ext->ddlist.anim_time == 0 || anim_en == false) { + lv_obj_set_y(roller_scrl, new_y); + } else { +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = roller_scrl; + a.start = lv_obj_get_y(roller_scrl); + a.end = new_y; + a.fp = (lv_anim_fp_t)lv_obj_set_y; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = ext->ddlist.anim_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#endif + } +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.h new file mode 100644 index 0000000..2f1b21c --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_roller.h @@ -0,0 +1,224 @@ +/** + * @file lv_roller.h + * + */ + +#ifndef LV_ROLLER_H +#define LV_ROLLER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_ROLLER != 0 + +/*Testing of dependencies*/ +#if USE_LV_DDLIST == 0 +#error "lv_roller: lv_ddlist is required. Enable it in lv_conf.h (USE_LV_DDLIST 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_ddlist.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of roller*/ +typedef struct { + lv_ddlist_ext_t ddlist; /*Ext. of ancestor*/ + /*New data for this type */ +} lv_roller_ext_t; + +enum { + LV_ROLLER_STYLE_BG, + LV_ROLLER_STYLE_SEL, +}; +typedef uint8_t lv_roller_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a roller object + * @param par pointer to an object, it will be the parent of the new roller + * @param copy pointer to a roller object, if not NULL then the new object will be copied from it + * @return pointer to the created roller + */ +lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the align of the roller's options (left, right or center[default]) + * @param roller - pointer to a roller object + * @param align - one of lv_label_align_t values (left, right, center) + */ +void lv_roller_set_align(lv_obj_t * roller, lv_label_align_t align); + +/** + * Set the options on a roller + * @param roller pointer to roller object + * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" + */ +static inline void lv_roller_set_options(lv_obj_t * roller, const char * options) +{ + lv_ddlist_set_options(roller, options); +} + +/** + * Set the selected option + * @param roller pointer to a roller object + * @param sel_opt id of the selected option (0 ... number of option - 1); + * @param anim_en true: set with animation; false set immediately + */ +void lv_roller_set_selected(lv_obj_t *roller, uint16_t sel_opt, bool anim_en); + +/** + * Set a function to call when a new option is chosen + * @param roller pointer to a roller + * @param action pointer to a callback function + */ +static inline void lv_roller_set_action(lv_obj_t * roller, lv_action_t action) +{ + lv_ddlist_set_action(roller, action); +} + +/** + * Set the height to show the given number of rows (options) + * @param roller pointer to a roller object + * @param row_cnt number of desired visible rows + */ +void lv_roller_set_visible_row_count(lv_obj_t *roller, uint8_t row_cnt); + +/** + * Enable or disable the horizontal fit to the content + * @param roller pointer to a roller + * @param en true: enable auto fit; false: disable auto fit + */ +static inline void lv_roller_set_hor_fit(lv_obj_t * roller, bool en) +{ + lv_ddlist_set_hor_fit(roller, en); +} + +/** + * Set the open/close animation time. + * @param roller pointer to a roller object + * @param anim_time: open/close animation time [ms] + */ +static inline void lv_roller_set_anim_time(lv_obj_t *roller, uint16_t anim_time) +{ + lv_ddlist_set_anim_time(roller, anim_time); +} + +/** + * Set a style of a roller + * @param roller pointer to a roller object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_roller_set_style(lv_obj_t *roller, lv_roller_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER + * @param roller pointer to a roller object + * @return LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER + */ +lv_label_align_t lv_roller_get_align(const lv_obj_t * roller); + +/** + * Get the options of a roller + * @param roller pointer to roller object + * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") + */ +static inline const char * lv_roller_get_options(const lv_obj_t *roller) +{ + return lv_ddlist_get_options(roller); +} + +/** + * Get the id of the selected option + * @param roller pointer to a roller object + * @return id of the selected option (0 ... number of option - 1); + */ +static inline uint16_t lv_roller_get_selected(const lv_obj_t *roller) +{ + return lv_ddlist_get_selected(roller); +} + +/** + * Get the current selected option as a string + * @param roller pointer to roller object + * @param buf pointer to an array to store the string + */ +static inline void lv_roller_get_selected_str(const lv_obj_t * roller, char * buf) +{ + lv_ddlist_get_selected_str(roller, buf); +} + +/** + * Get the "option selected" callback function + * @param roller pointer to a roller + * @return pointer to the call back function + */ +static inline lv_action_t lv_roller_get_action(const lv_obj_t * roller) +{ + return lv_ddlist_get_action(roller); +} + +/** + * Get the open/close animation time. + * @param roller pointer to a roller + * @return open/close animation time [ms] + */ +static inline uint16_t lv_roller_get_anim_time(const lv_obj_t * roller) +{ + return lv_ddlist_get_anim_time(roller); +} + +/** + * Get the auto width set attribute + * @param roller pointer to a roller object + * @return true: auto size enabled; false: manual width settings enabled + */ +bool lv_roller_get_hor_fit(const lv_obj_t *roller); + +/** + * Get a style of a roller + * @param roller pointer to a roller object + * @param type which style should be get + * @return style pointer to a style + * */ +lv_style_t * lv_roller_get_style(const lv_obj_t *roller, lv_roller_style_t type); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_ROLLER*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_ROLLER_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.c new file mode 100644 index 0000000..eaf04e8 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.c @@ -0,0 +1,520 @@ + +/** + * @file lv_slider.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_slider.h" +#if USE_LV_SLIDER != 0 + +#include "../lv_core/lv_group.h" +#include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define LV_SLIDER_SIZE_MIN 4 /*hor. pad and ver. pad cannot make the bar or indicator smaller then this [px]*/ +#define LV_SLIDER_NOT_PRESSED INT16_MIN + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_design_func_t ancestor_design_f; +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a slider objects + * @param par pointer to an object, it will be the parent of the new slider + * @param copy pointer to a slider object, if not NULL then the new object will be copied from it + * @return pointer to the created slider + */ +lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("slider create started"); + + /*Create the ancestor slider*/ + lv_obj_t * new_slider = lv_bar_create(par, copy); + lv_mem_assert(new_slider); + if(new_slider == NULL) return NULL; + + if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_slider); + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_slider); + + /*Allocate the slider type specific extended data*/ + lv_slider_ext_t * ext = lv_obj_allocate_ext_attr(new_slider, sizeof(lv_slider_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + /*Initialize the allocated 'ext' */ + ext->action = NULL; + ext->drag_value = LV_SLIDER_NOT_PRESSED; + ext->style_knob = &lv_style_pretty; + ext->knob_in = 0; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_slider, lv_slider_signal); + lv_obj_set_design_func(new_slider, lv_slider_design); + + /*Init the new slider slider*/ + if(copy == NULL) { + lv_obj_set_click(new_slider, true); + lv_obj_set_protect(new_slider, LV_PROTECT_PRESS_LOST); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_BG, th->slider.bg); + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_INDIC, th->slider.indic); + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, th->slider.knob); + } else { + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, ext->style_knob); + } + } + /*Copy an existing slider*/ + else { + lv_slider_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->style_knob = copy_ext->style_knob; + ext->action = copy_ext->action; + ext->knob_in = copy_ext->knob_in; + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_slider); + } + + + LV_LOG_INFO("slider created"); + + + return new_slider; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a function which will be called when a new value is set on the slider + * @param slider pointer to slider object + * @param action a callback function + */ +void lv_slider_set_action(lv_obj_t * slider, lv_action_t action) +{ + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + ext->action = action; +} + +/** + * Set the 'knob in' attribute of a slider + * @param slider pointer to slider object + * @param in true: the knob is drawn always in the slider; + * false: the knob can be out on the edges + */ +void lv_slider_set_knob_in(lv_obj_t * slider, bool in) +{ + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + if(ext->knob_in == in) return; + + ext->knob_in = in == false ? 0 : 1; + lv_obj_invalidate(slider); +} + +/** + * Set a style of a slider + * @param slider pointer to a slider object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_slider_set_style(lv_obj_t * slider, lv_slider_style_t type, lv_style_t * style) +{ + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + + switch(type) { + case LV_SLIDER_STYLE_BG: + lv_bar_set_style(slider, LV_BAR_STYLE_BG, style); + break; + case LV_SLIDER_STYLE_INDIC: + lv_bar_set_style(slider, LV_BAR_STYLE_INDIC, style); + break; + case LV_SLIDER_STYLE_KNOB: + ext->style_knob = style; + lv_obj_refresh_ext_size(slider); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a slider + * @param slider pointer to a slider object + * @return the value of the slider + */ +int16_t lv_slider_get_value(const lv_obj_t * slider) +{ + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + + if(ext->drag_value != LV_SLIDER_NOT_PRESSED) return ext->drag_value; + else return lv_bar_get_value(slider); +} + +/** + * Get the slider action function + * @param slider pointer to slider object + * @return the callback function + */ +lv_action_t lv_slider_get_action(const lv_obj_t * slider) +{ + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + return ext->action; +} + +/** + * Give the slider is being dragged or not + * @param slider pointer to a slider object + * @return true: drag in progress false: not dragged + */ +bool lv_slider_is_dragged(const lv_obj_t * slider) +{ + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + return ext->drag_value == LV_SLIDER_NOT_PRESSED ? false : true; +} + +/** + * Get the 'knob in' attribute of a slider + * @param slider pointer to slider object + * @return true: the knob is drawn always in the slider; + * false: the knob can be out on the edges + */ +bool lv_slider_get_knob_in(const lv_obj_t * slider) +{ + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + return ext->knob_in == 0 ? false : true; +} + +/** + * Get a style of a slider + * @param slider pointer to a slider object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_slider_get_style(const lv_obj_t * slider, lv_slider_style_t type) +{ + lv_style_t * style = NULL; + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + + switch(type) { + case LV_SLIDER_STYLE_BG: + style = lv_bar_get_style(slider, LV_BAR_STYLE_BG); + break; + case LV_SLIDER_STYLE_INDIC: + style = lv_bar_get_style(slider, LV_BAR_STYLE_INDIC); + break; + case LV_SLIDER_STYLE_KNOB: + style = ext->style_knob; + break; + default: + style = NULL; + break; + } + + return style; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + + +/** + * Handle the drawing related tasks of the sliders + * @param slider pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + + lv_style_t * style_bg = lv_slider_get_style(slider, LV_SLIDER_STYLE_BG); + lv_style_t * style_knob = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB); + lv_style_t * style_indic = lv_slider_get_style(slider, LV_SLIDER_STYLE_INDIC); + + lv_opa_t opa_scale = lv_obj_get_opa_scale(slider); + + lv_coord_t slider_w = lv_area_get_width(&slider->coords); + lv_coord_t slider_h = lv_area_get_height(&slider->coords); + + /*Draw the bar*/ + lv_area_t area_bg; + lv_area_copy(&area_bg, &slider->coords); + + /*Be sure at least LV_SLIDER_SIZE_MIN size will remain*/ + lv_coord_t pad_ver_bg = style_bg->body.padding.ver; + lv_coord_t pad_hor_bg = style_bg->body.padding.hor; + if(pad_ver_bg * 2 + LV_SLIDER_SIZE_MIN > lv_area_get_height(&area_bg)) { + pad_ver_bg = (lv_area_get_height(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1; + } + if(pad_hor_bg * 2 + LV_SLIDER_SIZE_MIN > lv_area_get_width(&area_bg)) { + pad_hor_bg = (lv_area_get_width(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1; + } + + if(ext->knob_in) { /*Enable extra size if the knob is inside */ + area_bg.x1 += pad_hor_bg; + area_bg.x2 -= pad_hor_bg; + area_bg.y1 += pad_hor_bg; + area_bg.y2 -= pad_hor_bg; + } else { /*Let space only in the perpendicular directions*/ + area_bg.x1 += slider_w < slider_h ? pad_hor_bg : 0; /*Pad only for vertical slider*/ + area_bg.x2 -= slider_w < slider_h ? pad_hor_bg : 0; /*Pad only for vertical slider*/ + area_bg.y1 += slider_w > slider_h ? pad_ver_bg : 0; /*Pad only for horizontal slider*/ + area_bg.y2 -= slider_w > slider_h ? pad_ver_bg : 0; /*Pad only for horizontal slider*/ + } + + +#if USE_LV_GROUP == 0 + lv_draw_rect(&area_bg, mask, style_bg, lv_obj_get_opa_scale(slider)); +#else + /* Draw the borders later if the bar is focused. + * At value = 100% the indicator can cover to whole background and the focused style won't be visible*/ + if(lv_obj_is_focused(slider)) { + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style_bg); + style_tmp.body.border.width = 0; + lv_draw_rect(&area_bg, mask, &style_tmp, opa_scale); + } else { + lv_draw_rect(&area_bg, mask, style_bg, opa_scale); + } +#endif + + + /*Draw the indicator*/ + lv_area_t area_indic; + lv_area_copy(&area_indic, &area_bg); + + /*Be sure at least ver pad/hor pad width indicator will remain*/ + lv_coord_t pad_ver_indic = style_indic->body.padding.ver; + lv_coord_t pad_hor_indic = style_indic->body.padding.hor; + if(pad_ver_indic * 2 + LV_SLIDER_SIZE_MIN > lv_area_get_height(&area_bg)) { + pad_ver_indic = (lv_area_get_height(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1; + } + if(pad_hor_indic * 2 + LV_SLIDER_SIZE_MIN > lv_area_get_width(&area_bg)) { + pad_hor_indic = (lv_area_get_width(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1; + } + + area_indic.x1 += pad_hor_indic; + area_indic.x2 -= pad_hor_indic; + area_indic.y1 += pad_ver_indic; + area_indic.y2 -= pad_ver_indic; + + + lv_coord_t cur_value = lv_slider_get_value(slider); + lv_coord_t min_value = lv_slider_get_min_value(slider); + lv_coord_t max_value = lv_slider_get_max_value(slider); + + /*If dragged draw to the drag position*/ + if(ext->drag_value != LV_SLIDER_NOT_PRESSED) cur_value = ext->drag_value; + + if(slider_w >= slider_h) { + area_indic.x2 = (int32_t)((int32_t)(lv_area_get_width(&area_indic)) * (cur_value - min_value)) / (max_value - min_value); + area_indic.x2 = area_indic.x1 + area_indic.x2 - 1; + + } else { + area_indic.y1 = (int32_t)((int32_t)(lv_area_get_height(&area_indic)) * (cur_value - min_value)) / (max_value - min_value); + area_indic.y1 = area_indic.y2 - area_indic.y1 + 1; + } + + if(cur_value != min_value) lv_draw_rect(&area_indic, mask, style_indic, opa_scale); + + /*Before the knob add the border if required*/ +#if USE_LV_GROUP + /* Draw the borders later if the bar is focused. + * At value = 100% the indicator can cover to whole background and the focused style won't be visible*/ + if(lv_obj_is_focused(slider)) { + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style_bg); + style_tmp.body.empty = 1; + style_tmp.body.shadow.width = 0; + lv_draw_rect(&area_bg, mask, &style_tmp, opa_scale); + } +#endif + + /*Draw the knob*/ + lv_area_t knob_area; + lv_area_copy(&knob_area, &slider->coords); + + if(slider_w >= slider_h) { + if(ext->knob_in == 0) { + knob_area.x1 = area_indic.x2 - slider_h / 2; + knob_area.x2 = knob_area.x1 + slider_h - 1; + } else { + knob_area.x1 = (int32_t)((int32_t)(slider_w - slider_h - 1) * (cur_value - min_value)) / (max_value - min_value); + knob_area.x1 += slider->coords.x1; + knob_area.x2 = knob_area.x1 + slider_h - 1; + } + + knob_area.y1 = slider->coords.y1; + knob_area.y2 = slider->coords.y2; + } else { + if(ext->knob_in == 0) { + knob_area.y1 = area_indic.y1 - slider_w / 2; + knob_area.y2 = knob_area.y1 + slider_w - 1; + } else { + knob_area.y2 = (int32_t)((int32_t)(slider_h - slider_w - 1) * (cur_value - min_value)) / (max_value - min_value); + knob_area.y2 = slider->coords.y2 - knob_area.y2; + knob_area.y1 = knob_area.y2 - slider_w - 1; + } + knob_area.x1 = slider->coords.x1; + knob_area.x2 = slider->coords.x2; + + } + lv_draw_rect(&knob_area, mask, style_knob, opa_scale); + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the slider + * @param slider pointer to a slider object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(slider, sign, param); + if(res != LV_RES_OK) return res; + + lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + lv_point_t p; + lv_coord_t w = lv_obj_get_width(slider); + lv_coord_t h = lv_obj_get_height(slider); + + if(sign == LV_SIGNAL_PRESSED) { + ext->drag_value = lv_slider_get_value(slider); + } else if(sign == LV_SIGNAL_PRESSING) { + lv_indev_get_point(param, &p); + int16_t tmp = 0; + if(w > h) { + lv_coord_t knob_w = h; + p.x -= slider->coords.x1 + h / 2; /*Modify the point to shift with half knob (important on the start and end)*/ + tmp = (int32_t)((int32_t) p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - knob_w); + tmp += ext->bar.min_value; + } else { + lv_coord_t knob_h = w; + p.y -= slider->coords.y1 + w / 2; /*Modify the point to shift with half knob (important on the start and end)*/ + tmp = (int32_t)((int32_t) p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - knob_h); + tmp = ext->bar.max_value - tmp; /*Invert the value: smaller value means higher y*/ + } + + if(tmp < ext->bar.min_value) tmp = ext->bar.min_value; + else if(tmp > ext->bar.max_value) tmp = ext->bar.max_value; + + if(tmp != ext->drag_value) { + ext->drag_value = tmp; + lv_obj_invalidate(slider); + if(ext->action != NULL) res = ext->action(slider); + } + } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { + lv_slider_set_value(slider, ext->drag_value); + ext->drag_value = LV_SLIDER_NOT_PRESSED; + if(ext->action != NULL) res = ext->action(slider); + } else if(sign == LV_SIGNAL_CORD_CHG) { + /* The knob size depends on slider size. + * During the drawing method the ext. size is used by the knob so refresh the ext. size.*/ + if(lv_obj_get_width(slider) != lv_area_get_width(param) || + lv_obj_get_height(slider) != lv_area_get_height(param)) { + slider->signal_func(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL); + } + } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + lv_style_t * style = lv_slider_get_style(slider, LV_SLIDER_STYLE_BG); + lv_style_t * knob_style = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB); + lv_coord_t shadow_w = knob_style->body.shadow.width; + if(ext->knob_in == 0) { + /* The smaller size is the knob diameter*/ + lv_coord_t x = LV_MATH_MIN(w / 2 + 1 + shadow_w, h / 2 + 1 + shadow_w); + if(slider->ext_size < x) slider->ext_size = x; + } else { + lv_coord_t pad = LV_MATH_MIN(style->body.padding.hor, style->body.padding.ver); + if(pad < 0) pad = -pad; + if(slider->ext_size < pad) slider->ext_size = pad; + + if(slider->ext_size < shadow_w) slider->ext_size = shadow_w; + } + } else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char *)param); + + ext->drag_value = LV_SLIDER_NOT_PRESSED; + +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(slider); + bool editing = lv_group_get_editing(g); + lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + /*Encoders need special handling*/ + if(indev_type == LV_INDEV_TYPE_ENCODER && c == LV_GROUP_KEY_ENTER) { + if(editing) lv_group_set_editing(g, false); + } +#endif + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { + lv_slider_set_value(slider, lv_slider_get_value(slider) + 1); + if(ext->action != NULL) res = ext->action(slider); + } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { + lv_slider_set_value(slider, lv_slider_get_value(slider) - 1); + if(ext->action != NULL) res = ext->action(slider); + } + } else if(sign == LV_SIGNAL_GET_EDITABLE) { + bool * editable = (bool *)param; + *editable = true; + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_slider"; + } + + return res; +} +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.h new file mode 100644 index 0000000..6336ae8 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_slider.h @@ -0,0 +1,202 @@ +/** + * @file lv_slider.h + * + */ + +#ifndef LV_SLIDER_H +#define LV_SLIDER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_SLIDER != 0 + +/*Testing of dependencies*/ +#if USE_LV_BAR == 0 +#error "lv_slider: lv_bar is required. Enable it in lv_conf.h (USE_LV_BAR 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_bar.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of slider*/ +typedef struct +{ + lv_bar_ext_t bar; /*Ext. of ancestor*/ + /*New data for this type */ + lv_action_t action; /*Function to call when a new value is set*/ + lv_style_t *style_knob; /*Style of the knob*/ + int16_t drag_value; /*Store a temporal value during press until release (Handled by the library)*/ + uint8_t knob_in :1; /*1: Draw the knob inside the bar*/ +} lv_slider_ext_t; + +/*Built-in styles of slider*/ +enum +{ + LV_SLIDER_STYLE_BG, + LV_SLIDER_STYLE_INDIC, + LV_SLIDER_STYLE_KNOB, +}; +typedef uint8_t lv_slider_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a slider objects + * @param par pointer to an object, it will be the parent of the new slider + * @param copy pointer to a slider object, if not NULL then the new object will be copied from it + * @return pointer to the created slider + */ +lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the slider + * @param slider pointer to a slider object + * @param value new value + */ +static inline void lv_slider_set_value(lv_obj_t * slider, int16_t value) +{ + lv_bar_set_value(slider, value); +} + +/** + * Set a new value with animation on a slider + * @param slider pointer to a slider object + * @param value new value + * @param anim_time animation time in milliseconds + */ +static inline void lv_slider_set_value_anim(lv_obj_t * slider, int16_t value, uint16_t anim_time) +{ + lv_bar_set_value_anim(slider, value, anim_time); +} + +/** + * Set minimum and the maximum values of a bar + * @param slider pointer to the slider object + * @param min minimum value + * @param max maximum value + */ +static inline void lv_slider_set_range(lv_obj_t *slider, int16_t min, int16_t max) +{ + lv_bar_set_range(slider, min, max); +} + +/** + * Set a function which will be called when a new value is set on the slider + * @param slider pointer to slider object + * @param action a callback function + */ +void lv_slider_set_action(lv_obj_t * slider, lv_action_t action); + +/** + * Set the 'knob in' attribute of a slider + * @param slider pointer to slider object + * @param in true: the knob is drawn always in the slider; + * false: the knob can be out on the edges + */ +void lv_slider_set_knob_in(lv_obj_t * slider, bool in); + +/** + * Set a style of a slider + * @param slider pointer to a slider object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_slider_set_style(lv_obj_t *slider, lv_slider_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a slider + * @param slider pointer to a slider object + * @return the value of the slider + */ +int16_t lv_slider_get_value(const lv_obj_t * slider); + +/** + * Get the minimum value of a slider + * @param slider pointer to a slider object + * @return the minimum value of the slider + */ +static inline int16_t lv_slider_get_min_value(const lv_obj_t * slider) +{ + return lv_bar_get_min_value(slider); +} + +/** + * Get the maximum value of a slider + * @param slider pointer to a slider object + * @return the maximum value of the slider + */ +static inline int16_t lv_slider_get_max_value(const lv_obj_t * slider) +{ + return lv_bar_get_max_value(slider); +} + +/** + * Get the slider action function + * @param slider pointer to slider object + * @return the callback function + */ +lv_action_t lv_slider_get_action(const lv_obj_t * slider); + +/** + * Give the slider is being dragged or not + * @param slider pointer to a slider object + * @return true: drag in progress false: not dragged + */ +bool lv_slider_is_dragged(const lv_obj_t * slider); + +/** + * Get the 'knob in' attribute of a slider + * @param slider pointer to slider object + * @return true: the knob is drawn always in the slider; + * false: the knob can be out on the edges + */ +bool lv_slider_get_knob_in(const lv_obj_t * slider); + + +/** + * Get a style of a slider + * @param slider pointer to a slider object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_slider_get_style(const lv_obj_t *slider, lv_slider_style_t type); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_SLIDER*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_SLIDER_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.c new file mode 100644 index 0000000..70fac33 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.c @@ -0,0 +1,471 @@ +/** + * @file lv_spinbox.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_spinbox.h" + +#if USE_LV_SPINBOX != 0 +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param); +static void lv_spinbox_updatevalue(lv_obj_t * spinbox); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a spinbox object + * @param par pointer to an object, it will be the parent of the new spinbox + * @param copy pointer to a spinbox object, if not NULL then the new object will be copied from it + * @return pointer to the created spinbox + */ +lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("spinbox create started"); + + /*Create the ancestor of spinbox*/ + lv_obj_t * new_spinbox = lv_ta_create(par, copy); + lv_mem_assert(new_spinbox); + if(new_spinbox == NULL) return NULL; + + /*Allocate the spinbox type specific extended data*/ + lv_spinbox_ext_t * ext = lv_obj_allocate_ext_attr(new_spinbox, sizeof(lv_spinbox_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_spinbox); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_spinbox); + + /*Initialize the allocated 'ext'*/ + ext->ta.one_line = 1; + ext->ta.pwd_mode = 0; + ext->ta.accapted_chars = "1234567890+-. "; + + ext->value = 0; + ext->dec_point_pos = 0; + ext->digit_count = 5; + ext->digit_padding_left = 0; + ext->step = 1; + ext->range_max = 99999; + ext->range_min = -99999; + ext->value_changed_cb = NULL; + + lv_ta_set_cursor_type(new_spinbox, LV_CURSOR_BLOCK | LV_CURSOR_HIDDEN); /*hidden by default*/ + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_spinbox, lv_spinbox_signal); + lv_obj_set_design_func(new_spinbox, ancestor_design); /*Leave the Text area's design function*/ + + /*Init the new spinbox spinbox*/ + if(copy == NULL) { + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_BG, th->spinbox.bg); + lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_CURSOR, th->spinbox.cursor); + lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_SB, th->spinbox.sb); + } + } + /*Copy an existing spinbox*/ + else { + lv_spinbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + + lv_spinbox_set_value(new_spinbox, copy_ext->value); + lv_spinbox_set_digit_format(new_spinbox, copy_ext->digit_count, copy_ext->dec_point_pos); + lv_spinbox_set_range(new_spinbox, copy_ext->range_min, copy_ext->range_max); + lv_spinbox_set_step(new_spinbox, copy_ext->step); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_spinbox); + } + + lv_spinbox_updatevalue(new_spinbox); + + LV_LOG_INFO("spinbox created"); + + return new_spinbox; +} + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set spinbox value + * @param spinbox pointer to spinbox + * @param i value to be set + */ +void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + if(ext == NULL) + return; + + if(i > ext->range_max) + i = ext->range_max; + if(i < ext->range_min) + i = ext->range_min; + + ext->value = i; + + lv_spinbox_updatevalue(spinbox); +} + +/** + * Set spinbox digit format (digit count and decimal format) + * @param spinbox pointer to spinbox + * @param digit_count number of digit excluding the decimal separator and the sign + * @param separator_position number of digit before the decimal point. If 0, decimal point is not shown + */ +void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + if(ext == NULL) + return; + + if(digit_count > LV_SPINBOX_MAX_DIGIT_COUNT) + digit_count = LV_SPINBOX_MAX_DIGIT_COUNT; + + if(separator_position > LV_SPINBOX_MAX_DIGIT_COUNT) + separator_position = LV_SPINBOX_MAX_DIGIT_COUNT; + + ext->digit_count = digit_count; + ext->dec_point_pos = separator_position; + + lv_spinbox_updatevalue(spinbox); +} + +/** + * Set spinbox step + * @param spinbox pointer to spinbox + * @param step steps on increment/decrement + */ +void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + if(ext == NULL) return; + + ext->step = step; +} + +/** + * Set spinbox value range + * @param spinbox pointer to spinbox + * @param range_min maximum value, inclusive + * @param range_max minimum value, inclusive + */ +void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + if(ext == NULL) return; + + ext->range_max = range_max; + ext->range_min = range_min; + + if(ext->value > ext->range_max) { + ext->value = ext->range_max; + lv_obj_invalidate(spinbox); + } + if(ext->value < ext->range_min) { + ext->value = ext->range_min; + lv_obj_invalidate(spinbox); + } +} + +/** + * Set spinbox callback on calue change + * @param spinbox pointer to spinbox + * @param cb Callback function called on value change event + */ +void lv_spinbox_set_value_changed_cb(lv_obj_t * spinbox, lv_spinbox_value_changed_cb_t cb) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + ext->value_changed_cb = cb; +} + +/** + * Set spinbox left padding in digits count (added between sign and first digit) + * @param spinbox pointer to spinbox + * @param cb Callback function called on value change event + */ +void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + ext->digit_padding_left = padding; + lv_spinbox_updatevalue(spinbox); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the spinbox numeral value (user has to convert to float according to its digit format) + * @param spinbox pointer to spinbox + * @return value integer value of the spinbox + */ +int32_t lv_spinbox_get_value(lv_obj_t * spinbox) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + + return ext->value; +} + +/*===================== + * Other functions + *====================*/ + +/** + * Select next lower digit for edition by dividing the step by 10 + * @param spinbox pointer to spinbox + */ +void lv_spinbox_step_next(lv_obj_t * spinbox) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + + int32_t new_step = ext->step / 10; + if((new_step) > 0) ext->step = new_step; + else ext->step = 1; + + lv_spinbox_updatevalue(spinbox); +} + +/** + * Select next higher digit for edition by multiplying the step by 10 + * @param spinbox pointer to spinbox + */ +void lv_spinbox_step_previous(lv_obj_t * spinbox) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + int32_t step_limit; + step_limit = LV_MATH_MAX(ext->range_max, (ext->range_min < 0 ? (-ext->range_min) : ext->range_min)); + int32_t new_step = ext->step * 10; + if(new_step <= step_limit) ext->step = new_step; + + lv_spinbox_updatevalue(spinbox); +} + +/** + * Increment spinbox value by one step + * @param spinbox pointer to spinbox + */ +void lv_spinbox_increment(lv_obj_t * spinbox) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + + if(ext->value + ext->step <= ext->range_max) { + /*Special mode when zero crossing*/ + if((ext->value + ext->step) > 0 && ext->value < 0) ext->value = -ext->value; + ext->value += ext->step; + + } else { + ext->value = ext->range_max; + } + + if(ext->value_changed_cb != NULL) ext->value_changed_cb(spinbox, ext->value); + lv_spinbox_updatevalue(spinbox); +} + +/** + * Decrement spinbox value by one step + * @param spinbox pointer to spinbox + */ +void lv_spinbox_decrement(lv_obj_t * spinbox) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + + if(ext->value - ext->step >= ext->range_min) { + /*Special mode when zero crossing*/ + if((ext->value - ext->step) < 0 && ext->value > 0) ext->value = -ext->value; + ext->value -= ext->step; + } else { + ext->value = ext->range_min; + } + + if(ext->value_changed_cb != NULL) ext->value_changed_cb(spinbox, ext->value); + lv_spinbox_updatevalue(spinbox); +} + + + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the spinbox + * @param spinbox pointer to a spinbox object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param) +{ + + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + + lv_res_t res = LV_RES_OK; + + /* Include the ancient signal function */ + if(sign != LV_SIGNAL_CONTROLL) + { + res = ancestor_signal(spinbox, sign, param); + if(res != LV_RES_OK) return res; + } + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_GET_TYPE) + { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) + { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_spinbox"; + } + else if(sign == LV_SIGNAL_CONTROLL) { + lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + + uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/ + if(c == LV_GROUP_KEY_RIGHT) { + if(indev_type == LV_INDEV_TYPE_ENCODER) lv_spinbox_increment(spinbox); + else lv_spinbox_step_next(spinbox); + } + else if(c == LV_GROUP_KEY_LEFT) { + if(indev_type == LV_INDEV_TYPE_ENCODER) lv_spinbox_decrement(spinbox); + else lv_spinbox_step_previous(spinbox); + } + else if(c == LV_GROUP_KEY_UP) { + lv_spinbox_increment(spinbox); + } + else if(c == LV_GROUP_KEY_DOWN) { + lv_spinbox_decrement(spinbox); + } + else if(c == LV_GROUP_KEY_ENTER) { + + if(ext->step > 1) { + lv_spinbox_step_next(spinbox); + } else { + /*Restart from the MSB*/ + ext->step = 1; + uint32_t i; + for(i = 0; i < ext->digit_count; i++) { + int32_t new_step = ext->step * 10; + if(new_step >= ext->range_max) break; + ext->step = new_step; + } + lv_spinbox_step_previous(spinbox); + } + } + else { + lv_ta_add_char(spinbox, c); + } + } + + return res; +} + +static void lv_spinbox_updatevalue(lv_obj_t * spinbox) +{ + lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + + char buf[LV_SPINBOX_MAX_DIGIT_COUNT + 8]; + memset(buf, 0, sizeof(buf)); + char * buf_p = buf; + + /*Add the sign*/ + (*buf_p) = ext->value >= 0 ? '+' : '-'; + buf_p++; + + int i; + /*padding left*/ + for(i = 0; i < ext->digit_padding_left; i++) { + (*buf_p) = ' '; + buf_p++; + } + + char digits[64]; + /*Convert the numbers to string (the sign is already handled so always covert positive number)*/ + lv_math_num_to_str(ext->value < 0 ? -ext->value : ext->value, digits); + + /*Add leading zeros*/ + int lz_cnt = ext->digit_count - (int)strlen(digits); + if(lz_cnt > 0) { + for(i = strlen(digits); i >= 0; i--) { + digits[i + lz_cnt] = digits[i]; + } + for(i = 0; i < lz_cnt; i++) { + digits[i] = '0'; + } + } + + int32_t intDigits; + intDigits = (ext->dec_point_pos == 0) ? ext->digit_count : ext->dec_point_pos; + + /*Add the decimal part*/ + for(i = 0; i < intDigits && digits[i] != '\0'; i++) { + (*buf_p) = digits[i]; + buf_p++; + } + + if(ext->dec_point_pos != 0) { + /*Insert the decimal point*/ + (*buf_p) = '.'; + buf_p++; + + for(/*Leave i*/ ;i < ext->digit_count && digits[i] != '\0'; i++) { + (*buf_p) = digits[i]; + buf_p++; + } + } + + /*Refresh the text*/ + lv_ta_set_text(spinbox, (char*)buf); + + + /*Set the cursor position*/ + int32_t step = ext->step; + uint8_t cur_pos = ext->digit_count; + while(step >= 10) + { + step /= 10; + cur_pos--; + } + + if(cur_pos > intDigits ) cur_pos ++; /*Skip teh decimal point*/ + + cur_pos += ext->digit_padding_left; + + lv_ta_set_cursor_pos(spinbox, cur_pos); +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.h new file mode 100644 index 0000000..ca57614 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_spinbox.h @@ -0,0 +1,201 @@ +/** + * @file lv_spinbox.h + * + */ + + +#ifndef LV_SPINBOX_H +#define LV_SPINBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_SPINBOX != 0 + +/*Testing of dependencies*/ +#if USE_LV_TA == 0 +#error "lv_spinbox: lv_ta is required. Enable it in lv_conf.h (USE_LV_TA 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "../lv_objx/lv_ta.h" + +/********************* + * DEFINES + *********************/ +#define LV_SPINBOX_MAX_DIGIT_COUNT 16 + +/********************** + * TYPEDEFS + **********************/ + +/*callback on value change*/ +typedef void (*lv_spinbox_value_changed_cb_t)(lv_obj_t * spinbox, int32_t new_value); + +/*Data of spinbox*/ +typedef struct { + lv_ta_ext_t ta; /*Ext. of ancestor*/ + /*New data for this type */ + int32_t value; + int32_t range_max; + int32_t range_min; + int32_t step; + uint16_t digit_count:4; + uint16_t dec_point_pos:4; /*if 0, there is no separator and the number is an integer*/ + uint16_t digit_padding_left:4; + lv_spinbox_value_changed_cb_t value_changed_cb; +} lv_spinbox_ext_t; + + +/*Styles*/ +enum { + LV_SPINBOX_STYLE_BG, + LV_SPINBOX_STYLE_SB, + LV_SPINBOX_STYLE_CURSOR, +}; +typedef uint8_t lv_spinbox_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a spinbox objects + * @param par pointer to an object, it will be the parent of the new spinbox + * @param copy pointer to a spinbox object, if not NULL then the new object will be copied from it + * @return pointer to the created spinbox + */ +lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a style of a spinbox. + * @param templ pointer to template object + * @param type which style should be set + * @param style pointer to a style + */ +static inline void lv_spinbox_set_style(lv_obj_t * spinbox, lv_spinbox_style_t type, lv_style_t *style) +{ + lv_ta_set_style(spinbox, type, style); +} + +/** + * Set spinbox value + * @param spinbox pointer to spinbox + * @param i value to be set + */ +void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i); + +/** + * Set spinbox digit format (digit count and decimal format) + * @param spinbox pointer to spinbox + * @param digit_count number of digit excluding the decimal separator and the sign + * @param separator_position number of digit before the decimal point. If 0, decimal point is not shown + */ +void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position); + +/** + * Set spinbox step + * @param spinbox pointer to spinbox + * @param step steps on increment/decrement + */ +void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step); + +/** + * Set spinbox value range + * @param spinbox pointer to spinbox + * @param range_min maximum value, inclusive + * @param range_max minimum value, inclusive + */ +void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max); + +/** + * Set spinbox callback on calue change + * @param spinbox pointer to spinbox + * @param cb Callback function called on value change event + */ +void lv_spinbox_set_value_changed_cb(lv_obj_t * spinbox, lv_spinbox_value_changed_cb_t cb); + +/** + * Set spinbox left padding in digits count (added between sign and first digit) + * @param spinbox pointer to spinbox + * @param cb Callback function called on value change event + */ +void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get style of a spinbox. + * @param templ pointer to template object + * @param type which style should be get + * @return style pointer to the style + */ +static inline lv_style_t * lv_spinbox_get_style(lv_obj_t * spinbox, lv_spinbox_style_t type) +{ + return lv_ta_get_style(spinbox, type); +} + +/** + * Get the spinbox numeral value (user has to convert to float according to its digit format) + * @param spinbox pointer to spinbox + * @return value integer value of the spinbox + */ +int32_t lv_spinbox_get_value(lv_obj_t * spinbox); + +/*===================== + * Other functions + *====================*/ + +/** + * Select next lower digit for edition by dividing the step by 10 + * @param spinbox pointer to spinbox + */ +void lv_spinbox_step_next(lv_obj_t * spinbox); + +/** + * Select next higher digit for edition by multiplying the step by 10 + * @param spinbox pointer to spinbox + */ +void lv_spinbox_step_previous(lv_obj_t * spinbox); + +/** + * Increment spinbox value by one step + * @param spinbox pointer to spinbox + */ +void lv_spinbox_increment(lv_obj_t * spinbox); + +/** + * Decrement spinbox value by one step + * @param spinbox pointer to spinbox + */ +void lv_spinbox_decrement(lv_obj_t * spinbox); + + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_SPINBOX*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_SPINBOX_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.c new file mode 100644 index 0000000..2b09354 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.c @@ -0,0 +1,445 @@ +/** + * @file lv_sw.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_sw.h" + +#if USE_LV_SW != 0 + +/*Testing of dependencies*/ +#if USE_LV_SLIDER == 0 +#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1) " +#endif + +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param); +static void lv_sw_anim_to_value(lv_obj_t * sw, int16_t value); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a switch objects + * @param par pointer to an object, it will be the parent of the new switch + * @param copy pointer to a switch object, if not NULL then the new object will be copied from it + * @return pointer to the created switch + */ +lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("switch create started"); + + /*Create the ancestor of switch*/ + lv_obj_t * new_sw = lv_slider_create(par, copy); + lv_mem_assert(new_sw); + if(new_sw == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_sw); + + /*Allocate the switch type specific extended data*/ + lv_sw_ext_t * ext = lv_obj_allocate_ext_attr(new_sw, sizeof(lv_sw_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + /*Initialize the allocated 'ext' */ + ext->changed = 0; +#if USE_LV_ANIMATION + ext->anim_time = 0; +#endif + ext->style_knob_off = ext->slider.style_knob; + ext->style_knob_on = ext->slider.style_knob; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_sw, lv_sw_signal); + + /*Init the new switch switch*/ + if(copy == NULL) { + lv_slider_set_range(new_sw, 0, 1); + lv_obj_set_size(new_sw, 2 * LV_DPI / 3, LV_DPI / 3); + lv_slider_set_knob_in(new_sw, true); + lv_slider_set_range(new_sw, 0, LV_SWITCH_SLIDER_ANIM_MAX); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_sw_set_style(new_sw, LV_SW_STYLE_BG, th->sw.bg); + lv_sw_set_style(new_sw, LV_SW_STYLE_INDIC, th->sw.indic); + lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_OFF, th->sw.knob_off); + lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_ON, th->sw.knob_on); + } else { + /*Let the slider' style*/ + } + + } + /*Copy an existing switch*/ + else { + lv_sw_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->style_knob_off = copy_ext->style_knob_off; + ext->style_knob_on = copy_ext->style_knob_on; +#if USE_LV_ANIMATION + ext->anim_time = copy_ext->anim_time; +#endif + + if(lv_sw_get_state(new_sw)) lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on); + else lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off); + + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_sw); + } + + LV_LOG_INFO("switch created"); + + return new_sw; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Turn ON the switch + * @param sw pointer to a switch object + */ +void lv_sw_on(lv_obj_t * sw) +{ + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + lv_slider_set_value(sw, LV_SWITCH_SLIDER_ANIM_MAX); + + lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on); +} + +/** + * Turn OFF the switch + * @param sw pointer to a switch object + */ +void lv_sw_off(lv_obj_t * sw) +{ + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + lv_slider_set_value(sw, 0); + + lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off); +} + +/** + * Toggle the position of the switch + * @param sw pointer to a switch object + * @return resulting state of the switch. + */ +bool lv_sw_toggle(lv_obj_t *sw) { + bool state = lv_sw_get_state(sw); + if(state) { + lv_sw_off(sw); + } + else { + lv_sw_on(sw); + } + return !state; +} + +/** + * Turn ON the switch with an animation + * @param sw pointer to a switch object + */ +void lv_sw_on_anim(lv_obj_t * sw) +{ + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + if(lv_sw_get_anim_time(sw) > 0)lv_sw_anim_to_value(sw, LV_SWITCH_SLIDER_ANIM_MAX); + else lv_slider_set_value(sw, LV_SWITCH_SLIDER_ANIM_MAX); + + lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on); +} + +/** + * Turn OFF the switch with an animation + * @param sw pointer to a switch object + */ +void lv_sw_off_anim(lv_obj_t * sw) +{ + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + if(lv_sw_get_anim_time(sw) > 0) lv_sw_anim_to_value(sw, 0); + else lv_slider_set_value(sw, 0); + + lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off); +} + +/** + * Toggle the position of the switch with an animation + * @param sw pointer to a switch object + * @return resulting state of the switch. + */ +bool lv_sw_toggle_anim(lv_obj_t *sw) { + bool state = lv_sw_get_state(sw); + if(state) { + lv_sw_off_anim(sw); + } + else { + lv_sw_on_anim(sw); + } + return !state; +} + +/** + * Set a style of a switch + * @param sw pointer to a switch object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_sw_set_style(lv_obj_t * sw, lv_sw_style_t type, lv_style_t * style) +{ + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + + switch(type) { + case LV_SLIDER_STYLE_BG: + lv_slider_set_style(sw, LV_SLIDER_STYLE_BG, style); + break; + case LV_SLIDER_STYLE_INDIC: + lv_bar_set_style(sw, LV_SLIDER_STYLE_INDIC, style); + break; + case LV_SW_STYLE_KNOB_OFF: + ext->style_knob_off = style; + if(lv_sw_get_state(sw) == 0) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, style); + break; + case LV_SW_STYLE_KNOB_ON: + ext->style_knob_on = style; + if(lv_sw_get_state(sw) != 0) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, style); + break; + } +} + +void lv_sw_set_anim_time(lv_obj_t *sw, uint16_t anim_time) +{ +#if USE_LV_ANIMATION + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + ext->anim_time = anim_time; +#endif +} + + +/*===================== + * Getter functions + *====================*/ + +/** + * Get a style of a switch + * @param sw pointer to a switch object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_sw_get_style(const lv_obj_t * sw, lv_sw_style_t type) +{ + lv_style_t * style = NULL; + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + + switch(type) { + case LV_SW_STYLE_BG: + style = lv_slider_get_style(sw, LV_SLIDER_STYLE_BG); + break; + case LV_SW_STYLE_INDIC: + style = lv_slider_get_style(sw, LV_SLIDER_STYLE_INDIC); + break; + case LV_SW_STYLE_KNOB_OFF: + style = ext->style_knob_off; + break; + case LV_SW_STYLE_KNOB_ON: + style = ext->style_knob_on; + break; + default: + style = NULL; + break; + } + + return style; +} + +uint16_t lv_sw_get_anim_time(const lv_obj_t *sw) +{ + +#if USE_LV_ANIMATION + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + return ext->anim_time; +#else + return 0; +#endif +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the switch + * @param sw pointer to a switch object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) +{ + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + + /*Save the current (old) value before slider signal modifies it*/ + int16_t old_val; + + if(sign == LV_SIGNAL_PRESSING) old_val = ext->slider.drag_value; + else old_val = lv_slider_get_value(sw); + + /*Do not let the slider to call the callback. The Switch will do it if required*/ + lv_action_t slider_action = ext->slider.action; + ext->slider.action = NULL; + + lv_res_t res; + /* Include the ancient signal function */ + res = ancestor_signal(sw, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } + else if(sign == LV_SIGNAL_PRESSED) { + + /*Save the x coordinate of the pressed point to see if the switch was slid*/ + lv_indev_t * indev = lv_indev_get_act(); + if(indev) { + lv_point_t p; + lv_indev_get_point(indev, &p); + ext->start_x = p.x; + } + ext->slided = 0; + ext->changed = 0; + } + else if(sign == LV_SIGNAL_PRESSING) { + /*See if the switch was slid*/ + lv_indev_t * indev = lv_indev_get_act(); + if(indev) { + lv_point_t p = {0,0}; + lv_indev_get_point(indev, &p); + if(LV_MATH_ABS(p.x - ext->start_x) > LV_INDEV_DRAG_LIMIT) ext->slided = 1; + } + + /*If didn't slide then revert the min/max value. So click without slide won't move the switch as a slider*/ + if(ext->slided == 0) { + if(lv_sw_get_state(sw)) ext->slider.drag_value = LV_SWITCH_SLIDER_ANIM_MAX; + else ext->slider.drag_value = 0; + } + + /*If explicitly changed (by slide) don't need to be toggled on release*/ + int16_t threshold = LV_SWITCH_SLIDER_ANIM_MAX / 2; + if((old_val < threshold && ext->slider.drag_value > threshold) || + (old_val > threshold && ext->slider.drag_value < threshold)) + { + ext->changed = 1; + } + } + else if(sign == LV_SIGNAL_PRESS_LOST) { + if(lv_sw_get_state(sw)) { + lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on); +#if USE_LV_ANIMATION + lv_sw_anim_to_value(sw, LV_SWITCH_SLIDER_ANIM_MAX); +#endif + } + else { + lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off); +#if USE_LV_ANIMATION + lv_sw_anim_to_value(sw, 0); +#endif + } + } + else if(sign == LV_SIGNAL_RELEASED) { + /*If not dragged then toggle the switch*/ + if(ext->changed == 0) { + if(lv_sw_get_state(sw)) lv_sw_off_anim(sw); + else lv_sw_on_anim(sw); + + if(slider_action != NULL) res = slider_action(sw); + } + /*If the switch was dragged then calculate the new state based on the current position*/ + else { + int16_t v = lv_slider_get_value(sw); + if(v > LV_SWITCH_SLIDER_ANIM_MAX / 2) lv_sw_on_anim(sw); + else lv_sw_off_anim(sw); + + if(slider_action != NULL) res = slider_action(sw); + } + + } else if(sign == LV_SIGNAL_CONTROLL) { + + char c = *((char *)param); + if(c == LV_GROUP_KEY_ENTER) { + if(old_val) lv_sw_off_anim(sw); + else lv_sw_on_anim(sw); + + if(slider_action) res = slider_action(sw); + } else if(c == LV_GROUP_KEY_UP || c == LV_GROUP_KEY_RIGHT) { + lv_sw_on_anim(sw); + if(slider_action) res = slider_action(sw); + } else if(c == LV_GROUP_KEY_DOWN || c == LV_GROUP_KEY_LEFT) { + lv_sw_off_anim(sw); + if(slider_action) res = slider_action(sw); + } + } else if(sign == LV_SIGNAL_GET_EDITABLE) { + bool * editable = (bool *)param; + *editable = false; /*The ancestor slider is editable the switch is not*/ + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_sw"; + } + + /*Restore the callback*/ + if(res == LV_RES_OK) ext->slider.action = slider_action; + + return res; +} + +static void lv_sw_anim_to_value(lv_obj_t * sw, int16_t value) +{ +#if USE_LV_ANIMATION + lv_anim_t a; + lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); + a.var = sw; + a.start = ext->slider.bar.cur_value; + a.end = value; + a.fp = (lv_anim_fp_t)lv_slider_set_value; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = lv_sw_get_anim_time(sw); + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#endif +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.h new file mode 100644 index 0000000..28b22f7 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_sw.h @@ -0,0 +1,194 @@ +/** + * @file lv_sw.h + * + */ + +#ifndef LV_SW_H +#define LV_SW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_SW != 0 + +/*Testing of dependencies*/ +#if USE_LV_SLIDER == 0 +#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1)" +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_slider.h" + +/********************* + * DEFINES + *********************/ +#define LV_SWITCH_SLIDER_ANIM_MAX 1000 + +/********************** + * TYPEDEFS + **********************/ +/*Data of switch*/ +typedef struct +{ + lv_slider_ext_t slider; /*Ext. of ancestor*/ + /*New data for this type */ + lv_style_t *style_knob_off; /*Style of the knob when the switch is OFF*/ + lv_style_t *style_knob_on; /*Style of the knob when the switch is ON (NULL to use the same as OFF)*/ + lv_coord_t start_x; + uint8_t changed :1; /*Indicates the switch state explicitly changed by drag*/ + uint8_t slided :1; +#if USE_LV_ANIMATION + uint16_t anim_time; /*switch animation time */ +#endif +} lv_sw_ext_t; + +enum { + LV_SW_STYLE_BG, + LV_SW_STYLE_INDIC, + LV_SW_STYLE_KNOB_OFF, + LV_SW_STYLE_KNOB_ON, +}; +typedef uint8_t lv_sw_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a switch objects + * @param par pointer to an object, it will be the parent of the new switch + * @param copy pointer to a switch object, if not NULL then the new object will be copied from it + * @return pointer to the created switch + */ +lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Turn ON the switch + * @param sw pointer to a switch object + */ +void lv_sw_on(lv_obj_t *sw); + +/** + * Turn OFF the switch + * @param sw pointer to a switch object + */ +void lv_sw_off(lv_obj_t *sw); + +/** + * Toggle the position of the switch + * @param sw pointer to a switch object + * @return resulting state of the switch. + */ +bool lv_sw_toggle(lv_obj_t *sw); + +/** + * Turn ON the switch with an animation + * @param sw pointer to a switch object + */ +void lv_sw_on_anim(lv_obj_t * sw); + +/** + * Turn OFF the switch with an animation + * @param sw pointer to a switch object + */ +void lv_sw_off_anim(lv_obj_t * sw); + +/** + * Toggle the position of the switch with an animation + * @param sw pointer to a switch object + * @return resulting state of the switch. + */ +bool lv_sw_toggle_anim(lv_obj_t *sw); + +/** + * Set a function which will be called when the switch is toggled by the user + * @param sw pointer to switch object + * @param action a callback function + */ +static inline void lv_sw_set_action(lv_obj_t * sw, lv_action_t action) +{ + lv_slider_set_action(sw, action); +} + +/** + * Set a style of a switch + * @param sw pointer to a switch object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style); + +#if USE_LV_ANIMATION +/** + * Set the animation time of the switch + * @param sw pointer to a switch object + * @param anim_time animation time + * @return style pointer to a style + */ +void lv_sw_set_anim_time(lv_obj_t *sw, uint16_t anim_time); +#endif + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the state of a switch + * @param sw pointer to a switch object + * @return false: OFF; true: ON + */ +static inline bool lv_sw_get_state(const lv_obj_t *sw) +{ + return lv_bar_get_value(sw) < LV_SWITCH_SLIDER_ANIM_MAX / 2 ? false : true; +} + +/** + * Get the switch action function + * @param slider pointer to a switch object + * @return the callback function + */ +static inline lv_action_t lv_sw_get_action(const lv_obj_t * slider) +{ + return lv_slider_get_action(slider); +} + +/** + * Get a style of a switch + * @param sw pointer to a switch object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_sw_get_style(const lv_obj_t *sw, lv_sw_style_t type); + +/** + * Get the animation time of the switch + * @param sw pointer to a switch object + * @return style pointer to a style + */ +uint16_t lv_sw_get_anim_time(const lv_obj_t *sw); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_SW*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_SW_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.c new file mode 100644 index 0000000..e3492a0 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.c @@ -0,0 +1,1365 @@ +/** + * @file lv_ta.c + * + */ + + +/********************* + * INCLUDES + *********************/ +#include "lv_ta.h" +#if USE_LV_TA != 0 + +#include "../lv_core/lv_group.h" +#include "../lv_core/lv_refr.h" +#include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_anim.h" +#include "../lv_misc/lv_txt.h" +#include "../lv_misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +/*Test configuration*/ + +#ifndef LV_TA_CURSOR_BLINK_TIME +#define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/ +#endif + +#ifndef LV_TA_PWD_SHOW_TIME +#define LV_TA_PWD_SHOW_TIME 1500 /*ms*/ +#endif + +#define LV_TA_DEF_WIDTH (2 * LV_DPI) +#define LV_TA_DEF_HEIGHT (1 * LV_DPI) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_ta_design(lv_obj_t * ta, const lv_area_t * mask, lv_design_mode_t mode); +static bool lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param); +static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); +#if USE_LV_ANIMATION +static void cursor_blink_anim(lv_obj_t * ta, uint8_t show); +static void pwd_char_hider_anim(lv_obj_t * ta, int32_t x); +#endif +static void pwd_char_hider(lv_obj_t * ta); +static bool char_is_accepted(lv_obj_t * ta, uint32_t c); +static void get_cursor_style(lv_obj_t * ta, lv_style_t * style_res); +static void refr_cursor_area(lv_obj_t * ta); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_design_func_t ancestor_design; +static lv_design_func_t scrl_design; +static lv_signal_func_t ancestor_signal; +static lv_signal_func_t scrl_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a text area objects + * @param par pointer to an object, it will be the parent of the new text area + * @param copy pointer to a text area object, if not NULL then the new object will be copied from it + * @return pointer to the created text area + */ +lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("text area create started"); + + /*Create the ancestor object*/ + lv_obj_t * new_ta = lv_page_create(par, copy); + lv_mem_assert(new_ta); + if(new_ta == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_ta); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_ta); + if(scrl_signal == NULL) scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_ta)); + if(scrl_design == NULL) scrl_design = lv_obj_get_design_func(lv_page_get_scrl(new_ta)); + + /*Allocate the object type specific extended data*/ + lv_ta_ext_t * ext = lv_obj_allocate_ext_attr(new_ta, sizeof(lv_ta_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->cursor.state = 1; + ext->pwd_mode = 0; + ext->pwd_tmp = NULL; + ext->accapted_chars = NULL; + ext->max_length = 0; + ext->cursor.style = NULL; + ext->cursor.pos = 0; + ext->cursor.type = LV_CURSOR_LINE; + ext->cursor.valid_x = 0; + ext->one_line = 0; + ext->label = NULL; + + lv_obj_set_signal_func(new_ta, lv_ta_signal); + lv_obj_set_signal_func(lv_page_get_scrl(new_ta), lv_ta_scrollable_signal); + lv_obj_set_design_func(new_ta, lv_ta_design); + + /*Init the new text area object*/ + if(copy == NULL) { + ext->label = lv_label_create(new_ta, NULL); + + lv_obj_set_design_func(ext->page.scrl, lv_ta_scrollable_design); + + lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK); + lv_label_set_text(ext->label, "Text area"); + lv_obj_set_click(ext->label, false); + lv_obj_set_size(new_ta, LV_TA_DEF_WIDTH, LV_TA_DEF_HEIGHT); + lv_ta_set_sb_mode(new_ta, LV_SB_MODE_DRAG); + lv_page_set_style(new_ta, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_ta_set_style(new_ta, LV_TA_STYLE_BG, th->ta.area); + lv_ta_set_style(new_ta, LV_TA_STYLE_SB, th->ta.sb); + } else { + lv_ta_set_style(new_ta, LV_TA_STYLE_BG, &lv_style_pretty); + } + } + /*Copy an existing object*/ + else { + lv_obj_set_design_func(ext->page.scrl, lv_ta_scrollable_design); + lv_ta_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->label = lv_label_create(new_ta, copy_ext->label); + ext->pwd_mode = copy_ext->pwd_mode; + ext->accapted_chars = copy_ext->accapted_chars; + ext->max_length = copy_ext->max_length; + ext->cursor.style = copy_ext->cursor.style; + ext->cursor.pos = copy_ext->cursor.pos; + ext->cursor.valid_x = copy_ext->cursor.valid_x; + ext->cursor.type = copy_ext->cursor.type; + if(copy_ext->one_line) lv_ta_set_one_line(new_ta, true); + + lv_ta_set_style(new_ta, LV_TA_STYLE_CURSOR, lv_ta_get_style(copy, LV_TA_STYLE_CURSOR)); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_ta); + } + +#if USE_LV_ANIMATION + /*Create a cursor blinker animation*/ + lv_anim_t a; + a.var = new_ta; + a.fp = (lv_anim_fp_t)cursor_blink_anim; + a.time = LV_TA_CURSOR_BLINK_TIME; + a.act_time = 0; + a.end_cb = NULL; + a.start = 1; + a.end = 0; + a.repeat = 1; + a.repeat_pause = 0; + a.playback = 1; + a.playback_pause = 0; + a.path = lv_anim_path_step; + lv_anim_create(&a); +#endif + + LV_LOG_INFO("text area created"); + + return new_ta; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Insert a character to the current cursor position. + * To add a wide char, e.g. 'Á' use `lv_txt_encoded_conv_wc('Á')` + * @param ta pointer to a text area object + * @param c a character (e.g. 'a') + */ +void lv_ta_add_char(lv_obj_t * ta, uint32_t c) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + if(ext->one_line && (c == '\n' || c == '\r')) { + LV_LOG_INFO("Text area: line break ignored in one-line mode"); + return; + } + + uint32_t c_uni = lv_txt_encoded_next((const char *)&c, NULL); + + if(char_is_accepted(ta, c_uni) == false) { + LV_LOG_INFO("Character is no accepted by the text area (too long text or not in the accepted list)"); + return; + } + + /*Disable edge flash. If a new line was added it could show edge flash effect*/ + bool edge_flash_en = lv_ta_get_edge_flash(ta); + lv_ta_set_edge_flash(ta, false); + + if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/ + uint32_t letter_buf[2]; + letter_buf[0] = c; + letter_buf[1] = '\0'; + + lv_label_ins_text(ext->label, ext->cursor.pos, (const char *)letter_buf); /*Insert the character*/ + + if(ext->pwd_mode != 0) { + + ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 2); /*+2: the new char + \0 */ + lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp == NULL) return; + + lv_txt_ins(ext->pwd_tmp, ext->cursor.pos, (const char *)letter_buf); + +#if USE_LV_ANIMATION && LV_TA_PWD_SHOW_TIME > 0 + /*Auto hide characters*/ + lv_anim_t a; + a.var = ta; + a.fp = (lv_anim_fp_t)pwd_char_hider_anim; + a.time = LV_TA_PWD_SHOW_TIME; + a.act_time = 0; + a.end_cb = (lv_anim_cb_t)pwd_char_hider; + a.start = 0; + a.end = 1; + a.repeat = 0; + a.repeat_pause = 0; + a.playback = 0; + a.playback_pause = 0; + a.path = lv_anim_path_step; + lv_anim_create(&a); +#else + pwd_char_hider(ta); +#endif + } + + /*Move the cursor after the new character*/ + lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + 1); + + /*Revert the original edge flash state*/ + lv_ta_set_edge_flash(ta, edge_flash_en); +} + +/** + * Insert a text to the current cursor position + * @param ta pointer to a text area object + * @param txt a '\0' terminated string to insert + */ +void lv_ta_add_text(lv_obj_t * ta, const char * txt) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/ + + /*Add the character one-by-one if not all characters are accepted or there is character limit.*/ + if(lv_ta_get_accepted_chars(ta) || lv_ta_get_max_length(ta)) { + uint32_t i = 0; + while(txt[i] != '\0') { + uint32_t c = lv_txt_encoded_next(txt, &i); + lv_ta_add_char(ta, lv_txt_unicode_to_encoded(c)); + } + return; + } + + /*Disable edge flash. If a new line was added it could show edge flash effect*/ + bool edge_flash_en = lv_ta_get_edge_flash(ta); + lv_ta_set_edge_flash(ta, false); + + /*Insert the text*/ + lv_label_ins_text(ext->label, ext->cursor.pos, txt); + + if(ext->pwd_mode != 0) { + ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + strlen(txt) + 1); + lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp == NULL) return; + + lv_txt_ins(ext->pwd_tmp, ext->cursor.pos, txt); + +#if USE_LV_ANIMATION && LV_TA_PWD_SHOW_TIME > 0 + /*Auto hide characters*/ + lv_anim_t a; + a.var = ta; + a.fp = (lv_anim_fp_t)pwd_char_hider_anim; + a.time = LV_TA_PWD_SHOW_TIME; + a.act_time = 0; + a.end_cb = (lv_anim_cb_t)pwd_char_hider; + a.start = 0; + a.end = 1; + a.repeat = 0; + a.repeat_pause = 0; + a.playback = 0; + a.playback_pause = 0; + a.path = lv_anim_path_step; + lv_anim_create(&a); +#else + pwd_char_hider(ta); +#endif + } + + /*Move the cursor after the new text*/ + lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + lv_txt_get_encoded_length(txt)); + + /*Revert the original edge flash state*/ + lv_ta_set_edge_flash(ta, edge_flash_en); +} + +/** + * Delete a the left character from the current cursor position + * @param ta pointer to a text area object + */ +void lv_ta_del_char(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + uint16_t cur_pos = ext->cursor.pos; + + if(cur_pos == 0) return; + + char * label_txt = lv_label_get_text(ext->label); + /*Delete a character*/ + lv_txt_cut(label_txt, ext->cursor.pos - 1, 1); + /*Refresh the label*/ + lv_label_set_text(ext->label, label_txt); + + /*Don't let 'width == 0' because cursor will not be visible*/ + if(lv_obj_get_width(ext->label) == 0) { + lv_style_t * style = lv_obj_get_style(ext->label); + lv_obj_set_width(ext->label, style->line.width); + } + + if(ext->pwd_mode != 0) { +#if LV_TXT_UTF8 == 0 + lv_txt_cut(ext->pwd_tmp, ext->cursor.pos - 1, 1); +#else + uint32_t byte_pos = lv_txt_encoded_get_byte_id(ext->pwd_tmp, ext->cursor.pos - 1); + lv_txt_cut(ext->pwd_tmp, ext->cursor.pos - 1, lv_txt_encoded_size(&label_txt[byte_pos])); +#endif + ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 1); + lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp == NULL) return; + } + + /*Move the cursor to the place of the deleted character*/ + lv_ta_set_cursor_pos(ta, ext->cursor.pos - 1); +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of a text area + * @param ta pointer to a text area + * @param txt pointer to the text + */ +void lv_ta_set_text(lv_obj_t * ta, const char * txt) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + /*Add the character one-by-one if not all characters are accepted or there is character limit.*/ + if(lv_ta_get_accepted_chars(ta) || lv_ta_get_max_length(ta)) { + lv_label_set_text(ext->label, ""); + lv_ta_set_cursor_pos(ta, LV_TA_CURSOR_LAST); + + uint32_t i = 0; + while(txt[i] != '\0') { + uint32_t c = lv_txt_encoded_next(txt, &i); + lv_ta_add_char(ta, lv_txt_unicode_to_encoded(c)); + } + } else { + lv_label_set_text(ext->label, txt); + lv_ta_set_cursor_pos(ta, LV_TA_CURSOR_LAST); + } + + /*Don't let 'width == 0' because the cursor will not be visible*/ + if(lv_obj_get_width(ext->label) == 0) { + lv_style_t * style = lv_obj_get_style(ext->label); + lv_obj_set_width(ext->label, lv_font_get_width(style->text.font, ' ')); + } + + if(ext->pwd_mode != 0) { + ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(txt) + 1); + lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp == NULL) return; + strcpy(ext->pwd_tmp, txt); + +#if USE_LV_ANIMATION && LV_TA_PWD_SHOW_TIME > 0 + /*Auto hide characters*/ + lv_anim_t a; + a.var = ta; + a.fp = (lv_anim_fp_t)pwd_char_hider_anim; + a.time = LV_TA_PWD_SHOW_TIME; + a.act_time = 0; + a.end_cb = (lv_anim_cb_t)pwd_char_hider; + a.start = 0; + a.end = 1; + a.repeat = 0; + a.repeat_pause = 0; + a.playback = 0; + a.playback_pause = 0; + a.path = lv_anim_path_step; + lv_anim_create(&a); +#else + pwd_char_hider(ta); +#endif + } +} + +/** + * Set the cursor position + * @param obj pointer to a text area object + * @param pos the new cursor position in character index + * < 0 : index from the end of the text + * LV_TA_CURSOR_LAST: go after the last character + */ +void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + if(ext->cursor.pos == pos) return; + + uint16_t len = lv_txt_get_encoded_length(lv_label_get_text(ext->label)); + + if(pos < 0) pos = len + pos; + + if(pos > len || pos == LV_TA_CURSOR_LAST) pos = len; + + ext->cursor.pos = pos; + + /*Position the label to make the cursor visible*/ + lv_obj_t * label_par = lv_obj_get_parent(ext->label); + lv_point_t cur_pos; + lv_style_t * style = lv_obj_get_style(ta); + const lv_font_t * font_p = style->text.font; + lv_area_t label_cords; + lv_area_t ta_cords; + lv_label_get_letter_pos(ext->label, pos, &cur_pos); + lv_obj_get_coords(ta, &ta_cords); + lv_obj_get_coords(ext->label, &label_cords); + + /*Check the top*/ + lv_coord_t font_h = lv_font_get_height(font_p); + if(lv_obj_get_y(label_par) + cur_pos.y < 0) { + lv_obj_set_y(label_par, - cur_pos.y + style->body.padding.ver); + } + + /*Check the bottom*/ + if(label_cords.y1 + cur_pos.y + font_h + style->body.padding.ver > ta_cords.y2) { + lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) + + font_h + 2 * style->body.padding.ver)); + } + /*Check the left (use the font_h as general unit)*/ + if(lv_obj_get_x(label_par) + cur_pos.x < font_h) { + lv_obj_set_x(label_par, - cur_pos.x + font_h); + } + + /*Check the right (use the font_h as general unit)*/ + if(label_cords.x1 + cur_pos.x + font_h + style->body.padding.hor > ta_cords.x2) { + lv_obj_set_x(label_par, -(cur_pos.x - lv_obj_get_width(ta) + + font_h + 2 * style->body.padding.hor)); + } + + ext->cursor.valid_x = cur_pos.x; + +#if USE_LV_ANIMATION + /*Reset cursor blink animation*/ + lv_anim_t a; + a.var = ta; + a.fp = (lv_anim_fp_t)cursor_blink_anim; + a.time = LV_TA_CURSOR_BLINK_TIME; + a.act_time = 0; + a.end_cb = NULL; + a.start = 1; + a.end = 0; + a.repeat = 1; + a.repeat_pause = 0; + a.playback = 1; + a.playback_pause = 0; + a.path = lv_anim_path_step; + lv_anim_create(&a); +#endif + + refr_cursor_area(ta); +} + +/** + * Set the cursor type. + * @param ta pointer to a text area object + * @param cur_type: element of 'lv_ta_cursor_type_t' + */ +void lv_ta_set_cursor_type(lv_obj_t * ta, lv_cursor_type_t cur_type) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + if(ext->cursor.type == cur_type) return; + + ext->cursor.type = cur_type; + + refr_cursor_area(ta); +} + +/** + * Enable/Disable password mode + * @param ta pointer to a text area object + * @param en true: enable, false: disable + */ +void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + if(ext->pwd_mode == en) return; + + /*Pwd mode is now enabled*/ + if(ext->pwd_mode == 0 && en != false) { + char * txt = lv_label_get_text(ext->label); + uint16_t len = strlen(txt); + ext->pwd_tmp = lv_mem_alloc(len + 1); + lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp == NULL) return; + + strcpy(ext->pwd_tmp, txt); + + uint16_t i; + for(i = 0; i < len; i++) { + txt[i] = '*'; /*All char to '*'*/ + } + txt[i] = '\0'; + + lv_label_set_text(ext->label, NULL); + } + /*Pwd mode is now disabled*/ + else if(ext->pwd_mode == 1 && en == false) { + lv_label_set_text(ext->label, ext->pwd_tmp); + lv_mem_free(ext->pwd_tmp); + ext->pwd_tmp = NULL; + } + + ext->pwd_mode = en == false ? 0 : 1; + + refr_cursor_area(ta); +} + +/** + * Configure the text area to one line or back to normal + * @param ta pointer to a Text area object + * @param en true: one line, false: normal + */ +void lv_ta_set_one_line(lv_obj_t * ta, bool en) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + if(ext->one_line == en) return; + + if(en) { + lv_style_t * style_ta = lv_obj_get_style(ta); + lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(ta)); + lv_style_t * style_label = lv_obj_get_style(ext->label); + lv_coord_t font_h = lv_font_get_height(style_label->text.font); + + ext->one_line = 1; + lv_page_set_scrl_fit(ta, true, true); + lv_obj_set_height(ta, font_h + (style_ta->body.padding.ver + style_scrl->body.padding.ver) * 2); + lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND); + lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.hor, style_ta->body.padding.ver); + } else { + lv_style_t * style_ta = lv_obj_get_style(ta); + + ext->one_line = 0; + lv_page_set_scrl_fit(ta, false, true); + lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK); + lv_obj_set_height(ta, LV_TA_DEF_HEIGHT); + lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.hor, style_ta->body.padding.ver); + } + + refr_cursor_area(ta); +} + +/** + * Set the alignment of the text area. + * In one line mode the text can be scrolled only with `LV_LABEL_ALIGN_LEFT`. + * This function should be called if the size of text area changes. + * @param ta pointer to a text are object + * @param align the desired alignment from `lv_label_align_t`. (LV_LABEL_ALIGN_LEFT/CENTER/RIGHT) + */ +void lv_ta_set_text_align(lv_obj_t * ta, lv_label_align_t align) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + lv_obj_t * label = lv_ta_get_label(ta); + if(!ext->one_line) { + lv_label_set_align(label, align); + } else { + /*Normal left align. Just let the text expand*/ + if(align == LV_LABEL_ALIGN_LEFT) { + lv_label_set_long_mode(label, LV_LABEL_LONG_EXPAND); + lv_page_set_scrl_fit(ta, true, false); + lv_label_set_align(label, align); + + } + /*Else use fix label width equal to the Text area width*/ + else { + lv_label_set_long_mode(label, LV_LABEL_LONG_CROP); + lv_page_set_scrl_fit(ta, false, false); + lv_page_set_scrl_width(ta, 1); /*To refresh the scrollable's width*/ + lv_label_set_align(label, align); + + lv_style_t * bg_style = lv_ta_get_style(ta, LV_TA_STYLE_BG); + lv_obj_set_width(label, lv_obj_get_width(ta) - 2 * bg_style->body.padding.hor); + } + } + + refr_cursor_area(ta); +} + +/** + * Set a list of characters. Only these characters will be accepted by the text area + * @param ta pointer to Text Area + * @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789" + */ +void lv_ta_set_accepted_chars(lv_obj_t * ta, const char * list) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + ext->accapted_chars = list; +} + +/** + * Set max length of a Text Area. + * @param ta pointer to Text Area + * @param num the maximal number of characters can be added (`lv_ta_set_text` ignores it) + */ +void lv_ta_set_max_length(lv_obj_t * ta, uint16_t num) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + ext->max_length = num; +} + +/** + * Set a style of a text area + * @param ta pointer to a text area object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_ta_set_style(lv_obj_t * ta, lv_ta_style_t type, lv_style_t * style) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + switch(type) { + case LV_TA_STYLE_BG: + lv_page_set_style(ta, LV_PAGE_STYLE_BG, style); + break; + case LV_TA_STYLE_SB: + lv_page_set_style(ta, LV_PAGE_STYLE_SB, style); + break; + case LV_TA_STYLE_EDGE_FLASH: + lv_page_set_style(ta, LV_PAGE_STYLE_EDGE_FLASH, style); + break; + case LV_TA_STYLE_CURSOR: + ext->cursor.style = style; + lv_obj_refresh_ext_size(lv_page_get_scrl(ta)); /*Refresh ext. size because of cursor drawing*/ + refr_cursor_area(ta); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a text area. In password mode it gives the real text (not '*'s). + * @param ta pointer to a text area object + * @return pointer to the text + */ +const char * lv_ta_get_text(const lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + const char * txt; + if(ext->pwd_mode == 0) { + txt = lv_label_get_text(ext->label); + } else { + txt = ext->pwd_tmp; + } + + return txt; +} + + +/** + * Get the label of a text area + * @param ta pointer to a text area object + * @return pointer to the label object + */ +lv_obj_t * lv_ta_get_label(const lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + return ext->label; +} + + +/** + * Get the current cursor position in character index + * @param ta pointer to a text area object + * @return the cursor position + */ +uint16_t lv_ta_get_cursor_pos(const lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + return ext->cursor.pos; +} + +/** + * Get the current cursor type. + * @param ta pointer to a text area object + * @return element of 'lv_ta_cursor_type_t' + */ +lv_cursor_type_t lv_ta_get_cursor_type(const lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + return ext->cursor.type; +} + +/** + * Get the password mode attribute + * @param ta pointer to a text area object + * @return true: password mode is enabled, false: disabled + */ +bool lv_ta_get_pwd_mode(const lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + return ext->pwd_mode == 0 ? false : true; +} + +/** + * Get the one line configuration attribute + * @param ta pointer to a text area object + * @return true: one line configuration is enabled, false: disabled + */ +bool lv_ta_get_one_line(const lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + return ext->one_line == 0 ? false : true; +} + +/** + * Get a list of accepted characters. + * @param ta pointer to Text Area + * @return list of accented characters. + */ +const char * lv_ta_get_accepted_chars(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + return ext->accapted_chars; +} + +/** + * Set max length of a Text Area. + * @param ta pointer to Text Area + * @return the maximal number of characters to be add + */ +uint16_t lv_ta_get_max_length(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + return ext->max_length; +} + +/** + * Get a style of a text area + * @param ta pointer to a text area object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_ta_get_style(const lv_obj_t * ta, lv_ta_style_t type) +{ + lv_style_t * style = NULL; + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + switch(type) { + case LV_TA_STYLE_BG: + style = lv_page_get_style(ta, LV_PAGE_STYLE_BG); + break; + case LV_TA_STYLE_SB: + style = lv_page_get_style(ta, LV_PAGE_STYLE_SB); + break; + case LV_TA_STYLE_EDGE_FLASH: + style = lv_page_get_style(ta, LV_PAGE_STYLE_EDGE_FLASH); + break; + case LV_TA_STYLE_CURSOR: + style = ext->cursor.style; + break; + default: + style = NULL; + break; + } + + return style; +} + +/*===================== + * Other functions + *====================*/ + +/** + * Move the cursor one character right + * @param ta pointer to a text area object + */ +void lv_ta_cursor_right(lv_obj_t * ta) +{ + uint16_t cp = lv_ta_get_cursor_pos(ta); + cp++; + lv_ta_set_cursor_pos(ta, cp); +} + +/** + * Move the cursor one character left + * @param ta pointer to a text area object + */ +void lv_ta_cursor_left(lv_obj_t * ta) +{ + uint16_t cp = lv_ta_get_cursor_pos(ta); + if(cp > 0) { + cp--; + lv_ta_set_cursor_pos(ta, cp); + } +} + +/** + * Move the cursor one line down + * @param ta pointer to a text area object + */ +void lv_ta_cursor_down(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + lv_point_t pos; + + /*Get the position of the current letter*/ + lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos); + + /*Increment the y with one line and keep the valid x*/ + lv_style_t * label_style = lv_obj_get_style(ext->label); + const lv_font_t * font_p = label_style->text.font; + lv_coord_t font_h = lv_font_get_height(font_p); + pos.y += font_h + label_style->text.line_space + 1; + pos.x = ext->cursor.valid_x; + + /*Do not go below the last line*/ + if(pos.y < lv_obj_get_height(ext->label)) { + /*Get the letter index on the new cursor position and set it*/ + uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos); + + lv_coord_t cur_valid_x_tmp = ext->cursor.valid_x; /*Cursor position set overwrites the valid positon */ + lv_ta_set_cursor_pos(ta, new_cur_pos); + ext->cursor.valid_x = cur_valid_x_tmp; + } +} + +/** + * Move the cursor one line up + * @param ta pointer to a text area object + */ +void lv_ta_cursor_up(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + lv_point_t pos; + + /*Get the position of the current letter*/ + lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos); + + /*Decrement the y with one line and keep the valid x*/ + lv_style_t * label_style = lv_obj_get_style(ext->label); + const lv_font_t * font = label_style->text.font; + lv_coord_t font_h = lv_font_get_height(font); + pos.y -= font_h + label_style->text.line_space - 1; + pos.x = ext->cursor.valid_x; + + + /*Get the letter index on the new cursor position and set it*/ + uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos); + lv_coord_t cur_valid_x_tmp = ext->cursor.valid_x; /*Cursor position set overwrites the valid positon */ + lv_ta_set_cursor_pos(ta, new_cur_pos); + ext->cursor.valid_x = cur_valid_x_tmp; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the text areas + * @param ta pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW_MAIN: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_ta_design(lv_obj_t * ta, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + /*Return false if the object is not covers the mask_p area*/ + return ancestor_design(ta, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { + /*Draw the object*/ + ancestor_design(ta, mask, mode); + + } else if(mode == LV_DESIGN_DRAW_POST) { + ancestor_design(ta, mask, mode); + } + return true; +} + + +/** + * An extended scrollable design of the page. Calls the normal design function and draws a cursor. + * @param scrl pointer to the scrollable part of the Text area + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW_MAIN: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @return return true/false, depends on 'mode' + */ +static bool lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + /*Return false if the object is not covers the mask_p area*/ + return scrl_design(scrl, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { + /*Draw the object*/ + scrl_design(scrl, mask, mode); + } else if(mode == LV_DESIGN_DRAW_POST) { + scrl_design(scrl, mask, mode); + + /*Draw the cursor*/ + lv_obj_t * ta = lv_obj_get_parent(scrl); + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + if(ext->cursor.type == LV_CURSOR_NONE || + (ext->cursor.type & LV_CURSOR_HIDDEN) || + ext->cursor.state == 0) { + return true; /*The cursor is not visible now*/ + } + + lv_style_t cur_style; + get_cursor_style(ta, &cur_style); + + const char * txt = lv_label_get_text(ext->label); + + /*Draw he cursor according to the type*/ + lv_area_t cur_area; + lv_area_copy(&cur_area, &ext->cursor.area); + + cur_area.x1 += ext->label->coords.x1; + cur_area.y1 += ext->label->coords.y1; + cur_area.x2 += ext->label->coords.x1; + cur_area.y2 += ext->label->coords.y1; + + lv_opa_t opa_scale = lv_obj_get_opa_scale(ta); + + if(ext->cursor.type == LV_CURSOR_LINE) { + lv_draw_rect(&cur_area, mask, &cur_style, opa_scale); + } else if(ext->cursor.type == LV_CURSOR_BLOCK) { + lv_draw_rect(&cur_area, mask, &cur_style, opa_scale); + +#if LV_TXT_UTF8 == 0 + char letter_buf[2]; + letter_buf[0] = txt[ext->cursor.txt_byte_pos]; + letter_buf[1] = '\0'; +#else + char letter_buf[8] = {0}; + memcpy(letter_buf, &txt[ext->cursor.txt_byte_pos], lv_txt_encoded_size(&txt[ext->cursor.txt_byte_pos])); +#endif + cur_area.x1 += cur_style.body.padding.hor; + cur_area.y1 += cur_style.body.padding.ver; + lv_draw_label(&cur_area, mask, &cur_style, opa_scale, letter_buf, LV_TXT_FLAG_NONE, 0); + + } else if(ext->cursor.type == LV_CURSOR_OUTLINE) { + cur_style.body.empty = 1; + if(cur_style.body.border.width == 0) cur_style.body.border.width = 1; /*Be sure the border will be drawn*/ + lv_draw_rect(&cur_area, mask, &cur_style, opa_scale); + } else if(ext->cursor.type == LV_CURSOR_UNDERLINE) { + lv_draw_rect(&cur_area, mask, &cur_style, opa_scale); + } + } + + return true; +} + +/** + * Signal function of the text area + * @param ta pointer to a text area object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(ta, sign, param); + if(res != LV_RES_OK) return res; + + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + if(sign == LV_SIGNAL_CLEANUP) { + if(ext->pwd_tmp != NULL) lv_mem_free(ext->pwd_tmp); + + /* (The created label will be deleted automatically) */ + } else if(sign == LV_SIGNAL_STYLE_CHG) { + if(ext->label) { + lv_obj_t * scrl = lv_page_get_scrl(ta); + lv_style_t * style_ta = lv_obj_get_style(ta); + lv_style_t * style_scrl = lv_obj_get_style(scrl); + if(ext->one_line) { + /*In one line mode refresh the Text Area height because 'vpad' can modify it*/ + lv_style_t * style_label = lv_obj_get_style(ext->label); + lv_coord_t font_h = lv_font_get_height(style_label->text.font); + lv_obj_set_height(ta, font_h + (style_ta->body.padding.ver + style_scrl->body.padding.ver) * 2); + } else { + /*In not one line mode refresh the Label width because 'hpad' can modify it*/ + lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); + lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); /*Be sure the Label is in the correct position*/ + } + lv_label_set_text(ext->label, NULL); + + } + } else if(sign == LV_SIGNAL_CORD_CHG) { + /*Set the label width according to the text area width*/ + if(ext->label) { + if(lv_obj_get_width(ta) != lv_area_get_width(param) || + lv_obj_get_height(ta) != lv_area_get_height(param)) { + lv_obj_t * scrl = lv_page_get_scrl(ta); + lv_style_t * style_scrl = lv_obj_get_style(scrl); + lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); + lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); + lv_label_set_text(ext->label, NULL); /*Refresh the label*/ + + refr_cursor_area(ta); + } + } + } else if(sign == LV_SIGNAL_CONTROLL) { + uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/ + if(c == LV_GROUP_KEY_RIGHT) lv_ta_cursor_right(ta); + else if(c == LV_GROUP_KEY_LEFT) lv_ta_cursor_left(ta); + else if(c == LV_GROUP_KEY_UP) lv_ta_cursor_up(ta); + else if(c == LV_GROUP_KEY_DOWN) lv_ta_cursor_down(ta); + else if(c == LV_GROUP_KEY_BACKSPACE) lv_ta_del_char(ta); + else if(c == LV_GROUP_KEY_DEL) { + uint16_t cp = lv_ta_get_cursor_pos(ta); + lv_ta_set_cursor_pos(ta, cp + 1); + if(cp != lv_ta_get_cursor_pos(ta)) lv_ta_del_char(ta); + } + else { + lv_ta_add_char(ta, c); + } + } else if(sign == LV_SIGNAL_GET_EDITABLE) { + bool * editable = (bool *)param; + *editable = true; + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_ta"; + } else if(sign == LV_SIGNAL_DEFOCUS) { + lv_cursor_type_t cur_type; + cur_type = lv_ta_get_cursor_type(ta); + lv_ta_set_cursor_type(ta, cur_type | LV_CURSOR_HIDDEN); + } else if(sign == LV_SIGNAL_FOCUS) { +#if USE_LV_GROUP + lv_cursor_type_t cur_type; + cur_type = lv_ta_get_cursor_type(ta); + lv_group_t * g = lv_obj_get_group(ta); + bool editing = lv_group_get_editing(g); + lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + + /*Encoders need special handling*/ + if(indev_type == LV_INDEV_TYPE_ENCODER) { + if(editing) lv_ta_set_cursor_type(ta, cur_type & (~LV_CURSOR_HIDDEN)); + else lv_ta_set_cursor_type(ta, cur_type | LV_CURSOR_HIDDEN); + } + else { + lv_ta_set_cursor_type(ta, cur_type & (~LV_CURSOR_HIDDEN)); + } +#endif + } + return res; +} + +/** + * Signal function of the scrollable part of the text area + * @param scrl pointer to scrollable part of a text area object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) +{ + lv_res_t res; + lv_obj_t * ta = lv_obj_get_parent(scrl); + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + /* Include the ancient signal function */ + res = scrl_signal(scrl, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + /*Set ext. size because the cursor might be out of this object*/ + lv_style_t * style_label = lv_obj_get_style(ext->label); + lv_coord_t font_h = lv_font_get_height(style_label->text.font); + scrl->ext_size = LV_MATH_MAX(scrl->ext_size, style_label->text.line_space + font_h); + } +#if 0 + else if(sign == LV_SIGNAL_CORD_CHG) { + /*Set the label width according to the text area width*/ + if(ext->label) { + if(lv_obj_get_width(ta) != lv_area_get_width(param) || + lv_obj_get_height(ta) != lv_area_get_height(param)) { + lv_obj_t * scrl = lv_page_get_scrl(ta); + lv_style_t * style_scrl = lv_obj_get_style(scrl); + lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); + lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); + lv_label_set_text(ext->label, NULL); /*Refresh the label*/ + + refr_cursor_area(ta); + } + } + } +#endif + + return res; +} + +#if USE_LV_ANIMATION + +/** + * Called to blink the cursor + * @param ta pointer to a text area + * @param hide 1: hide the cursor, 0: show it + */ +static void cursor_blink_anim(lv_obj_t * ta, uint8_t show) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + if(show != ext->cursor.state) { + ext->cursor.state = show == 0 ? 0 : 1; + if(ext->cursor.type != LV_CURSOR_NONE && + (ext->cursor.type & LV_CURSOR_HIDDEN) == 0) + { + lv_area_t area_tmp; + lv_area_copy(&area_tmp, &ext->cursor.area); + area_tmp.x1 += ext->label->coords.x1; + area_tmp.y1 += ext->label->coords.y1; + area_tmp.x2 += ext->label->coords.x1; + area_tmp.y2 += ext->label->coords.y1; + lv_inv_area(&area_tmp); + } + } +} + + +/** + * Dummy function to animate char hiding in pwd mode. + * Does nothing, but a function is required in car hiding anim. + * (pwd_char_hider callback do the real job) + * @param ta unused + * @param x unused + */ +static void pwd_char_hider_anim(lv_obj_t * ta, int32_t x) +{ + (void)ta; + (void)x; +} + +#endif + +/** + * Hide all characters (convert them to '*') + * @param ta: pointer to text area object + */ +static void pwd_char_hider(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + if(ext->pwd_mode != 0) { + char * txt = lv_label_get_text(ext->label); + int16_t len = lv_txt_get_encoded_length(txt); + bool refr = false; + uint16_t i; + for(i = 0; i < len; i++) { + txt[i] = '*'; + refr = true; + } + + txt[i] = '\0'; + + if(refr != false) lv_label_set_text(ext->label, txt); + } +} + +/** + * Test an unicode character if it is accepted or not. Checks max length and accepted char list. + * @param ta pointer to a test area object + * @param c an unicode character + * @return true: accapted; false: rejected + */ +static bool char_is_accepted(lv_obj_t * ta, uint32_t c) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + /*If no restriction accept it*/ + if(ext->accapted_chars == NULL && ext->max_length == 0) return true; + + /*Too many characters?*/ + if(ext->max_length > 0 && + lv_txt_get_encoded_length(lv_ta_get_text(ta)) >= ext->max_length) { + return false; + } + + /*Accepted character?*/ + if(ext->accapted_chars) { + uint32_t i = 0; + uint32_t a; + while(ext->accapted_chars[i] != '\0') { + a = lv_txt_encoded_next(ext->accapted_chars, &i); + if(a == c) return true; /*Accepted*/ + } + + return false; /*The character wasn't in the list*/ + } else { + return true; /*If the accepted char list in not specified the accept the character*/ + } + +} + +static void get_cursor_style(lv_obj_t * ta, lv_style_t * style_res) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + lv_style_t * label_style = lv_obj_get_style(ext->label); + + if(ext->cursor.style) { + lv_style_copy(style_res, ext->cursor.style); + } else { + /*If cursor style is not specified then use the modified label style */ + lv_style_copy(style_res, label_style); + lv_color_t clv_color_tmp = style_res->text.color; /*Make letter color to cursor color*/ + style_res->text.color = style_res->body.main_color; /*In block mode the letter color will be current background color*/ + style_res->body.main_color = clv_color_tmp; + style_res->body.grad_color = clv_color_tmp; + style_res->body.border.color = clv_color_tmp; + style_res->body.border.opa = LV_OPA_COVER; + style_res->body.border.width = 1; + style_res->body.shadow.width = 0; + style_res->body.radius = 0; + style_res->body.empty = 0; + style_res->body.padding.hor = 0; + style_res->body.padding.ver = 0; + style_res->line.width = 1; + style_res->body.opa = LV_OPA_COVER; + } + +} + +static void refr_cursor_area(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + lv_style_t * label_style = lv_obj_get_style(ext->label); + + lv_style_t cur_style; + get_cursor_style(ta, &cur_style); + + uint16_t cur_pos = lv_ta_get_cursor_pos(ta); + const char * txt = lv_label_get_text(ext->label); + uint32_t byte_pos; +#if LV_TXT_UTF8 != 0 + byte_pos = lv_txt_encoded_get_byte_id(txt, cur_pos); + uint32_t letter = lv_txt_encoded_next(&txt[byte_pos], NULL); +#else + byte_pos = cur_pos; + uint32_t letter = txt[byte_pos]; +#endif + + lv_coord_t letter_h = lv_font_get_height(label_style->text.font); + /*Set letter_w (set not 0 on non printable but valid chars)*/ + lv_coord_t letter_w; + if(letter == '\0' || letter == '\n' || letter == '\r') { + letter_w = lv_font_get_width(label_style->text.font, ' '); + } else { + letter_w = lv_font_get_width(label_style->text.font, letter); + } + + lv_point_t letter_pos; + lv_label_get_letter_pos(ext->label, cur_pos, &letter_pos); + + /*If the cursor is out of the text (most right) draw it to the next line*/ + if(letter_pos.x + ext->label->coords.x1 + letter_w > ext->label->coords.x2 && ext->one_line == 0 && lv_label_get_align(ext->label) != LV_LABEL_ALIGN_RIGHT) { + letter_pos.x = 0; + letter_pos.y += letter_h + label_style->text.line_space; + + if(letter != '\0') { + byte_pos += lv_txt_encoded_size(&txt[byte_pos]); + letter = lv_txt_encoded_next(&txt[byte_pos], NULL); + } + + if(letter == '\0' || letter == '\n' || letter == '\r') { + letter_w = lv_font_get_width(label_style->text.font, ' '); + } else { + letter_w = lv_font_get_width(label_style->text.font, letter); + } + } + + /*Save the byte position. It is required to draw `LV_CURSOR_BLOCK`*/ + ext->cursor.txt_byte_pos = byte_pos; + + /*Draw he cursor according to the type*/ + lv_area_t cur_area; + + if(ext->cursor.type == LV_CURSOR_LINE) { + cur_area.x1 = letter_pos.x + cur_style.body.padding.hor - (cur_style.line.width >> 1) - (cur_style.line.width & 0x1); + cur_area.y1 = letter_pos.y + cur_style.body.padding.ver; + cur_area.x2 = letter_pos.x + cur_style.body.padding.hor + (cur_style.line.width >> 1); + cur_area.y2 = letter_pos.y + cur_style.body.padding.ver + letter_h; + } else if(ext->cursor.type == LV_CURSOR_BLOCK) { + cur_area.x1 = letter_pos.x - cur_style.body.padding.hor; + cur_area.y1 = letter_pos.y - cur_style.body.padding.ver; + cur_area.x2 = letter_pos.x + cur_style.body.padding.hor + letter_w; + cur_area.y2 = letter_pos.y + cur_style.body.padding.ver + letter_h; + + } else if(ext->cursor.type == LV_CURSOR_OUTLINE) { + cur_area.x1 = letter_pos.x - cur_style.body.padding.hor; + cur_area.y1 = letter_pos.y - cur_style.body.padding.ver; + cur_area.x2 = letter_pos.x + cur_style.body.padding.hor + letter_w; + cur_area.y2 = letter_pos.y + cur_style.body.padding.ver + letter_h; + } else if(ext->cursor.type == LV_CURSOR_UNDERLINE) { + cur_area.x1 = letter_pos.x + cur_style.body.padding.hor; + cur_area.y1 = letter_pos.y + cur_style.body.padding.ver + letter_h - (cur_style.line.width >> 1); + cur_area.x2 = letter_pos.x + cur_style.body.padding.hor + letter_w; + cur_area.y2 = letter_pos.y + cur_style.body.padding.ver + letter_h + (cur_style.line.width >> 1) + (cur_style.line.width & 0x1); + } + + /*Save the new area*/ + lv_area_t area_tmp; + lv_area_copy(&area_tmp, &ext->cursor.area); + area_tmp.x1 += ext->label->coords.x1; + area_tmp.y1 += ext->label->coords.y1; + area_tmp.x2 += ext->label->coords.x1; + area_tmp.y2 += ext->label->coords.y1; + lv_inv_area(&area_tmp); + + lv_area_copy(&ext->cursor.area, &cur_area); + + lv_area_copy(&area_tmp, &ext->cursor.area); + area_tmp.x1 += ext->label->coords.x1; + area_tmp.y1 += ext->label->coords.y1; + area_tmp.x2 += ext->label->coords.x1; + area_tmp.y2 += ext->label->coords.y1; + lv_inv_area(&area_tmp); +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.h new file mode 100644 index 0000000..3227873 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_ta.h @@ -0,0 +1,390 @@ +/** + * @file lv_ta.h + * + */ + +#ifndef LV_TA_H +#define LV_TA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_TA != 0 + +/*Testing of dependencies*/ +#if USE_LV_PAGE == 0 +#error "lv_ta: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " +#endif + +#if USE_LV_LABEL == 0 +#error "lv_ta: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_page.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ +#define LV_TA_CURSOR_LAST (0x7FFF) /*Put the cursor after the last character*/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_CURSOR_NONE, + LV_CURSOR_LINE, + LV_CURSOR_BLOCK, + LV_CURSOR_OUTLINE, + LV_CURSOR_UNDERLINE, + LV_CURSOR_HIDDEN = 0x08, /*Or it to any value to hide the cursor temporally*/ +}; +typedef uint8_t lv_cursor_type_t; + +/*Data of text area*/ +typedef struct +{ + lv_page_ext_t page; /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t * label; /*Label of the text area*/ + char * pwd_tmp; /*Used to store the original text in password mode*/ + const char * accapted_chars;/*Only these characters will be accepted. NULL: accept all*/ + uint16_t max_length; /*The max. number of characters. 0: no limit*/ + uint8_t pwd_mode :1; /*Replace characters with '*' */ + uint8_t one_line :1; /*One line mode (ignore line breaks)*/ + struct { + lv_style_t *style; /*Style of the cursor (NULL to use label's style)*/ + lv_coord_t valid_x; /*Used when stepping up/down in text area when stepping to a shorter line. (Handled by the library)*/ + uint16_t pos; /*The current cursor position (0: before 1. letter; 1: before 2. letter etc.)*/ + lv_area_t area; /*Cursor area relative to the Text Area*/ + uint16_t txt_byte_pos; /*Byte index of the letter after (on) the cursor*/ + lv_cursor_type_t type:4; /*Shape of the cursor*/ + uint8_t state :1; /*Indicates that the cursor is visible now or not (Handled by the library)*/ + } cursor; +} lv_ta_ext_t; + +enum { + LV_TA_STYLE_BG, + LV_TA_STYLE_SB, + LV_TA_STYLE_EDGE_FLASH, + LV_TA_STYLE_CURSOR, +}; +typedef uint8_t lv_ta_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + + +/** + * Create a text area objects + * @param par pointer to an object, it will be the parent of the new text area + * @param copy pointer to a text area object, if not NULL then the new object will be copied from it + * @return pointer to the created text area + */ +lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy); + + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Insert a character to the current cursor position. + * To add a wide char, e.g. 'Á' use `lv_txt_encoded_conv_wc('Á')` + * @param ta pointer to a text area object + * @param c a character (e.g. 'a') + */ +void lv_ta_add_char(lv_obj_t * ta, uint32_t c); + +/** + * Insert a text to the current cursor position + * @param ta pointer to a text area object + * @param txt a '\0' terminated string to insert + */ +void lv_ta_add_text(lv_obj_t * ta, const char * txt); + +/** + * Delete a the left character from the current cursor position + * @param ta pointer to a text area object + */ +void lv_ta_del_char(lv_obj_t * ta); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of a text area + * @param ta pointer to a text area + * @param txt pointer to the text + */ +void lv_ta_set_text(lv_obj_t * ta, const char * txt); + +/** + * Set the cursor position + * @param obj pointer to a text area object + * @param pos the new cursor position in character index + * < 0 : index from the end of the text + * LV_TA_CURSOR_LAST: go after the last character + */ +void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos); + +/** + * Set the cursor type. + * @param ta pointer to a text area object + * @param cur_type: element of 'lv_cursor_type_t' + */ +void lv_ta_set_cursor_type(lv_obj_t * ta, lv_cursor_type_t cur_type); + +/** + * Enable/Disable password mode + * @param ta pointer to a text area object + * @param en true: enable, false: disable + */ +void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en); + +/** + * Configure the text area to one line or back to normal + * @param ta pointer to a Text area object + * @param en true: one line, false: normal + */ +void lv_ta_set_one_line(lv_obj_t * ta, bool en); + +/** + * Set the alignment of the text area. + * In one line mode the text can be scrolled only with `LV_LABEL_ALIGN_LEFT`. + * This function should be called if the size of text area changes. + * @param ta pointer to a text are object + * @param align the desired alignment from `lv_label_align_t`. (LV_LABEL_ALIGN_LEFT/CENTER/RIGHT) + */ +void lv_ta_set_text_align(lv_obj_t * ta, lv_label_align_t align); + +/** + * Set a list of characters. Only these characters will be accepted by the text area + * @param ta pointer to Text Area + * @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789" + */ +void lv_ta_set_accepted_chars(lv_obj_t * ta, const char * list); + +/** + * Set max length of a Text Area. + * @param ta pointer to Text Area + * @param num the maximal number of characters can be added (`lv_ta_set_text` ignores it) + */ +void lv_ta_set_max_length(lv_obj_t * ta, uint16_t num); + +/** + * Set an action to call when the Text area is clicked + * @param ta pointer to a Text area + * @param action a function pointer + */ +static inline void lv_ta_set_action(lv_obj_t * ta, lv_action_t action) +{ + lv_page_set_rel_action(ta, action); +} + +/** + * Set the scroll bar mode of a text area + * @param ta pointer to a text area object + * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum + */ +static inline void lv_ta_set_sb_mode(lv_obj_t * ta, lv_sb_mode_t mode) +{ + lv_page_set_sb_mode(ta, mode); +} + +/** + * Enable the scroll propagation feature. If enabled then the Text area will move its parent if there is no more space to scroll. + * @param ta pointer to a Text area + * @param en true or false to enable/disable scroll propagation + */ +static inline void lv_ta_set_scroll_propagation(lv_obj_t * ta, bool en) +{ + lv_page_set_scroll_propagation(ta, en); +} + +/** + * Enable the edge flash effect. (Show an arc when the an edge is reached) + * @param page pointer to a Text Area + * @param en true or false to enable/disable end flash + */ +static inline void lv_ta_set_edge_flash(lv_obj_t * ta, bool en) +{ + lv_page_set_edge_flash(ta, en); +} + +/** + * Set a style of a text area + * @param ta pointer to a text area object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_ta_set_style(lv_obj_t *ta, lv_ta_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a text area. In password mode it gives the real text (not '*'s). + * @param ta pointer to a text area object + * @return pointer to the text + */ +const char * lv_ta_get_text(const lv_obj_t * ta); + +/** + * Get the label of a text area + * @param ta pointer to a text area object + * @return pointer to the label object + */ +lv_obj_t * lv_ta_get_label(const lv_obj_t * ta); + +/** + * Get the current cursor position in character index + * @param ta pointer to a text area object + * @return the cursor position + */ +uint16_t lv_ta_get_cursor_pos(const lv_obj_t * ta); + +/** + * Get the current cursor visibility. + * @param ta pointer to a text area object + * @return true: the cursor is drawn, false: the cursor is hidden + */ +//bool lv_ta_get_cursor_show(const lv_obj_t * ta); + +/** + * Get the current cursor type. + * @param ta pointer to a text area object + * @return element of 'lv_cursor_type_t' + */ +lv_cursor_type_t lv_ta_get_cursor_type(const lv_obj_t * ta); + +/** + * Get the password mode attribute + * @param ta pointer to a text area object + * @return true: password mode is enabled, false: disabled + */ +bool lv_ta_get_pwd_mode(const lv_obj_t * ta); + +/** + * Get the one line configuration attribute + * @param ta pointer to a text area object + * @return true: one line configuration is enabled, false: disabled + */ +bool lv_ta_get_one_line(const lv_obj_t * ta); + +/** + * Get a list of accepted characters. + * @param ta pointer to Text Area + * @return list of accented characters. + */ +const char * lv_ta_get_accepted_chars(lv_obj_t * ta); + +/** + * Set max length of a Text Area. + * @param ta pointer to Text Area + * @return the maximal number of characters to be add + */ +uint16_t lv_ta_get_max_length(lv_obj_t * ta); + +/** + * Set an action to call when the Text area is clicked + * @param ta pointer to a Text area + * @param action a function pointer + */ +static inline lv_action_t lv_ta_get_action(lv_obj_t * ta) +{ + return lv_page_get_rel_action(ta); +} + +/** + * Get the scroll bar mode of a text area + * @param ta pointer to a text area object + * @return scrollbar mode from 'lv_page_sb_mode_t' enum + */ +static inline lv_sb_mode_t lv_ta_get_sb_mode(const lv_obj_t * ta) +{ + return lv_page_get_sb_mode(ta); +} + +/** + * Get the scroll propagation property + * @param ta pointer to a Text area + * @return true or false + */ +static inline bool lv_ta_get_scroll_propagation(lv_obj_t * ta) +{ + return lv_page_get_scroll_propagation(ta); +} + +/** + * Get the scroll propagation property + * @param ta pointer to a Text area + * @return true or false + */ +static inline bool lv_ta_get_edge_flash(lv_obj_t * ta) +{ + return lv_page_get_edge_flash(ta); +} + +/** + * Get a style of a text area + * @param ta pointer to a text area object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_ta_get_style(const lv_obj_t *ta, lv_ta_style_t type); + +/*===================== + * Other functions + *====================*/ + +/** + * Move the cursor one character right + * @param ta pointer to a text area object + */ +void lv_ta_cursor_right(lv_obj_t * ta); + +/** + * Move the cursor one character left + * @param ta pointer to a text area object + */ +void lv_ta_cursor_left(lv_obj_t * ta); + +/** + * Move the cursor one line down + * @param ta pointer to a text area object + */ +void lv_ta_cursor_down(lv_obj_t * ta); + +/** + * Move the cursor one line up + * @param ta pointer to a text area object + */ +void lv_ta_cursor_up(lv_obj_t * ta); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_TA_H*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TA_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.c new file mode 100644 index 0000000..c6177ed --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.c @@ -0,0 +1,855 @@ +/** + * @file lv_table.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_table.h" +#if USE_LV_TABLE != 0 + +#include "../lv_misc/lv_txt.h" +#include "../lv_misc/lv_math.h" +#include "../lv_draw/lv_draw_label.h" +#include "../lv_themes/lv_theme.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_table_design(lv_obj_t * table, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param); +static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id); +static void refr_size(lv_obj_t * table); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_scrl_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a table object + * @param par pointer to an object, it will be the parent of the new table + * @param copy pointer to a table object, if not NULL then the new object will be copied from it + * @return pointer to the created table + */ +lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("table create started"); + + /*Create the ancestor of table*/ + lv_obj_t * new_table = lv_obj_create(par, copy); + lv_mem_assert(new_table); + if(new_table == NULL) return NULL; + + /*Allocate the table type specific extended data*/ + lv_table_ext_t * ext = lv_obj_allocate_ext_attr(new_table, sizeof(lv_table_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_table); + if(ancestor_scrl_design == NULL) ancestor_scrl_design = lv_obj_get_design_func(new_table); + + /*Initialize the allocated 'ext' */ + ext->cell_data = NULL; + ext->cell_style[0] = &lv_style_plain; + ext->cell_style[1] = &lv_style_plain; + ext->cell_style[2] = &lv_style_plain; + ext->cell_style[3] = &lv_style_plain; + ext->col_cnt = 0; + ext->row_cnt = 0; + + uint16_t i; + for(i = 0; i < LV_TABLE_COL_MAX; i++) { + ext->col_w[i] = LV_DPI; + } + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_table, lv_table_signal); + lv_obj_set_design_func(new_table, lv_table_design); + + /*Init the new table table*/ + if(copy == NULL) { + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_table_set_style(new_table, LV_TABLE_STYLE_BG, th->table.bg); + lv_table_set_style(new_table, LV_TABLE_STYLE_CELL1, th->table.cell); + lv_table_set_style(new_table, LV_TABLE_STYLE_CELL2, th->table.cell); + lv_table_set_style(new_table, LV_TABLE_STYLE_CELL3, th->table.cell); + lv_table_set_style(new_table, LV_TABLE_STYLE_CELL4, th->table.cell); + } else { + lv_table_set_style(new_table, LV_TABLE_STYLE_BG, &lv_style_plain_color); + } + } + /*Copy an existing table*/ + else { + lv_table_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->cell_style[0] = copy_ext->cell_style[0]; + ext->cell_style[1] = copy_ext->cell_style[1]; + ext->cell_style[2] = copy_ext->cell_style[2]; + ext->cell_style[3] = copy_ext->cell_style[3]; + ext->col_cnt = copy_ext->col_cnt; + ext->row_cnt = copy_ext->row_cnt; + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_table); + } + + LV_LOG_INFO("table created"); + + return new_table; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the value of a cell. + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param txt text to display in the cell. It will be copied and saved so this variable is not required after this function call. + */ +void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const char * txt) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_set_cell_value: invalid row or column"); + return; + } + uint32_t cell = row * ext->col_cnt + col; + lv_table_cell_format_t format; + + /*Save the format byte*/ + if(ext->cell_data[cell]) { + format.format_byte = ext->cell_data[cell][0]; + } + /*Initialize the format byte*/ + else { + format.align = LV_LABEL_ALIGN_LEFT; + format.right_merge = 0; + format.type = 0; + format.crop = 0; + } + + + ext->cell_data[cell] = lv_mem_realloc(ext->cell_data[cell], strlen(txt) + 2); /*+1: trailing '\0; +1: format byte*/ + strcpy(ext->cell_data[cell] + 1, txt); /*Leave the format byte*/ + ext->cell_data[cell][0] = format.format_byte; + refr_size(table); +} + +/** + * Set the number of rows + * @param table table pointer to a Table object + * @param row_cnt number of rows + */ +void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + uint16_t old_row_cnt = ext->row_cnt; + ext->row_cnt = row_cnt; + + if(ext->row_cnt > 0 && ext->col_cnt > 0) { + ext->cell_data = lv_mem_realloc(ext->cell_data, ext->row_cnt * ext->col_cnt * sizeof(char*)); + + /*Initilize the new fields*/ + if(old_row_cnt < row_cnt) { + uint16_t old_cell_cnt = old_row_cnt * ext->col_cnt; + uint32_t new_cell_cnt = ext->col_cnt * ext->row_cnt; + memset(&ext->cell_data[old_cell_cnt], 0, (new_cell_cnt - old_cell_cnt) * sizeof(ext->cell_data[0])); + } + } + else { + lv_mem_free(ext->cell_data); + ext->cell_data = NULL; + } + + refr_size(table); +} + +/** + * Set the number of columns + * @param table table pointer to a Table object + * @param col_cnt number of columns. Must be < LV_TABLE_COL_MAX + */ +void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt) +{ + + if(col_cnt >= LV_TABLE_COL_MAX) { + LV_LOG_WARN("lv_table_set_col_cnt: too many columns. Must be < LV_TABLE_COL_MAX."); + return; + } + + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + uint16_t old_col_cnt = ext->col_cnt; + ext->col_cnt = col_cnt; + + if(ext->row_cnt > 0 && ext->col_cnt > 0) { + ext->cell_data = lv_mem_realloc(ext->cell_data, ext->row_cnt * ext->col_cnt * sizeof(char*)); + /*Initilize the new fields*/ + if(old_col_cnt < col_cnt) { + uint16_t old_cell_cnt = old_col_cnt * ext->row_cnt; + uint32_t new_cell_cnt = ext->col_cnt * ext->row_cnt; + memset(&ext->cell_data[old_cell_cnt], 0, (new_cell_cnt - old_cell_cnt) * sizeof(ext->cell_data[0])); + } + + } + else { + lv_mem_free(ext->cell_data); + ext->cell_data = NULL; + } + refr_size(table); +} + +/** + * Set the width of a column + * @param table table pointer to a Table object + * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] + * @param w width of the column + */ +void lv_table_set_col_width(lv_obj_t * table, uint16_t col_id, lv_coord_t w) +{ + if(col_id >= LV_TABLE_COL_MAX) { + LV_LOG_WARN("lv_table_set_col_width: too big 'col_id'. Must be < LV_TABLE_COL_MAX."); + return; + } + + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + ext->col_w[col_id] = w; + refr_size(table); +} + +/** + * Set the text align in a cell + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param align LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT + */ +void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_label_align_t align) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_set_cell_align: invalid row or column"); + return; + } + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) { + ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ + ext->cell_data[cell][0] = 0; + ext->cell_data[cell][1] = '\0'; + } + + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + format.align = align; + ext->cell_data[cell][0] = format.format_byte; +} + +/** + * Set the type of a cell. + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param type 1,2,3 or 4. The cell style will be chosen accordingly. + */ +void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_t type) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_set_cell_type: invalid row or column"); + return; + } + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) { + ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ + ext->cell_data[cell][0] = 0; + ext->cell_data[cell][1] = '\0'; + } + + if(type > 0) type--; /*User gives 1,2,3,4 but easier to handle 0, 1, 2, 3*/ + if(type >= LV_TABLE_CELL_STYLE_CNT) type = LV_TABLE_CELL_STYLE_CNT - 1; + + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + format.type = type; + ext->cell_data[cell][0] = format.format_byte; +} + +/** + * Set the cell crop. (Don't adjust the height of the cell according to its content) + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param crop true: crop the cell content; false: set the cell height to the content. + */ +void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool crop) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_set_cell_crop: invalid row or column"); + return; + } + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) { + ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ + ext->cell_data[cell][0] = 0; + ext->cell_data[cell][1] = '\0'; + } + + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + format.crop = crop; + ext->cell_data[cell][0] = format.format_byte; +} + + +/** + * Merge a cell with the right neighbor. The value of the cell to the right won't be displayed. + * @param table table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param en true: merge right; false: don't merge right + */ +void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col, bool en) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_set_cell_merge_right: invalid row or column"); + return; + } + + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) { + ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ + ext->cell_data[cell][0] = 0; + ext->cell_data[cell][1] = '\0'; + } + + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + format.right_merge = en ? 1 : 0; + ext->cell_data[cell][0] = format.format_byte; + refr_size(table); +} + +/** + * Set a style of a table. + * @param table pointer to table object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_table_set_style(lv_obj_t * table, lv_table_style_t type, lv_style_t * style) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + + switch(type) { + case LV_TABLE_STYLE_BG: + lv_obj_set_style(table, style); + refr_size(table); + break; + case LV_TABLE_STYLE_CELL1: + ext->cell_style[0] = style; + refr_size(table); + break; + case LV_TABLE_STYLE_CELL2: + ext->cell_style[1] = style; + refr_size(table); + break; + case LV_TABLE_STYLE_CELL3: + ext->cell_style[2] = style; + refr_size(table); + break; + case LV_TABLE_STYLE_CELL4: + ext->cell_style[3] = style; + refr_size(table); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a cell. + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return text in the cell + */ +const char * lv_table_get_cell_value(lv_obj_t * table, uint16_t row, uint16_t col) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_set_cell_value: invalid row or column"); + return ""; + } + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) return ""; + + return &ext->cell_data[cell][1]; /*Skip the format byte*/ +} + +/** + * Get the number of rows. + * @param table table pointer to a Table object + * @return number of rows. + */ +uint16_t lv_table_get_row_cnt(lv_obj_t * table) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + return ext->row_cnt; +} + +/** + * Get the number of columns. + * @param table table pointer to a Table object + * @return number of columns. + */ +uint16_t lv_table_get_col_cnt(lv_obj_t * table) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + return ext->col_cnt; +} + +/** + * Get the width of a column + * @param table table pointer to a Table object + * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] + * @return width of the column + */ +lv_coord_t lv_table_get_col_width(lv_obj_t * table, uint16_t col_id) +{ + if(col_id >= LV_TABLE_COL_MAX) { + LV_LOG_WARN("lv_table_set_col_width: too big 'col_id'. Must be < LV_TABLE_COL_MAX."); + return 0; + } + + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + return ext->col_w[col_id]; +} + +/** + * Get the text align of a cell + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return LV_LABEL_ALIGN_LEFT (default in case of error) or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT + */ +lv_label_align_t lv_table_get_cell_align(lv_obj_t * table, uint16_t row, uint16_t col) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_set_cell_align: invalid row or column"); + return LV_LABEL_ALIGN_LEFT; /*Just return with something*/ + } + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) return LV_LABEL_ALIGN_LEFT; /*Just return with something*/ + else { + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + return format.align; + } +} + +/** + * Get the type of a cell + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return 1,2,3 or 4 + */ +lv_label_align_t lv_table_get_cell_type(lv_obj_t * table, uint16_t row, uint16_t col) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_get_cell_type: invalid row or column"); + return 1; /*Just return with something*/ + } + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) return 1; /*Just return with something*/ + else { + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + return format.type + 1; /*0,1,2,3 is stored but user sees 1,2,3,4*/ + } +} + +/** + * Get the crop property of a cell + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return true: text crop enabled; false: disabled + */ +lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_get_cell_crop: invalid row or column"); + return false; /*Just return with something*/ + } + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) return false; /*Just return with something*/ + else { + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + return format.crop; + } +} + +/** + * Get the cell merge attribute. + * @param table table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return true: merge right; false: don't merge right + */ +bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(row >= ext->row_cnt || col >= ext->col_cnt) { + LV_LOG_WARN("lv_table_get_cell_merge_right: invalid row or column"); + return false; + } + + uint32_t cell = row * ext->col_cnt + col; + + if(ext->cell_data[cell] == NULL) return false; + else { + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + return format.right_merge ? true : false; + } +} + +/** + * Get style of a table. + * @param table pointer to table object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_table_get_style(const lv_obj_t * table, lv_table_style_t type) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + lv_style_t * style = NULL; + + switch(type) { + case LV_TABLE_STYLE_BG: + style = lv_obj_get_style(table); + break; + case LV_TABLE_STYLE_CELL1: + style = ext->cell_style[0]; + break; + case LV_TABLE_STYLE_CELL2: + style = ext->cell_style[1]; + break; + case LV_TABLE_STYLE_CELL3: + style = ext->cell_style[2]; + break; + case LV_TABLE_STYLE_CELL4: + style = ext->cell_style[3]; + break; + default: + return NULL; + } + + return style; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the tables + * @param table pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_table_design(lv_obj_t * table, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + ancestor_scrl_design(table, mask, mode); + + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + lv_style_t * bg_style = lv_obj_get_style(table); + lv_style_t * cell_style; + lv_coord_t h_row; + lv_point_t txt_size; + lv_area_t cell_area; + lv_area_t txt_area; + lv_txt_flag_t txt_flags; + lv_opa_t opa_scale = lv_obj_get_opa_scale(table); + + uint16_t col; + uint16_t row; + uint16_t cell = 0; + + cell_area.y2 = table->coords.y1 + bg_style->body.padding.ver; + for(row = 0; row < ext->row_cnt; row++) { + h_row = get_row_height(table, row); + + cell_area.y1 = cell_area.y2; + cell_area.y2 = cell_area.y1 + h_row; + + cell_area.x2 = table->coords.x1 + bg_style->body.padding.hor; + + for(col = 0; col < ext->col_cnt; col++) { + + lv_table_cell_format_t format; + if(ext->cell_data[cell]) { + format.format_byte = ext->cell_data[cell][0]; + } else { + format.right_merge = 0; + format.align = LV_LABEL_ALIGN_LEFT; + format.type = 0; + format.crop = 1; + } + + cell_style = ext->cell_style[format.type]; + cell_area.x1 = cell_area.x2; + cell_area.x2 = cell_area.x1 + ext->col_w[col]; + + uint16_t col_merge = 0; + for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge ++) { + + if(ext->cell_data[cell + col_merge] != NULL) { + format.format_byte = ext->cell_data[cell + col_merge][0]; + if(format.right_merge) cell_area.x2 += ext->col_w[col + col_merge + 1]; + else break; + } else { + break; + } + } + + lv_draw_rect(&cell_area, mask, cell_style, opa_scale); + + if(ext->cell_data[cell]) { + txt_area.x1 = cell_area.x1 + cell_style->body.padding.hor; + txt_area.x2 = cell_area.x2 - cell_style->body.padding.hor; + txt_area.y1 = cell_area.y1 + cell_style->body.padding.ver; + txt_area.y2 = cell_area.y2 - cell_style->body.padding.ver; + /*Align the content to the middle if not cropped*/ + if(format.crop == 0) { + txt_flags = LV_TXT_FLAG_NONE; + } else { + txt_flags = LV_TXT_FLAG_EXPAND; + } + + lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, cell_style->text.font, + cell_style->text.letter_space, cell_style->text.line_space, lv_area_get_width(&txt_area), txt_flags); + + /*Align the content to the middle if not cropped*/ + if(format.crop == 0) { + txt_area.y1 = cell_area.y1 + h_row / 2 - txt_size.y / 2; + txt_area.y2 = cell_area.y1 + h_row / 2 + txt_size.y / 2; + } + + switch(format.align) { + default: + case LV_LABEL_ALIGN_LEFT: + txt_flags |= LV_TXT_FLAG_NONE; + break; + case LV_LABEL_ALIGN_RIGHT: + txt_flags |= LV_TXT_FLAG_RIGHT; + break; + case LV_LABEL_ALIGN_CENTER: + txt_flags |= LV_TXT_FLAG_CENTER; + break; + } + + lv_area_t label_mask; + bool label_mask_ok; + label_mask_ok = lv_area_intersect(&label_mask, mask, &cell_area); + if(label_mask_ok) { + lv_draw_label(&txt_area, &label_mask, cell_style, opa_scale, ext->cell_data[cell] + 1, txt_flags, NULL); + } + /*Draw lines after '\n's*/ + lv_point_t p1; + lv_point_t p2; + p1.x = cell_area.x1; + p2.x = cell_area.x2; + uint16_t i; + for(i = 1; ext->cell_data[cell][i] != '\0'; i++) { + if(ext->cell_data[cell][i] == '\n') { + ext->cell_data[cell][i] = '\0'; + lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, cell_style->text.font, + cell_style->text.letter_space, cell_style->text.line_space, lv_area_get_width(&txt_area), txt_flags); + + p1.y = txt_area.y1 + txt_size.y + cell_style->text.line_space / 2; + p2.y = txt_area.y1 + txt_size.y + cell_style->text.line_space / 2; + lv_draw_line(&p1, &p2, mask, cell_style, opa_scale); + + ext->cell_data[cell][i] = '\n'; + } + } + } + + cell += col_merge + 1; + col += col_merge; + } + } + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the table + * @param table pointer to a table object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(table, sign, param); + if(res != LV_RES_OK) return res; + + + if(sign == LV_SIGNAL_CLEANUP) { + /*Free the cell texts*/ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + uint16_t cell; + for(cell = 0; cell < ext->col_cnt * ext->row_cnt; cell++) { + if(ext->cell_data[cell]) { + lv_mem_free(ext->cell_data[cell]); + ext->cell_data[cell] = NULL; + } + } + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_table"; + } + + return res; +} + +static void refr_size(lv_obj_t * table) +{ + lv_coord_t h = 0; + lv_coord_t w = 0; + + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + + uint16_t i; + for(i= 0; i < ext->col_cnt; i++) { + w += ext->col_w[i]; + } + for(i= 0; i < ext->row_cnt; i++) { + h += get_row_height(table, i); + } + + lv_style_t * bg_style = lv_obj_get_style(table); + + w += bg_style->body.padding.hor * 2; + h += bg_style->body.padding.ver * 2; + + lv_obj_set_size(table, w + 1, h + 1); + lv_obj_invalidate(table); +} + +static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + lv_point_t txt_size; + lv_coord_t txt_w; + lv_style_t * cell_style; + + uint16_t row_start = row_id * ext->col_cnt; + uint16_t cell; + uint16_t col; + lv_coord_t h_max = lv_font_get_height(ext->cell_style[0]->text.font) + 2 * ext->cell_style[0]->body.padding.ver; + + for(cell = row_start, col = 0; cell < row_start + ext->col_cnt; cell++, col ++) { + if(ext->cell_data[cell] != NULL) { + + txt_w = ext->col_w[col]; + uint16_t col_merge = 0; + for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge ++) { + + if(ext->cell_data[cell + col_merge] != NULL) { + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell + col_merge][0]; + if(format.right_merge) txt_w += ext->col_w[col + col_merge + 1]; + else break; + } else { + break; + } + } + + lv_table_cell_format_t format; + format.format_byte = ext->cell_data[cell][0]; + cell_style = ext->cell_style[format.type]; + + /*With text crop assume 1 line*/ + if(format.crop) { + h_max = LV_MATH_MAX(lv_font_get_height(cell_style->text.font) + 2 * cell_style->body.padding.ver, h_max); + } + /*Without text crop calculate the height of the text in the cell*/ + else { + txt_w -= 2 * cell_style->body.padding.hor; + + lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, cell_style->text.font, + cell_style->text.letter_space, cell_style->text.line_space, txt_w, LV_TXT_FLAG_NONE); + + h_max = LV_MATH_MAX(txt_size.y + 2 * cell_style->body.padding.ver, h_max); + cell += col_merge; + col += col_merge; + } + } + } + + return h_max; +} + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.h new file mode 100644 index 0000000..94c3575 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_table.h @@ -0,0 +1,261 @@ +/** + * @file lv_table.h + * + */ + +#ifndef LV_TABLE_H +#define LV_TABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_TABLE != 0 + +/*Testing of dependencies*/ +#if USE_LV_LABEL == 0 +#error "lv_table: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ +#ifndef LV_TABLE_COL_MAX +#define LV_TABLE_COL_MAX 12 +#endif + +#define LV_TABLE_CELL_STYLE_CNT 4 +/********************** + * TYPEDEFS + **********************/ + +typedef union { + struct { + uint8_t align:2; + uint8_t right_merge:1; + uint8_t type:2; + uint8_t crop:1; + }; + uint8_t format_byte; +}lv_table_cell_format_t; + +/*Data of table*/ +typedef struct { + /*New data for this type */ + uint16_t col_cnt; + uint16_t row_cnt; + char ** cell_data; + lv_style_t * cell_style[LV_TABLE_CELL_STYLE_CNT]; + lv_coord_t col_w[LV_TABLE_COL_MAX]; +} lv_table_ext_t; + + +/*Styles*/ +enum { + LV_TABLE_STYLE_BG, + LV_TABLE_STYLE_CELL1, + LV_TABLE_STYLE_CELL2, + LV_TABLE_STYLE_CELL3, + LV_TABLE_STYLE_CELL4, +}; +typedef uint8_t lv_table_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a table object + * @param par pointer to an object, it will be the parent of the new table + * @param copy pointer to a table object, if not NULL then the new object will be copied from it + * @return pointer to the created table + */ +lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the value of a cell. + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param txt text to display in the cell. It will be copied and saved so this variable is not required after this function call. + */ +void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const char * txt); + +/** + * Set the number of rows + * @param table table pointer to a Table object + * @param row_cnt number of rows + */ +void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt); + +/** + * Set the number of columns + * @param table table pointer to a Table object + * @param col_cnt number of columns. Must be < LV_TABLE_COL_MAX + */ +void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt); + +/** + * Set the width of a column + * @param table table pointer to a Table object + * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] + * @param w width of the column + */ +void lv_table_set_col_width(lv_obj_t * table, uint16_t col_id, lv_coord_t w); + +/** + * Set the text align in a cell + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param align LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT + */ +void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_label_align_t align); + +/** + * Set the type of a cell. + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param type 1,2,3 or 4. The cell style will be chosen accordingly. + */ +void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_t type); + +/** + * Set the cell crop. (Don't adjust the height of the cell according to its content) + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param crop true: crop the cell content; false: set the cell height to the content. + */ +void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool crop); + +/** + * Merge a cell with the right neighbor. The value of the cell to the right won't be displayed. + * @param table table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param en true: merge right; false: don't merge right + */ +void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col, bool en); + +/** + * Set a style of a table. + * @param table pointer to table object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_table_set_style(lv_obj_t * table, lv_table_style_t type, lv_style_t * style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a cell. + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return text in the cell + */ +const char * lv_table_get_cell_value(lv_obj_t * table, uint16_t row, uint16_t col); + +/** + * Get the number of rows. + * @param table table pointer to a Table object + * @return number of rows. + */ +uint16_t lv_table_get_row_cnt(lv_obj_t * table); + +/** + * Get the number of columns. + * @param table table pointer to a Table object + * @return number of columns. + */ +uint16_t lv_table_get_col_cnt(lv_obj_t * table); + +/** + * Get the width of a column + * @param table table pointer to a Table object + * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] + * @return width of the column + */ +lv_coord_t lv_table_get_col_width(lv_obj_t * table, uint16_t col_id); + +/** + * Get the text align of a cell + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return LV_LABEL_ALIGN_LEFT (default in case of error) or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT + */ +lv_label_align_t lv_table_get_cell_align(lv_obj_t * table, uint16_t row, uint16_t col); + +/** + * Get the type of a cell + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return 1,2,3 or 4 + */ +lv_label_align_t lv_table_get_cell_type(lv_obj_t * table, uint16_t row, uint16_t col); + + +/** + * Get the crop property of a cell + * @param table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return true: text crop enabled; false: disabled + */ +lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col); + +/** + * Get the cell merge attribute. + * @param table table pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return true: merge right; false: don't merge right + */ +bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col); + +/** + * Get style of a table. + * @param table pointer to table object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_table_get_style(const lv_obj_t * table, lv_table_style_t type); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_TABLE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TABLE_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.c new file mode 100644 index 0000000..00f7d55 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.c @@ -0,0 +1,909 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_tab.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_tabview.h" +#if USE_LV_TABVIEW != 0 + +#include "lv_btnm.h" +#include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_anim.h" + +/********************* + * DEFINES + *********************/ +#if USE_LV_ANIMATION +# ifndef LV_TABVIEW_ANIM_TIME +# define LV_TABVIEW_ANIM_TIME 300 /*Animation time of focusing to the a list element [ms] (0: no animation) */ +# endif +#else +# undef LV_TABVIEW_ANIM_TIME +# define LV_TABVIEW_ANIM_TIME 0 /*No animations*/ +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param); +static lv_res_t tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param); +static lv_res_t tabpage_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param); + +static void tabpage_pressed_handler(lv_obj_t * tabview, lv_obj_t * tabpage); +static void tabpage_pressing_handler(lv_obj_t * tabview, lv_obj_t * tabpage); +static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage); +static lv_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name); +static void tabview_realign(lv_obj_t * tabview); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_signal_func_t page_signal; +static lv_signal_func_t page_scrl_signal; +static const char * tab_def[] = {""}; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a Tab view object + * @param par pointer to an object, it will be the parent of the new tab + * @param copy pointer to a tab object, if not NULL then the new object will be copied from it + * @return pointer to the created tab + */ +lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("tab view create started"); + + /*Create the ancestor of tab*/ + lv_obj_t * new_tabview = lv_obj_create(par, copy); + lv_mem_assert(new_tabview); + if(new_tabview == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_tabview); + + /*Allocate the tab type specific extended data*/ + lv_tabview_ext_t * ext = lv_obj_allocate_ext_attr(new_tabview, sizeof(lv_tabview_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + /*Initialize the allocated 'ext' */ + ext->drag_hor = 0; + ext->draging = 0; + ext->slide_enable = 1; + ext->tab_cur = 0; + ext->point_last.x = 0; + ext->point_last.y = 0; + ext->content = NULL; + ext->indic = NULL; + ext->btns = NULL; + ext->tab_load_action = NULL; + ext->btns_pos = LV_TABVIEW_BTNS_POS_TOP; + ext->anim_time = LV_TABVIEW_ANIM_TIME; + ext->btns_hide = 0; + + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_tabview, lv_tabview_signal); + + /*Init the new tab tab*/ + if(copy == NULL) { + ext->tab_name_ptr = lv_mem_alloc(sizeof(char *)); + lv_mem_assert(ext->tab_name_ptr); + if(ext->tab_name_ptr == NULL) return NULL; + ext->tab_name_ptr[0] = ""; + ext->tab_cnt = 0; + + lv_obj_set_size(new_tabview, LV_HOR_RES, LV_VER_RES); + + ext->btns = lv_btnm_create(new_tabview, NULL); + lv_obj_set_height(ext->btns, 3 * LV_DPI / 4); + lv_btnm_set_map(ext->btns, tab_def); + lv_btnm_set_action(ext->btns, tab_btnm_action); + lv_btnm_set_toggle(ext->btns, true, 0); + + ext->indic = lv_obj_create(ext->btns, NULL); + lv_obj_set_width(ext->indic, LV_DPI); + lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_set_click(ext->indic, false); + + ext->content = lv_cont_create(new_tabview, NULL); + lv_cont_set_fit(ext->content, true, false); + lv_cont_set_layout(ext->content, LV_LAYOUT_ROW_T); + lv_cont_set_style(ext->content, &lv_style_transp_tight); + lv_obj_set_height(ext->content, LV_VER_RES - lv_obj_get_height(ext->btns)); + lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, th->tabview.bg); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, th->tabview.indic); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, th->tabview.btn.bg); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_REL, th->tabview.btn.rel); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_PR, th->tabview.btn.pr); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_REL, th->tabview.btn.tgl_rel); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_PR, th->tabview.btn.tgl_pr); + } else { + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, &lv_style_plain); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, &lv_style_transp); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, &lv_style_plain_color); + } + } + /*Copy an existing tab view*/ + else { + lv_tabview_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->point_last.x = 0; + ext->point_last.y = 0; + ext->btns = lv_btnm_create(new_tabview, copy_ext->btns); + ext->indic = lv_obj_create(ext->btns, copy_ext->indic); + ext->content = lv_cont_create(new_tabview, copy_ext->content); + ext->anim_time = copy_ext->anim_time; + ext->tab_load_action = copy_ext->tab_load_action; + + ext->tab_name_ptr = lv_mem_alloc(sizeof(char *)); + lv_mem_assert(ext->tab_name_ptr); + if(ext->tab_name_ptr == NULL) return NULL; + ext->tab_name_ptr[0] = ""; + lv_btnm_set_map(ext->btns, ext->tab_name_ptr); + + uint16_t i; + lv_obj_t * new_tab; + lv_obj_t * copy_tab; + for(i = 0; i < copy_ext->tab_cnt; i++) { + new_tab = lv_tabview_add_tab(new_tabview, copy_ext->tab_name_ptr[i]); + copy_tab = lv_tabview_get_tab(copy, i); + lv_page_set_style(new_tab, LV_PAGE_STYLE_BG, lv_page_get_style(copy_tab, LV_PAGE_STYLE_BG)); + lv_page_set_style(new_tab, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy_tab, LV_PAGE_STYLE_SCRL)); + lv_page_set_style(new_tab, LV_PAGE_STYLE_SB, lv_page_get_style(copy_tab, LV_PAGE_STYLE_SB)); + } + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_tabview); + } + + + LV_LOG_INFO("tab view created"); + + return new_tabview; +} + +/** + * Delete all children of the scrl object, without deleting scrl child. + * @param obj pointer to an object + */ +void lv_tabview_clean(lv_obj_t * obj) +{ + lv_obj_t * scrl = lv_page_get_scrl(obj); + lv_obj_clean(scrl); +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add a new tab with the given name + * @param tabview pointer to Tab view object where to ass the new tab + * @param name the text on the tab button + * @return pointer to the created page object (lv_page). You can create your content here + */ +lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + + /*Create the container page*/ + lv_obj_t * h = lv_page_create(ext->content, NULL); + lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(ext->content)); + lv_page_set_sb_mode(h, LV_SB_MODE_OFF); // Important! + lv_page_set_style(h, LV_PAGE_STYLE_BG, &lv_style_transp); + lv_page_set_style(h, LV_PAGE_STYLE_SCRL, &lv_style_transp); + + if(page_signal == NULL) page_signal = lv_obj_get_signal_func(h); + if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(h)); + lv_obj_set_signal_func(h, tabpage_signal); + lv_obj_set_signal_func(lv_page_get_scrl(h), tabpage_scrl_signal); + + /*Extend the button matrix map with the new name*/ + char * name_dm; + if((name[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) { /*If control byte presented let is*/ + name_dm = lv_mem_alloc(strlen(name) + 1); /*+1 for the the closing '\0' */ + lv_mem_assert(name_dm); + if(name_dm == NULL) return NULL; + strcpy(name_dm, name); + } else { /*Set a no long press control byte is not presented*/ + name_dm = lv_mem_alloc(strlen(name) + 2); /*+1 for the the closing '\0' and +1 for the control byte */ + lv_mem_assert(name_dm); + if(name_dm == NULL) return NULL; + name_dm[0] = '\221'; + strcpy(&name_dm[1], name); + } + + ext->tab_cnt++; + ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1)); + lv_mem_assert(ext->tab_name_ptr); + if(ext->tab_name_ptr == NULL) return NULL; + + ext->tab_name_ptr[ext->tab_cnt - 1] = name_dm; + ext->tab_name_ptr[ext->tab_cnt] = ""; + + lv_btnm_set_map(ext->btns, ext->tab_name_ptr); + + /*Modify the indicator size*/ + lv_style_t * style_tabs = lv_obj_get_style(ext->btns); + lv_coord_t indic_width = (lv_obj_get_width(tabview) - style_tabs->body.padding.inner * (ext->tab_cnt - 1) - 2 * style_tabs->body.padding.hor) / ext->tab_cnt; + lv_obj_set_width(ext->indic, indic_width); + lv_obj_set_x(ext->indic, indic_width * ext->tab_cur + style_tabs->body.padding.inner * ext->tab_cur + style_tabs->body.padding.hor); + + /*Set the first btn as active*/ + if(ext->tab_cnt == 1) { + ext->tab_cur = 0; + lv_tabview_set_tab_act(tabview, 0, false); + tabview_realign(tabview); /*To set the proper btns height*/ + } + + return h; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new tab + * @param tabview pointer to Tab view object + * @param id index of a tab to load + * @param anim_en true: set with sliding animation; false: set immediately + */ +void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en) +{ +#if USE_LV_ANIMATION == 0 + anim_en = false; +#endif + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + + lv_style_t * style = lv_obj_get_style(ext->content); + + lv_res_t res = LV_RES_OK; + if(id >= ext->tab_cnt) id = ext->tab_cnt - 1; + if(ext->tab_load_action && id != ext->tab_cur) res = ext->tab_load_action(tabview, id); + if(res != LV_RES_OK) return; /*Prevent the tab loading*/ + + ext->tab_cur = id; + + lv_coord_t cont_x = -(lv_obj_get_width(tabview) * id + style->body.padding.inner * id + style->body.padding.hor); + if(ext->anim_time == 0 || anim_en == false) { + lv_obj_set_x(ext->content, cont_x); + } else { +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = ext->content; + a.start = lv_obj_get_x(ext->content); + a.end = cont_x; + a.fp = (lv_anim_fp_t)lv_obj_set_x; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = ext->anim_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#endif + } + + /*Move the indicator*/ + lv_coord_t indic_width = lv_obj_get_width(ext->indic); + lv_style_t * tabs_style = lv_obj_get_style(ext->btns); + lv_coord_t indic_x = indic_width * id + tabs_style->body.padding.inner * id + tabs_style->body.padding.hor; + + if(ext->anim_time == 0 || anim_en == false) { + lv_obj_set_x(ext->indic, indic_x); + } else { +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = ext->indic; + a.start = lv_obj_get_x(ext->indic); + a.end = indic_x; + a.fp = (lv_anim_fp_t)lv_obj_set_x; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = ext->anim_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#endif + } + + lv_btnm_set_toggle(ext->btns, true, ext->tab_cur); +} + +/** + * Set an action to call when a tab is loaded (Good to create content only if required) + * lv_tabview_get_act() still gives the current (old) tab (to remove content from here) + * @param tabview pointer to a tabview object + * @param action pointer to a function to call when a btn is loaded + */ +void lv_tabview_set_tab_load_action(lv_obj_t * tabview, lv_tabview_action_t action) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + ext->tab_load_action = action; +} + +/** + * Enable horizontal sliding with touch pad + * @param tabview pointer to Tab view object + * @param en true: enable sliding; false: disable sliding + */ +void lv_tabview_set_sliding(lv_obj_t * tabview, bool en) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + ext->slide_enable = en == false ? 0 : 1; +} + +/** + * Set the animation time of tab view when a new tab is loaded + * @param tabview pointer to Tab view object + * @param anim_time_ms time of animation in milliseconds + */ +void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); +#if USE_LV_ANIMATION == 0 + anim_time = 0; +#endif + ext->anim_time = anim_time; +} + +/** + * Set the style of a tab view + * @param tabview pointer to a tan view object + * @param type which style should be set + * @param style pointer to the new style + */ +void lv_tabview_set_style(lv_obj_t * tabview, lv_tabview_style_t type, lv_style_t * style) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + + switch(type) { + case LV_TABVIEW_STYLE_BG: + lv_obj_set_style(tabview, style); + break; + case LV_TABVIEW_STYLE_BTN_BG: + lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BG, style); + tabview_realign(tabview); + break; + case LV_TABVIEW_STYLE_BTN_REL: + lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_REL, style); + tabview_realign(tabview); + break; + case LV_TABVIEW_STYLE_BTN_PR: + lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_PR, style); + break; + case LV_TABVIEW_STYLE_BTN_TGL_REL: + lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_REL, style); + break; + case LV_TABVIEW_STYLE_BTN_TGL_PR: + lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_PR, style); + break; + case LV_TABVIEW_STYLE_INDIC: + lv_obj_set_style(ext->indic, style); + lv_obj_set_height(ext->indic, style->body.padding.inner); + tabview_realign(tabview); + break; + } +} + +/** + * Set the position of tab select buttons + * @param tabview pointer to a tan view object + * @param btns_pos which button position + */ +void lv_tabview_set_btns_pos(lv_obj_t * tabview, lv_tabview_btns_pos_t btns_pos) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + + ext->btns_pos = btns_pos; + tabview_realign(tabview); +} + +/** + * Set whether tab buttons are hidden + * @param tabview pointer to a tab view object + * @param en whether tab buttons are hidden + */ +void lv_tabview_set_btns_hidden(lv_obj_t *tabview, bool en) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + + ext->btns_hide = en; + tabview_realign(tabview); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the index of the currently active tab + * @param tabview pointer to Tab view object + * @return the active btn index + */ +uint16_t lv_tabview_get_tab_act(const lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + return ext->tab_cur; +} + +/** + * Get the number of tabs + * @param tabview pointer to Tab view object + * @return btn count + */ +uint16_t lv_tabview_get_tab_count(const lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + return ext->tab_cnt; +} + +/** + * Get the page (content area) of a tab + * @param tabview pointer to Tab view object + * @param id index of the btn (>= 0) + * @return pointer to page (lv_page) object + */ +lv_obj_t * lv_tabview_get_tab(const lv_obj_t * tabview, uint16_t id) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + uint16_t i = 0; + lv_obj_t * page = lv_obj_get_child_back(ext->content, NULL); + + while(page != NULL && i != id) { + i++; + page = lv_obj_get_child_back(ext->content, page); + } + + if(i == id) return page; + + return NULL; +} + +/** + * Get the tab load action + * @param tabview pointer to a tabview object + * @param return the current btn load action + */ +lv_tabview_action_t lv_tabview_get_tab_load_action(const lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + return ext->tab_load_action; +} + +/** + * Get horizontal sliding is enabled or not + * @param tabview pointer to Tab view object + * @return true: enable sliding; false: disable sliding + */ +bool lv_tabview_get_sliding(const lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + return ext->slide_enable ? true : false; +} + +/** + * Get the animation time of tab view when a new tab is loaded + * @param tabview pointer to Tab view object + * @return time of animation in milliseconds + */ +uint16_t lv_tabview_get_anim_time(const lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + return ext->anim_time; +} + +/** + * Get a style of a tab view + * @param tabview pointer to a ab view object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_tabview_get_style(const lv_obj_t * tabview, lv_tabview_style_t type) +{ + lv_style_t * style = NULL; + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + + switch(type) { + case LV_TABVIEW_STYLE_BG: + style = lv_obj_get_style(tabview); + break; + case LV_TABVIEW_STYLE_BTN_BG: + style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BG); + break; + case LV_TABVIEW_STYLE_BTN_REL: + style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_REL); + break; + case LV_TABVIEW_STYLE_BTN_PR: + style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_PR); + break; + case LV_TABVIEW_STYLE_BTN_TGL_REL: + style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_REL); + break; + case LV_TABVIEW_STYLE_BTN_TGL_PR: + style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_PR); + break; + default: + style = NULL; + break; + } + + return style; +} + +/** + * Get position of tab select buttons + * @param tabview pointer to a ab view object + */ +lv_tabview_btns_pos_t lv_tabview_get_btns_pos(const lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + return ext->btns_pos; +} + +/** + * Get whether tab buttons are hidden + * @param tabview pointer to a tab view object + * @return whether tab buttons are hidden + */ +bool lv_tabview_get_btns_hidden(const lv_obj_t *tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + + return ext->btns_hide; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the Tab view + * @param tabview pointer to a Tab view object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(tabview, sign, param); + if(res != LV_RES_OK) return res; + + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + if(sign == LV_SIGNAL_CLEANUP) { + uint8_t i; + for(i = 0; ext->tab_name_ptr[i][0] != '\0'; i++) lv_mem_free(ext->tab_name_ptr[i]); + + lv_mem_free(ext->tab_name_ptr); + ext->tab_name_ptr = NULL; + ext->btns = NULL; /*These objects were children so they are already invalid*/ + ext->content = NULL; + } else if(sign == LV_SIGNAL_CORD_CHG) { + if(ext->content != NULL && + (lv_obj_get_width(tabview) != lv_area_get_width(param) || + lv_obj_get_height(tabview) != lv_area_get_height(param))) { + tabview_realign(tabview); + } + } else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROLL) { + /* The button matrix is not in a group (the tab view is in it) but it should handle the group signals. + * So propagate the related signals to the button matrix manually*/ + if(ext->btns) { + ext->btns->signal_func(ext->btns, sign, param); + } + if(sign == LV_SIGNAL_FOCUS) { + lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + /*With ENCODER select the first button only in edit mode*/ + if(indev_type == LV_INDEV_TYPE_ENCODER) { +#if USE_LV_GROUP + lv_group_t * g = lv_obj_get_group(tabview); + if(lv_group_get_editing(g)) { + lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns); + btnm_ext->btn_id_pr = 0; + lv_obj_invalidate(ext->btns); + } +#endif + } else { + lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns); + btnm_ext->btn_id_pr = 0; + lv_obj_invalidate(ext->btns); + } + } + } else if(sign == LV_SIGNAL_GET_EDITABLE) { + bool * editable = (bool *)param; + *editable = true; + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_tabview"; + } + + return res; +} + + +/** + * Signal function of a tab's page + * @param tab pointer to a tab page object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = page_signal(tab_page, sign, param); + if(res != LV_RES_OK) return res; + + lv_obj_t * cont = lv_obj_get_parent(tab_page); + lv_obj_t * tabview = lv_obj_get_parent(cont); + + if(lv_tabview_get_sliding(tabview) == false) return res; + + if(sign == LV_SIGNAL_PRESSED) { + tabpage_pressed_handler(tabview, tab_page); + } else if(sign == LV_SIGNAL_PRESSING) { + tabpage_pressing_handler(tabview, tab_page); + } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { + tabpage_press_lost_handler(tabview, tab_page); + } + + return res; +} +/** + * Signal function of the tab page's scrollable object + * @param tab_scrl pointer to a tab page's scrollable object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t tabpage_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = page_scrl_signal(tab_scrl, sign, param); + if(res != LV_RES_OK) return res; + + lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl); + lv_obj_t * cont = lv_obj_get_parent(tab_page); + lv_obj_t * tabview = lv_obj_get_parent(cont); + + if(lv_tabview_get_sliding(tabview) == false) return res; + + if(sign == LV_SIGNAL_PRESSED) { + tabpage_pressed_handler(tabview, tab_page); + } else if(sign == LV_SIGNAL_PRESSING) { + tabpage_pressing_handler(tabview, tab_page); + } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { + tabpage_press_lost_handler(tabview, tab_page); + } + + return res; +} + +/** + * Called when a tab's page or scrollable object is pressed + * @param tabview pointer to the btn view object + * @param tabpage pointer to the page of a btn + */ +static void tabpage_pressed_handler(lv_obj_t * tabview, lv_obj_t * tabpage) +{ + (void)tabpage; + + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + lv_indev_t * indev = lv_indev_get_act(); + lv_indev_get_point(indev, &ext->point_last); +} + +/** + * Called when a tab's page or scrollable object is being pressed + * @param tabview pointer to the btn view object + * @param tabpage pointer to the page of a btn + */ +static void tabpage_pressing_handler(lv_obj_t * tabview, lv_obj_t * tabpage) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + lv_indev_t * indev = lv_indev_get_act(); + lv_point_t point_act; + lv_indev_get_point(indev, &point_act); + lv_coord_t x_diff = point_act.x - ext->point_last.x; + lv_coord_t y_diff = point_act.y - ext->point_last.y; + + if(ext->draging == 0) { + if(x_diff >= LV_INDEV_DRAG_LIMIT || x_diff <= -LV_INDEV_DRAG_LIMIT) { + ext->drag_hor = 1; + ext->draging = 1; + lv_obj_set_drag(lv_page_get_scrl(tabpage), false); + } else if(y_diff >= LV_INDEV_DRAG_LIMIT || y_diff <= -LV_INDEV_DRAG_LIMIT) { + ext->drag_hor = 0; + ext->draging = 1; + } + } + if(ext->drag_hor) { + lv_obj_set_x(ext->content, lv_obj_get_x(ext->content) + point_act.x - ext->point_last.x); + ext->point_last.x = point_act.x; + ext->point_last.y = point_act.y; + + /*Move the indicator*/ + lv_coord_t indic_width = lv_obj_get_width(ext->indic); + lv_style_t * tabs_style = lv_obj_get_style(ext->btns); + lv_style_t * indic_style = lv_obj_get_style(ext->indic); + lv_coord_t p = ((tabpage->coords.x1 - tabview->coords.x1) * (indic_width + tabs_style->body.padding.inner)) / lv_obj_get_width(tabview); + + lv_obj_set_x(ext->indic, indic_width * ext->tab_cur + tabs_style->body.padding.inner * ext->tab_cur + indic_style->body.padding.hor - p); + } +} + +/** + * Called when a tab's page or scrollable object is released or the press id lost + * @param tabview pointer to the btn view object + * @param tabpage pointer to the page of a btn + */ +static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + ext->drag_hor = 0; + ext->draging = 0; + + lv_obj_set_drag(lv_page_get_scrl(tabpage), true); + + lv_indev_t * indev = lv_indev_get_act(); + lv_point_t point_act; + lv_indev_get_point(indev, &point_act); + lv_point_t vect; + lv_indev_get_vect(indev, &vect); + lv_coord_t x_predict = 0; + + while(vect.x != 0) { + x_predict += vect.x; + vect.x = vect.x * (100 - LV_INDEV_DRAG_THROW) / 100; + } + + lv_coord_t page_x1 = tabpage->coords.x1 - tabview->coords.x1 + x_predict; + lv_coord_t page_x2 = page_x1 + lv_obj_get_width(tabpage); + lv_coord_t treshold = lv_obj_get_width(tabview) / 2; + + uint16_t tab_cur = ext->tab_cur; + if(page_x1 > treshold) { + if(tab_cur != 0) tab_cur--; + } else if(page_x2 < treshold) { + if(tab_cur < ext->tab_cnt - 1) tab_cur++; + } + + lv_tabview_set_tab_act(tabview, tab_cur, true); +} + +/** + * Called when a tab button is released + * @param tab_btnm pointer to the tab's button matrix object + * @param id the id of the tab (>= 0) + * @return LV_ACTION_RES_OK because the button matrix in not deleted in the function + */ +static lv_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name) +{ + lv_obj_t * tab = lv_obj_get_parent(tab_btnm); + const char ** tabs_map = lv_btnm_get_map(tab_btnm); + + uint8_t i = 0; + + while(tabs_map[i][0] != '\0') { + if(strcmp(&tabs_map[i][1], tab_name) == 0) break; /*[1] to skip the control byte*/ + i++; + } + + lv_tabview_set_tab_act(tab, i, true); + + return LV_RES_OK; +} + +/** + * Realign and resize the elements of Tab view + * @param tabview pointer to a Tab view object + */ +static void tabview_realign(lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + + lv_obj_set_width(ext->btns, lv_obj_get_width(tabview)); + + if(ext->btns_hide) { + lv_obj_set_hidden(ext->btns, true); + lv_obj_set_hidden(ext->indic, true); + lv_obj_set_height(ext->content, lv_obj_get_height(tabview)); + lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + } + else if(ext->tab_cnt != 0) { + lv_obj_set_hidden(ext->btns, false); + lv_obj_set_hidden(ext->indic, false); + + lv_style_t * style_btn_bg = lv_tabview_get_style(tabview, LV_TABVIEW_STYLE_BTN_BG); + lv_style_t * style_btn_rel = lv_tabview_get_style(tabview, LV_TABVIEW_STYLE_BTN_REL); + + /*Set the indicator widths*/ + lv_coord_t indic_width = (lv_obj_get_width(tabview) - style_btn_bg->body.padding.inner * (ext->tab_cnt - 1) - + 2 * style_btn_bg->body.padding.hor) / ext->tab_cnt; + lv_obj_set_width(ext->indic, indic_width); + + /*Set the tabs height*/ + lv_coord_t btns_height = lv_font_get_height(style_btn_rel->text.font) + + 2 * style_btn_rel->body.padding.ver + + 2 * style_btn_bg->body.padding.ver; + lv_obj_set_height(ext->btns, btns_height); + + lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns)); + + switch(ext->btns_pos) { + case LV_TABVIEW_BTNS_POS_TOP: + lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + break; + case LV_TABVIEW_BTNS_POS_BOTTOM: + lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_obj_align(ext->btns, ext->content, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + break; + } + } + + lv_obj_t * pages = lv_obj_get_child(ext->content, NULL); + while(pages != NULL) { + if(lv_obj_get_signal_func(pages) == tabpage_signal) { /*Be sure adjust only the pages (user can other things)*/ + lv_obj_set_size(pages, lv_obj_get_width(tabview), lv_obj_get_height(ext->content)); + } + pages = lv_obj_get_child(ext->content, pages); + } + + if(!ext->btns_hide) { + lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + } + + lv_tabview_set_tab_act(tabview, ext->tab_cur, false); +} +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.h new file mode 100644 index 0000000..2d60c3c --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tabview.h @@ -0,0 +1,252 @@ +/** + * @file lv_tabview.h + * + */ + +#ifndef LV_TABVIEW_H +#define LV_TABVIEW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_TABVIEW != 0 + +/*Testing of dependencies*/ +#if USE_LV_BTNM == 0 +#error "lv_tabview: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " +#endif + +#if USE_LV_PAGE == 0 +#error "lv_tabview: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "../lv_objx/lv_win.h" +#include "../lv_objx/lv_page.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/* parametes: pointer to a tabview object, tab_id + * return: LV_RES_INV: to prevent the loading of the tab; LV_RES_OK: if everything is fine*/ +typedef lv_res_t (*lv_tabview_action_t)(lv_obj_t *, uint16_t); + + +enum { + LV_TABVIEW_BTNS_POS_TOP, + LV_TABVIEW_BTNS_POS_BOTTOM, +}; +typedef uint8_t lv_tabview_btns_pos_t; + +/*Data of tab*/ +typedef struct +{ + /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t * btns; + lv_obj_t * indic; + lv_obj_t * content; /*A rectangle to show the current tab*/ + const char ** tab_name_ptr; + lv_point_t point_last; + uint16_t tab_cur; + uint16_t tab_cnt; + uint16_t anim_time; + uint8_t slide_enable :1; /*1: enable horizontal sliding by touch pad*/ + uint8_t draging :1; + uint8_t drag_hor :1; + uint8_t btns_hide :1; + lv_tabview_btns_pos_t btns_pos :1; + lv_tabview_action_t tab_load_action; +} lv_tabview_ext_t; + +enum { + LV_TABVIEW_STYLE_BG, + LV_TABVIEW_STYLE_INDIC, + LV_TABVIEW_STYLE_BTN_BG, + LV_TABVIEW_STYLE_BTN_REL, + LV_TABVIEW_STYLE_BTN_PR, + LV_TABVIEW_STYLE_BTN_TGL_REL, + LV_TABVIEW_STYLE_BTN_TGL_PR, +}; +typedef uint8_t lv_tabview_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + + +/** + * Create a Tab view object + * @param par pointer to an object, it will be the parent of the new tab + * @param copy pointer to a tab object, if not NULL then the new object will be copied from it + * @return pointer to the created tab + */ +lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy); + +/** + * Delete all children of the scrl object, without deleting scrl child. + * @param obj pointer to an object + */ +void lv_tabview_clean(lv_obj_t *obj); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add a new tab with the given name + * @param tabview pointer to Tab view object where to ass the new tab + * @param name the text on the tab button + * @return pointer to the created page object (lv_page). You can create your content here + */ +lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new tab + * @param tabview pointer to Tab view object + * @param id index of a tab to load + * @param anim_en true: set with sliding animation; false: set immediately + */ +void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en); + +/** + * Set an action to call when a tab is loaded (Good to create content only if required) + * lv_tabview_get_act() still gives the current (old) tab (to remove content from here) + * @param tabview pointer to a tabview object + * @param action pointer to a function to call when a tab is loaded + */ +void lv_tabview_set_tab_load_action(lv_obj_t *tabview, lv_tabview_action_t action); + +/** + * Enable horizontal sliding with touch pad + * @param tabview pointer to Tab view object + * @param en true: enable sliding; false: disable sliding + */ +void lv_tabview_set_sliding(lv_obj_t * tabview, bool en); + +/** + * Set the animation time of tab view when a new tab is loaded + * @param tabview pointer to Tab view object + * @param anim_time time of animation in milliseconds + */ +void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time); + +/** + * Set the style of a tab view + * @param tabview pointer to a tan view object + * @param type which style should be set + * @param style pointer to the new style + */ +void lv_tabview_set_style(lv_obj_t *tabview, lv_tabview_style_t type, lv_style_t *style); + +/** + * Set the position of tab select buttons + * @param tabview pointer to a tab view object + * @param btns_pos which button position + */ +void lv_tabview_set_btns_pos(lv_obj_t *tabview, lv_tabview_btns_pos_t btns_pos); + +/** + * Set whether tab buttons are hidden + * @param tabview pointer to a tab view object + * @param en whether tab buttons are hidden + */ +void lv_tabview_set_btns_hidden(lv_obj_t *tabview, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the index of the currently active tab + * @param tabview pointer to Tab view object + * @return the active tab index + */ +uint16_t lv_tabview_get_tab_act(const lv_obj_t * tabview); + +/** + * Get the number of tabs + * @param tabview pointer to Tab view object + * @return tab count + */ +uint16_t lv_tabview_get_tab_count(const lv_obj_t * tabview); +/** + * Get the page (content area) of a tab + * @param tabview pointer to Tab view object + * @param id index of the tab (>= 0) + * @return pointer to page (lv_page) object + */ +lv_obj_t * lv_tabview_get_tab(const lv_obj_t * tabview, uint16_t id); + +/** + * Get the tab load action + * @param tabview pointer to a tabview object + * @param return the current tab load action + */ +lv_tabview_action_t lv_tabview_get_tab_load_action(const lv_obj_t *tabview); + +/** + * Get horizontal sliding is enabled or not + * @param tabview pointer to Tab view object + * @return true: enable sliding; false: disable sliding + */ +bool lv_tabview_get_sliding(const lv_obj_t * tabview); + +/** + * Get the animation time of tab view when a new tab is loaded + * @param tabview pointer to Tab view object + * @return time of animation in milliseconds + */ +uint16_t lv_tabview_get_anim_time(const lv_obj_t * tabview); + +/** + * Get a style of a tab view + * @param tabview pointer to a ab view object + * @param type which style should be get + * @return style pointer to a style + */ +lv_style_t * lv_tabview_get_style(const lv_obj_t *tabview, lv_tabview_style_t type); + +/** + * Get position of tab select buttons + * @param tabview pointer to a ab view object + */ +lv_tabview_btns_pos_t lv_tabview_get_btns_pos(const lv_obj_t *tabview); + +/** + * Get whether tab buttons are hidden + * @param tabview pointer to a tab view object + * @return whether tab buttons are hidden + */ +bool lv_tabview_get_btns_hidden(const lv_obj_t *tabview); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_TABVIEW*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TABVIEW_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.c new file mode 100644 index 0000000..7435a9b --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.c @@ -0,0 +1,578 @@ +/** + * @file lv_tileview.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_tileview.h" +#if USE_LV_TILEVIEW != 0 + +#include "lv_cont.h" +#include "../lv_themes/lv_theme.h" + +/********************* + * DEFINES + *********************/ +#if USE_LV_ANIMATION +# ifndef LV_TILEVIEW_ANIM_TIME +# define LV_TILEVIEW_ANIM_TIME 300 /*Animation time loading a tile [ms] (0: no animation) */ +# endif +#else +# undef LV_TILEVIEW_ANIM_TIME +# define LV_TILEVIEW_ANIM_TIME 0 /*No animations*/ +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_tileview_signal(lv_obj_t * tileview, lv_signal_t sign, void * param); +static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); +static lv_res_t element_signal_func(lv_obj_t * element, lv_signal_t sign, void * param); +static void drag_end_handler(lv_obj_t * tileview); +static bool set_valid_drag_dirs(lv_obj_t * tileview); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_signal_func_t ancestor_scrl_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a tileview object + * @param par pointer to an object, it will be the parent of the new tileview + * @param copy pointer to a tileview object, if not NULL then the new object will be copied from it + * @return pointer to the created tileview + */ +lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("tileview create started"); + + /*Create the ancestor of tileview*/ + lv_obj_t * new_tileview = lv_page_create(par, copy); + lv_mem_assert(new_tileview); + if(new_tileview == NULL) return NULL; + + /*Allocate the tileview type specific extended data*/ + lv_tileview_ext_t * ext = lv_obj_allocate_ext_attr(new_tileview, sizeof(lv_tileview_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_tileview); + if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_tileview)); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_tileview); + + /*Initialize the allocated 'ext' */ + ext->anim_time = LV_TILEVIEW_ANIM_TIME; + ext->action = NULL; + ext->act_id.x = 0; + ext->act_id.y = 0; + ext->valid_pos = NULL; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_tileview, lv_tileview_signal); + lv_obj_set_signal_func(lv_page_get_scrl(new_tileview), lv_tileview_scrl_signal); + + /*Init the new tileview*/ + if(copy == NULL) { + lv_obj_set_size(new_tileview, LV_HOR_RES, LV_VER_RES); + lv_obj_set_drag_throw(lv_page_get_scrl(new_tileview), false); + lv_page_set_scrl_fit(new_tileview, true, true); + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_page_set_style(new_tileview, LV_PAGE_STYLE_BG, th->tileview.bg); + lv_page_set_style(new_tileview, LV_PAGE_STYLE_SCRL, th->tileview.scrl); + lv_page_set_style(new_tileview, LV_PAGE_STYLE_SB, th->tileview.sb); + } else { + lv_page_set_style(new_tileview, LV_PAGE_STYLE_BG, &lv_style_transp_tight); + lv_page_set_style(new_tileview, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); + } + } + /*Copy an existing tileview*/ + else { + lv_tileview_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + ext->act_id.x = copy_ext->act_id.x; + ext->act_id.y = copy_ext->act_id.y; + ext->action = copy_ext->action; + ext->anim_time = copy_ext->anim_time; + + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_tileview); + } + + LV_LOG_INFO("tileview created"); + + return new_tileview; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Register an object on the tileview. The register object will able to slide the tileview + * @param element pointer to an object + */ +void lv_tileview_add_element(lv_obj_t * element) +{ + lv_obj_set_free_ptr(element, lv_obj_get_signal_func(element)); + lv_obj_set_signal_func(element, element_signal_func); + lv_obj_set_drag_parent(element, true); +} + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the valid position's indices. The scrolling will be possible only to these positions. + * @param tileview pointer to a Tileview object + * @param valid_pos array width the indices. E.g. `lv_point_t p[] = {{0,0}, {1,0}, {1,1}, {LV_COORD_MIN, LV_COORD_MIN}};` + * Must be closed with `{LV_COORD_MIN, LV_COORD_MIN}`. Only the pointer is saved so can't be a local variable. + */ +void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos) +{ + lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); + ext->valid_pos = valid_pos; +} + +/** + * Set the tile to be shown + * @param tileview pointer to a tileview object + * @param x column id (0, 1, 2...) + * @param y line id (0, 1, 2...) + * @param anim_en true: move with animation + */ +void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, bool anim_en) +{ +#if USE_LV_ANIMATION == 0 + anim_en = false; +#endif + + lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); + + + uint16_t i; + bool valid = false; + for(i = 0; ext->valid_pos[i].x != LV_COORD_MIN; i++) { + if(ext->valid_pos[i].x == x && ext->valid_pos[i].y == y) { + valid = true; + } + } + + if(valid == false) return; /*Don't load not valid tiles*/ + + lv_res_t res = LV_RES_OK; + if(ext->action) res = ext->action(tileview, x, y); + if(res != LV_RES_OK) return; /*Prevent the tile loading*/ + + ext->act_id.x = x; + ext->act_id.y = y; + + lv_coord_t x_coord = -x * lv_obj_get_width(tileview); + lv_coord_t y_coord = -y * lv_obj_get_height(tileview); + lv_obj_t * scrl = lv_page_get_scrl(tileview); + if(anim_en) { +#if USE_LV_ANIMATION + lv_coord_t x_act = lv_obj_get_x(scrl); + lv_coord_t y_act = lv_obj_get_y(scrl); + + lv_anim_t a; + a.var = scrl; + a.fp = (lv_anim_fp_t)lv_obj_set_x; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = ext->anim_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + + if(x_coord != x_act) { + a.start = x_act; + a.end = x_coord; + lv_anim_create(&a); + } + + if(y_coord != y_act) { + a.start = y_act; + a.end = y_coord; + a.fp = (lv_anim_fp_t)lv_obj_set_y; + lv_anim_create(&a); + } +#endif + } else { + lv_obj_set_pos(scrl, x_coord, y_coord); + } +} + +void lv_tileview_set_tile_load_action(lv_obj_t * tileview, lv_tileview_action_t action) +{ + lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); + ext->action = action; + +} + +/** + * Set a style of a tileview. + * @param tileview pointer to tileview object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, lv_style_t * style) +{ + + switch(type) { + case LV_TILEVIEW_STYLE_BG: + lv_obj_set_style(tileview, style); + break; + } +} + +/*===================== + * Getter functions + *====================*/ + +/* + * New object specific "get" functions come here + */ + +/** + * Get style of a tileview. + * @param tileview pointer to tileview object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_tileview_get_style(const lv_obj_t * tileview, lv_tileview_style_t type) +{ + lv_style_t * style = NULL; + switch(type) { + case LV_TILEVIEW_STYLE_BG: + style = lv_obj_get_style(tileview); + break; + default: + style = NULL; + } + + return style; +} + +/*===================== + * Other functions + *====================*/ + +/* + * New object specific "other" functions come here + */ + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the tileview + * @param tileview pointer to a tileview object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_tileview_signal(lv_obj_t * tileview, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(tileview, sign, param); + if(res != LV_RES_OK) return res; + + + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_tileview"; + } + + return res; +} + +/** + * Signal function of the tileview scrollable + * @param tileview pointer to the scrollable part of the tileview object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) +{ + + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_scrl_signal(scrl, sign, param); + if(res != LV_RES_OK) return res; + + lv_obj_t * tileview = lv_obj_get_parent(scrl); + lv_style_t * style_bg = lv_tileview_get_style(tileview, LV_TILEVIEW_STYLE_BG); + + + /*Apply constraint on moving of the tileview*/ + if(sign == LV_SIGNAL_CORD_CHG) { + lv_indev_t * indev = lv_indev_get_act(); + if(indev) { + lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); + + /*Set horizontal drag constraint if no vertical constraint an dragged to valid x direction */ + if(ext->drag_ver == 0 && + ((ext->drag_right_en && indev->proc.drag_sum.x <= -LV_INDEV_DRAG_LIMIT) || + (ext->drag_left_en && indev->proc.drag_sum.x >= LV_INDEV_DRAG_LIMIT))) { + ext->drag_hor = 1; + } + /*Set vertical drag constraint if no horizontal constraint an dragged to valid y direction */ + if(ext->drag_hor == 0 && + ((ext->drag_bottom_en && indev->proc.drag_sum.y <= -LV_INDEV_DRAG_LIMIT) || + (ext->drag_top_en && indev->proc.drag_sum.y >= LV_INDEV_DRAG_LIMIT))) { + ext->drag_ver = 1; + } + + if(ext->drag_hor) { + ext->page.edge_flash.top_ip = 0; + ext->page.edge_flash.bottom_ip = 0; + } + + if(ext->drag_ver) { + ext->page.edge_flash.right_ip = 0; + ext->page.edge_flash.left_ip = 0; + } + + lv_coord_t x = lv_obj_get_x(scrl); + lv_coord_t y = lv_obj_get_y(scrl); + lv_coord_t h = lv_obj_get_height(tileview); + lv_coord_t w = lv_obj_get_width(tileview); + if(ext->drag_top_en == 0) { + if(y > -(ext->act_id.y * h) && indev->proc.vect.y > 0 && ext->drag_hor == 0) { + if(ext->page.edge_flash.enabled && + ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 && + ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) { + ext->page.edge_flash.top_ip = 1; + lv_page_start_edge_flash(tileview); + } + + lv_obj_set_y(scrl, -ext->act_id.y * h + style_bg->body.padding.ver); + } + } + if(ext->drag_bottom_en == 0 && indev->proc.vect.y < 0 && ext->drag_hor == 0) { + if(y < -(ext->act_id.y * h)) { + if(ext->page.edge_flash.enabled && + ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 && + ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) { + ext->page.edge_flash.bottom_ip = 1; + lv_page_start_edge_flash(tileview); + } + } + + lv_obj_set_y(scrl, -ext->act_id.y * h + style_bg->body.padding.ver); + } + if(ext->drag_left_en == 0) { + if(x > -(ext->act_id.x * w) && indev->proc.vect.x > 0 && ext->drag_ver == 0) { + if(ext->page.edge_flash.enabled && + ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 && + ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) { + ext->page.edge_flash.left_ip = 1; + lv_page_start_edge_flash(tileview); + } + + lv_obj_set_x(scrl, -ext->act_id.x * w + style_bg->body.padding.hor); + } + } + if(ext->drag_right_en == 0 && indev->proc.vect.x < 0 && ext->drag_ver == 0) { + if(x < -(ext->act_id.x * w)) { + if(ext->page.edge_flash.enabled && + ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 && + ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) { + ext->page.edge_flash.right_ip = 1; + lv_page_start_edge_flash(tileview); + } + } + + lv_obj_set_x(scrl, -ext->act_id.x * w + style_bg->body.padding.hor); + } + + /*Apply the drag constraints*/ + if(ext->drag_ver == 0) lv_obj_set_y(scrl, - ext->act_id.y * lv_obj_get_height(tileview) + style_bg->body.padding.ver); + if(ext->drag_hor == 0) lv_obj_set_x(scrl, - ext->act_id.x * lv_obj_get_width(tileview) + style_bg->body.padding.hor); + } + } + + return res; + +} + +/** + * This function is applied called for the elements of the tileview. Used when the element is + * @param element + * @param sign + * @param param + * @return + */ +static lv_res_t element_signal_func(lv_obj_t * element, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + lv_signal_func_t sign_func = lv_obj_get_free_ptr(element); + res = sign_func(element, sign, param); + if(res != LV_RES_OK) return res; + + /*Initialize some variables on PRESS*/ + if(sign == LV_SIGNAL_PRESSED) { + /*Get the tileview from the element*/ + lv_obj_t * tileview = lv_obj_get_parent(element); + while(tileview) { + if(lv_obj_get_signal_func(tileview) != lv_tileview_signal) tileview = lv_obj_get_parent(tileview); + else break; + } + + if(tileview) { + lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); + ext->drag_hor = 0; + ext->drag_ver = 0; + set_valid_drag_dirs(tileview); + } + } + + /*Animate the tabview to the correct location on RELEASE*/ + else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_RELEASED) { + + /*Get the tileview from the element*/ + lv_obj_t * tileview = lv_obj_get_parent(element); + while(tileview) { + if(lv_obj_get_signal_func(tileview) != lv_tileview_signal) tileview = lv_obj_get_parent(tileview); + else break; + } + + if(tileview) { + /* If the element was dragged and it moved the tileview finish the drag manually to + * let the tileview to finish the move.*/ + lv_indev_t * indev = lv_indev_get_act(); + lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); + if(indev->proc.drag_in_prog && (ext->drag_hor || ext->drag_ver)) { + + lv_obj_t * drag_obj = element; + while(lv_obj_get_drag_parent(drag_obj)) { + drag_obj = lv_obj_get_parent(drag_obj); + if(drag_obj == NULL) break; + } + indev->proc.drag_in_prog = 0; + if(drag_obj) drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, NULL); + } + + drag_end_handler(tileview); + } + } + + return res; +} + +/** + * Called when the user releases an element of the tileview after dragging it. + * @param tileview pointer to a tileview object + */ +static void drag_end_handler(lv_obj_t * tileview) +{ + lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); + lv_indev_t * indev = lv_indev_get_act(); + lv_point_t point_act; + lv_indev_get_point(indev, &point_act); + lv_obj_t * scrl = lv_page_get_scrl(tileview); + lv_point_t p; + + p.x = - (scrl->coords.x1 - LV_HOR_RES / 2); + p.y = - (scrl->coords.y1 - LV_VER_RES / 2); + + /*From the drag vector (drag throw) predict the end position*/ + if(ext->drag_hor) { + lv_point_t vect; + lv_indev_get_vect(indev, &vect); + lv_coord_t predict = 0; + + while(vect.x != 0) { + predict += vect.x; + vect.x = vect.x * (100 - LV_INDEV_DRAG_THROW) / 100; + } + + p.x -= predict; + } + else if(ext->drag_ver) { + lv_point_t vect; + lv_indev_get_vect(indev, &vect); + lv_coord_t predict = 0; + + while(vect.y != 0) { + predict += vect.y; + vect.y = vect.y * (100 - LV_INDEV_DRAG_THROW) / 100; + } + + p.y -= predict; + } + + /*Get the index of the tile*/ + p.x = p.x / lv_obj_get_width(tileview); + p.y = p.y / lv_obj_get_height(tileview); + + /*Max +- move*/ + lv_coord_t x_move = p.x - ext->act_id.x; + lv_coord_t y_move = p.y - ext->act_id.y; + if(x_move < -1) x_move = -1; + if(x_move > 1) x_move = 1; + if(y_move < -1) y_move = -1; + if(y_move > 1) y_move = 1; + + /*Set the new tile*/ + lv_tileview_set_tile_act(tileview, ext->act_id.x + x_move, ext->act_id.y + y_move,true); +} + +static bool set_valid_drag_dirs(lv_obj_t * tileview) +{ + + lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); + if(ext->valid_pos == NULL) return false; + + ext->drag_bottom_en = 0; + ext->drag_top_en = 0; + ext->drag_left_en = 0; + ext->drag_right_en = 0; + + uint16_t i; + for(i = 0; ext->valid_pos[i].x != LV_COORD_MIN; i++) { + if(ext->valid_pos[i].x == ext->act_id.x && ext->valid_pos[i].y == ext->act_id.y - 1) ext->drag_top_en = 1; + if(ext->valid_pos[i].x == ext->act_id.x && ext->valid_pos[i].y == ext->act_id.y + 1) ext->drag_bottom_en = 1; + if(ext->valid_pos[i].x == ext->act_id.x - 1 && ext->valid_pos[i].y == ext->act_id.y) ext->drag_left_en = 1; + if(ext->valid_pos[i].x == ext->act_id.x + 1 && ext->valid_pos[i].y == ext->act_id.y) ext->drag_right_en = 1; + } + + return true; +} + + +#endif diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.h new file mode 100644 index 0000000..d276fea --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_tileview.h @@ -0,0 +1,163 @@ +/** + * @file lv_tileview.h + * + */ + + +#ifndef LV_TILEVIEW_H +#define LV_TILEVIEW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_TILEVIEW != 0 + +#include "../lv_objx/lv_page.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + + + +/* parametes: pointer to a tileview object, x, y (tile coordinates to load) + * return: LV_RES_INV: to prevent the loading of the tab; LV_RES_OK: if everything is fine*/ +typedef lv_res_t (*lv_tileview_action_t)(lv_obj_t *, lv_coord_t, lv_coord_t); + +/*Data of tileview*/ +typedef struct { + lv_page_ext_t page; + /*New data for this type */ + const lv_point_t * valid_pos; + uint16_t anim_time; + lv_tileview_action_t action; + lv_point_t act_id; + uint8_t drag_top_en :1; + uint8_t drag_bottom_en :1; + uint8_t drag_left_en :1; + uint8_t drag_right_en :1; + uint8_t drag_hor :1; + uint8_t drag_ver :1; +} lv_tileview_ext_t; + + +/*Styles*/ +enum { + LV_TILEVIEW_STYLE_BG, +}; +typedef uint8_t lv_tileview_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a tileview objects + * @param par pointer to an object, it will be the parent of the new tileview + * @param copy pointer to a tileview object, if not NULL then the new object will be copied from it + * @return pointer to the created tileview + */ +lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Register an object on the tileview. The register object will able to slide the tileview + * @param element pointer to an object + */ +void lv_tileview_add_element(lv_obj_t * element); + +/*===================== + * Setter functions + *====================*/ + + +/** + * Set the valid position's indices. The scrolling will be possible only to these positions. + * @param tileview pointer to a Tileview object + * @param valid_pos array width the indices. E.g. `lv_point_t p[] = {{0,0}, {1,0}, {1,1}, {LV_COORD_MIN, LV_COORD_MIN}};` + * Must be closed with `{LV_COORD_MIN, LV_COORD_MIN}`. Only the pointer is saved so can't be a local variable. + */ +void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos); + +/** + * Set the tile to be shown + * @param tileview pointer to a tileview object + * @param x column id (0, 1, 2...) + * @param y line id (0, 1, 2...) + * @param anim_en true: move with animation + */ +void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, bool anim_en); + +/** + * Enable the edge flash effect. (Show an arc when the an edge is reached) + * @param tileview pointer to a Tileview + * @param en true or false to enable/disable end flash + */ +static inline void lv_tileview_set_edge_flash(lv_obj_t * tileview, bool en) +{ + lv_page_set_edge_flash(tileview, en); +} + +/** + * Set a style of a tileview. + * @param tileview pointer to tileview object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the scroll propagation property + * @param tileview pointer to a Tileview + * @return true or false + */ +static inline bool lv_tileview_get_edge_flash(lv_obj_t * tileview) +{ + return lv_page_get_edge_flash(tileview); +} + +/** + * Get style of a tileview. + * @param tileview pointer to tileview object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_tileview_get_style(const lv_obj_t * tileview, lv_tileview_style_t type); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_TILEVIEW*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TILEVIEW_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.c b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.c new file mode 100644 index 0000000..8f1cc87 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.c @@ -0,0 +1,590 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_win.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_win.h" +#if USE_LV_WIN != 0 + +#include "../lv_themes/lv_theme.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param); +static void lv_win_realign(lv_obj_t * win); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a window objects + * @param par pointer to an object, it will be the parent of the new window + * @param copy pointer to a window object, if not NULL then the new object will be copied from it + * @return pointer to the created window + */ +lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("window create started"); + + /*Create the ancestor object*/ + lv_obj_t * new_win = lv_obj_create(par, copy); + lv_mem_assert(new_win); + if(new_win == NULL) return NULL; + + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_win); + + /*Allocate the object type specific extended data*/ + lv_win_ext_t * ext = lv_obj_allocate_ext_attr(new_win, sizeof(lv_win_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + + ext->page = NULL; + ext->header = NULL; + ext->title = NULL; + ext->style_header = &lv_style_plain_color; + ext->style_btn_rel = &lv_style_btn_rel; + ext->style_btn_pr = &lv_style_btn_pr; + ext->btn_size = (LV_DPI) / 2; + + /*Init the new window object*/ + if(copy == NULL) { + lv_obj_set_size(new_win, LV_HOR_RES, LV_VER_RES); + lv_obj_set_pos(new_win, 0, 0); + lv_obj_set_style(new_win, &lv_style_pretty); + + ext->page = lv_page_create(new_win, NULL); + lv_obj_set_protect(ext->page, LV_PROTECT_PARENT); + lv_page_set_sb_mode(ext->page, LV_SB_MODE_AUTO); + lv_page_set_arrow_scroll(ext->page, true); + + /*Create a holder for the header*/ + ext->header = lv_obj_create(new_win, NULL); + /*Move back the header because it is automatically moved to the scrollable */ + lv_obj_set_protect(ext->header, LV_PROTECT_PARENT); + lv_obj_set_parent(ext->header, new_win); + lv_obj_set_width(ext->header, LV_HOR_RES - 62);//// + ext->btn_size = lv_obj_get_height(ext->header) - 3;//// + + /*Create a title on the header*/ + ext->title = lv_label_create(ext->header, NULL); + lv_label_set_text(ext->title, "My title"); + + /*Set the default styles*/ + lv_theme_t * th = lv_theme_get_current(); + if(th) { + lv_win_set_style(new_win, LV_WIN_STYLE_BG, th->win.bg); + lv_win_set_style(new_win, LV_WIN_STYLE_SB, th->win.sb); + lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, th->win.header); + lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, th->win.content.bg); + lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_SCRL, th->win.content.scrl); + lv_win_set_style(new_win, LV_WIN_STYLE_BTN_REL, th->win.btn.rel); + lv_win_set_style(new_win, LV_WIN_STYLE_BTN_PR, th->win.btn.pr); + } else { + lv_win_set_style(new_win, LV_WIN_STYLE_BG, &lv_style_plain); + lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, &lv_style_plain); + lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_SCRL, &lv_style_transp); + lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, &lv_style_plain_color); + } + + lv_obj_set_signal_func(new_win, lv_win_signal); + lv_obj_set_size(new_win, LV_HOR_RES, LV_VER_RES); + } + /*Copy an existing object*/ + else { + lv_win_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + /*Create the objects*/ + ext->header = lv_obj_create(new_win, copy_ext->header); + ext->title = lv_label_create(ext->header, copy_ext->title); + ext->page = lv_page_create(new_win, copy_ext->page); + ext->btn_size = copy_ext->btn_size; + + /*Copy the control buttons*/ + lv_obj_t * child; + lv_obj_t * cbtn; + child = lv_obj_get_child_back(copy_ext->header, NULL); + child = lv_obj_get_child_back(copy_ext->header, child); /*Sip the title*/ + while(child != NULL) { + cbtn = lv_btn_create(ext->header, child); + lv_img_create(cbtn, lv_obj_get_child(child, NULL)); + child = lv_obj_get_child_back(copy_ext->header, child); + } + + lv_obj_set_signal_func(new_win, lv_win_signal); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_win); + } + + lv_win_realign(new_win); + + LV_LOG_INFO("window created"); + + return new_win; +} + +/** + * Delete all children of the scrl object, without deleting scrl child. + * @param obj pointer to an object + */ +void lv_win_clean(lv_obj_t * obj) +{ + lv_obj_t * scrl = lv_page_get_scrl(obj); + lv_obj_clean(scrl); +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add control button to the header of the window + * @param win pointer to a window object + * @param img_src an image source ('lv_img_t' variable, path to file or a symbol) + * @param rel_action a function pointer to call when the button is released + * @return pointer to the created button object + */ +lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, const char * label_src, lv_action_t rel_action) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + + lv_obj_t * btn = lv_btn_create(ext->header, NULL); + lv_btn_set_style(btn, LV_BTN_STYLE_REL, ext->style_btn_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, ext->style_btn_pr); + lv_obj_set_size(btn, lv_obj_get_width(btn), ext->btn_size); + lv_btn_set_fit(btn, true, false); + lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, rel_action); + + if (img_src) + { + lv_obj_t * img = lv_img_create(btn, NULL); + lv_obj_set_click(img, false); + lv_img_set_src(img, img_src); + } + else if (label_src) + { + lv_obj_t *label = lv_label_create(btn, NULL); + lv_label_set_text(label, label_src); + } + + lv_win_realign(win); + + return btn; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * A release action which can be assigned to a window control button to close it + * @param btn pointer to the released button + * @return always LV_ACTION_RES_INV because the button is deleted with the window + */ +lv_res_t lv_win_close_action(lv_obj_t * btn) +{ + lv_obj_t * win = lv_win_get_from_btn(btn); + + lv_obj_del(win); + + return LV_RES_INV; +} + +/** + * Set the title of a window + * @param win pointer to a window object + * @param title string of the new title + */ +void lv_win_set_title(lv_obj_t * win, const char * title) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + + lv_label_set_text(ext->title, title); + lv_win_realign(win); +} + +/** + * Set the control button size of a window + * @param win pointer to a window object + * @param size control button size + */ +void lv_win_set_btn_size(lv_obj_t * win, lv_coord_t size) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + if(ext->btn_size == size) return; + + ext->btn_size = size; + + lv_win_realign(win); +} + +/** + * Set the layout of the window + * @param win pointer to a window object + * @param layout the layout from 'lv_layout_t' + */ +void lv_win_set_layout(lv_obj_t * win, lv_layout_t layout) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + lv_page_set_scrl_layout(ext->page, layout); +} + +/** + * Set the scroll bar mode of a window + * @param win pointer to a window object + * @param sb_mode the new scroll bar mode from 'lv_sb_mode_t' + */ +void lv_win_set_sb_mode(lv_obj_t * win, lv_sb_mode_t sb_mode) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + lv_page_set_sb_mode(ext->page, sb_mode); +} + +/** + * Set a style of a window + * @param win pointer to a window object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_win_set_style(lv_obj_t * win, lv_win_style_t type, lv_style_t * style) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + + switch(type) { + case LV_WIN_STYLE_BG: + lv_obj_set_style(win, style); + lv_win_realign(win); + break; + case LV_WIN_STYLE_CONTENT_BG: + lv_page_set_style(ext->page, LV_PAGE_STYLE_BG, style); + break; + case LV_WIN_STYLE_CONTENT_SCRL: + lv_page_set_style(ext->page, LV_PAGE_STYLE_SCRL, style); + break; + case LV_WIN_STYLE_SB: + lv_page_set_style(ext->page, LV_PAGE_STYLE_SB, style); + break; + case LV_WIN_STYLE_HEADER: + lv_obj_set_style(ext->header, style); + lv_win_realign(win); + break; + case LV_WIN_STYLE_BTN_REL: + ext->style_btn_rel = style; + break; + case LV_WIN_STYLE_BTN_PR: + ext->style_btn_pr = style; + break; + } + + /*Refresh the existing buttons*/ + if(type == LV_WIN_STYLE_BTN_REL || type == LV_WIN_STYLE_BTN_PR) { + lv_obj_t * btn; + btn = lv_obj_get_child_back(ext->header, NULL); + btn = lv_obj_get_child_back(ext->header, btn); /*Skip the title*/ + while(btn != NULL) { + if(type == LV_WIN_STYLE_BTN_REL) lv_btn_set_style(btn, LV_BTN_STYLE_REL, style); + else lv_btn_set_style(btn, LV_BTN_STYLE_PR, style); + btn = lv_obj_get_child_back(ext->header, btn); + } + } +} + +/** + * Set drag status of a window. If set to 'true' window can be dragged like on a PC. + * @param win pointer to a window object + * @param en whether dragging is enabled + */ +void lv_win_set_drag(lv_obj_t *win, bool en) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + lv_obj_t * win_header = ext->header; + lv_obj_set_drag_parent(win_header, en); + lv_obj_set_drag(win, en); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the title of a window + * @param win pointer to a window object + * @return title string of the window + */ +const char * lv_win_get_title(const lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + return lv_label_get_text(ext->title); +} + +/** +* Get the content holder object of window (`lv_page`) to allow additional customization +* @param win pointer to a window object +* @return the Page object where the window's content is +*/ +lv_obj_t * lv_win_get_content(const lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + return ext->page; +} + +/** + * Get the control button size of a window + * @param win pointer to a window object + * @return control button size + */ +lv_coord_t lv_win_get_btn_size(const lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + return ext->btn_size; +} + +/** + * Get the pointer of a widow from one of its control button. + * It is useful in the action of the control buttons where only button is known. + * @param ctrl_btn pointer to a control button of a window + * @return pointer to the window of 'ctrl_btn' + */ +lv_obj_t * lv_win_get_from_btn(const lv_obj_t * ctrl_btn) +{ + lv_obj_t * header = lv_obj_get_parent(ctrl_btn); + lv_obj_t * win = lv_obj_get_parent(header); + + return win; +} + +/** + * Get the layout of a window + * @param win pointer to a window object + * @return the layout of the window (from 'lv_layout_t') + */ +lv_layout_t lv_win_get_layout(lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + return lv_page_get_scrl_layout(ext->page); +} + +/** + * Get the scroll bar mode of a window + * @param win pointer to a window object + * @return the scroll bar mode of the window (from 'lv_sb_mode_t') + */ +lv_sb_mode_t lv_win_get_sb_mode(lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + return lv_page_get_sb_mode(ext->page); +} + +/** + * Get width of the content area (page scrollable) of the window + * @param win pointer to a window object + * @return the width of the content_bg area + */ +lv_coord_t lv_win_get_width(lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + lv_obj_t * scrl = lv_page_get_scrl(ext->page); + lv_style_t * style_scrl = lv_obj_get_style(scrl); + + return lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor; +} + +/** + * Get a style of a window + * @param win pointer to a button object + * @param type which style window be get + * @return style pointer to a style + */ +lv_style_t * lv_win_get_style(const lv_obj_t * win, lv_win_style_t type) +{ + lv_style_t * style = NULL; + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + + switch(type) { + case LV_WIN_STYLE_BG: + style = lv_obj_get_style(win); + break; + case LV_WIN_STYLE_CONTENT_BG: + style = lv_page_get_style(ext->page, LV_PAGE_STYLE_BG); + break; + case LV_WIN_STYLE_CONTENT_SCRL: + style = lv_page_get_style(ext->page, LV_PAGE_STYLE_SCRL); + break; + case LV_WIN_STYLE_SB: + style = lv_page_get_style(ext->page, LV_PAGE_STYLE_SB); + break; + case LV_WIN_STYLE_HEADER: + style = lv_obj_get_style(ext->header); + break; + case LV_WIN_STYLE_BTN_REL: + style = ext->style_btn_rel; + break; + case LV_WIN_STYLE_BTN_PR: + style = ext->style_btn_pr; + break; + default: + style = NULL; + break; + } + + return style; +} + +/*===================== + * Other functions + *====================*/ + +/** + * Focus on an object. It ensures that the object will be visible in the window. + * @param win pointer to a window object + * @param obj pointer to an object to focus (must be in the window) + * @param anim_time scroll animation time in milliseconds (0: no animation) + */ +void lv_win_focus(lv_obj_t * win, lv_obj_t * obj, uint16_t anim_time) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + lv_page_focus(ext->page, obj, anim_time); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Signal function of the window + * @param win pointer to a window object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(win, sign, param); + if(res != LV_RES_OK) return res; + + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + if(sign == LV_SIGNAL_CHILD_CHG) { /*Move children to the page*/ + lv_obj_t * page = ext->page; + if(page != NULL) { + lv_obj_t * child; + child = lv_obj_get_child(win, NULL); + while(child != NULL) { + if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) { + lv_obj_t * tmp = child; + child = lv_obj_get_child(win, child); /*Get the next child before move this*/ + lv_obj_set_parent(tmp, page); + } else { + child = lv_obj_get_child(win, child); + } + } + } + } else if(sign == LV_SIGNAL_STYLE_CHG) { + lv_win_realign(win); + } else if(sign == LV_SIGNAL_CORD_CHG) { + /*If the size is changed refresh the window*/ + if(lv_area_get_width(param) != lv_obj_get_width(win) || + lv_area_get_height(param) != lv_obj_get_height(win)) { + lv_win_realign(win); + } + } else if(sign == LV_SIGNAL_CLEANUP) { + ext->header = NULL; /*These objects were children so they are already invalid*/ + ext->page = NULL; + ext->title = NULL; + } else if(sign == LV_SIGNAL_CONTROLL) { + /*Forward all the control signals to the page*/ + ext->page->signal_func(ext->page, sign, param); + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_win"; + } + + + return res; +} + +/** + * Realign the building elements of a window + * @param win pointer to window objectker + */ +static void lv_win_realign(lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + + if(ext->page == NULL || ext->header == NULL || ext->title == NULL) return; + + lv_style_t * header_style = lv_win_get_style(win, LV_WIN_STYLE_HEADER); + lv_obj_set_size(ext->header, lv_obj_get_width(win) - 62, ext->btn_size + 2 * header_style->body.padding.ver); + + bool first_btn = true; + lv_obj_t * btn; + lv_obj_t * btn_prev = NULL; + /*Refresh the size of all control buttons*/ + btn = lv_obj_get_child_back(ext->header, NULL); + btn = lv_obj_get_child_back(ext->header, btn); /*Skip the title*/ + while(btn != NULL) { + lv_obj_set_size(btn, lv_obj_get_width(btn), ext->btn_size); + if(first_btn) { + lv_obj_align(btn, ext->header, LV_ALIGN_IN_RIGHT_MID, - header_style->body.padding.hor, 0); + first_btn = false; + } else { + lv_obj_align(btn, btn_prev, LV_ALIGN_OUT_LEFT_MID, - header_style->body.padding.inner, 0); + } + btn_prev = btn; + btn = lv_obj_get_child_back(ext->header, btn); + } + + + lv_obj_align(ext->title, NULL, LV_ALIGN_IN_LEFT_MID, ext->style_header->body.padding.hor, 0); + + lv_obj_set_pos(ext->header, 31, 0); + + lv_obj_set_size(ext->page, lv_obj_get_width(win), lv_obj_get_height(win) - lv_obj_get_height(ext->header)); + lv_obj_align(ext->page, ext->header, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); +} + +#endif + diff --git a/nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.h b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.h new file mode 100644 index 0000000..4bb5d00 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_objx/lv_win.h @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file lv_win.h + * + */ + +#ifndef LV_WIN_H +#define LV_WIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_WIN != 0 + +/*Testing of dependencies*/ +#if USE_LV_BTN == 0 +#error "lv_win: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " +#endif + +#if USE_LV_LABEL == 0 +#error "lv_win: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#endif + +#if USE_LV_IMG == 0 +#error "lv_win: lv_img is required. Enable it in lv_conf.h (USE_LV_IMG 1) " +#endif + + +#if USE_LV_PAGE == 0 +#error "lv_win: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_cont.h" +#include "lv_btn.h" +#include "lv_label.h" +#include "lv_img.h" +#include "lv_page.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of window*/ +typedef struct +{ + /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t * page; /*Pointer to a page which holds the content*/ + lv_obj_t * header; /*Pointer to the header container of the window*/ + lv_obj_t * title; /*Pointer to the title label of the window*/ + lv_style_t * style_header; /*Style of the header container*/ + lv_style_t * style_btn_rel; /*Control button releases style*/ + lv_style_t * style_btn_pr; /*Control button pressed style*/ + lv_coord_t btn_size; /*Size of the control buttons (square)*/ +} lv_win_ext_t; + +enum { + LV_WIN_STYLE_BG, + LV_WIN_STYLE_CONTENT_BG, + LV_WIN_STYLE_CONTENT_SCRL, + LV_WIN_STYLE_SB, + LV_WIN_STYLE_HEADER, + LV_WIN_STYLE_BTN_REL, + LV_WIN_STYLE_BTN_PR, +}; +typedef uint8_t lv_win_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a window objects + * @param par pointer to an object, it will be the parent of the new window + * @param copy pointer to a window object, if not NULL then the new object will be copied from it + * @return pointer to the created window + */ +lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy); + +/** + * Delete all children of the scrl object, without deleting scrl child. + * @param obj pointer to an object + */ +void lv_win_clean(lv_obj_t *obj); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add control button to the header of the window + * @param win pointer to a window object + * @param img_src an image source ('lv_img_t' variable, path to file or a symbol) + * @param rel_action a function pointer to call when the button is released + * @return pointer to the created button object + */ +lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, const char * label_src, lv_action_t rel_action); + +/*===================== + * Setter functions + *====================*/ + +/** + * A release action which can be assigned to a window control button to close it + * @param btn pointer to the released button + * @return always LV_ACTION_RES_INV because the button is deleted with the window + */ +lv_res_t lv_win_close_action(lv_obj_t * btn); + +/** + * Set the title of a window + * @param win pointer to a window object + * @param title string of the new title + */ +void lv_win_set_title(lv_obj_t * win, const char * title); + +/** + * Set the control button size of a window + * @param win pointer to a window object + * @return control button size + */ +void lv_win_set_btn_size(lv_obj_t * win, lv_coord_t size); + +/** + * Set the layout of the window + * @param win pointer to a window object + * @param layout the layout from 'lv_layout_t' + */ +void lv_win_set_layout(lv_obj_t *win, lv_layout_t layout); + +/** + * Set the scroll bar mode of a window + * @param win pointer to a window object + * @param sb_mode the new scroll bar mode from 'lv_sb_mode_t' + */ +void lv_win_set_sb_mode(lv_obj_t *win, lv_sb_mode_t sb_mode); + +/** + * Set a style of a window + * @param win pointer to a window object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_win_set_style(lv_obj_t *win, lv_win_style_t type, lv_style_t *style); + +/** + * Set drag status of a window. If set to 'true' window can be dragged like on a PC. + * @param win pointer to a window object + * @param en whether dragging is enabled + */ +void lv_win_set_drag(lv_obj_t *win, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the title of a window + * @param win pointer to a window object + * @return title string of the window + */ +const char * lv_win_get_title(const lv_obj_t * win); + +/** +* Get the content holder object of window (`lv_page`) to allow additional customization +* @param win pointer to a window object +* @return the Page object where the window's content is +*/ +lv_obj_t * lv_win_get_content(const lv_obj_t * win); + +/** + * Get the control button size of a window + * @param win pointer to a window object + * @return control button size + */ +lv_coord_t lv_win_get_btn_size(const lv_obj_t * win); + +/** + * Get the pointer of a widow from one of its control button. + * It is useful in the action of the control buttons where only button is known. + * @param ctrl_btn pointer to a control button of a window + * @return pointer to the window of 'ctrl_btn' + */ +lv_obj_t * lv_win_get_from_btn(const lv_obj_t * ctrl_btn); + +/** + * Get the layout of a window + * @param win pointer to a window object + * @return the layout of the window (from 'lv_layout_t') + */ +lv_layout_t lv_win_get_layout(lv_obj_t *win); + +/** + * Get the scroll bar mode of a window + * @param win pointer to a window object + * @return the scroll bar mode of the window (from 'lv_sb_mode_t') + */ +lv_sb_mode_t lv_win_get_sb_mode(lv_obj_t *win); + +/** + * Get width of the content area (page scrollable) of the window + * @param win pointer to a window object + * @return the width of the content area + */ +lv_coord_t lv_win_get_width(lv_obj_t * win); + +/** + * Get a style of a window + * @param win pointer to a button object + * @param type which style window be get + * @return style pointer to a style + */ +lv_style_t * lv_win_get_style(const lv_obj_t *win, lv_win_style_t type); + +/** + * Get drag status of a window. If set to 'true' window can be dragged like on a PC. + * @param win pointer to a window object + * @return whether window is draggable + */ +static inline bool lv_win_get_drag(const lv_obj_t *win) +{ + return lv_obj_get_drag(win); +} + +/*===================== + * Other functions + *====================*/ + +/** + * Focus on an object. It ensures that the object will be visible in the window. + * @param win pointer to a window object + * @param obj pointer to an object to focus (must be in the window) + * @param anim_time scroll animation time in milliseconds (0: no animation) + */ +void lv_win_focus(lv_obj_t * win, lv_obj_t * obj, uint16_t anim_time); + +/** + * Scroll the window horizontally + * @param win pointer to a window object + * @param dist the distance to scroll (< 0: scroll right; > 0 scroll left) + */ +static inline void lv_win_scroll_hor(lv_obj_t * win, lv_coord_t dist) +{ + lv_win_ext_t * ext = (lv_win_ext_t *)lv_obj_get_ext_attr(win); + lv_page_scroll_hor(ext->page, dist); +} +/** + * Scroll the window vertically + * @param win pointer to a window object + * @param dist the distance to scroll (< 0: scroll down; > 0 scroll up) + */ +static inline void lv_win_scroll_ver(lv_obj_t * win, lv_coord_t dist) +{ + lv_win_ext_t * ext = (lv_win_ext_t *)lv_obj_get_ext_attr(win); + lv_page_scroll_ver(ext->page, dist); +} + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_WIN*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_WIN_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.c b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.c new file mode 100644 index 0000000..59a0489 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.c @@ -0,0 +1,112 @@ +/** + * @file lv_theme.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_theme.h" +#include "../lv_core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +#if LV_THEME_LIVE_UPDATE == 0 +static lv_theme_t * current_theme; +#else +/* If live update is used then a big `lv_style_t` array is used to store the real styles of the theme not only pointers. + * On `lv_theme_set_current` the styles of the theme are copied to this array. + * The pointers in `current_theme` are initialized to point to the styles in the array. + * This way the theme styles will always point to the same memory address even after theme is change. + * (The pointers in the theme points to the styles declared by the theme itself) */ + +/* Store the styles in this array. + * Can't determine the size in compile time because sizeof is not evaluated (should be `sizeof(lv_theme_t) / sizeof(lv_style_t*)`). + * Error will be generated in run time if too small.*/ +static lv_style_t th_styles[120]; +static bool inited = false; +static lv_theme_t current_theme; +#endif + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Set a theme for the system. + * From now, all the created objects will use styles from this theme by default + * @param th pointer to theme (return value of: 'lv_theme_init_xxx()') + */ +void lv_theme_set_current(lv_theme_t * th) +{ +#if LV_THEME_LIVE_UPDATE == 0 + current_theme = th; +#else + uint32_t style_num = sizeof(lv_theme_t) / sizeof(lv_style_t *); /*Number of styles in a theme*/ + + if(!inited) { + /*It's not sure `th_styles` is big enough. Check it now!*/ + if(style_num > sizeof(th_styles) / sizeof(lv_style_t)) { + LV_LOG_ERROR("Themes: th_styles array is too small. Increase it's size!"); + while(1); + } + + /*Initialize the style pointers `current_theme` to point to the `th_styles` style array */ + uint16_t i; + lv_style_t ** cur_th_style_p = (lv_style_t **) ¤t_theme; + for(i = 0; i < style_num; i++) { + uintptr_t adr = (uintptr_t)&th_styles[i]; + memcpy(&cur_th_style_p[i], &adr, sizeof(lv_style_t *)); + } + inited = true; + } + + + /*Copy the styles pointed by the new theme to the `th_styles` style array*/ + uint16_t i; + lv_style_t ** th_style = (lv_style_t **) th; + for(i = 0; i < style_num; i++) { + uintptr_t s = (uintptr_t)th_style[i]; + if(s) memcpy(&th_styles[i], (void *)s, sizeof(lv_style_t)); + } + + /*Let the object know their style might change*/ + lv_obj_report_style_mod(NULL); +#endif +} + +/** + * Get the current system theme. + * @return pointer to the current system theme. NULL if not set. + */ +lv_theme_t * lv_theme_get_current(void) +{ +#if LV_THEME_LIVE_UPDATE == 0 + return current_theme; +#else + if(!inited) return NULL; + else return ¤t_theme; +#endif +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.h b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.h new file mode 100644 index 0000000..d609051 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme.h @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *@file lv_themes.h + * + */ + +#ifndef LV_THEMES_H +#define LV_THEMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#include "../lv_core/lv_style.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_style_t *bg; + lv_style_t *panel; + +#if USE_LV_CONT != 0 + lv_style_t *cont; +#endif + +#if USE_LV_BTN != 0 + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; +#endif + + +#if USE_LV_IMGBTN != 0 + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } imgbtn; +#endif + +#if USE_LV_LABEL != 0 + struct { + lv_style_t *prim; + lv_style_t *sec; + lv_style_t *hint; + } label; +#endif + +#if USE_LV_IMG != 0 + struct { + lv_style_t *light; + lv_style_t *dark; + } img; +#endif + +#if USE_LV_LINE != 0 + struct { + lv_style_t *decor; + } line; +#endif + +#if USE_LV_LED != 0 + lv_style_t *led; +#endif + +#if USE_LV_BAR != 0 + struct { + lv_style_t *bg; + lv_style_t *indic; + } bar; +#endif + +#if USE_LV_SLIDER != 0 + struct { + lv_style_t *bg; + lv_style_t *indic; + lv_style_t *knob; + } slider; +#endif + +#if USE_LV_LMETER != 0 + lv_style_t *lmeter; +#endif + +#if USE_LV_GAUGE != 0 + lv_style_t *gauge; +#endif + +#if USE_LV_ARC != 0 + lv_style_t *arc; +#endif + +#if USE_LV_PRELOAD != 0 + lv_style_t *preload; +#endif + +#if USE_LV_SW != 0 + struct { + lv_style_t *bg; + lv_style_t *indic; + lv_style_t *knob_off; + lv_style_t *knob_on; + } sw; +#endif + +#if USE_LV_CHART != 0 + lv_style_t *chart; +#endif + +#if USE_LV_CALENDAR != 0 + struct { + lv_style_t *bg; + lv_style_t *header; + lv_style_t *header_pr; + lv_style_t *day_names; + lv_style_t *highlighted_days; + lv_style_t *inactive_days; + lv_style_t *week_box; + lv_style_t *today_box; + } calendar; +#endif + +#if USE_LV_CB != 0 + struct { + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } box; + } cb; +#endif + +#if USE_LV_BTNM != 0 + struct { + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; + } btnm; +#endif + +#if USE_LV_KB != 0 + struct { + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; + } kb; +#endif + +#if USE_LV_MBOX != 0 + struct { + lv_style_t *bg; + struct { + lv_style_t *bg; + lv_style_t *rel; + lv_style_t *pr; + } btn; + } mbox; +#endif + +#if USE_LV_PAGE != 0 + struct { + lv_style_t *bg; + lv_style_t *scrl; + lv_style_t *sb; + } page; +#endif + +#if USE_LV_TA != 0 + struct { + lv_style_t *area; + lv_style_t *oneline; + lv_style_t *cursor; + lv_style_t *sb; + } ta; +#endif + +#if USE_LV_SPINBOX != 0 + struct { + lv_style_t *bg; + lv_style_t *cursor; + lv_style_t *sb; + } spinbox; +#endif + +#if USE_LV_LIST + struct { + lv_style_t *bg; + lv_style_t *scrl; + lv_style_t *sb; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; + } list; +#endif + +#if USE_LV_DDLIST != 0 + struct { + lv_style_t *bg; + lv_style_t *bgo; + lv_style_t *pr; + lv_style_t *sel; + lv_style_t *sb; + } ddlist; +#endif + +#if USE_LV_ROLLER != 0 + struct { + lv_style_t *bg; + lv_style_t *sel; + } roller; +#endif + +#if USE_LV_TABVIEW != 0 + struct { + lv_style_t *bg; + lv_style_t *indic; + struct { + lv_style_t *bg; + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + } btn; + } tabview; +#endif + +#if USE_LV_TILEVIEW != 0 + struct { + lv_style_t *bg; + lv_style_t *scrl; + lv_style_t *sb; + } tileview; +#endif + +#if USE_LV_TABLE != 0 + struct { + lv_style_t *bg; + lv_style_t *cell; + } table; +#endif + +#if USE_LV_WIN != 0 + struct { + lv_style_t *bg; + lv_style_t *sb; + lv_style_t *header; + struct { + lv_style_t *bg; + lv_style_t *scrl; + } content; + struct { + lv_style_t *rel; + lv_style_t *pr; + } btn; + } win; +#endif +} lv_theme_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Set a theme for the system. + * From now, all the created objects will use styles from this theme by default + * @param th pointer to theme (return value of: 'lv_theme_init_xxx()') + */ +void lv_theme_set_current(lv_theme_t *th); + +/** + * Get the current system theme. + * @return pointer to the current system theme. NULL if not set. + */ +lv_theme_t * lv_theme_get_current(void); + +/********************** + * MACROS + **********************/ + +/********************** + * POST INCLUDE + *********************/ +#include "lv_theme_hekate.h" + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_THEMES_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme_hekate.c b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme_hekate.c new file mode 100644 index 0000000..2bdd095 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme_hekate.c @@ -0,0 +1,905 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_theme.h" + +#if USE_LV_THEME_HEKATE + +/********************* + * DEFINES + *********************/ +#define DEF_RADIUS 4 +#define COLOR_SHADOW_LIGHT LV_COLOR_HEX3(0xAAA) +#define COLOR_SHADOW_DARK LV_COLOR_HEX(0x1F1F1F) +#define COLOR_HOS_TURQUOISE LV_COLOR_HEX(0x00FFC9) +#define COLOR_HOS_TEAL_LIGHTER LV_COLOR_HEX(0x00EDBA) +#define COLOR_HOS_TEAL_LIGHT LV_COLOR_HEX(0x00B78F) +#define COLOR_HOS_TEAL LV_COLOR_HEX(0x00A273) +#define COLOR_HOS_BG LV_COLOR_HEX(0x2D2D2D) +#define COLOR_HOS_BG_LIGHT LV_COLOR_HEX(0x3D3D3D) +#define COLOR_HOS_TXT_WHITE LV_COLOR_HEX(0xFBFBFB) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static lv_theme_t theme; +static lv_style_t def; + +/*Static style definitions*/ +static lv_style_t sb; + +/*Saved input parameters*/ +static uint16_t _hue; +static lv_font_t * _font; + +/********************** + * MACROS + **********************/ + +/********************** + * STATIC FUNCTIONS + **********************/ + +static void basic_init(void) +{ + static lv_style_t bg, panel; + + lv_style_copy(&def, &lv_style_plain); /*Initialize the default style*/ + def.text.font = _font; + def.body.radius = DEF_RADIUS; + def.text.color = COLOR_HOS_TXT_WHITE; + //def.image.color = COLOR_HOS_TXT_WHITE; //Needed if symbol image + //def.image.opa = LV_OPA_COVER; + + lv_style_copy(&bg, &def); + bg.body.main_color = COLOR_HOS_BG; + //bg.body.main_color = LV_COLOR_BLACK; + bg.body.grad_color = bg.body.main_color; + bg.body.radius = 0; + bg.body.empty = 1; + + lv_style_copy(&panel, &def); + panel.body.radius = DEF_RADIUS; + panel.body.main_color = COLOR_HOS_BG; + panel.body.grad_color = COLOR_HOS_BG; + panel.body.border.width = 1; + panel.body.border.color = LV_COLOR_HEX(0x4D4D4D); + panel.body.border.opa = LV_OPA_COVER; + panel.body.shadow.color = COLOR_SHADOW_LIGHT; + panel.body.shadow.type = LV_SHADOW_BOTTOM; + panel.body.shadow.width = 4; + panel.body.padding.hor = LV_DPI / 8; + panel.body.padding.ver = LV_DPI / 8; + panel.body.padding.inner = LV_DPI / 12; + //panel.text.color = COLOR_HOS_TXT_WHITE; + + lv_style_copy(&sb, &def); + sb.body.main_color = LV_COLOR_BLACK; + sb.body.grad_color = LV_COLOR_BLACK; + sb.body.opa = LV_OPA_40; + sb.body.padding.hor = LV_DPI / 25; + + theme.bg = &bg; + theme.panel = &panel; + +} + +static void cont_init(void) +{ +#if USE_LV_CONT != 0 + static lv_style_t cont; + lv_style_copy(&cont, theme.panel); + cont.body.shadow.width = 0; + cont.body.border.width = 0; + + theme.cont = &cont; +#endif +} + +static void btn_init(void) +{ +#if USE_LV_BTN != 0 + static lv_style_t rel, pr, tgl_rel, tgl_pr, ina; + + lv_style_copy(&rel, &def); + rel.body.main_color = COLOR_HOS_BG_LIGHT; + rel.body.grad_color = rel.body.main_color; + rel.body.radius = 6; + rel.body.padding.hor = LV_DPI / 3; + rel.body.padding.ver = LV_DPI / 6; + rel.body.padding.inner = LV_DPI / 10; + rel.body.shadow.color = COLOR_SHADOW_DARK; + rel.body.shadow.type = LV_SHADOW_BOTTOM; + rel.body.shadow.width = 6; + rel.body.border.width = 0; + rel.body.border.color = COLOR_HOS_BG_LIGHT; + rel.body.border.part = LV_BORDER_FULL; + //rel.text.color = COLOR_HOS_TXT_WHITE; + + lv_style_copy(&pr, &rel); + pr.body.main_color = LV_COLOR_HEX(0x505050); + pr.body.grad_color = pr.body.main_color; + pr.body.shadow.width = 0; + pr.body.border.color = COLOR_HOS_TEAL_LIGHTER; + pr.text.color = COLOR_HOS_TURQUOISE; + pr.body.border.width = 4; + + lv_style_copy(&tgl_rel, &rel); + tgl_rel.body.border.color = COLOR_HOS_TEAL_LIGHTER; + tgl_rel.body.border.width = 4; + + lv_style_copy(&tgl_pr, &tgl_rel); + tgl_pr.body.main_color = LV_COLOR_HEX(0x505050); + tgl_pr.body.grad_color = tgl_pr.body.main_color; + tgl_pr.text.color = COLOR_HOS_TURQUOISE; + tgl_pr.body.shadow.width = 0; + + lv_style_copy(&ina, &rel); + ina.body.main_color = LV_COLOR_HEX(0x1B1B1B); + ina.body.grad_color = ina.body.main_color; + //ina.body.shadow.width = 0; + ina.text.color = LV_COLOR_HEX(0x888888); + ina.body.border.width = 4; + + theme.btn.rel = &rel; + theme.btn.pr = ≺ + theme.btn.tgl_rel = &tgl_rel; + theme.btn.tgl_pr = &tgl_pr; + theme.btn.ina = &ina; +#endif +} + + +static void label_init(void) +{ +#if USE_LV_LABEL != 0 + static lv_style_t prim, sec, hint; + + lv_style_copy(&prim, &def); + prim.text.font = _font; + prim.text.color = COLOR_HOS_TXT_WHITE; + + lv_style_copy(&sec, &prim); + sec.text.color = LV_COLOR_HEX(0xFF5500); + + lv_style_copy(&hint, &prim); + hint.text.color = LV_COLOR_HEX3(0xCCC); + + theme.label.prim = &prim; + theme.label.sec = &sec; + theme.label.hint = &hint; +#endif +} + +static void img_init(void) +{ +#if USE_LV_IMG != 0 + static lv_style_t img_light, img_dark; + lv_style_copy(&img_light, &def); + img_light.image.color = LV_COLOR_HEX(0xffffff); + img_light.image.intense = LV_OPA_80; + + lv_style_copy(&img_dark, &def); + img_dark.image.color = LV_COLOR_HEX(0x1B1B1B); + img_dark.image.intense = LV_OPA_80; + + + theme.img.light = &def; + theme.img.dark = &def; +#endif +} + +static void line_init(void) +{ +#if USE_LV_LINE != 0 + static lv_style_t line; + lv_style_copy(&line, &def); + line.line.color = LV_COLOR_HEX(0x656565); + theme.line.decor = &line; +#endif +} + +static void led_init(void) +{ +#if USE_LV_LED != 0 + static lv_style_t led; + lv_style_copy(&led, &def); + led.body.shadow.width = LV_DPI / 10; + led.body.radius = LV_RADIUS_CIRCLE; + led.body.border.width = LV_DPI / 30; + led.body.border.opa = LV_OPA_30; + led.body.main_color = lv_color_hsv_to_rgb(_hue, 100, 100); + led.body.grad_color = lv_color_hsv_to_rgb(_hue, 100, 100); + led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60); + led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100); + + + theme.led = &led; +#endif +} + +static void bar_init(void) +{ +#if USE_LV_BAR + static lv_style_t bar_bg, bar_indic; + + lv_style_copy(&bar_bg, &def); + bar_bg.body.main_color = LV_COLOR_HEX(0x4D4D4D); + bar_bg.body.grad_color = bar_bg.body.main_color; + bar_bg.body.radius = 3; + bar_bg.body.border.width = 0; + bar_bg.body.padding.hor = LV_DPI / 12; + bar_bg.body.padding.ver = LV_DPI / 12; + + lv_style_copy(&bar_indic, &bar_bg); + bar_indic.body.main_color = COLOR_HOS_TURQUOISE; + bar_indic.body.grad_color = bar_indic.body.main_color; + bar_indic.body.padding.hor = 0; + bar_indic.body.padding.ver = 0; + + theme.bar.bg = &bar_bg; + theme.bar.indic = &bar_indic; +#endif +} + +static void slider_init(void) +{ +#if USE_LV_SLIDER != 0 + static lv_style_t knob; + static lv_style_t slide_bar; + + lv_style_copy(&knob, &def); + knob.body.radius = LV_RADIUS_CIRCLE; + knob.body.border.width = 0; + knob.body.main_color = theme.bar.indic->body.main_color; + knob.body.grad_color = knob.body.main_color; + + lv_style_copy(&slide_bar, theme.bar.indic); + slide_bar.body.main_color = COLOR_HOS_TEAL_LIGHT; + slide_bar.body.grad_color = slide_bar.body.main_color; + + theme.slider.bg = theme.bar.bg; + theme.slider.indic = &slide_bar; + theme.slider.knob = &knob; +#endif +} + +static void sw_init(void) +{ +#if USE_LV_SW != 0 + static lv_style_t sw_bg, sw_indic, sw_knob_off, sw_knob_on; + lv_style_copy(&sw_bg, theme.slider.bg); + sw_bg.body.radius = LV_RADIUS_CIRCLE; + + lv_style_copy(&sw_indic, theme.slider.bg); + sw_indic.body.radius = LV_RADIUS_CIRCLE; + + lv_style_copy(&sw_knob_on, theme.slider.knob); + + lv_style_copy(&sw_knob_off, &sw_knob_on); + sw_knob_off.body.main_color = LV_COLOR_HEX(0xDADADA); + sw_knob_off.body.grad_color = sw_knob_off.body.main_color; + sw_knob_off.body.border.width = 1; + sw_knob_off.body.border.color = LV_COLOR_HEX3(0x999); + sw_knob_off.body.border.opa = LV_OPA_COVER; + + theme.sw.bg = &sw_bg; + theme.sw.indic = &sw_indic; + theme.sw.knob_off = &sw_knob_off; + theme.sw.knob_on = &sw_knob_on; +#endif +} + + +static void lmeter_init(void) +{ +#if USE_LV_LMETER != 0 + static lv_style_t lmeter; + lv_style_copy(&lmeter, &def); + lmeter.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 90); + lmeter.body.grad_color = lmeter.body.main_color; + lmeter.body.padding.hor = LV_DPI / 10; /*Scale line length*/ + lmeter.line.color = LV_COLOR_HEX3(0x999); + lmeter.line.width = 2; + + theme.lmeter = &lmeter; +#endif +} + +static void gauge_init(void) +{ +#if USE_LV_GAUGE != 0 + + static lv_style_t gauge; + lv_style_copy(&gauge, &def); + gauge.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 60); + gauge.body.grad_color = gauge.body.main_color; + gauge.body.padding.hor = LV_DPI / 16; /*Scale line length*/ + gauge.body.padding.inner = LV_DPI / 8; + gauge.body.border.color = LV_COLOR_HEX3(0x999); + gauge.text.color = LV_COLOR_HEX3(0xddd); + gauge.line.width = 3; + gauge.line.color = lv_color_hsv_to_rgb(_hue, 95, 70); + + theme.gauge = &gauge; +#endif +} + +static void arc_init(void) +{ +#if USE_LV_ARC != 0 + + static lv_style_t arc; + lv_style_copy(&arc, &def); + arc.line.width = 10; + arc.line.color = lv_color_hsv_to_rgb(_hue, 90, 90); + + /*For prelaoder*/ + arc.body.border.width = 10; + arc.body.border.color = lv_color_hsv_to_rgb(_hue, 30, 90); + arc.body.padding.hor = 0; + arc.body.padding.ver = 0; + + theme.arc = &arc; +#endif +} + +static void preload_init(void) +{ +#if USE_LV_PRELOAD != 0 + + theme.preload = theme.arc; +#endif +} + +static void chart_init(void) +{ +#if USE_LV_CHART + theme.chart = theme.panel; +#endif +} + +static void calendar_init(void) +{ +#if USE_LV_CALENDAR + static lv_style_t ina_days; + lv_style_copy(&ina_days, &def); + ina_days.text.color = lv_color_hsv_to_rgb(_hue, 0, 70); + + static lv_style_t high_days; + lv_style_copy(&high_days, &def); + high_days.text.color = lv_color_hsv_to_rgb(_hue, 80, 90); + + static lv_style_t week_box; + lv_style_copy(&week_box, &def); + week_box.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 100); + week_box.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 100); + week_box.body.padding.ver = LV_DPI / 20; + week_box.body.padding.hor = theme.panel->body.padding.hor; + week_box.body.border.color = theme.panel->body.border.color; + week_box.body.border.width = theme.panel->body.border.width; + week_box.body.border.part = LV_BORDER_LEFT | LV_BORDER_RIGHT; + week_box.body.radius = 0; + + static lv_style_t today_box; + lv_style_copy(&today_box, &def); + today_box.body.main_color = LV_COLOR_WHITE; + today_box.body.grad_color = LV_COLOR_WHITE; + today_box.body.padding.ver = LV_DPI / 20; + today_box.body.radius = 0; + + theme.calendar.bg = theme.panel; + theme.calendar.header = &lv_style_transp; + theme.calendar.inactive_days = &ina_days; + theme.calendar.highlighted_days = &high_days; + theme.calendar.week_box = &week_box; + theme.calendar.today_box = &today_box; +#endif +} + +static void cb_init(void) +{ +#if USE_LV_CB != 0 + static lv_style_t rel, pr, tgl_rel, tgl_pr, ina; + lv_style_copy(&rel, theme.panel); + rel.body.shadow.type = LV_SHADOW_FULL; + rel.body.shadow.width = 3; + + lv_style_copy(&pr, &rel); + pr.body.main_color = LV_COLOR_HEX3(0xCCC); + pr.body.grad_color = pr.body.main_color; + pr.body.shadow.width = 3; + + lv_style_copy(&tgl_rel, &rel); + tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 85); + tgl_rel.body.grad_color = tgl_rel.body.main_color; + tgl_rel.body.shadow.width = 0; + + lv_style_copy(&tgl_pr, &tgl_rel); + tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 65); + tgl_pr.body.grad_color = tgl_pr.body.main_color; + + lv_style_copy(&ina, theme.btn.ina); + + theme.cb.bg = &lv_style_transp; + theme.cb.box.rel = &rel; + theme.cb.box.pr = ≺ + theme.cb.box.tgl_rel = &tgl_rel; + theme.cb.box.tgl_pr = &tgl_pr; + theme.cb.box.ina = &ina; +#endif +} + + +static void btnm_init(void) +{ +#if USE_LV_BTNM + static lv_style_t bg, rel, pr, tgl_rel, tgl_pr, ina; + + lv_style_copy(&bg, theme.panel); + bg.body.padding.hor = 0; + bg.body.padding.ver = 0; + bg.body.padding.inner = 0; + bg.text.color = LV_COLOR_HEX3(0x555); + + lv_style_copy(&rel, theme.panel); + rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL; + rel.body.border.width = 1; + rel.body.border.color = LV_COLOR_HEX3(0xBBB); + rel.body.empty = 1; + rel.body.shadow.width = 0; + + lv_style_copy(&pr, &rel); + pr.glass = 0; + pr.body.main_color = LV_COLOR_HEX3(0xDDD); + pr.body.grad_color = pr.body.main_color; + pr.body.border.width = 0; + pr.body.empty = 0; + + lv_style_copy(&tgl_rel, &pr); + tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70); + tgl_rel.body.grad_color = tgl_rel.body.main_color; + tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95); + + + lv_style_copy(&tgl_pr, &tgl_rel); + tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 95, 65); + tgl_pr.body.grad_color = tgl_pr.body.main_color; + tgl_pr.body.border.width = 0; + + lv_style_copy(&ina, &pr); + ina.body.main_color = LV_COLOR_HEX3(0xCCC); + ina.body.grad_color = ina.body.main_color; + + theme.btnm.bg = &bg; + theme.btnm.btn.rel = &rel; + theme.btnm.btn.pr = ≺ + theme.btnm.btn.tgl_rel = &tgl_rel; + theme.btnm.btn.tgl_pr = &tgl_pr; + theme.btnm.btn.ina = &def; +#endif +} + +static void kb_init(void) +{ +#if USE_LV_KB + + static lv_style_t bg, rel; + + lv_style_copy(&bg, theme.btnm.bg); + bg.text.color = LV_COLOR_HEX3(0xCCC); + + lv_style_copy(&rel, &lv_style_transp); + rel.text.font = _font; + + theme.kb.bg = &bg; + theme.kb.btn.rel = &rel; + theme.kb.btn.pr = theme.btnm.btn.pr; + theme.kb.btn.tgl_rel = theme.btnm.btn.tgl_rel; + theme.kb.btn.tgl_pr = theme.btnm.btn.tgl_pr; + theme.kb.btn.ina = theme.btnm.btn.ina; +#endif + +} + +static void mbox_init(void) +{ +#if USE_LV_MBOX + static lv_style_t bg; + + lv_style_copy(&bg, theme.panel); + bg.body.main_color = LV_COLOR_HEX(0x464646); + bg.body.grad_color = bg.body.main_color; + bg.body.shadow.color = COLOR_HOS_BG; + bg.body.shadow.type = LV_SHADOW_FULL; + bg.body.shadow.width = 8; + + bg.body.padding.hor = LV_DPI * 3 / 6; + bg.body.padding.ver = LV_DPI / 4; + bg.body.padding.inner = LV_DPI / 3; + + + theme.mbox.bg = &bg; + theme.mbox.btn.bg = &lv_style_transp; + theme.mbox.btn.rel = theme.btn.rel; + theme.mbox.btn.pr = theme.btn.pr; +#endif +} + +static void page_init(void) +{ +#if USE_LV_PAGE + + + theme.page.bg = theme.panel; + theme.page.scrl = &lv_style_transp; + theme.page.sb = &sb; +#endif +} + +static void ta_init(void) +{ +#if USE_LV_TA + static lv_style_t oneline; + + lv_style_copy(&oneline, &def); + oneline.body.empty = 1; + oneline.body.radius = 0; + oneline.body.border.part = LV_BORDER_BOTTOM; + oneline.body.border.width = 3; + oneline.body.border.color = LV_COLOR_HEX3(0x555); + oneline.body.border.opa = LV_OPA_COVER; + oneline.text.color = LV_COLOR_HEX3(0x888); + + theme.ta.area = theme.panel; + theme.ta.oneline = &oneline; + theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ + theme.ta.sb = &sb; +#endif +} + +static void spinbox_init(void) +{ +#if USE_LV_SPINBOX + theme.spinbox.bg= theme.panel; + theme.spinbox.cursor = theme.ta.cursor; + theme.spinbox.sb = theme.ta.sb; +#endif +} + +static void list_init(void) +{ +#if USE_LV_LIST != 0 + + static lv_style_t list_bg, rel, pr, tgl_rel, tgl_pr, ina; + + lv_style_copy(&list_bg, theme.panel); + list_bg.body.padding.hor = 0; + list_bg.body.padding.ver = 0; + list_bg.body.padding.inner = 0; + list_bg.body.shadow.width = 0; + + lv_style_copy(&rel, &lv_style_transp); + rel.body.padding.hor = LV_DPI / 8; + rel.body.padding.ver = LV_DPI / 6; + rel.body.radius = 0; + rel.body.border.color = LV_COLOR_HEX(0x444444); + rel.body.border.width = 1; + rel.body.border.part = LV_BORDER_BOTTOM; + + lv_style_copy(&pr, &rel); + pr.glass = 0; + pr.body.main_color = LV_COLOR_HEX(0x505050); + pr.body.grad_color = pr.body.main_color; + //pr.body.border.width = 1; + pr.body.empty = 0; + //pr.body.radius = 0; + // pr.text.font = _font; + + lv_style_copy(&tgl_rel, &pr); + tgl_rel.body.main_color = COLOR_HOS_BG_LIGHT; + tgl_rel.body.grad_color = tgl_rel.body.main_color; + //tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95); + tgl_rel.text.color = COLOR_HOS_TEAL_LIGHTER; + + lv_style_copy(&tgl_pr, &tgl_rel); + tgl_pr.body.main_color = LV_COLOR_HEX(0x505050); + tgl_pr.body.grad_color = tgl_pr.body.main_color; + tgl_pr.body.border.width = 0; + + lv_style_copy(&ina, &pr); + ina.body.main_color = LV_COLOR_HEX(0x1B1B1B); + ina.body.grad_color = ina.body.main_color; + + + theme.list.sb = &sb; + theme.list.bg = &list_bg; + theme.list.scrl = &lv_style_transp_tight; + theme.list.btn.rel = &rel; + theme.list.btn.pr = ≺ + theme.list.btn.tgl_rel = &tgl_rel; + theme.list.btn.tgl_pr = &tgl_pr; + theme.list.btn.ina = &ina; +#endif +} + +static void ddlist_init(void) +{ +#if USE_LV_DDLIST != 0 + static lv_style_t bg, sel; + lv_style_copy(&bg, theme.panel); + bg.body.padding.hor = LV_DPI / 6; + //bg.body.padding.ver = LV_DPI / 6; + bg.body.radius = 0; + bg.body.shadow.width = 0; + bg.body.border.width = 0; + bg.text.line_space = LV_DPI / 8; + bg.text.color = COLOR_HOS_TURQUOISE; + + lv_style_copy(&sel, &bg); + sel.body.main_color = COLOR_HOS_BG_LIGHT; + sel.body.grad_color = sel.body.main_color; + + theme.ddlist.bg = &bg; + theme.ddlist.bgo = &bg; + theme.ddlist.pr = &sel; + theme.ddlist.sel = &sel; + theme.ddlist.sb = &sb; +#endif +} + +static void roller_init(void) +{ +#if USE_LV_ROLLER != 0 + static lv_style_t roller_bg, roller_sel; + + lv_style_copy(&roller_bg, &lv_style_transp); + roller_bg.body.padding.hor = LV_DPI / 6; + roller_bg.body.padding.ver = LV_DPI / 6; + roller_bg.text.line_space = LV_DPI / 8; + roller_bg.text.font = _font; + roller_bg.glass = 0; + roller_bg.text.color = LV_COLOR_HEX3(0x444); + + lv_style_copy(&roller_sel, &roller_bg); + roller_sel.text.color = COLOR_HOS_TURQUOISE; + + + theme.roller.bg = &roller_bg; + theme.roller.sel = &roller_sel; +#endif +} + +static void tabview_init(void) +{ +#if USE_LV_TABVIEW != 0 + static lv_style_t indic, btn_bg, rel, pr, tgl_rel, tgl_pr; + + lv_style_copy(&indic, &def); + indic.body.main_color = COLOR_HOS_TURQUOISE; + indic.body.grad_color = indic.body.main_color; + indic.body.radius = 0; + indic.body.border.width = 0; + indic.body.padding.inner = LV_DPI / 20; + indic.body.opa = LV_OPA_0; + + lv_style_copy(&btn_bg, &def); + btn_bg.body.main_color = COLOR_HOS_BG; + btn_bg.body.grad_color = btn_bg.body.main_color; + btn_bg.body.radius = 0; + btn_bg.body.empty = 1; + btn_bg.body.border.width = 0; + btn_bg.body.border.color = LV_COLOR_HEX3(0xDDD); + btn_bg.body.border.part = LV_BORDER_BOTTOM; + btn_bg.body.border.opa = LV_OPA_COVER; + btn_bg.body.shadow.width = 0; + btn_bg.body.shadow.color = COLOR_SHADOW_LIGHT; + btn_bg.body.shadow.type = LV_SHADOW_BOTTOM; + btn_bg.body.padding.inner = 0; + btn_bg.body.padding.hor = 0; + btn_bg.body.padding.ver = 0; + btn_bg.text.color = COLOR_HOS_TXT_WHITE; + + lv_style_copy(&rel, &lv_style_transp); + rel.body.padding.ver = LV_DPI * 4 / 23; + rel.text.font = _font; + + lv_style_copy(&pr, &def); + pr.body.main_color = COLOR_HOS_BG_LIGHT; + pr.body.grad_color = pr.body.main_color; + pr.body.border.width = 0; + pr.body.empty = 0; + pr.body.radius = 0; + pr.body.border.color = LV_COLOR_HEX3(0x888); + pr.body.border.part = LV_BORDER_BOTTOM; + pr.body.border.opa = LV_OPA_COVER; + pr.text.color = COLOR_HOS_TURQUOISE; + + lv_style_copy(&tgl_rel, &lv_style_transp); + tgl_rel.glass = 0; + tgl_rel.text.font = _font; + tgl_rel.text.color = COLOR_HOS_TURQUOISE; + + lv_style_copy(&tgl_pr, &def); + tgl_pr.body.main_color = COLOR_HOS_BG_LIGHT; + tgl_pr.body.grad_color = tgl_pr.body.main_color; + tgl_pr.body.border.width = 0; + tgl_pr.body.empty = 0; + tgl_pr.body.radius = 0; + tgl_pr.text.color = COLOR_HOS_TURQUOISE; + + theme.tabview.bg = theme.bg; + theme.tabview.indic = &indic; + theme.tabview.btn.bg = &btn_bg; + theme.tabview.btn.rel = &rel; + theme.tabview.btn.pr = ≺ + theme.tabview.btn.tgl_rel = &tgl_rel; + theme.tabview.btn.tgl_pr = &tgl_pr; +#endif +} + +static void tileview_init(void) +{ +#if USE_LV_TILEVIEW != 0 + theme.tileview.bg = &lv_style_transp_tight; + theme.tileview.scrl = &lv_style_transp_tight; + theme.tileview.sb = theme.page.sb; +#endif +} + +static void table_init(void) +{ +#if USE_LV_TABLE != 0 + static lv_style_t cell; + lv_style_copy(&cell, theme.panel); + cell.body.radius = 0; + cell.body.border.width = 1; + cell.body.padding.hor = LV_DPI / 12; + cell.body.padding.ver = LV_DPI / 12; + + + theme.table.bg = &lv_style_transp_tight; + theme.table.cell = &cell; +#endif +} + +static void win_init(void) +{ +#if USE_LV_WIN != 0 + static lv_style_t header, rel, pr; + + lv_style_copy(&header, &def); + header.body.main_color = COLOR_HOS_BG; + header.body.grad_color = header.body.main_color; + header.body.radius = 0; + header.body.border.width = 0; + header.body.border.color = LV_COLOR_HEX3(0xDDD); + header.body.border.part = LV_BORDER_BOTTOM; + header.body.border.opa = LV_OPA_COVER; + header.body.shadow.width = 0; + header.body.shadow.color = COLOR_SHADOW_LIGHT; + header.body.shadow.type = LV_SHADOW_BOTTOM; + header.body.padding.inner = 0; + header.body.padding.hor = 8; + header.body.padding.ver = 0; + //header.text.color = COLOR_HOS_TXT_WHITE; + + lv_style_copy(&rel, theme.btn.rel); + rel.body.radius = 0; + rel.body.opa = LV_OPA_0; + rel.body.border.width = 0; + + lv_style_copy(&pr, theme.btn.pr); + pr.body.radius = 0; + pr.body.border.width = 0; + + theme.win.bg = theme.panel; + theme.win.sb = &sb; + theme.win.header = &header; + theme.win.content.bg = &lv_style_transp; + theme.win.content.scrl = &lv_style_transp; + theme.win.btn.rel = &rel; + theme.win.btn.pr = ≺ +#endif +} + +/********************** + * GLOBAL FUNCTIONS + **********************/ + + + +/** + * Initialize the hekate theme + * @param hue [0..360] hue value from HSV color space to define the theme's base color + * @param font pointer to a font (NULL to use the default) + * @return pointer to the initialized theme + */ +lv_theme_t * lv_theme_hekate_init(uint16_t hue, lv_font_t * font) +{ + if(font == NULL) font = LV_FONT_DEFAULT; + + _hue = hue; + _font = font; + + /*For backward compatibility initialize all theme elements with a default style */ + uint16_t i; + lv_style_t ** style_p = (lv_style_t **) &theme; + for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + *style_p = &def; + style_p++; + } + + basic_init(); + cont_init(); + btn_init(); + label_init(); + img_init(); + line_init(); + led_init(); + bar_init(); + slider_init(); + sw_init(); + lmeter_init(); + gauge_init(); + chart_init(); + arc_init(); + preload_init(); + calendar_init(); + cb_init(); + btnm_init(); + kb_init(); + mbox_init(); + page_init(); + ta_init(); + spinbox_init(); + list_init(); + ddlist_init(); + roller_init(); + tabview_init(); + tileview_init(); + table_init(); + win_init(); + + return &theme; +} + +/** + * Get a pointer to the theme + * @return pointer to the theme + */ +lv_theme_t * lv_theme_get_hekate(void) +{ + return &theme; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif + diff --git a/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme_hekate.h b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme_hekate.h new file mode 100644 index 0000000..0f906ea --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_theme_hekate.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LV_THEME_MATERIAL_H +#define LV_THEME_MATERIAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_THEME_HEKATE + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the material theme + * @param hue [0..360] hue value from HSV color space to define the theme's base color + * @param font pointer to a font (NULL to use the default) + * @return pointer to the initialized theme + */ +lv_theme_t * lv_theme_hekate_init(uint16_t hue, lv_font_t *font); + +/** + * Get a pointer to the theme + * @return pointer to the theme + */ +lv_theme_t * lv_theme_get_hekate(void); + +/********************** + * MACROS + **********************/ + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_THEME_MATERIAL_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lv_themes/lv_themes.mk b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_themes.mk new file mode 100644 index 0000000..3345b44 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_themes/lv_themes.mk @@ -0,0 +1,9 @@ +CSRCS += lv_theme.c +CSRCS += lv_theme_default.c +CSRCS += lv_theme_templ.c +CSRCS += lv_theme_material.c + +DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_themes +VPATH += :$(LVGL_DIR)/lvgl/lv_themes + +CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_themes" diff --git a/nyx/nyx_gui/libs/lvgl/lv_version.h b/nyx/nyx_gui/libs/lvgl/lv_version.h new file mode 100644 index 0000000..ec8fe64 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lv_version.h @@ -0,0 +1,66 @@ +/** + * @file lv_version.h + * + */ + +#ifndef LV_VERSION_H +#define LV_VERSION_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +/*Current version of LittlevGL*/ +#define LVGL_VERSION_MAJOR 5 +#define LVGL_VERSION_MINOR 3 +#define LVGL_VERSION_PATCH 0 +#define LVGL_VERSION_INFO "hekate" + + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ +/* Gives 1 if the x.y.z version is supported in the current version + * Usage: + * + * - Require v6 + * #if LV_VERSION_CHECK(6,0,0) + * new_func_in_v6(); + * #endif + * + * + * - Require at least v5.3 + * #if LV_VERSION_CHECK(5,3,0) + * new_feature_from_v5_3(); + * #endif + * + * + * - Require v5.3.2 bugfixes + * #if LV_VERSION_CHECK(5,3,2) + * bugfix_in_v5_3_2(); + * #endif + * + * */ +#define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_VERSION_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lvgl.h b/nyx/nyx_gui/libs/lvgl/lvgl.h new file mode 100644 index 0000000..2d0dd56 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lvgl.h @@ -0,0 +1,85 @@ +/** + * @file lvgl.h + * Include all LittleV GL related headers + */ + +#ifndef LVGL_H +#define LVGL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "lv_version.h" + +#include "lv_misc/lv_log.h" +#include "lv_misc/lv_task.h" + +#include "lv_hal/lv_hal.h" + +#include "lv_core/lv_obj.h" +#include "lv_core/lv_group.h" +#include "lv_core/lv_lang.h" +#include "lv_core/lv_vdb.h" +#include "lv_core/lv_refr.h" + +#include "lv_themes/lv_theme.h" + +#include "lv_objx/lv_btn.h" +#include "lv_objx/lv_imgbtn.h" +#include "lv_objx/lv_img.h" +#include "lv_objx/lv_label.h" +#include "lv_objx/lv_line.h" +#include "lv_objx/lv_page.h" +#include "lv_objx/lv_cont.h" +#include "lv_objx/lv_list.h" +#include "lv_objx/lv_chart.h" +#include "lv_objx/lv_table.h" +#include "lv_objx/lv_cb.h" +#include "lv_objx/lv_bar.h" +#include "lv_objx/lv_slider.h" +#include "lv_objx/lv_led.h" +#include "lv_objx/lv_btnm.h" +#include "lv_objx/lv_kb.h" +#include "lv_objx/lv_ddlist.h" +#include "lv_objx/lv_roller.h" +#include "lv_objx/lv_ta.h" +#include "lv_objx/lv_canvas.h" +#include "lv_objx/lv_win.h" +#include "lv_objx/lv_tabview.h" +#include "lv_objx/lv_tileview.h" +#include "lv_objx/lv_mbox.h" +#include "lv_objx/lv_gauge.h" +#include "lv_objx/lv_lmeter.h" +#include "lv_objx/lv_sw.h" +#include "lv_objx/lv_kb.h" +#include "lv_objx/lv_arc.h" +#include "lv_objx/lv_preload.h" +#include "lv_objx/lv_calendar.h" +#include "lv_objx/lv_spinbox.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} +#endif + +#endif /*LVGL_H*/ diff --git a/nyx/nyx_gui/libs/lvgl/lvgl.mk b/nyx/nyx_gui/libs/lvgl/lvgl.mk new file mode 100644 index 0000000..a4f3237 --- /dev/null +++ b/nyx/nyx_gui/libs/lvgl/lvgl.mk @@ -0,0 +1,8 @@ +include $(LVGL_DIR)/lvgl/lv_core/lv_core.mk +include $(LVGL_DIR)/lvgl/lv_hal/lv_hal.mk +include $(LVGL_DIR)/lvgl/lv_objx/lv_objx.mk +include $(LVGL_DIR)/lvgl/lv_fonts/lv_fonts.mk +include $(LVGL_DIR)/lvgl/lv_misc/lv_misc.mk +include $(LVGL_DIR)/lvgl/lv_themes/lv_themes.mk +include $(LVGL_DIR)/lvgl/lv_draw/lv_draw.mk + diff --git a/nyx/nyx_gui/libs/lvgl/ref/2017031823595300-57B4628D2267231D57E0FC1078C0596D.jpg b/nyx/nyx_gui/libs/lvgl/ref/2017031823595300-57B4628D2267231D57E0FC1078C0596D.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1d1ed8071ce73919fa851e57cc607f38f58b3b3f GIT binary patch literal 67711 zcmeFa2~< zv>Z|f-%8*QQqq9td`UylMJ3I@rmrh){PQ#5Ev4;W-dzEn`+1hy-`kb9&Ru3Epmsk) zkP3KW_SWqtTjQ1flvbLh4BaAsNpAreEV%cVXSQwKdQa(Zb+|X{Pw5#V?kWE%J?kw5 z4QfO4!KIm!SA*lvpQVsNd4<;0vXHidE>a?bKjfwaErnbQPsFYd(A9SBmMsl`=}rU> z&sF+!UeH{S$zOS-bnS0EQi}UMk7gI)e%I34_P(9lBk29m*Z=X;z@T_+{PTol z5}BHwp$kaPpUCZ0F=wx~{ko)kBYRHHQcL%a$&PVaSKm@Hb>^Ea_g_Z1 z=NDZV#(FzICds$i`&!I)yF4!_jQGKITj9lvS?^V5rz-7)0!EiZuLT!3T5kU~es|s~ z=dP%CzIm`2E^+(C1skCU|Lv3Z>bW*589@!d&^lK@5%%&%yO~s#&SCi6;qBjMxnEo` z*WMr^UDgM+D(hVKRG_?;;L01?MYR1; z+IojY^c7hH>$kbs&R(heNH;&@!*nu46^54BO&<=>imklTz-k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omwk%$JH81(@+)2(2Cmc{V*)eqIg4>vM)t=szHTCUxv!?F7( z2kqaxad-B#c`rZ2E=fyE&Hu({IQhWI^#^b3y1nNt7{o@PYY}hyLDhg;NI)Z%sLE@KT2gj**SIT zEVpTHmg!|G^H-WM-m5A9adg$6iXRKtR-6tCX1;eq?A`^tuUi}4lso;{3asYvOgb)e zoe@~>GrqOw0iJ^VH~8Q_J~{4>`t4ihci3@;8y#Mf-QgXz@yQG|d6USKFJBe*fF>}0 zsoH19S|1D(_x!N=VO#Tu*CD%lA5D&q?ktsladF>=w#c3Rb~okj8h+l&P!)eDzju2* z_v4TM{@VY}su!=Q`|LEY@}1Y7_za26&rPw7&)Frvt~Xi0@9{(V6dK}`}ZA_1YU#ws&swVJ+qH` zGtFkN{&771YRSuOKetWaHRrRdnuNifo+B~>94B5eu8V5Wd$H@?(uZsPWW7DE=xtf+ zCVMaR?v%4U8=rd3UAIJVf`^4Ir>Iwhb)=p7AJ?gp^2hIKlq5E-U2|uG``_;|p$vAF mPj=3H3XHXI)tPs@jpd$9zDBqrCjT7y!P@m4Kp)BfzX<@#j(vLo literal 0 HcmV?d00001 diff --git a/nyx/nyx_gui/libs/lvgl/ref/2017031900001400-57B4628D2267231D57E0FC1078C0596D.jpg b/nyx/nyx_gui/libs/lvgl/ref/2017031900001400-57B4628D2267231D57E0FC1078C0596D.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7b5d70fd8945e80981d4a29dc0d26afea4657daa GIT binary patch literal 75176 zcmeEv1z1$yw)h#kyK6{6Lg{X#L|R%v>5!6?8bkrDl@7??Ae)s;L=bLk8pE-N)Icx2G)>?bjxtzUR1+%ILxjF%Wt}eh20004i z48Y{{}=M_V3GBqnMLF zZWI7r#+hi|bt;q);|#Y!O_>G=pa9Go>=HShxme9sP!vHQEIa@_&>va@co!6m@O#lgWP!pFxWAR!_lAtoXwCMBbyASI(DBPOPxqoAawp{1oIA*W}cqhX+; zp{4n)6A(704Gu0LE-oPrDKRO{e|o$808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lvgl/ref/2017091903111300-57B4628D2267231D57E0FC1078C0596D.jpg new file mode 100644 index 0000000000000000000000000000000000000000..471aafcc7f46c734ea8c6b7523f48681542bb99c GIT binary patch literal 78744 zcmeFZ2UHZ@mM>mS&P~qHL;=Y;(;!L^5fn+11tdw5)IdWc2uMzfiV_qQ$&z!L;_pQ_sDoW1v{6ZUWKs;il+ResZ3Fqg*w zpsx>H2LONsAOV2^JY0$v_wxYJ0{FOp5bgtjSOLPnqyZod#P+Z07a+mE(cp4{r2dkZ z9!HmqNB8%<(JlbN-}2_+sIK32@$hx@aPZ`^_Y@Q1dgAMVy9ns~jp8r=QWBE#N)n1n zl8Rgs(n^w&N|Mq5K%9*G;iw2Cq@*QMKz~hx@bH0D_+Qc@xNF#)f1#0-kjMf3orfH} zzo!2XA_xDkX}l5K!M|?QfZjQ;&DVx7e;W7HQq?#sa}Yocm{vVX;Bn&RFkQh=!`jT< z0V2@fasx#Fs1*?G?^*$c{i9a!K>s2==mj3$zodD4|5ovz{b2}uYE2?z+uh>3|vD99)%$jQjbDXD0wDXD0v$jPZ0scGow z85kHSz)Z}H^vtyM4D^2#0>a1TAs{3rBqXJ$B&VeRPj6Rk01XLH1yaWcaRYcXAbc9o zRTluk@kt2!%l0q2#5D>5ArUbNDH%DApqd)M1L5Q25#ay9HI6#uk47V)A*AJ&)F7g} zXGhHAO)vE<h9_7>mL{!pO~DQo|&CnU0dJS+}i%}a|d;FlA=+Og`#%#b{QpX_e--TSa?Jr0_#j;4;nM(6038|&2Jl9+s?WA+(&xlh=A=CZA8ne9r4!cSq*m(O+>h~Ma?n=oM$TIO;v+S zu1T`UbR~BxH>)dYojaG^61hJMG2u&x?PL-$EE8G<=GjF%vm>n+KoGHKI4py3&dd$& zTcnQ{q~J-kq`u4KnrcR8({4?PeEp(Hb`|}Lkwo@`3j*OaX2oDpH!|>1irmghPHTrq zp7N}Jj)bTjZNB1*(ya}C_pZIcoU*!k!CPx($dAHX%d1Q7QA~yIcZ~f9#h|1P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# zq;$Z#>JWTX0UX8BwBMBvFDPKqAtAP_Nk4e9$k>soYVXavPIr&?-?1p($JncUWc5sE zA4)`nlu(B8SwWNqN*%v%I3_12cm5K=;F#j^MPKdV2R2?u4ig@rj36$K_i^TYuyttr zrlMUamtq55Ka&Lgnj4(=Oq7yur?IAUnO~BUqA%_7Rp??WM1i))jwOV^IjTf6RU_t> z;%T>iBp+YPz@k?%J(s2T)iPB}TQSTIoo{rnXKc`W*1#CI@47ATy9&*&`Cx7>&>{*f9Zgf26G%6+&syJC%`iAsu%|Rlw^&&6;mMMr*G$8p1?D(q z&s9=~Szc-usm)Sl7H@^(e}1#w1}S_kG} zSO&>-8hrH@h7093cPz?j`cwhZjN5$9!|2`!6VF1LbTm|xB1FcWqa02_Dqbo{qqtnm zu{eUnFMXs3Vpv!$t=KnBc2uRwMze&sehe8-b5e=8zT$utP9_;>!e2DRC~Uf3+8e> zIh{+eNL+t?8$0xv+PP@. + */ + +#include +#include "heap.h" +#include "../../../common/common_heap.h" + +static void _heap_create(heap_t *heap, u32 start) +{ + heap->start = start; + heap->first = NULL; +} + +static u32 _heap_alloc(heap_t *heap, u32 size, u32 alignment) +{ + hnode_t *node, *new; + int search = 1; + + size = ALIGN(size, alignment); + + if (!heap->first) + { + node = (hnode_t *)heap->start; + node->used = 1; + node->size = size; + node->prev = NULL; + node->next = NULL; + heap->first = node; + + return (u32)node + sizeof(hnode_t); + } + + node = heap->first; + while (search) + { + if (!node->used && size + sizeof(hnode_t) < node->size) + { + new = (hnode_t *)((u32)node + sizeof(hnode_t) + size); + + new->size = node->size - sizeof(hnode_t) - size; + node->size = size; + node->used = 1; + new->used = 0; + new->next = node->next; + new->prev = node; + node->next = new; + + return (u32)node + sizeof(hnode_t); + } + if (node->next) + node = node->next; + else + search = 0; + } + + new = (hnode_t *)((u32)node + sizeof(hnode_t) + node->size); + new->used = 1; + new->size = size; + new->prev = node; + new->next = NULL; + node->next = new; + + return (u32)new + sizeof(hnode_t); +} + +static void _heap_free(heap_t *heap, u32 addr) +{ + hnode_t *node = (hnode_t *)(addr - sizeof(hnode_t)); + node->used = 0; + node = heap->first; + while (node) + { + if (!node->used) + { + if (node->prev && !node->prev->used) + { + node->prev->size += node->size + sizeof(hnode_t); + node->prev->next = node->next; + if (node->next) + node->next->prev = node->prev; + } + } + node = node->next; + } +} + +heap_t _heap; + +void heap_init(u32 base) +{ + _heap_create(&_heap, base); +} + +void *malloc(u32 size) +{ + return (void *)_heap_alloc(&_heap, size, 0x10); +} + +void *memalign(u32 align, u32 size) +{ + return (void *)_heap_alloc(&_heap, size, align); +} + +void *calloc(u32 num, u32 size) +{ + void *res = (void *)_heap_alloc(&_heap, num * size, 0x10); + memset(res, 0, num * size); + return res; +} + +void free(void *buf) +{ + if ((u32)buf >= _heap.start) + _heap_free(&_heap, (u32)buf); +} diff --git a/nyx/nyx_gui/mem/heap.h b/nyx/nyx_gui/mem/heap.h new file mode 100644 index 0000000..ad0783c --- /dev/null +++ b/nyx/nyx_gui/mem/heap.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _HEAP_H_ +#define _HEAP_H_ + +#include "../utils/types.h" + +void heap_init(u32 base); +void *malloc(u32 size); +void *calloc(u32 num, u32 size); +void free(void *buf); +void *memalign(u32 align, u32 size); + +#endif diff --git a/nyx/nyx_gui/mem/mc.c b/nyx/nyx_gui/mem/mc.c new file mode 100644 index 0000000..c799573 --- /dev/null +++ b/nyx/nyx_gui/mem/mc.c @@ -0,0 +1,143 @@ +#include "../mem/mc.h" +#include "../soc/t210.h" +#include "../soc/clock.h" +#include "../utils/util.h" + +void mc_config_tsec_carveout(u32 bom, u32 size1mb, bool lock) +{ + MC(MC_SEC_CARVEOUT_BOM) = bom; + MC(MC_SEC_CARVEOUT_SIZE_MB) = size1mb; + if (lock) + MC(MC_SEC_CARVEOUT_REG_CTRL) = 1; +} + +void mc_config_carveout() +{ + *(vu32 *)0x8005FFFC = 0xC0EDBBCC; + MC(MC_VIDEO_PROTECT_GPU_OVERRIDE_0) = 1; + MC(MC_VIDEO_PROTECT_GPU_OVERRIDE_1) = 0; + MC(MC_VIDEO_PROTECT_BOM) = 0; + MC(MC_VIDEO_PROTECT_SIZE_MB) = 0; + MC(MC_VIDEO_PROTECT_REG_CTRL) = 1; + + // Configure TSEC carveout @ 0x90000000, 1MB. + //mc_config_tsec_carveout(0x90000000, 1, false); + mc_config_tsec_carveout(0, 0, true); + + MC(MC_MTS_CARVEOUT_BOM) = 0; + MC(MC_MTS_CARVEOUT_SIZE_MB) = 0; + MC(MC_MTS_CARVEOUT_ADR_HI) = 0; + MC(MC_MTS_CARVEOUT_REG_CTRL) = 1; + + MC(MC_SECURITY_CARVEOUT1_BOM) = 0; + MC(MC_SECURITY_CARVEOUT1_BOM_HI) = 0; + MC(MC_SECURITY_CARVEOUT1_SIZE_128KB) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_ACCESS2) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_ACCESS4) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS2) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS4) = 0; + MC(MC_SECURITY_CARVEOUT1_CFG0) = 0x4000006; + + MC(MC_SECURITY_CARVEOUT2_BOM) = 0x80020000; + MC(MC_SECURITY_CARVEOUT2_BOM_HI) = 0; + MC(MC_SECURITY_CARVEOUT2_SIZE_128KB) = 2; + MC(MC_SECURITY_CARVEOUT2_CLIENT_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT2_CLIENT_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT2_CLIENT_ACCESS2) = 0x3100000; + MC(MC_SECURITY_CARVEOUT2_CLIENT_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT2_CLIENT_ACCESS4) = 0x300; + MC(MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS2) = 0; + MC(MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS4) = 0; + MC(MC_SECURITY_CARVEOUT2_CFG0) = 0x440167E; + + MC(MC_SECURITY_CARVEOUT3_BOM) = 0; + MC(MC_SECURITY_CARVEOUT3_BOM_HI) = 0; + MC(MC_SECURITY_CARVEOUT3_SIZE_128KB) = 0; + MC(MC_SECURITY_CARVEOUT3_CLIENT_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT3_CLIENT_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT3_CLIENT_ACCESS2) = 0x3000000; + MC(MC_SECURITY_CARVEOUT3_CLIENT_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT3_CLIENT_ACCESS4) = 0x300; + MC(MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS2) = 0; + MC(MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS4) = 0; + MC(MC_SECURITY_CARVEOUT3_CFG0) = 0x4401E7E; + + MC(MC_SECURITY_CARVEOUT4_BOM) = 0; + MC(MC_SECURITY_CARVEOUT4_BOM_HI) = 0; + MC(MC_SECURITY_CARVEOUT4_SIZE_128KB) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_ACCESS2) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_ACCESS4) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS2) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS4) = 0; + MC(MC_SECURITY_CARVEOUT4_CFG0) = 0x8F; + + MC(MC_SECURITY_CARVEOUT5_BOM) = 0; + MC(MC_SECURITY_CARVEOUT5_BOM_HI) = 0; + MC(MC_SECURITY_CARVEOUT5_SIZE_128KB) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_ACCESS2) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_ACCESS4) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS0) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS1) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS2) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS3) = 0; + MC(MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS4) = 0; + MC(MC_SECURITY_CARVEOUT5_CFG0) = 0x8F; +} + +void mc_enable_ahb_redirect() +{ + // Enable ARC_CLK_OVR_ON. + CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRD) = (CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRD) & 0xFFF7FFFF) | 0x80000; + //MC(MC_IRAM_REG_CTRL) &= 0xFFFFFFFE; + MC(MC_IRAM_BOM) = 0x40000000; + MC(MC_IRAM_TOM) = 0x4003F000; +} + +void mc_disable_ahb_redirect() +{ + MC(MC_IRAM_BOM) = 0xFFFFF000; + MC(MC_IRAM_TOM) = 0; + // Disable IRAM_CFG_WRITE_ACCESS (sticky). + //MC(MC_IRAM_REG_CTRL) = MC(MC_IRAM_REG_CTRL) & 0xFFFFFFFE | 1; + // Disable ARC_CLK_OVR_ON. + CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRD) &= 0xFFF7FFFF; +} + +void mc_enable() +{ + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_EMC) = (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_EMC) & 0x1FFFFFFF) | 0x40000000; + // Enable MIPI CAL clock. + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_H_SET) = (CLOCK(CLK_RST_CONTROLLER_CLK_ENB_H_SET) & 0xFDFFFFFF) | 0x2000000; + // Enable MC clock. + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_H_SET) = (CLOCK(CLK_RST_CONTROLLER_CLK_ENB_H_SET) & 0xFFFFFFFE) | 1; + // Enable EMC DLL clock. + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_X_SET) = (CLOCK(CLK_RST_CONTROLLER_CLK_ENB_X_SET) & 0xFFFFBFFF) | 0x4000; + CLOCK(CLK_RST_CONTROLLER_RST_DEV_H_CLR) = 0x2000001; //Clear EMC and MC reset. + usleep(5); + + //#ifdef CONFIG_ENABLE_AHB_REDIRECT + mc_disable_ahb_redirect(); + //mc_enable_ahb_redirect(); + //#endif +} diff --git a/nyx/nyx_gui/mem/mc.h b/nyx/nyx_gui/mem/mc.h new file mode 100644 index 0000000..6a28bde --- /dev/null +++ b/nyx/nyx_gui/mem/mc.h @@ -0,0 +1,14 @@ +#ifndef _MC_H_ +#define _MC_H_ + +#include "../utils/types.h" +#include "../mem/mc_t210.h" + +void mc_config_tsec_carveout(u32 bom, u32 size1mb, bool lock); +void mc_config_carveout(); +void mc_config_carveout_finalize(); +void mc_enable_ahb_redirect(); +void mc_disable_ahb_redirect(); +void mc_enable(); + +#endif diff --git a/nyx/nyx_gui/mem/mc_t210.h b/nyx/nyx_gui/mem/mc_t210.h new file mode 100644 index 0000000..602915f --- /dev/null +++ b/nyx/nyx_gui/mem/mc_t210.h @@ -0,0 +1,466 @@ +/* + * Copyright (c) 2014, NVIDIA Corporation. All rights reserved. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _MC_T210_H_ +#define _MC_T210_H_ + +#define MC_INTSTATUS 0x0 +#define MC_INTMASK 0x4 +#define MC_ERR_STATUS 0x8 +#define MC_ERR_ADR 0xc +#define MC_PCFIFO_CLIENT_CONFIG0 0xdd0 +#define MC_PCFIFO_CLIENT_CONFIG1 0xdd4 +#define MC_PCFIFO_CLIENT_CONFIG2 0xdd8 +#define MC_PCFIFO_CLIENT_CONFIG3 0xddc +#define MC_PCFIFO_CLIENT_CONFIG4 0xde0 +#define MC_EMEM_CFG 0x50 +#define MC_EMEM_ADR_CFG 0x54 +#define MC_EMEM_ADR_CFG_DEV0 0x58 +#define MC_EMEM_ADR_CFG_DEV1 0x5c +#define MC_EMEM_ADR_CFG_CHANNEL_MASK 0x60 +#define MC_EMEM_ADR_CFG_BANK_MASK_0 0x64 +#define MC_EMEM_ADR_CFG_BANK_MASK_1 0x68 +#define MC_EMEM_ADR_CFG_BANK_MASK_2 0x6c +#define MC_SECURITY_CFG0 0x70 +#define MC_SECURITY_CFG1 0x74 +#define MC_SECURITY_CFG3 0x9bc +#define MC_SECURITY_RSV 0x7c +#define MC_EMEM_ARB_CFG 0x90 +#define MC_EMEM_ARB_OUTSTANDING_REQ 0x94 +#define MC_EMEM_ARB_TIMING_RCD 0x98 +#define MC_EMEM_ARB_TIMING_RP 0x9c +#define MC_EMEM_ARB_TIMING_RC 0xa0 +#define MC_EMEM_ARB_TIMING_RAS 0xa4 +#define MC_EMEM_ARB_TIMING_FAW 0xa8 +#define MC_EMEM_ARB_TIMING_RRD 0xac +#define MC_EMEM_ARB_TIMING_RAP2PRE 0xb0 +#define MC_EMEM_ARB_TIMING_WAP2PRE 0xb4 +#define MC_EMEM_ARB_TIMING_R2R 0xb8 +#define MC_EMEM_ARB_TIMING_W2W 0xbc +#define MC_EMEM_ARB_TIMING_R2W 0xc0 +#define MC_EMEM_ARB_TIMING_W2R 0xc4 +#define MC_EMEM_ARB_TIMING_RFCPB 0x6c0 +#define MC_EMEM_ARB_TIMING_CCDMW 0x6c4 +#define MC_EMEM_ARB_REFPB_HP_CTRL 0x6f0 +#define MC_EMEM_ARB_REFPB_BANK_CTRL 0x6f4 +#define MC_EMEM_ARB_DA_TURNS 0xd0 +#define MC_EMEM_ARB_DA_COVERS 0xd4 +#define MC_EMEM_ARB_MISC0 0xd8 +#define MC_EMEM_ARB_MISC1 0xdc +#define MC_EMEM_ARB_MISC2 0xc8 +#define MC_EMEM_ARB_RING1_THROTTLE 0xe0 +#define MC_EMEM_ARB_RING3_THROTTLE 0xe4 +#define MC_EMEM_ARB_NISO_THROTTLE 0x6b0 +#define MC_EMEM_ARB_OVERRIDE 0xe8 +#define MC_EMEM_ARB_RSV 0xec +#define MC_CLKEN_OVERRIDE 0xf4 +#define MC_TIMING_CONTROL_DBG 0xf8 +#define MC_TIMING_CONTROL 0xfc +#define MC_STAT_CONTROL 0x100 +#define MC_STAT_STATUS 0x104 +#define MC_STAT_EMC_CLOCK_LIMIT 0x108 +#define MC_STAT_EMC_CLOCK_LIMIT_MSBS 0x10c +#define MC_STAT_EMC_CLOCKS 0x110 +#define MC_STAT_EMC_CLOCKS_MSBS 0x114 +#define MC_STAT_EMC_FILTER_SET0_ADR_LIMIT_LO 0x118 +#define MC_STAT_EMC_FILTER_SET1_ADR_LIMIT_LO 0x158 +#define MC_STAT_EMC_FILTER_SET0_ADR_LIMIT_HI 0x11c +#define MC_STAT_EMC_FILTER_SET1_ADR_LIMIT_HI 0x15c +#define MC_STAT_EMC_FILTER_SET0_ADR_LIMIT_UPPER 0xa20 +#define MC_STAT_EMC_FILTER_SET1_ADR_LIMIT_UPPER 0xa24 +#define MC_STAT_EMC_FILTER_SET0_VIRTUAL_ADR_LIMIT_LO 0x198 +#define MC_STAT_EMC_FILTER_SET1_VIRTUAL_ADR_LIMIT_LO 0x1a8 +#define MC_STAT_EMC_FILTER_SET0_VIRTUAL_ADR_LIMIT_HI 0x19c +#define MC_STAT_EMC_FILTER_SET1_VIRTUAL_ADR_LIMIT_HI 0x1ac +#define MC_STAT_EMC_FILTER_SET0_VIRTUAL_ADR_LIMIT_UPPER 0xa28 +#define MC_STAT_EMC_FILTER_SET1_VIRTUAL_ADR_LIMIT_UPPER 0xa2c +#define MC_STAT_EMC_FILTER_SET0_ASID 0x1a0 +#define MC_STAT_EMC_FILTER_SET1_ASID 0x1b0 +#define MC_STAT_EMC_FILTER_SET0_SLACK_LIMIT 0x120 +#define MC_STAT_EMC_FILTER_SET1_SLACK_LIMIT 0x160 +#define MC_STAT_EMC_FILTER_SET0_CLIENT_0 0x128 +#define MC_STAT_EMC_FILTER_SET1_CLIENT_0 0x168 +#define MC_STAT_EMC_FILTER_SET0_CLIENT_1 0x12c +#define MC_STAT_EMC_FILTER_SET1_CLIENT_1 0x16c +#define MC_STAT_EMC_FILTER_SET0_CLIENT_2 0x130 +#define MC_STAT_EMC_FILTER_SET1_CLIENT_2 0x170 +#define MC_STAT_EMC_FILTER_SET0_CLIENT_3 0x134 +#define MC_STAT_EMC_FILTER_SET0_CLIENT_4 0xb88 +#define MC_STAT_EMC_FILTER_SET1_CLIENT_3 0x174 +#define MC_STAT_EMC_FILTER_SET1_CLIENT_4 0xb8c +#define MC_STAT_EMC_SET0_COUNT 0x138 +#define MC_STAT_EMC_SET0_COUNT_MSBS 0x13c +#define MC_STAT_EMC_SET1_COUNT 0x178 +#define MC_STAT_EMC_SET1_COUNT_MSBS 0x17c +#define MC_STAT_EMC_SET0_SLACK_ACCUM 0x140 +#define MC_STAT_EMC_SET0_SLACK_ACCUM_MSBS 0x144 +#define MC_STAT_EMC_SET1_SLACK_ACCUM 0x180 +#define MC_STAT_EMC_SET1_SLACK_ACCUM_MSBS 0x184 +#define MC_STAT_EMC_SET0_HISTO_COUNT 0x148 +#define MC_STAT_EMC_SET0_HISTO_COUNT_MSBS 0x14c +#define MC_STAT_EMC_SET1_HISTO_COUNT 0x188 +#define MC_STAT_EMC_SET1_HISTO_COUNT_MSBS 0x18c +#define MC_STAT_EMC_SET0_MINIMUM_SLACK_OBSERVED 0x150 +#define MC_STAT_EMC_SET1_MINIMUM_SLACK_OBSERVED 0x190 +#define MC_STAT_EMC_SET0_IDLE_CYCLE_COUNT 0x1b8 +#define MC_STAT_EMC_SET0_IDLE_CYCL_COUNT_MSBS 0x1bc +#define MC_STAT_EMC_SET1_IDLE_CYCLE_COUNT 0x1c8 +#define MC_STAT_EMC_SET1_IDLE_CYCL_COUNT_MSBS 0x1cc +#define MC_STAT_EMC_SET0_IDLE_CYCLE_PARTITION_SELECT 0x1c0 +#define MC_STAT_EMC_SET1_IDLE_CYCLE_PARTITION_SELECT 0x1d0 +#define MC_CLIENT_HOTRESET_CTRL 0x200 +#define MC_CLIENT_HOTRESET_CTRL_1 0x970 +#define MC_CLIENT_HOTRESET_STATUS 0x204 +#define MC_CLIENT_HOTRESET_STATUS_1 0x974 +#define MC_EMEM_ARB_ISOCHRONOUS_0 0x208 +#define MC_EMEM_ARB_ISOCHRONOUS_1 0x20c +#define MC_EMEM_ARB_ISOCHRONOUS_2 0x210 +#define MC_EMEM_ARB_ISOCHRONOUS_3 0x214 +#define MC_EMEM_ARB_ISOCHRONOUS_4 0xb94 +#define MC_EMEM_ARB_HYSTERESIS_0 0x218 +#define MC_EMEM_ARB_HYSTERESIS_1 0x21c +#define MC_EMEM_ARB_HYSTERESIS_2 0x220 +#define MC_EMEM_ARB_HYSTERESIS_3 0x224 +#define MC_EMEM_ARB_HYSTERESIS_4 0xb84 +#define MC_EMEM_ARB_DHYSTERESIS_0 0xbb0 +#define MC_EMEM_ARB_DHYSTERESIS_1 0xbb4 +#define MC_EMEM_ARB_DHYSTERESIS_2 0xbb8 +#define MC_EMEM_ARB_DHYSTERESIS_3 0xbbc +#define MC_EMEM_ARB_DHYSTERESIS_4 0xbc0 +#define MC_EMEM_ARB_DHYST_CTRL 0xbcc +#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_0 0xbd0 +#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_1 0xbd4 +#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_2 0xbd8 +#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_3 0xbdc +#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_4 0xbe0 +#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_5 0xbe4 +#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_6 0xbe8 +#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_7 0xbec +#define MC_RESERVED_RSV 0x3fc +#define MC_DISB_EXTRA_SNAP_LEVELS 0x408 +#define MC_APB_EXTRA_SNAP_LEVELS 0x2a4 +#define MC_AHB_EXTRA_SNAP_LEVELS 0x2a0 +#define MC_USBD_EXTRA_SNAP_LEVELS 0xa18 +#define MC_ISP_EXTRA_SNAP_LEVELS 0xa08 +#define MC_AUD_EXTRA_SNAP_LEVELS 0xa10 +#define MC_MSE_EXTRA_SNAP_LEVELS 0x40c +#define MC_GK2_EXTRA_SNAP_LEVELS 0xa40 +#define MC_A9AVPPC_EXTRA_SNAP_LEVELS 0x414 +#define MC_FTOP_EXTRA_SNAP_LEVELS 0x2bc +#define MC_JPG_EXTRA_SNAP_LEVELS 0xa3c +#define MC_HOST_EXTRA_SNAP_LEVELS 0xa14 +#define MC_SAX_EXTRA_SNAP_LEVELS 0x2c0 +#define MC_DIS_EXTRA_SNAP_LEVELS 0x2ac +#define MC_VICPC_EXTRA_SNAP_LEVELS 0xa1c +#define MC_HDAPC_EXTRA_SNAP_LEVELS 0xa48 +#define MC_AVP_EXTRA_SNAP_LEVELS 0x2a8 +#define MC_USBX_EXTRA_SNAP_LEVELS 0x404 +#define MC_PCX_EXTRA_SNAP_LEVELS 0x2b8 +#define MC_SD_EXTRA_SNAP_LEVELS 0xa04 +#define MC_DFD_EXTRA_SNAP_LEVELS 0xa4c +#define MC_VE_EXTRA_SNAP_LEVELS 0x2d8 +#define MC_GK_EXTRA_SNAP_LEVELS 0xa00 +#define MC_VE2_EXTRA_SNAP_LEVELS 0x410 +#define MC_SDM_EXTRA_SNAP_LEVELS 0xa44 +#define MC_VIDEO_PROTECT_BOM 0x648 +#define MC_VIDEO_PROTECT_SIZE_MB 0x64c +#define MC_VIDEO_PROTECT_BOM_ADR_HI 0x978 +#define MC_VIDEO_PROTECT_REG_CTRL 0x650 +#define MC_ERR_VPR_STATUS 0x654 +#define MC_ERR_VPR_ADR 0x658 +#define MC_VIDEO_PROTECT_VPR_OVERRIDE 0x418 +#define MC_VIDEO_PROTECT_VPR_OVERRIDE1 0x590 +#define MC_IRAM_BOM 0x65c +#define MC_IRAM_TOM 0x660 +#define MC_IRAM_ADR_HI 0x980 +#define MC_IRAM_REG_CTRL 0x964 +#define MC_EMEM_CFG_ACCESS_CTRL 0x664 +#define MC_TZ_SECURITY_CTRL 0x668 +#define MC_EMEM_ARB_OUTSTANDING_REQ_RING3 0x66c +#define MC_EMEM_ARB_OUTSTANDING_REQ_NISO 0x6b4 +#define MC_EMEM_ARB_RING0_THROTTLE_MASK 0x6bc +#define MC_EMEM_ARB_NISO_THROTTLE_MASK 0x6b8 +#define MC_EMEM_ARB_NISO_THROTTLE_MASK_1 0xb80 +#define MC_SEC_CARVEOUT_BOM 0x670 +#define MC_SEC_CARVEOUT_SIZE_MB 0x674 +#define MC_SEC_CARVEOUT_ADR_HI 0x9d4 +#define MC_SEC_CARVEOUT_REG_CTRL 0x678 +#define MC_ERR_SEC_STATUS 0x67c +#define MC_ERR_SEC_ADR 0x680 +#define MC_PC_IDLE_CLOCK_GATE_CONFIG 0x684 +#define MC_STUTTER_CONTROL 0x688 +#define MC_RESERVED_RSV_1 0x958 +#define MC_DVFS_PIPE_SELECT 0x95c +#define MC_AHB_PTSA_MIN 0x4e0 +#define MC_AUD_PTSA_MIN 0x54c +#define MC_MLL_MPCORER_PTSA_RATE 0x44c +#define MC_RING2_PTSA_RATE 0x440 +#define MC_USBD_PTSA_RATE 0x530 +#define MC_USBX_PTSA_MIN 0x528 +#define MC_USBD_PTSA_MIN 0x534 +#define MC_APB_PTSA_MAX 0x4f0 +#define MC_JPG_PTSA_RATE 0x584 +#define MC_DIS_PTSA_MIN 0x420 +#define MC_AVP_PTSA_MAX 0x4fc +#define MC_AVP_PTSA_RATE 0x4f4 +#define MC_RING1_PTSA_MIN 0x480 +#define MC_DIS_PTSA_MAX 0x424 +#define MC_SD_PTSA_MAX 0x4d8 +#define MC_MSE_PTSA_RATE 0x4c4 +#define MC_VICPC_PTSA_MIN 0x558 +#define MC_PCX_PTSA_MAX 0x4b4 +#define MC_ISP_PTSA_RATE 0x4a0 +#define MC_A9AVPPC_PTSA_MIN 0x48c +#define MC_RING2_PTSA_MAX 0x448 +#define MC_AUD_PTSA_RATE 0x548 +#define MC_HOST_PTSA_MIN 0x51c +#define MC_MLL_MPCORER_PTSA_MAX 0x454 +#define MC_SD_PTSA_MIN 0x4d4 +#define MC_RING1_PTSA_RATE 0x47c +#define MC_JPG_PTSA_MIN 0x588 +#define MC_HDAPC_PTSA_MIN 0x62c +#define MC_AVP_PTSA_MIN 0x4f8 +#define MC_JPG_PTSA_MAX 0x58c +#define MC_VE_PTSA_MAX 0x43c +#define MC_DFD_PTSA_MAX 0x63c +#define MC_VICPC_PTSA_RATE 0x554 +#define MC_GK_PTSA_MAX 0x544 +#define MC_VICPC_PTSA_MAX 0x55c +#define MC_SDM_PTSA_MAX 0x624 +#define MC_SAX_PTSA_RATE 0x4b8 +#define MC_PCX_PTSA_MIN 0x4b0 +#define MC_APB_PTSA_MIN 0x4ec +#define MC_GK2_PTSA_MIN 0x614 +#define MC_PCX_PTSA_RATE 0x4ac +#define MC_RING1_PTSA_MAX 0x484 +#define MC_HDAPC_PTSA_RATE 0x628 +#define MC_MLL_MPCORER_PTSA_MIN 0x450 +#define MC_GK2_PTSA_MAX 0x618 +#define MC_AUD_PTSA_MAX 0x550 +#define MC_GK2_PTSA_RATE 0x610 +#define MC_ISP_PTSA_MAX 0x4a8 +#define MC_DISB_PTSA_RATE 0x428 +#define MC_VE2_PTSA_MAX 0x49c +#define MC_DFD_PTSA_MIN 0x638 +#define MC_FTOP_PTSA_RATE 0x50c +#define MC_A9AVPPC_PTSA_RATE 0x488 +#define MC_VE2_PTSA_MIN 0x498 +#define MC_USBX_PTSA_MAX 0x52c +#define MC_DIS_PTSA_RATE 0x41c +#define MC_USBD_PTSA_MAX 0x538 +#define MC_A9AVPPC_PTSA_MAX 0x490 +#define MC_USBX_PTSA_RATE 0x524 +#define MC_FTOP_PTSA_MAX 0x514 +#define MC_HDAPC_PTSA_MAX 0x630 +#define MC_SD_PTSA_RATE 0x4d0 +#define MC_DFD_PTSA_RATE 0x634 +#define MC_FTOP_PTSA_MIN 0x510 +#define MC_SDM_PTSA_RATE 0x61c +#define MC_AHB_PTSA_RATE 0x4dc +#define MC_SMMU_SMMU_PTSA_MAX 0x460 +#define MC_RING2_PTSA_MIN 0x444 +#define MC_SDM_PTSA_MIN 0x620 +#define MC_APB_PTSA_RATE 0x4e8 +#define MC_MSE_PTSA_MIN 0x4c8 +#define MC_HOST_PTSA_RATE 0x518 +#define MC_VE_PTSA_RATE 0x434 +#define MC_AHB_PTSA_MAX 0x4e4 +#define MC_SAX_PTSA_MIN 0x4bc +#define MC_SMMU_SMMU_PTSA_MIN 0x45c +#define MC_ISP_PTSA_MIN 0x4a4 +#define MC_HOST_PTSA_MAX 0x520 +#define MC_SAX_PTSA_MAX 0x4c0 +#define MC_VE_PTSA_MIN 0x438 +#define MC_GK_PTSA_MIN 0x540 +#define MC_MSE_PTSA_MAX 0x4cc +#define MC_DISB_PTSA_MAX 0x430 +#define MC_DISB_PTSA_MIN 0x42c +#define MC_SMMU_SMMU_PTSA_RATE 0x458 +#define MC_VE2_PTSA_RATE 0x494 +#define MC_GK_PTSA_RATE 0x53c +#define MC_PTSA_GRANT_DECREMENT 0x960 +#define MC_LATENCY_ALLOWANCE_AVPC_0 0x2e4 +#define MC_LATENCY_ALLOWANCE_AXIAP_0 0x3a0 +#define MC_LATENCY_ALLOWANCE_XUSB_1 0x380 +#define MC_LATENCY_ALLOWANCE_ISP2B_0 0x384 +#define MC_LATENCY_ALLOWANCE_SDMMCAA_0 0x3bc +#define MC_LATENCY_ALLOWANCE_SDMMCA_0 0x3b8 +#define MC_LATENCY_ALLOWANCE_ISP2_0 0x370 +#define MC_LATENCY_ALLOWANCE_SE_0 0x3e0 +#define MC_LATENCY_ALLOWANCE_ISP2_1 0x374 +#define MC_LATENCY_ALLOWANCE_DC_0 0x2e8 +#define MC_LATENCY_ALLOWANCE_VIC_0 0x394 +#define MC_LATENCY_ALLOWANCE_DCB_1 0x2f8 +#define MC_LATENCY_ALLOWANCE_NVDEC_0 0x3d8 +#define MC_LATENCY_ALLOWANCE_DCB_2 0x2fc +#define MC_LATENCY_ALLOWANCE_TSEC_0 0x390 +#define MC_LATENCY_ALLOWANCE_DC_2 0x2f0 +#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0AB 0x694 +#define MC_LATENCY_ALLOWANCE_PPCS_1 0x348 +#define MC_LATENCY_ALLOWANCE_XUSB_0 0x37c +#define MC_LATENCY_ALLOWANCE_PPCS_0 0x344 +#define MC_LATENCY_ALLOWANCE_TSECB_0 0x3f0 +#define MC_LATENCY_ALLOWANCE_AFI_0 0x2e0 +#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0B 0x698 +#define MC_LATENCY_ALLOWANCE_DC_1 0x2ec +#define MC_LATENCY_ALLOWANCE_APE_0 0x3dc +#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0C 0x6a0 +#define MC_LATENCY_ALLOWANCE_A9AVP_0 0x3a4 +#define MC_LATENCY_ALLOWANCE_GPU2_0 0x3e8 +#define MC_LATENCY_ALLOWANCE_DCB_0 0x2f4 +#define MC_LATENCY_ALLOWANCE_HC_1 0x314 +#define MC_LATENCY_ALLOWANCE_SDMMC_0 0x3c0 +#define MC_LATENCY_ALLOWANCE_NVJPG_0 0x3e4 +#define MC_LATENCY_ALLOWANCE_PTC_0 0x34c +#define MC_LATENCY_ALLOWANCE_ETR_0 0x3ec +#define MC_LATENCY_ALLOWANCE_MPCORE_0 0x320 +#define MC_LATENCY_ALLOWANCE_VI2_0 0x398 +#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0BB 0x69c +#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0CB 0x6a4 +#define MC_LATENCY_ALLOWANCE_SATA_0 0x350 +#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0A 0x690 +#define MC_LATENCY_ALLOWANCE_HC_0 0x310 +#define MC_LATENCY_ALLOWANCE_DC_3 0x3c8 +#define MC_LATENCY_ALLOWANCE_GPU_0 0x3ac +#define MC_LATENCY_ALLOWANCE_SDMMCAB_0 0x3c4 +#define MC_LATENCY_ALLOWANCE_ISP2B_1 0x388 +#define MC_LATENCY_ALLOWANCE_NVENC_0 0x328 +#define MC_LATENCY_ALLOWANCE_HDA_0 0x318 +#define MC_MIN_LENGTH_APE_0 0xb34 +#define MC_MIN_LENGTH_DCB_2 0x8a8 +#define MC_MIN_LENGTH_A9AVP_0 0x950 +#define MC_MIN_LENGTH_TSEC_0 0x93c +#define MC_MIN_LENGTH_DC_1 0x898 +#define MC_MIN_LENGTH_AXIAP_0 0x94c +#define MC_MIN_LENGTH_ISP2B_0 0x930 +#define MC_MIN_LENGTH_VI2_0 0x944 +#define MC_MIN_LENGTH_DCB_0 0x8a0 +#define MC_MIN_LENGTH_DCB_1 0x8a4 +#define MC_MIN_LENGTH_PPCS_1 0x8f4 +#define MC_MIN_LENGTH_NVJPG_0 0xb3c +#define MC_MIN_LENGTH_HDA_0 0x8c4 +#define MC_MIN_LENGTH_NVENC_0 0x8d4 +#define MC_MIN_LENGTH_SDMMC_0 0xb18 +#define MC_MIN_LENGTH_ISP2B_1 0x934 +#define MC_MIN_LENGTH_HC_1 0x8c0 +#define MC_MIN_LENGTH_DC_3 0xb20 +#define MC_MIN_LENGTH_AVPC_0 0x890 +#define MC_MIN_LENGTH_VIC_0 0x940 +#define MC_MIN_LENGTH_ISP2_0 0x91c +#define MC_MIN_LENGTH_HC_0 0x8bc +#define MC_MIN_LENGTH_SE_0 0xb38 +#define MC_MIN_LENGTH_NVDEC_0 0xb30 +#define MC_MIN_LENGTH_SATA_0 0x8fc +#define MC_MIN_LENGTH_DC_0 0x894 +#define MC_MIN_LENGTH_XUSB_1 0x92c +#define MC_MIN_LENGTH_DC_2 0x89c +#define MC_MIN_LENGTH_SDMMCAA_0 0xb14 +#define MC_MIN_LENGTH_GPU_0 0xb04 +#define MC_MIN_LENGTH_ETR_0 0xb44 +#define MC_MIN_LENGTH_AFI_0 0x88c +#define MC_MIN_LENGTH_PPCS_0 0x8f0 +#define MC_MIN_LENGTH_ISP2_1 0x920 +#define MC_MIN_LENGTH_XUSB_0 0x928 +#define MC_MIN_LENGTH_MPCORE_0 0x8cc +#define MC_MIN_LENGTH_TSECB_0 0xb48 +#define MC_MIN_LENGTH_SDMMCA_0 0xb10 +#define MC_MIN_LENGTH_GPU2_0 0xb40 +#define MC_MIN_LENGTH_SDMMCAB_0 0xb1c +#define MC_MIN_LENGTH_PTC_0 0x8f8 +#define MC_EMEM_ARB_OVERRIDE_1 0x968 +#define MC_VIDEO_PROTECT_GPU_OVERRIDE_0 0x984 +#define MC_VIDEO_PROTECT_GPU_OVERRIDE_1 0x988 +#define MC_EMEM_ARB_STATS_0 0x990 +#define MC_EMEM_ARB_STATS_1 0x994 +#define MC_MTS_CARVEOUT_BOM 0x9a0 +#define MC_MTS_CARVEOUT_SIZE_MB 0x9a4 +#define MC_MTS_CARVEOUT_ADR_HI 0x9a8 +#define MC_MTS_CARVEOUT_REG_CTRL 0x9ac +#define MC_ERR_MTS_STATUS 0x9b0 +#define MC_ERR_MTS_ADR 0x9b4 +#define MC_ERR_GENERALIZED_CARVEOUT_STATUS 0xc00 +#define MC_ERR_GENERALIZED_CARVEOUT_ADR 0xc04 +#define MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS2 0xd74 +#define MC_SECURITY_CARVEOUT4_CFG0 0xcf8 +#define MC_SECURITY_CARVEOUT4_CLIENT_ACCESS2 0xd10 +#define MC_SECURITY_CARVEOUT4_SIZE_128KB 0xd04 +#define MC_SECURITY_CARVEOUT1_CLIENT_ACCESS4 0xc28 +#define MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS1 0xc30 +#define MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS4 0xc8c +#define MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS0 0xd1c +#define MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS1 0xd70 +#define MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS0 0xc2c +#define MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS4 0xd7c +#define MC_SECURITY_CARVEOUT3_SIZE_128KB 0xcb4 +#define MC_SECURITY_CARVEOUT2_CFG0 0xc58 +#define MC_SECURITY_CARVEOUT1_CFG0 0xc08 +#define MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS2 0xc84 +#define MC_SECURITY_CARVEOUT2_CLIENT_ACCESS0 0xc68 +#define MC_SECURITY_CARVEOUT3_BOM 0xcac +#define MC_SECURITY_CARVEOUT2_CLIENT_ACCESS2 0xc70 +#define MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS3 0xd78 +#define MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS0 0xc7c +#define MC_SECURITY_CARVEOUT4_CLIENT_ACCESS4 0xd18 +#define MC_SECURITY_CARVEOUT3_CLIENT_ACCESS1 0xcbc +#define MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS3 0xc38 +#define MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS2 0xc34 +#define MC_SECURITY_CARVEOUT3_CLIENT_ACCESS2 0xcc0 +#define MC_SECURITY_CARVEOUT5_CLIENT_ACCESS2 0xd60 +#define MC_SECURITY_CARVEOUT3_CFG0 0xca8 +#define MC_SECURITY_CARVEOUT3_CLIENT_ACCESS0 0xcb8 +#define MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS3 0xc88 +#define MC_SECURITY_CARVEOUT2_SIZE_128KB 0xc64 +#define MC_SECURITY_CARVEOUT5_BOM_HI 0xd50 +#define MC_SECURITY_CARVEOUT1_SIZE_128KB 0xc14 +#define MC_SECURITY_CARVEOUT4_CLIENT_ACCESS3 0xd14 +#define MC_SECURITY_CARVEOUT1_BOM 0xc0c +#define MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS4 0xd2c +#define MC_SECURITY_CARVEOUT5_CLIENT_ACCESS4 0xd68 +#define MC_SECURITY_CARVEOUT3_CLIENT_ACCESS4 0xcc8 +#define MC_SECURITY_CARVEOUT5_CLIENT_ACCESS0 0xd58 +#define MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS2 0xd24 +#define MC_SECURITY_CARVEOUT3_CLIENT_ACCESS3 0xcc4 +#define MC_SECURITY_CARVEOUT2_CLIENT_ACCESS4 0xc78 +#define MC_SECURITY_CARVEOUT1_CLIENT_ACCESS1 0xc1c +#define MC_SECURITY_CARVEOUT1_CLIENT_ACCESS0 0xc18 +#define MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS3 0xd28 +#define MC_SECURITY_CARVEOUT5_CLIENT_ACCESS1 0xd5c +#define MC_SECURITY_CARVEOUT3_BOM_HI 0xcb0 +#define MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS3 0xcd8 +#define MC_SECURITY_CARVEOUT2_BOM_HI 0xc60 +#define MC_SECURITY_CARVEOUT4_BOM_HI 0xd00 +#define MC_SECURITY_CARVEOUT5_CLIENT_ACCESS3 0xd64 +#define MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS4 0xcdc +#define MC_SECURITY_CARVEOUT2_CLIENT_FORCE_INTERNAL_ACCESS1 0xc80 +#define MC_SECURITY_CARVEOUT5_SIZE_128KB 0xd54 +#define MC_SECURITY_CARVEOUT4_CLIENT_FORCE_INTERNAL_ACCESS1 0xd20 +#define MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS2 0xcd4 +#define MC_SECURITY_CARVEOUT4_CLIENT_ACCESS1 0xd0c +#define MC_SECURITY_CARVEOUT2_CLIENT_ACCESS3 0xc74 +#define MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS0 0xccc +#define MC_SECURITY_CARVEOUT4_BOM 0xcfc +#define MC_SECURITY_CARVEOUT5_CFG0 0xd48 +#define MC_SECURITY_CARVEOUT2_BOM 0xc5c +#define MC_SECURITY_CARVEOUT5_BOM 0xd4c +#define MC_SECURITY_CARVEOUT1_CLIENT_ACCESS3 0xc24 +#define MC_SECURITY_CARVEOUT5_CLIENT_FORCE_INTERNAL_ACCESS0 0xd6c +#define MC_SECURITY_CARVEOUT3_CLIENT_FORCE_INTERNAL_ACCESS1 0xcd0 +#define MC_SECURITY_CARVEOUT1_BOM_HI 0xc10 +#define MC_SECURITY_CARVEOUT1_CLIENT_ACCESS2 0xc20 +#define MC_SECURITY_CARVEOUT1_CLIENT_FORCE_INTERNAL_ACCESS4 0xc3c +#define MC_SECURITY_CARVEOUT2_CLIENT_ACCESS1 0xc6c +#define MC_SECURITY_CARVEOUT4_CLIENT_ACCESS0 0xd08 +#define MC_ERR_APB_ASID_UPDATE_STATUS 0x9d0 +#define MC_DA_CONFIG0 0x9dc + +#endif diff --git a/nyx/nyx_gui/mem/minerva.c b/nyx/nyx_gui/mem/minerva.c new file mode 100644 index 0000000..a80bd0b --- /dev/null +++ b/nyx/nyx_gui/mem/minerva.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "minerva.h" +#include "../soc/fuse.h" +#include "../utils/util.h" + +#include "../soc/clock.h" +#include "../ianos/ianos.h" +#include "../soc/fuse.h" +#include "../soc/t210.h" + +extern volatile nyx_storage_t *nyx_str; + +void minerva_init() +{ + u32 curr_ram_idx = 0; + + mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg; + + // Set table to ram. + if (!(mtc_cfg->table_entries == 10)) + { + mtc_cfg->mtc_table = NULL; + mtc_cfg->sdram_id = (fuse_read_odm(4) >> 3) & 0x1F; + u32 ep_addr = ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)mtc_cfg); + minerva_cfg = (void *)ep_addr; + } + else + { + mtc_config_t mtc_tmp; + mtc_tmp.mtc_table = NULL; + mtc_tmp.sdram_id = (fuse_read_odm(4) >> 3) & 0x1F; + u32 ep_addr = ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)&mtc_tmp); + minerva_cfg = (void *)ep_addr; + + return; + } + + if (!minerva_cfg) + return; + + // Get current frequency + for (curr_ram_idx = 0; curr_ram_idx < 10; curr_ram_idx++) + { + if (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_EMC) == mtc_cfg->mtc_table[curr_ram_idx].clk_src_emc) + break; + } + + mtc_cfg->rate_from = mtc_cfg->mtc_table[curr_ram_idx].rate_khz; + mtc_cfg->rate_to = 204000; + mtc_cfg->train_mode = OP_TRAIN; + minerva_cfg(mtc_cfg, NULL); + mtc_cfg->rate_to = 800000; + minerva_cfg(mtc_cfg, NULL); + mtc_cfg->rate_to = 1600000; + minerva_cfg(mtc_cfg, NULL); +} + +void minerva_change_freq(minerva_freq_t freq) +{ + if (!minerva_cfg) + return; + mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg; + if (minerva_cfg && (mtc_cfg->rate_from != freq)) + { + mtc_cfg->rate_to = freq; + mtc_cfg->train_mode = OP_SWITCH; + minerva_cfg(mtc_cfg, NULL); + } +} + +void minerva_periodic_training() +{ + if (!minerva_cfg) + return; + mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg; + if (minerva_cfg && mtc_cfg->rate_from == FREQ_1600) + { + mtc_cfg->train_mode = OP_PERIODIC_TRAIN; + minerva_cfg(mtc_cfg, NULL); + } +} \ No newline at end of file diff --git a/nyx/nyx_gui/mem/minerva.h b/nyx/nyx_gui/mem/minerva.h new file mode 100644 index 0000000..dd71658 --- /dev/null +++ b/nyx/nyx_gui/mem/minerva.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _FE_MINERVA_H_ +#define _FE_MINERVA_H_ + +#include "mtc_table.h" +#include "../utils/types.h" + +#define EMC_PERIODIC_TRAIN_MS 100 + +typedef struct +{ + s32 rate_to; + s32 rate_from; + emc_table_t *mtc_table; + u32 table_entries; + emc_table_t *current_emc_table; + u32 train_mode; + u32 sdram_id; + u32 prev_temp; + bool emc_2X_clk_src_is_pllmb; + bool fsp_for_src_freq; + bool train_ram_patterns; +} mtc_config_t; + +enum train_mode_t +{ + OP_SWITCH = 0, + OP_TRAIN = 1, + OP_TRAIN_SWITCH = 2, + OP_PERIODIC_TRAIN = 3, + OP_TEMP_COMP = 4 +}; + +typedef enum +{ + FREQ_204 = 204000, + FREQ_800 = 800000, + FREQ_1600 = 1600000 +} minerva_freq_t; + +void (*minerva_cfg)(mtc_config_t *mtc_cfg, void *); +void minerva_init(); +void minerva_change_freq(minerva_freq_t freq); +void minerva_periodic_training(); + +#endif diff --git a/nyx/nyx_gui/mem/mtc_table.h b/nyx/nyx_gui/mem/mtc_table.h new file mode 100644 index 0000000..7f18232 --- /dev/null +++ b/nyx/nyx_gui/mem/mtc_table.h @@ -0,0 +1,560 @@ +/* + * Minerva Training Cell + * DRAM Training for Tegra X1 SoC. Supports DDR2/3 and LPDDR3/4. + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _MTC_TABLE_H_ +#define _MTC_TABLE_H_ + +#include "../utils/types.h" + +typedef struct +{ + s32 pll_osc_in; + s32 pll_out; + u32 pll_feedback_div; + u32 pll_input_div; + u32 pll_post_div; +} pllm_clk_config_t; + +typedef struct +{ + u32 emc_rc_idx; + u32 emc_rfc_idx; + u32 emc_rfcpb_idx; + u32 emc_refctrl2_idx; + u32 emc_rfc_slr_idx; + u32 emc_ras_idx; + u32 emc_rp_idx; + u32 emc_r2w_idx; + u32 emc_w2r_idx; + u32 emc_r2p_idx; + u32 emc_w2p_idx; + u32 emc_r2r_idx; + u32 emc_tppd_idx; + u32 emc_ccdmw_idx; + u32 emc_rd_rcd_idx; + u32 emc_wr_rcd_idx; + u32 emc_rrd_idx; + u32 emc_rext_idx; + u32 emc_wext_idx; + u32 emc_wdv_chk_idx; + u32 emc_wdv_idx; + u32 emc_wsv_idx; + u32 emc_wev_idx; + u32 emc_wdv_mask_idx; + u32 emc_ws_duration_idx; + u32 emc_we_duration_idx; + u32 emc_quse_idx; + u32 emc_quse_width_idx; + u32 emc_ibdly_idx; + u32 emc_obdly_idx; + u32 emc_einput_idx; + u32 emc_mrw6_idx; + u32 emc_einput_duration_idx; + u32 emc_puterm_extra_idx; + u32 emc_puterm_width_idx; + u32 emc_qrst_idx; + u32 emc_qsafe_idx; + u32 emc_rdv_idx; + u32 emc_rdv_mask_idx; + u32 emc_rdv_early_idx; + u32 emc_rdv_early_mask_idx; + u32 emc_refresh_idx; + u32 emc_burst_refresh_num_idx; + u32 emc_pre_refresh_req_cnt_idx; + u32 emc_pdex2wr_idx; + u32 emc_pdex2rd_idx; + u32 emc_pchg2pden_idx; + u32 emc_act2pden_idx; + u32 emc_ar2pden_idx; + u32 emc_rw2pden_idx; + u32 emc_cke2pden_idx; + u32 emc_pdex2cke_idx; + u32 emc_pdex2mrr_idx; + u32 emc_txsr_idx; + u32 emc_txsrdll_idx; + u32 emc_tcke_idx; + u32 emc_tckesr_idx; + u32 emc_tpd_idx; + u32 emc_tfaw_idx; + u32 emc_trpab_idx; + u32 emc_tclkstable_idx; + u32 emc_tclkstop_idx; + u32 emc_mrw7_idx; + u32 emc_trefbw_idx; + u32 emc_odt_write_idx; + u32 emc_fbio_cfg5_idx; + u32 emc_fbio_cfg7_idx; + u32 emc_cfg_dig_dll_idx; + u32 emc_cfg_dig_dll_period_idx; + u32 emc_pmacro_ib_rxrt_idx; + u32 emc_cfg_pipe_1_idx; + u32 emc_cfg_pipe_2_idx; + u32 emc_pmacro_quse_ddll_rank0_4_idx; + u32 emc_pmacro_quse_ddll_rank0_5_idx; + u32 emc_pmacro_quse_ddll_rank1_4_idx; + u32 emc_pmacro_quse_ddll_rank1_5_idx; + u32 emc_mrw8_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank1_4_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank1_5_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_0_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_1_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_2_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_3_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_4_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_5_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_0_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_1_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_2_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_3_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_4_idx; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_5_idx; + u32 emc_pmacro_ddll_long_cmd_0_idx; + u32 emc_pmacro_ddll_long_cmd_1_idx; + u32 emc_pmacro_ddll_long_cmd_2_idx; + u32 emc_pmacro_ddll_long_cmd_3_idx; + u32 emc_pmacro_ddll_long_cmd_4_idx; + u32 emc_pmacro_ddll_short_cmd_0_idx; + u32 emc_pmacro_ddll_short_cmd_1_idx; + u32 emc_pmacro_ddll_short_cmd_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte0_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte1_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte2_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte3_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte4_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte5_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte6_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte7_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd0_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd1_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd2_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd3_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte0_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte1_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte2_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte3_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte4_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte5_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte6_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte7_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd0_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd0_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd0_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd0_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd1_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd1_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd1_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd1_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd2_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd2_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd2_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd2_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd3_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd3_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd3_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd3_3_idx; + u32 emc_txdsrvttgen_idx; + u32 emc_fdpd_ctrl_dq_idx; + u32 emc_fdpd_ctrl_cmd_idx; + u32 emc_fbio_spare_idx; + u32 emc_zcal_interval_idx; + u32 emc_zcal_wait_cnt_idx; + u32 emc_mrs_wait_cnt_idx; + u32 emc_mrs_wait_cnt2_idx; + u32 emc_auto_cal_channel_idx; + u32 emc_dll_cfg_0_idx; + u32 emc_dll_cfg_1_idx; + u32 emc_pmacro_autocal_cfg_common_idx; + u32 emc_pmacro_zctrl_idx; + u32 emc_cfg_idx; + u32 emc_cfg_pipe_idx; + u32 emc_dyn_self_ref_control_idx; + u32 emc_qpop_idx; + u32 emc_dqs_brlshft_0_idx; + u32 emc_dqs_brlshft_1_idx; + u32 emc_cmd_brlshft_2_idx; + u32 emc_cmd_brlshft_3_idx; + u32 emc_pmacro_pad_cfg_ctrl_idx; + u32 emc_pmacro_data_pad_rx_ctrl_idx; + u32 emc_pmacro_cmd_pad_rx_ctrl_idx; + u32 emc_pmacro_data_rx_term_mode_idx; + u32 emc_pmacro_cmd_rx_term_mode_idx; + u32 emc_pmacro_cmd_pad_tx_ctrl_idx; + u32 emc_pmacro_data_pad_tx_ctrl_idx; + u32 emc_pmacro_common_pad_tx_ctrl_idx; + u32 emc_pmacro_vttgen_ctrl_0_idx; + u32 emc_pmacro_vttgen_ctrl_1_idx; + u32 emc_pmacro_vttgen_ctrl_2_idx; + u32 emc_pmacro_brick_ctrl_rfu1_idx; + u32 emc_pmacro_cmd_brick_ctrl_fdpd_idx; + u32 emc_pmacro_brick_ctrl_rfu2_idx; + u32 emc_pmacro_data_brick_ctrl_fdpd_idx; + u32 emc_pmacro_bg_bias_ctrl_0_idx; + u32 emc_cfg_3_idx; + u32 emc_pmacro_tx_pwrd_0_idx; + u32 emc_pmacro_tx_pwrd_1_idx; + u32 emc_pmacro_tx_pwrd_2_idx; + u32 emc_pmacro_tx_pwrd_3_idx; + u32 emc_pmacro_tx_pwrd_4_idx; + u32 emc_pmacro_tx_pwrd_5_idx; + u32 emc_config_sample_delay_idx; + u32 emc_pmacro_tx_sel_clk_src_0_idx; + u32 emc_pmacro_tx_sel_clk_src_1_idx; + u32 emc_pmacro_tx_sel_clk_src_2_idx; + u32 emc_pmacro_tx_sel_clk_src_3_idx; + u32 emc_pmacro_tx_sel_clk_src_4_idx; + u32 emc_pmacro_tx_sel_clk_src_5_idx; + u32 emc_pmacro_ddll_bypass_idx; + u32 emc_pmacro_ddll_pwrd_0_idx; + u32 emc_pmacro_ddll_pwrd_1_idx; + u32 emc_pmacro_ddll_pwrd_2_idx; + u32 emc_pmacro_cmd_ctrl_0_idx; + u32 emc_pmacro_cmd_ctrl_1_idx; + u32 emc_pmacro_cmd_ctrl_2_idx; + u32 emc_tr_timing_0_idx; + u32 emc_tr_dvfs_idx; + u32 emc_tr_ctrl_1_idx; + u32 emc_tr_rdv_idx; + u32 emc_tr_qpop_idx; + u32 emc_tr_rdv_mask_idx; + u32 emc_mrw14_idx; + u32 emc_tr_qsafe_idx; + u32 emc_tr_qrst_idx; + u32 emc_training_ctrl_idx; + u32 emc_training_settle_idx; + u32 emc_training_vref_settle_idx; + u32 emc_training_ca_fine_ctrl_idx; + u32 emc_training_ca_ctrl_misc_idx; + u32 emc_training_ca_ctrl_misc1_idx; + u32 emc_training_ca_vref_ctrl_idx; + u32 emc_training_quse_cors_ctrl_idx; + u32 emc_training_quse_fine_ctrl_idx; + u32 emc_training_quse_ctrl_misc_idx; + u32 emc_training_quse_vref_ctrl_idx; + u32 emc_training_read_fine_ctrl_idx; + u32 emc_training_read_ctrl_misc_idx; + u32 emc_training_read_vref_ctrl_idx; + u32 emc_training_write_fine_ctrl_idx; + u32 emc_training_write_ctrl_misc_idx; + u32 emc_training_write_vref_ctrl_idx; + u32 emc_training_mpc_idx; + u32 emc_mrw15_idx; +} burst_regs_t; + + +typedef struct +{ + u32 burst_regs[221]; + u32 burst_reg_per_ch[8]; + u32 shadow_regs_ca_train[221]; + u32 shadow_regs_quse_train[221]; + u32 shadow_regs_rdwr_train[221]; +} burst_regs_table_t; + +typedef struct +{ + u32 ptfv_dqsosc_movavg_c0d0u0_idx; + u32 ptfv_dqsosc_movavg_c0d0u1_idx; + u32 ptfv_dqsosc_movavg_c0d1u0_idx; + u32 ptfv_dqsosc_movavg_c0d1u1_idx; + u32 ptfv_dqsosc_movavg_c1d0u0_idx; + u32 ptfv_dqsosc_movavg_c1d0u1_idx; + u32 ptfv_dqsosc_movavg_c1d1u0_idx; + u32 ptfv_dqsosc_movavg_c1d1u1_idx; + u32 ptfv_write_samples_idx; + u32 ptfv_dvfs_samples_idx; + u32 ptfv_movavg_weight_idx; + u32 ptfv_config_ctrl_idx; +} ptfv_list_table_t; + +typedef struct +{ + u32 emc0_mrw10_idx; + u32 emc1_mrw10_idx; + u32 emc0_mrw11_idx; + u32 emc1_mrw11_idx; + u32 emc0_mrw12_idx; + u32 emc1_mrw12_idx; + u32 emc0_mrw13_idx; + u32 emc1_mrw13_idx; +} burst_reg_per_ch_t; + +typedef struct +{ + u32 emc_pmacro_ib_ddll_long_dqs_rank0_0_idx; + u32 emc_pmacro_ib_ddll_long_dqs_rank0_1_idx; + u32 emc_pmacro_ib_ddll_long_dqs_rank0_2_idx; + u32 emc_pmacro_ib_ddll_long_dqs_rank0_3_idx; + u32 emc_pmacro_ib_ddll_long_dqs_rank1_0_idx; + u32 emc_pmacro_ib_ddll_long_dqs_rank1_1_idx; + u32 emc_pmacro_ib_ddll_long_dqs_rank1_2_idx; + u32 emc_pmacro_ib_ddll_long_dqs_rank1_3_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte0_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte0_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte0_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte1_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte1_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte1_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte2_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte2_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte2_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte3_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte3_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte3_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte4_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte4_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte4_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte5_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte5_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte5_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte6_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte6_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte6_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte7_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte7_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank0_byte7_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte0_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte0_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte0_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte1_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte1_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte1_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte2_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte2_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte2_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte3_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte3_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte3_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte4_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte4_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte4_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte5_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte5_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte5_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte6_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte6_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte6_2_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte7_0_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte7_1_idx; + u32 emc_pmacro_ib_ddll_short_dq_rank1_byte7_2_idx; + u32 emc_pmacro_ib_vref_dqs_0_idx; + u32 emc_pmacro_ib_vref_dqs_1_idx; + u32 emc_pmacro_ib_vref_dq_0_idx; + u32 emc_pmacro_ib_vref_dq_1_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank0_0_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank0_1_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank0_2_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank0_3_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank0_4_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank0_5_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank1_0_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank1_1_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank1_2_idx; + u32 emc_pmacro_ob_ddll_long_dq_rank1_3_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte0_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte0_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte0_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte1_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte1_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte1_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte2_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte2_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte2_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte3_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte3_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte3_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte4_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte4_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte4_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte5_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte5_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte5_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte6_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte6_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte6_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte7_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte7_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_byte7_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd0_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd0_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd0_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd1_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd1_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd1_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd2_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd2_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd2_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd3_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd3_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd3_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte0_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte0_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte0_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte1_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte1_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte1_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte2_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte2_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte2_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte3_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte3_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte3_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte4_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte4_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte4_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte5_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte5_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte5_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte6_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte6_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte6_2_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte7_0_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte7_1_idx; + u32 emc_pmacro_ob_ddll_short_dq_rank1_byte7_2_idx; + u32 emc_pmacro_quse_ddll_rank0_0_idx; + u32 emc_pmacro_quse_ddll_rank0_1_idx; + u32 emc_pmacro_quse_ddll_rank0_2_idx; + u32 emc_pmacro_quse_ddll_rank0_3_idx; + u32 emc_pmacro_quse_ddll_rank1_0_idx; + u32 emc_pmacro_quse_ddll_rank1_1_idx; + u32 emc_pmacro_quse_ddll_rank1_2_idx; + u32 emc_pmacro_quse_ddll_rank1_3_idx; +} trim_regs_t; + +typedef struct +{ + u32 emc_cmd_brlshft_0_idx; + u32 emc_cmd_brlshft_1_idx; + u32 emc0_data_brlshft_0_idx; + u32 emc1_data_brlshft_0_idx; + u32 emc0_data_brlshft_1_idx; + u32 emc1_data_brlshft_1_idx; + u32 emc_quse_brlshft_0_idx; + u32 emc_quse_brlshft_1_idx; + u32 emc_quse_brlshft_2_idx; + u32 emc_quse_brlshft_3_idx; +} trim_perch_regs_t; + +typedef struct +{ + u32 t_rp; + u32 t_fc_lpddr4; + u32 t_rfc; + u32 t_pdex; + u32 rl; +} dram_timings_t; + +typedef struct +{ + u32 emc0_training_opt_dqs_ib_vref_rank0_idx; + u32 emc1_training_opt_dqs_ib_vref_rank0_idx; + u32 emc0_training_opt_dqs_ib_vref_rank1_idx; + u32 emc1_training_opt_dqs_ib_vref_rank1_idx; +} vref_perch_regs_t; + +typedef struct +{ + u32 trim_regs[138]; + u32 trim_perch_regs[10]; + u32 vref_perch_regs[4]; +} trim_regs_table_t; + +typedef struct +{ + u32 rev; + char dvfs_ver[60]; + u32 rate_khz; + u32 min_volt; + u32 gpu_min_volt; + char clock_src[32]; + u32 clk_src_emc; + u32 needs_training; + u32 training_pattern; + u32 trained; + u32 periodic_training; + u32 trained_dram_clktree_c0d0u0; + u32 trained_dram_clktree_c0d0u1; + u32 trained_dram_clktree_c0d1u0; + u32 trained_dram_clktree_c0d1u1; + u32 trained_dram_clktree_c1d0u0; + u32 trained_dram_clktree_c1d0u1; + u32 trained_dram_clktree_c1d1u0; + u32 trained_dram_clktree_c1d1u1; + u32 current_dram_clktree_c0d0u0; + u32 current_dram_clktree_c0d0u1; + u32 current_dram_clktree_c0d1u0; + u32 current_dram_clktree_c0d1u1; + u32 current_dram_clktree_c1d0u0; + u32 current_dram_clktree_c1d0u1; + u32 current_dram_clktree_c1d1u0; + u32 current_dram_clktree_c1d1u1; + u32 run_clocks; + u32 tree_margin; + u32 num_burst; + u32 num_burst_per_ch; + u32 num_trim; + u32 num_trim_per_ch; + u32 num_mc_regs; + u32 num_up_down; + u32 vref_num; + u32 training_mod_num; + u32 dram_timing_num; + + ptfv_list_table_t ptfv_list; + + burst_regs_t burst_regs; + burst_reg_per_ch_t burst_reg_per_ch; + burst_regs_t shadow_regs_ca_train; + burst_regs_t shadow_regs_quse_train; + burst_regs_t shadow_regs_rdwr_train; + trim_regs_t trim_regs; + trim_perch_regs_t trim_perch_regs; + vref_perch_regs_t vref_perch_regs; + dram_timings_t dram_timings; + + u32 training_mod_regs[20]; + u32 save_restore_mod_regs[12]; + u32 burst_mc_regs[33]; + u32 la_scale_regs[24]; + + u32 min_mrs_wait; + u32 emc_mrw; + u32 emc_mrw2; + u32 emc_mrw3; + u32 emc_mrw4; + u32 emc_mrw9; + u32 emc_mrs; + u32 emc_emrs; + u32 emc_emrs2; + u32 emc_auto_cal_config; + u32 emc_auto_cal_config2; + u32 emc_auto_cal_config3; + u32 emc_auto_cal_config4; + u32 emc_auto_cal_config5; + u32 emc_auto_cal_config6; + u32 emc_auto_cal_config7; + u32 emc_auto_cal_config8; + u32 emc_cfg_2; + u32 emc_sel_dpd_ctrl; + u32 emc_fdpd_ctrl_cmd_no_ramp; + u32 dll_clk_src; + u32 clk_out_enb_x_0_clk_enb_emc_dll; + u32 latency; +} emc_table_t; + +#endif \ No newline at end of file diff --git a/nyx/nyx_gui/mem/sdram.c b/nyx/nyx_gui/mem/sdram.c new file mode 100644 index 0000000..b809d08 --- /dev/null +++ b/nyx/nyx_gui/mem/sdram.c @@ -0,0 +1,565 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 balika011 + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../soc/i2c.h" +#include "../soc/t210.h" +#include "mc.h" +#include "emc.h" +#include "sdram_param_t210.h" +#include "../soc/pmc.h" +#include "../utils/util.h" +#include "../soc/fuse.h" +#include "../power/max77620.h" +#include "../power/max7762x.h" +#include "../soc/clock.h" + +#define CONFIG_SDRAM_COMPRESS_CFG + +#ifdef CONFIG_SDRAM_COMPRESS_CFG +#include "../libs/compr/lz.h" +#include "sdram_config_lz.inl" +#else +#include "sdram_config.inl" +#endif + +static u32 _get_sdram_id() +{ + return (fuse_read_odm(4) & 0x38) >> 3; +} + +static void _sdram_config(const sdram_params_t *params) +{ + PMC(APBDEV_PMC_IO_DPD3_REQ) = (((4 * params->emc_pmc_scratch1 >> 2) + 0x80000000) ^ 0xFFFF) & 0xC000FFFF; + usleep(params->pmc_io_dpd3_req_wait); + + u32 req = (4 * params->emc_pmc_scratch2 >> 2) + 0x80000000; + PMC(APBDEV_PMC_IO_DPD4_REQ) = (req >> 16 << 16) ^ 0x3FFF0000; + usleep(params->pmc_io_dpd4_req_wait); + PMC(APBDEV_PMC_IO_DPD4_REQ) = (req ^ 0xFFFF) & 0xC000FFFF; + usleep(params->pmc_io_dpd4_req_wait); + PMC(APBDEV_PMC_WEAK_BIAS) = 0; + usleep(1); + + CLOCK(CLK_RST_CONTROLLER_PLLM_MISC1) = params->pllm_setup_control; + CLOCK(CLK_RST_CONTROLLER_PLLM_MISC2) = 0; + CLOCK(CLK_RST_CONTROLLER_PLLM_BASE) = (params->pllm_feedback_divider << 8) | params->pllm_input_divider | 0x40000000 | ((params->pllm_post_divider & 0xFFFF) << 20); + + u32 wait_end = get_tmr_us() + 300; + while (!(CLOCK(CLK_RST_CONTROLLER_PLLM_BASE) & 0x8000000)) + { + if (get_tmr_us() >= wait_end) + goto break_nosleep; + } + usleep(10); +break_nosleep: + + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_EMC) = ((params->mc_emem_arb_misc0 >> 11) & 0x10000) | (params->emc_clock_source & 0xFFFEFFFF); + if (params->emc_clock_source_dll) + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_EMC_DLL) = params->emc_clock_source_dll; + if (params->clear_clock2_mc1) + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_W_CLR) = 0x40000000; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_H_SET) = 0x2000001; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_X_SET) = 0x4000; + CLOCK(CLK_RST_CONTROLLER_RST_DEV_H_CLR) = 0x2000001; + EMC(EMC_PMACRO_VTTGEN_CTRL_0) = params->emc_pmacro_vttgen_ctrl0; + EMC(EMC_PMACRO_VTTGEN_CTRL_1) = params->emc_pmacro_vttgen_ctrl1; + EMC(EMC_PMACRO_VTTGEN_CTRL_2) = params->emc_pmacro_vttgen_ctrl2; + EMC(EMC_TIMING_CONTROL) = 1; + usleep(1); + EMC(EMC_DBG) = (params->emc_dbg_write_mux << 1) | params->emc_dbg; + if (params->emc_bct_spare2) + *(vu32 *)params->emc_bct_spare2 = params->emc_bct_spare3; + EMC(EMC_FBIO_CFG7) = params->emc_fbio_cfg7; + EMC(EMC_CMD_MAPPING_CMD0_0) = params->emc_cmd_mapping_cmd0_0; + EMC(EMC_CMD_MAPPING_CMD0_1) = params->emc_cmd_mapping_cmd0_1; + EMC(EMC_CMD_MAPPING_CMD0_2) = params->emc_cmd_mapping_cmd0_2; + EMC(EMC_CMD_MAPPING_CMD1_0) = params->emc_cmd_mapping_cmd1_0; + EMC(EMC_CMD_MAPPING_CMD1_1) = params->emc_cmd_mapping_cmd1_1; + EMC(EMC_CMD_MAPPING_CMD1_2) = params->emc_cmd_mapping_cmd1_2; + EMC(EMC_CMD_MAPPING_CMD2_0) = params->emc_cmd_mapping_cmd2_0; + EMC(EMC_CMD_MAPPING_CMD2_1) = params->emc_cmd_mapping_cmd2_1; + EMC(EMC_CMD_MAPPING_CMD2_2) = params->emc_cmd_mapping_cmd2_2; + EMC(EMC_CMD_MAPPING_CMD3_0) = params->emc_cmd_mapping_cmd3_0; + EMC(EMC_CMD_MAPPING_CMD3_1) = params->emc_cmd_mapping_cmd3_1; + EMC(EMC_CMD_MAPPING_CMD3_2) = params->emc_cmd_mapping_cmd3_2; + EMC(EMC_CMD_MAPPING_BYTE) = params->emc_cmd_mapping_byte; + EMC(EMC_PMACRO_BRICK_MAPPING_0) = params->emc_pmacro_brick_mapping0; + EMC(EMC_PMACRO_BRICK_MAPPING_1) = params->emc_pmacro_brick_mapping1; + EMC(EMC_PMACRO_BRICK_MAPPING_2) = params->emc_pmacro_brick_mapping2; + EMC(EMC_PMACRO_BRICK_CTRL_RFU1) = (params->emc_pmacro_brick_ctrl_rfu1 & 0x1120112) | 0x1EED1EED; + EMC(EMC_CONFIG_SAMPLE_DELAY) = params->emc_config_sample_delay; + EMC(EMC_FBIO_CFG8) = params->emc_fbio_cfg8; + EMC(EMC_SWIZZLE_RANK0_BYTE0) = params->emc_swizzle_rank0_byte0; + EMC(EMC_SWIZZLE_RANK0_BYTE1) = params->emc_swizzle_rank0_byte1; + EMC(EMC_SWIZZLE_RANK0_BYTE2) = params->emc_swizzle_rank0_byte2; + EMC(EMC_SWIZZLE_RANK0_BYTE3) = params->emc_swizzle_rank0_byte3; + EMC(EMC_SWIZZLE_RANK1_BYTE0) = params->emc_swizzle_rank1_byte0; + EMC(EMC_SWIZZLE_RANK1_BYTE1) = params->emc_swizzle_rank1_byte1; + EMC(EMC_SWIZZLE_RANK1_BYTE2) = params->emc_swizzle_rank1_byte2; + EMC(EMC_SWIZZLE_RANK1_BYTE3) = params->emc_swizzle_rank1_byte3; + if (params->emc_bct_spare6) + *(vu32 *)params->emc_bct_spare6 = params->emc_bct_spare7; + EMC(EMC_XM2COMPPADCTRL) = params->emc_xm2_comp_pad_ctrl; + EMC(EMC_XM2COMPPADCTRL2) = params->emc_xm2_comp_pad_ctrl2; + EMC(EMC_XM2COMPPADCTRL3) = params->emc_xm2_comp_pad_ctrl3; + EMC(EMC_AUTO_CAL_CONFIG2) = params->emc_auto_cal_config2; + EMC(EMC_AUTO_CAL_CONFIG3) = params->emc_auto_cal_config3; + EMC(EMC_AUTO_CAL_CONFIG4) = params->emc_auto_cal_config4; + EMC(EMC_AUTO_CAL_CONFIG5) = params->emc_auto_cal_config5; + EMC(EMC_AUTO_CAL_CONFIG6) = params->emc_auto_cal_config6; + EMC(EMC_AUTO_CAL_CONFIG7) = params->emc_auto_cal_config7; + EMC(EMC_AUTO_CAL_CONFIG8) = params->emc_auto_cal_config8; + EMC(EMC_PMACRO_RX_TERM) = params->emc_pmacro_rx_term; + EMC(EMC_PMACRO_DQ_TX_DRV) = params->emc_pmacro_dq_tx_drive; + EMC(EMC_PMACRO_CA_TX_DRV) = params->emc_pmacro_ca_tx_drive; + EMC(EMC_PMACRO_CMD_TX_DRV) = params->emc_pmacro_cmd_tx_drive; + EMC(EMC_PMACRO_AUTOCAL_CFG_COMMON) = params->emc_pmacro_auto_cal_common; + EMC(EMC_AUTO_CAL_CHANNEL) = params->emc_auto_cal_channel; + EMC(EMC_PMACRO_ZCTRL) = params->emc_pmacro_zcrtl; + EMC(EMC_DLL_CFG_0) = params->emc_dll_cfg0; + EMC(EMC_DLL_CFG_1) = params->emc_dll_cfg1; + EMC(EMC_CFG_DIG_DLL_1) = params->emc_cfg_dig_dll_1; + EMC(EMC_DATA_BRLSHFT_0) = params->emc_data_brlshft0; + EMC(EMC_DATA_BRLSHFT_1) = params->emc_data_brlshft1; + EMC(EMC_DQS_BRLSHFT_0) = params->emc_dqs_brlshft0; + EMC(EMC_DQS_BRLSHFT_1) = params->emc_dqs_brlshft1; + EMC(EMC_CMD_BRLSHFT_0) = params->emc_cmd_brlshft0; + EMC(EMC_CMD_BRLSHFT_1) = params->emc_cmd_brlshft1; + EMC(EMC_CMD_BRLSHFT_2) = params->emc_cmd_brlshft2; + EMC(EMC_CMD_BRLSHFT_3) = params->emc_cmd_brlshft3; + EMC(EMC_QUSE_BRLSHFT_0) = params->emc_quse_brlshft0; + EMC(EMC_QUSE_BRLSHFT_1) = params->emc_quse_brlshft1; + EMC(EMC_QUSE_BRLSHFT_2) = params->emc_quse_brlshft2; + EMC(EMC_QUSE_BRLSHFT_3) = params->emc_quse_brlshft3; + EMC(EMC_PMACRO_BRICK_CTRL_RFU1) = (params->emc_pmacro_brick_ctrl_rfu1 & 0x1BF01BF) | 0x1E401E40; + EMC(EMC_PMACRO_PAD_CFG_CTRL) = params->emc_pmacro_pad_cfg_ctrl; + EMC(EMC_PMACRO_CMD_BRICK_CTRL_FDPD) = params->emc_pmacro_cmd_brick_ctrl_fdpd; + EMC(EMC_PMACRO_BRICK_CTRL_RFU2) = params->emc_pmacro_brick_ctrl_rfu2 & 0xFF7FFF7F; + EMC(EMC_PMACRO_DATA_BRICK_CTRL_FDPD) = params->emc_pmacro_data_brick_ctrl_fdpd; + EMC(EMC_PMACRO_BG_BIAS_CTRL_0) = params->emc_pmacro_bg_bias_ctrl0; + EMC(EMC_PMACRO_DATA_PAD_RX_CTRL) = params->emc_pmacro_data_pad_rx_ctrl; + EMC(EMC_PMACRO_CMD_PAD_RX_CTRL) = params->emc_pmacro_cmd_pad_rx_ctrl; + EMC(EMC_PMACRO_DATA_PAD_TX_CTRL) = params->emc_pmacro_data_pad_tx_ctrl; + EMC(EMC_PMACRO_DATA_RX_TERM_MODE) = params->emc_pmacro_data_rx_term_mode; + EMC(EMC_PMACRO_CMD_RX_TERM_MODE) = params->emc_pmacro_cmd_rx_term_mode; + EMC(EMC_PMACRO_CMD_PAD_TX_CTRL) = params->emc_pmacro_cmd_pad_tx_ctrl; + EMC(EMC_CFG_3) = params->emc_cfg3; + EMC(EMC_PMACRO_TX_PWRD_0) = params->emc_pmacro_tx_pwrd0; + EMC(EMC_PMACRO_TX_PWRD_1) = params->emc_pmacro_tx_pwrd1; + EMC(EMC_PMACRO_TX_PWRD_2) = params->emc_pmacro_tx_pwrd2; + EMC(EMC_PMACRO_TX_PWRD_3) = params->emc_pmacro_tx_pwrd3; + EMC(EMC_PMACRO_TX_PWRD_4) = params->emc_pmacro_tx_pwrd4; + EMC(EMC_PMACRO_TX_PWRD_5) = params->emc_pmacro_tx_pwrd5; + EMC(EMC_PMACRO_TX_SEL_CLK_SRC_0) = params->emc_pmacro_tx_sel_clk_src0; + EMC(EMC_PMACRO_TX_SEL_CLK_SRC_1) = params->emc_pmacro_tx_sel_clk_src1; + EMC(EMC_PMACRO_TX_SEL_CLK_SRC_2) = params->emc_pmacro_tx_sel_clk_src2; + EMC(EMC_PMACRO_TX_SEL_CLK_SRC_3) = params->emc_pmacro_tx_sel_clk_src3; + EMC(EMC_PMACRO_TX_SEL_CLK_SRC_4) = params->emc_pmacro_tx_sel_clk_src4; + EMC(EMC_PMACRO_TX_SEL_CLK_SRC_5) = params->emc_pmacro_tx_sel_clk_src5; + EMC(EMC_PMACRO_DDLL_BYPASS) = params->emc_pmacro_ddll_bypass; + EMC(EMC_PMACRO_DDLL_PWRD_0) = params->emc_pmacro_ddll_pwrd0; + EMC(EMC_PMACRO_DDLL_PWRD_1) = params->emc_pmacro_ddll_pwrd1; + EMC(EMC_PMACRO_DDLL_PWRD_2) = params->emc_pmacro_ddll_pwrd2; + EMC(EMC_PMACRO_CMD_CTRL_0) = params->emc_pmacro_cmd_ctrl0; + EMC(EMC_PMACRO_CMD_CTRL_1) = params->emc_pmacro_cmd_ctrl1; + EMC(EMC_PMACRO_CMD_CTRL_2) = params->emc_pmacro_cmd_ctrl2; + EMC(EMC_PMACRO_IB_VREF_DQ_0) = params->emc_pmacro_ib_vref_dq_0; + EMC(EMC_PMACRO_IB_VREF_DQ_1) = params->emc_pmacro_ib_vref_dq_1; + EMC(EMC_PMACRO_IB_VREF_DQS_0) = params->emc_pmacro_ib_vref_dqs_0; + EMC(EMC_PMACRO_IB_VREF_DQS_1) = params->emc_pmacro_ib_vref_dqs_1; + EMC(EMC_PMACRO_IB_RXRT) = params->emc_pmacro_ib_rxrt; + EMC(EMC_PMACRO_QUSE_DDLL_RANK0_0) = params->emc_pmacro_quse_ddll_rank0_0; + EMC(EMC_PMACRO_QUSE_DDLL_RANK0_1) = params->emc_pmacro_quse_ddll_rank0_1; + EMC(EMC_PMACRO_QUSE_DDLL_RANK0_2) = params->emc_pmacro_quse_ddll_rank0_2; + EMC(EMC_PMACRO_QUSE_DDLL_RANK0_3) = params->emc_pmacro_quse_ddll_rank0_3; + EMC(EMC_PMACRO_QUSE_DDLL_RANK0_4) = params->emc_pmacro_quse_ddll_rank0_4; + EMC(EMC_PMACRO_QUSE_DDLL_RANK0_5) = params->emc_pmacro_quse_ddll_rank0_5; + EMC(EMC_PMACRO_QUSE_DDLL_RANK1_0) = params->emc_pmacro_quse_ddll_rank1_0; + EMC(EMC_PMACRO_QUSE_DDLL_RANK1_1) = params->emc_pmacro_quse_ddll_rank1_1; + EMC(EMC_PMACRO_QUSE_DDLL_RANK1_2) = params->emc_pmacro_quse_ddll_rank1_2; + EMC(EMC_PMACRO_QUSE_DDLL_RANK1_3) = params->emc_pmacro_quse_ddll_rank1_3; + EMC(EMC_PMACRO_QUSE_DDLL_RANK1_4) = params->emc_pmacro_quse_ddll_rank1_4; + EMC(EMC_PMACRO_QUSE_DDLL_RANK1_5) = params->emc_pmacro_quse_ddll_rank1_5; + EMC(EMC_PMACRO_BRICK_CTRL_RFU1) = params->emc_pmacro_brick_ctrl_rfu1; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_0) = params->emc_pmacro_ob_ddll_long_dq_rank0_0; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_1) = params->emc_pmacro_ob_ddll_long_dq_rank0_1; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_2) = params->emc_pmacro_ob_ddll_long_dq_rank0_2; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_3) = params->emc_pmacro_ob_ddll_long_dq_rank0_3; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_4) = params->emc_pmacro_ob_ddll_long_dq_rank0_4; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_5) = params->emc_pmacro_ob_ddll_long_dq_rank0_5; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_0) = params->emc_pmacro_ob_ddll_long_dq_rank1_0; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_1) = params->emc_pmacro_ob_ddll_long_dq_rank1_1; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_2) = params->emc_pmacro_ob_ddll_long_dq_rank1_2; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_3) = params->emc_pmacro_ob_ddll_long_dq_rank1_3; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_4) = params->emc_pmacro_ob_ddll_long_dq_rank1_4; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_5) = params->emc_pmacro_ob_ddll_long_dq_rank1_5; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_0) = params->emc_pmacro_ob_ddll_long_dqs_rank0_0; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_1) = params->emc_pmacro_ob_ddll_long_dqs_rank0_1; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_2) = params->emc_pmacro_ob_ddll_long_dqs_rank0_2; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_3) = params->emc_pmacro_ob_ddll_long_dqs_rank0_3; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_4) = params->emc_pmacro_ob_ddll_long_dqs_rank0_4; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_5) = params->emc_pmacro_ob_ddll_long_dqs_rank0_5; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_0) = params->emc_pmacro_ob_ddll_long_dqs_rank1_0; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_1) = params->emc_pmacro_ob_ddll_long_dqs_rank1_1; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_2) = params->emc_pmacro_ob_ddll_long_dqs_rank1_2; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_3) = params->emc_pmacro_ob_ddll_long_dqs_rank1_3; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_4) = params->emc_pmacro_ob_ddll_long_dqs_rank1_4; + EMC(EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_5) = params->emc_pmacro_ob_ddll_long_dqs_rank1_5; + EMC(EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_0) = params->emc_pmacro_ib_ddll_long_dqs_rank0_0; + EMC(EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_1) = params->emc_pmacro_ib_ddll_long_dqs_rank0_1; + EMC(EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_2) = params->emc_pmacro_ib_ddll_long_dqs_rank0_2; + EMC(EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_3) = params->emc_pmacro_ib_ddll_long_dqs_rank0_3; + EMC(EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_0) = params->emc_pmacro_ib_ddll_long_dqs_rank1_0; + EMC(EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_1) = params->emc_pmacro_ib_ddll_long_dqs_rank1_1; + EMC(EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_2) = params->emc_pmacro_ib_ddll_long_dqs_rank1_2; + EMC(EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_3) = params->emc_pmacro_ib_ddll_long_dqs_rank1_3; + EMC(EMC_PMACRO_DDLL_LONG_CMD_0) = params->emc_pmacro_ddll_long_cmd_0; + EMC(EMC_PMACRO_DDLL_LONG_CMD_1) = params->emc_pmacro_ddll_long_cmd_1; + EMC(EMC_PMACRO_DDLL_LONG_CMD_2) = params->emc_pmacro_ddll_long_cmd_2; + EMC(EMC_PMACRO_DDLL_LONG_CMD_3) = params->emc_pmacro_ddll_long_cmd_3; + EMC(EMC_PMACRO_DDLL_LONG_CMD_4) = params->emc_pmacro_ddll_long_cmd_4; + EMC(EMC_PMACRO_DDLL_SHORT_CMD_0) = params->emc_pmacro_ddll_short_cmd_0; + EMC(EMC_PMACRO_DDLL_SHORT_CMD_1) = params->emc_pmacro_ddll_short_cmd_1; + EMC(EMC_PMACRO_DDLL_SHORT_CMD_2) = params->emc_pmacro_ddll_short_cmd_2; + EMC(EMC_PMACRO_COMMON_PAD_TX_CTRL) = (params->emc_pmacro_common_pad_tx_ctrl & 1) | 0xE; + if (params->emc_bct_spare4) + *(vu32 *)params->emc_bct_spare4 = params->emc_bct_spare5; + EMC(EMC_TIMING_CONTROL) = 1; + MC(MC_VIDEO_PROTECT_BOM) = params->mc_video_protect_bom; + MC(MC_VIDEO_PROTECT_BOM_ADR_HI) = params->mc_video_protect_bom_adr_hi; + MC(MC_VIDEO_PROTECT_SIZE_MB) = params->mc_video_protect_size_mb; + MC(MC_VIDEO_PROTECT_VPR_OVERRIDE) = params->mc_video_protect_vpr_override; + MC(MC_VIDEO_PROTECT_VPR_OVERRIDE1) = params->mc_video_protect_vpr_override1; + MC(MC_VIDEO_PROTECT_GPU_OVERRIDE_0) = params->mc_video_protect_gpu_override0; + MC(MC_VIDEO_PROTECT_GPU_OVERRIDE_1) = params->mc_video_protect_gpu_override1; + MC(MC_EMEM_ADR_CFG) = params->mc_emem_adr_cfg; + MC(MC_EMEM_ADR_CFG_DEV0) = params->mc_emem_adr_cfg_dev0; + MC(MC_EMEM_ADR_CFG_DEV1) = params->mc_emem_adr_cfg_dev1; + MC(MC_EMEM_ADR_CFG_CHANNEL_MASK) = params->mc_emem_adr_cfg_channel_mask; + MC(MC_EMEM_ADR_CFG_BANK_MASK_0) = params->mc_emem_adr_cfg_bank_mask0; + MC(MC_EMEM_ADR_CFG_BANK_MASK_1) = params->mc_emem_adr_cfg_bank_mask1; + MC(MC_EMEM_ADR_CFG_BANK_MASK_2) = params->mc_emem_adr_cfg_bank_mask2; + MC(MC_EMEM_CFG) = params->mc_emem_cfg; + MC(MC_SEC_CARVEOUT_BOM) = params->mc_sec_carveout_bom; + MC(MC_SEC_CARVEOUT_ADR_HI) = params->mc_sec_carveout_adr_hi; + MC(MC_SEC_CARVEOUT_SIZE_MB) = params->mc_sec_carveout_size_mb; + MC(MC_MTS_CARVEOUT_BOM) = params->mc_mts_carveout_bom; + MC(MC_MTS_CARVEOUT_ADR_HI) = params->mc_mts_carveout_adr_hi; + MC(MC_MTS_CARVEOUT_SIZE_MB) = params->mc_mts_carveout_size_mb; + MC(MC_EMEM_ARB_CFG) = params->mc_emem_arb_cfg; + MC(MC_EMEM_ARB_OUTSTANDING_REQ) = params->mc_emem_arb_outstanding_req; + MC(MC_EMEM_ARB_REFPB_HP_CTRL) = params->emc_emem_arb_refpb_hp_ctrl; + MC(MC_EMEM_ARB_REFPB_BANK_CTRL) = params->emc_emem_arb_refpb_bank_ctrl; + MC(MC_EMEM_ARB_TIMING_RCD) = params->mc_emem_arb_timing_rcd; + MC(MC_EMEM_ARB_TIMING_RP) = params->mc_emem_arb_timing_rp; + MC(MC_EMEM_ARB_TIMING_RC) = params->mc_emem_arb_timing_rc; + MC(MC_EMEM_ARB_TIMING_RAS) = params->mc_emem_arb_timing_ras; + MC(MC_EMEM_ARB_TIMING_FAW) = params->mc_emem_arb_timing_faw; + MC(MC_EMEM_ARB_TIMING_RRD) = params->mc_emem_arb_timing_rrd; + MC(MC_EMEM_ARB_TIMING_RAP2PRE) = params->mc_emem_arb_timing_rap2pre; + MC(MC_EMEM_ARB_TIMING_WAP2PRE) = params->mc_emem_arb_timing_wap2pre; + MC(MC_EMEM_ARB_TIMING_R2R) = params->mc_emem_arb_timing_r2r; + MC(MC_EMEM_ARB_TIMING_W2W) = params->mc_emem_arb_timing_w2w; + MC(MC_EMEM_ARB_TIMING_CCDMW) = params->mc_emem_arb_timing_ccdmw; + MC(MC_EMEM_ARB_TIMING_R2W) = params->mc_emem_arb_timing_r2w; + MC(MC_EMEM_ARB_TIMING_W2R) = params->mc_emem_arb_timing_w2r; + MC(MC_EMEM_ARB_TIMING_RFCPB) = params->mc_emem_arb_timing_rfcpb; + MC(MC_EMEM_ARB_DA_TURNS) = params->mc_emem_arb_da_turns; + MC(MC_EMEM_ARB_DA_COVERS) = params->mc_emem_arb_da_covers; + MC(MC_EMEM_ARB_MISC0) = params->mc_emem_arb_misc0; + MC(MC_EMEM_ARB_MISC1) = params->mc_emem_arb_misc1; + MC(MC_EMEM_ARB_MISC2) = params->mc_emem_arb_misc2; + MC(MC_EMEM_ARB_RING1_THROTTLE) = params->mc_emem_arb_ring1_throttle; + MC(MC_EMEM_ARB_OVERRIDE) = params->mc_emem_arb_override; + MC(MC_EMEM_ARB_OVERRIDE_1) = params->mc_emem_arb_override1; + MC(MC_EMEM_ARB_RSV) = params->mc_emem_arb_rsv; + MC(MC_DA_CONFIG0) = params->mc_da_cfg0; + MC(MC_TIMING_CONTROL) = 1; + MC(MC_CLKEN_OVERRIDE) = params->mc_clken_override; + MC(MC_STAT_CONTROL) = params->mc_stat_control; + EMC(EMC_ADR_CFG) = params->emc_adr_cfg; + EMC(EMC_CLKEN_OVERRIDE) = params->emc_clken_override; + EMC(EMC_PMACRO_AUTOCAL_CFG_0) = params->emc_pmacro_auto_cal_cfg0; + EMC(EMC_PMACRO_AUTOCAL_CFG_1) = params->emc_pmacro_auto_cal_cfg1; + EMC(EMC_PMACRO_AUTOCAL_CFG_2) = params->emc_pmacro_auto_cal_cfg2; + EMC(EMC_AUTO_CAL_VREF_SEL_0) = params->emc_auto_cal_vref_sel0; + EMC(EMC_AUTO_CAL_VREF_SEL_1) = params->emc_auto_cal_vref_sel1; + EMC(EMC_AUTO_CAL_INTERVAL) = params->emc_auto_cal_interval; + EMC(EMC_AUTO_CAL_CONFIG) = params->emc_auto_cal_config; + usleep(params->emc_auto_cal_wait); + if (params->emc_bct_spare8) + *(vu32 *)params->emc_bct_spare8 = params->emc_bct_spare9; + EMC(EMC_CFG_2) = params->emc_cfg2; + EMC(EMC_CFG_PIPE) = params->emc_cfg_pipe; + EMC(EMC_CFG_PIPE_1) = params->emc_cfg_pipe1; + EMC(EMC_CFG_PIPE_2) = params->emc_cfg_pipe2; + EMC(EMC_CMDQ) = params->emc_cmd_q; + EMC(EMC_MC2EMCQ) = params->emc_mc2emc_q; + EMC(EMC_MRS_WAIT_CNT) = params->emc_mrs_wait_cnt; + EMC(EMC_MRS_WAIT_CNT2) = params->emc_mrs_wait_cnt2; + EMC(EMC_FBIO_CFG5) = params->emc_fbio_cfg5; + EMC(EMC_RC) = params->emc_rc; + EMC(EMC_RFC) = params->emc_rfc; + EMC(EMC_RFCPB) = params->emc_rfc_pb; + EMC(EMC_REFCTRL2) = params->emc_ref_ctrl2; + EMC(EMC_RFC_SLR) = params->emc_rfc_slr; + EMC(EMC_RAS) = params->emc_ras; + EMC(EMC_RP) = params->emc_rp; + EMC(EMC_TPPD) = params->emc_tppd; + EMC(EMC_R2R) = params->emc_r2r; + EMC(EMC_W2W) = params->emc_w2w; + EMC(EMC_R2W) = params->emc_r2w; + EMC(EMC_W2R) = params->emc_w2r; + EMC(EMC_R2P) = params->emc_r2p; + EMC(EMC_W2P) = params->emc_w2p; + EMC(EMC_CCDMW) = params->emc_ccdmw; + EMC(EMC_RD_RCD) = params->emc_rd_rcd; + EMC(EMC_WR_RCD) = params->emc_wr_rcd; + EMC(EMC_RRD) = params->emc_rrd; + EMC(EMC_REXT) = params->emc_rext; + EMC(EMC_WEXT) = params->emc_wext; + EMC(EMC_WDV) = params->emc_wdv; + EMC(EMC_WDV_CHK) = params->emc_wdv_chk; + EMC(EMC_WSV) = params->emc_wsv; + EMC(EMC_WEV) = params->emc_wev; + EMC(EMC_WDV_MASK) = params->emc_wdv_mask; + EMC(EMC_WS_DURATION) = params->emc_ws_duration; + EMC(EMC_WE_DURATION) = params->emc_we_duration; + EMC(EMC_QUSE) = params->emc_quse; + EMC(EMC_QUSE_WIDTH) = params->emc_quse_width; + EMC(EMC_IBDLY) = params->emc_ibdly; + EMC(EMC_OBDLY) = params->emc_obdly; + EMC(EMC_EINPUT) = params->emc_einput; + EMC(EMC_EINPUT_DURATION) = params->emc_einput_duration; + EMC(EMC_PUTERM_EXTRA) = params->emc_puterm_extra; + EMC(EMC_PUTERM_WIDTH) = params->emc_puterm_width; + EMC(EMC_PMACRO_COMMON_PAD_TX_CTRL) = params->emc_pmacro_common_pad_tx_ctrl; + EMC(EMC_DBG) = params->emc_dbg; + EMC(EMC_QRST) = params->emc_qrst; + EMC(EMC_ISSUE_QRST) = 0; + EMC(EMC_QSAFE) = params->emc_qsafe; + EMC(EMC_RDV) = params->emc_rdv; + EMC(EMC_RDV_MASK) = params->emc_rdv_mask; + EMC(EMC_RDV_EARLY) = params->emc_rdv_early; + EMC(EMC_RDV_EARLY_MASK) = params->emc_rdv_early_mask; + EMC(EMC_QPOP) = params->emc_qpop; + EMC(EMC_REFRESH) = params->emc_refresh; + EMC(EMC_BURST_REFRESH_NUM) = params->emc_burst_refresh_num; + EMC(EMC_PRE_REFRESH_REQ_CNT) = params->emc_prerefresh_req_cnt; + EMC(EMC_PDEX2WR) = params->emc_pdex2wr; + EMC(EMC_PDEX2RD) = params->emc_pdex2rd; + EMC(EMC_PCHG2PDEN) = params->emc_pchg2pden; + EMC(EMC_ACT2PDEN) = params->emc_act2pden; + EMC(EMC_AR2PDEN) = params->emc_ar2pden; + EMC(EMC_RW2PDEN) = params->emc_rw2pden; + EMC(EMC_CKE2PDEN) = params->emc_cke2pden; + EMC(EMC_PDEX2CKE) = params->emc_pdex2che; + EMC(EMC_PDEX2MRR) = params->emc_pdex2mrr; + EMC(EMC_TXSR) = params->emc_txsr; + EMC(EMC_TXSRDLL) = params->emc_txsr_dll; + EMC(EMC_TCKE) = params->emc_tcke; + EMC(EMC_TCKESR) = params->emc_tckesr; + EMC(EMC_TPD) = params->emc_tpd; + EMC(EMC_TFAW) = params->emc_tfaw; + EMC(EMC_TRPAB) = params->emc_trpab; + EMC(EMC_TCLKSTABLE) = params->emc_tclkstable; + EMC(EMC_TCLKSTOP) = params->emc_tclkstop; + EMC(EMC_TREFBW) = params->emc_trefbw; + EMC(EMC_ODT_WRITE) = params->emc_odt_write; + EMC(EMC_CFG_DIG_DLL) = params->emc_cfg_dig_dll; + EMC(EMC_CFG_DIG_DLL_PERIOD) = params->emc_cfg_dig_dll_period; + EMC(EMC_FBIO_SPARE) = params->emc_fbio_spare & 0xFFFFFFFD; + EMC(EMC_CFG_RSV) = params->emc_cfg_rsv; + EMC(EMC_PMC_SCRATCH1) = params->emc_pmc_scratch1; + EMC(EMC_PMC_SCRATCH2) = params->emc_pmc_scratch2; + EMC(EMC_PMC_SCRATCH3) = params->emc_pmc_scratch3; + EMC(EMC_ACPD_CONTROL) = params->emc_acpd_control; + EMC(EMC_TXDSRVTTGEN) = params->emc_txdsrvttgen; + EMC(EMC_CFG) = (params->emc_cfg & 0xE) | 0x3C00000; + if (params->boot_rom_patch_control & (1 << 31)) + { + *(vu32 *)(APB_MISC_BASE + params->boot_rom_patch_control * 4) = params->boot_rom_patch_data; + MC(MC_TIMING_CONTROL) = 1; + } + PMC(APBDEV_PMC_IO_DPD3_REQ) = ((4 * params->emc_pmc_scratch1 >> 2) + 0x40000000) & 0xCFFF0000; + usleep(params->pmc_io_dpd3_req_wait); + if (!params->emc_auto_cal_interval) + EMC(EMC_AUTO_CAL_CONFIG) = params->emc_auto_cal_config | 0x200; + EMC(EMC_PMACRO_BRICK_CTRL_RFU2) = params->emc_pmacro_brick_ctrl_rfu2; + if (params->emc_zcal_warm_cold_boot_enables & 1) + { + if (params->memory_type == 2) + EMC(EMC_ZCAL_WAIT_CNT) = 8 * params->emc_zcal_wait_cnt; + if (params->memory_type == 3) + { + EMC(EMC_ZCAL_WAIT_CNT) = params->emc_zcal_wait_cnt; + EMC(EMC_ZCAL_MRW_CMD) = params->emc_zcal_mrw_cmd; + } + } + EMC(EMC_TIMING_CONTROL) = 1; + usleep(params->emc_timing_control_wait); + PMC(APBDEV_PMC_DDR_CNTRL) &= 0xFFF8007F; + usleep(params->pmc_ddr_ctrl_wait); + if (params->memory_type == 2) + { + EMC(EMC_PIN) = (params->emc_pin_gpio_enable << 16) | (params->emc_pin_gpio << 12); + usleep(params->emc_pin_extra_wait + 200); + EMC(EMC_PIN) = ((params->emc_pin_gpio_enable << 16) | (params->emc_pin_gpio << 12)) + 256; + usleep(params->emc_pin_extra_wait + 500); + } + if (params->memory_type == 3) + { + EMC(EMC_PIN) = (params->emc_pin_gpio_enable << 16) | (params->emc_pin_gpio << 12); + usleep(params->emc_pin_extra_wait + 200); + EMC(EMC_PIN) = ((params->emc_pin_gpio_enable << 16) | (params->emc_pin_gpio << 12)) + 256; + usleep(params->emc_pin_extra_wait + 2000); + } + EMC(EMC_PIN) = ((params->emc_pin_gpio_enable << 16) | (params->emc_pin_gpio << 12)) + 0x101; + usleep(params->emc_pin_program_wait); + if (params->memory_type != 3) + EMC(EMC_NOP) = (params->emc_dev_select << 30) + 1; + if (params->memory_type == 1) + usleep(params->emc_pin_extra_wait + 200); + if (params->memory_type == 3) + { + if (params->emc_bct_spare10) + *(vu32 *)params->emc_bct_spare10 = params->emc_bct_spare11; + EMC(EMC_MRW2) = params->emc_mrw2; + EMC(EMC_MRW) = params->emc_mrw1; + EMC(EMC_MRW3) = params->emc_mrw3; + EMC(EMC_MRW4) = params->emc_mrw4; + EMC(EMC_MRW6) = params->emc_mrw6; + EMC(EMC_MRW14) = params->emc_mrw14; + EMC(EMC_MRW8) = params->emc_mrw8; + EMC(EMC_MRW12) = params->emc_mrw12; + EMC(EMC_MRW9) = params->emc_mrw9; + EMC(EMC_MRW13) = params->emc_mrw13; + if (params->emc_zcal_warm_cold_boot_enables & 1) + { + EMC(EMC_ZQ_CAL) = params->emc_zcal_init_dev0; + usleep(params->emc_zcal_init_wait); + EMC(EMC_ZQ_CAL) = params->emc_zcal_init_dev0 ^ 3; + if (!(params->emc_dev_select & 2)) + { + EMC(EMC_ZQ_CAL) = params->emc_zcal_init_dev1; + usleep(params->emc_zcal_init_wait); + EMC(EMC_ZQ_CAL) = params->emc_zcal_init_dev1 ^ 3; + } + } + } + PMC(APBDEV_PMC_DDR_CFG) = params->pmc_ddr_cfg; + if (params->memory_type - 1 <= 2) + { + EMC(EMC_ZCAL_INTERVAL) = params->emc_zcal_interval; + EMC(EMC_ZCAL_WAIT_CNT) = params->emc_zcal_wait_cnt; + EMC(EMC_ZCAL_MRW_CMD) = params->emc_zcal_mrw_cmd; + } + if (params->emc_bct_spare12) + *(vu32 *)params->emc_bct_spare12 = params->emc_bct_spare13; + EMC(EMC_TIMING_CONTROL) = 1; + if (params->emc_extra_refresh_num) + EMC(EMC_REF) = ((1 << params->emc_extra_refresh_num << 8) - 0xFD) | (params->emc_pin_gpio << 30); + EMC(EMC_REFCTRL) = params->emc_dev_select | 0x80000000; + EMC(EMC_DYN_SELF_REF_CONTROL) = params->emc_dyn_self_ref_control; + EMC(EMC_CFG_UPDATE) = params->emc_cfg_update; + EMC(EMC_CFG) = params->emc_cfg; + EMC(EMC_FDPD_CTRL_DQ) = params->emc_fdpd_ctrl_dq; + EMC(EMC_FDPD_CTRL_CMD) = params->emc_fdpd_ctrl_cmd; + EMC(EMC_SEL_DPD_CTRL) = params->emc_sel_dpd_ctrl; + EMC(EMC_FBIO_SPARE) = params->emc_fbio_spare | 2; + EMC(EMC_TIMING_CONTROL) = 1; + EMC(EMC_CFG_PIPE_CLK) = params->emc_cfg_pipe_clk; + EMC(EMC_FDPD_CTRL_CMD_NO_RAMP) = params->emc_fdpd_ctrl_cmd_no_ramp; + SYSREG(AHB_ARBITRATION_XBAR_CTRL) = (SYSREG(AHB_ARBITRATION_XBAR_CTRL) & 0xFFFEFFFF) | ((params->ahb_arbitration_xbar_ctrl_meminit_done & 0xFFFF) << 16); + MC(MC_VIDEO_PROTECT_REG_CTRL) = params->mc_video_protect_write_access; + MC(MC_SEC_CARVEOUT_REG_CTRL) = params->mc_sec_carveout_protect_write_access; + MC(MC_MTS_CARVEOUT_REG_CTRL) = params->mc_mts_carveout_reg_ctrl; + MC(MC_EMEM_CFG_ACCESS_CTRL) = 1; //Disable write access to a bunch of EMC registers. +} + +sdram_params_t *sdram_get_params() +{ + //TODO: sdram_id should be in [0, 7]. + +#ifdef CONFIG_SDRAM_COMPRESS_CFG + u8 *buf = (u8 *)0x40030000; + LZ_Uncompress(_dram_cfg_lz, buf, sizeof(_dram_cfg_lz)); + return (sdram_params_t *)&buf[sizeof(sdram_params_t) * _get_sdram_id()]; +#else + return _dram_cfgs[_get_sdram_id()]; +#endif +} + +/* + * Function: sdram_get_params_patched + * + * This code implements a warmboot exploit. Warmboot, that is actually so hot, it burns Nvidia once again. + * If the boot_rom_patch_control's MSB is set, it uses it as an index to + * APB_MISC_BASE (u32 array) and sets it to the value of boot_rom_patch_data. + * (The MSB falls out when it gets multiplied by sizeof(u32)). + * Because the bootrom does not do any boundary checks, it lets us write anywhere and anything. + * Ipatch hardware let us apply 12 changes to the bootrom and can be changed any time. + * The first patch is not needed any more when the exploit is triggered, so we overwrite that. + * 0x10459E is the address where it returns an error when the signature is not valid. + * We change that to MOV R0, #0, so we pass the check. + * + * Note: The modulus in the header must match and validated. + */ + +sdram_params_t *sdram_get_params_patched() +{ + #define IPATCH_CONFIG(addr, data) (((addr - 0x100000) / 2) << 16 | (data & 0xffff)) + sdram_params_t *sdram_params = sdram_get_params(); + + // Disable Warmboot signature check. + sdram_params->boot_rom_patch_control = (1 << 31) | (((IPATCH_BASE + 4) - APB_MISC_BASE) / 4); + sdram_params->boot_rom_patch_data = IPATCH_CONFIG(0x10459E, 0x2000); +/* + // Disable SBK lock. + sdram_params->emc_bct_spare8 = (IPATCH_BASE + 7 * 4); + sdram_params->emc_bct_spare9 = IPATCH_CONFIG(0x10210E, 0x2000); + + // Disable bootrom read lock. + sdram_params->emc_bct_spare10 = (IPATCH_BASE + 10 * 4); + sdram_params->emc_bct_spare11 = IPATCH_CONFIG(0x100FDC, 0xF000); + sdram_params->emc_bct_spare12 = (IPATCH_BASE + 11 * 4); + sdram_params->emc_bct_spare13 = IPATCH_CONFIG(0x100FDE, 0xE320); +*/ + return sdram_params; +} + +void sdram_init() +{ + //TODO: sdram_id should be in [0,4]. + const sdram_params_t *params = (const sdram_params_t *)sdram_get_params(); + + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_SD_CFG2, 0x05); + max77620_regulator_set_voltage(REGULATOR_SD1, 1100000); + + PMC(APBDEV_PMC_VDDP_SEL) = params->pmc_vddp_sel; + usleep(params->pmc_vddp_sel_wait); + PMC(APBDEV_PMC_DDR_PWR) = PMC(APBDEV_PMC_DDR_PWR); + PMC(APBDEV_PMC_NO_IOPOWER) = params->pmc_no_io_power; + PMC(APBDEV_PMC_REG_SHORT) = params->pmc_reg_short; + PMC(APBDEV_PMC_DDR_CNTRL) = params->pmc_ddr_ctrl; + + if (params->emc_bct_spare0) + *(vu32 *)params->emc_bct_spare0 = params->emc_bct_spare1; + + _sdram_config(params); +} diff --git a/nyx/nyx_gui/mem/sdram.h b/nyx/nyx_gui/mem/sdram.h new file mode 100644 index 0000000..badc703 --- /dev/null +++ b/nyx/nyx_gui/mem/sdram.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _SDRAM_H_ +#define _SDRAM_H_ + +#include "sdram_param_t210.h" + +void sdram_init(); +sdram_params_t *sdram_get_params(); +sdram_params_t *sdram_get_params_patched(); +void sdram_lp0_save_params(const void *params); + +#endif diff --git a/nyx/nyx_gui/mem/sdram_config.inl b/nyx/nyx_gui/mem/sdram_config.inl new file mode 100644 index 0000000..d23f4da --- /dev/null +++ b/nyx/nyx_gui/mem/sdram_config.inl @@ -0,0 +1,1152 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +static const u8 _dram_cfg_0[1896] = { + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0xBC, 0x01, 0x70, 0x0A, 0x00, 0x00, 0x00, 0x04, 0xB4, 0x01, 0x70, + 0x01, 0x32, 0x54, 0x76, 0xC8, 0xE6, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x02, 0x80, 0x18, 0x40, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x1F, 0x00, 0xD8, 0x51, 0x1A, 0xA0, 0x00, 0x00, 0x50, 0x05, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0xA6, 0xA6, 0xAF, 0xB3, 0x3C, 0x9E, 0x00, 0x00, 0x03, 0x03, 0xE0, 0xC1, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0x1F, 0x1F, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, + 0xA1, 0x01, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC1, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x00, 0x0D, 0xA0, 0x60, 0x91, + 0xBF, 0x3B, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x0C, 0x04, 0x05, 0x1B, 0x06, + 0x02, 0x03, 0x07, 0x1C, 0x23, 0x25, 0x25, 0x05, 0x08, 0x1D, 0x09, 0x0A, + 0x24, 0x0B, 0x1E, 0x0D, 0x0C, 0x26, 0x26, 0x03, 0x02, 0x1B, 0x1C, 0x23, + 0x03, 0x04, 0x07, 0x05, 0x06, 0x25, 0x25, 0x02, 0x0A, 0x0B, 0x1D, 0x0D, + 0x08, 0x0C, 0x09, 0x1E, 0x24, 0x26, 0x26, 0x08, 0x24, 0x06, 0x07, 0x9A, + 0x12, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x0D, 0x08, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x71, 0x03, 0x08, 0x00, 0x00, 0x0B, 0x08, + 0x72, 0x72, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0D, 0x0C, + 0x00, 0x00, 0x0D, 0x0C, 0x14, 0x14, 0x16, 0x08, 0x04, 0x00, 0x01, 0x08, + 0x00, 0x00, 0x11, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0xCC, 0x00, + 0x0A, 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0xF3, 0x05, 0x08, 0x11, 0x00, + 0xFF, 0x0F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x03, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x44, 0x00, 0x10, 0x04, 0x04, 0x00, 0x06, 0x13, 0x07, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x2C, 0x00, 0x01, 0x37, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x1F, 0x22, 0x20, 0x80, 0x0F, 0xF4, 0x20, 0x02, 0x28, 0x28, 0x28, 0x28, + 0x28, 0x28, 0x28, 0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xBE, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x12, 0x00, 0x12, 0x00, 0x10, 0x00, 0x10, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x06, 0x00, 0xCC, 0x00, 0x09, 0x00, 0x4F, 0x00, 0x51, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x0A, 0x04, + 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x22, 0x04, 0xFF, 0xFF, 0xAF, 0x4F, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x54, 0x76, 0x10, 0x47, 0x32, 0x65, + 0x10, 0x34, 0x76, 0x25, 0x01, 0x34, 0x67, 0x25, 0x01, 0x75, 0x64, 0x32, + 0x01, 0x72, 0x56, 0x34, 0x10, 0x23, 0x74, 0x56, 0x01, 0x45, 0x32, 0x67, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x92, 0x24, 0x00, 0x49, 0x92, 0x24, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2F, 0x41, 0x13, 0x1F, 0x14, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xAF, 0x4F, 0xFF, 0xFF, 0xFF, 0x7F, 0x0B, 0xD7, 0x06, 0x40, + 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x03, 0x00, 0x00, 0x5C, 0x01, 0x00, + 0x10, 0x10, 0x10, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x37, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x11, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x81, 0x10, 0x09, 0x28, 0x93, 0x32, 0xA5, 0x44, 0x5B, 0x8A, 0x67, 0x76, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xEF, 0xFF, 0xEF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xDC, 0xDC, 0xDC, 0xDC, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, + 0x0A, 0x0A, 0x0A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x07, 0x00, + 0x02, 0x03, 0x07, 0x00, 0x00, 0x24, 0xFF, 0xFF, 0x00, 0x44, 0x57, 0x6E, + 0x00, 0x28, 0x72, 0x39, 0x00, 0x10, 0x9C, 0x4B, 0x00, 0x10, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x08, 0x4C, 0x00, 0x00, 0x80, 0x20, 0x10, 0x0A, 0x00, + 0x28, 0x10, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x02, + 0x01, 0x02, 0x03, 0x00, 0x04, 0x05, 0xC3, 0x71, 0x0F, 0x0F, 0x00, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x43, 0xC3, 0xBA, 0xE4, 0xD3, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x76, 0x0C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x16, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x1E, 0x40, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x24, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x2C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u8 _dram_cfg_1[1896] = { + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0xBC, 0x01, 0x70, 0x0A, 0x00, 0x00, 0x00, 0x04, 0xB4, 0x01, 0x70, + 0x01, 0x32, 0x54, 0x76, 0xC8, 0xE6, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x02, 0x80, 0x18, 0x40, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x1F, 0x00, 0xD8, 0x51, 0x1A, 0xA0, 0x00, 0x00, 0x50, 0x05, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0xA6, 0xA6, 0xAF, 0xB3, 0x3C, 0x9E, 0x00, 0x00, 0x03, 0x03, 0xE0, 0xC1, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0x1F, 0x1F, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, + 0xA1, 0x01, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC1, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x00, 0x0D, 0xA0, 0x60, 0x91, + 0xBF, 0x3B, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x0C, 0x04, 0x05, 0x1B, 0x06, + 0x02, 0x03, 0x07, 0x1C, 0x23, 0x25, 0x25, 0x05, 0x08, 0x1D, 0x09, 0x0A, + 0x24, 0x0B, 0x1E, 0x0D, 0x0C, 0x26, 0x26, 0x03, 0x02, 0x1B, 0x1C, 0x23, + 0x03, 0x04, 0x07, 0x05, 0x06, 0x25, 0x25, 0x02, 0x0A, 0x0B, 0x1D, 0x0D, + 0x08, 0x0C, 0x09, 0x1E, 0x24, 0x26, 0x26, 0x08, 0x24, 0x06, 0x07, 0x9A, + 0x12, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x0D, 0x08, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x71, 0x03, 0x08, 0x00, 0x00, 0x0B, 0x08, + 0x72, 0x72, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0D, 0x0C, + 0x00, 0x00, 0x0D, 0x0C, 0x14, 0x14, 0x16, 0x08, 0x04, 0x00, 0x01, 0x08, + 0x00, 0x00, 0x11, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0xCC, 0x00, + 0x0A, 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0xF3, 0x05, 0x08, 0x11, 0x00, + 0xFF, 0x0F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x03, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x44, 0x00, 0x10, 0x04, 0x04, 0x00, 0x06, 0x13, 0x07, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x2C, 0x00, 0x01, 0x37, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x1F, 0x22, 0x20, 0x80, 0x0F, 0xF4, 0x20, 0x02, 0x28, 0x28, 0x28, 0x28, + 0x28, 0x28, 0x28, 0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xBE, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x12, 0x00, 0x12, 0x00, 0x10, 0x00, 0x10, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x06, 0x00, 0xCC, 0x00, 0x09, 0x00, 0x4F, 0x00, 0x51, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x0A, 0x04, + 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x22, 0x04, 0xFF, 0xFF, 0xAF, 0x4F, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x54, 0x76, 0x10, 0x47, 0x32, 0x65, + 0x10, 0x34, 0x76, 0x25, 0x01, 0x34, 0x67, 0x25, 0x01, 0x75, 0x64, 0x32, + 0x01, 0x72, 0x56, 0x34, 0x10, 0x23, 0x74, 0x56, 0x01, 0x45, 0x32, 0x67, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x92, 0x24, 0x00, 0x49, 0x92, 0x24, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2F, 0x41, 0x13, 0x1F, 0x14, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xAF, 0x4F, 0xFF, 0xFF, 0xFF, 0x7F, 0x0B, 0xD7, 0x06, 0x40, + 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x03, 0x00, 0x00, 0x5C, 0x01, 0x00, + 0x10, 0x10, 0x10, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x37, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x11, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x81, 0x10, 0x09, 0x28, 0x93, 0x32, 0xA5, 0x44, 0x5B, 0x8A, 0x67, 0x76, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xEF, 0xFF, 0xEF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xDC, 0xDC, 0xDC, 0xDC, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, + 0x0A, 0x0A, 0x0A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x07, 0x00, + 0x02, 0x03, 0x07, 0x00, 0x00, 0x24, 0xFF, 0xFF, 0x00, 0x44, 0x57, 0x6E, + 0x00, 0x28, 0x72, 0x39, 0x00, 0x10, 0x9C, 0x4B, 0x00, 0x10, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x08, 0x4C, 0x00, 0x00, 0x80, 0x20, 0x10, 0x0A, 0x00, + 0x28, 0x10, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x02, + 0x01, 0x02, 0x03, 0x00, 0x04, 0x05, 0xC3, 0x71, 0x0F, 0x0F, 0x00, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x43, 0xC3, 0xBA, 0xE4, 0xD3, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x76, 0x0C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x16, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x1E, 0x40, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x24, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x2C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u8 _dram_cfg_2[1896] = { + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0xBC, 0x01, 0x70, 0x0A, 0x00, 0x00, 0x00, 0x04, 0xB4, 0x01, 0x70, + 0x01, 0x32, 0x54, 0x76, 0xC8, 0xE6, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x02, 0x80, 0x18, 0x40, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x1F, 0x00, 0xD8, 0x51, 0x1A, 0xA0, 0x00, 0x00, 0x50, 0x05, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0xA6, 0xA6, 0xAF, 0xB3, 0x3C, 0x9E, 0x00, 0x00, 0x03, 0x03, 0xE0, 0xC1, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0x1F, 0x1F, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, + 0xA1, 0x01, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC1, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x00, 0x0D, 0xA0, 0x60, 0x91, + 0xBF, 0x3B, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x0C, 0x04, 0x05, 0x1B, 0x06, + 0x02, 0x03, 0x07, 0x1C, 0x23, 0x25, 0x25, 0x05, 0x08, 0x1D, 0x09, 0x0A, + 0x24, 0x0B, 0x1E, 0x0D, 0x0C, 0x26, 0x26, 0x03, 0x02, 0x1B, 0x1C, 0x23, + 0x03, 0x04, 0x07, 0x05, 0x06, 0x25, 0x25, 0x02, 0x0A, 0x0B, 0x1D, 0x0D, + 0x08, 0x0C, 0x09, 0x1E, 0x24, 0x26, 0x26, 0x08, 0x24, 0x06, 0x07, 0x9A, + 0x12, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x0D, 0x08, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x71, 0x03, 0x08, 0x00, 0x00, 0x0B, 0x08, + 0x72, 0x72, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0D, 0x0C, + 0x00, 0x00, 0x0D, 0x0C, 0x14, 0x14, 0x16, 0x08, 0x04, 0x00, 0x01, 0x08, + 0x00, 0x00, 0x11, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0xCC, 0x00, + 0x0A, 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0xF3, 0x05, 0x08, 0x11, 0x00, + 0xFF, 0x0F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x03, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x44, 0x00, 0x10, 0x04, 0x04, 0x00, 0x06, 0x13, 0x07, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x2C, 0x00, 0x01, 0x37, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x1F, 0x22, 0x20, 0x80, 0x0F, 0xF4, 0x20, 0x02, 0x28, 0x28, 0x28, 0x28, + 0x28, 0x28, 0x28, 0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xBE, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x12, 0x00, 0x12, 0x00, 0x10, 0x00, 0x10, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x06, 0x00, 0xCC, 0x00, 0x09, 0x00, 0x4F, 0x00, 0x51, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x0A, 0x04, + 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x22, 0x04, 0xFF, 0xFF, 0xAF, 0x4F, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x54, 0x76, 0x10, 0x47, 0x32, 0x65, + 0x10, 0x34, 0x76, 0x25, 0x01, 0x34, 0x67, 0x25, 0x01, 0x75, 0x64, 0x32, + 0x01, 0x72, 0x56, 0x34, 0x10, 0x23, 0x74, 0x56, 0x01, 0x45, 0x32, 0x67, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x92, 0x24, 0x00, 0x49, 0x92, 0x24, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2F, 0x41, 0x13, 0x1F, 0x14, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xAF, 0x4F, 0xFF, 0xFF, 0xFF, 0x7F, 0x0B, 0xD7, 0x06, 0x40, + 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x03, 0x00, 0x00, 0x5C, 0x01, 0x00, + 0x10, 0x10, 0x10, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x37, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x11, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x81, 0x10, 0x09, 0x28, 0x93, 0x32, 0xA5, 0x44, 0x5B, 0x8A, 0x67, 0x76, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xEF, 0xFF, 0xEF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xDC, 0xDC, 0xDC, 0xDC, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, + 0x0A, 0x0A, 0x0A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x07, 0x00, + 0x02, 0x03, 0x07, 0x00, 0x00, 0x24, 0xFF, 0xFF, 0x00, 0x44, 0x57, 0x6E, + 0x00, 0x28, 0x72, 0x39, 0x00, 0x10, 0x9C, 0x4B, 0x00, 0x10, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x08, 0x4C, 0x00, 0x00, 0x80, 0x20, 0x10, 0x0A, 0x00, + 0x28, 0x10, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x02, + 0x01, 0x02, 0x03, 0x00, 0x04, 0x05, 0xC3, 0x71, 0x0F, 0x0F, 0x00, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x43, 0xC3, 0xBA, 0xE4, 0xD3, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x76, 0x0C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x16, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x1E, 0x40, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x24, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x2C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u8 _dram_cfg_3[1896] = { + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0xBC, 0x01, 0x70, 0x0A, 0x00, 0x00, 0x00, 0x04, 0xB4, 0x01, 0x70, + 0x01, 0x32, 0x54, 0x76, 0xC8, 0xE6, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x02, 0x80, 0x18, 0x40, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x1F, 0x00, 0xD8, 0x51, 0x1A, 0xA0, 0x00, 0x00, 0x50, 0x05, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0xA6, 0xA6, 0xAF, 0xB3, 0x3C, 0x9E, 0x00, 0x00, 0x03, 0x03, 0xE0, 0xC1, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0x1F, 0x1F, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, + 0xA1, 0x01, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC1, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x00, 0x0D, 0xA0, 0x60, 0x91, + 0xBF, 0x3B, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x0C, 0x04, 0x05, 0x1B, 0x06, + 0x02, 0x03, 0x07, 0x1C, 0x23, 0x25, 0x25, 0x05, 0x08, 0x1D, 0x09, 0x0A, + 0x24, 0x0B, 0x1E, 0x0D, 0x0C, 0x26, 0x26, 0x03, 0x02, 0x1B, 0x1C, 0x23, + 0x03, 0x04, 0x07, 0x05, 0x06, 0x25, 0x25, 0x02, 0x0A, 0x0B, 0x1D, 0x0D, + 0x08, 0x0C, 0x09, 0x1E, 0x24, 0x26, 0x26, 0x08, 0x24, 0x06, 0x07, 0x9A, + 0x12, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x0D, 0x08, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x71, 0x03, 0x08, 0x00, 0x00, 0x0B, 0x08, + 0x72, 0x72, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0D, 0x0C, + 0x00, 0x00, 0x0D, 0x0C, 0x14, 0x14, 0x16, 0x08, 0x04, 0x00, 0x01, 0x08, + 0x00, 0x00, 0x11, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0xCC, 0x00, + 0x0A, 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0xF3, 0x05, 0x08, 0x11, 0x00, + 0xFF, 0x0F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x03, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x44, 0x00, 0x10, 0x04, 0x04, 0x00, 0x06, 0x13, 0x07, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x2C, 0x00, 0x01, 0x37, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x1F, 0x22, 0x20, 0x80, 0x0F, 0xF4, 0x20, 0x02, 0x28, 0x28, 0x28, 0x28, + 0x28, 0x28, 0x28, 0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xBE, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x12, 0x00, 0x12, 0x00, 0x10, 0x00, 0x10, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x06, 0x00, 0xCC, 0x00, 0x09, 0x00, 0x4F, 0x00, 0x51, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x0A, 0x04, + 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x22, 0x04, 0xFF, 0xFF, 0xAF, 0x4F, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x54, 0x76, 0x10, 0x47, 0x32, 0x65, + 0x10, 0x34, 0x76, 0x25, 0x01, 0x34, 0x67, 0x25, 0x01, 0x75, 0x64, 0x32, + 0x01, 0x72, 0x56, 0x34, 0x10, 0x23, 0x74, 0x56, 0x01, 0x45, 0x32, 0x67, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x92, 0x24, 0x00, 0x49, 0x92, 0x24, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2F, 0x41, 0x13, 0x1F, 0x14, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xAF, 0x4F, 0xFF, 0xFF, 0xFF, 0x7F, 0x0B, 0xD7, 0x06, 0x40, + 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x03, 0x00, 0x00, 0x5C, 0x01, 0x00, + 0x10, 0x10, 0x10, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x37, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x11, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x81, 0x10, 0x09, 0x28, 0x93, 0x32, 0xA5, 0x44, 0x5B, 0x8A, 0x67, 0x76, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xEF, 0xFF, 0xEF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xDC, 0xDC, 0xDC, 0xDC, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, + 0x0A, 0x0A, 0x0A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x07, 0x00, + 0x02, 0x03, 0x07, 0x00, 0x00, 0x24, 0xFF, 0xFF, 0x00, 0x44, 0x57, 0x6E, + 0x00, 0x28, 0x72, 0x39, 0x00, 0x10, 0x9C, 0x4B, 0x00, 0x10, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x08, 0x4C, 0x00, 0x00, 0x80, 0x20, 0x10, 0x0A, 0x00, + 0x28, 0x10, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x02, + 0x01, 0x02, 0x03, 0x00, 0x04, 0x05, 0xC3, 0x71, 0x0F, 0x0F, 0x00, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x43, 0xC3, 0xBA, 0xE4, 0xD3, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x76, 0x0C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x16, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x1E, 0x40, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x24, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x2C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u8 _dram_cfg_4[1896] = { + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0xBC, 0x01, 0x70, 0x0A, 0x00, 0x00, 0x00, 0x04, 0xB4, 0x01, 0x70, + 0x01, 0x32, 0x54, 0x76, 0xC8, 0xE6, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x02, 0x80, 0x18, 0x40, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x1F, 0x00, 0xD8, 0x51, 0x1A, 0xA0, 0x00, 0x00, 0x50, 0x05, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0xA6, 0xA6, 0xAF, 0xB3, 0x3C, 0x9E, 0x00, 0x00, 0x03, 0x03, 0xE0, 0xC1, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0x1F, 0x1F, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, + 0xA1, 0x01, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC1, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x00, 0x0D, 0xA0, 0x60, 0x91, + 0xBF, 0x3B, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x0C, 0x04, 0x05, 0x1B, 0x06, + 0x02, 0x03, 0x07, 0x1C, 0x23, 0x25, 0x25, 0x05, 0x08, 0x1D, 0x09, 0x0A, + 0x24, 0x0B, 0x1E, 0x0D, 0x0C, 0x26, 0x26, 0x03, 0x02, 0x1B, 0x1C, 0x23, + 0x03, 0x04, 0x07, 0x05, 0x06, 0x25, 0x25, 0x02, 0x0A, 0x0B, 0x1D, 0x0D, + 0x08, 0x0C, 0x09, 0x1E, 0x24, 0x26, 0x26, 0x08, 0x24, 0x06, 0x07, 0x9A, + 0x12, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x0D, 0x08, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x71, 0x03, 0x08, 0x00, 0x00, 0x0B, 0x08, + 0x72, 0x72, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0D, 0x0C, + 0x00, 0x00, 0x0D, 0x0C, 0x14, 0x14, 0x16, 0x08, 0x04, 0x00, 0x01, 0x08, + 0x00, 0x00, 0x11, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0xCC, 0x00, + 0x0A, 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0xF3, 0x05, 0x08, 0x11, 0x00, + 0xFF, 0x0F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x03, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x44, 0x00, 0x10, 0x04, 0x04, 0x00, 0x06, 0x13, 0x07, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x2C, 0x00, 0x01, 0x37, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x1F, 0x22, 0x20, 0x80, 0x0F, 0xF4, 0x20, 0x02, 0x28, 0x28, 0x28, 0x28, + 0x28, 0x28, 0x28, 0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xBE, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x12, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, 0x33, 0x00, 0x35, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x12, 0x00, 0x12, 0x00, 0x10, 0x00, 0x10, 0x00, 0x14, 0x00, 0x14, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x06, 0x00, 0xCC, 0x00, 0x09, 0x00, 0x4F, 0x00, 0x51, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x0A, 0x04, + 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x22, 0x04, 0xFF, 0xFF, 0xAF, 0x4F, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x54, 0x76, 0x10, 0x47, 0x32, 0x65, + 0x10, 0x34, 0x76, 0x25, 0x01, 0x34, 0x67, 0x25, 0x01, 0x75, 0x64, 0x32, + 0x01, 0x72, 0x56, 0x34, 0x10, 0x23, 0x74, 0x56, 0x01, 0x45, 0x32, 0x67, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x92, 0x24, 0x00, 0x49, 0x92, 0x24, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2F, 0x41, 0x13, 0x1F, 0x14, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xAF, 0x4F, 0xFF, 0xFF, 0xFF, 0x7F, 0x0B, 0xD7, 0x06, 0x40, + 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x03, 0x00, 0x00, 0x5C, 0x01, 0x00, + 0x10, 0x10, 0x10, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x37, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x11, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x81, 0x10, 0x09, 0x28, 0x93, 0x32, 0xA5, 0x44, 0x5B, 0x8A, 0x67, 0x76, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xEF, 0xFF, 0xEF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xDC, 0xDC, 0xDC, 0xDC, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, + 0x0A, 0x0A, 0x0A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x0C, 0x00, + 0x02, 0x03, 0x0C, 0x00, 0x00, 0x24, 0xFF, 0xFF, 0x00, 0x44, 0x57, 0x6E, + 0x00, 0x28, 0x72, 0x39, 0x00, 0x10, 0x9C, 0x4B, 0x00, 0x18, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x08, 0x4C, 0x00, 0x00, 0x80, 0x20, 0x10, 0x0A, 0x00, + 0x28, 0x10, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x02, + 0x01, 0x02, 0x03, 0x00, 0x04, 0x05, 0xC3, 0x71, 0x0F, 0x0F, 0x00, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x43, 0xC3, 0xBA, 0xE4, 0xD3, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x76, 0x0C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x16, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x1E, 0x40, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x24, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x2C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u8 _dram_cfg_5[1896] = { + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0xBC, 0x01, 0x70, 0x0A, 0x00, 0x00, 0x00, 0x04, 0xB4, 0x01, 0x70, + 0x01, 0x32, 0x54, 0x76, 0xC8, 0xE6, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x02, 0x80, 0x18, 0x40, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x1F, 0x00, 0xD8, 0x51, 0x1A, 0xA0, 0x00, 0x00, 0x50, 0x05, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0xA6, 0xA6, 0xAF, 0xB3, 0x3C, 0x9E, 0x00, 0x00, 0x03, 0x03, 0xE0, 0xC1, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0x1F, 0x1F, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, + 0xA1, 0x01, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC1, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x00, 0x0D, 0xA0, 0x60, 0x91, + 0xBF, 0x3B, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x0C, 0x04, 0x05, 0x1B, 0x06, + 0x02, 0x03, 0x07, 0x1C, 0x23, 0x25, 0x25, 0x05, 0x08, 0x1D, 0x09, 0x0A, + 0x24, 0x0B, 0x1E, 0x0D, 0x0C, 0x26, 0x26, 0x03, 0x02, 0x1B, 0x1C, 0x23, + 0x03, 0x04, 0x07, 0x05, 0x06, 0x25, 0x25, 0x02, 0x0A, 0x0B, 0x1D, 0x0D, + 0x08, 0x0C, 0x09, 0x1E, 0x24, 0x26, 0x26, 0x08, 0x24, 0x06, 0x07, 0x9A, + 0x12, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x0D, 0x08, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x71, 0x03, 0x08, 0x00, 0x00, 0x0B, 0x08, + 0x72, 0x72, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0D, 0x0C, + 0x00, 0x00, 0x0D, 0x0C, 0x14, 0x14, 0x16, 0x08, 0x04, 0x00, 0x01, 0x08, + 0x00, 0x00, 0x11, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0xCC, 0x00, + 0x0A, 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0xF3, 0x05, 0x08, 0x11, 0x00, + 0xFF, 0x0F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x03, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x44, 0x00, 0x10, 0x04, 0x04, 0x00, 0x06, 0x13, 0x07, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x2C, 0x00, 0x01, 0x37, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x1F, 0x22, 0x20, 0x80, 0x0F, 0xF4, 0x20, 0x02, 0x28, 0x28, 0x28, 0x28, + 0x28, 0x28, 0x28, 0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xBE, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x12, 0x00, 0x12, 0x00, 0x16, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x12, 0x00, 0x12, 0x00, 0x16, 0x00, + 0x32, 0x00, 0x2F, 0x00, 0x32, 0x00, 0x31, 0x00, 0x34, 0x00, 0x36, 0x00, + 0x2F, 0x00, 0x33, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x32, 0x00, 0x2F, 0x00, 0x32, 0x00, 0x31, 0x00, 0x34, 0x00, 0x36, 0x00, + 0x2F, 0x00, 0x33, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x15, 0x00, 0x15, 0x00, + 0x12, 0x00, 0x12, 0x00, 0x12, 0x00, 0x12, 0x00, 0x16, 0x00, 0x16, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x06, 0x00, 0xCC, 0x00, 0x09, 0x00, 0x4F, 0x00, 0x51, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x0A, 0x04, + 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x22, 0x04, 0xFF, 0xFF, 0xAF, 0x4F, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x54, 0x76, 0x10, 0x47, 0x32, 0x65, + 0x10, 0x34, 0x76, 0x25, 0x01, 0x34, 0x67, 0x25, 0x01, 0x75, 0x64, 0x32, + 0x01, 0x72, 0x56, 0x34, 0x10, 0x23, 0x74, 0x56, 0x01, 0x45, 0x32, 0x67, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x92, 0x24, 0x00, 0x49, 0x92, 0x24, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2F, 0x41, 0x13, 0x1F, 0x14, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xAF, 0x4F, 0xFF, 0xFF, 0xFF, 0x7F, 0x0B, 0xD7, 0x06, 0x40, + 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x03, 0x00, 0x00, 0x5C, 0x01, 0x00, + 0x10, 0x10, 0x10, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x37, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x11, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x81, 0x10, 0x09, 0x28, 0x93, 0x32, 0xA5, 0x44, 0x5B, 0x8A, 0x67, 0x76, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xEF, 0xFF, 0xEF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xDC, 0xDC, 0xDC, 0xDC, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, + 0x0A, 0x0A, 0x0A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x07, 0x00, + 0x02, 0x03, 0x07, 0x00, 0x00, 0x24, 0xFF, 0xFF, 0x00, 0x44, 0x57, 0x6E, + 0x00, 0x28, 0x72, 0x39, 0x00, 0x10, 0x9C, 0x4B, 0x00, 0x10, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x08, 0x4C, 0x00, 0x00, 0x80, 0x20, 0x10, 0x0A, 0x00, + 0x28, 0x10, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x02, + 0x01, 0x02, 0x03, 0x00, 0x04, 0x05, 0xC3, 0x71, 0x0F, 0x0F, 0x00, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x43, 0xC3, 0xBA, 0xE4, 0xD3, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x76, 0x0C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x16, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x1E, 0x40, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x24, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x2C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u8 _dram_cfg_6[1896] = { + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0xBC, 0x01, 0x70, 0x0A, 0x00, 0x00, 0x00, 0x04, 0xB4, 0x01, 0x70, + 0x01, 0x32, 0x54, 0x76, 0xC8, 0xE6, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x02, 0x80, 0x18, 0x40, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x1F, 0x00, 0xD8, 0x51, 0x1A, 0xA0, 0x00, 0x00, 0x50, 0x05, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x77, 0x00, + 0xA6, 0xA6, 0xAF, 0xB3, 0x3C, 0x9E, 0x00, 0x00, 0x03, 0x03, 0xE0, 0xC1, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0x1F, 0x1F, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, + 0xA1, 0x01, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x3A, 0x00, 0x00, 0x00, + 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC1, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x3B, 0x00, 0x00, 0x00, 0x3B, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x00, 0x0D, 0xA0, 0x60, 0x91, + 0xBF, 0x3B, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x0C, 0x04, 0x05, 0x1B, 0x06, + 0x02, 0x03, 0x07, 0x1C, 0x23, 0x25, 0x25, 0x05, 0x08, 0x1D, 0x09, 0x0A, + 0x24, 0x0B, 0x1E, 0x0D, 0x0C, 0x26, 0x26, 0x03, 0x02, 0x1B, 0x1C, 0x23, + 0x03, 0x04, 0x07, 0x05, 0x06, 0x25, 0x25, 0x02, 0x0A, 0x0B, 0x1D, 0x0D, + 0x08, 0x0C, 0x09, 0x1E, 0x24, 0x26, 0x26, 0x08, 0x24, 0x06, 0x07, 0x9A, + 0x12, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x0D, 0x08, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x71, 0x03, 0x08, 0x00, 0x00, 0x0B, 0x08, + 0x72, 0x72, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0D, 0x0C, + 0x00, 0x00, 0x0D, 0x0C, 0x14, 0x14, 0x16, 0x08, 0x04, 0x00, 0x01, 0x08, + 0x00, 0x00, 0x11, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0xCC, 0x00, + 0x0A, 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0xF3, 0x05, 0x08, 0x11, 0x00, + 0xFF, 0x0F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x03, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x44, 0x00, 0x10, 0x04, 0x04, 0x00, 0x06, 0x13, 0x07, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x2C, 0x00, 0x01, 0x37, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x1F, 0x22, 0x20, 0x80, 0x0F, 0xF4, 0x20, 0x02, 0x28, 0x28, 0x28, 0x28, + 0x28, 0x28, 0x28, 0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0xBE, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x12, 0x00, 0x12, 0x00, 0x16, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x12, 0x00, 0x12, 0x00, 0x16, 0x00, + 0x32, 0x00, 0x2F, 0x00, 0x32, 0x00, 0x31, 0x00, 0x34, 0x00, 0x36, 0x00, + 0x2F, 0x00, 0x33, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x32, 0x00, 0x2F, 0x00, 0x32, 0x00, 0x31, 0x00, 0x34, 0x00, 0x36, 0x00, + 0x2F, 0x00, 0x33, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, + 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x15, 0x00, 0x15, 0x00, + 0x12, 0x00, 0x12, 0x00, 0x12, 0x00, 0x12, 0x00, 0x16, 0x00, 0x16, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x06, 0x00, 0xCC, 0x00, 0x09, 0x00, 0x4F, 0x00, 0x51, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x0A, 0x04, + 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x22, 0x04, 0xFF, 0xFF, 0xAF, 0x4F, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x54, 0x76, 0x10, 0x47, 0x32, 0x65, + 0x10, 0x34, 0x76, 0x25, 0x01, 0x34, 0x67, 0x25, 0x01, 0x75, 0x64, 0x32, + 0x01, 0x72, 0x56, 0x34, 0x10, 0x23, 0x74, 0x56, 0x01, 0x45, 0x32, 0x67, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x92, 0x24, 0x00, 0x49, 0x92, 0x24, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2F, 0x41, 0x13, 0x1F, 0x14, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xAF, 0x4F, 0xFF, 0xFF, 0xFF, 0x7F, 0x0B, 0xD7, 0x06, 0x40, + 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x03, 0x00, 0x00, 0x5C, 0x01, 0x00, + 0x10, 0x10, 0x10, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x37, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x11, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x81, 0x10, 0x09, 0x28, 0x93, 0x32, 0xA5, 0x44, 0x5B, 0x8A, 0x67, 0x76, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xEF, 0xFF, 0xEF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xDC, 0xDC, 0xDC, 0xDC, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, + 0x0A, 0x0A, 0x0A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x07, 0x00, + 0x02, 0x03, 0x07, 0x00, 0x00, 0x24, 0xFF, 0xFF, 0x00, 0x44, 0x57, 0x6E, + 0x00, 0x28, 0x72, 0x39, 0x00, 0x10, 0x9C, 0x4B, 0x00, 0x10, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x08, 0x4C, 0x00, 0x00, 0x80, 0x20, 0x10, 0x0A, 0x00, + 0x28, 0x10, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x02, + 0x01, 0x02, 0x03, 0x00, 0x04, 0x05, 0xA3, 0x72, 0x0F, 0x0F, 0x00, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x43, 0xC3, 0xBA, 0xE4, 0xD3, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x76, 0x0C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x16, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x1E, 0x40, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x24, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x2C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u32 *_dram_cfgs[7] = { + (const u32 *)_dram_cfg_0, + (const u32 *)_dram_cfg_1, + (const u32 *)_dram_cfg_2, + (const u32 *)_dram_cfg_3, + (const u32 *)_dram_cfg_4, + (const u32 *)_dram_cfg_5, + (const u32 *)_dram_cfg_6 +}; diff --git a/nyx/nyx_gui/mem/sdram_config_lz.inl b/nyx/nyx_gui/mem/sdram_config_lz.inl new file mode 100644 index 0000000..832b5b4 --- /dev/null +++ b/nyx/nyx_gui/mem/sdram_config_lz.inl @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +static const u8 _dram_cfg_lz[1262] = { + 0x17, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, + 0x00, 0x2C, 0x17, 0x04, 0x09, 0x00, 0x17, 0x04, 0x04, 0x17, 0x08, 0x08, + 0x17, 0x10, 0x10, 0x00, 0x00, 0x68, 0xBC, 0x01, 0x70, 0x0A, 0x00, 0x00, + 0x00, 0x04, 0xB4, 0x01, 0x70, 0x01, 0x32, 0x54, 0x76, 0xC8, 0xE6, 0x00, + 0x70, 0x17, 0x10, 0x24, 0x34, 0x00, 0x00, 0x00, 0x02, 0x80, 0x18, 0x40, + 0x00, 0x00, 0x00, 0x17, 0x04, 0x04, 0x17, 0x09, 0x18, 0xFF, 0xFF, 0x1F, + 0x00, 0xD8, 0x51, 0x1A, 0xA0, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x77, + 0x00, 0x17, 0x04, 0x04, 0x17, 0x08, 0x08, 0x17, 0x08, 0x08, 0xA6, 0xA6, + 0xAF, 0xB3, 0x3C, 0x9E, 0x00, 0x00, 0x03, 0x03, 0xE0, 0xC1, 0x04, 0x04, + 0x04, 0x04, 0x17, 0x04, 0x04, 0x17, 0x04, 0x3C, 0x1F, 0x1F, 0x1F, 0x1F, + 0x17, 0x04, 0x04, 0x17, 0x06, 0x06, 0x00, 0x00, 0x04, 0x08, 0x17, 0x06, + 0x46, 0xA1, 0x01, 0x00, 0x00, 0x32, 0x17, 0x0B, 0x64, 0x01, 0x17, 0x04, + 0x7C, 0x17, 0x07, 0x0C, 0x03, 0x17, 0x04, 0x04, 0x00, 0x00, 0x00, 0x1E, + 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x13, + 0x17, 0x0B, 0x2C, 0x09, 0x00, 0x00, 0x00, 0x17, 0x05, 0x5D, 0x17, 0x07, + 0x10, 0x0B, 0x17, 0x07, 0x28, 0x08, 0x17, 0x07, 0x0C, 0x17, 0x04, 0x1C, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x17, 0x04, 0x04, 0x17, 0x07, 0x08, 0x17, + 0x04, 0x50, 0x17, 0x04, 0x2C, 0x17, 0x04, 0x1C, 0x17, 0x04, 0x10, 0x17, + 0x08, 0x6C, 0x17, 0x04, 0x10, 0x17, 0x04, 0x38, 0x17, 0x04, 0x40, 0x05, + 0x17, 0x07, 0x1C, 0x17, 0x08, 0x58, 0x17, 0x04, 0x24, 0x17, 0x04, 0x18, + 0x17, 0x08, 0x64, 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, + 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x17, 0x09, 0x0C, 0x17, 0x05, 0x82, + 0x58, 0x17, 0x07, 0x61, 0xC1, 0x17, 0x07, 0x50, 0x17, 0x04, 0x04, 0x17, + 0x08, 0x81, 0x48, 0x17, 0x04, 0x04, 0x17, 0x04, 0x28, 0x17, 0x04, 0x60, + 0x17, 0x08, 0x54, 0x27, 0x17, 0x04, 0x04, 0x17, 0x07, 0x14, 0x17, 0x04, + 0x04, 0x04, 0x17, 0x07, 0x81, 0x58, 0x17, 0x0C, 0x0C, 0x1C, 0x03, 0x00, + 0x00, 0x0D, 0xA0, 0x60, 0x91, 0xBF, 0x3B, 0x17, 0x04, 0x5A, 0xF3, 0x0C, + 0x04, 0x05, 0x1B, 0x06, 0x02, 0x03, 0x07, 0x1C, 0x23, 0x25, 0x25, 0x05, + 0x08, 0x1D, 0x09, 0x0A, 0x24, 0x0B, 0x1E, 0x0D, 0x0C, 0x26, 0x26, 0x03, + 0x02, 0x1B, 0x1C, 0x23, 0x03, 0x04, 0x07, 0x05, 0x06, 0x25, 0x25, 0x02, + 0x0A, 0x0B, 0x1D, 0x0D, 0x08, 0x0C, 0x09, 0x1E, 0x24, 0x26, 0x26, 0x08, + 0x24, 0x06, 0x07, 0x9A, 0x12, 0x17, 0x05, 0x83, 0x41, 0x00, 0xFF, 0x17, + 0x10, 0x83, 0x6C, 0x04, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, + 0x00, 0x0D, 0x08, 0x00, 0x00, 0x00, 0xC0, 0x71, 0x71, 0x03, 0x08, 0x00, + 0x00, 0x0B, 0x08, 0x72, 0x72, 0x0E, 0x0C, 0x17, 0x04, 0x20, 0x08, 0x08, + 0x0D, 0x0C, 0x00, 0x00, 0x0D, 0x0C, 0x14, 0x14, 0x16, 0x08, 0x17, 0x06, + 0x2C, 0x11, 0x08, 0x17, 0x10, 0x84, 0x67, 0x15, 0x00, 0xCC, 0x00, 0x0A, + 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0xF3, 0x05, 0x08, 0x11, 0x00, 0xFF, + 0x0F, 0xFF, 0x0F, 0x17, 0x08, 0x83, 0x4C, 0x01, 0x03, 0x00, 0x70, 0x00, + 0x0C, 0x00, 0x01, 0x17, 0x04, 0x0C, 0x08, 0x44, 0x00, 0x10, 0x04, 0x04, + 0x00, 0x06, 0x13, 0x07, 0x00, 0x80, 0x17, 0x04, 0x10, 0xA0, 0x00, 0x2C, + 0x00, 0x01, 0x37, 0x00, 0x00, 0x00, 0x80, 0x17, 0x06, 0x48, 0x08, 0x00, + 0x04, 0x00, 0x1F, 0x22, 0x20, 0x80, 0x0F, 0xF4, 0x20, 0x02, 0x28, 0x28, + 0x28, 0x28, 0x17, 0x04, 0x04, 0x11, 0x11, 0x11, 0x11, 0x17, 0x04, 0x04, + 0xBE, 0x00, 0x00, 0x17, 0x05, 0x58, 0x17, 0x08, 0x5C, 0x17, 0x22, 0x85, + 0x6A, 0x17, 0x1A, 0x1A, 0x14, 0x00, 0x12, 0x00, 0x10, 0x17, 0x05, 0x83, + 0x0A, 0x17, 0x16, 0x18, 0x30, 0x00, 0x2E, 0x00, 0x33, 0x00, 0x30, 0x00, + 0x33, 0x00, 0x35, 0x00, 0x30, 0x00, 0x32, 0x17, 0x05, 0x83, 0x0C, 0x17, + 0x04, 0x20, 0x17, 0x18, 0x18, 0x28, 0x00, 0x28, 0x17, 0x04, 0x04, 0x17, + 0x08, 0x08, 0x17, 0x10, 0x10, 0x00, 0x14, 0x17, 0x05, 0x5A, 0x17, 0x04, + 0x5C, 0x17, 0x04, 0x5E, 0x17, 0x04, 0x0E, 0x17, 0x0E, 0x78, 0x17, 0x09, + 0x82, 0x50, 0x40, 0x06, 0x00, 0xCC, 0x00, 0x09, 0x00, 0x4F, 0x00, 0x51, + 0x17, 0x08, 0x18, 0x80, 0x01, 0x00, 0x00, 0x40, 0x17, 0x04, 0x20, 0x03, + 0x00, 0x00, 0x00, 0xAB, 0x00, 0x0A, 0x04, 0x11, 0x17, 0x08, 0x82, 0x58, + 0x17, 0x0C, 0x38, 0x17, 0x1B, 0x81, 0x6C, 0x17, 0x08, 0x85, 0x60, 0x17, + 0x08, 0x86, 0x50, 0x17, 0x08, 0x86, 0x60, 0x17, 0x06, 0x83, 0x21, 0x22, + 0x04, 0xFF, 0xFF, 0xAF, 0x4F, 0x17, 0x0C, 0x86, 0x74, 0x17, 0x08, 0x2C, + 0x8B, 0xFF, 0x07, 0x17, 0x06, 0x81, 0x04, 0x32, 0x54, 0x76, 0x10, 0x47, + 0x32, 0x65, 0x10, 0x34, 0x76, 0x25, 0x01, 0x34, 0x67, 0x25, 0x01, 0x75, + 0x64, 0x32, 0x01, 0x72, 0x56, 0x34, 0x10, 0x23, 0x74, 0x56, 0x01, 0x45, + 0x32, 0x67, 0x17, 0x04, 0x24, 0x49, 0x92, 0x24, 0x17, 0x04, 0x04, 0x17, + 0x11, 0x7C, 0x1B, 0x17, 0x04, 0x04, 0x17, 0x13, 0x81, 0x14, 0x2F, 0x41, + 0x13, 0x1F, 0x14, 0x00, 0x01, 0x00, 0x17, 0x04, 0x7C, 0xFF, 0xFF, 0xFF, + 0x7F, 0x0B, 0xD7, 0x06, 0x40, 0x00, 0x00, 0x02, 0x00, 0x08, 0x08, 0x03, + 0x00, 0x00, 0x5C, 0x01, 0x00, 0x10, 0x10, 0x10, 0x17, 0x06, 0x86, 0x59, + 0x17, 0x0F, 0x89, 0x14, 0x37, 0x17, 0x07, 0x82, 0x72, 0x10, 0x17, 0x06, + 0x83, 0x0D, 0x00, 0x11, 0x01, 0x17, 0x05, 0x85, 0x39, 0x17, 0x04, 0x0E, + 0x0A, 0x17, 0x07, 0x89, 0x29, 0x17, 0x04, 0x1B, 0x17, 0x08, 0x86, 0x77, + 0x17, 0x09, 0x12, 0x20, 0x00, 0x00, 0x00, 0x81, 0x10, 0x09, 0x28, 0x93, + 0x32, 0xA5, 0x44, 0x5B, 0x8A, 0x67, 0x76, 0x17, 0x18, 0x82, 0x2C, 0xFF, + 0xEF, 0xFF, 0xEF, 0xC0, 0xC0, 0xC0, 0xC0, 0x17, 0x04, 0x04, 0xDC, 0xDC, + 0xDC, 0xDC, 0x0A, 0x0A, 0x0A, 0x0A, 0x17, 0x04, 0x04, 0x17, 0x04, 0x04, + 0x17, 0x05, 0x82, 0x24, 0x03, 0x07, 0x17, 0x04, 0x04, 0x00, 0x00, 0x24, + 0xFF, 0xFF, 0x00, 0x44, 0x57, 0x6E, 0x00, 0x28, 0x72, 0x39, 0x00, 0x10, + 0x9C, 0x4B, 0x17, 0x04, 0x64, 0x01, 0x00, 0x00, 0x08, 0x4C, 0x00, 0x00, + 0x80, 0x20, 0x10, 0x0A, 0x00, 0x28, 0x10, 0x17, 0x06, 0x85, 0x60, 0x17, + 0x10, 0x82, 0x74, 0x17, 0x08, 0x08, 0x17, 0x08, 0x88, 0x00, 0x17, 0x04, + 0x10, 0x04, 0x17, 0x0B, 0x87, 0x6C, 0x01, 0x00, 0x02, 0x02, 0x01, 0x02, + 0x03, 0x00, 0x04, 0x05, 0xC3, 0x71, 0x0F, 0x0F, 0x17, 0x08, 0x8B, 0x18, + 0x1F, 0x17, 0x09, 0x81, 0x73, 0x00, 0xFF, 0x00, 0xFF, 0x17, 0x05, 0x86, + 0x48, 0x17, 0x04, 0x0C, 0x17, 0x07, 0x86, 0x34, 0x00, 0x00, 0xF0, 0x17, + 0x09, 0x87, 0x54, 0x43, 0xC3, 0xBA, 0xE4, 0xD3, 0x1E, 0x17, 0x0C, 0x81, + 0x52, 0x17, 0x0A, 0x1C, 0x17, 0x10, 0x81, 0x6C, 0x17, 0x0A, 0x82, 0x21, + 0x17, 0x07, 0x82, 0x4D, 0x17, 0x0A, 0x8A, 0x1B, 0x17, 0x11, 0x2C, 0x76, + 0x0C, 0x17, 0x0A, 0x8A, 0x67, 0x17, 0x0F, 0x84, 0x28, 0x17, 0x06, 0x34, + 0x17, 0x17, 0x3A, 0x7E, 0x16, 0x40, 0x17, 0x0C, 0x8B, 0x1F, 0x17, 0x2A, + 0x38, 0x1E, 0x17, 0x0A, 0x38, 0x17, 0x13, 0x81, 0x28, 0x00, 0xC0, 0x17, + 0x17, 0x55, 0x46, 0x24, 0x17, 0x0A, 0x81, 0x28, 0x17, 0x14, 0x38, 0x17, + 0x18, 0x81, 0x60, 0x46, 0x2C, 0x17, 0x06, 0x38, 0xEC, 0x17, 0x0D, 0x16, + 0x17, 0x0E, 0x82, 0x3C, 0x17, 0x82, 0x0C, 0x8E, 0x68, 0x17, 0x04, 0x24, + 0x17, 0x5C, 0x8E, 0x68, 0x17, 0x07, 0x82, 0x5F, 0x80, 0x17, 0x87, 0x01, + 0x8E, 0x68, 0x02, 0x17, 0x81, 0x4A, 0x8E, 0x68, 0x17, 0x0C, 0x87, 0x78, + 0x17, 0x85, 0x28, 0x8E, 0x68, 0x17, 0x8E, 0x68, 0x9D, 0x50, 0x17, 0x81, + 0x24, 0x8E, 0x68, 0x17, 0x04, 0x2C, 0x17, 0x28, 0x8E, 0x68, 0x17, 0x04, + 0x30, 0x17, 0x85, 0x3C, 0x8E, 0x68, 0x12, 0x17, 0x07, 0x85, 0x70, 0x17, + 0x88, 0x74, 0x8E, 0x68, 0x17, 0x87, 0x3E, 0x9D, 0x50, 0x0C, 0x17, 0x04, + 0x04, 0x17, 0x12, 0x8E, 0x68, 0x18, 0x17, 0x87, 0x12, 0xBB, 0x20, 0x17, + 0x83, 0x04, 0x9D, 0x50, 0x15, 0x17, 0x05, 0x8D, 0x76, 0x17, 0x0F, 0x8B, + 0x49, 0x17, 0x0B, 0x18, 0x32, 0x00, 0x2F, 0x00, 0x32, 0x00, 0x31, 0x00, + 0x34, 0x00, 0x36, 0x00, 0x2F, 0x00, 0x33, 0x17, 0x09, 0x84, 0x0C, 0x17, + 0x18, 0x18, 0x17, 0x20, 0x8E, 0x68, 0x15, 0x17, 0x07, 0x5A, 0x17, 0x06, + 0x5E, 0x16, 0x00, 0x15, 0x17, 0x82, 0x40, 0x9D, 0x50, 0x17, 0x86, 0x5F, + 0xBB, 0x20, 0x3A, 0x00, 0x00, 0x00, 0x1D, 0x17, 0x81, 0x4F, 0xAC, 0x38, + 0x3B, 0x17, 0x04, 0x04, 0x17, 0x86, 0x30, 0x8E, 0x68, 0x17, 0x81, 0x53, + 0xAC, 0x38, 0x07, 0x17, 0x0D, 0x8E, 0x68, 0xA3, 0x72, 0x17, 0x83, 0x10, + 0x8E, 0x68 +}; diff --git a/nyx/nyx_gui/mem/sdram_lp0.c b/nyx/nyx_gui/mem/sdram_lp0.c new file mode 100644 index 0000000..869e85a --- /dev/null +++ b/nyx/nyx_gui/mem/sdram_lp0.c @@ -0,0 +1,1126 @@ +/* + * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved. + * Copyright 2014 Google Inc. + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include "../soc/t210.h" +#include "../soc/pmc_lp0_t210.h" +#include "sdram_lp0_param_t210.h" + +/* + * This function reads SDRAM parameters from the common BCT format and + * writes them into PMC scratch registers (where the BootROM expects them + * on LP0 resume). + */ +void sdram_lp0_save_params(const void *params) +{ + struct sdram_params *sdram = (struct sdram_params *)params; + struct tegra_pmc_regs *pmc = (struct tegra_pmc_regs *)PMC_BASE; + +#define pack(src, src_bits, dst, dst_bits) { \ + u32 mask = 0xffffffff >> (31 - ((1 ? src_bits) - (0 ? src_bits))); \ + dst &= ~(mask << (0 ? dst_bits)); \ + dst |= ((src >> (0 ? src_bits)) & mask) << (0 ? dst_bits); \ +} + +#define s(param, src_bits, pmcreg, dst_bits) \ + pack(sdram->param, src_bits, pmc->pmcreg, dst_bits) + +#define c(value, pmcreg, dst_bits) \ + pack(value, (1 ? dst_bits) - (0 ? dst_bits) : 0, pmc->pmcreg, dst_bits) + +/* 32 bits version of s macro */ +#define s32(param, pmcreg) pmc->pmcreg = sdram->param + +/* 32 bits version c macro */ +#define c32(value, pmcreg) pmc->pmcreg = value + + //TODO: pkg1.1 (1.X - 3.X) reads them from MC. + // Patch carveout parameters. + /*sdram->McGeneralizedCarveout1Bom = 0; + sdram->McGeneralizedCarveout1BomHi = 0; + sdram->McGeneralizedCarveout1Size128kb = 0; + sdram->McGeneralizedCarveout1Access0 = 0; + sdram->McGeneralizedCarveout1Access1 = 0; + sdram->McGeneralizedCarveout1Access2 = 0; + sdram->McGeneralizedCarveout1Access3 = 0; + sdram->McGeneralizedCarveout1Access4 = 0; + sdram->McGeneralizedCarveout1ForceInternalAccess0 = 0; + sdram->McGeneralizedCarveout1ForceInternalAccess1 = 0; + sdram->McGeneralizedCarveout1ForceInternalAccess2 = 0; + sdram->McGeneralizedCarveout1ForceInternalAccess3 = 0; + sdram->McGeneralizedCarveout1ForceInternalAccess4 = 0; + sdram->McGeneralizedCarveout1Cfg0 = 0; + sdram->McGeneralizedCarveout2Bom = 0x80020000; + sdram->McGeneralizedCarveout2BomHi = 0; + sdram->McGeneralizedCarveout2Size128kb = 2; + sdram->McGeneralizedCarveout2Access0 = 0; + sdram->McGeneralizedCarveout2Access1 = 0; + sdram->McGeneralizedCarveout2Access2 = 0x3000000; + sdram->McGeneralizedCarveout2Access3 = 0; + sdram->McGeneralizedCarveout2Access4 = 0x300; + sdram->McGeneralizedCarveout2ForceInternalAccess0 = 0; + sdram->McGeneralizedCarveout2ForceInternalAccess1 = 0; + sdram->McGeneralizedCarveout2ForceInternalAccess2 = 0; + sdram->McGeneralizedCarveout2ForceInternalAccess3 = 0; + sdram->McGeneralizedCarveout2ForceInternalAccess4 = 0; + sdram->McGeneralizedCarveout2Cfg0 = 0x440167E; + sdram->McGeneralizedCarveout3Bom = 0; + sdram->McGeneralizedCarveout3BomHi = 0; + sdram->McGeneralizedCarveout3Size128kb = 0; + sdram->McGeneralizedCarveout3Access0 = 0; + sdram->McGeneralizedCarveout3Access1 = 0; + sdram->McGeneralizedCarveout3Access2 = 0x3000000; + sdram->McGeneralizedCarveout3Access3 = 0; + sdram->McGeneralizedCarveout3Access4 = 0x300; + sdram->McGeneralizedCarveout3ForceInternalAccess0 = 0; + sdram->McGeneralizedCarveout3ForceInternalAccess1 = 0; + sdram->McGeneralizedCarveout3ForceInternalAccess2 = 0; + sdram->McGeneralizedCarveout3ForceInternalAccess3 = 0; + sdram->McGeneralizedCarveout3ForceInternalAccess4 = 0; + sdram->McGeneralizedCarveout3Cfg0 = 0x4401E7E; + sdram->McGeneralizedCarveout4Bom = 0; + sdram->McGeneralizedCarveout4BomHi = 0; + sdram->McGeneralizedCarveout4Size128kb = 0; + sdram->McGeneralizedCarveout4Access0 = 0; + sdram->McGeneralizedCarveout4Access1 = 0; + sdram->McGeneralizedCarveout4Access2 = 0; + sdram->McGeneralizedCarveout4Access3 = 0; + sdram->McGeneralizedCarveout4Access4 = 0; + sdram->McGeneralizedCarveout4ForceInternalAccess0 = 0; + sdram->McGeneralizedCarveout4ForceInternalAccess1 = 0; + sdram->McGeneralizedCarveout4ForceInternalAccess2 = 0; + sdram->McGeneralizedCarveout4ForceInternalAccess3 = 0; + sdram->McGeneralizedCarveout4ForceInternalAccess4 = 0; + sdram->McGeneralizedCarveout4Cfg0 = 0x8F; + sdram->McGeneralizedCarveout5Bom = 0; + sdram->McGeneralizedCarveout5BomHi = 0; + sdram->McGeneralizedCarveout5Size128kb = 0; + sdram->McGeneralizedCarveout5Access0 = 0; + sdram->McGeneralizedCarveout5Access1 = 0; + sdram->McGeneralizedCarveout5Access2 = 0; + sdram->McGeneralizedCarveout5Access3 = 0; + sdram->McGeneralizedCarveout5Access4 = 0; + sdram->McGeneralizedCarveout5ForceInternalAccess0 = 0; + sdram->McGeneralizedCarveout5ForceInternalAccess1 = 0; + sdram->McGeneralizedCarveout5ForceInternalAccess2 = 0; + sdram->McGeneralizedCarveout5ForceInternalAccess3 = 0; + sdram->McGeneralizedCarveout5ForceInternalAccess4 = 0; + sdram->McGeneralizedCarveout5Cfg0 = 0x8F;*/ + + //TODO: this is 4.X+ behaviour which seems to work fine for < 4.X. + // Patch carveout parameters. + sdram->McGeneralizedCarveout1Cfg0 = 0; + sdram->McGeneralizedCarveout2Cfg0 = 0; + sdram->McGeneralizedCarveout3Cfg0 = 0; + sdram->McGeneralizedCarveout4Cfg0 = 0; + sdram->McGeneralizedCarveout5Cfg0 = 0; + + // Patch SDRAM parameters. + u32 t0 = sdram->EmcSwizzleRank0Byte0 << 5 >> 29 > sdram->EmcSwizzleRank0Byte0 << 1 >> 29; + u32 t1 = (t0 & 0xFFFFFFEF) | ((sdram->EmcSwizzleRank1Byte0 << 5 >> 29 > sdram->EmcSwizzleRank1Byte0 << 1 >> 29) << 4); + u32 t2 = (t1 & 0xFFFFFFFD) | ((sdram->EmcSwizzleRank0Byte1 << 5 >> 29 > sdram->EmcSwizzleRank0Byte1 << 1 >> 29) << 1); + u32 t3 = (t2 & 0xFFFFFFDF) | ((sdram->EmcSwizzleRank1Byte1 << 5 >> 29 > sdram->EmcSwizzleRank1Byte1 << 1 >> 29) << 5); + u32 t4 = (t3 & 0xFFFFFFFB) | ((sdram->EmcSwizzleRank0Byte2 << 5 >> 29 > sdram->EmcSwizzleRank0Byte2 << 1 >> 29) << 2); + u32 t5 = (t4 & 0xFFFFFFBF) | ((sdram->EmcSwizzleRank1Byte2 << 5 >> 29 > sdram->EmcSwizzleRank1Byte2 << 1 >> 29) << 6); + u32 t6 = (t5 & 0xFFFFFFF7) | ((sdram->EmcSwizzleRank0Byte3 << 5 >> 29 > sdram->EmcSwizzleRank0Byte3 << 1 >> 29) << 3); + u32 t7 = (t6 & 0xFFFFFF7F) | ((sdram->EmcSwizzleRank1Byte3 << 5 >> 29 > sdram->EmcSwizzleRank1Byte3 << 1 >> 29) << 7); + sdram->SwizzleRankByteEncode = t7; + sdram->EmcBctSpare2 = 0x40000DD8; + sdram->EmcBctSpare3 = t7; + + s(EmcClockSource, 7:0, scratch6, 15:8); + s(EmcClockSourceDll, 7:0, scratch6, 23:16); + s(EmcClockSource, 31:29, scratch6, 26:24); + s(EmcClockSourceDll, 31:29, scratch6, 29:27); + s(EmcClockSourceDll, 11:10, scratch6, 31:30); + s(ClkRstControllerPllmMisc2Override, 9:8, scratch7, 1:0); + s(ClkRstControllerPllmMisc2Override, 2:1, scratch7, 3:2); + s(EmcZqCalLpDdr4WarmBoot, 31:30, scratch7, 5:4); + s(EmcClockSource, 15:15, scratch7, 6:6); + s(EmcClockSource, 26:26, scratch7, 7:7); + s(EmcClockSource, 20:20, scratch7, 8:8); + s(EmcClockSource, 19:19, scratch7, 9:9); + s(ClkRstControllerPllmMisc2Override, 13:13, scratch7, 10:10); + s(ClkRstControllerPllmMisc2Override, 12:12, scratch7, 11:11); + s(ClkRstControllerPllmMisc2Override, 11:11, scratch7, 12:12); + s(ClkRstControllerPllmMisc2Override, 10:10, scratch7, 13:13); + s(ClkRstControllerPllmMisc2Override, 5:5, scratch7, 14:14); + s(ClkRstControllerPllmMisc2Override, 4:4, scratch7, 15:15); + s(ClkRstControllerPllmMisc2Override, 3:3, scratch7, 16:16); + s(ClkRstControllerPllmMisc2Override, 0:0, scratch7, 17:17); + s(EmcZqCalLpDdr4WarmBoot, 1:0, scratch7, 19:18); + s(EmcZqCalLpDdr4WarmBoot, 4:4, scratch7, 20:20); + s(EmcOdtWrite, 5:0, scratch7, 26:21); + s(EmcOdtWrite, 11:8, scratch7, 30:27); + s(EmcOdtWrite, 31:31, scratch7, 31:31); + s(EmcFdpdCtrlCmdNoRamp, 0:0, scratch13, 30:30); + s(EmcCfgPipeClk, 0:0, scratch13, 31:31); + s(McEmemArbMisc2, 0:0, scratch14, 30:30); + s(McDaCfg0, 0:0, scratch14, 31:31); + s(EmcQRst, 6:0, scratch15, 26:20); + s(EmcQRst, 20:16, scratch15, 31:27); + s(EmcPmacroCmdTxDrv, 5:0, scratch16, 25:20); + s(EmcPmacroCmdTxDrv, 13:8, scratch16, 31:26); + s(EmcPmacroAutocalCfg0, 2:0, scratch17, 22:20); + s(EmcPmacroAutocalCfg0, 10:8, scratch17, 25:23); + s(EmcPmacroAutocalCfg0, 18:16, scratch17, 28:26); + s(EmcPmacroAutocalCfg0, 26:24, scratch17, 31:29); + s(EmcPmacroAutocalCfg1, 2:0, scratch18, 22:20); + s(EmcPmacroAutocalCfg1, 10:8, scratch18, 25:23); + s(EmcPmacroAutocalCfg1, 18:16, scratch18, 28:26); + s(EmcPmacroAutocalCfg1, 26:24, scratch18, 31:29); + s(EmcPmacroAutocalCfg2, 2:0, scratch19, 22:20); + s(EmcPmacroAutocalCfg2, 10:8, scratch19, 25:23); + s(EmcPmacroAutocalCfg2, 18:16, scratch19, 28:26); + s(EmcPmacroAutocalCfg2, 26:24, scratch19, 31:29); + s32(EmcCfgRsv,scratch22); + s32(EmcAutoCalConfig, scratch23); + s32(EmcAutoCalVrefSel0, scratch24); + s32(EmcPmacroBrickCtrlRfu1, scratch25); + s32(EmcPmacroBrickCtrlRfu2, scratch26); + s32(EmcPmcScratch1, scratch27); + s32(EmcPmcScratch2, scratch28); + s32(EmcPmcScratch3, scratch29); + s32(McEmemArbDaTurns, scratch30); + s(EmcFbioSpare, 31:24, scratch58, 7:0); + s(EmcFbioSpare, 23:16, scratch58, 15:8); + s(EmcFbioSpare, 15:8, scratch58, 23:16); + s(EmcFbioSpare, 7:2, scratch58, 29:24); + s(EmcFbioSpare, 0:0, scratch58, 30:30); + s(EmcDllCfg0, 29:0, scratch59, 29:0); + s(EmcPmacroDdllBypass, 11:0, scratch60, 11:0); + s(EmcPmacroDdllBypass, 27:13, scratch60, 26:12); + s(EmcPmacroDdllBypass, 31:29, scratch60, 29:27); + s(McEmemArbMisc0, 14:0, scratch61, 14:0); + s(McEmemArbMisc0, 30:16, scratch61, 29:15); + s(EmcFdpdCtrlCmd, 16:0, scratch62, 16:0); + s(EmcFdpdCtrlCmd, 31:20, scratch62, 28:17); + s(EmcAutoCalConfig2, 27:0, scratch63, 27:0); + s(EmcBurstRefreshNum, 3:0, scratch63, 31:28); + s(EmcPmacroZctrl, 27:0, scratch64, 27:0); + s(EmcTppd, 3:0, scratch64, 31:28); + s(EmcCfgDigDll, 10:0, scratch65, 10:0); + s(EmcCfgDigDll, 25:12, scratch65, 24:11); + s(EmcCfgDigDll, 27:27, scratch65, 25:25); + s(EmcCfgDigDll, 31:30, scratch65, 27:26); + s(EmcR2r, 3:0, scratch65, 31:28); + s(EmcFdpdCtrlDq, 16:0, scratch66, 16:0); + s(EmcFdpdCtrlDq, 28:20, scratch66, 25:17); + s(EmcFdpdCtrlDq, 31:30, scratch66, 27:26); + s(EmcW2w, 3:0, scratch66, 31:28); + s(EmcPmacroTxPwrd4, 13:0, scratch67, 13:0); + s(EmcPmacroTxPwrd4, 29:16, scratch67, 27:14); + s(EmcPmacroCommonPadTxCtrl, 3:0, scratch67, 31:28); + s(EmcPmacroTxPwrd5, 13:0, scratch68, 13:0); + s(EmcPmacroTxPwrd5, 29:16, scratch68, 27:14); + s(EmcPmacroDdllPwrd0, 4:0, scratch69, 4:0); + s(EmcPmacroDdllPwrd0, 12:6, scratch69, 11:5); + s(EmcPmacroDdllPwrd0, 20:14, scratch69, 18:12); + s(EmcPmacroDdllPwrd0, 28:22, scratch69, 25:19); + s(EmcPmacroDdllPwrd0, 31:30, scratch69, 27:26); + s(EmcCfg, 4:4, scratch69, 31:31); + s(EmcPmacroDdllPwrd1, 4:0, scratch70, 4:0); + s(EmcPmacroDdllPwrd1, 12:6, scratch70, 11:5); + s(EmcPmacroDdllPwrd1, 20:14, scratch70, 18:12); + s(EmcPmacroDdllPwrd1, 28:22, scratch70, 25:19); + s(EmcPmacroDdllPwrd1, 31:30, scratch70, 27:26); + s(EmcCfg, 5:5, scratch70, 31:31); + s(EmcPmacroDdllPwrd2, 4:0, scratch71, 4:0); + s(EmcPmacroDdllPwrd2, 12:6, scratch71, 11:5); + s(EmcPmacroDdllPwrd2, 20:14, scratch71, 18:12); + s(EmcPmacroDdllPwrd2, 28:22, scratch71, 25:19); + s(EmcPmacroDdllPwrd2, 31:30, scratch71, 27:26); + s(EmcFbioCfg5, 23:20, scratch71, 31:28); + s(EmcPmacroIbVrefDq_0, 6:0, scratch72, 6:0); + s(EmcPmacroIbVrefDq_0, 14:8, scratch72, 13:7); + s(EmcPmacroIbVrefDq_0, 22:16, scratch72, 20:14); + s(EmcPmacroIbVrefDq_0, 30:24, scratch72, 27:21); + s(EmcFbioCfg5, 15:13, scratch72, 30:28); + s(EmcCfg, 6:6, scratch72, 31:31); + s(EmcPmacroIbVrefDq_1, 6:0, scratch73, 6:0); + s(EmcPmacroIbVrefDq_1, 14:8, scratch73, 13:7); + s(EmcPmacroIbVrefDq_1, 22:16, scratch73, 20:14); + s(EmcPmacroIbVrefDq_1, 30:24, scratch73, 27:21); + s(EmcCfg2, 5:3, scratch73, 30:28); + s(EmcCfg, 7:7, scratch73, 31:31); + s(EmcPmacroIbVrefDqs_0, 6:0, scratch74, 6:0); + s(EmcPmacroIbVrefDqs_0, 14:8, scratch74, 13:7); + s(EmcPmacroIbVrefDqs_0, 22:16, scratch74, 20:14); + s(EmcPmacroIbVrefDqs_0, 30:24, scratch74, 27:21); + s(EmcCfg, 17:16, scratch74, 29:28); + s(EmcFbioCfg5, 1:0, scratch74, 31:30); + s(EmcPmacroIbVrefDqs_1, 6:0, scratch75, 6:0); + s(EmcPmacroIbVrefDqs_1, 14:8, scratch75, 13:7); + s(EmcPmacroIbVrefDqs_1, 22:16, scratch75, 20:14); + s(EmcPmacroIbVrefDqs_1, 30:24, scratch75, 27:21); + s(EmcFbioCfg5, 3:2, scratch75, 29:28); + s(EmcCfg2, 27:26, scratch75, 31:30); + s(EmcPmacroDdllShortCmd_0, 6:0, scratch76, 6:0); + s(EmcPmacroDdllShortCmd_0, 14:8, scratch76, 13:7); + s(EmcPmacroDdllShortCmd_0, 22:16, scratch76, 20:14); + s(EmcPmacroDdllShortCmd_0, 30:24, scratch76, 27:21); + s(EmcPmacroCmdPadTxCtrl, 3:2, scratch76, 29:28); + s(EmcPmacroCmdPadTxCtrl, 7:6, scratch76, 31:30); + s(EmcPmacroDdllShortCmd_1, 6:0, scratch77, 6:0); + s(EmcPmacroDdllShortCmd_1, 14:8, scratch77, 13:7); + s(EmcPmacroDdllShortCmd_1, 22:16, scratch77, 20:14); + s(EmcPmacroDdllShortCmd_1, 30:24, scratch77, 27:21); + s(EmcPmacroCmdPadTxCtrl, 11:10, scratch77, 29:28); + s(EmcPmacroCmdPadTxCtrl, 15:14, scratch77, 31:30); + s(EmcAutoCalChannel, 5:0, scratch78, 5:0); + s(EmcAutoCalChannel, 11:8, scratch78, 9:6); + s(EmcAutoCalChannel, 27:16, scratch78, 21:10); + s(EmcAutoCalChannel, 31:29, scratch78, 24:22); + s(EmcConfigSampleDelay, 6:0, scratch78, 31:25); + s(EmcPmacroRxTerm, 5:0, scratch79, 5:0); + s(EmcPmacroRxTerm, 13:8, scratch79, 11:6); + s(EmcPmacroRxTerm, 21:16, scratch79, 17:12); + s(EmcPmacroRxTerm, 29:24, scratch79, 23:18); + s(EmcRc, 7:0, scratch79, 31:24); + s(EmcPmacroDqTxDrv, 5:0, scratch80, 5:0); + s(EmcPmacroDqTxDrv, 13:8, scratch80, 11:6); + s(EmcPmacroDqTxDrv, 21:16, scratch80, 17:12); + s(EmcPmacroDqTxDrv, 29:24, scratch80, 23:18); + s(EmcSelDpdCtrl, 5:2, scratch80, 27:24); + s(EmcSelDpdCtrl, 8:8, scratch80, 28:28); + s(EmcSelDpdCtrl, 18:16, scratch80, 31:29); + s(EmcPmacroCaTxDrv, 5:0, scratch81, 5:0); + s(EmcPmacroCaTxDrv, 13:8, scratch81, 11:6); + s(EmcPmacroCaTxDrv, 21:16, scratch81, 17:12); + s(EmcPmacroCaTxDrv, 29:24, scratch81, 23:18); + s(EmcObdly, 5:0, scratch81, 29:24); + s(EmcObdly, 29:28, scratch81, 31:30); + s(EmcZcalInterval, 23:10, scratch82, 13:0); + s(EmcZcalInterval, 9:0, scratch82, 23:14); + s(EmcPmacroCmdRxTermMode, 1:0, scratch82, 25:24); + s(EmcPmacroCmdRxTermMode, 5:4, scratch82, 27:26); + s(EmcPmacroCmdRxTermMode, 9:8, scratch82, 29:28); + s(EmcPmacroCmdRxTermMode, 13:12, scratch82, 31:30); + s(EmcDataBrlshft0, 23:0, scratch83, 23:0); + s(EmcPmacroDataRxTermMode, 1:0, scratch83, 25:24); + s(EmcPmacroDataRxTermMode, 5:4, scratch83, 27:26); + s(EmcPmacroDataRxTermMode, 9:8, scratch83, 29:28); + s(EmcPmacroDataRxTermMode, 13:12, scratch83, 31:30); + s(EmcDataBrlshft1, 23:0, scratch84, 23:0); + s(McEmemArbTimingRc, 7:0, scratch84, 31:24); + s(EmcDqsBrlshft0, 23:0, scratch85, 23:0); + s(McEmemArbRsv, 7:0, scratch85, 31:24); + s(EmcDqsBrlshft1, 23:0, scratch86, 23:0); + s(EmcCfgPipe2, 11:0, scratch87, 11:0); + s(EmcCfgPipe2, 27:16, scratch87, 23:12); + s(EmcCfgPipe1, 11:0, scratch88, 11:0); + s(EmcCfgPipe1, 27:16, scratch88, 23:12); + s(EmcPmacroCmdCtrl0, 5:0, scratch89, 5:0); + s(EmcPmacroCmdCtrl0, 13:8, scratch89, 11:6); + s(EmcPmacroCmdCtrl0, 21:16, scratch89, 17:12); + s(EmcPmacroCmdCtrl0, 29:24, scratch89, 23:18); + s(EmcPmacroCmdCtrl1, 5:0, scratch90, 5:0); + s(EmcPmacroCmdCtrl1, 13:8, scratch90, 11:6); + s(EmcPmacroCmdCtrl1, 21:16, scratch90, 17:12); + s(EmcPmacroCmdCtrl1, 29:24, scratch90, 23:18); + s(EmcRas, 6:0, scratch90, 30:24); + s(EmcCfg, 8:8, scratch90, 31:31); + s(EmcPmacroVttgenCtrl2, 23:0, scratch91, 23:0); + s(EmcW2p, 6:0, scratch91, 30:24); + s(EmcCfg, 9:9, scratch91, 31:31); + s(EmcPmacroCmdPadRxCtrl, 2:0, scratch92, 2:0); + s(EmcPmacroCmdPadRxCtrl, 5:4, scratch92, 4:3); + s(EmcPmacroCmdPadRxCtrl, 10:8, scratch92, 7:5); + s(EmcPmacroCmdPadRxCtrl, 22:12, scratch92, 18:8); + s(EmcPmacroCmdPadRxCtrl, 28:24, scratch92, 23:19); + s(EmcQSafe, 6:0, scratch92, 30:24); + s(EmcCfg, 18:18, scratch92, 31:31); + s(EmcPmacroDataPadRxCtrl, 2:0, scratch93, 2:0); + s(EmcPmacroDataPadRxCtrl, 5:4, scratch93, 4:3); + s(EmcPmacroDataPadRxCtrl, 10:8, scratch93, 7:5); + s(EmcPmacroDataPadRxCtrl, 22:12, scratch93, 18:8); + s(EmcPmacroDataPadRxCtrl, 28:24, scratch93, 23:19); + s(EmcRdv, 6:0, scratch93, 30:24); + s(EmcCfg, 21:21, scratch93, 31:31); + s(McEmemArbDaCovers, 23:0, scratch94, 23:0); + s(EmcRw2Pden, 6:0, scratch94, 30:24); + s(EmcCfg, 22:22, scratch94, 31:31); + s(EmcPmacroCmdCtrl2, 5:0, scratch95, 5:0); + s(EmcPmacroCmdCtrl2, 13:9, scratch95, 10:6); + s(EmcPmacroCmdCtrl2, 21:16, scratch95, 16:11); + s(EmcPmacroCmdCtrl2, 29:24, scratch95, 22:17); + s(EmcRfcPb, 8:0, scratch95, 31:23); + s(EmcPmacroQuseDdllRank0_0, 10:0, scratch96, 10:0); + s(EmcPmacroQuseDdllRank0_0, 26:16, scratch96, 21:11); + s(EmcCfgUpdate, 2:0, scratch96, 24:22); + s(EmcCfgUpdate, 10:8, scratch96, 27:25); + s(EmcCfgUpdate, 31:28, scratch96, 31:28); + s(EmcPmacroQuseDdllRank0_1, 10:0, scratch97, 10:0); + s(EmcPmacroQuseDdllRank0_1, 26:16, scratch97, 21:11); + s(EmcRfc, 9:0, scratch97, 31:22); + s(EmcPmacroQuseDdllRank0_2, 10:0, scratch98, 10:0); + s(EmcPmacroQuseDdllRank0_2, 26:16, scratch98, 21:11); + s(EmcTxsr, 9:0, scratch98, 31:22); + s(EmcPmacroQuseDdllRank0_3, 10:0, scratch99, 10:0); + s(EmcPmacroQuseDdllRank0_3, 26:16, scratch99, 21:11); + s(EmcMc2EmcQ, 2:0, scratch99, 24:22); + s(EmcMc2EmcQ, 10:8, scratch99, 27:25); + s(EmcMc2EmcQ, 27:24, scratch99, 31:28); + s(EmcPmacroQuseDdllRank0_4, 10:0, scratch100, 10:0); + s(EmcPmacroQuseDdllRank0_4, 26:16, scratch100, 21:11); + s(McEmemArbRing1Throttle, 4:0, scratch100, 26:22); + s(McEmemArbRing1Throttle, 20:16, scratch100, 31:27); + s(EmcPmacroQuseDdllRank0_5, 10:0, scratch101, 10:0); + s(EmcPmacroQuseDdllRank0_5, 26:16, scratch101, 21:11); + s(EmcPmacroQuseDdllRank1_0, 10:0, scratch102, 10:0); + s(EmcPmacroQuseDdllRank1_0, 26:16, scratch102, 21:11); + s(EmcAr2Pden, 8:0, scratch102, 30:22); + s(EmcCfg, 23:23, scratch102, 31:31); + s(EmcPmacroQuseDdllRank1_1, 10:0, scratch103, 10:0); + s(EmcPmacroQuseDdllRank1_1, 26:16, scratch103, 21:11); + s(EmcRfcSlr, 8:0, scratch103, 30:22); + s(EmcCfg, 24:24, scratch103, 31:31); + s(EmcPmacroQuseDdllRank1_2, 10:0, scratch104, 10:0); + s(EmcPmacroQuseDdllRank1_2, 26:16, scratch104, 21:11); + s(EmcIbdly, 6:0, scratch104, 28:22); + s(EmcIbdly, 29:28, scratch104, 30:29); + s(EmcCfg, 25:25, scratch104, 31:31); + s(EmcPmacroQuseDdllRank1_3, 10:0, scratch105, 10:0); + s(EmcPmacroQuseDdllRank1_3, 26:16, scratch105, 21:11); + s(McEmemArbTimingRFCPB, 8:0, scratch105, 30:22); + s(EmcCfg, 26:26, scratch105, 31:31); + s(EmcPmacroQuseDdllRank1_4, 10:0, scratch106, 10:0); + s(EmcPmacroQuseDdllRank1_4, 26:16, scratch106, 21:11); + s(EmcTfaw, 6:0, scratch106, 28:22); + s(EmcPmacroDataPadTxCtrl, 3:2, scratch106, 30:29); + s(EmcCfg, 28:28, scratch106, 31:31); + s(EmcPmacroQuseDdllRank1_5, 10:0, scratch107, 10:0); + s(EmcPmacroQuseDdllRank1_5, 26:16, scratch107, 21:11); + s(EmcTClkStable, 6:0, scratch107, 28:22); + s(EmcPmacroDataPadTxCtrl, 7:6, scratch107, 30:29); + s(EmcCfg, 29:29, scratch107, 31:31); + s(EmcPmacroObDdllLongDqRank0_0, 10:0, scratch108, 10:0); + s(EmcPmacroObDdllLongDqRank0_0, 26:16, scratch108, 21:11); + s(EmcPdex2Mrr, 6:0, scratch108, 28:22); + s(EmcPmacroDataPadTxCtrl, 11:10, scratch108, 30:29); + s(EmcCfg, 30:30, scratch108, 31:31); + s(EmcPmacroObDdllLongDqRank0_1, 10:0, scratch109, 10:0); + s(EmcPmacroObDdllLongDqRank0_1, 26:16, scratch109, 21:11); + s(EmcRdvMask, 6:0, scratch109, 28:22); + s(EmcPmacroDataPadTxCtrl, 15:14, scratch109, 30:29); + s(EmcCfg, 31:31, scratch109, 31:31); + s(EmcPmacroObDdllLongDqRank0_2, 10:0, scratch110, 10:0); + s(EmcPmacroObDdllLongDqRank0_2, 26:16, scratch110, 21:11); + s(EmcRdvEarlyMask, 6:0, scratch110, 28:22); + s(EmcFbioCfg5, 4:4, scratch110, 29:29); + s(EmcFbioCfg5, 8:8, scratch110, 30:30); + s(EmcFbioCfg5, 10:10, scratch110, 31:31); + s(EmcPmacroObDdllLongDqRank0_3, 10:0, scratch111, 10:0); + s(EmcPmacroObDdllLongDqRank0_3, 26:16, scratch111, 21:11); + s(EmcRdvEarly, 6:0, scratch111, 28:22); + s(EmcFbioCfg5, 12:12, scratch111, 29:29); + s(EmcFbioCfg5, 25:24, scratch111, 31:30); + s(EmcPmacroObDdllLongDqRank0_4, 10:0, scratch112, 10:0); + s(EmcPmacroObDdllLongDqRank0_4, 26:16, scratch112, 21:11); + s(EmcPmacroDdllShortCmd_2, 6:0, scratch112, 28:22); + s(EmcFbioCfg5, 28:26, scratch112, 31:29); + s(EmcPmacroObDdllLongDqRank0_5, 10:0, scratch113, 10:0); + s(EmcPmacroObDdllLongDqRank0_5, 26:16, scratch113, 21:11); + s(McEmemArbTimingRp, 6:0, scratch113, 28:22); + s(EmcFbioCfg5, 31:30, scratch113, 30:29); + s(EmcCfg2, 0:0, scratch113, 31:31); + s(EmcPmacroObDdllLongDqRank1_0, 10:0, scratch114, 10:0); + s(EmcPmacroObDdllLongDqRank1_0, 26:16, scratch114, 21:11); + s(McEmemArbTimingRas, 6:0, scratch114, 28:22); + s(EmcCfg2, 2:1, scratch114, 30:29); + s(EmcCfg2, 7:7, scratch114, 31:31); + s(EmcPmacroObDdllLongDqRank1_1, 10:0, scratch115, 10:0); + s(EmcPmacroObDdllLongDqRank1_1, 26:16, scratch115, 21:11); + s(McEmemArbTimingFaw, 6:0, scratch115, 28:22); + s(EmcCfg2, 11:10, scratch115, 30:29); + s(EmcCfg2, 14:14, scratch115, 31:31); + s(EmcPmacroObDdllLongDqRank1_2, 10:0, scratch123, 10:0); + s(EmcPmacroObDdllLongDqRank1_2, 26:16, scratch123, 21:11); + s(McEmemArbTimingRap2Pre, 6:0, scratch123, 28:22); + s(EmcCfg2, 16:15, scratch123, 30:29); + s(EmcCfg2, 20:20, scratch123, 31:31); + s(EmcPmacroObDdllLongDqRank1_3, 10:0, scratch124, 10:0); + s(EmcPmacroObDdllLongDqRank1_3, 26:16, scratch124, 21:11); + s(McEmemArbTimingWap2Pre, 6:0, scratch124, 28:22); + s(EmcCfg2, 24:22, scratch124, 31:29); + s(EmcPmacroObDdllLongDqRank1_4, 10:0, scratch125, 10:0); + s(EmcPmacroObDdllLongDqRank1_4, 26:16, scratch125, 21:11); + s(McEmemArbTimingR2W, 6:0, scratch125, 28:22); + s(EmcCfg2, 25:25, scratch125, 29:29); + s(EmcCfg2, 29:28, scratch125, 31:30); + s(EmcPmacroObDdllLongDqRank1_5, 10:0, scratch126, 10:0); + s(EmcPmacroObDdllLongDqRank1_5, 26:16, scratch126, 21:11); + s(McEmemArbTimingW2R, 6:0, scratch126, 28:22); + s(EmcCfg2, 31:30, scratch126, 30:29); + s(EmcCfgPipe, 0:0, scratch126, 31:31); + s(EmcPmacroObDdllLongDqsRank0_0, 10:0, scratch127, 10:0); + s(EmcPmacroObDdllLongDqsRank0_0, 26:16, scratch127, 21:11); + s(EmcRp, 5:0, scratch127, 27:22); + s(EmcCfgPipe, 4:1, scratch127, 31:28); + s(EmcPmacroObDdllLongDqsRank0_1, 10:0, scratch128, 10:0); + s(EmcPmacroObDdllLongDqsRank0_1, 26:16, scratch128, 21:11); + s(EmcR2w, 5:0, scratch128, 27:22); + s(EmcCfgPipe, 8:5, scratch128, 31:28); + s(EmcPmacroObDdllLongDqsRank0_2, 10:0, scratch129, 10:0); + s(EmcPmacroObDdllLongDqsRank0_2, 26:16, scratch129, 21:11); + s(EmcW2r, 5:0, scratch129, 27:22); + s(EmcCfgPipe, 11:9, scratch129, 30:28); + s(EmcCfgPipe, 16:16, scratch129, 31:31); + s(EmcPmacroObDdllLongDqsRank0_3, 10:0, scratch130, 10:0); + s(EmcPmacroObDdllLongDqsRank0_3, 26:16, scratch130, 21:11); + s(EmcR2p, 5:0, scratch130, 27:22); + s(EmcCfgPipe, 20:17, scratch130, 31:28); + s(EmcPmacroObDdllLongDqsRank0_4, 10:0, scratch131, 10:0); + s(EmcPmacroObDdllLongDqsRank0_4, 26:16, scratch131, 21:11); + s(EmcCcdmw, 5:0, scratch131, 27:22); + s(EmcCfgPipe, 24:21, scratch131, 31:28); + s(EmcPmacroObDdllLongDqsRank0_5, 10:0, scratch132, 10:0); + s(EmcPmacroObDdllLongDqsRank0_5, 26:16, scratch132, 21:11); + s(EmcRdRcd, 5:0, scratch132, 27:22); + s(EmcCfgPipe, 27:25, scratch132, 30:28); + s(EmcPmacroTxPwrd0, 0:0, scratch132, 31:31); + s(EmcPmacroObDdllLongDqsRank1_0, 10:0, scratch133, 10:0); + s(EmcPmacroObDdllLongDqsRank1_0, 26:16, scratch133, 21:11); + s(EmcWrRcd, 5:0, scratch133, 27:22); + s(EmcPmacroTxPwrd0, 4:1, scratch133, 31:28); + s(EmcPmacroObDdllLongDqsRank1_1, 10:0, scratch134, 10:0); + s(EmcPmacroObDdllLongDqsRank1_1, 26:16, scratch134, 21:11); + s(EmcWdv, 5:0, scratch134, 27:22); + s(EmcPmacroTxPwrd0, 8:5, scratch134, 31:28); + s(EmcPmacroObDdllLongDqsRank1_2, 10:0, scratch135, 10:0); + s(EmcPmacroObDdllLongDqsRank1_2, 26:16, scratch135, 21:11); + s(EmcQUse, 5:0, scratch135, 27:22); + s(EmcPmacroTxPwrd0, 12:9, scratch135, 31:28); + s(EmcPmacroObDdllLongDqsRank1_3, 10:0, scratch136, 10:0); + s(EmcPmacroObDdllLongDqsRank1_3, 26:16, scratch136, 21:11); + s(EmcPdEx2Wr, 5:0, scratch136, 27:22); + s(EmcPmacroTxPwrd0, 13:13, scratch136, 28:28); + s(EmcPmacroTxPwrd0, 18:16, scratch136, 31:29); + s(EmcPmacroObDdllLongDqsRank1_4, 10:0, scratch137, 10:0); + s(EmcPmacroObDdllLongDqsRank1_4, 26:16, scratch137, 21:11); + s(EmcPdEx2Rd, 5:0, scratch137, 27:22); + s(EmcPmacroTxPwrd0, 22:19, scratch137, 31:28); + s(EmcPmacroObDdllLongDqsRank1_5, 10:0, scratch138, 10:0); + s(EmcPmacroObDdllLongDqsRank1_5, 26:16, scratch138, 21:11); + s(EmcPdex2Cke, 5:0, scratch138, 27:22); + s(EmcPmacroTxPwrd0, 26:23, scratch138, 31:28); + s(EmcPmacroIbDdllLongDqsRank0_0, 10:0, scratch139, 10:0); + s(EmcPmacroIbDdllLongDqsRank0_0, 26:16, scratch139, 21:11); + s(EmcPChg2Pden, 5:0, scratch139, 27:22); + s(EmcPmacroTxPwrd0, 29:27, scratch139, 30:28); + s(EmcPmacroTxPwrd1, 0:0, scratch139, 31:31); + s(EmcPmacroIbDdllLongDqsRank0_1, 10:0, scratch140, 10:0); + s(EmcPmacroIbDdllLongDqsRank0_1, 26:16, scratch140, 21:11); + s(EmcAct2Pden, 5:0, scratch140, 27:22); + s(EmcPmacroTxPwrd1, 4:1, scratch140, 31:28); + s(EmcPmacroIbDdllLongDqsRank0_2, 10:0, scratch141, 10:0); + s(EmcPmacroIbDdllLongDqsRank0_2, 26:16, scratch141, 21:11); + s(EmcCke2Pden, 5:0, scratch141, 27:22); + s(EmcPmacroTxPwrd1, 8:5, scratch141, 31:28); + s(EmcPmacroIbDdllLongDqsRank0_3, 10:0, scratch142, 10:0); + s(EmcPmacroIbDdllLongDqsRank0_3, 26:16, scratch142, 21:11); + s(EmcTcke, 5:0, scratch142, 27:22); + s(EmcPmacroTxPwrd1, 12:9, scratch142, 31:28); + s(EmcPmacroIbDdllLongDqsRank1_0, 10:0, scratch143, 10:0); + s(EmcPmacroIbDdllLongDqsRank1_0, 26:16, scratch143, 21:11); + s(EmcTrpab, 5:0, scratch143, 27:22); + s(EmcPmacroTxPwrd1, 13:13, scratch143, 28:28); + s(EmcPmacroTxPwrd1, 18:16, scratch143, 31:29); + s(EmcPmacroIbDdllLongDqsRank1_1, 10:0, scratch144, 10:0); + s(EmcPmacroIbDdllLongDqsRank1_1, 26:16, scratch144, 21:11); + s(EmcClkenOverride, 3:1, scratch144, 24:22); + s(EmcClkenOverride, 8:6, scratch144, 27:25); + s(EmcPmacroTxPwrd1, 22:19, scratch144, 31:28); + s(EmcPmacroIbDdllLongDqsRank1_2, 10:0, scratch145, 10:0); + s(EmcPmacroIbDdllLongDqsRank1_2, 26:16, scratch145, 21:11); + s(EmcEInput, 5:0, scratch145, 27:22); + s(EmcPmacroTxPwrd1, 26:23, scratch145, 31:28); + s(EmcPmacroIbDdllLongDqsRank1_3, 10:0, scratch146, 10:0); + s(EmcPmacroIbDdllLongDqsRank1_3, 26:16, scratch146, 21:11); + s(EmcEInputDuration, 5:0, scratch146, 27:22); + s(EmcPmacroTxPwrd1, 29:27, scratch146, 30:28); + s(EmcPmacroTxPwrd2, 0:0, scratch146, 31:31); + s(EmcPmacroDdllLongCmd_0, 10:0, scratch147, 10:0); + s(EmcPmacroDdllLongCmd_0, 26:16, scratch147, 21:11); + s(EmcPutermExtra, 5:0, scratch147, 27:22); + s(EmcPmacroTxPwrd2, 4:1, scratch147, 31:28); + s(EmcPmacroDdllLongCmd_1, 10:0, scratch148, 10:0); + s(EmcPmacroDdllLongCmd_1, 26:16, scratch148, 21:11); + s(EmcTckesr, 5:0, scratch148, 27:22); + s(EmcPmacroTxPwrd2, 8:5, scratch148, 31:28); + s(EmcPmacroDdllLongCmd_2, 10:0, scratch149, 10:0); + s(EmcPmacroDdllLongCmd_2, 26:16, scratch149, 21:11); + s(EmcTpd, 5:0, scratch149, 27:22); + s(EmcPmacroTxPwrd2, 12:9, scratch149, 31:28); + s(EmcPmacroDdllLongCmd_3, 10:0, scratch150, 10:0); + s(EmcPmacroDdllLongCmd_3, 26:16, scratch150, 21:11); + s(EmcWdvMask, 5:0, scratch150, 27:22); + s(EmcPmacroTxPwrd2, 13:13, scratch150, 28:28); + s(EmcPmacroTxPwrd2, 18:16, scratch150, 31:29); + s(McEmemArbCfg, 8:0, scratch151, 8:0); + s(McEmemArbCfg, 20:16, scratch151, 13:9); + s(McEmemArbCfg, 31:24, scratch151, 21:14); + s(EmcWdvChk, 5:0, scratch151, 27:22); + s(EmcPmacroTxPwrd2, 22:19, scratch151, 31:28); + s(McEmemArbMisc1, 12:0, scratch152, 12:0); + s(McEmemArbMisc1, 25:21, scratch152, 17:13); + s(McEmemArbMisc1, 31:28, scratch152, 21:18); + s(EmcCmdBrlshft0, 5:0, scratch152, 27:22); + s(EmcPmacroTxPwrd2, 26:23, scratch152, 31:28); + s(EmcMrsWaitCnt2, 9:0, scratch153, 9:0); + s(EmcMrsWaitCnt2, 26:16, scratch153, 20:10); + s(EmcPmacroIbRxrt, 10:0, scratch153, 31:21); + s(EmcMrsWaitCnt, 9:0, scratch154, 9:0); + s(EmcMrsWaitCnt, 26:16, scratch154, 20:10); + s(EmcPmacroDdllLongCmd_4, 10:0, scratch154, 31:21); + s(EmcAutoCalInterval, 20:0, scratch155, 20:0); + s(McEmemArbOutstandingReq, 8:0, scratch155, 29:21); + s(McEmemArbOutstandingReq, 31:30, scratch155, 31:30); + s(McEmemArbRefpbHpCtrl, 6:0, scratch156, 6:0); + s(McEmemArbRefpbHpCtrl, 14:8, scratch156, 13:7); + s(McEmemArbRefpbHpCtrl, 22:16, scratch156, 20:14); + s(EmcCmdBrlshft1, 5:0, scratch156, 26:21); + s(EmcRrd, 4:0, scratch156, 31:27); + s(EmcQuseBrlshft0, 19:0, scratch157, 19:0); + s(EmcFbioCfg8, 27:16, scratch157, 31:20); + s(EmcQuseBrlshft1, 19:0, scratch158, 19:0); + s(EmcTxsrDll, 11:0, scratch158, 31:20); + s(EmcQuseBrlshft2, 19:0, scratch159, 19:0); + s(EmcTxdsrvttgen, 11:0, scratch159, 31:20); + s(EmcQuseBrlshft3, 19:0, scratch160, 19:0); + s(EmcPmacroVttgenCtrl0, 3:0, scratch160, 23:20); + s(EmcPmacroVttgenCtrl0, 11:8, scratch160, 27:24); + s(EmcPmacroVttgenCtrl0, 19:16, scratch160, 31:28); + s(EmcPmacroVttgenCtrl1, 19:0, scratch161, 19:0); + s(EmcCmdBrlshft2, 5:0, scratch161, 25:20); + s(EmcCmdBrlshft3, 5:0, scratch161, 31:26); + s(EmcAutoCalConfig3, 5:0, scratch162, 5:0); + s(EmcAutoCalConfig3, 13:8, scratch162, 11:6); + s(EmcAutoCalConfig3, 18:16, scratch162, 14:12); + s(EmcAutoCalConfig3, 22:20, scratch162, 17:15); + s(EmcTRefBw, 13:0, scratch162, 31:18); + s(EmcAutoCalConfig4, 5:0, scratch163, 5:0); + s(EmcAutoCalConfig4, 13:8, scratch163, 11:6); + s(EmcAutoCalConfig4, 18:16, scratch163, 14:12); + s(EmcAutoCalConfig4, 22:20, scratch163, 17:15); + s(EmcQpop, 6:0, scratch163, 24:18); + s(EmcQpop, 22:16, scratch163, 31:25); + s(EmcAutoCalConfig5, 5:0, scratch164, 5:0); + s(EmcAutoCalConfig5, 13:8, scratch164, 11:6); + s(EmcAutoCalConfig5, 18:16, scratch164, 14:12); + s(EmcAutoCalConfig5, 22:20, scratch164, 17:15); + s(EmcPmacroAutocalCfgCommon, 5:0, scratch164, 23:18); + s(EmcPmacroAutocalCfgCommon, 13:8, scratch164, 29:24); + s(EmcPmacroAutocalCfgCommon, 16:16, scratch164, 30:30); + s(EmcPmacroTxPwrd2, 27:27, scratch164, 31:31); + s(EmcAutoCalConfig6, 5:0, scratch165, 5:0); + s(EmcAutoCalConfig6, 13:8, scratch165, 11:6); + s(EmcAutoCalConfig6, 18:16, scratch165, 14:12); + s(EmcAutoCalConfig6, 22:20, scratch165, 17:15); + s(EmcWev, 5:0, scratch165, 23:18); + s(EmcWsv, 5:0, scratch165, 29:24); + s(EmcPmacroTxPwrd2, 29:28, scratch165, 31:30); + s(EmcAutoCalConfig7, 5:0, scratch166, 5:0); + s(EmcAutoCalConfig7, 13:8, scratch166, 11:6); + s(EmcAutoCalConfig7, 18:16, scratch166, 14:12); + s(EmcAutoCalConfig7, 22:20, scratch166, 17:15); + s(EmcCfg3, 2:0, scratch166, 20:18); + s(EmcCfg3, 6:4, scratch166, 23:21); + s(EmcQuseWidth, 3:0, scratch166, 27:24); + s(EmcQuseWidth, 29:28, scratch166, 29:28); + s(EmcPmacroTxPwrd3, 1:0, scratch166, 31:30); + s(EmcAutoCalConfig8, 5:0, scratch167, 5:0); + s(EmcAutoCalConfig8, 13:8, scratch167, 11:6); + s(EmcAutoCalConfig8, 18:16, scratch167, 14:12); + s(EmcAutoCalConfig8, 22:20, scratch167, 17:15); + s(EmcPmacroBgBiasCtrl0, 2:0, scratch167, 20:18); + s(EmcPmacroBgBiasCtrl0, 6:4, scratch167, 23:21); + s(McEmemArbTimingRcd, 5:0, scratch167, 29:24); + s(EmcPmacroTxPwrd3, 3:2, scratch167, 31:30); + s(EmcXm2CompPadCtrl2, 17:0, scratch168, 17:0); + s(McEmemArbTimingCcdmw, 5:0, scratch168, 23:18); + s(McEmemArbOverride, 27:27, scratch168, 24:24); + s(McEmemArbOverride, 26:26, scratch168, 25:25); + s(McEmemArbOverride, 16:16, scratch168, 26:26); + s(McEmemArbOverride, 10:10, scratch168, 27:27); + s(McEmemArbOverride, 4:4, scratch168, 28:28); + s(McEmemArbOverride, 3:3, scratch168, 29:29); + s(EmcPmacroTxPwrd3, 5:4, scratch168, 31:30); + s(EmcXm2CompPadCtrl3, 17:0, scratch169, 17:0); + s(EmcRext, 4:0, scratch169, 22:18); + s(EmcTClkStop, 4:0, scratch169, 27:23); + s(EmcPmacroTxPwrd3, 9:6, scratch169, 31:28); + s(EmcZcalWaitCnt, 10:0, scratch170, 10:0); + s(EmcZcalWaitCnt, 21:16, scratch170, 16:11); + s(EmcZcalWaitCnt, 31:31, scratch170, 17:17); + s(EmcWext, 4:0, scratch170, 22:18); + s(EmcRefctrl2, 0:0, scratch170, 23:23); + s(EmcRefctrl2, 26:24, scratch170, 26:24); + s(EmcRefctrl2, 31:31, scratch170, 27:27); + s(EmcPmacroTxPwrd3, 13:10, scratch170, 31:28); + s(EmcZcalMrwCmd, 7:0, scratch171, 7:0); + s(EmcZcalMrwCmd, 23:16, scratch171, 15:8); + s(EmcZcalMrwCmd, 31:30, scratch171, 17:16); + s(EmcWeDuration, 4:0, scratch171, 22:18); + s(EmcWsDuration, 4:0, scratch171, 27:23); + s(EmcPmacroTxPwrd3, 19:16, scratch171, 31:28); + s(EmcSwizzleRank0Byte0, 2:0, scratch172, 2:0); + s(EmcSwizzleRank0Byte0, 6:4, scratch172, 5:3); + s(EmcSwizzleRank0Byte0, 10:8, scratch172, 8:6); + s(EmcSwizzleRank0Byte0, 14:12, scratch172, 11:9); + s(EmcSwizzleRank0Byte0, 18:16, scratch172, 14:12); + s(EmcSwizzleRank0Byte0, 22:20, scratch172, 17:15); + s(EmcPutermWidth, 31:31, scratch172, 18:18); + s(EmcPutermWidth, 3:0, scratch172, 22:19); + s(McEmemArbTimingRrd, 4:0, scratch172, 27:23); + s(EmcPmacroTxPwrd3, 23:20, scratch172, 31:28); + s(EmcSwizzleRank0Byte1, 2:0, scratch173, 2:0); + s(EmcSwizzleRank0Byte1, 6:4, scratch173, 5:3); + s(EmcSwizzleRank0Byte1, 10:8, scratch173, 8:6); + s(EmcSwizzleRank0Byte1, 14:12, scratch173, 11:9); + s(EmcSwizzleRank0Byte1, 18:16, scratch173, 14:12); + s(EmcSwizzleRank0Byte1, 22:20, scratch173, 17:15); + s(McEmemArbTimingR2R, 4:0, scratch173, 22:18); + s(McEmemArbTimingW2W, 4:0, scratch173, 27:23); + s(EmcPmacroTxPwrd3, 27:24, scratch173, 31:28); + s(EmcSwizzleRank0Byte2, 2:0, scratch174, 2:0); + s(EmcSwizzleRank0Byte2, 6:4, scratch174, 5:3); + s(EmcSwizzleRank0Byte2, 10:8, scratch174, 8:6); + s(EmcSwizzleRank0Byte2, 14:12, scratch174, 11:9); + s(EmcSwizzleRank0Byte2, 18:16, scratch174, 14:12); + s(EmcSwizzleRank0Byte2, 22:20, scratch174, 17:15); + s(EmcPmacroTxPwrd3, 29:28, scratch174, 19:18); + s(EmcPmacroTxSelClkSrc0, 11:0, scratch174, 31:20); + s(EmcSwizzleRank0Byte3, 2:0, scratch175, 2:0); + s(EmcSwizzleRank0Byte3, 6:4, scratch175, 5:3); + s(EmcSwizzleRank0Byte3, 10:8, scratch175, 8:6); + s(EmcSwizzleRank0Byte3, 14:12, scratch175, 11:9); + s(EmcSwizzleRank0Byte3, 18:16, scratch175, 14:12); + s(EmcSwizzleRank0Byte3, 22:20, scratch175, 17:15); + s(EmcPmacroTxSelClkSrc0, 27:16, scratch175, 29:18); + s(EmcPmacroTxSelClkSrc1, 1:0, scratch175, 31:30); + s(EmcSwizzleRank1Byte0, 2:0, scratch176, 2:0); + s(EmcSwizzleRank1Byte0, 6:4, scratch176, 5:3); + s(EmcSwizzleRank1Byte0, 10:8, scratch176, 8:6); + s(EmcSwizzleRank1Byte0, 14:12, scratch176, 11:9); + s(EmcSwizzleRank1Byte0, 18:16, scratch176, 14:12); + s(EmcSwizzleRank1Byte0, 22:20, scratch176, 17:15); + s(EmcPmacroTxSelClkSrc1, 11:2, scratch176, 27:18); + s(EmcPmacroTxSelClkSrc1, 19:16, scratch176, 31:28); + s(EmcSwizzleRank1Byte1, 2:0, scratch177, 2:0); + s(EmcSwizzleRank1Byte1, 6:4, scratch177, 5:3); + s(EmcSwizzleRank1Byte1, 10:8, scratch177, 8:6); + s(EmcSwizzleRank1Byte1, 14:12, scratch177, 11:9); + s(EmcSwizzleRank1Byte1, 18:16, scratch177, 14:12); + s(EmcSwizzleRank1Byte1, 22:20, scratch177, 17:15); + s(EmcPmacroTxSelClkSrc1, 27:20, scratch177, 25:18); + s(EmcPmacroTxSelClkSrc3, 5:0, scratch177, 31:26); + s(EmcSwizzleRank1Byte2, 2:0, scratch178, 2:0); + s(EmcSwizzleRank1Byte2, 6:4, scratch178, 5:3); + s(EmcSwizzleRank1Byte2, 10:8, scratch178, 8:6); + s(EmcSwizzleRank1Byte2, 14:12, scratch178, 11:9); + s(EmcSwizzleRank1Byte2, 18:16, scratch178, 14:12); + s(EmcSwizzleRank1Byte2, 22:20, scratch178, 17:15); + s(EmcPmacroTxSelClkSrc3, 11:6, scratch178, 23:18); + s(EmcPmacroTxSelClkSrc3, 23:16, scratch178, 31:24); + s(EmcSwizzleRank1Byte3, 2:0, scratch179, 2:0); + s(EmcSwizzleRank1Byte3, 6:4, scratch179, 5:3); + s(EmcSwizzleRank1Byte3, 10:8, scratch179, 8:6); + s(EmcSwizzleRank1Byte3, 14:12, scratch179, 11:9); + s(EmcSwizzleRank1Byte3, 18:16, scratch179, 14:12); + s(EmcSwizzleRank1Byte3, 22:20, scratch179, 17:15); + s(EmcPmacroTxSelClkSrc3, 27:24, scratch179, 21:18); + s(EmcPmacroTxSelClkSrc2, 9:0, scratch179, 31:22); + s(EmcPmacroCmdBrickCtrlFdpd, 17:0, scratch180, 17:0); + s(EmcPmacroTxSelClkSrc2, 11:10, scratch180, 19:18); + s(EmcPmacroTxSelClkSrc2, 27:16, scratch180, 31:20); + s(EmcPmacroDataBrickCtrlFdpd, 17:0, scratch181, 17:0); + s(EmcPmacroTxSelClkSrc4, 11:0, scratch181, 29:18); + s(EmcPmacroTxSelClkSrc4, 17:16, scratch181, 31:30); + s(EmcFbioCfg7, 16:0, scratch182, 16:0); + s(McEmemArbRefpbBankCtrl, 6:0, scratch182, 23:17); + s(McEmemArbRefpbBankCtrl, 14:8, scratch182, 30:24); + s(McEmemArbRefpbBankCtrl, 31:31, scratch182, 31:31); + s(EmcDynSelfRefControl, 15:0, scratch183, 15:0); + s(EmcDynSelfRefControl, 31:31, scratch183, 16:16); + s(EmcPmacroTxSelClkSrc4, 27:18, scratch183, 26:17); + s(EmcPmacroTxSelClkSrc5, 4:0, scratch183, 31:27); + s(EmcDllCfg1, 16:0, scratch184, 16:0); + s(EmcPmacroTxSelClkSrc5, 11:5, scratch184, 23:17); + s(EmcPmacroTxSelClkSrc5, 23:16, scratch184, 31:24); + s(EmcPmacroPadCfgCtrl, 1:0, scratch185, 1:0); + s(EmcPmacroPadCfgCtrl, 6:5, scratch185, 3:2); + s(EmcPmacroPadCfgCtrl, 11:9, scratch185, 6:4); + s(EmcPmacroPadCfgCtrl, 13:13, scratch185, 7:7); + s(EmcPmacroPadCfgCtrl, 17:16, scratch185, 9:8); + s(EmcPmacroPadCfgCtrl, 21:20, scratch185, 11:10); + s(EmcPmacroPadCfgCtrl, 25:24, scratch185, 13:12); + s(EmcPmacroPadCfgCtrl, 30:28, scratch185, 16:14); + s(EmcPmacroTxSelClkSrc5, 27:24, scratch185, 20:17); + s(EmcPmacroCmdPadTxCtrl, 1:0, scratch185, 22:21); + s(EmcPmacroCmdPadTxCtrl, 5:4, scratch185, 24:23); + s(EmcPmacroCmdPadTxCtrl, 9:8, scratch185, 26:25); + s(EmcPmacroCmdPadTxCtrl, 13:12, scratch185, 28:27); + s(EmcPmacroCmdPadTxCtrl, 16:16, scratch185, 29:29); + s(EmcPmacroCmdPadTxCtrl, 21:20, scratch185, 31:30); + s(EmcRefresh, 15:0, scratch186, 15:0); + s(EmcCmdQ, 4:0, scratch186, 20:16); + s(EmcCmdQ, 10:8, scratch186, 23:21); + s(EmcCmdQ, 14:12, scratch186, 26:24); + s(EmcCmdQ, 28:24, scratch186, 31:27); + s(EmcAcpdControl, 15:0, scratch187, 15:0); + s(EmcAutoCalVrefSel1, 15:0, scratch187, 31:16); + s(EmcXm2CompPadCtrl, 1:0, scratch188, 1:0); + s(EmcXm2CompPadCtrl, 6:3, scratch188, 5:2); + s(EmcXm2CompPadCtrl, 9:9, scratch188, 6:6); + s(EmcXm2CompPadCtrl, 19:11, scratch188, 15:7); + s(EmcCfgDigDllPeriod, 15:0, scratch188, 31:16); + s(EmcCfgDigDll_1, 15:0, scratch189, 15:0); + s(EmcPreRefreshReqCnt, 15:0, scratch189, 31:16); + s(EmcPmacroCmdPadTxCtrl, 27:24, scratch190, 19:16); + s(EmcPmacroDataPadTxCtrl, 1:0, scratch190, 21:20); + s(EmcPmacroDataPadTxCtrl, 5:4, scratch190, 23:22); + s(EmcPmacroDataPadTxCtrl, 9:8, scratch190, 25:24); + s(EmcPmacroDataPadTxCtrl, 13:12, scratch190, 27:26); + s(EmcPmacroDataPadTxCtrl, 16:16, scratch190, 28:28); + s(EmcPmacroDataPadTxCtrl, 21:20, scratch190, 30:29); + s(EmcPmacroDataPadTxCtrl, 24:24, scratch190, 31:31); + s(EmcPmacroDataPadTxCtrl, 27:25, scratch191, 2:0); + + s(EmcPinGpio, 1:0, scratch8, 31:30); + s(EmcPinGpioEn, 1:0, scratch9, 31:30); + s(EmcDevSelect, 1:0, scratch10, 31:30); + s(EmcZcalWarmColdBootEnables, 1:0, scratch11, 31:30); + s(EmcCfgDigDllPeriodWarmBoot, 1:0, scratch12, 31:30); + s32(EmcBctSpare13, scratch31); + s32(EmcBctSpare12, scratch32); + s32(EmcBctSpare7, scratch33); + s32(EmcBctSpare6, scratch40); + s32(EmcBctSpare5, scratch42); + s32(EmcBctSpare4, scratch44); + s32(EmcBctSpare3, scratch45); + s32(EmcBctSpare2, scratch46); + s32(EmcBctSpare1, scratch47); + s32(EmcBctSpare0, scratch48); + s32(EmcBctSpare9, scratch50); + s32(EmcBctSpare8, scratch51); + s32(BootRomPatchData, scratch56); + s32(BootRomPatchControl, scratch57); + s(McClkenOverrideAllWarmBoot, 0:0, scratch58, 31:31); + s(EmcClkenOverrideAllWarmBoot, 0:0, scratch59, 30:30); + s(EmcMrsWarmBootEnable, 0:0, scratch59, 31:31); + s(ClearClk2Mc1, 0:0, scratch60, 30:30); + s(EmcWarmBootExtraModeRegWriteEnable, 0:0, scratch60, 31:31); + s(ClkRstControllerPllmMisc2OverrideEnable, 0:0, scratch61, 30:30); + s(EmcDbgWriteMux, 0:0, scratch61, 31:31); + s(EmcExtraRefreshNum, 2:0, scratch62, 31:29); + s(PmcIoDpd3ReqWait, 2:0, scratch68, 30:28); + s(AhbArbitrationXbarCtrlMemInitDone, 0:0, scratch68, 31:31); + s(MemoryType, 2:0, scratch69, 30:28); + s(PmcIoDpd4ReqWait, 2:0, scratch70, 30:28); + s(EmcTimingControlWait, 7:0, scratch86, 31:24); + s(EmcZcalWarmBootWait, 7:0, scratch87, 31:24); + s(WarmBootWait, 7:0, scratch88, 31:24); + s(EmcPinProgramWait, 7:0, scratch89, 31:24); + s(EmcAutoCalWait, 9:0, scratch101, 31:22); + s(SwizzleRankByteEncode, 15:0, scratch190, 15:0); + + switch (sdram->MemoryType) + { + case NvBootMemoryType_LpDdr2: + case NvBootMemoryType_LpDdr4: + s(EmcMrwLpddr2ZcalWarmBoot, 23:16, scratch5, 7:0); + s(EmcMrwLpddr2ZcalWarmBoot, 7:0, scratch5, 15:8); + s(EmcWarmBootMrwExtra, 23:16, scratch5, 23:16); + s(EmcWarmBootMrwExtra, 7:0, scratch5, 31:24); + s(EmcMrwLpddr2ZcalWarmBoot, 31:30, scratch6, 1:0); + s(EmcWarmBootMrwExtra, 31:30, scratch6, 3:2); + s(EmcMrwLpddr2ZcalWarmBoot, 27:26, scratch6, 5:4); + s(EmcWarmBootMrwExtra, 27:26, scratch6, 7:6); + s(EmcMrw6, 27:0, scratch8, 27:0); + s(EmcMrw6, 31:30, scratch8, 29:28); + s(EmcMrw8, 27:0, scratch9, 27:0); + s(EmcMrw8, 31:30, scratch9, 29:28); + s(EmcMrw9, 27:0, scratch10, 27:0); + s(EmcMrw9, 31:30, scratch10, 29:28); + s(EmcMrw10, 27:0, scratch11, 27:0); + s(EmcMrw10, 31:30, scratch11, 29:28); + s(EmcMrw12, 27:0, scratch12, 27:0); + s(EmcMrw12, 31:30, scratch12, 29:28); + s(EmcMrw13, 27:0, scratch13, 27:0); + s(EmcMrw13, 31:30, scratch13, 29:28); + s(EmcMrw14, 27:0, scratch14, 27:0); + s(EmcMrw14, 31:30, scratch14, 29:28); + s(EmcMrw1, 7:0, scratch15, 7:0); + s(EmcMrw1, 23:16, scratch15, 15:8); + s(EmcMrw1, 27:26, scratch15, 17:16); + s(EmcMrw1, 31:30, scratch15, 19:18); + s(EmcWarmBootMrwExtra, 7:0, scratch16, 7:0); + s(EmcWarmBootMrwExtra, 23:16, scratch16, 15:8); + s(EmcWarmBootMrwExtra, 27:26, scratch16, 17:16); + s(EmcWarmBootMrwExtra, 31:30, scratch16, 19:18); + s(EmcMrw2, 7:0, scratch17, 7:0); + s(EmcMrw2, 23:16, scratch17, 15:8); + s(EmcMrw2, 27:26, scratch17, 17:16); + s(EmcMrw2, 31:30, scratch17, 19:18); + s(EmcMrw3, 7:0, scratch18, 7:0); + s(EmcMrw3, 23:16, scratch18, 15:8); + s(EmcMrw3, 27:26, scratch18, 17:16); + s(EmcMrw3, 31:30, scratch18, 19:18); + s(EmcMrw4, 7:0, scratch19, 7:0); + s(EmcMrw4, 23:16, scratch19, 15:8); + s(EmcMrw4, 27:26, scratch19, 17:16); + s(EmcMrw4, 31:30, scratch19, 19:18); + break; + case NvBootMemoryType_Ddr3: + s(EmcMrs, 13:0, scratch5, 13:0); + s(EmcEmrs, 13:0, scratch5, 27:14); + s(EmcMrs, 21:20, scratch5, 29:28); + s(EmcMrs, 31:30, scratch5, 31:30); + s(EmcEmrs2, 13:0, scratch8, 13:0); + s(EmcEmrs3, 13:0, scratch8, 27:14); + s(EmcEmrs, 21:20, scratch8, 29:28); + s(EmcWarmBootMrsExtra, 13:0, scratch9, 13:0); + s(EmcEmrs, 31:30, scratch9, 15:14); + s(EmcEmrs2, 21:20, scratch9, 17:16); + s(EmcEmrs2, 31:30, scratch9, 19:18); + s(EmcEmrs3, 21:20, scratch9, 21:20); + s(EmcEmrs3, 31:30, scratch9, 23:22); + s(EmcWarmBootMrsExtra, 31:30, scratch9, 25:24); + s(EmcWarmBootMrsExtra, 21:20, scratch9, 27:26); + s(EmcZqCalDdr3WarmBoot, 31:30, scratch9, 29:28); + s(EmcMrs, 27:26, scratch10, 1:0); + s(EmcEmrs, 27:26, scratch10, 3:2); + s(EmcEmrs2, 27:26, scratch10, 5:4); + s(EmcEmrs3, 27:26, scratch10, 7:6); + s(EmcWarmBootMrsExtra, 27:27, scratch10, 8:8); + s(EmcWarmBootMrsExtra, 26:26, scratch10, 9:9); + s(EmcZqCalDdr3WarmBoot, 0:0, scratch10, 10:10); + s(EmcZqCalDdr3WarmBoot, 4:4, scratch10, 11:11); + break; + } + + s32(EmcCmdMappingByte, secure_scratch8); + s32(EmcPmacroBrickMapping0, secure_scratch9); + s32(EmcPmacroBrickMapping1, secure_scratch10); + s32(EmcPmacroBrickMapping2, secure_scratch11); + s32(McVideoProtectGpuOverride0, secure_scratch12); + s(EmcCmdMappingCmd0_0, 6:0, secure_scratch13, 6:0); + s(EmcCmdMappingCmd0_0, 14:8, secure_scratch13, 13:7); + s(EmcCmdMappingCmd0_0, 22:16, secure_scratch13, 20:14); + s(EmcCmdMappingCmd0_0, 30:24, secure_scratch13, 27:21); + s(McVideoProtectBomAdrHi, 1:0, secure_scratch13, 29:28); + s(McVideoProtectWriteAccess, 1:0, secure_scratch13, 31:30); + s(EmcCmdMappingCmd0_1, 6:0, secure_scratch14, 6:0); + s(EmcCmdMappingCmd0_1, 14:8, secure_scratch14, 13:7); + s(EmcCmdMappingCmd0_1, 22:16, secure_scratch14, 20:14); + s(EmcCmdMappingCmd0_1, 30:24, secure_scratch14, 27:21); + s(McSecCarveoutAdrHi, 1:0, secure_scratch14, 29:28); + s(McMtsCarveoutAdrHi, 1:0, secure_scratch14, 31:30); + s(EmcCmdMappingCmd1_0, 6:0, secure_scratch15, 6:0); + s(EmcCmdMappingCmd1_0, 14:8, secure_scratch15, 13:7); + s(EmcCmdMappingCmd1_0, 22:16, secure_scratch15, 20:14); + s(EmcCmdMappingCmd1_0, 30:24, secure_scratch15, 27:21); + s(McGeneralizedCarveout5BomHi, 1:0, secure_scratch15, 29:28); + s(McGeneralizedCarveout3BomHi, 1:0, secure_scratch15, 31:30); + s(EmcCmdMappingCmd1_1, 6:0, secure_scratch16, 6:0); + s(EmcCmdMappingCmd1_1, 14:8, secure_scratch16, 13:7); + s(EmcCmdMappingCmd1_1, 22:16, secure_scratch16, 20:14); + s(EmcCmdMappingCmd1_1, 30:24, secure_scratch16, 27:21); + s(McGeneralizedCarveout2BomHi, 1:0, secure_scratch16, 29:28); + s(McGeneralizedCarveout4BomHi, 1:0, secure_scratch16, 31:30); + s(EmcCmdMappingCmd2_0, 6:0, secure_scratch17, 6:0); + s(EmcCmdMappingCmd2_0, 14:8, secure_scratch17, 13:7); + s(EmcCmdMappingCmd2_0, 22:16, secure_scratch17, 20:14); + s(EmcCmdMappingCmd2_0, 30:24, secure_scratch17, 27:21); + s(McGeneralizedCarveout1BomHi, 1:0, secure_scratch17, 29:28); + s(EmcAdrCfg, 0:0, secure_scratch17, 30:30); + s(EmcFbioSpare, 1:1, secure_scratch17, 31:31); + s(EmcCmdMappingCmd2_1, 6:0, secure_scratch18, 6:0); + s(EmcCmdMappingCmd2_1, 14:8, secure_scratch18, 13:7); + s(EmcCmdMappingCmd2_1, 22:16, secure_scratch18, 20:14); + s(EmcCmdMappingCmd2_1, 30:24, secure_scratch18, 27:21); + s(EmcFbioCfg8, 15:15, secure_scratch18, 28:28); + s(McEmemAdrCfg, 0:0, secure_scratch18, 29:29); + s(McSecCarveoutProtectWriteAccess, 0:0, secure_scratch18, 30:30); + s(McMtsCarveoutRegCtrl, 0:0, secure_scratch18, 31:31); + s(EmcCmdMappingCmd3_0, 6:0, secure_scratch19, 6:0); + s(EmcCmdMappingCmd3_0, 14:8, secure_scratch19, 13:7); + s(EmcCmdMappingCmd3_0, 22:16, secure_scratch19, 20:14); + s(EmcCmdMappingCmd3_0, 30:24, secure_scratch19, 27:21); + s(McGeneralizedCarveout2Cfg0, 6:3, secure_scratch19, 31:28); + s(EmcCmdMappingCmd3_1, 6:0, secure_scratch20, 6:0); + s(EmcCmdMappingCmd3_1, 14:8, secure_scratch20, 13:7); + s(EmcCmdMappingCmd3_1, 22:16, secure_scratch20, 20:14); + s(EmcCmdMappingCmd3_1, 30:24, secure_scratch20, 27:21); + s(McGeneralizedCarveout2Cfg0, 10:7, secure_scratch20, 31:28); + s(McGeneralizedCarveout4Cfg0, 26:0, secure_scratch39, 26:0); + s(McGeneralizedCarveout2Cfg0, 17:14, secure_scratch39, 30:27); + s(McVideoProtectVprOverride, 0:0, secure_scratch39, 31:31); + s(McGeneralizedCarveout5Cfg0, 26:0, secure_scratch40, 26:0); + s(McGeneralizedCarveout2Cfg0, 21:18, secure_scratch40, 30:27); + s(McVideoProtectVprOverride, 1:1, secure_scratch40, 31:31); + s(EmcCmdMappingCmd0_2, 6:0, secure_scratch41, 6:0); + s(EmcCmdMappingCmd0_2, 14:8, secure_scratch41, 13:7); + s(EmcCmdMappingCmd0_2, 22:16, secure_scratch41, 20:14); + s(EmcCmdMappingCmd0_2, 27:24, secure_scratch41, 24:21); + s(McGeneralizedCarveout1Cfg0, 6:3, secure_scratch41, 28:25); + s(McGeneralizedCarveout2Cfg0, 13:11, secure_scratch41, 31:29); + s(EmcCmdMappingCmd1_2, 6:0, secure_scratch42, 6:0); + s(EmcCmdMappingCmd1_2, 14:8, secure_scratch42, 13:7); + s(EmcCmdMappingCmd1_2, 22:16, secure_scratch42, 20:14); + s(EmcCmdMappingCmd1_2, 27:24, secure_scratch42, 24:21); + s(McGeneralizedCarveout1Cfg0, 13:7, secure_scratch42, 31:25); + s(EmcCmdMappingCmd2_2, 6:0, secure_scratch43, 6:0); + s(EmcCmdMappingCmd2_2, 14:8, secure_scratch43, 13:7); + s(EmcCmdMappingCmd2_2, 22:16, secure_scratch43, 20:14); + s(EmcCmdMappingCmd2_2, 27:24, secure_scratch43, 24:21); + s(McGeneralizedCarveout1Cfg0, 17:14, secure_scratch43, 28:25); + s(McGeneralizedCarveout3Cfg0, 13:11, secure_scratch43, 31:29); + s(EmcCmdMappingCmd3_2, 6:0, secure_scratch44, 6:0); + s(EmcCmdMappingCmd3_2, 14:8, secure_scratch44, 13:7); + s(EmcCmdMappingCmd3_2, 22:16, secure_scratch44, 20:14); + s(EmcCmdMappingCmd3_2, 27:24, secure_scratch44, 24:21); + s(McGeneralizedCarveout1Cfg0, 21:18, secure_scratch44, 28:25); + s(McVideoProtectVprOverride, 3:2, secure_scratch44, 30:29); + s(McVideoProtectVprOverride, 6:6, secure_scratch44, 31:31); + s(McEmemAdrCfgChannelMask, 31:9, secure_scratch45, 22:0); + s(McEmemAdrCfgDev0, 2:0, secure_scratch45, 25:23); + s(McEmemAdrCfgDev0, 9:8, secure_scratch45, 27:26); + s(McEmemAdrCfgDev0, 19:16, secure_scratch45, 31:28); + s(McEmemAdrCfgBankMask0, 31:10, secure_scratch46, 21:0); + s(McEmemAdrCfgDev1, 2:0, secure_scratch46, 24:22); + s(McEmemAdrCfgDev1, 9:8, secure_scratch46, 26:25); + s(McEmemAdrCfgDev1, 19:16, secure_scratch46, 30:27); + s(McVideoProtectVprOverride, 7:7, secure_scratch46, 31:31); + s(McEmemAdrCfgBankMask1, 31:10, secure_scratch47, 21:0); + s(McGeneralizedCarveout3Cfg0, 10:3, secure_scratch47, 29:22); + s(McVideoProtectVprOverride, 9:8, secure_scratch47, 31:30); + s(McEmemAdrCfgBankMask2, 31:10, secure_scratch48, 21:0); + s(McGeneralizedCarveout3Cfg0, 21:14, secure_scratch48, 29:22); + s(McVideoProtectVprOverride, 11:11, secure_scratch48, 30:30); + s(McVideoProtectVprOverride, 14:14, secure_scratch48, 31:31); + s(McVideoProtectGpuOverride1, 15:0, secure_scratch49, 15:0); + s(McEmemCfg, 13:0, secure_scratch49, 29:16); + s(McEmemCfg, 31:31, secure_scratch49, 30:30); + s(McVideoProtectVprOverride, 15:15, secure_scratch49, 31:31); + s(McGeneralizedCarveout3Bom, 31:17, secure_scratch50, 14:0); + s(McGeneralizedCarveout1Bom, 31:17, secure_scratch50, 29:15); + s(McVideoProtectVprOverride, 18:17, secure_scratch50, 31:30); + s(McGeneralizedCarveout4Bom, 31:17, secure_scratch51, 14:0); + s(McGeneralizedCarveout2Bom, 31:17, secure_scratch51, 29:15); + s(McVideoProtectVprOverride, 20:19, secure_scratch51, 31:30); + s(McGeneralizedCarveout5Bom, 31:17, secure_scratch52, 14:0); + s(McVideoProtectBom, 31:20, secure_scratch52, 26:15); + s(McVideoProtectVprOverride, 23:21, secure_scratch52, 29:27); + s(McVideoProtectVprOverride, 26:26, secure_scratch52, 30:30); + s(McVideoProtectVprOverride, 29:29, secure_scratch52, 31:31); + s(McVideoProtectSizeMb, 11:0, secure_scratch53, 11:0); + s(McSecCarveoutBom, 31:20, secure_scratch53, 23:12); + s(McVideoProtectVprOverride, 31:30, secure_scratch53, 25:24); + s(McVideoProtectVprOverride1, 1:0, secure_scratch53, 27:26); + s(McVideoProtectVprOverride1, 7:4, secure_scratch53, 31:28); + s(McSecCarveoutSizeMb, 11:0, secure_scratch54, 11:0); + s(McMtsCarveoutBom, 31:20, secure_scratch54, 23:12); + s(McVideoProtectVprOverride1, 15:8, secure_scratch54, 31:24); + s(McMtsCarveoutSizeMb, 11:0, secure_scratch55, 11:0); + s(McGeneralizedCarveout4Size128kb, 11:0, secure_scratch55, 23:12); + s(McVideoProtectVprOverride1, 16:16, secure_scratch55, 24:24); + s(McGeneralizedCarveout2Cfg0, 2:0, secure_scratch55, 27:25); + s(McGeneralizedCarveout2Cfg0, 25:22, secure_scratch55, 31:28); + s(McGeneralizedCarveout3Size128kb, 11:0, secure_scratch56, 11:0); + s(McGeneralizedCarveout2Size128kb, 11:0, secure_scratch56, 23:12); + s(McGeneralizedCarveout2Cfg0, 26:26, secure_scratch56, 24:24); + s(McGeneralizedCarveout1Cfg0, 2:0, secure_scratch56, 27:25); + s(McGeneralizedCarveout1Cfg0, 25:22, secure_scratch56, 31:28); + s(McGeneralizedCarveout1Size128kb, 11:0, secure_scratch57, 11:0); + s(McGeneralizedCarveout5Size128kb, 11:0, secure_scratch57, 23:12); + s(McGeneralizedCarveout1Cfg0, 26:26, secure_scratch57, 24:24); + s(McGeneralizedCarveout3Cfg0, 2:0, secure_scratch57, 27:25); + s(McGeneralizedCarveout3Cfg0, 25:22, secure_scratch57, 31:28); + s(McGeneralizedCarveout3Cfg0, 26:26, secure_scratch58, 0:0); + + s32(McGeneralizedCarveout1Access0, secure_scratch59); + s32(McGeneralizedCarveout1Access1, secure_scratch60); + s32(McGeneralizedCarveout1Access2, secure_scratch61); + s32(McGeneralizedCarveout1Access3, secure_scratch62); + s32(McGeneralizedCarveout1Access4, secure_scratch63); + s32(McGeneralizedCarveout2Access0, secure_scratch64); + s32(McGeneralizedCarveout2Access1, secure_scratch65); + s32(McGeneralizedCarveout2Access2, secure_scratch66); + s32(McGeneralizedCarveout2Access3, secure_scratch67); + s32(McGeneralizedCarveout2Access4, secure_scratch68); + s32(McGeneralizedCarveout3Access0, secure_scratch69); + s32(McGeneralizedCarveout3Access1, secure_scratch70); + s32(McGeneralizedCarveout3Access2, secure_scratch71); + s32(McGeneralizedCarveout3Access3, secure_scratch72); + s32(McGeneralizedCarveout3Access4, secure_scratch73); + s32(McGeneralizedCarveout4Access0, secure_scratch74); + s32(McGeneralizedCarveout4Access1, secure_scratch75); + s32(McGeneralizedCarveout4Access2, secure_scratch76); + s32(McGeneralizedCarveout4Access3, secure_scratch77); + s32(McGeneralizedCarveout4Access4, secure_scratch78); + s32(McGeneralizedCarveout5Access0, secure_scratch79); + s32(McGeneralizedCarveout5Access1, secure_scratch80); + s32(McGeneralizedCarveout5Access2, secure_scratch81); + s32(McGeneralizedCarveout5Access3, secure_scratch82); + s32(McGeneralizedCarveout1ForceInternalAccess0, secure_scratch84); + s32(McGeneralizedCarveout1ForceInternalAccess1, secure_scratch85); + s32(McGeneralizedCarveout1ForceInternalAccess2, secure_scratch86); + s32(McGeneralizedCarveout1ForceInternalAccess3, secure_scratch87); + s32(McGeneralizedCarveout1ForceInternalAccess4, secure_scratch88); + s32(McGeneralizedCarveout2ForceInternalAccess0, secure_scratch89); + s32(McGeneralizedCarveout2ForceInternalAccess1, secure_scratch90); + s32(McGeneralizedCarveout2ForceInternalAccess2, secure_scratch91); + s32(McGeneralizedCarveout2ForceInternalAccess3, secure_scratch92); + s32(McGeneralizedCarveout2ForceInternalAccess4, secure_scratch93); + s32(McGeneralizedCarveout3ForceInternalAccess0, secure_scratch94); + s32(McGeneralizedCarveout3ForceInternalAccess1, secure_scratch95); + s32(McGeneralizedCarveout3ForceInternalAccess2, secure_scratch96); + s32(McGeneralizedCarveout3ForceInternalAccess3, secure_scratch97); + s32(McGeneralizedCarveout3ForceInternalAccess4, secure_scratch98); + s32(McGeneralizedCarveout4ForceInternalAccess0, secure_scratch99); + s32(McGeneralizedCarveout4ForceInternalAccess1, secure_scratch100); + s32(McGeneralizedCarveout4ForceInternalAccess2, secure_scratch101); + s32(McGeneralizedCarveout4ForceInternalAccess3, secure_scratch102); + s32(McGeneralizedCarveout4ForceInternalAccess4, secure_scratch103); + s32(McGeneralizedCarveout5ForceInternalAccess0, secure_scratch104); + s32(McGeneralizedCarveout5ForceInternalAccess1, secure_scratch105); + s32(McGeneralizedCarveout5ForceInternalAccess2, secure_scratch106); + s32(McGeneralizedCarveout5ForceInternalAccess3, secure_scratch107); + + c32(0, scratch2); + s(PllMInputDivider, 7:0, scratch2, 7:0); + s(PllMFeedbackDivider, 7:0, scratch2, 15:8); + s(PllMPostDivider, 4:0, scratch2, 20:16); + s(PllMKVCO, 0:0, scratch2, 21:21); + s(PllMKCP, 1:0, scratch2, 23:22); + + c32(0, scratch35); + s(PllMSetupControl, 15:0, scratch35, 15:0); + + c32(0, scratch3); + s(PllMInputDivider, 7:0, scratch3, 7:0); + c(0x3e, scratch3, 15:8); + c(0, scratch3, 20:16); + s(PllMKVCO, 0:0, scratch3, 21:21); + s(PllMKCP, 1:0, scratch3, 23:22); + + c32(0, scratch36); + s(PllMSetupControl, 23:0, scratch36, 23:0); + + c32(0, scratch4); + s(PllMStableTime, 9:0, scratch4, 9:0); +} diff --git a/nyx/nyx_gui/mem/sdram_lp0_param_t210.h b/nyx/nyx_gui/mem/sdram_lp0_param_t210.h new file mode 100644 index 0000000..7f44f1d --- /dev/null +++ b/nyx/nyx_gui/mem/sdram_lp0_param_t210.h @@ -0,0 +1,964 @@ +/* + * Copyright (c) 2013-2015, NVIDIA CORPORATION. All rights reserved. + * Copyright 2014 Google Inc. + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +/** + * Defines the SDRAM parameter structure. + * + * Note that PLLM is used by EMC. The field names are in camel case to ease + * directly converting BCT config files (*.cfg) into C structure. + */ + +#ifndef __SOC_NVIDIA_TEGRA210_SDRAM_PARAM_H__ +#define __SOC_NVIDIA_TEGRA210_SDRAM_PARAM_H__ + +#include "../utils/types.h" + +enum +{ + /* Specifies the memory type to be undefined */ + NvBootMemoryType_None = 0, + + /* Specifies the memory type to be DDR SDRAM */ + NvBootMemoryType_Ddr = 0, + + /* Specifies the memory type to be LPDDR SDRAM */ + NvBootMemoryType_LpDdr = 0, + + /* Specifies the memory type to be DDR2 SDRAM */ + NvBootMemoryType_Ddr2 = 0, + + /* Specifies the memory type to be LPDDR2 SDRAM */ + NvBootMemoryType_LpDdr2, + + /* Specifies the memory type to be DDR3 SDRAM */ + NvBootMemoryType_Ddr3, + + /* Specifies the memory type to be LPDDR4 SDRAM */ + NvBootMemoryType_LpDdr4, + + NvBootMemoryType_Num, + + /* Specifies an entry in the ram_code table that's not in use */ + NvBootMemoryType_Unused = 0X7FFFFFF, +}; + +/** + * Defines the SDRAM parameter structure + */ +struct sdram_params +{ + + /* Specifies the type of memory device */ + u32 MemoryType; + + /* MC/EMC clock source configuration */ + + /* Specifies the M value for PllM */ + u32 PllMInputDivider; + /* Specifies the N value for PllM */ + u32 PllMFeedbackDivider; + /* Specifies the time to wait for PLLM to lock (in microseconds) */ + u32 PllMStableTime; + /* Specifies misc. control bits */ + u32 PllMSetupControl; + /* Specifies the P value for PLLM */ + u32 PllMPostDivider; + /* Specifies value for Charge Pump Gain Control */ + u32 PllMKCP; + /* Specifies VCO gain */ + u32 PllMKVCO; + /* Spare BCT param */ + u32 EmcBctSpare0; + /* Spare BCT param */ + u32 EmcBctSpare1; + /* Spare BCT param */ + u32 EmcBctSpare2; + /* Spare BCT param */ + u32 EmcBctSpare3; + /* Spare BCT param */ + u32 EmcBctSpare4; + /* Spare BCT param */ + u32 EmcBctSpare5; + /* Spare BCT param */ + u32 EmcBctSpare6; + /* Spare BCT param */ + u32 EmcBctSpare7; + /* Spare BCT param */ + u32 EmcBctSpare8; + /* Spare BCT param */ + u32 EmcBctSpare9; + /* Spare BCT param */ + u32 EmcBctSpare10; + /* Spare BCT param */ + u32 EmcBctSpare11; + /* Spare BCT param */ + u32 EmcBctSpare12; + /* Spare BCT param */ + u32 EmcBctSpare13; + + /* Defines EMC_2X_CLK_SRC, EMC_2X_CLK_DIVISOR, EMC_INVERT_DCD */ + u32 EmcClockSource; + u32 EmcClockSourceDll; + + /* Defines possible override for PLLLM_MISC2 */ + u32 ClkRstControllerPllmMisc2Override; + /* enables override for PLLLM_MISC2 */ + u32 ClkRstControllerPllmMisc2OverrideEnable; + /* defines CLK_ENB_MC1 in register clk_rst_controller_clk_enb_w_clr */ + u32 ClearClk2Mc1; + + /* Auto-calibration of EMC pads */ + + /* Specifies the value for EMC_AUTO_CAL_INTERVAL */ + u32 EmcAutoCalInterval; + /* + * Specifies the value for EMC_AUTO_CAL_CONFIG + * Note: Trigger bits are set by the SDRAM code. + */ + u32 EmcAutoCalConfig; + + /* Specifies the value for EMC_AUTO_CAL_CONFIG2 */ + u32 EmcAutoCalConfig2; + + /* Specifies the value for EMC_AUTO_CAL_CONFIG3 */ + u32 EmcAutoCalConfig3; + + /* Specifies the values for EMC_AUTO_CAL_CONFIG4-8 */ + u32 EmcAutoCalConfig4; + u32 EmcAutoCalConfig5; + u32 EmcAutoCalConfig6; + u32 EmcAutoCalConfig7; + u32 EmcAutoCalConfig8; + + /* Specifies the value for EMC_AUTO_CAL_VREF_SEL_0 */ + u32 EmcAutoCalVrefSel0; + u32 EmcAutoCalVrefSel1; + + /* Specifies the value for EMC_AUTO_CAL_CHANNEL */ + u32 EmcAutoCalChannel; + + /* Specifies the value for EMC_PMACRO_AUTOCAL_CFG_0 */ + u32 EmcPmacroAutocalCfg0; + u32 EmcPmacroAutocalCfg1; + u32 EmcPmacroAutocalCfg2; + u32 EmcPmacroRxTerm; + u32 EmcPmacroDqTxDrv; + u32 EmcPmacroCaTxDrv; + u32 EmcPmacroCmdTxDrv; + u32 EmcPmacroAutocalCfgCommon; + u32 EmcPmacroZctrl; + + /* + * Specifies the time for the calibration + * to stabilize (in microseconds) + */ + u32 EmcAutoCalWait; + + u32 EmcXm2CompPadCtrl; + u32 EmcXm2CompPadCtrl2; + u32 EmcXm2CompPadCtrl3; + + /* + * DRAM size information + * Specifies the value for EMC_ADR_CFG + */ + u32 EmcAdrCfg; + + /* + * Specifies the time to wait after asserting pin + * CKE (in microseconds) + */ + u32 EmcPinProgramWait; + /* Specifies the extra delay before/after pin RESET/CKE command */ + u32 EmcPinExtraWait; + + u32 EmcPinGpioEn; + u32 EmcPinGpio; + + /* + * Specifies the extra delay after the first writing + * of EMC_TIMING_CONTROL + */ + u32 EmcTimingControlWait; + + /* Timing parameters required for the SDRAM */ + + /* Specifies the value for EMC_RC */ + u32 EmcRc; + /* Specifies the value for EMC_RFC */ + u32 EmcRfc; + /* Specifies the value for EMC_RFC_PB */ + u32 EmcRfcPb; + /* Specifies the value for EMC_RFC_CTRL2 */ + u32 EmcRefctrl2; + /* Specifies the value for EMC_RFC_SLR */ + u32 EmcRfcSlr; + /* Specifies the value for EMC_RAS */ + u32 EmcRas; + /* Specifies the value for EMC_RP */ + u32 EmcRp; + /* Specifies the value for EMC_R2R */ + u32 EmcR2r; + /* Specifies the value for EMC_W2W */ + u32 EmcW2w; + /* Specifies the value for EMC_R2W */ + u32 EmcR2w; + /* Specifies the value for EMC_W2R */ + u32 EmcW2r; + /* Specifies the value for EMC_R2P */ + u32 EmcR2p; + /* Specifies the value for EMC_W2P */ + u32 EmcW2p; + + u32 EmcTppd; + u32 EmcCcdmw; + + /* Specifies the value for EMC_RD_RCD */ + u32 EmcRdRcd; + /* Specifies the value for EMC_WR_RCD */ + u32 EmcWrRcd; + /* Specifies the value for EMC_RRD */ + u32 EmcRrd; + /* Specifies the value for EMC_REXT */ + u32 EmcRext; + /* Specifies the value for EMC_WEXT */ + u32 EmcWext; + /* Specifies the value for EMC_WDV */ + u32 EmcWdv; + + u32 EmcWdvChk; + u32 EmcWsv; + u32 EmcWev; + + /* Specifies the value for EMC_WDV_MASK */ + u32 EmcWdvMask; + + u32 EmcWsDuration; + u32 EmcWeDuration; + + /* Specifies the value for EMC_QUSE */ + u32 EmcQUse; + /* Specifies the value for EMC_QUSE_WIDTH */ + u32 EmcQuseWidth; + /* Specifies the value for EMC_IBDLY */ + u32 EmcIbdly; + /* Specifies the value for EMC_OBDLY */ + u32 EmcObdly; + /* Specifies the value for EMC_EINPUT */ + u32 EmcEInput; + /* Specifies the value for EMC_EINPUT_DURATION */ + u32 EmcEInputDuration; + /* Specifies the value for EMC_PUTERM_EXTRA */ + u32 EmcPutermExtra; + /* Specifies the value for EMC_PUTERM_WIDTH */ + u32 EmcPutermWidth; + /* Specifies the value for EMC_PUTERM_ADJ */ + ////u32 EmcPutermAdj; + + /* Specifies the value for EMC_QRST */ + u32 EmcQRst; + /* Specifies the value for EMC_QSAFE */ + u32 EmcQSafe; + /* Specifies the value for EMC_RDV */ + u32 EmcRdv; + /* Specifies the value for EMC_RDV_MASK */ + u32 EmcRdvMask; + /* Specifies the value for EMC_RDV_EARLY */ + u32 EmcRdvEarly; + /* Specifies the value for EMC_RDV_EARLY_MASK */ + u32 EmcRdvEarlyMask; + /* Specifies the value for EMC_QPOP */ + u32 EmcQpop; + + /* Specifies the value for EMC_REFRESH */ + u32 EmcRefresh; + /* Specifies the value for EMC_BURST_REFRESH_NUM */ + u32 EmcBurstRefreshNum; + /* Specifies the value for EMC_PRE_REFRESH_REQ_CNT */ + u32 EmcPreRefreshReqCnt; + /* Specifies the value for EMC_PDEX2WR */ + u32 EmcPdEx2Wr; + /* Specifies the value for EMC_PDEX2RD */ + u32 EmcPdEx2Rd; + /* Specifies the value for EMC_PCHG2PDEN */ + u32 EmcPChg2Pden; + /* Specifies the value for EMC_ACT2PDEN */ + u32 EmcAct2Pden; + /* Specifies the value for EMC_AR2PDEN */ + u32 EmcAr2Pden; + /* Specifies the value for EMC_RW2PDEN */ + u32 EmcRw2Pden; + /* Specifies the value for EMC_CKE2PDEN */ + u32 EmcCke2Pden; + /* Specifies the value for EMC_PDEX2CKE */ + u32 EmcPdex2Cke; + /* Specifies the value for EMC_PDEX2MRR */ + u32 EmcPdex2Mrr; + /* Specifies the value for EMC_TXSR */ + u32 EmcTxsr; + /* Specifies the value for EMC_TXSRDLL */ + u32 EmcTxsrDll; + /* Specifies the value for EMC_TCKE */ + u32 EmcTcke; + /* Specifies the value for EMC_TCKESR */ + u32 EmcTckesr; + /* Specifies the value for EMC_TPD */ + u32 EmcTpd; + /* Specifies the value for EMC_TFAW */ + u32 EmcTfaw; + /* Specifies the value for EMC_TRPAB */ + u32 EmcTrpab; + /* Specifies the value for EMC_TCLKSTABLE */ + u32 EmcTClkStable; + /* Specifies the value for EMC_TCLKSTOP */ + u32 EmcTClkStop; + /* Specifies the value for EMC_TREFBW */ + u32 EmcTRefBw; + + /* FBIO configuration values */ + + /* Specifies the value for EMC_FBIO_CFG5 */ + u32 EmcFbioCfg5; + /* Specifies the value for EMC_FBIO_CFG7 */ + u32 EmcFbioCfg7; + /* Specifies the value for EMC_FBIO_CFG8 */ + u32 EmcFbioCfg8; + + /* Command mapping for CMD brick 0 */ + u32 EmcCmdMappingCmd0_0; + u32 EmcCmdMappingCmd0_1; + u32 EmcCmdMappingCmd0_2; + u32 EmcCmdMappingCmd1_0; + u32 EmcCmdMappingCmd1_1; + u32 EmcCmdMappingCmd1_2; + u32 EmcCmdMappingCmd2_0; + u32 EmcCmdMappingCmd2_1; + u32 EmcCmdMappingCmd2_2; + u32 EmcCmdMappingCmd3_0; + u32 EmcCmdMappingCmd3_1; + u32 EmcCmdMappingCmd3_2; + u32 EmcCmdMappingByte; + + /* Specifies the value for EMC_FBIO_SPARE */ + u32 EmcFbioSpare; + + /* Specifies the value for EMC_CFG_RSV */ + u32 EmcCfgRsv; + + /* MRS command values */ + + /* Specifies the value for EMC_MRS */ + u32 EmcMrs; + /* Specifies the MP0 command to initialize mode registers */ + u32 EmcEmrs; + /* Specifies the MP2 command to initialize mode registers */ + u32 EmcEmrs2; + /* Specifies the MP3 command to initialize mode registers */ + u32 EmcEmrs3; + /* Specifies the programming to LPDDR2 Mode Register 1 at cold boot */ + u32 EmcMrw1; + /* Specifies the programming to LPDDR2 Mode Register 2 at cold boot */ + u32 EmcMrw2; + /* Specifies the programming to LPDDR2 Mode Register 3 at cold boot */ + u32 EmcMrw3; + /* Specifies the programming to LPDDR2 Mode Register 11 at cold boot */ + u32 EmcMrw4; + /* Specifies the programming to LPDDR2 Mode Register 3? at cold boot */ + u32 EmcMrw6; + /* Specifies the programming to LPDDR2 Mode Register 11 at cold boot */ + u32 EmcMrw8; + /* Specifies the programming to LPDDR2 Mode Register 11? at cold boot */ + u32 EmcMrw9; + /* Specifies the programming to LPDDR2 Mode Register 12 at cold boot */ + u32 EmcMrw10; + /* Specifies the programming to LPDDR2 Mode Register 14 at cold boot */ + u32 EmcMrw12; + /* Specifies the programming to LPDDR2 Mode Register 14? at cold boot */ + u32 EmcMrw13; + /* Specifies the programming to LPDDR2 Mode Register 22 at cold boot */ + u32 EmcMrw14; + /* + * Specifies the programming to extra LPDDR2 Mode Register + * at cold boot + */ + u32 EmcMrwExtra; + /* + * Specifies the programming to extra LPDDR2 Mode Register + * at warm boot + */ + u32 EmcWarmBootMrwExtra; + /* + * Specify the enable of extra Mode Register programming at + * warm boot + */ + u32 EmcWarmBootExtraModeRegWriteEnable; + /* + * Specify the enable of extra Mode Register programming at + * cold boot + */ + u32 EmcExtraModeRegWriteEnable; + + /* Specifies the EMC_MRW reset command value */ + u32 EmcMrwResetCommand; + /* Specifies the EMC Reset wait time (in microseconds) */ + u32 EmcMrwResetNInitWait; + /* Specifies the value for EMC_MRS_WAIT_CNT */ + u32 EmcMrsWaitCnt; + /* Specifies the value for EMC_MRS_WAIT_CNT2 */ + u32 EmcMrsWaitCnt2; + + /* EMC miscellaneous configurations */ + + /* Specifies the value for EMC_CFG */ + u32 EmcCfg; + /* Specifies the value for EMC_CFG_2 */ + u32 EmcCfg2; + /* Specifies the pipe bypass controls */ + u32 EmcCfgPipe; + u32 EmcCfgPipeClk; + u32 EmcFdpdCtrlCmdNoRamp; + u32 EmcCfgUpdate; + + /* Specifies the value for EMC_DBG */ + u32 EmcDbg; + u32 EmcDbgWriteMux; + + /* Specifies the value for EMC_CMDQ */ + u32 EmcCmdQ; + /* Specifies the value for EMC_MC2EMCQ */ + u32 EmcMc2EmcQ; + /* Specifies the value for EMC_DYN_SELF_REF_CONTROL */ + u32 EmcDynSelfRefControl; + + /* Specifies the value for MEM_INIT_DONE */ + u32 AhbArbitrationXbarCtrlMemInitDone; + + /* Specifies the value for EMC_CFG_DIG_DLL */ + u32 EmcCfgDigDll; + u32 EmcCfgDigDll_1; + /* Specifies the value for EMC_CFG_DIG_DLL_PERIOD */ + u32 EmcCfgDigDllPeriod; + /* Specifies the value of *DEV_SELECTN of various EMC registers */ + u32 EmcDevSelect; + + /* Specifies the value for EMC_SEL_DPD_CTRL */ + u32 EmcSelDpdCtrl; + + /* Pads trimmer delays */ + u32 EmcFdpdCtrlDq; + u32 EmcFdpdCtrlCmd; + u32 EmcPmacroIbVrefDq_0; + u32 EmcPmacroIbVrefDq_1; + u32 EmcPmacroIbVrefDqs_0; + u32 EmcPmacroIbVrefDqs_1; + u32 EmcPmacroIbRxrt; + u32 EmcCfgPipe1; + u32 EmcCfgPipe2; + + /* Specifies the value for EMC_PMACRO_QUSE_DDLL_RANK0_0 */ + u32 EmcPmacroQuseDdllRank0_0; + u32 EmcPmacroQuseDdllRank0_1; + u32 EmcPmacroQuseDdllRank0_2; + u32 EmcPmacroQuseDdllRank0_3; + u32 EmcPmacroQuseDdllRank0_4; + u32 EmcPmacroQuseDdllRank0_5; + u32 EmcPmacroQuseDdllRank1_0; + u32 EmcPmacroQuseDdllRank1_1; + u32 EmcPmacroQuseDdllRank1_2; + u32 EmcPmacroQuseDdllRank1_3; + u32 EmcPmacroQuseDdllRank1_4; + u32 EmcPmacroQuseDdllRank1_5; + + u32 EmcPmacroObDdllLongDqRank0_0; + u32 EmcPmacroObDdllLongDqRank0_1; + u32 EmcPmacroObDdllLongDqRank0_2; + u32 EmcPmacroObDdllLongDqRank0_3; + u32 EmcPmacroObDdllLongDqRank0_4; + u32 EmcPmacroObDdllLongDqRank0_5; + u32 EmcPmacroObDdllLongDqRank1_0; + u32 EmcPmacroObDdllLongDqRank1_1; + u32 EmcPmacroObDdllLongDqRank1_2; + u32 EmcPmacroObDdllLongDqRank1_3; + u32 EmcPmacroObDdllLongDqRank1_4; + u32 EmcPmacroObDdllLongDqRank1_5; + + u32 EmcPmacroObDdllLongDqsRank0_0; + u32 EmcPmacroObDdllLongDqsRank0_1; + u32 EmcPmacroObDdllLongDqsRank0_2; + u32 EmcPmacroObDdllLongDqsRank0_3; + u32 EmcPmacroObDdllLongDqsRank0_4; + u32 EmcPmacroObDdllLongDqsRank0_5; + u32 EmcPmacroObDdllLongDqsRank1_0; + u32 EmcPmacroObDdllLongDqsRank1_1; + u32 EmcPmacroObDdllLongDqsRank1_2; + u32 EmcPmacroObDdllLongDqsRank1_3; + u32 EmcPmacroObDdllLongDqsRank1_4; + u32 EmcPmacroObDdllLongDqsRank1_5; + + u32 EmcPmacroIbDdllLongDqsRank0_0; + u32 EmcPmacroIbDdllLongDqsRank0_1; + u32 EmcPmacroIbDdllLongDqsRank0_2; + u32 EmcPmacroIbDdllLongDqsRank0_3; + u32 EmcPmacroIbDdllLongDqsRank1_0; + u32 EmcPmacroIbDdllLongDqsRank1_1; + u32 EmcPmacroIbDdllLongDqsRank1_2; + u32 EmcPmacroIbDdllLongDqsRank1_3; + + u32 EmcPmacroDdllLongCmd_0; + u32 EmcPmacroDdllLongCmd_1; + u32 EmcPmacroDdllLongCmd_2; + u32 EmcPmacroDdllLongCmd_3; + u32 EmcPmacroDdllLongCmd_4; + u32 EmcPmacroDdllShortCmd_0; + u32 EmcPmacroDdllShortCmd_1; + u32 EmcPmacroDdllShortCmd_2; + + /* + * Specifies the delay after asserting CKE pin during a WarmBoot0 + * sequence (in microseconds) + */ + u32 WarmBootWait; + + /* Specifies the value for EMC_ODT_WRITE */ + u32 EmcOdtWrite; + + /* Periodic ZQ calibration */ + + /* + * Specifies the value for EMC_ZCAL_INTERVAL + * Value 0 disables ZQ calibration + */ + u32 EmcZcalInterval; + /* Specifies the value for EMC_ZCAL_WAIT_CNT */ + u32 EmcZcalWaitCnt; + /* Specifies the value for EMC_ZCAL_MRW_CMD */ + u32 EmcZcalMrwCmd; + + /* DRAM initialization sequence flow control */ + + /* Specifies the MRS command value for resetting DLL */ + u32 EmcMrsResetDll; + /* Specifies the command for ZQ initialization of device 0 */ + u32 EmcZcalInitDev0; + /* Specifies the command for ZQ initialization of device 1 */ + u32 EmcZcalInitDev1; + /* + * Specifies the wait time after programming a ZQ initialization + * command (in microseconds) + */ + u32 EmcZcalInitWait; + /* + * Specifies the enable for ZQ calibration at cold boot [bit 0] + * and warm boot [bit 1] + */ + u32 EmcZcalWarmColdBootEnables; + + /* + * Specifies the MRW command to LPDDR2 for ZQ calibration + * on warmboot + */ + /* Is issued to both devices separately */ + u32 EmcMrwLpddr2ZcalWarmBoot; + /* + * Specifies the ZQ command to DDR3 for ZQ calibration on warmboot + * Is issued to both devices separately + */ + u32 EmcZqCalDdr3WarmBoot; + u32 EmcZqCalLpDdr4WarmBoot; + /* + * Specifies the wait time for ZQ calibration on warmboot + * (in microseconds) + */ + u32 EmcZcalWarmBootWait; + /* + * Specifies the enable for DRAM Mode Register programming + * at warm boot + */ + u32 EmcMrsWarmBootEnable; + /* + * Specifies the wait time after sending an MRS DLL reset command + * in microseconds) + */ + u32 EmcMrsResetDllWait; + /* Specifies the extra MRS command to initialize mode registers */ + u32 EmcMrsExtra; + /* Specifies the extra MRS command at warm boot */ + u32 EmcWarmBootMrsExtra; + /* Specifies the EMRS command to enable the DDR2 DLL */ + u32 EmcEmrsDdr2DllEnable; + /* Specifies the MRS command to reset the DDR2 DLL */ + u32 EmcMrsDdr2DllReset; + /* Specifies the EMRS command to set OCD calibration */ + u32 EmcEmrsDdr2OcdCalib; + /* + * Specifies the wait between initializing DDR and setting OCD + * calibration (in microseconds) + */ + u32 EmcDdr2Wait; + /* Specifies the value for EMC_CLKEN_OVERRIDE */ + u32 EmcClkenOverride; + + /* + * Specifies LOG2 of the extra refresh numbers after booting + * Program 0 to disable + */ + u32 EmcExtraRefreshNum; + /* Specifies the master override for all EMC clocks */ + u32 EmcClkenOverrideAllWarmBoot; + /* Specifies the master override for all MC clocks */ + u32 McClkenOverrideAllWarmBoot; + /* Specifies digital dll period, choosing between 4 to 64 ms */ + u32 EmcCfgDigDllPeriodWarmBoot; + + /* Pad controls */ + + /* Specifies the value for PMC_VDDP_SEL */ + u32 PmcVddpSel; + /* Specifies the wait time after programming PMC_VDDP_SEL */ + u32 PmcVddpSelWait; + /* Specifies the value for PMC_DDR_PWR */ + u32 PmcDdrPwr; + /* Specifies the value for PMC_DDR_CFG */ + u32 PmcDdrCfg; + /* Specifies the value for PMC_IO_DPD3_REQ */ + u32 PmcIoDpd3Req; + /* Specifies the wait time after programming PMC_IO_DPD3_REQ */ + u32 PmcIoDpd3ReqWait; + u32 PmcIoDpd4ReqWait; + + /* Specifies the value for PMC_REG_SHORT */ + u32 PmcRegShort; + /* Specifies the value for PMC_NO_IOPOWER */ + u32 PmcNoIoPower; + + u32 PmcDdrCntrlWait; + u32 PmcDdrCntrl; + + /* Specifies the value for EMC_ACPD_CONTROL */ + u32 EmcAcpdControl; + + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE_CFG */ + ////u32 EmcSwizzleRank0ByteCfg; + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE0 */ + u32 EmcSwizzleRank0Byte0; + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE1 */ + u32 EmcSwizzleRank0Byte1; + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE2 */ + u32 EmcSwizzleRank0Byte2; + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE3 */ + u32 EmcSwizzleRank0Byte3; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE_CFG */ + ////u32 EmcSwizzleRank1ByteCfg; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE0 */ + u32 EmcSwizzleRank1Byte0; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE1 */ + u32 EmcSwizzleRank1Byte1; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE2 */ + u32 EmcSwizzleRank1Byte2; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE3 */ + u32 EmcSwizzleRank1Byte3; + + /* Specifies the value for EMC_TXDSRVTTGEN */ + u32 EmcTxdsrvttgen; + + /* Specifies the value for EMC_DATA_BRLSHFT_0 */ + u32 EmcDataBrlshft0; + u32 EmcDataBrlshft1; + + u32 EmcDqsBrlshft0; + u32 EmcDqsBrlshft1; + + u32 EmcCmdBrlshft0; + u32 EmcCmdBrlshft1; + u32 EmcCmdBrlshft2; + u32 EmcCmdBrlshft3; + + u32 EmcQuseBrlshft0; + u32 EmcQuseBrlshft1; + u32 EmcQuseBrlshft2; + u32 EmcQuseBrlshft3; + + u32 EmcDllCfg0; + u32 EmcDllCfg1; + + u32 EmcPmcScratch1; + u32 EmcPmcScratch2; + u32 EmcPmcScratch3; + + u32 EmcPmacroPadCfgCtrl; + + u32 EmcPmacroVttgenCtrl0; + u32 EmcPmacroVttgenCtrl1; + u32 EmcPmacroVttgenCtrl2; + + u32 EmcPmacroBrickCtrlRfu1; + u32 EmcPmacroCmdBrickCtrlFdpd; + u32 EmcPmacroBrickCtrlRfu2; + u32 EmcPmacroDataBrickCtrlFdpd; + u32 EmcPmacroBgBiasCtrl0; + u32 EmcPmacroDataPadRxCtrl; + u32 EmcPmacroCmdPadRxCtrl; + u32 EmcPmacroDataRxTermMode; + u32 EmcPmacroCmdRxTermMode; + u32 EmcPmacroDataPadTxCtrl; + u32 EmcPmacroCommonPadTxCtrl; + u32 EmcPmacroCmdPadTxCtrl; + u32 EmcCfg3; + + u32 EmcPmacroTxPwrd0; + u32 EmcPmacroTxPwrd1; + u32 EmcPmacroTxPwrd2; + u32 EmcPmacroTxPwrd3; + u32 EmcPmacroTxPwrd4; + u32 EmcPmacroTxPwrd5; + + u32 EmcConfigSampleDelay; + + u32 EmcPmacroBrickMapping0; + u32 EmcPmacroBrickMapping1; + u32 EmcPmacroBrickMapping2; + + u32 EmcPmacroTxSelClkSrc0; + u32 EmcPmacroTxSelClkSrc1; + u32 EmcPmacroTxSelClkSrc2; + u32 EmcPmacroTxSelClkSrc3; + u32 EmcPmacroTxSelClkSrc4; + u32 EmcPmacroTxSelClkSrc5; + + u32 EmcPmacroDdllBypass; + + u32 EmcPmacroDdllPwrd0; + u32 EmcPmacroDdllPwrd1; + u32 EmcPmacroDdllPwrd2; + + u32 EmcPmacroCmdCtrl0; + u32 EmcPmacroCmdCtrl1; + u32 EmcPmacroCmdCtrl2; + + /* DRAM size information */ + + /* Specifies the value for MC_EMEM_ADR_CFG */ + u32 McEmemAdrCfg; + /* Specifies the value for MC_EMEM_ADR_CFG_DEV0 */ + u32 McEmemAdrCfgDev0; + /* Specifies the value for MC_EMEM_ADR_CFG_DEV1 */ + u32 McEmemAdrCfgDev1; + u32 McEmemAdrCfgChannelMask; + + /* Specifies the value for MC_EMEM_BANK_SWIZZLECfg0 */ + u32 McEmemAdrCfgBankMask0; + /* Specifies the value for MC_EMEM_BANK_SWIZZLE_CFG1 */ + u32 McEmemAdrCfgBankMask1; + /* Specifies the value for MC_EMEM_BANK_SWIZZLE_CFG2 */ + u32 McEmemAdrCfgBankMask2; + + /* + * Specifies the value for MC_EMEM_CFG which holds the external memory + * size (in KBytes) + */ + u32 McEmemCfg; + + /* MC arbitration configuration */ + + /* Specifies the value for MC_EMEM_ARB_CFG */ + u32 McEmemArbCfg; + /* Specifies the value for MC_EMEM_ARB_OUTSTANDING_REQ */ + u32 McEmemArbOutstandingReq; + + u32 McEmemArbRefpbHpCtrl; + u32 McEmemArbRefpbBankCtrl; + + /* Specifies the value for MC_EMEM_ARB_TIMING_RCD */ + u32 McEmemArbTimingRcd; + /* Specifies the value for MC_EMEM_ARB_TIMING_RP */ + u32 McEmemArbTimingRp; + /* Specifies the value for MC_EMEM_ARB_TIMING_RC */ + u32 McEmemArbTimingRc; + /* Specifies the value for MC_EMEM_ARB_TIMING_RAS */ + u32 McEmemArbTimingRas; + /* Specifies the value for MC_EMEM_ARB_TIMING_FAW */ + u32 McEmemArbTimingFaw; + /* Specifies the value for MC_EMEM_ARB_TIMING_RRD */ + u32 McEmemArbTimingRrd; + /* Specifies the value for MC_EMEM_ARB_TIMING_RAP2PRE */ + u32 McEmemArbTimingRap2Pre; + /* Specifies the value for MC_EMEM_ARB_TIMING_WAP2PRE */ + u32 McEmemArbTimingWap2Pre; + /* Specifies the value for MC_EMEM_ARB_TIMING_R2R */ + u32 McEmemArbTimingR2R; + /* Specifies the value for MC_EMEM_ARB_TIMING_W2W */ + u32 McEmemArbTimingW2W; + /* Specifies the value for MC_EMEM_ARB_TIMING_R2W */ + u32 McEmemArbTimingR2W; + /* Specifies the value for MC_EMEM_ARB_TIMING_W2R */ + u32 McEmemArbTimingW2R; + + u32 McEmemArbTimingRFCPB; + + /* Specifies the value for MC_EMEM_ARB_DA_TURNS */ + u32 McEmemArbDaTurns; + /* Specifies the value for MC_EMEM_ARB_DA_COVERS */ + u32 McEmemArbDaCovers; + /* Specifies the value for MC_EMEM_ARB_MISC0 */ + u32 McEmemArbMisc0; + /* Specifies the value for MC_EMEM_ARB_MISC1 */ + u32 McEmemArbMisc1; + u32 McEmemArbMisc2; + + /* Specifies the value for MC_EMEM_ARB_RING1_THROTTLE */ + u32 McEmemArbRing1Throttle; + /* Specifies the value for MC_EMEM_ARB_OVERRIDE */ + u32 McEmemArbOverride; + /* Specifies the value for MC_EMEM_ARB_OVERRIDE_1 */ + u32 McEmemArbOverride1; + /* Specifies the value for MC_EMEM_ARB_RSV */ + u32 McEmemArbRsv; + + u32 McDaCfg0; + u32 McEmemArbTimingCcdmw; + + /* Specifies the value for MC_CLKEN_OVERRIDE */ + u32 McClkenOverride; + + /* Specifies the value for MC_STAT_CONTROL */ + u32 McStatControl; + + /* Specifies the value for MC_VIDEO_PROTECT_BOM */ + u32 McVideoProtectBom; + /* Specifies the value for MC_VIDEO_PROTECT_BOM_ADR_HI */ + u32 McVideoProtectBomAdrHi; + /* Specifies the value for MC_VIDEO_PROTECT_SIZE_MB */ + u32 McVideoProtectSizeMb; + /* Specifies the value for MC_VIDEO_PROTECT_VPR_OVERRIDE */ + u32 McVideoProtectVprOverride; + /* Specifies the value for MC_VIDEO_PROTECT_VPR_OVERRIDE1 */ + u32 McVideoProtectVprOverride1; + /* Specifies the value for MC_VIDEO_PROTECT_GPU_OVERRIDE_0 */ + u32 McVideoProtectGpuOverride0; + /* Specifies the value for MC_VIDEO_PROTECT_GPU_OVERRIDE_1 */ + u32 McVideoProtectGpuOverride1; + /* Specifies the value for MC_SEC_CARVEOUT_BOM */ + u32 McSecCarveoutBom; + /* Specifies the value for MC_SEC_CARVEOUT_ADR_HI */ + u32 McSecCarveoutAdrHi; + /* Specifies the value for MC_SEC_CARVEOUT_SIZE_MB */ + u32 McSecCarveoutSizeMb; + /* Specifies the value for MC_VIDEO_PROTECT_REG_CTRL. + VIDEO_PROTECT_WRITEAccess */ + u32 McVideoProtectWriteAccess; + /* Specifies the value for MC_SEC_CARVEOUT_REG_CTRL. + SEC_CARVEOUT_WRITEAccess */ + u32 McSecCarveoutProtectWriteAccess; + + /* Write-Protect Regions (WPR) */ + u32 McGeneralizedCarveout1Bom; + u32 McGeneralizedCarveout1BomHi; + u32 McGeneralizedCarveout1Size128kb; + u32 McGeneralizedCarveout1Access0; + u32 McGeneralizedCarveout1Access1; + u32 McGeneralizedCarveout1Access2; + u32 McGeneralizedCarveout1Access3; + u32 McGeneralizedCarveout1Access4; + u32 McGeneralizedCarveout1ForceInternalAccess0; + u32 McGeneralizedCarveout1ForceInternalAccess1; + u32 McGeneralizedCarveout1ForceInternalAccess2; + u32 McGeneralizedCarveout1ForceInternalAccess3; + u32 McGeneralizedCarveout1ForceInternalAccess4; + u32 McGeneralizedCarveout1Cfg0; + + u32 McGeneralizedCarveout2Bom; + u32 McGeneralizedCarveout2BomHi; + u32 McGeneralizedCarveout2Size128kb; + u32 McGeneralizedCarveout2Access0; + u32 McGeneralizedCarveout2Access1; + u32 McGeneralizedCarveout2Access2; + u32 McGeneralizedCarveout2Access3; + u32 McGeneralizedCarveout2Access4; + u32 McGeneralizedCarveout2ForceInternalAccess0; + u32 McGeneralizedCarveout2ForceInternalAccess1; + u32 McGeneralizedCarveout2ForceInternalAccess2; + u32 McGeneralizedCarveout2ForceInternalAccess3; + u32 McGeneralizedCarveout2ForceInternalAccess4; + u32 McGeneralizedCarveout2Cfg0; + + u32 McGeneralizedCarveout3Bom; + u32 McGeneralizedCarveout3BomHi; + u32 McGeneralizedCarveout3Size128kb; + u32 McGeneralizedCarveout3Access0; + u32 McGeneralizedCarveout3Access1; + u32 McGeneralizedCarveout3Access2; + u32 McGeneralizedCarveout3Access3; + u32 McGeneralizedCarveout3Access4; + u32 McGeneralizedCarveout3ForceInternalAccess0; + u32 McGeneralizedCarveout3ForceInternalAccess1; + u32 McGeneralizedCarveout3ForceInternalAccess2; + u32 McGeneralizedCarveout3ForceInternalAccess3; + u32 McGeneralizedCarveout3ForceInternalAccess4; + u32 McGeneralizedCarveout3Cfg0; + + u32 McGeneralizedCarveout4Bom; + u32 McGeneralizedCarveout4BomHi; + u32 McGeneralizedCarveout4Size128kb; + u32 McGeneralizedCarveout4Access0; + u32 McGeneralizedCarveout4Access1; + u32 McGeneralizedCarveout4Access2; + u32 McGeneralizedCarveout4Access3; + u32 McGeneralizedCarveout4Access4; + u32 McGeneralizedCarveout4ForceInternalAccess0; + u32 McGeneralizedCarveout4ForceInternalAccess1; + u32 McGeneralizedCarveout4ForceInternalAccess2; + u32 McGeneralizedCarveout4ForceInternalAccess3; + u32 McGeneralizedCarveout4ForceInternalAccess4; + u32 McGeneralizedCarveout4Cfg0; + + u32 McGeneralizedCarveout5Bom; + u32 McGeneralizedCarveout5BomHi; + u32 McGeneralizedCarveout5Size128kb; + u32 McGeneralizedCarveout5Access0; + u32 McGeneralizedCarveout5Access1; + u32 McGeneralizedCarveout5Access2; + u32 McGeneralizedCarveout5Access3; + u32 McGeneralizedCarveout5Access4; + u32 McGeneralizedCarveout5ForceInternalAccess0; + u32 McGeneralizedCarveout5ForceInternalAccess1; + u32 McGeneralizedCarveout5ForceInternalAccess2; + u32 McGeneralizedCarveout5ForceInternalAccess3; + u32 McGeneralizedCarveout5ForceInternalAccess4; + u32 McGeneralizedCarveout5Cfg0; + + /* Specifies enable for CA training */ + u32 EmcCaTrainingEnable; + + /* Set if bit 6 select is greater than bit 7 select; uses aremc. + spec packet SWIZZLE_BIT6_GT_BIT7 */ + u32 SwizzleRankByteEncode; + /* Specifies enable and offset for patched boot ROM write */ + u32 BootRomPatchControl; + /* Specifies data for patched boot ROM write */ + u32 BootRomPatchData; + + /* Specifies the value for MC_MTS_CARVEOUT_BOM */ + u32 McMtsCarveoutBom; + /* Specifies the value for MC_MTS_CARVEOUT_ADR_HI */ + u32 McMtsCarveoutAdrHi; + /* Specifies the value for MC_MTS_CARVEOUT_SIZE_MB */ + u32 McMtsCarveoutSizeMb; + /* Specifies the value for MC_MTS_CARVEOUT_REG_CTRL */ + u32 McMtsCarveoutRegCtrl; + + /* End */ +}; + +#endif /* __SOC_NVIDIA_TEGRA210_SDRAM_PARAM_H__ */ diff --git a/nyx/nyx_gui/mem/sdram_param_t210.h b/nyx/nyx_gui/mem/sdram_param_t210.h new file mode 100644 index 0000000..d926fa4 --- /dev/null +++ b/nyx/nyx_gui/mem/sdram_param_t210.h @@ -0,0 +1,931 @@ +/* + * Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * See file CREDITS for list of people who contributed to this + * project. + */ + +/** + * Defines the SDRAM parameter structure. + * + * Note that PLLM is used by EMC. + */ + +#ifndef _SDRAM_PARAM_T210_H_ +#define _SDRAM_PARAM_T210_H_ + +#define MEMORY_TYPE_NONE 0 +#define MEMORY_TYPE_DDR 0 +#define MEMORY_TYPE_LPDDR 0 +#define MEMORY_TYPE_DDR2 0 +#define MEMORY_TYPE_LPDDR2 1 +#define MEMORY_TYPE_DDR3 2 +#define MEMORY_TYPE_LPDDR4 3 + +/** + * Defines the SDRAM parameter structure + */ +typedef struct _sdram_params +{ + /* Specifies the type of memory device */ + u32 memory_type; + + /* MC/EMC clock source configuration */ + + /* Specifies the M value for PllM */ + u32 pllm_input_divider; + /* Specifies the N value for PllM */ + u32 pllm_feedback_divider; + /* Specifies the time to wait for PLLM to lock (in microseconds) */ + u32 pllm_stable_time; + /* Specifies misc. control bits */ + u32 pllm_setup_control; + /* Specifies the P value for PLLM */ + u32 pllm_post_divider; + /* Specifies value for Charge Pump Gain Control */ + u32 pllm_kcp; + /* Specifies VCO gain */ + u32 pllm_kvco; + /* Spare BCT param */ + u32 emc_bct_spare0; + /* Spare BCT param */ + u32 emc_bct_spare1; + /* Spare BCT param */ + u32 emc_bct_spare2; + /* Spare BCT param */ + u32 emc_bct_spare3; + /* Spare BCT param */ + u32 emc_bct_spare4; + /* Spare BCT param */ + u32 emc_bct_spare5; + /* Spare BCT param */ + u32 emc_bct_spare6; + /* Spare BCT param */ + u32 emc_bct_spare7; + /* Spare BCT param */ + u32 emc_bct_spare8; + /* Spare BCT param */ + u32 emc_bct_spare9; + /* Spare BCT param */ + u32 emc_bct_spare10; + /* Spare BCT param */ + u32 emc_bct_spare11; + /* Spare BCT param */ + u32 emc_bct_spare12; + /* Spare BCT param */ + u32 emc_bct_spare13; + + /* Defines EMC_2X_CLK_SRC, EMC_2X_CLK_DIVISOR, EMC_INVERT_DCD */ + u32 emc_clock_source; + u32 emc_clock_source_dll; + + /* Defines possible override for PLLLM_MISC2 */ + u32 clk_rst_pllm_misc20_override; + /* enables override for PLLLM_MISC2 */ + u32 clk_rst_pllm_misc20_override_enable; + /* defines CLK_ENB_MC1 in register clk_rst_controller_clk_enb_w_clr */ + u32 clear_clock2_mc1; + + /* Auto-calibration of EMC pads */ + + /* Specifies the value for EMC_AUTO_CAL_INTERVAL */ + u32 emc_auto_cal_interval; + /* + * Specifies the value for EMC_AUTO_CAL_CONFIG + * Note: Trigger bits are set by the SDRAM code. + */ + u32 emc_auto_cal_config; + + /* Specifies the value for EMC_AUTO_CAL_CONFIG2 */ + u32 emc_auto_cal_config2; + + /* Specifies the value for EMC_AUTO_CAL_CONFIG3 */ + u32 emc_auto_cal_config3; + + u32 emc_auto_cal_config4; + u32 emc_auto_cal_config5; + u32 emc_auto_cal_config6; + u32 emc_auto_cal_config7; + u32 emc_auto_cal_config8; + /* Specifies the value for EMC_AUTO_CAL_VREF_SEL_0 */ + u32 emc_auto_cal_vref_sel0; + u32 emc_auto_cal_vref_sel1; + + /* Specifies the value for EMC_AUTO_CAL_CHANNEL */ + u32 emc_auto_cal_channel; + + /* Specifies the value for EMC_PMACRO_AUTOCAL_CFG_0 */ + u32 emc_pmacro_auto_cal_cfg0; + u32 emc_pmacro_auto_cal_cfg1; + u32 emc_pmacro_auto_cal_cfg2; + + u32 emc_pmacro_rx_term; + u32 emc_pmacro_dq_tx_drive; + u32 emc_pmacro_ca_tx_drive; + u32 emc_pmacro_cmd_tx_drive; + u32 emc_pmacro_auto_cal_common; + u32 emc_pmacro_zcrtl; + + /* + * Specifies the time for the calibration + * to stabilize (in microseconds) + */ + u32 emc_auto_cal_wait; + + u32 emc_xm2_comp_pad_ctrl; + u32 emc_xm2_comp_pad_ctrl2; + u32 emc_xm2_comp_pad_ctrl3; + + /* + * DRAM size information + * Specifies the value for EMC_ADR_CFG + */ + u32 emc_adr_cfg; + + /* + * Specifies the time to wait after asserting pin + * CKE (in microseconds) + */ + u32 emc_pin_program_wait; + /* Specifies the extra delay before/after pin RESET/CKE command */ + u32 emc_pin_extra_wait; + + u32 emc_pin_gpio_enable; + u32 emc_pin_gpio; + + /* + * Specifies the extra delay after the first writing + * of EMC_TIMING_CONTROL + */ + u32 emc_timing_control_wait; + + /* Timing parameters required for the SDRAM */ + + /* Specifies the value for EMC_RC */ + u32 emc_rc; + /* Specifies the value for EMC_RFC */ + u32 emc_rfc; + + u32 emc_rfc_pb; + u32 emc_ref_ctrl2; + + /* Specifies the value for EMC_RFC_SLR */ + u32 emc_rfc_slr; + /* Specifies the value for EMC_RAS */ + u32 emc_ras; + /* Specifies the value for EMC_RP */ + u32 emc_rp; + /* Specifies the value for EMC_R2R */ + u32 emc_r2r; + /* Specifies the value for EMC_W2W */ + u32 emc_w2w; + /* Specifies the value for EMC_R2W */ + u32 emc_r2w; + /* Specifies the value for EMC_W2R */ + u32 emc_w2r; + /* Specifies the value for EMC_R2P */ + u32 emc_r2p; + /* Specifies the value for EMC_W2P */ + u32 emc_w2p; + /* Specifies the value for EMC_RD_RCD */ + + u32 emc_tppd; + u32 emc_ccdmw; + + u32 emc_rd_rcd; + /* Specifies the value for EMC_WR_RCD */ + u32 emc_wr_rcd; + /* Specifies the value for EMC_RRD */ + u32 emc_rrd; + /* Specifies the value for EMC_REXT */ + u32 emc_rext; + /* Specifies the value for EMC_WEXT */ + u32 emc_wext; + /* Specifies the value for EMC_WDV */ + u32 emc_wdv; + + u32 emc_wdv_chk; + u32 emc_wsv; + u32 emc_wev; + + /* Specifies the value for EMC_WDV_MASK */ + u32 emc_wdv_mask; + + u32 emc_ws_duration; + u32 emc_we_duration; + + /* Specifies the value for EMC_QUSE */ + u32 emc_quse; + /* Specifies the value for EMC_QUSE_WIDTH */ + u32 emc_quse_width; + /* Specifies the value for EMC_IBDLY */ + u32 emc_ibdly; + + u32 emc_obdly; + + /* Specifies the value for EMC_EINPUT */ + u32 emc_einput; + /* Specifies the value for EMC_EINPUT_DURATION */ + u32 emc_einput_duration; + /* Specifies the value for EMC_PUTERM_EXTRA */ + u32 emc_puterm_extra; + /* Specifies the value for EMC_PUTERM_WIDTH */ + u32 emc_puterm_width; + + u32 emc_qrst; + u32 emc_qsafe; + u32 emc_rdv; + u32 emc_rdv_mask; + + u32 emc_rdv_early; + u32 emc_rdv_early_mask; + + /* Specifies the value for EMC_QPOP */ + u32 emc_qpop; + + /* Specifies the value for EMC_REFRESH */ + u32 emc_refresh; + /* Specifies the value for EMC_BURST_REFRESH_NUM */ + u32 emc_burst_refresh_num; + /* Specifies the value for EMC_PRE_REFRESH_REQ_CNT */ + u32 emc_prerefresh_req_cnt; + /* Specifies the value for EMC_PDEX2WR */ + u32 emc_pdex2wr; + /* Specifies the value for EMC_PDEX2RD */ + u32 emc_pdex2rd; + /* Specifies the value for EMC_PCHG2PDEN */ + u32 emc_pchg2pden; + /* Specifies the value for EMC_ACT2PDEN */ + u32 emc_act2pden; + /* Specifies the value for EMC_AR2PDEN */ + u32 emc_ar2pden; + /* Specifies the value for EMC_RW2PDEN */ + u32 emc_rw2pden; + + u32 emc_cke2pden; + u32 emc_pdex2che; + u32 emc_pdex2mrr; + + /* Specifies the value for EMC_TXSR */ + u32 emc_txsr; + /* Specifies the value for EMC_TXSRDLL */ + u32 emc_txsr_dll; + /* Specifies the value for EMC_TCKE */ + u32 emc_tcke; + /* Specifies the value for EMC_TCKESR */ + u32 emc_tckesr; + /* Specifies the value for EMC_TPD */ + u32 emc_tpd; + /* Specifies the value for EMC_TFAW */ + u32 emc_tfaw; + /* Specifies the value for EMC_TRPAB */ + u32 emc_trpab; + /* Specifies the value for EMC_TCLKSTABLE */ + u32 emc_tclkstable; + /* Specifies the value for EMC_TCLKSTOP */ + u32 emc_tclkstop; + /* Specifies the value for EMC_TREFBW */ + u32 emc_trefbw; + + /* FBIO configuration values */ + + /* Specifies the value for EMC_FBIO_CFG5 */ + u32 emc_fbio_cfg5; + /* Specifies the value for EMC_FBIO_CFG7 */ + u32 emc_fbio_cfg7; + u32 emc_fbio_cfg8; + + /* Command mapping for CMD brick 0 */ + u32 emc_cmd_mapping_cmd0_0; + u32 emc_cmd_mapping_cmd0_1; + u32 emc_cmd_mapping_cmd0_2; + u32 emc_cmd_mapping_cmd1_0; + u32 emc_cmd_mapping_cmd1_1; + u32 emc_cmd_mapping_cmd1_2; + u32 emc_cmd_mapping_cmd2_0; + u32 emc_cmd_mapping_cmd2_1; + u32 emc_cmd_mapping_cmd2_2; + u32 emc_cmd_mapping_cmd3_0; + u32 emc_cmd_mapping_cmd3_1; + u32 emc_cmd_mapping_cmd3_2; + u32 emc_cmd_mapping_byte; + + /* Specifies the value for EMC_FBIO_SPARE */ + u32 emc_fbio_spare; + + /* Specifies the value for EMC_CFG_RSV */ + u32 emc_cfg_rsv; + + /* MRS command values */ + + /* Specifies the value for EMC_MRS */ + u32 emc_mrs; + /* Specifies the MP0 command to initialize mode registers */ + u32 emc_emrs; + /* Specifies the MP2 command to initialize mode registers */ + u32 emc_emrs2; + /* Specifies the MP3 command to initialize mode registers */ + u32 emc_emrs3; + /* Specifies the programming to LPDDR2 Mode Register 1 at cold boot */ + u32 emc_mrw1; + /* Specifies the programming to LPDDR2 Mode Register 2 at cold boot */ + u32 emc_mrw2; + /* Specifies the programming to LPDDR2 Mode Register 3 at cold boot */ + u32 emc_mrw3; + /* Specifies the programming to LPDDR2 Mode Register 11 at cold boot */ + u32 emc_mrw4; + + /* Specifies the programming to LPDDR4 Mode Register 3 at cold boot */ + u32 emc_mrw6; + /* Specifies the programming to LPDDR4 Mode Register 11 at cold boot */ + u32 emc_mrw8; + /* Specifies the programming to LPDDR4 Mode Register 11 at cold boot */ + u32 emc_mrw9; + /* Specifies the programming to LPDDR4 Mode Register 12 at cold boot */ + u32 emc_mrw10; + /* Specifies the programming to LPDDR4 Mode Register 14 at cold boot */ + u32 emc_mrw12; + /* Specifies the programming to LPDDR4 Mode Register 14 at cold boot */ + u32 emc_mrw13; + /* Specifies the programming to LPDDR4 Mode Register 22 at cold boot */ + u32 emc_mrw14; + + /* + * Specifies the programming to extra LPDDR2 Mode Register + * at cold boot + */ + u32 emc_mrw_extra; + /* + * Specifies the programming to extra LPDDR2 Mode Register + * at warm boot + */ + u32 emc_warm_boot_mrw_extra; + /* + * Specify the enable of extra Mode Register programming at + * warm boot + */ + u32 emc_warm_boot_extramode_reg_write_enable; + /* + * Specify the enable of extra Mode Register programming at + * cold boot + */ + u32 emc_extramode_reg_write_enable; + + /* Specifies the EMC_MRW reset command value */ + u32 emc_mrw_reset_command; + /* Specifies the EMC Reset wait time (in microseconds) */ + u32 emc_mrw_reset_ninit_wait; + /* Specifies the value for EMC_MRS_WAIT_CNT */ + u32 emc_mrs_wait_cnt; + /* Specifies the value for EMC_MRS_WAIT_CNT2 */ + u32 emc_mrs_wait_cnt2; + + /* EMC miscellaneous configurations */ + + /* Specifies the value for EMC_CFG */ + u32 emc_cfg; + /* Specifies the value for EMC_CFG_2 */ + u32 emc_cfg2; + /* Specifies the pipe bypass controls */ + u32 emc_cfg_pipe; + + u32 emc_cfg_pipe_clk; + u32 emc_fdpd_ctrl_cmd_no_ramp; + u32 emc_cfg_update; + + /* Specifies the value for EMC_DBG */ + u32 emc_dbg; + + u32 emc_dbg_write_mux; + + /* Specifies the value for EMC_CMDQ */ + u32 emc_cmd_q; + /* Specifies the value for EMC_MC2EMCQ */ + u32 emc_mc2emc_q; + /* Specifies the value for EMC_DYN_SELF_REF_CONTROL */ + u32 emc_dyn_self_ref_control; + + /* Specifies the value for MEM_INIT_DONE */ + u32 ahb_arbitration_xbar_ctrl_meminit_done; + + /* Specifies the value for EMC_CFG_DIG_DLL */ + u32 emc_cfg_dig_dll; + u32 emc_cfg_dig_dll_1; + + /* Specifies the value for EMC_CFG_DIG_DLL_PERIOD */ + u32 emc_cfg_dig_dll_period; + /* Specifies the value of *DEV_SELECTN of various EMC registers */ + u32 emc_dev_select; + + /* Specifies the value for EMC_SEL_DPD_CTRL */ + u32 emc_sel_dpd_ctrl; + + /* Pads trimmer delays */ + u32 emc_fdpd_ctrl_dq; + u32 emc_fdpd_ctrl_cmd; + u32 emc_pmacro_ib_vref_dq_0; + u32 emc_pmacro_ib_vref_dq_1; + u32 emc_pmacro_ib_vref_dqs_0; + u32 emc_pmacro_ib_vref_dqs_1; + u32 emc_pmacro_ib_rxrt; + u32 emc_cfg_pipe1; + u32 emc_cfg_pipe2; + + /* Specifies the value for EMC_PMACRO_QUSE_DDLL_RANK0_0 */ + u32 emc_pmacro_quse_ddll_rank0_0; + u32 emc_pmacro_quse_ddll_rank0_1; + u32 emc_pmacro_quse_ddll_rank0_2; + u32 emc_pmacro_quse_ddll_rank0_3; + u32 emc_pmacro_quse_ddll_rank0_4; + u32 emc_pmacro_quse_ddll_rank0_5; + u32 emc_pmacro_quse_ddll_rank1_0; + u32 emc_pmacro_quse_ddll_rank1_1; + u32 emc_pmacro_quse_ddll_rank1_2; + u32 emc_pmacro_quse_ddll_rank1_3; + u32 emc_pmacro_quse_ddll_rank1_4; + u32 emc_pmacro_quse_ddll_rank1_5; + + u32 emc_pmacro_ob_ddll_long_dq_rank0_0; + u32 emc_pmacro_ob_ddll_long_dq_rank0_1; + u32 emc_pmacro_ob_ddll_long_dq_rank0_2; + u32 emc_pmacro_ob_ddll_long_dq_rank0_3; + u32 emc_pmacro_ob_ddll_long_dq_rank0_4; + u32 emc_pmacro_ob_ddll_long_dq_rank0_5; + u32 emc_pmacro_ob_ddll_long_dq_rank1_0; + u32 emc_pmacro_ob_ddll_long_dq_rank1_1; + u32 emc_pmacro_ob_ddll_long_dq_rank1_2; + u32 emc_pmacro_ob_ddll_long_dq_rank1_3; + u32 emc_pmacro_ob_ddll_long_dq_rank1_4; + u32 emc_pmacro_ob_ddll_long_dq_rank1_5; + + u32 emc_pmacro_ob_ddll_long_dqs_rank0_0; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_1; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_2; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_3; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_4; + u32 emc_pmacro_ob_ddll_long_dqs_rank0_5; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_0; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_1; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_2; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_3; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_4; + u32 emc_pmacro_ob_ddll_long_dqs_rank1_5; + + u32 emc_pmacro_ib_ddll_long_dqs_rank0_0; + u32 emc_pmacro_ib_ddll_long_dqs_rank0_1; + u32 emc_pmacro_ib_ddll_long_dqs_rank0_2; + u32 emc_pmacro_ib_ddll_long_dqs_rank0_3; + u32 emc_pmacro_ib_ddll_long_dqs_rank1_0; + u32 emc_pmacro_ib_ddll_long_dqs_rank1_1; + u32 emc_pmacro_ib_ddll_long_dqs_rank1_2; + u32 emc_pmacro_ib_ddll_long_dqs_rank1_3; + + u32 emc_pmacro_ddll_long_cmd_0; + u32 emc_pmacro_ddll_long_cmd_1; + u32 emc_pmacro_ddll_long_cmd_2; + u32 emc_pmacro_ddll_long_cmd_3; + u32 emc_pmacro_ddll_long_cmd_4; + u32 emc_pmacro_ddll_short_cmd_0; + u32 emc_pmacro_ddll_short_cmd_1; + u32 emc_pmacro_ddll_short_cmd_2; + + /* + * Specifies the delay after asserting CKE pin during a WarmBoot0 + * sequence (in microseconds) + */ + u32 warm_boot_wait; + + /* Specifies the value for EMC_ODT_WRITE */ + u32 emc_odt_write; + + /* Periodic ZQ calibration */ + + /* + * Specifies the value for EMC_ZCAL_INTERVAL + * Value 0 disables ZQ calibration + */ + u32 emc_zcal_interval; + /* Specifies the value for EMC_ZCAL_WAIT_CNT */ + u32 emc_zcal_wait_cnt; + /* Specifies the value for EMC_ZCAL_MRW_CMD */ + u32 emc_zcal_mrw_cmd; + + /* DRAM initialization sequence flow control */ + + /* Specifies the MRS command value for resetting DLL */ + u32 emc_mrs_reset_dll; + /* Specifies the command for ZQ initialization of device 0 */ + u32 emc_zcal_init_dev0; + /* Specifies the command for ZQ initialization of device 1 */ + u32 emc_zcal_init_dev1; + /* + * Specifies the wait time after programming a ZQ initialization + * command (in microseconds) + */ + u32 emc_zcal_init_wait; + /* + * Specifies the enable for ZQ calibration at cold boot [bit 0] + * and warm boot [bit 1] + */ + u32 emc_zcal_warm_cold_boot_enables; + + /* + * Specifies the MRW command to LPDDR2 for ZQ calibration + * on warmboot + */ + /* Is issued to both devices separately */ + u32 emc_mrw_lpddr2zcal_warm_boot; + /* + * Specifies the ZQ command to DDR3 for ZQ calibration on warmboot + * Is issued to both devices separately + */ + u32 emc_zqcal_ddr3_warm_boot; + + u32 emc_zqcal_lpddr4_warm_boot; + + /* + * Specifies the wait time for ZQ calibration on warmboot + * (in microseconds) + */ + u32 emc_zcal_warm_boot_wait; + /* + * Specifies the enable for DRAM Mode Register programming + * at warm boot + */ + u32 emc_mrs_warm_boot_enable; + /* + * Specifies the wait time after sending an MRS DLL reset command + * in microseconds) + */ + u32 emc_mrs_reset_dll_wait; + /* Specifies the extra MRS command to initialize mode registers */ + u32 emc_mrs_extra; + /* Specifies the extra MRS command at warm boot */ + u32 emc_warm_boot_mrs_extra; + /* Specifies the EMRS command to enable the DDR2 DLL */ + u32 emc_emrs_ddr2_dll_enable; + /* Specifies the MRS command to reset the DDR2 DLL */ + u32 emc_mrs_ddr2_dll_reset; + /* Specifies the EMRS command to set OCD calibration */ + u32 emc_emrs_ddr2_ocd_calib; + /* + * Specifies the wait between initializing DDR and setting OCD + * calibration (in microseconds) + */ + u32 emc_ddr2_wait; + /* Specifies the value for EMC_CLKEN_OVERRIDE */ + u32 emc_clken_override; + /* + * Specifies LOG2 of the extra refresh numbers after booting + * Program 0 to disable + */ + u32 emc_extra_refresh_num; + /* Specifies the master override for all EMC clocks */ + u32 emc_clken_override_allwarm_boot; + /* Specifies the master override for all MC clocks */ + u32 mc_clken_override_allwarm_boot; + /* Specifies digital dll period, choosing between 4 to 64 ms */ + u32 emc_cfg_dig_dll_period_warm_boot; + + /* Pad controls */ + + /* Specifies the value for PMC_VDDP_SEL */ + u32 pmc_vddp_sel; + /* Specifies the wait time after programming PMC_VDDP_SEL */ + u32 pmc_vddp_sel_wait; + /* Specifies the value for PMC_DDR_PWR */ + u32 pmc_ddr_pwr; + /* Specifies the value for PMC_DDR_CFG */ + u32 pmc_ddr_cfg; + /* Specifies the value for PMC_IO_DPD3_REQ */ + u32 pmc_io_dpd3_req; + /* Specifies the wait time after programming PMC_IO_DPD3_REQ */ + u32 pmc_io_dpd3_req_wait; + + u32 pmc_io_dpd4_req_wait; + + /* Specifies the value for PMC_REG_SHORT */ + u32 pmc_reg_short; + /* Specifies the value for PMC_NO_IOPOWER */ + u32 pmc_no_io_power; + + u32 pmc_ddr_ctrl_wait; + u32 pmc_ddr_ctrl; + + /* Specifies the value for EMC_ACPD_CONTROL */ + u32 emc_acpd_control; + + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE0 */ + u32 emc_swizzle_rank0_byte0; + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE1 */ + u32 emc_swizzle_rank0_byte1; + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE2 */ + u32 emc_swizzle_rank0_byte2; + /* Specifies the value for EMC_SWIZZLE_RANK0_BYTE3 */ + u32 emc_swizzle_rank0_byte3; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE0 */ + u32 emc_swizzle_rank1_byte0; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE1 */ + u32 emc_swizzle_rank1_byte1; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE2 */ + u32 emc_swizzle_rank1_byte2; + /* Specifies the value for EMC_SWIZZLE_RANK1_BYTE3 */ + u32 emc_swizzle_rank1_byte3; + + /* Specifies the value for EMC_TXDSRVTTGEN */ + u32 emc_txdsrvttgen; + + /* Specifies the value for EMC_DATA_BRLSHFT_0 */ + u32 emc_data_brlshft0; + u32 emc_data_brlshft1; + + u32 emc_dqs_brlshft0; + u32 emc_dqs_brlshft1; + + u32 emc_cmd_brlshft0; + u32 emc_cmd_brlshft1; + u32 emc_cmd_brlshft2; + u32 emc_cmd_brlshft3; + + u32 emc_quse_brlshft0; + u32 emc_quse_brlshft1; + u32 emc_quse_brlshft2; + u32 emc_quse_brlshft3; + + u32 emc_dll_cfg0; + u32 emc_dll_cfg1; + + u32 emc_pmc_scratch1; + u32 emc_pmc_scratch2; + u32 emc_pmc_scratch3; + + u32 emc_pmacro_pad_cfg_ctrl; + + u32 emc_pmacro_vttgen_ctrl0; + u32 emc_pmacro_vttgen_ctrl1; + u32 emc_pmacro_vttgen_ctrl2; + + u32 emc_pmacro_brick_ctrl_rfu1; + u32 emc_pmacro_cmd_brick_ctrl_fdpd; + u32 emc_pmacro_brick_ctrl_rfu2; + u32 emc_pmacro_data_brick_ctrl_fdpd; + u32 emc_pmacro_bg_bias_ctrl0; + u32 emc_pmacro_data_pad_rx_ctrl; + u32 emc_pmacro_cmd_pad_rx_ctrl; + u32 emc_pmacro_data_rx_term_mode; + u32 emc_pmacro_cmd_rx_term_mode; + u32 emc_pmacro_data_pad_tx_ctrl; + u32 emc_pmacro_common_pad_tx_ctrl; + u32 emc_pmacro_cmd_pad_tx_ctrl; + u32 emc_cfg3; + + u32 emc_pmacro_tx_pwrd0; + u32 emc_pmacro_tx_pwrd1; + u32 emc_pmacro_tx_pwrd2; + u32 emc_pmacro_tx_pwrd3; + u32 emc_pmacro_tx_pwrd4; + u32 emc_pmacro_tx_pwrd5; + + u32 emc_config_sample_delay; + + u32 emc_pmacro_brick_mapping0; + u32 emc_pmacro_brick_mapping1; + u32 emc_pmacro_brick_mapping2; + + u32 emc_pmacro_tx_sel_clk_src0; + u32 emc_pmacro_tx_sel_clk_src1; + u32 emc_pmacro_tx_sel_clk_src2; + u32 emc_pmacro_tx_sel_clk_src3; + u32 emc_pmacro_tx_sel_clk_src4; + u32 emc_pmacro_tx_sel_clk_src5; + + u32 emc_pmacro_ddll_bypass; + + u32 emc_pmacro_ddll_pwrd0; + u32 emc_pmacro_ddll_pwrd1; + u32 emc_pmacro_ddll_pwrd2; + + u32 emc_pmacro_cmd_ctrl0; + u32 emc_pmacro_cmd_ctrl1; + u32 emc_pmacro_cmd_ctrl2; + + /* DRAM size information */ + + /* Specifies the value for MC_EMEM_ADR_CFG */ + u32 mc_emem_adr_cfg; + /* Specifies the value for MC_EMEM_ADR_CFG_DEV0 */ + u32 mc_emem_adr_cfg_dev0; + /* Specifies the value for MC_EMEM_ADR_CFG_DEV1 */ + u32 mc_emem_adr_cfg_dev1; + + u32 mc_emem_adr_cfg_channel_mask; + + /* Specifies the value for MC_EMEM_BANK_SWIZZLE_CFG0 */ + u32 mc_emem_adr_cfg_bank_mask0; + /* Specifies the value for MC_EMEM_BANK_SWIZZLE_CFG1 */ + u32 mc_emem_adr_cfg_bank_mask1; + /* Specifies the value for MC_EMEM_BANK_SWIZZLE_CFG2 */ + u32 mc_emem_adr_cfg_bank_mask2; + + /* + * Specifies the value for MC_EMEM_CFG which holds the external memory + * size (in KBytes) + */ + u32 mc_emem_cfg; + + /* MC arbitration configuration */ + + /* Specifies the value for MC_EMEM_ARB_CFG */ + u32 mc_emem_arb_cfg; + /* Specifies the value for MC_EMEM_ARB_OUTSTANDING_REQ */ + u32 mc_emem_arb_outstanding_req; + + u32 emc_emem_arb_refpb_hp_ctrl; + u32 emc_emem_arb_refpb_bank_ctrl; + + /* Specifies the value for MC_EMEM_ARB_TIMING_RCD */ + u32 mc_emem_arb_timing_rcd; + /* Specifies the value for MC_EMEM_ARB_TIMING_RP */ + u32 mc_emem_arb_timing_rp; + /* Specifies the value for MC_EMEM_ARB_TIMING_RC */ + u32 mc_emem_arb_timing_rc; + /* Specifies the value for MC_EMEM_ARB_TIMING_RAS */ + u32 mc_emem_arb_timing_ras; + /* Specifies the value for MC_EMEM_ARB_TIMING_FAW */ + u32 mc_emem_arb_timing_faw; + /* Specifies the value for MC_EMEM_ARB_TIMING_RRD */ + u32 mc_emem_arb_timing_rrd; + /* Specifies the value for MC_EMEM_ARB_TIMING_RAP2PRE */ + u32 mc_emem_arb_timing_rap2pre; + /* Specifies the value for MC_EMEM_ARB_TIMING_WAP2PRE */ + u32 mc_emem_arb_timing_wap2pre; + /* Specifies the value for MC_EMEM_ARB_TIMING_R2R */ + u32 mc_emem_arb_timing_r2r; + /* Specifies the value for MC_EMEM_ARB_TIMING_W2W */ + u32 mc_emem_arb_timing_w2w; + /* Specifies the value for MC_EMEM_ARB_TIMING_R2W */ + u32 mc_emem_arb_timing_r2w; + /* Specifies the value for MC_EMEM_ARB_TIMING_W2R */ + u32 mc_emem_arb_timing_w2r; + + u32 mc_emem_arb_timing_rfcpb; + + /* Specifies the value for MC_EMEM_ARB_DA_TURNS */ + u32 mc_emem_arb_da_turns; + /* Specifies the value for MC_EMEM_ARB_DA_COVERS */ + u32 mc_emem_arb_da_covers; + /* Specifies the value for MC_EMEM_ARB_MISC0 */ + u32 mc_emem_arb_misc0; + /* Specifies the value for MC_EMEM_ARB_MISC1 */ + u32 mc_emem_arb_misc1; + u32 mc_emem_arb_misc2; + + /* Specifies the value for MC_EMEM_ARB_RING1_THROTTLE */ + u32 mc_emem_arb_ring1_throttle; + /* Specifies the value for MC_EMEM_ARB_OVERRIDE */ + u32 mc_emem_arb_override; + /* Specifies the value for MC_EMEM_ARB_OVERRIDE_1 */ + u32 mc_emem_arb_override1; + /* Specifies the value for MC_EMEM_ARB_RSV */ + u32 mc_emem_arb_rsv; + + u32 mc_da_cfg0; + u32 mc_emem_arb_timing_ccdmw; + + /* Specifies the value for MC_CLKEN_OVERRIDE */ + u32 mc_clken_override; + + /* Specifies the value for MC_STAT_CONTROL */ + u32 mc_stat_control; + /* Specifies the value for MC_VIDEO_PROTECT_BOM */ + u32 mc_video_protect_bom; + /* Specifies the value for MC_VIDEO_PROTECT_BOM_ADR_HI */ + u32 mc_video_protect_bom_adr_hi; + /* Specifies the value for MC_VIDEO_PROTECT_SIZE_MB */ + u32 mc_video_protect_size_mb; + /* Specifies the value for MC_VIDEO_PROTECT_VPR_OVERRIDE */ + u32 mc_video_protect_vpr_override; + /* Specifies the value for MC_VIDEO_PROTECT_VPR_OVERRIDE1 */ + u32 mc_video_protect_vpr_override1; + /* Specifies the value for MC_VIDEO_PROTECT_GPU_OVERRIDE_0 */ + u32 mc_video_protect_gpu_override0; + /* Specifies the value for MC_VIDEO_PROTECT_GPU_OVERRIDE_1 */ + u32 mc_video_protect_gpu_override1; + /* Specifies the value for MC_SEC_CARVEOUT_BOM */ + u32 mc_sec_carveout_bom; + /* Specifies the value for MC_SEC_CARVEOUT_ADR_HI */ + u32 mc_sec_carveout_adr_hi; + /* Specifies the value for MC_SEC_CARVEOUT_SIZE_MB */ + u32 mc_sec_carveout_size_mb; + /* Specifies the value for MC_VIDEO_PROTECT_REG_CTRL.VIDEO_PROTECT_WRITE_ACCESS */ + u32 mc_video_protect_write_access; + /* Specifies the value for MC_SEC_CARVEOUT_REG_CTRL.SEC_CARVEOUT_WRITE_ACCESS */ + u32 mc_sec_carveout_protect_write_access; + + u32 mc_generalized_carveout1_bom; + u32 mc_generalized_carveout1_bom_hi; + u32 mc_generalized_carveout1_size_128kb; + u32 mc_generalized_carveout1_access0; + u32 mc_generalized_carveout1_access1; + u32 mc_generalized_carveout1_access2; + u32 mc_generalized_carveout1_access3; + u32 mc_generalized_carveout1_access4; + u32 mc_generalized_carveout1_force_internal_access0; + u32 mc_generalized_carveout1_force_internal_access1; + u32 mc_generalized_carveout1_force_internal_access2; + u32 mc_generalized_carveout1_force_internal_access3; + u32 mc_generalized_carveout1_force_internal_access4; + u32 mc_generalized_carveout1_cfg0; + + u32 mc_generalized_carveout2_bom; + u32 mc_generalized_carveout2_bom_hi; + u32 mc_generalized_carveout2_size_128kb; + u32 mc_generalized_carveout2_access0; + u32 mc_generalized_carveout2_access1; + u32 mc_generalized_carveout2_access2; + u32 mc_generalized_carveout2_access3; + u32 mc_generalized_carveout2_access4; + u32 mc_generalized_carveout2_force_internal_access0; + u32 mc_generalized_carveout2_force_internal_access1; + u32 mc_generalized_carveout2_force_internal_access2; + u32 mc_generalized_carveout2_force_internal_access3; + u32 mc_generalized_carveout2_force_internal_access4; + u32 mc_generalized_carveout2_cfg0; + + u32 mc_generalized_carveout3_bom; + u32 mc_generalized_carveout3_bom_hi; + u32 mc_generalized_carveout3_size_128kb; + u32 mc_generalized_carveout3_access0; + u32 mc_generalized_carveout3_access1; + u32 mc_generalized_carveout3_access2; + u32 mc_generalized_carveout3_access3; + u32 mc_generalized_carveout3_access4; + u32 mc_generalized_carveout3_force_internal_access0; + u32 mc_generalized_carveout3_force_internal_access1; + u32 mc_generalized_carveout3_force_internal_access2; + u32 mc_generalized_carveout3_force_internal_access3; + u32 mc_generalized_carveout3_force_internal_access4; + u32 mc_generalized_carveout3_cfg0; + + u32 mc_generalized_carveout4_bom; + u32 mc_generalized_carveout4_bom_hi; + u32 mc_generalized_carveout4_size_128kb; + u32 mc_generalized_carveout4_access0; + u32 mc_generalized_carveout4_access1; + u32 mc_generalized_carveout4_access2; + u32 mc_generalized_carveout4_access3; + u32 mc_generalized_carveout4_access4; + u32 mc_generalized_carveout4_force_internal_access0; + u32 mc_generalized_carveout4_force_internal_access1; + u32 mc_generalized_carveout4_force_internal_access2; + u32 mc_generalized_carveout4_force_internal_access3; + u32 mc_generalized_carveout4_force_internal_access4; + u32 mc_generalized_carveout4_cfg0; + + u32 mc_generalized_carveout5_bom; + u32 mc_generalized_carveout5_bom_hi; + u32 mc_generalized_carveout5_size_128kb; + u32 mc_generalized_carveout5_access0; + u32 mc_generalized_carveout5_access1; + u32 mc_generalized_carveout5_access2; + u32 mc_generalized_carveout5_access3; + u32 mc_generalized_carveout5_access4; + u32 mc_generalized_carveout5_force_internal_access0; + u32 mc_generalized_carveout5_force_internal_access1; + u32 mc_generalized_carveout5_force_internal_access2; + u32 mc_generalized_carveout5_force_internal_access3; + u32 mc_generalized_carveout5_force_internal_access4; + u32 mc_generalized_carveout5_cfg0; + + /* Specifies enable for CA training */ + u32 emc_ca_training_enable; + /* Set if bit 6 select is greater than bit 7 select; uses aremc.spec packet SWIZZLE_BIT6_GT_BIT7 */ + u32 swizzle_rank_byte_encode; + /* Specifies enable and offset for patched boot rom write */ + u32 boot_rom_patch_control; + /* Specifies data for patched boot rom write */ + u32 boot_rom_patch_data; + + /* Specifies the value for MC_MTS_CARVEOUT_BOM */ + u32 mc_mts_carveout_bom; + /* Specifies the value for MC_MTS_CARVEOUT_ADR_HI */ + u32 mc_mts_carveout_adr_hi; + /* Specifies the value for MC_MTS_CARVEOUT_SIZE_MB */ + u32 mc_mts_carveout_size_mb; + /* Specifies the value for MC_MTS_CARVEOUT_REG_CTRL */ + u32 mc_mts_carveout_reg_ctrl; +} sdram_params_t; + +#endif diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c new file mode 100644 index 0000000..8836e67 --- /dev/null +++ b/nyx/nyx_gui/nyx.c @@ -0,0 +1,427 @@ +/* + * Copyright (c) 2018 naehrwert + * + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "config/config.h" +#include "gfx/di.h" +#include "gfx/gfx.h" +#include "hos/hos.h" +#include "ianos/ianos.h" +#include "libs/compr/blz.h" +#include "libs/fatfs/ff.h" +#include "mem/heap.h" +#include "mem/minerva.h" +#include "mem/sdram.h" +#include "power/max77620.h" +#include "soc/bpmp.h" +#include "soc/fuse.h" +#include "soc/gpio.h" +#include "soc/hw_init.h" +#include "soc/i2c.h" +#include "soc/pmc.h" +#include "soc/t210.h" +#include "soc/uart.h" +#include "storage/sdmmc.h" +#include "utils/btn.h" +#include "utils/dirlist.h" +#include "utils/list.h" +#include "utils/util.h" + +#include "frontend/fe_emmc_tools.h" +#include "frontend/gui.h" + +//TODO: ugly. +sdmmc_t sd_sdmmc; +sdmmc_storage_t sd_storage; +FATFS sd_fs; +static bool sd_mounted = false; +static bool sd_init_done = false; + +#ifdef MENU_LOGO_ENABLE +u8 *Kc_MENU_LOGO; +#endif //MENU_LOGO_ENABLE + +hekate_config h_cfg; +const volatile ipl_ver_meta_t __attribute__((section ("._ipl_version"))) ipl_ver = { + .magic = BL_MAGIC, + .version = (BL_VER_MJ + '0') | ((BL_VER_MN + '0') << 8) | ((BL_VER_HF + '0') << 16), + .rsvd0 = 0, + .rsvd1 = 0 +}; + +volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR; +volatile boot_cfg_t *b_cfg; + +bool get_sd_card_removed() +{ + if (sd_init_done && !!gpio_read(GPIO_PORT_Z, GPIO_PIN_1)) + return true; + + return false; +} + +bool sd_mount() +{ + if (sd_mounted) + return true; + + int res = 0; + + if (!sd_init_done) + res = !sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, SDMMC_1, SDMMC_BUS_WIDTH_4, 11); + + if (res) + { + EPRINTF("Failed to init SD card.\nMake sure that it is inserted.\nOr that SD reader is properly seated!"); + } + else + { + sd_init_done = true; + int res = f_mount(&sd_fs, "", 1); + if (res == FR_OK) + { + sd_mounted = 1; + return true; + } + else + { + EPRINTFARGS("Failed to mount SD card (FatFS Error %d).\nMake sure that a FAT partition exists..", res); + } + } + + return false; +} + +void sd_unmount(bool deinit) +{ + if (sd_mounted) + { + f_mount(NULL, "", 1); + sd_mounted = false; + } + if (sd_init_done && deinit) + { + sdmmc_storage_end(&sd_storage); + sd_init_done = false; + } +} + +void *sd_file_read(const char *path, u32 *fsize) +{ + FIL fp; + if (f_open(&fp, path, FA_READ) != FR_OK) + return NULL; + + u32 size = f_size(&fp); + if (fsize) + *fsize = size; + + void *buf = malloc(size); + + if (f_read(&fp, buf, size, NULL) != FR_OK) + { + free(buf); + f_close(&fp); + + return NULL; + } + + f_close(&fp); + + return buf; +} + +int sd_save_to_file(void *buf, u32 size, const char *filename) +{ + FIL fp; + u32 res = 0; + res = f_open(&fp, filename, FA_CREATE_ALWAYS | FA_WRITE); + if (res) + { + EPRINTFARGS("Error (%d) creating file\n%s.\n", res, filename); + return res; + } + + f_write(&fp, buf, size, NULL); + f_close(&fp); + + return 0; +} + +void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage) +{ + sdmmc_storage_t storage2; + sdmmc_t sdmmc; + char emmcSN[9]; + bool init_done = false; + + memcpy(path, "backup", 7); + f_mkdir(path); + + if (!storage) + { + if (!sdmmc_storage_init_mmc(&storage2, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4)) + memcpy(emmcSN, "00000000", 9); + else + { + init_done = true; + itoa(storage2.cid.serial, emmcSN, 16); + } + } + else + itoa(storage->cid.serial, emmcSN, 16); + + u32 sub_dir_len = strlen(sub_dir); // Can be a null-terminator. + u32 filename_len = strlen(filename); // Can be a null-terminator. + + memcpy(path + strlen(path), "/", 2); + memcpy(path + strlen(path), emmcSN, 9); + f_mkdir(path); + memcpy(path + strlen(path), sub_dir, sub_dir_len + 1); + if (sub_dir_len) + f_mkdir(path); + memcpy(path + strlen(path), "/", 2); + memcpy(path + strlen(path), filename, filename_len + 1); + + if (init_done) + sdmmc_storage_end(&storage2); +} + +// This is a safe and unused DRAM region for our payloads. +#define RELOC_META_OFF 0x7C +#define PATCHED_RELOC_SZ 0x94 +#define PATCHED_RELOC_STACK 0x40007000 +#define PATCHED_RELOC_ENTRY 0x40010000 +#define EXT_PAYLOAD_ADDR 0xC0000000 +#define RCM_PAYLOAD_ADDR (EXT_PAYLOAD_ADDR + ALIGN(PATCHED_RELOC_SZ, 0x10)) +#define COREBOOT_ADDR (0xD0000000 - 0x100000) +#define CBFS_DRAM_EN_ADDR 0x4003e000 +#define CBFS_DRAM_MAGIC 0x4452414D // "DRAM" + +void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size) +{ + memcpy((u8 *)payload_src, (u8 *)NYX_LOAD_ADDR, PATCHED_RELOC_SZ); + + volatile reloc_meta_t *relocator = (reloc_meta_t *)(payload_src + RELOC_META_OFF); + + relocator->start = payload_dst - ALIGN(PATCHED_RELOC_SZ, 0x10); + relocator->stack = PATCHED_RELOC_STACK; + relocator->end = payload_dst + payload_size; + relocator->ep = payload_dst; + + if (payload_size == 0x7000) + { + memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), (u8 *)COREBOOT_ADDR, 0x7000); //Bootblock + *(vu32 *)CBFS_DRAM_EN_ADDR = CBFS_DRAM_MAGIC; + } +} + +lv_res_t launch_payload(lv_obj_t *list) +{ + const char *filename = lv_list_get_btn_text(list); + + if (!filename || !filename[0]) + goto out; + + char path[128]; + + strcpy(path,"bootloader/payloads/"); + strcat(path, filename); + + if (sd_mount()) + { + FIL fp; + if (f_open(&fp, path, FA_READ)) + { + EPRINTFARGS("Payload file is missing!\n(%s)", path); + sd_unmount(false); + + goto out; + } + + // Read and copy the payload to our chosen address + void *buf; + u32 size = f_size(&fp); + + if (size < 0x30000) + buf = (void *)RCM_PAYLOAD_ADDR; + else + buf = (void *)COREBOOT_ADDR; + + if (f_read(&fp, buf, size, NULL)) + { + f_close(&fp); + sd_unmount(false); + + goto out; + } + + f_close(&fp); + + sd_unmount(true); + + if (size < 0x30000) + { + reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10)); + reconfig_hw_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32)))); + } + else + { + reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000); + reconfig_hw_workaround(true, 0); + } + + void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR; + + msleep(100); + + // Launch our payload. + (*ext_payload_ptr)(); + } + +out: + return LV_RES_OK; +} + +void load_saved_configuration() +{ + LIST_INIT(ini_sections); + LIST_INIT(ini_list_sections); + + if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) + { + // Load configuration. + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) + { + // Skip other ini entries for autoboot. + if (ini_sec->type == INI_CHOICE) + { + if (!strcmp(ini_sec->name, "config")) + { + LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) + { + if (!strcmp("autoboot", kv->key)) + h_cfg.autoboot = atoi(kv->val); + else if (!strcmp("autoboot_list", kv->key)) + h_cfg.autoboot_list = atoi(kv->val); + else if (!strcmp("bootwait", kv->key)) + h_cfg.bootwait = atoi(kv->val); + else if (!strcmp("verification", kv->key)) + h_cfg.verification = atoi(kv->val); + else if (!strcmp("backlight", kv->key)) + h_cfg.backlight = atoi(kv->val); + else if (!strcmp("autohosoff", kv->key)) + h_cfg.autohosoff = atoi(kv->val); + else if (!strcmp("autonogc", kv->key)) + h_cfg.autonogc = atoi(kv->val); + else if (!strcmp("brand", kv->key)) + { + h_cfg.brand = malloc(strlen(kv->val) + 1); + strcpy(h_cfg.brand, kv->val); + } + else if (!strcmp("tagline", kv->key)) + { + h_cfg.tagline = malloc(strlen(kv->val) + 1); + strcpy(h_cfg.tagline, kv->val); + } + } + + continue; + } + } + } + } +} + +void nyx_init_load_res() +{ + bpmp_mmu_enable(); + + // Set bootloader's default configuration. + set_default_configuration(); + + gfx_init_ctxt((u32 *)FB_ADDRESS, 720, 1280, 720); + gfx_con_init(); + + sd_mount(); + + minerva_init(); + minerva_change_freq(FREQ_1600); + + load_saved_configuration(); + + FIL fp; + f_open(&fp, "bootloader/sys/res.pak", FA_READ); + f_read(&fp, (void *)NYX_RES_ADDR, f_size(&fp), NULL); + f_close(&fp); + + icon_switch = bmp_to_lvimg_obj("bootloader/res/icon_switch.bmp"); + icon_payload = bmp_to_lvimg_obj("bootloader/res/icon_payload.bmp"); + icon_lakka = bmp_to_lvimg_obj("bootloader/res/icon_lakka.bmp"); + hekate_bg = bmp_to_lvimg_obj("bootloader/res/background.bmp"); + + sd_unmount(false); + + h_cfg.rcm_patched = fuse_check_patched_rcm(); + + bpmp_clk_rate_set(BPMP_CLK_SUPER_BOOST); +} + +#define IPL_STACK_TOP 0x90010000 +#define IPL_HEAP_START 0x90020000 +#define IPL_HEAP_END 0xB5000000 + +extern void pivot_stack(u32 stack_top); + +#if (LV_LOG_PRINTF == 1) + #include "soc/clock.h" + #include "soc/gpio.h" + #include "soc/pinmux.h" +#endif + +void ipl_main() +{ + //Pivot the stack so we have enough space. + pivot_stack(IPL_STACK_TOP); + + //Tegra/Horizon configuration goes to 0x80000000+, package2 goes to 0xA9800000, we place our heap in between. + heap_init(IPL_HEAP_START); + + b_cfg = (boot_cfg_t *)(nyx_str->hekate + 0x94); + +#if (LV_LOG_PRINTF == 1) + gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO); + gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_GPIO); + pinmux_config_uart(UART_B); + clock_enable_uart(UART_B); + uart_init(UART_B, 115200); + + uart_send(UART_B, (u8 *)"Hekate-NYX: Hello!\r\n", 20); + uart_wait_idle(UART_B, UART_TX_IDLE); +#endif + + // Initialize the rest of hw and load nyx's resources. + nyx_init_load_res(); + + nyx_load_and_run(); + + while (true) + ; +} diff --git a/nyx/nyx_gui/power/bq24193.c b/nyx/nyx_gui/power/bq24193.c new file mode 100644 index 0000000..717c364 --- /dev/null +++ b/nyx/nyx_gui/power/bq24193.c @@ -0,0 +1,162 @@ +/* + * Battery charger driver for Nintendo Switch's TI BQ24193 + * + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "bq24193.h" +#include "../soc/i2c.h" +#include "../utils/util.h" + +int bq24193_get_property(enum BQ24193_reg_prop prop, int *value) +{ + u8 data; + + switch (prop) { + case BQ24193_InputVoltageLimit: // Input voltage limit (mV). + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_InputSource); + data = (data & BQ24193_INCONFIG_VINDPM_MASK) >> 3; + *value += ((data >> 0) & 1) ? 80 : 0; + *value += ((data >> 1) & 1) ? 160 : 0; + *value += ((data >> 2) & 1) ? 320 : 0; + *value += ((data >> 3) & 1) ? 640 : 0; + *value += 3880; + break; + case BQ24193_InputCurrentLimit: // Input current limit (mA). + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_InputSource); + data &= BQ24193_INCONFIG_INLIMIT_MASK; + switch (data) + { + case 0: + *value = 100; + break; + case 1: + *value = 150; + break; + case 2: + *value = 500; + break; + case 3: + *value = 900; + break; + case 4: + *value = 1200; + break; + case 5: + *value = 1500; + break; + case 6: + *value = 2000; + break; + case 7: + *value = 3000; + break; + } + break; + case BQ24193_SystemMinimumVoltage: // Minimum system voltage limit (mV). + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_PORConfig); + *value = (data & BQ24193_PORCONFIG_SYSMIN_MASK) >> 1; + *value *= 100; + *value += 3000; + break; + case BQ24193_FastChargeCurrentLimit: // Fast charge current limit (mA). + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgCurr); + data = (data & BQ24193_CHRGCURR_ICHG_MASK) >> 2; + *value += ((data >> 0) & 1) ? 64 : 0; + *value += ((data >> 1) & 1) ? 128 : 0; + *value += ((data >> 2) & 1) ? 256 : 0; + *value += ((data >> 3) & 1) ? 512 : 0; + *value += ((data >> 4) & 1) ? 1024 : 0; + *value += ((data >> 5) & 1) ? 2048 : 0; + *value += 512; + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgCurr); + data &= BQ24193_CHRGCURR_20PCT_MASK; + if (data) + *value = *value * 20 / 100; // Fast charge current limit is 20%. + break; + case BQ24193_ChargeVoltageLimit: // Charge voltage limit (mV). + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgVolt); + data = (data & BQ24193_CHRGVOLT_VREG) >> 2; + *value += ((data >> 0) & 1) ? 16 : 0; + *value += ((data >> 1) & 1) ? 32 : 0; + *value += ((data >> 2) & 1) ? 64 : 0; + *value += ((data >> 3) & 1) ? 128 : 0; + *value += ((data >> 4) & 1) ? 256 : 0; + *value += ((data >> 5) & 1) ? 512 : 0; + *value += 3504; + break; + case BQ24193_RechargeThreshold: // Recharge voltage threshold less than voltage limit (mV). + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgVolt); + data &= BQ24193_IRTHERMAL_THERM_MASK; + if (data) + *value = 300; + else + *value = 100; + break; + case BQ24193_ThermalRegulation: // Thermal regulation threshold (oC). + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_IRCompThermal); + data &= BQ24193_IRTHERMAL_THERM_MASK; + switch (data) + { + case 0: + *value = 60; + break; + case 1: + *value = 80; + break; + case 2: + *value = 100; + break; + case 3: + *value = 120; + break; + } + break; + case BQ24193_ChargeStatus: // 0: Not charging, 1: Pre-charge, 2: Fast charging, 3: Charge termination done + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_Status); + *value = (data & BQ24193_STATUS_CHRG_MASK) >> 4; + break; + case BQ24193_TempStatus: // 0: Normal, 2: Warm, 3: Cool, 5: Cold, 6: Hot. + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_FaultReg); + *value = data & BQ24193_FAULT_THERM_MASK; + break; + case BQ24193_DevID: // Dev ID. + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_VendorPart); + *value = data & BQ24193_VENDORPART_DEV_MASK; + break; + case BQ24193_ProductNumber: // Product number. + data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_VendorPart); + *value = (data & BQ24193_VENDORPART_PN_MASK) >> 3; + break; + default: + return -1; + } + return 0; +} + +void bq24193_fake_battery_removal() +{ + u8 value; + + // Disable watchdog to keep BATFET disabled. + value = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgTermTimer); + value &= ~BQ24193_CHRGTERM_WATCHDOG_MASK; + i2c_send_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgTermTimer, value); + + // Force BATFET to disabled state. This disconnects the battery from the system. + value = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_Misc); + value |= BQ24193_MISC_BATFET_DI_MASK; + i2c_send_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_Misc, value); +} diff --git a/nyx/nyx_gui/power/bq24193.h b/nyx/nyx_gui/power/bq24193.h new file mode 100644 index 0000000..9c7b74e --- /dev/null +++ b/nyx/nyx_gui/power/bq24193.h @@ -0,0 +1,119 @@ +/* + * Battery charger driver for Nintendo Switch's TI BQ24193 + * + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __BQ24193_H_ +#define __BQ24193_H_ + +#define BQ24193_I2C_ADDR 0x6B + +// REG 0 masks. +#define BQ24193_INCONFIG_INLIMIT_MASK (7<<0) +#define BQ24193_INCONFIG_VINDPM_MASK 0x78 +#define BQ24193_INCONFIG_HIZ_EN_MASK (1<<7) + +// REG 1 masks. +#define BQ24193_PORCONFIG_BOOST_MASK (1<<0) +#define BQ24193_PORCONFIG_SYSMIN_MASK (7<<1) +#define BQ24193_PORCONFIG_CHGCONFIG_MASK (3<<4) +#define BQ24193_PORCONFIG_I2CWATCHDOG_MASK (1<<6) +#define BQ24193_PORCONFIG_RESET_MASK (1<<7) + +// REG 2 masks. +#define BQ24193_CHRGCURR_20PCT_MASK (1<<0) +#define BQ24193_CHRGCURR_ICHG_MASK 0xFC + +// REG 3 masks. +#define BQ24193_PRECHRG_ITERM 0x0F +#define BQ24193_PRECHRG_IPRECHG 0xF0 + +// REG 4 masks. +#define BQ24193_CHRGVOLT_VTHRES (1<<0) +#define BQ24193_CHRGVOLT_BATTLOW (1<<1) +#define BQ24193_CHRGVOLT_VREG 0xFC + +// REG 5 masks. +#define BQ24193_CHRGTERM_ISET_MASK (1<<0) +#define BQ24193_CHRGTERM_CHGTIMER_MASK (3<<1) +#define BQ24193_CHRGTERM_ENTIMER_MASK (1<<3) +#define BQ24193_CHRGTERM_WATCHDOG_MASK (3<<4) +#define BQ24193_CHRGTERM_TERM_ST_MASK (1<<6) +#define BQ24193_CHRGTERM_TERM_EN_MASK (1<<7) + +// REG 6 masks. +#define BQ24193_IRTHERMAL_THERM_MASK (3<<0) +#define BQ24193_IRTHERMAL_VCLAMP_MASK (7<<2) +#define BQ24193_IRTHERMAL_BATTCOMP_MASK (7<<5) + +// REG 7 masks. +#define BQ24193_MISC_INT_MASK (3<<0) +#define BQ24193_MISC_VSET_MASK (1<<4) +#define BQ24193_MISC_BATFET_DI_MASK (1<<5) +#define BQ24193_MISC_TMR2X_EN_MASK (1<<6) +#define BQ24193_MISC_DPDM_EN_MASK (1<<7) + +// REG 8 masks. +#define BQ24193_STATUS_VSYS_MASK (1<<0) +#define BQ24193_STATUS_THERM_MASK (1<<1) +#define BQ24193_STATUS_PG_MASK (1<<2) +#define BQ24193_STATUS_DPM_MASK (1<<3) +#define BQ24193_STATUS_CHRG_MASK (3<<4) +#define BQ24193_STATUS_VBUS_MASK (3<<6) + +// REG 9 masks. +#define BQ24193_FAULT_THERM_MASK (7<<0) +#define BQ24193_FAULT_BATT_OVP_MASK (1<<3) +#define BQ24193_FAULT_CHARGE_MASK (3<<4) +#define BQ24193_FAULT_BOOST_MASK (1<<6) +#define BQ24193_FAULT_WATCHDOG_MASK (1<<7) + +// REG A masks. +#define BQ24193_VENDORPART_DEV_MASK (3<<0) +#define BQ24193_VENDORPART_PN_MASK (7<<3) + +enum BQ24193_reg { + BQ24193_InputSource = 0x00, + BQ24193_PORConfig = 0x01, + BQ24193_ChrgCurr = 0x02, + BQ24193_PreChrgTerm = 0x03, + BQ24193_ChrgVolt = 0x04, + BQ24193_ChrgTermTimer = 0x05, + BQ24193_IRCompThermal = 0x06, + BQ24193_Misc = 0x07, + BQ24193_Status = 0x08, + BQ24193_FaultReg = 0x09, + BQ24193_VendorPart = 0x0A, +}; + +enum BQ24193_reg_prop { + BQ24193_InputVoltageLimit, // REG 0. + BQ24193_InputCurrentLimit, // REG 0. + BQ24193_SystemMinimumVoltage, // REG 1. + BQ24193_FastChargeCurrentLimit, // REG 2. + BQ24193_ChargeVoltageLimit, // REG 4. + BQ24193_RechargeThreshold, // REG 4. + BQ24193_ThermalRegulation, // REG 6. + BQ24193_ChargeStatus, // REG 8. + BQ24193_TempStatus, // REG 9. + BQ24193_DevID, // REG A. + BQ24193_ProductNumber, // REG A. +}; + +int bq24193_get_property(enum BQ24193_reg_prop prop, int *value); +void bq24193_fake_battery_removal(); + +#endif /* __BQ24193_H_ */ diff --git a/nyx/nyx_gui/power/max17050.c b/nyx/nyx_gui/power/max17050.c new file mode 100644 index 0000000..2a2c8f6 --- /dev/null +++ b/nyx/nyx_gui/power/max17050.c @@ -0,0 +1,266 @@ +/* + * Fuel gauge driver for Nintendo Switch's Maxim 17050 + * + * Copyright (C) 2011 Samsung Electronics + * MyungJoo Ham + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * This driver is based on max17040_battery.c + */ + +#include "max17050.h" +#include "../soc/i2c.h" +#include "../utils/util.h" + +/* Status register bits */ +#define STATUS_POR_BIT (1 << 1) +#define STATUS_BST_BIT (1 << 3) +#define STATUS_VMN_BIT (1 << 8) +#define STATUS_TMN_BIT (1 << 9) +#define STATUS_SMN_BIT (1 << 10) +#define STATUS_BI_BIT (1 << 11) +#define STATUS_VMX_BIT (1 << 12) +#define STATUS_TMX_BIT (1 << 13) +#define STATUS_SMX_BIT (1 << 14) +#define STATUS_BR_BIT (1 << 15) + +#define VFSOC0_LOCK 0x0000 +#define VFSOC0_UNLOCK 0x0080 + +#define MAX17050_VMAX_TOLERANCE 50 /* 50 mV */ + +int max17050_get_property(enum MAX17050_reg reg, int *value) +{ + u16 data; + + switch (reg) + { + case MAX17050_Age: // Age (percent). Based on 100% x (FullCAP Register/DesignCap). + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_Age); + *value = data >> 8; /* Show MSB. 1% increments */ + break; + case MAX17050_Cycles: // Cycle count. + i2c_recv_buf_small((u8 *)value, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_Cycles); + break; + case MAX17050_MinVolt: // Voltage max/min + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_MinMaxVolt); + *value = (data & 0xff) * 20; /* Voltage MIN. Units of 20mV */ + break; + case MAX17050_MaxVolt: // Voltage max/min + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_MinMaxVolt); + *value = (data >> 8) * 20; /* Voltage MAX. Units of LSB = 20mV */ + break; + case MAX17050_V_empty: // Voltage min design. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_V_empty); + *value = (data >> 7) * 10; /* Units of LSB = 10mV */ + break; + case MAX17050_VCELL: // Voltage now. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_VCELL); + *value = data * 625 / 8 / 1000; + break; + case MAX17050_AvgVCELL: // Voltage avg. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_AvgVCELL); + *value = data * 625 / 8 / 1000; + break; + case MAX17050_OCVInternal: // Voltage ocv. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_OCVInternal); + *value = data * 625 / 8 / 1000; + break; + case MAX17050_RepSOC: // Capacity %. + i2c_recv_buf_small((u8 *)value, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_RepSOC); + break; + case MAX17050_DesignCap: // Charge full design. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_DesignCap); + data = data * 5 / 10; + *value = data; + break; + case MAX17050_FullCAP: // Charge full. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_FullCAP); + data = data * 5 / 10; + *value = data; + break; + case MAX17050_RepCap: // Charge now. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_RepCap); + data = data * 5 / 10; + *value = data; + break; + case MAX17050_TEMP: // Temp. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_TEMP); + *value = (s16)data; + *value = *value * 10 / 256; + break; + case MAX17050_Current: // Current now. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_Current); + *value = (s16)data; + *value *= 1562500 / MAX17050_DEFAULT_SNS_RESISTOR; + break; + case MAX17050_AvgCurrent: // Current avg. + i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_AvgCurrent); + *value = (s16)data; + *value *= 1562500 / MAX17050_DEFAULT_SNS_RESISTOR; + break; + default: + return -1; + } + return 0; +} + +static int _max17050_write_verify_reg(u8 reg, u16 value) +{ + int retries = 8; + int ret; + u16 read_value; + + do + { + ret = i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, reg, (u8 *)&value, 2); + i2c_recv_buf_small((u8 *)&read_value, 2, I2C_1, MAXIM17050_I2C_ADDR, reg); + if (read_value != value) + { + ret = -1; + retries--; + } + } while (retries && read_value != value); + + return ret; +} + +static void _max17050_override_por(u8 reg, u16 value) +{ + if (value) + i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, reg, (u8 *)&value, 2); +} + +static void _max17050_load_new_capacity_params() +{ + u16 fullcap, repSoc, dq_acc, dp_acc; + + fullcap = 0x2476; // 4667mAh design capacity. + dq_acc = 0x10bc; // From a healthy fuel gauge. + dp_acc = 0x5e09; // =||= + repSoc = 0x6400; // 100%. + + _max17050_write_verify_reg(MAX17050_RemCap, fullcap); + _max17050_write_verify_reg(MAX17050_RepCap, fullcap); + + _max17050_write_verify_reg(MAX17050_dQacc, dq_acc); + _max17050_write_verify_reg(MAX17050_dPacc, dp_acc); + + _max17050_write_verify_reg(MAX17050_FullCAP, fullcap); + //i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_DesignCap, (u8 *)&fullcap, 2); + _max17050_write_verify_reg(MAX17050_FullCAPNom, fullcap); + /* Update SOC register with new SOC */ + i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_RepSOC, (u8 *)&repSoc, 2); +} + +static void _max17050_reset_vfsoc0_reg() +{ + u16 lockVal = 0; + u16 vfSoc = 0x6440; // >100% for fully charged battery + + lockVal = VFSOC0_UNLOCK; + i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_VFSOC0Enable, (u8 *)&lockVal, 2); + + _max17050_write_verify_reg(MAX17050_VFSOC0, vfSoc); + + lockVal = VFSOC0_LOCK; + i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_VFSOC0Enable, (u8 *)&lockVal, 2); +} + +static void _max17050_update_capacity_regs() +{ + u16 value = 0x2476; // Set to 4667mAh design capacity. + _max17050_write_verify_reg(MAX17050_FullCAP, value); + _max17050_write_verify_reg(MAX17050_FullCAPNom, value); + //i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_DesignCap, config->design_cap, 2); +} + +static void _max17050_write_config_regs() +{ + u16 value = 0; + + value = 0x7254; + i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_CONFIG, (u8 *)&value, 2); + value = 0x2473; + i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_LearnCFG, (u8 *)&value, 2); + //i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_FilterCFG, (u8 *)&value, 2) + //i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_RelaxCFG, (u8 *)&value, 2) + //i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_FullSOCThr, (u8 *)&value, 2) +} + +/* + * Block write all the override values coming from platform data. + * This function MUST be called before the POR initialization proceedure + * specified by maxim. + */ +static void _max17050_override_por_values() +{ + u16 dq_acc = 0x10bc; // From a healthy fuel gauge. + u16 dp_acc = 0x5e09; // =||= + + _max17050_override_por(MAX17050_dQacc, dq_acc); + _max17050_override_por(MAX17050_dPacc, dp_acc); + + //_max17050_override_por(MAX17050_RCOMP0, config->rcomp0); //0x58 + //_max17050_override_por(MAX17050_TempCo, config->tcompc0); //0x1b22 + + //u16 k_empty0 = 0x439; + //_max17050_override_por(map, MAX17050_K_empty0, k_empty0); // Unknown cell data +} + +static void _max17050_set_por_bit(u16 value) +{ + _max17050_write_verify_reg(MAX17050_STATUS, value); +} + +int max17050_fix_configuration() +{ + /* Init phase, set the POR bit */ + _max17050_set_por_bit(STATUS_POR_BIT); + + /* Override POR values */ + _max17050_override_por_values(); + /* After Power up, the MAX17050 requires 500ms in order + * to perform signal debouncing and initial SOC reporting + */ + msleep(500); + + /* Initialize configaration */ + _max17050_write_config_regs(); + + /* update capacity params */ + _max17050_update_capacity_regs(); + + /* delay must be atleast 350mS to allow VFSOC + * to be calculated from the new configuration + */ + msleep(350); + + /* reset vfsoc0 reg */ + _max17050_reset_vfsoc0_reg(); + + /* load new capacity params */ + _max17050_load_new_capacity_params(); + + /* Init complete, Clear the POR bit */ + //_max17050_set_por_bit(0); // Should we? Or let the switch to reconfigure POR? + + // Sets POR, BI, BR. + _max17050_set_por_bit(0x8801); + + return 0; +} diff --git a/nyx/nyx_gui/power/max17050.h b/nyx/nyx_gui/power/max17050.h new file mode 100644 index 0000000..2196b80 --- /dev/null +++ b/nyx/nyx_gui/power/max17050.h @@ -0,0 +1,127 @@ +/* + * Fuel gauge driver for Nintendo Switch's Maxim 17050 + * Note that Maxim 8966 and 8997 are mfd and this is its subdevice. + * + * Copyright (C) 2011 Samsung Electronics + * MyungJoo Ham + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __MAX17050_H_ +#define __MAX17050_H_ + +#define MAX17050_STATUS_BattAbsent (1 << 3) +#define MAX17050_DEFAULT_SNS_RESISTOR 10000 + +/* Consider RepCap which is less then 10 units below FullCAP full */ +#define MAX17050_FULL_THRESHOLD 10 + +#define MAX17050_CHARACTERIZATION_DATA_SIZE 48 + +#define MAXIM17050_I2C_ADDR 0x36 + +enum MAX17050_reg { + MAX17050_STATUS = 0x00, + MAX17050_VALRT_Th = 0x01, + MAX17050_TALRT_Th = 0x02, + MAX17050_SALRT_Th = 0x03, + MAX17050_AtRate = 0x04, + MAX17050_RepCap = 0x05, + MAX17050_RepSOC = 0x06, + MAX17050_Age = 0x07, + MAX17050_TEMP = 0x08, + MAX17050_VCELL = 0x09, + MAX17050_Current = 0x0A, + MAX17050_AvgCurrent = 0x0B, + + MAX17050_SOC = 0x0D, + MAX17050_AvSOC = 0x0E, + MAX17050_RemCap = 0x0F, + MAX17050_FullCAP = 0x10, + MAX17050_TTE = 0x11, + MAX17050_QRTbl00 = 0x12, + MAX17050_FullSOCThr = 0x13, + MAX17050_RSLOW = 0x14, + + MAX17050_AvgTA = 0x16, + MAX17050_Cycles = 0x17, + MAX17050_DesignCap = 0x18, + MAX17050_AvgVCELL = 0x19, + MAX17050_MinMaxTemp = 0x1A, + MAX17050_MinMaxVolt = 0x1B, + MAX17050_MinMaxCurr = 0x1C, + MAX17050_CONFIG = 0x1D, + MAX17050_ICHGTerm = 0x1E, + MAX17050_AvCap = 0x1F, + MAX17050_ManName = 0x20, + MAX17050_DevName = 0x21, + MAX17050_QRTbl10 = 0x22, + MAX17050_FullCAPNom = 0x23, + MAX17050_TempNom = 0x24, + MAX17050_TempLim = 0x25, + MAX17050_TempHot = 0x26, + MAX17050_AIN = 0x27, + MAX17050_LearnCFG = 0x28, + MAX17050_FilterCFG = 0x29, + MAX17050_RelaxCFG = 0x2A, + MAX17050_MiscCFG = 0x2B, + MAX17050_TGAIN = 0x2C, + MAX17050_TOFF = 0x2D, + MAX17050_CGAIN = 0x2E, + MAX17050_COFF = 0x2F, + + MAX17050_QRTbl20 = 0x32, + MAX17050_SOC_empty = 0x33, + MAX17050_T_empty = 0x34, + MAX17050_FullCAP0 = 0x35, + MAX17050_LAvg_empty = 0x36, + MAX17050_FCTC = 0x37, + MAX17050_RCOMP0 = 0x38, + MAX17050_TempCo = 0x39, + MAX17050_V_empty = 0x3A, + MAX17050_K_empty0 = 0x3B, + MAX17050_TaskPeriod = 0x3C, + MAX17050_FSTAT = 0x3D, + + MAX17050_SHDNTIMER = 0x3F, + MAX17050_QRTbl30 = 0x42, + MAX17050_dQacc = 0x45, + MAX17050_dPacc = 0x46, + + MAX17050_VFSOC0 = 0x48, + + MAX17050_QH = 0x4D, + MAX17050_QL = 0x4E, + + MAX17050_MinVolt = 0x50, // Custom ID. Not to be sent to i2c. + MAX17050_MaxVolt = 0x51, // Custom ID. Not to be sent to i2c. + + MAX17050_VFSOC0Enable = 0x60, + + MAX17050_MODELChrTbl = 0x80, + + MAX17050_OCV = 0xEE, + + MAX17050_OCVInternal = 0xFB, + + MAX17050_VFSOC = 0xFF, +}; + +int max17050_get_property(enum MAX17050_reg reg, int *value); +int max17050_fix_configuration(); + +#endif /* __MAX17050_H_ */ diff --git a/nyx/nyx_gui/power/max77620.h b/nyx/nyx_gui/power/max77620.h new file mode 100644 index 0000000..fcce309 --- /dev/null +++ b/nyx/nyx_gui/power/max77620.h @@ -0,0 +1,331 @@ +/* + * Defining registers address and its bit definitions of MAX77620 and MAX20024 + * + * Copyright (C) 2016 NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + */ + +#ifndef _MFD_MAX77620_H_ +#define _MFD_MAX77620_H_ + +#define MAX77620_I2C_ADDR 0x3C + +/* GLOBAL, PMIC, GPIO, FPS, ONOFFC, CID Registers */ +#define MAX77620_REG_CNFGGLBL1 0x00 +#define MAX77620_CNFGGLBL1_LBDAC_EN (1 << 7) +#define MAX77620_CNFGGLBL1_MPPLD (1 << 6) +#define MAX77620_CNFGGLBL1_LBHYST ((1 << 5) | (1 << 4)) +#define MAX77620_CNFGGLBL1_LBHYST_N (1 << 4) +#define MAX77620_CNFGGLBL1_LBDAC 0x0E +#define MAX77620_CNFGGLBL1_LBDAC_N (1 << 1) +#define MAX77620_CNFGGLBL1_LBRSTEN (1 << 0) + +#define MAX77620_REG_CNFGGLBL2 0x01 +#define MAX77620_REG_CNFGGLBL3 0x02 +#define MAX77620_WDTC_MASK 0x3 +#define MAX77620_WDTOFFC (1 << 4) +#define MAX77620_WDTSLPC (1 << 3) +#define MAX77620_WDTEN (1 << 2) +#define MAX77620_TWD_MASK 0x3 +#define MAX77620_TWD_2s 0x0 +#define MAX77620_TWD_16s 0x1 +#define MAX77620_TWD_64s 0x2 +#define MAX77620_TWD_128s 0x3 + +#define MAX77620_REG_CNFG1_32K 0x03 +#define MAX77620_CNFG1_32K_OUT0_EN (1 << 2) + +#define MAX77620_REG_CNFGBBC 0x04 +#define MAX77620_CNFGBBC_ENABLE (1 << 0) +#define MAX77620_CNFGBBC_CURRENT_MASK 0x06 +#define MAX77620_CNFGBBC_CURRENT_SHIFT 1 +#define MAX77620_CNFGBBC_VOLTAGE_MASK 0x18 +#define MAX77620_CNFGBBC_VOLTAGE_SHIFT 3 +#define MAX77620_CNFGBBC_LOW_CURRENT_DISABLE (1 << 5) +#define MAX77620_CNFGBBC_RESISTOR_MASK 0xC0 +#define MAX77620_CNFGBBC_RESISTOR_SHIFT 6 +#define MAX77620_CNFGBBC_RESISTOR_100 (0 << MAX77620_CNFGBBC_RESISTOR_SHIFT) +#define MAX77620_CNFGBBC_RESISTOR_1K (1 << MAX77620_CNFGBBC_RESISTOR_SHIFT) +#define MAX77620_CNFGBBC_RESISTOR_3K (2 << MAX77620_CNFGBBC_RESISTOR_SHIFT) +#define MAX77620_CNFGBBC_RESISTOR_6K (3 << MAX77620_CNFGBBC_RESISTOR_SHIFT) + +#define MAX77620_REG_IRQTOP 0x05 +#define MAX77620_IRQ_TOP_GLBL_MASK (1 << 7) +#define MAX77620_IRQ_TOP_SD_MASK (1 << 6) +#define MAX77620_IRQ_TOP_LDO_MASK (1 << 5) +#define MAX77620_IRQ_TOP_GPIO_MASK (1 << 4) +#define MAX77620_IRQ_TOP_RTC_MASK (1 << 3) +#define MAX77620_IRQ_TOP_32K_MASK (1 << 2) +#define MAX77620_IRQ_TOP_ONOFF_MASK (1 << 1) + +#define MAX77620_REG_INTLBT 0x06 +#define MAX77620_REG_IRQTOPM 0x0D +#define MAX77620_IRQ_LBM_MASK (1 << 3) +#define MAX77620_IRQ_TJALRM1_MASK (1 << 2) +#define MAX77620_IRQ_TJALRM2_MASK (1 << 1) + +#define MAX77620_REG_IRQSD 0x07 +#define MAX77620_REG_IRQ_LVL2_L0_7 0x08 +#define MAX77620_REG_IRQ_LVL2_L8 0x09 +#define MAX77620_REG_IRQ_LVL2_GPIO 0x0A +#define MAX77620_REG_ONOFFIRQ 0x0B +#define MAX77620_REG_NVERC 0x0C + +#define MAX77620_REG_INTENLBT 0x0E +#define MAX77620_GLBLM_MASK (1 << 0) + +#define MAX77620_REG_IRQMASKSD 0x0F +#define MAX77620_REG_IRQ_MSK_L0_7 0x10 +#define MAX77620_REG_IRQ_MSK_L8 0x11 +#define MAX77620_REG_ONOFFIRQM 0x12 +#define MAX77620_REG_STATLBT 0x13 +#define MAX77620_REG_STATSD 0x14 +#define MAX77620_REG_ONOFFSTAT 0x15 + +/* SD and LDO Registers */ +#define MAX77620_REG_SD0 0x16 +#define MAX77620_REG_SD1 0x17 +#define MAX77620_REG_SD2 0x18 +#define MAX77620_REG_SD3 0x19 +#define MAX77620_REG_SD4 0x1A +#define MAX77620_SDX_VOLT_MASK 0xFF +#define MAX77620_SD0_VOLT_MASK 0x3F +#define MAX77620_SD1_VOLT_MASK 0x7F +#define MAX77620_LDO_VOLT_MASK 0x3F +#define MAX77620_REG_DVSSD0 0x1B +#define MAX77620_REG_DVSSD1 0x1C +#define MAX77620_REG_SD0_CFG 0x1D +#define MAX77620_REG_SD1_CFG 0x1E +#define MAX77620_REG_SD2_CFG 0x1F +#define MAX77620_REG_SD3_CFG 0x20 +#define MAX77620_REG_SD4_CFG 0x21 +#define MAX77620_REG_SD_CFG2 0x22 +#define MAX77620_REG_LDO0_CFG 0x23 +#define MAX77620_REG_LDO0_CFG2 0x24 +#define MAX77620_REG_LDO1_CFG 0x25 +#define MAX77620_REG_LDO1_CFG2 0x26 +#define MAX77620_REG_LDO2_CFG 0x27 +#define MAX77620_REG_LDO2_CFG2 0x28 +#define MAX77620_REG_LDO3_CFG 0x29 +#define MAX77620_REG_LDO3_CFG2 0x2A +#define MAX77620_REG_LDO4_CFG 0x2B +#define MAX77620_REG_LDO4_CFG2 0x2C +#define MAX77620_REG_LDO5_CFG 0x2D +#define MAX77620_REG_LDO5_CFG2 0x2E +#define MAX77620_REG_LDO6_CFG 0x2F +#define MAX77620_REG_LDO6_CFG2 0x30 +#define MAX77620_REG_LDO7_CFG 0x31 +#define MAX77620_REG_LDO7_CFG2 0x32 +#define MAX77620_REG_LDO8_CFG 0x33 +#define MAX77620_REG_LDO8_CFG2 0x34 +#define MAX77620_LDO_POWER_MODE_MASK 0xC0 +#define MAX77620_LDO_POWER_MODE_SHIFT 6 +#define MAX77620_POWER_MODE_NORMAL 3 +#define MAX77620_POWER_MODE_LPM 2 +#define MAX77620_POWER_MODE_GLPM 1 +#define MAX77620_POWER_MODE_DISABLE 0 +#define MAX20024_LDO_CFG2_MPOK_MASK (1 << 2) +#define MAX77620_LDO_CFG2_ADE_MASK (1 << 1) +#define MAX77620_LDO_CFG2_ADE_DISABLE 0 +#define MAX77620_LDO_CFG2_ADE_ENABLE (1 << 1) +#define MAX77620_LDO_CFG2_SS_MASK (1 << 0) +#define MAX77620_LDO_CFG2_SS_FAST (1 << 0) +#define MAX77620_LDO_CFG2_SS_SLOW 0 + +#define MAX77620_REG_LDO_CFG3 0x35 +#define MAX77620_TRACK4_MASK (1 << 5) +#define MAX77620_TRACK4_SHIFT 5 + +#define MAX77620_LDO_SLEW_RATE_MASK 0x1 + +#define MAX77620_REG_GPIO0 0x36 +#define MAX77620_REG_GPIO1 0x37 +#define MAX77620_REG_GPIO2 0x38 +#define MAX77620_REG_GPIO3 0x39 +#define MAX77620_REG_GPIO4 0x3A +#define MAX77620_REG_GPIO5 0x3B +#define MAX77620_REG_GPIO6 0x3C +#define MAX77620_REG_GPIO7 0x3D +#define MAX77620_REG_PUE_GPIO 0x3E +#define MAX77620_REG_PDE_GPIO 0x3F +#define MAX77620_REG_AME_GPIO 0x40 + +#define MAX77620_REG_ONOFFCNFG1 0x41 +#define MAX77620_ONOFFCNFG1_SFT_RST (1 << 7) +#define MAX77620_ONOFFCNFG1_MRT_MASK 0x38 +#define MAX77620_ONOFFCNFG1_MRT_SHIFT 0x3 +#define MAX77620_ONOFFCNFG1_SLPEN (1 << 2) +#define MAX77620_ONOFFCNFG1_PWR_OFF (1 << 1) +#define MAX20024_ONOFFCNFG1_CLRSE 0x18 + +#define MAX77620_REG_ONOFFCNFG2 0x42 +#define MAX77620_ONOFFCNFG2_SFT_RST_WK (1 << 7) +#define MAX77620_ONOFFCNFG2_WD_RST_WK (1 << 6) +#define MAX77620_ONOFFCNFG2_SLP_LPM_MSK (1 << 5) +#define MAX77620_ONOFFCNFG2_WK_ALARM1 (1 << 2) +#define MAX77620_ONOFFCNFG2_WK_EN0 (1 << 0) + +/* FPS Registers */ +#define MAX77620_REG_FPS_CFG0 0x43 +#define MAX77620_REG_FPS_CFG1 0x44 +#define MAX77620_REG_FPS_CFG2 0x45 +#define MAX77620_REG_FPS_LDO0 0x46 +#define MAX77620_REG_FPS_LDO1 0x47 +#define MAX77620_REG_FPS_LDO2 0x48 +#define MAX77620_REG_FPS_LDO3 0x49 +#define MAX77620_REG_FPS_LDO4 0x4A +#define MAX77620_REG_FPS_LDO5 0x4B +#define MAX77620_REG_FPS_LDO6 0x4C +#define MAX77620_REG_FPS_LDO7 0x4D +#define MAX77620_REG_FPS_LDO8 0x4E +#define MAX77620_REG_FPS_SD0 0x4F +#define MAX77620_REG_FPS_SD1 0x50 +#define MAX77620_REG_FPS_SD2 0x51 +#define MAX77620_REG_FPS_SD3 0x52 +#define MAX77620_REG_FPS_SD4 0x53 +#define MAX77620_REG_FPS_NONE 0 +#define MAX77620_FPS_SRC_MASK 0xC0 +#define MAX77620_FPS_SRC_SHIFT 6 +#define MAX77620_FPS_PU_PERIOD_MASK 0x38 +#define MAX77620_FPS_PU_PERIOD_SHIFT 3 +#define MAX77620_FPS_PD_PERIOD_MASK 0x07 +#define MAX77620_FPS_PD_PERIOD_SHIFT 0 + +/* Minimum and maximum FPS period time (in microseconds) are + * different for MAX77620 and Max20024. + */ +#define MAX77620_FPS_COUNT 3 + +#define MAX77620_FPS_PERIOD_MIN_US 40 +#define MAX20024_FPS_PERIOD_MIN_US 20 + +#define MAX77620_FPS_PERIOD_MAX_US 2560 +#define MAX20024_FPS_PERIOD_MAX_US 5120 + +#define MAX77620_REG_FPS_GPIO1 0x54 +#define MAX77620_REG_FPS_GPIO2 0x55 +#define MAX77620_REG_FPS_GPIO3 0x56 +#define MAX77620_FPS_TIME_PERIOD_MASK 0x38 +#define MAX77620_FPS_TIME_PERIOD_SHIFT 3 +#define MAX77620_FPS_EN_SRC_MASK 0x06 +#define MAX77620_FPS_EN_SRC_SHIFT 1 +#define MAX77620_FPS_ENFPS_SW_MASK 0x01 +#define MAX77620_FPS_ENFPS_SW 0x01 + +#define MAX77620_REG_FPS_RSO 0x57 +#define MAX77620_REG_CID0 0x58 +#define MAX77620_REG_CID1 0x59 +#define MAX77620_REG_CID2 0x5A +#define MAX77620_REG_CID3 0x5B +#define MAX77620_REG_CID4 0x5C +#define MAX77620_REG_CID5 0x5D + +#define MAX77620_REG_DVSSD4 0x5E +#define MAX20024_REG_MAX_ADD 0x70 + +#define MAX77620_CID_DIDM_MASK 0xF0 +#define MAX77620_CID_DIDM_SHIFT 4 + +/* CNCG2SD */ +#define MAX77620_SD_CNF2_ROVS_EN_SD1 (1 << 1) +#define MAX77620_SD_CNF2_ROVS_EN_SD0 (1 << 2) + +/* Device Identification Metal */ +#define MAX77620_CID5_DIDM(n) (((n) >> 4) & 0xF) +/* Device Indentification OTP */ +#define MAX77620_CID5_DIDO(n) ((n) & 0xF) + +/* SD CNFG1 */ +#define MAX77620_SD_SR_MASK 0xC0 +#define MAX77620_SD_SR_SHIFT 6 +#define MAX77620_SD_POWER_MODE_MASK 0x30 +#define MAX77620_SD_POWER_MODE_SHIFT 4 +#define MAX77620_SD_CFG1_ADE_MASK (1 << 3) +#define MAX77620_SD_CFG1_ADE_DISABLE 0 +#define MAX77620_SD_CFG1_ADE_ENABLE (1 << 3) +#define MAX77620_SD_FPWM_MASK 0x04 +#define MAX77620_SD_FPWM_SHIFT 2 +#define MAX77620_SD_FSRADE_MASK 0x01 +#define MAX77620_SD_FSRADE_SHIFT 0 +#define MAX77620_SD_CFG1_FPWM_SD_MASK (1 << 2) +#define MAX77620_SD_CFG1_FPWM_SD_SKIP 0 +#define MAX77620_SD_CFG1_FPWM_SD_FPWM (1 << 2) +#define MAX20024_SD_CFG1_MPOK_MASK (1 << 1) +#define MAX77620_SD_CFG1_FSRADE_SD_MASK (1 << 0) +#define MAX77620_SD_CFG1_FSRADE_SD_DISABLE 0 +#define MAX77620_SD_CFG1_FSRADE_SD_ENABLE (1 << 0) + +#define MAX77620_CNFG_GPIO_DRV_MASK (1 << 0) +#define MAX77620_CNFG_GPIO_DRV_PUSHPULL (1 << 0) +#define MAX77620_CNFG_GPIO_DRV_OPENDRAIN 0 +#define MAX77620_CNFG_GPIO_DIR_MASK (1 << 1) +#define MAX77620_CNFG_GPIO_DIR_INPUT (1 << 1) +#define MAX77620_CNFG_GPIO_DIR_OUTPUT 0 +#define MAX77620_CNFG_GPIO_INPUT_VAL_MASK (1 << 2) +#define MAX77620_CNFG_GPIO_OUTPUT_VAL_MASK (1 << 3) +#define MAX77620_CNFG_GPIO_OUTPUT_VAL_HIGH (1 << 3) +#define MAX77620_CNFG_GPIO_OUTPUT_VAL_LOW 0 +#define MAX77620_CNFG_GPIO_INT_MASK (0x3 << 4) +#define MAX77620_CNFG_GPIO_INT_FALLING (1 << 4) +#define MAX77620_CNFG_GPIO_INT_RISING (1 << 5) +#define MAX77620_CNFG_GPIO_DBNC_MASK (0x3 << 6) +#define MAX77620_CNFG_GPIO_DBNC_None (0x0 << 6) +#define MAX77620_CNFG_GPIO_DBNC_8ms (0x1 << 6) +#define MAX77620_CNFG_GPIO_DBNC_16ms (0x2 << 6) +#define MAX77620_CNFG_GPIO_DBNC_32ms (0x3 << 6) + +#define MAX77620_IRQ_LVL2_GPIO_EDGE0 (1 << 0) +#define MAX77620_IRQ_LVL2_GPIO_EDGE1 (1 << 1) +#define MAX77620_IRQ_LVL2_GPIO_EDGE2 (1 << 2) +#define MAX77620_IRQ_LVL2_GPIO_EDGE3 (1 << 3) +#define MAX77620_IRQ_LVL2_GPIO_EDGE4 (1 << 4) +#define MAX77620_IRQ_LVL2_GPIO_EDGE5 (1 << 5) +#define MAX77620_IRQ_LVL2_GPIO_EDGE6 (1 << 6) +#define MAX77620_IRQ_LVL2_GPIO_EDGE7 (1 << 7) + +/* Interrupts */ +enum { + MAX77620_IRQ_TOP_GLBL, /* Low-Battery */ + MAX77620_IRQ_TOP_SD, /* SD power fail */ + MAX77620_IRQ_TOP_LDO, /* LDO power fail */ + MAX77620_IRQ_TOP_GPIO, /* TOP GPIO internal int to MAX77620 */ + MAX77620_IRQ_TOP_RTC, /* RTC */ + MAX77620_IRQ_TOP_32K, /* 32kHz oscillator */ + MAX77620_IRQ_TOP_ONOFF, /* ON/OFF oscillator */ + MAX77620_IRQ_LBT_MBATLOW, /* Thermal alarm status, > 120C */ + MAX77620_IRQ_LBT_TJALRM1, /* Thermal alarm status, > 120C */ + MAX77620_IRQ_LBT_TJALRM2, /* Thermal alarm status, > 140C */ +}; + +/* GPIOs */ +enum { + MAX77620_GPIO0, + MAX77620_GPIO1, + MAX77620_GPIO2, + MAX77620_GPIO3, + MAX77620_GPIO4, + MAX77620_GPIO5, + MAX77620_GPIO6, + MAX77620_GPIO7, + MAX77620_GPIO_NR, +}; + +/* FPS Source */ +enum max77620_fps_src { + MAX77620_FPS_SRC_0, + MAX77620_FPS_SRC_1, + MAX77620_FPS_SRC_2, + MAX77620_FPS_SRC_NONE, + MAX77620_FPS_SRC_DEF, +}; + +enum max77620_chip_id { + MAX77620, + MAX20024, +}; + +#endif /* _MFD_MAX77620_H_ */ diff --git a/nyx/nyx_gui/power/max7762x.c b/nyx/nyx_gui/power/max7762x.c new file mode 100644 index 0000000..2c8cff4 --- /dev/null +++ b/nyx/nyx_gui/power/max7762x.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "max7762x.h" +#include "max77620.h" +#include "../soc/i2c.h" +#include "../utils/util.h" + +#define REGULATOR_SD 0 +#define REGULATOR_LDO 1 + +typedef struct _max77620_regulator_t +{ + u8 type; + const char *name; + u8 reg_sd; + + u32 mv_step; + u32 mv_min; + u32 mv_default; + u32 mv_max; + + u8 volt_addr; + u8 cfg_addr; + + u8 volt_mask; + u8 enable_mask; + u8 enable_shift; + u8 status_mask; + + u8 fps_addr; + u8 fps_src; + u8 pd_period; + u8 pu_period; +} max77620_regulator_t; + +static const max77620_regulator_t _pmic_regulators[] = { + { REGULATOR_SD, "sd0", 0x16, 12500, 600000, 625000, 1400000, MAX77620_REG_SD0, MAX77620_REG_SD0_CFG, MAX77620_SD0_VOLT_MASK, MAX77620_SD_POWER_MODE_MASK, MAX77620_SD_POWER_MODE_SHIFT, 0x80, MAX77620_REG_FPS_SD0, 1, 7, 1 }, + { REGULATOR_SD, "sd1", 0x17, 12500, 600000, 1125000, 1125000, MAX77620_REG_SD1, MAX77620_REG_SD1_CFG, MAX77620_SD1_VOLT_MASK, MAX77620_SD_POWER_MODE_MASK, MAX77620_SD_POWER_MODE_SHIFT, 0x40, MAX77620_REG_FPS_SD1, 0, 1, 5 }, + { REGULATOR_SD, "sd2", 0x18, 12500, 600000, 1325000, 1350000, MAX77620_REG_SD2, MAX77620_REG_SD2_CFG, MAX77620_SDX_VOLT_MASK, MAX77620_SD_POWER_MODE_MASK, MAX77620_SD_POWER_MODE_SHIFT, 0x20, MAX77620_REG_FPS_SD2, 1, 5, 2 }, + { REGULATOR_SD, "sd3", 0x19, 12500, 600000, 1800000, 1800000, MAX77620_REG_SD3, MAX77620_REG_SD3_CFG, MAX77620_SDX_VOLT_MASK, MAX77620_SD_POWER_MODE_MASK, MAX77620_SD_POWER_MODE_SHIFT, 0x10, MAX77620_REG_FPS_SD3, 0, 3, 3 }, + { REGULATOR_LDO, "ldo0", 0x00, 25000, 800000, 1200000, 1200000, MAX77620_REG_LDO0_CFG, MAX77620_REG_LDO0_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO0, 3, 7, 0 }, + { REGULATOR_LDO, "ldo1", 0x00, 25000, 800000, 1050000, 1050000, MAX77620_REG_LDO1_CFG, MAX77620_REG_LDO1_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO1, 3, 7, 0 }, + { REGULATOR_LDO, "ldo2", 0x00, 50000, 800000, 1800000, 3300000, MAX77620_REG_LDO2_CFG, MAX77620_REG_LDO2_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO2, 3, 7, 0 }, + { REGULATOR_LDO, "ldo3", 0x00, 50000, 800000, 3100000, 3100000, MAX77620_REG_LDO3_CFG, MAX77620_REG_LDO3_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO3, 3, 7, 0 }, + { REGULATOR_LDO, "ldo4", 0x00, 12500, 800000, 850000, 850000, MAX77620_REG_LDO4_CFG, MAX77620_REG_LDO4_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO4, 0, 7, 1 }, + { REGULATOR_LDO, "ldo5", 0x00, 50000, 800000, 1800000, 1800000, MAX77620_REG_LDO5_CFG, MAX77620_REG_LDO5_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO5, 3, 7, 0 }, + { REGULATOR_LDO, "ldo6", 0x00, 50000, 800000, 2900000, 2900000, MAX77620_REG_LDO6_CFG, MAX77620_REG_LDO6_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO6, 3, 7, 0 }, + { REGULATOR_LDO, "ldo7", 0x00, 50000, 800000, 1050000, 1050000, MAX77620_REG_LDO7_CFG, MAX77620_REG_LDO7_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO7, 1, 4, 3 }, + { REGULATOR_LDO, "ldo8", 0x00, 50000, 800000, 1050000, 1050000, MAX77620_REG_LDO8_CFG, MAX77620_REG_LDO8_CFG2, MAX77620_LDO_VOLT_MASK, MAX77620_LDO_POWER_MODE_MASK, MAX77620_LDO_POWER_MODE_SHIFT, 0x00, MAX77620_REG_FPS_LDO8, 3, 7, 0 } +}; + +int max77620_regulator_get_status(u32 id) +{ + if (id > REGULATOR_MAX) + return 0; + + const max77620_regulator_t *reg = &_pmic_regulators[id]; + + if (reg->type == REGULATOR_SD) + return (i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_STATSD) & reg->status_mask) ? 0 : 1; + return (i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, reg->cfg_addr) & 8) ? 1 : 0; +} + +int max77620_regulator_config_fps(u32 id) +{ + if (id > REGULATOR_MAX) + return 0; + + const max77620_regulator_t *reg = &_pmic_regulators[id]; + + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, reg->fps_addr, + (reg->fps_src << MAX77620_FPS_SRC_SHIFT) | (reg->pu_period << MAX77620_FPS_PU_PERIOD_SHIFT) | (reg->pd_period)); + + return 1; +} + +int max77620_regulator_set_voltage(u32 id, u32 mv) +{ + if (id > REGULATOR_MAX) + return 0; + + const max77620_regulator_t *reg = &_pmic_regulators[id]; + + if (mv < reg->mv_min || mv > reg->mv_max) + return 0; + + u32 mult = (mv + reg->mv_step - 1 - reg->mv_min) / reg->mv_step; + u8 val = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, reg->volt_addr); + val = (val & ~reg->volt_mask) | (mult & reg->volt_mask); + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, reg->volt_addr, val); + usleep(1000); + + return 1; +} + +int max77620_regulator_enable(u32 id, int enable) +{ + if (id > REGULATOR_MAX) + return 0; + + const max77620_regulator_t *reg = &_pmic_regulators[id]; + + u32 addr = reg->type == REGULATOR_SD ? reg->cfg_addr : reg->volt_addr; + u8 val = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, addr); + if (enable) + val = (val & ~reg->enable_mask) | ((MAX77620_POWER_MODE_NORMAL << reg->enable_shift) & reg->enable_mask); + else + val &= ~reg->enable_mask; + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, addr, val); + usleep(1000); + + return 1; +} + +int max77620_regulator_set_volt_and_flags(u32 id, u32 mv, u8 flags) +{ + if (id > REGULATOR_MAX) + return 0; + + const max77620_regulator_t *reg = &_pmic_regulators[id]; + + if (mv < reg->mv_min || mv > reg->mv_max) + return 0; + + u32 mult = (mv + reg->mv_step - 1 - reg->mv_min) / reg->mv_step; + u8 val = ((flags << reg->enable_shift) & ~reg->volt_mask) | (mult & reg->volt_mask); + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, reg->volt_addr, val); + usleep(1000); + + return 1; +} + +void max77620_config_default() +{ + for (u32 i = 1; i <= REGULATOR_MAX; i++) + { + i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_CID4); + max77620_regulator_config_fps(i); + max77620_regulator_set_voltage(i, _pmic_regulators[i].mv_default); + if (_pmic_regulators[i].fps_src != MAX77620_FPS_SRC_NONE) + max77620_regulator_enable(i, 1); + } + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_SD_CFG2, 4); +} + +void max77620_low_battery_monitor_config() +{ + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_CNFGGLBL1, + MAX77620_CNFGGLBL1_LBDAC_EN | MAX77620_CNFGGLBL1_LBHYST_N | MAX77620_CNFGGLBL1_LBDAC_N); +} diff --git a/nyx/nyx_gui/power/max7762x.h b/nyx/nyx_gui/power/max7762x.h new file mode 100644 index 0000000..eefa112 --- /dev/null +++ b/nyx/nyx_gui/power/max7762x.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _MAX7762X_H_ +#define _MAX7762X_H_ + +#include "../utils/types.h" + +/* +* Switch Power domains (max77620): +* Name | Usage | uV step | uV min | uV default | uV max | Init +*-------+---------------+---------+--------+------------+---------+------------------ +* sd0 | core | 12500 | 600000 | 625000 | 1400000 | 1.125V (pkg1.1) +* sd1 | SDRAM | 12500 | 600000 | 1125000 | 1125000 | 1.1V (pkg1.1) +* sd2 | ldo{0-1, 7-8} | 12500 | 600000 | 1325000 | 1350000 | 1.325V (pcv) +* sd3 | 1.8V general | 12500 | 600000 | 1800000 | 1800000 | +* ldo0 | Display Panel | 25000 | 800000 | 1200000 | 1200000 | 1.2V (pkg1.1) +* ldo1 | XUSB, PCIE | 25000 | 800000 | 1050000 | 1050000 | 1.05V (pcv) +* ldo2 | SDMMC1 | 50000 | 800000 | 1800000 | 3300000 | +* ldo3 | GC ASIC | 50000 | 800000 | 3100000 | 3100000 | 3.1V (pcv) +* ldo4 | RTC | 12500 | 800000 | 850000 | 850000 | +* ldo5 | GC ASIC | 50000 | 800000 | 1800000 | 1800000 | 1.8V (pcv) +* ldo6 | Touch, ALS | 50000 | 800000 | 2900000 | 2900000 | 2.9V +* ldo7 | XUSB | 50000 | 800000 | 1050000 | 1050000 | +* ldo8 | XUSB, DC | 50000 | 800000 | 1050000 | 1050000 | +*/ + +/* +* MAX77620_AME_GPIO: control GPIO modes (bits 0 - 7 correspond to GPIO0 - GPIO7); 0 -> GPIO, 1 -> alt-mode +* MAX77620_REG_GPIOx: 0x9 sets output and enable +*/ + +/*! MAX77620 partitions. */ +#define REGULATOR_SD0 0 +#define REGULATOR_SD1 1 +#define REGULATOR_SD2 2 +#define REGULATOR_SD3 3 +#define REGULATOR_LDO0 4 +#define REGULATOR_LDO1 5 +#define REGULATOR_LDO2 6 +#define REGULATOR_LDO3 7 +#define REGULATOR_LDO4 8 +#define REGULATOR_LDO5 9 +#define REGULATOR_LDO6 10 +#define REGULATOR_LDO7 11 +#define REGULATOR_LDO8 12 +#define REGULATOR_MAX 12 + +#define MAX77621_CPU_I2C_ADDR 0x1B +#define MAX77621_GPU_I2C_ADDR 0x1C + +#define MAX77621_VOUT_REG 0 +#define MAX77621_VOUT_DVC_REG 1 +#define MAX77621_CONTROL1_REG 2 +#define MAX77621_CONTROL2_REG 3 + +/* MAX77621_VOUT */ +#define MAX77621_VOUT_ENABLE (1 << 7) +#define MAX77621_VOUT_MASK 0x7F + +/* MAX77621_VOUT_DVC_DVS */ +#define MAX77621_DVS_VOUT_MASK 0x7F + +/* MAX77621_CONTROL1 */ +#define MAX77621_SNS_ENABLE (1 << 7) +#define MAX77621_FPWM_EN_M (1 << 6) +#define MAX77621_NFSR_ENABLE (1 << 5) +#define MAX77621_AD_ENABLE (1 << 4) +#define MAX77621_BIAS_ENABLE (1 << 3) +#define MAX77621_FREQSHIFT_9PER (1 << 2) + +#define MAX77621_RAMP_12mV_PER_US 0x0 +#define MAX77621_RAMP_25mV_PER_US 0x1 +#define MAX77621_RAMP_50mV_PER_US 0x2 +#define MAX77621_RAMP_200mV_PER_US 0x3 +#define MAX77621_RAMP_MASK 0x3 + +/* MAX77621_CONTROL2 */ +#define MAX77621_WDTMR_ENABLE (1 << 6) +#define MAX77621_DISCH_ENBABLE (1 << 5) +#define MAX77621_FT_ENABLE (1 << 4) +#define MAX77621_T_JUNCTION_120 (1 << 7) + +#define MAX77621_CKKADV_TRIP_DISABLE 0xC +#define MAX77621_CKKADV_TRIP_75mV_PER_US 0x0 +#define MAX77621_CKKADV_TRIP_150mV_PER_US 0x4 +#define MAX77621_CKKADV_TRIP_75mV_PER_US_HIST_DIS 0x8 + +#define MAX77621_INDUCTOR_MIN_30_PER 0x0 +#define MAX77621_INDUCTOR_NOMINAL 0x1 +#define MAX77621_INDUCTOR_PLUS_30_PER 0x2 +#define MAX77621_INDUCTOR_PLUS_60_PER 0x3 + +int max77620_regulator_get_status(u32 id); +int max77620_regulator_config_fps(u32 id); +int max77620_regulator_set_voltage(u32 id, u32 mv); +int max77620_regulator_enable(u32 id, int enable); +int max77620_regulator_set_volt_and_flags(u32 id, u32 mv, u8 flags); +void max77620_config_default(); +void max77620_low_battery_monitor_config(); + +#endif diff --git a/nyx/nyx_gui/rtc/max77620-rtc.c b/nyx/nyx_gui/rtc/max77620-rtc.c new file mode 100644 index 0000000..85895af --- /dev/null +++ b/nyx/nyx_gui/rtc/max77620-rtc.c @@ -0,0 +1,77 @@ +/* + * PMIC Real Time Clock driver for Nintendo Switch's MAX77620-RTC + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "max77620-rtc.h" +#include "../soc/i2c.h" +#include "../utils/util.h" + +void max77620_rtc_get_time(rtc_time_t *time) +{ + u8 val = 0; + + // Update RTC regs from RTC clock. + i2c_send_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_UPDATE0_REG, MAX77620_RTC_READ_UPDATE); + + // Get control reg config. + val = i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_CONTROL_REG); + // TODO: Check for binary format also? + + // Get time. + time->sec = i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_SEC_REG) & 0x7F; + time->min = i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_MIN_REG) & 0x7F; + + time->hour = i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_HOUR_REG) & 0x1F; + + if (!(val & MAX77620_RTC_24H) && time->hour & MAX77620_RTC_HOUR_PM_MASK) + time->hour = (time->hour & 0xF) + 12; + + // Get day of week. 1: Monday to 7: Sunday. + time->weekday = 0; + val = i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_WEEKDAY_REG); + for (int i = 0; i < 8; i++) + { + time->weekday++; + if (val & 1) + break; + val >>= 1; + } + + // Get date. + time->date = i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_DATE_REG) & 0x1f; + time->month = (i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_MONTH_REG) & 0xF) - 1; + time->year = (i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_YEAR_REG) & 0x7F) + 2000; +} + +void max77620_rtc_stop_alarm() +{ + u8 val = 0; + + // Update RTC regs from RTC clock. + i2c_send_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_UPDATE0_REG, MAX77620_RTC_READ_UPDATE); + + // Stop alarm for both ALARM1 and ALARM2. Horizon uses ALARM2. + for (int i = 0; i < (MAX77620_RTC_NR_TIME_REGS * 2); i++) + { + val = i2c_recv_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_ALARM1_SEC_REG + i); + val &= ~MAX77620_RTC_ALARM_EN_MASK; + i2c_send_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_ALARM1_SEC_REG + i, val); + } + + // Update RTC clock from RTC regs. + i2c_send_byte(I2C_5, MAX77620_RTC_I2C_ADDR, MAX77620_RTC_UPDATE0_REG, MAX77620_RTC_WRITE_UPDATE); +} diff --git a/nyx/nyx_gui/rtc/max77620-rtc.h b/nyx/nyx_gui/rtc/max77620-rtc.h new file mode 100644 index 0000000..756e67c --- /dev/null +++ b/nyx/nyx_gui/rtc/max77620-rtc.h @@ -0,0 +1,75 @@ +/* + * PMIC Real Time Clock driver for Nintendo Switch's MAX77620-RTC + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _MFD_MAX77620_RTC_H_ +#define _MFD_MAX77620_RTC_H_ + +#include "../utils/types.h" + +#define MAX77620_RTC_I2C_ADDR 0x68 + +#define MAX77620_RTC_NR_TIME_REGS 7 + +#define MAX77620_RTC_CONTROLM_REG 0x02 +#define MAX77620_RTC_CONTROL_REG 0x03 +#define MAX77620_RTC_BIN_FORMAT (1 << 0) +#define MAX77620_RTC_24H (1 << 1) + +#define MAX77620_RTC_UPDATE0_REG 0x04 +#define MAX77620_RTC_WRITE_UPDATE (1 << 0) +#define MAX77620_RTC_READ_UPDATE (1 << 4) + +#define MAX77620_RTC_SEC_REG 0x07 +#define MAX77620_RTC_MIN_REG 0x08 +#define MAX77620_RTC_HOUR_REG 0x09 +#define MAX77620_RTC_HOUR_PM_MASK (1 << 6) +#define MAX77620_RTC_WEEKDAY_REG 0x0A +#define MAX77620_RTC_MONTH_REG 0x0B +#define MAX77620_RTC_YEAR_REG 0x0C +#define MAX77620_RTC_DATE_REG 0x0D + +#define MAX77620_ALARM1_SEC_REG 0x0E +#define MAX77620_ALARM1_MIN_REG 0x0F +#define MAX77620_ALARM1_HOUR_REG 0x10 +#define MAX77620_ALARM1_WEEKDAY_REG 0x11 +#define MAX77620_ALARM1_MONTH_REG 0x12 +#define MAX77620_ALARM1_YEAR_REG 0x13 +#define MAX77620_ALARM1_DATE_REG 0x14 +#define MAX77620_ALARM2_SEC_REG 0x15 +#define MAX77620_ALARM2_MIN_REG 0x16 +#define MAX77620_ALARM2_HOUR_REG 0x17 +#define MAX77620_ALARM2_WEEKDAY_REG 0x18 +#define MAX77620_ALARM2_MONTH_REG 0x19 +#define MAX77620_ALARM2_YEAR_REG 0x1A +#define MAX77620_ALARM2_DATE_REG 0x1B +#define MAX77620_RTC_ALARM_EN_MASK (1 << 7) + +typedef struct _rtc_time_t { + u8 weekday; + u8 sec; + u8 min; + u8 hour; + u8 date; + u8 month; + u16 year; +} rtc_time_t; + +void max77620_rtc_get_time(rtc_time_t *time); +void max77620_rtc_stop_alarm(); + +#endif /* _MFD_MAX77620_RTC_H_ */ diff --git a/nyx/nyx_gui/sec/se.c b/nyx/nyx_gui/sec/se.c new file mode 100644 index 0000000..794c39d --- /dev/null +++ b/nyx/nyx_gui/sec/se.c @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 CTCaer + * Copyright (c) 2018 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "../sec/se.h" +#include "../mem/heap.h" +#include "../soc/bpmp.h" +#include "../soc/t210.h" +#include "../sec/se_t210.h" +#include "../utils/util.h" + +typedef struct _se_ll_t +{ + vu32 num; + vu32 addr; + vu32 size; +} se_ll_t; + +static void _gf256_mul_x(void *block) +{ + u8 *pdata = (u8 *)block; + u32 carry = 0; + + for (int i = 0xF; i >= 0; i--) + { + u8 b = pdata[i]; + pdata[i] = (b << 1) | carry; + carry = b >> 7; + } + + if (carry) + pdata[0xF] ^= 0x87; +} + +static void _se_ll_init(se_ll_t *ll, u32 addr, u32 size) +{ + ll->num = 0; + ll->addr = addr; + ll->size = size; +} + +static void _se_ll_set(se_ll_t *dst, se_ll_t *src) +{ + SE(SE_IN_LL_ADDR_REG_OFFSET) = (u32)src; + SE(SE_OUT_LL_ADDR_REG_OFFSET) = (u32)dst; +} + +static int _se_wait() +{ + while (!(SE(SE_INT_STATUS_REG_OFFSET) & SE_INT_OP_DONE(INT_SET))) + ; + if (SE(SE_INT_STATUS_REG_OFFSET) & SE_INT_ERROR(INT_SET) || + SE(SE_STATUS_0) & 3 || + SE(SE_ERR_STATUS_0) != 0) + return 0; + return 1; +} + +static int _se_execute(u32 op, void *dst, u32 dst_size, const void *src, u32 src_size) +{ + bpmp_mmu_disable(); + + se_ll_t *ll_dst = NULL, *ll_src = NULL; + + if (dst) + { + ll_dst = (se_ll_t *)malloc(sizeof(se_ll_t)); + _se_ll_init(ll_dst, (u32)dst, dst_size); + } + + if (src) + { + ll_src = (se_ll_t *)malloc(sizeof(se_ll_t)); + _se_ll_init(ll_src, (u32)src, src_size); + } + + _se_ll_set(ll_dst, ll_src); + + SE(SE_ERR_STATUS_0) = SE(SE_ERR_STATUS_0); + SE(SE_INT_STATUS_REG_OFFSET) = SE(SE_INT_STATUS_REG_OFFSET); + SE(SE_OPERATION_REG_OFFSET) = SE_OPERATION(op); + + int res = _se_wait(); + + if (src) + free(ll_src); + if (dst) + free(ll_dst); + + bpmp_mmu_enable(); + + return res; +} + +static int _se_execute_one_block(u32 op, void *dst, u32 dst_size, const void *src, u32 src_size) +{ + if (!src || !dst) + return 0; + + u8 *block = (u8 *)malloc(0x10); + memset(block, 0, 0x10); + + SE(SE_BLOCK_COUNT_REG_OFFSET) = 0; + + memcpy(block, src, src_size); + int res = _se_execute(op, block, 0x10, block, 0x10); + memcpy(dst, block, dst_size); + + free(block); + return res; +} + +static void _se_aes_ctr_set(void *ctr) +{ + u32 *data = (u32 *)ctr; + for (u32 i = 0; i < 4; i++) + SE(SE_CRYPTO_CTR_REG_OFFSET + 4 * i) = data[i]; +} + +void se_rsa_acc_ctrl(u32 rs, u32 flags) +{ + if (flags & 0x7F) + SE(SE_RSA_KEYTABLE_ACCESS_REG_OFFSET + 4 * rs) = (((flags >> 4) & 4) | (flags & 3)) ^ 7; + if (flags & 0x80) + SE(SE_RSA_KEYTABLE_ACCESS_LOCK_OFFSET) &= ~(1 << rs); +} + +void se_key_acc_ctrl(u32 ks, u32 flags) +{ + if (flags & 0x7F) + SE(SE_KEY_TABLE_ACCESS_REG_OFFSET + 4 * ks) = ~flags; + if (flags & 0x80) + SE(SE_KEY_TABLE_ACCESS_LOCK_OFFSET) &= ~(1 << ks); +} + +void se_aes_key_set(u32 ks, void *key, u32 size) +{ + u32 *data = (u32 *)key; + for (u32 i = 0; i < size / 4; i++) + { + SE(SE_KEYTABLE_REG_OFFSET) = SE_KEYTABLE_SLOT(ks) | i; + SE(SE_KEYTABLE_DATA0_REG_OFFSET) = data[i]; + } +} + +void se_aes_key_clear(u32 ks) +{ + for (u32 i = 0; i < TEGRA_SE_AES_MAX_KEY_SIZE / 4; i++) + { + SE(SE_KEYTABLE_REG_OFFSET) = SE_KEYTABLE_SLOT(ks) | i; + SE(SE_KEYTABLE_DATA0_REG_OFFSET) = 0; + } +} + +int se_aes_unwrap_key(u32 ks_dst, u32 ks_src, const void *input) +{ + SE(SE_CONFIG_REG_OFFSET) = SE_CONFIG_DEC_ALG(ALG_AES_DEC) | SE_CONFIG_DST(DST_KEYTAB); + SE(SE_CRYPTO_REG_OFFSET) = SE_CRYPTO_KEY_INDEX(ks_src) | SE_CRYPTO_CORE_SEL(CORE_DECRYPT); + SE(SE_BLOCK_COUNT_REG_OFFSET) = 0; + SE(SE_CRYPTO_KEYTABLE_DST_REG_OFFSET) = SE_CRYPTO_KEYTABLE_DST_KEY_INDEX(ks_dst); + + return _se_execute(OP_START, NULL, 0, input, 0x10); +} + +int se_aes_crypt_block_ecb(u32 ks, u32 enc, void *dst, const void *src) +{ + if (enc) + { + SE(SE_CONFIG_REG_OFFSET) = SE_CONFIG_ENC_ALG(ALG_AES_ENC) | SE_CONFIG_DST(DST_MEMORY); + SE(SE_CRYPTO_REG_OFFSET) = SE_CRYPTO_KEY_INDEX(ks) | SE_CRYPTO_CORE_SEL(CORE_ENCRYPT); + } + else + { + SE(SE_CONFIG_REG_OFFSET) = SE_CONFIG_DEC_ALG(ALG_AES_DEC) | SE_CONFIG_DST(DST_MEMORY); + SE(SE_CRYPTO_REG_OFFSET) = SE_CRYPTO_KEY_INDEX(ks) | SE_CRYPTO_CORE_SEL(CORE_DECRYPT); + } + SE(SE_BLOCK_COUNT_REG_OFFSET) = 0; + return _se_execute(OP_START, dst, 0x10, src, 0x10); +} + +int se_aes_crypt_ctr(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size, void *ctr) +{ + SE(SE_SPARE_0_REG_OFFSET) = 1; + SE(SE_CONFIG_REG_OFFSET) = SE_CONFIG_ENC_ALG(ALG_AES_ENC) | SE_CONFIG_DST(DST_MEMORY); + SE(SE_CRYPTO_REG_OFFSET) = SE_CRYPTO_KEY_INDEX(ks) | SE_CRYPTO_CORE_SEL(CORE_ENCRYPT) | + SE_CRYPTO_XOR_POS(XOR_BOTTOM) | SE_CRYPTO_INPUT_SEL(INPUT_LNR_CTR) | SE_CRYPTO_CTR_VAL(1); + _se_aes_ctr_set(ctr); + + u32 src_size_aligned = src_size & 0xFFFFFFF0; + u32 src_size_delta = src_size & 0xF; + + if (src_size_aligned) + { + SE(SE_BLOCK_COUNT_REG_OFFSET) = (src_size >> 4) - 1; + if (!_se_execute(OP_START, dst, dst_size, src, src_size_aligned)) + return 0; + } + + if (src_size - src_size_aligned && src_size_aligned < dst_size) + return _se_execute_one_block(OP_START, dst + src_size_aligned, + MIN(src_size_delta, dst_size - src_size_aligned), + src + src_size_aligned, src_size_delta); + + return 1; +} + +int se_aes_xts_crypt_sec(u32 ks1, u32 ks2, u32 enc, u64 sec, void *dst, void *src, u32 secsize) +{ + int res = 0; + u8 *tweak = (u8 *)malloc(0x10); + u8 *pdst = (u8 *)dst; + u8 *psrc = (u8 *)src; + + //Generate tweak. + for (int i = 0xF; i >= 0; i--) + { + tweak[i] = sec & 0xFF; + sec >>= 8; + } + if (!se_aes_crypt_block_ecb(ks1, 1, tweak, tweak)) + goto out; + + //We are assuming a 0x10-aligned sector size in this implementation. + for (u32 i = 0; i < secsize / 0x10; i++) + { + for (u32 j = 0; j < 0x10; j++) + pdst[j] = psrc[j] ^ tweak[j]; + if (!se_aes_crypt_block_ecb(ks2, enc, pdst, pdst)) + goto out; + for (u32 j = 0; j < 0x10; j++) + pdst[j] = pdst[j] ^ tweak[j]; + _gf256_mul_x(tweak); + psrc += 0x10; + pdst += 0x10; + } + + res = 1; + +out:; + free(tweak); + return res; +} + +int se_aes_xts_crypt(u32 ks1, u32 ks2, u32 enc, u64 sec, void *dst, void *src, u32 secsize, u32 num_secs) +{ + u8 *pdst = (u8 *)dst; + u8 *psrc = (u8 *)src; + + for (u32 i = 0; i < num_secs; i++) + if (!se_aes_xts_crypt_sec(ks1, ks2, enc, sec + i, pdst + secsize * i, psrc + secsize * i, secsize)) + return 0; + + return 1; +} + +// se_calc_sha256() was derived from Atmosphère's se_calculate_sha256. +int se_calc_sha256(void *dst, const void *src, u32 src_size) +{ + int res; + // Setup config for SHA256, size = BITS(src_size). + SE(SE_CONFIG_REG_OFFSET) = SE_CONFIG_ENC_MODE(MODE_SHA256) | SE_CONFIG_ENC_ALG(ALG_SHA) | SE_CONFIG_DST(DST_HASHREG); + SE(SE_SHA_CONFIG_REG_OFFSET) = SHA_ENABLE; + SE(SE_SHA_MSG_LENGTH_REG_OFFSET) = (u32)(src_size << 3); + SE(SE_SHA_MSG_LENGTH_REG_OFFSET + 4 * 1) = 0; + SE(SE_SHA_MSG_LENGTH_REG_OFFSET + 4 * 2) = 0; + SE(SE_SHA_MSG_LENGTH_REG_OFFSET + 4 * 3) = 0; + SE(SE_SHA_MSG_LEFT_REG_OFFSET) = (u32)(src_size << 3); + SE(SE_SHA_MSG_LEFT_REG_OFFSET + 4 * 1) = 0; + SE(SE_SHA_MSG_LEFT_REG_OFFSET + 4 * 2) = 0; + SE(SE_SHA_MSG_LEFT_REG_OFFSET + 4 * 3) = 0; + + // Trigger the operation. + res = _se_execute(OP_START, NULL, 0, src, src_size); + + // Copy output hash. + u32 *dst32 = (u32 *)dst; + for (u32 i = 0; i < 8; i++) + dst32[i] = byte_swap_32(SE(SE_HASH_RESULT_REG_OFFSET + (i << 2))); + + return res; +} + diff --git a/nyx/nyx_gui/sec/se.h b/nyx/nyx_gui/sec/se.h new file mode 100644 index 0000000..350463e --- /dev/null +++ b/nyx/nyx_gui/sec/se.h @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2018 naehrwert +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef _SE_H_ +#define _SE_H_ + +#include "../utils/types.h" + +void se_rsa_acc_ctrl(u32 rs, u32 flags); +void se_key_acc_ctrl(u32 ks, u32 flags); +void se_aes_key_set(u32 ks, void *key, u32 size); +void se_aes_key_clear(u32 ks); +int se_aes_unwrap_key(u32 ks_dst, u32 ks_src, const void *input); +int se_aes_crypt_block_ecb(u32 ks, u32 enc, void *dst, const void *src); +int se_aes_crypt_ctr(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size, void *ctr); +int se_calc_sha256(void *dst, const void *src, u32 src_size); + +#endif diff --git a/nyx/nyx_gui/sec/se_t210.h b/nyx/nyx_gui/sec/se_t210.h new file mode 100644 index 0000000..760527d --- /dev/null +++ b/nyx/nyx_gui/sec/se_t210.h @@ -0,0 +1,357 @@ +/* +* Driver for Tegra Security Engine +* +* Copyright (c) 2011-2013, NVIDIA Corporation. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef _CRYPTO_TEGRA_SE_H +#define _CRYPTO_TEGRA_SE_H + +#include "../utils/types.h" + +#define TEGRA_SE_CRA_PRIORITY 300 +#define TEGRA_SE_COMPOSITE_PRIORITY 400 +#define TEGRA_SE_CRYPTO_QUEUE_LENGTH 50 +#define SE_MAX_SRC_SG_COUNT 50 +#define SE_MAX_DST_SG_COUNT 50 + +#define TEGRA_SE_KEYSLOT_COUNT 16 +#define SE_MAX_LAST_BLOCK_SIZE 0xFFFFF + +/* SE register definitions */ +#define SE_SECURITY_0 0x000 +#define SE_KEY_SCHED_READ_SHIFT 3 + +#define SE_CONFIG_REG_OFFSET 0x014 +#define SE_CONFIG_ENC_ALG_SHIFT 12 +#define SE_CONFIG_DEC_ALG_SHIFT 8 +#define ALG_AES_ENC 1 +#define ALG_RNG 2 +#define ALG_SHA 3 +#define ALG_RSA 4 +#define ALG_NOP 0 +#define ALG_AES_DEC 1 +#define SE_CONFIG_ENC_ALG(x) (x << SE_CONFIG_ENC_ALG_SHIFT) +#define SE_CONFIG_DEC_ALG(x) (x << SE_CONFIG_DEC_ALG_SHIFT) +#define SE_CONFIG_DST_SHIFT 2 +#define DST_MEMORY 0 +#define DST_HASHREG 1 +#define DST_KEYTAB 2 +#define DST_SRK 3 +#define DST_RSAREG 4 +#define SE_CONFIG_DST(x) (x << SE_CONFIG_DST_SHIFT) +#define SE_CONFIG_ENC_MODE_SHIFT 24 +#define SE_CONFIG_DEC_MODE_SHIFT 16 +#define MODE_KEY128 0 +#define MODE_KEY192 1 +#define MODE_KEY256 2 +#define MODE_SHA1 0 +#define MODE_SHA224 4 +#define MODE_SHA256 5 +#define MODE_SHA384 6 +#define MODE_SHA512 7 +#define SE_CONFIG_ENC_MODE(x) (x << SE_CONFIG_ENC_MODE_SHIFT) +#define SE_CONFIG_DEC_MODE(x) (x << SE_CONFIG_DEC_MODE_SHIFT) + +#define SE_RNG_CONFIG_REG_OFFSET 0x340 +#define DRBG_MODE_SHIFT 0 +#define DRBG_MODE_NORMAL 0 +#define DRBG_MODE_FORCE_INSTANTION 1 +#define DRBG_MODE_FORCE_RESEED 2 +#define SE_RNG_CONFIG_MODE(x) (x << DRBG_MODE_SHIFT) + +#define SE_RNG_SRC_CONFIG_REG_OFFSET 0x344 +#define DRBG_RO_ENT_SRC_SHIFT 1 +#define DRBG_RO_ENT_SRC_ENABLE 1 +#define DRBG_RO_ENT_SRC_DISABLE 0 +#define SE_RNG_SRC_CONFIG_RO_ENT_SRC(x) (x << DRBG_RO_ENT_SRC_SHIFT) +#define DRBG_RO_ENT_SRC_LOCK_SHIFT 0 +#define DRBG_RO_ENT_SRC_LOCK_ENABLE 1 +#define DRBG_RO_ENT_SRC_LOCK_DISABLE 0 +#define SE_RNG_SRC_CONFIG_RO_ENT_SRC_LOCK(x) (x << DRBG_RO_ENT_SRC_LOCK_SHIFT) + +#define DRBG_SRC_SHIFT 2 +#define DRBG_SRC_NONE 0 +#define DRBG_SRC_ENTROPY 1 +#define DRBG_SRC_LFSR 2 +#define SE_RNG_CONFIG_SRC(x) (x << DRBG_SRC_SHIFT) + +#define SE_RNG_RESEED_INTERVAL_REG_OFFSET 0x348 + +#define SE_KEYTABLE_REG_OFFSET 0x31c +#define SE_KEYTABLE_SLOT_SHIFT 4 +#define SE_KEYTABLE_SLOT(x) (x << SE_KEYTABLE_SLOT_SHIFT) +#define SE_KEYTABLE_QUAD_SHIFT 2 +#define QUAD_KEYS_128 0 +#define QUAD_KEYS_192 1 +#define QUAD_KEYS_256 1 +#define QUAD_ORG_IV 2 +#define QUAD_UPDTD_IV 3 +#define SE_KEYTABLE_QUAD(x) (x << SE_KEYTABLE_QUAD_SHIFT) +#define SE_KEYTABLE_OP_TYPE_SHIFT 9 +#define OP_READ 0 +#define OP_WRITE 1 +#define SE_KEYTABLE_OP_TYPE(x) (x << SE_KEYTABLE_OP_TYPE_SHIFT) +#define SE_KEYTABLE_TABLE_SEL_SHIFT 8 +#define TABLE_KEYIV 0 +#define TABLE_SCHEDULE 1 +#define SE_KEYTABLE_TABLE_SEL(x) (x << SE_KEYTABLE_TABLE_SEL_SHIFT) +#define SE_KEYTABLE_PKT_SHIFT 0 +#define SE_KEYTABLE_PKT(x) (x << SE_KEYTABLE_PKT_SHIFT) + +#define SE_OP_DONE_SHIFT 4 +#define OP_DONE 1 +#define SE_OP_DONE(x, y) ((x) && (y << SE_OP_DONE_SHIFT)) + +#define SE_CRYPTO_REG_OFFSET 0x304 +#define SE_CRYPTO_HASH_SHIFT 0 +#define HASH_DISABLE 0 +#define HASH_ENABLE 1 +#define SE_CRYPTO_HASH(x) (x << SE_CRYPTO_HASH_SHIFT) +#define SE_CRYPTO_XOR_POS_SHIFT 1 +#define XOR_BYPASS 0 +#define XOR_TOP 2 +#define XOR_BOTTOM 3 +#define SE_CRYPTO_XOR_POS(x) (x << SE_CRYPTO_XOR_POS_SHIFT) +#define SE_CRYPTO_INPUT_SEL_SHIFT 3 +#define INPUT_AHB 0 +#define INPUT_RANDOM 1 +#define INPUT_AESOUT 2 +#define INPUT_LNR_CTR 3 +#define SE_CRYPTO_INPUT_SEL(x) (x << SE_CRYPTO_INPUT_SEL_SHIFT) +#define SE_CRYPTO_VCTRAM_SEL_SHIFT 5 +#define VCTRAM_AHB 0 +#define VCTRAM_AESOUT 2 +#define VCTRAM_PREVAHB 3 +#define SE_CRYPTO_VCTRAM_SEL(x) (x << SE_CRYPTO_VCTRAM_SEL_SHIFT) +#define SE_CRYPTO_IV_SEL_SHIFT 7 +#define IV_ORIGINAL 0 +#define IV_UPDATED 1 +#define SE_CRYPTO_IV_SEL(x) (x << SE_CRYPTO_IV_SEL_SHIFT) +#define SE_CRYPTO_CORE_SEL_SHIFT 8 +#define CORE_DECRYPT 0 +#define CORE_ENCRYPT 1 +#define SE_CRYPTO_CORE_SEL(x) (x << SE_CRYPTO_CORE_SEL_SHIFT) +#define SE_CRYPTO_CTR_VAL_SHIFT 11 +#define SE_CRYPTO_CTR_VAL(x) (x << SE_CRYPTO_CTR_VAL_SHIFT) +#define SE_CRYPTO_KEY_INDEX_SHIFT 24 +#define SE_CRYPTO_KEY_INDEX(x) (x << SE_CRYPTO_KEY_INDEX_SHIFT) +#define SE_CRYPTO_CTR_CNTN_SHIFT 11 +#define SE_CRYPTO_CTR_CNTN(x) (x << SE_CRYPTO_CTR_CNTN_SHIFT) + +#define SE_CRYPTO_CTR_REG_COUNT 4 +#define SE_CRYPTO_CTR_REG_OFFSET 0x308 + +#define SE_OPERATION_REG_OFFSET 0x008 +#define SE_OPERATION_SHIFT 0 +#define OP_ABORT 0 +#define OP_START 1 +#define OP_RESTART 2 +#define OP_CTX_SAVE 3 +#define OP_RESTART_IN 4 +#define SE_OPERATION(x) (x << SE_OPERATION_SHIFT) + +#define SE_CONTEXT_SAVE_CONFIG_REG_OFFSET 0x070 +#define SE_CONTEXT_SAVE_WORD_QUAD_SHIFT 0 +#define KEYS_0_3 0 +#define KEYS_4_7 1 +#define ORIG_IV 2 +#define UPD_IV 3 +#define SE_CONTEXT_SAVE_WORD_QUAD(x) (x << SE_CONTEXT_SAVE_WORD_QUAD_SHIFT) + +#define SE_CONTEXT_SAVE_KEY_INDEX_SHIFT 8 +#define SE_CONTEXT_SAVE_KEY_INDEX(x) (x << SE_CONTEXT_SAVE_KEY_INDEX_SHIFT) + +#define SE_CONTEXT_SAVAE_STICKY_WORD_QUAD_SHIFT 24 +#define STICKY_0_3 0 +#define STICKY_4_7 1 +#define SE_CONTEXT_SAVE_STICKY_WORD_QUAD(x) \ + (x << SE_CONTEXT_SAVAE_STICKY_WORD_QUAD_SHIFT) + +#define SE_CONTEXT_SAVE_SRC_SHIFT 29 +#define STICKY_BITS 0 +#define KEYTABLE 2 +#define MEM 4 +#define SRK 6 + +#define RSA_KEYTABLE 1 +#define SE_CONTEXT_SAVE_SRC(x) (x << SE_CONTEXT_SAVE_SRC_SHIFT) + +#define SE_CONTEXT_SAVE_RSA_KEY_INDEX_SHIFT 16 +#define SE_CONTEXT_SAVE_RSA_KEY_INDEX(x) \ + (x << SE_CONTEXT_SAVE_RSA_KEY_INDEX_SHIFT) + +#define SE_CONTEXT_RSA_WORD_QUAD_SHIFT 12 +#define SE_CONTEXT_RSA_WORD_QUAD(x) \ + (x << SE_CONTEXT_RSA_WORD_QUAD_SHIFT) + +#define SE_INT_ENABLE_REG_OFFSET 0x00c +#define SE_INT_STATUS_REG_OFFSET 0x010 +#define INT_DISABLE 0 +#define INT_ENABLE 1 +#define INT_UNSET 0 +#define INT_SET 1 +#define SE_INT_OP_DONE_SHIFT 4 +#define SE_INT_OP_DONE(x) (x << SE_INT_OP_DONE_SHIFT) +#define SE_INT_ERROR_SHIFT 16 +#define SE_INT_ERROR(x) (x << SE_INT_ERROR_SHIFT) +#define SE_STATUS_0 0x800 +#define SE_ERR_STATUS_0 0x804 + +#define SE_CRYPTO_KEYTABLE_DST_REG_OFFSET 0X330 +#define SE_CRYPTO_KEYTABLE_DST_WORD_QUAD_SHIFT 0 +#define SE_CRYPTO_KEYTABLE_DST_WORD_QUAD(x) \ + (x << SE_CRYPTO_KEYTABLE_DST_WORD_QUAD_SHIFT) + +#define SE_KEY_INDEX_SHIFT 8 +#define SE_CRYPTO_KEYTABLE_DST_KEY_INDEX(x) (x << SE_KEY_INDEX_SHIFT) + +#define SE_IN_LL_ADDR_REG_OFFSET 0x018 +#define SE_OUT_LL_ADDR_REG_OFFSET 0x024 + +#define SE_KEYTABLE_DATA0_REG_OFFSET 0x320 +#define SE_KEYTABLE_REG_MAX_DATA 16 + +#define SE_BLOCK_COUNT_REG_OFFSET 0x318 + +#define SE_SPARE_0_REG_OFFSET 0x80c + +#define SE_SHA_CONFIG_REG_OFFSET 0x200 +#define SHA_DISABLE 0 +#define SHA_ENABLE 1 + +#define SE_SHA_MSG_LENGTH_REG_OFFSET 0x204 +#define SE_SHA_MSG_LEFT_REG_OFFSET 0x214 + +#define SE_HASH_RESULT_REG_COUNT 16 +#define SE_HASH_RESULT_REG_OFFSET 0x030 +#define TEGRA_SE_KEY_256_SIZE 32 +#define TEGRA_SE_KEY_192_SIZE 24 +#define TEGRA_SE_KEY_128_SIZE 16 +#define TEGRA_SE_AES_BLOCK_SIZE 16 +#define TEGRA_SE_AES_MIN_KEY_SIZE 16 +#define TEGRA_SE_AES_MAX_KEY_SIZE 32 +#define TEGRA_SE_AES_IV_SIZE 16 +#define TEGRA_SE_RNG_IV_SIZE 16 +#define TEGRA_SE_RNG_DT_SIZE 16 +#define TEGRA_SE_RNG_KEY_SIZE 16 +#define TEGRA_SE_RNG_SEED_SIZE (TEGRA_SE_RNG_IV_SIZE + \ + TEGRA_SE_RNG_KEY_SIZE + \ + TEGRA_SE_RNG_DT_SIZE) + +#define TEGRA_SE_AES_CMAC_DIGEST_SIZE 16 +#define TEGRA_SE_RSA512_DIGEST_SIZE 64 +#define TEGRA_SE_RSA1024_DIGEST_SIZE 128 +#define TEGRA_SE_RSA1536_DIGEST_SIZE 192 +#define TEGRA_SE_RSA2048_DIGEST_SIZE 256 + +#define SE_KEY_TABLE_ACCESS_LOCK_OFFSET 0x280 +#define SE_KEY_TABLE_ACCESS_REG_OFFSET 0x284 +#define SE_KEY_READ_DISABLE_SHIFT 0 +#define SE_KEY_UPDATE_DISABLE_SHIFT 1 + +#define SE_CONTEXT_BUFER_SIZE 1072 +#define SE_CONTEXT_DRBG_BUFER_SIZE 2112 + +#define SE_CONTEXT_SAVE_RANDOM_DATA_OFFSET 0 +#define SE_CONTEXT_SAVE_RANDOM_DATA_SIZE 16 +#define SE_CONTEXT_SAVE_STICKY_BITS_OFFSET \ + (SE_CONTEXT_SAVE_RANDOM_DATA_OFFSET + SE_CONTEXT_SAVE_RANDOM_DATA_SIZE) +#define SE_CONTEXT_SAVE_STICKY_BITS_SIZE 16 + +#define SE_CONTEXT_SAVE_KEYS_OFFSET (SE_CONTEXT_SAVE_STICKY_BITS_OFFSET + \ + SE_CONTEXT_SAVE_STICKY_BITS_SIZE) +#define SE11_CONTEXT_SAVE_KEYS_OFFSET (SE_CONTEXT_SAVE_STICKY_BITS_OFFSET + \ + SE_CONTEXT_SAVE_STICKY_BITS_SIZE + \ + SE_CONTEXT_SAVE_STICKY_BITS_SIZE) + +#define SE_CONTEXT_SAVE_KEY_LENGTH 512 +#define SE_CONTEXT_ORIGINAL_IV_OFFSET (SE_CONTEXT_SAVE_KEYS_OFFSET + \ + SE_CONTEXT_SAVE_KEY_LENGTH) +#define SE11_CONTEXT_ORIGINAL_IV_OFFSET (SE11_CONTEXT_SAVE_KEYS_OFFSET + \ + SE_CONTEXT_SAVE_KEY_LENGTH) + +#define SE_CONTEXT_ORIGINAL_IV_LENGTH 256 + +#define SE_CONTEXT_UPDATED_IV_OFFSET (SE_CONTEXT_ORIGINAL_IV_OFFSET + \ + SE_CONTEXT_ORIGINAL_IV_LENGTH) +#define SE11_CONTEXT_UPDATED_IV_OFFSET (SE11_CONTEXT_ORIGINAL_IV_OFFSET + \ + SE_CONTEXT_ORIGINAL_IV_LENGTH) + +#define SE_CONTEXT_UPDATED_IV_LENGTH 256 + +#define SE_CONTEXT_SAVE_KNOWN_PATTERN_OFFSET (SE_CONTEXT_UPDATED_IV_OFFSET + \ + SE_CONTEXT_UPDATED_IV_LENGTH) +#define SE11_CONTEXT_SAVE_KNOWN_PATTERN_OFFSET \ + (SE11_CONTEXT_UPDATED_IV_OFFSET + \ + SE_CONTEXT_UPDATED_IV_LENGTH) + +#define SE_CONTEXT_SAVE_RSA_KEYS_OFFSET SE11_CONTEXT_SAVE_KNOWN_PATTERN_OFFSET + +#define SE_CONTEXT_SAVE_RSA_KEY_LENGTH 1024 + +#define SE_CONTEXT_SAVE_RSA_KNOWN_PATTERN_OFFSET \ + (SE_CONTEXT_SAVE_RSA_KEYS_OFFSET + SE_CONTEXT_SAVE_RSA_KEY_LENGTH) + +#define SE_CONTEXT_KNOWN_PATTERN_SIZE 16 + +#define TEGRA_SE_RSA_KEYSLOT_COUNT 2 + +#define SE_RSA_KEYTABLE_ACCESS_LOCK_OFFSET 0x40C +#define SE_RSA_KEYTABLE_ACCESS_REG_OFFSET 0x410 + +#define SE_RSA_KEYTABLE_ADDR 0x420 +#define SE_RSA_KEYTABLE_DATA 0x424 +#define SE_RSA_OUTPUT 0x428 + +#define RSA_KEY_READ 0 +#define RSA_KEY_WRITE 1 +#define SE_RSA_KEY_OP_SHIFT 10 +#define SE_RSA_KEY_OP(x) (x << SE_RSA_KEY_OP_SHIFT) + +#define RSA_KEY_INPUT_MODE_REG 0 +#define RSA_KEY_INPUT_MODE_DMA 1 +#define RSA_KEY_INPUT_MODE_SHIFT 8 +#define RSA_KEY_INPUT_MODE(x) (x << RSA_KEY_INPUT_MODE_SHIFT) + +#define RSA_KEY_SLOT_ONE 0 +#define RSA_KEY_SLOT_TW0 1 +#define RSA_KEY_NUM_SHIFT 7 +#define RSA_KEY_NUM(x) (x << RSA_KEY_NUM_SHIFT) + +#define RSA_KEY_TYPE_EXP 0 +#define RSA_KEY_TYPE_MOD 1 +#define RSA_KEY_TYPE_SHIFT 6 +#define RSA_KEY_TYPE(x) (x << RSA_KEY_TYPE_SHIFT) + +#define SE_RSA_KEY_SIZE_REG_OFFSET 0x404 +#define SE_RSA_EXP_SIZE_REG_OFFSET 0x408 + +#define RSA_KEY_SLOT_SHIFT 24 +#define RSA_KEY_SLOT(x) (x << RSA_KEY_SLOT_SHIFT) +#define SE_RSA_CONFIG 0x400 + +#define RSA_KEY_PKT_WORD_ADDR_SHIFT 0 +#define RSA_KEY_PKT_WORD_ADDR(x) (x << RSA_KEY_PKT_WORD_ADDR_SHIFT) + +#define RSA_KEY_WORD_ADDR_SHIFT 0 +#define RSA_KEY_WORD_ADDR(x) (x << RSA_KEY_WORD_ADDR_SHIFT) + +#define SE_RSA_KEYTABLE_PKT_SHIFT 0 +#define SE_RSA_KEYTABLE_PKT(x) (x << SE_RSA_KEYTABLE_PKT_SHIFT) + +#endif /* _CRYPTO_TEGRA_SE_H */ diff --git a/nyx/nyx_gui/sec/tsec.c b/nyx/nyx_gui/sec/tsec.c new file mode 100644 index 0000000..fe1256d --- /dev/null +++ b/nyx/nyx_gui/sec/tsec.c @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018-2019 CTCaer + * Copyright (c) 2018 balika011 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "../sec/tsec.h" +#include "../sec/tsec_t210.h" +#include "../sec/se_t210.h" +#include "../soc/bpmp.h" +#include "../soc/clock.h" +#include "../soc/smmu.h" +#include "../soc/t210.h" +#include "../mem/heap.h" +#include "../mem/mc.h" +#include "../utils/util.h" +#include "../hos/hos.h" + +// #include "../gfx/gfx.h" + +static int _tsec_dma_wait_idle() +{ + u32 timeout = get_tmr_ms() + 10000; + + while (!(TSEC(TSEC_DMATRFCMD) & TSEC_DMATRFCMD_IDLE)) + if (get_tmr_ms() > timeout) + return 0; + + return 1; +} + +static int _tsec_dma_pa_to_internal_100(int not_imem, int i_offset, int pa_offset) +{ + u32 cmd; + + if (not_imem) + cmd = TSEC_DMATRFCMD_SIZE_256B; // DMA 256 bytes + else + cmd = TSEC_DMATRFCMD_IMEM; // DMA IMEM (Instruction memmory) + + TSEC(TSEC_DMATRFMOFFS) = i_offset; + TSEC(TSEC_DMATRFFBOFFS) = pa_offset; + TSEC(TSEC_DMATRFCMD) = cmd; + + return _tsec_dma_wait_idle(); +} + +int tsec_query(u8 *tsec_keys, u8 kb, tsec_ctxt_t *tsec_ctxt) +{ + int res = 0; + u8 *fwbuf = NULL; + u32 *pdir, *car, *fuse, *pmc, *flowctrl, *se, *mc, *iram, *evec; + u32 *pkg11_magic_off; + + bpmp_mmu_disable(); + bpmp_clk_rate_set(BPMP_CLK_NORMAL); + + //Enable clocks. + clock_enable_host1x(); + clock_enable_tsec(); + clock_enable_sor_safe(); + clock_enable_sor0(); + clock_enable_sor1(); + clock_enable_kfuse(); + + //Configure Falcon. + TSEC(TSEC_DMACTL) = 0; + TSEC(TSEC_IRQMSET) = + TSEC_IRQMSET_EXT(0xFF) | + TSEC_IRQMSET_WDTMR | + TSEC_IRQMSET_HALT | + TSEC_IRQMSET_EXTERR | + TSEC_IRQMSET_SWGEN0 | + TSEC_IRQMSET_SWGEN1; + TSEC(TSEC_IRQDEST) = + TSEC_IRQDEST_EXT(0xFF) | + TSEC_IRQDEST_HALT | + TSEC_IRQDEST_EXTERR | + TSEC_IRQDEST_SWGEN0 | + TSEC_IRQDEST_SWGEN1; + TSEC(TSEC_ITFEN) = TSEC_ITFEN_CTXEN | TSEC_ITFEN_MTHDEN; + if (!_tsec_dma_wait_idle()) + { + res = -1; + goto out; + } + + //Load firmware or emulate memio environment for newer TSEC fw. + if (kb == KB_FIRMWARE_VERSION_620) + TSEC(TSEC_DMATRFBASE) = (u32)tsec_ctxt->fw >> 8; + else + { + fwbuf = (u8 *)malloc(0x4000); + u8 *fwbuf_aligned = (u8 *)ALIGN((u32)fwbuf, 0x100); + memcpy(fwbuf_aligned, tsec_ctxt->fw, tsec_ctxt->size); + TSEC(TSEC_DMATRFBASE) = (u32)fwbuf_aligned >> 8; + } + + for (u32 addr = 0; addr < tsec_ctxt->size; addr += 0x100) + { + if (!_tsec_dma_pa_to_internal_100(false, addr, addr)) + { + res = -2; + goto out_free; + } + } + + if (kb == KB_FIRMWARE_VERSION_620) + { + // Init SMMU translation for TSEC. + pdir = smmu_init_for_tsec(); + smmu_init(tsec_ctxt->secmon_base); + // Enable SMMU + if (!smmu_is_used()) + smmu_enable(); + + // Clock reset controller. + car = page_alloc(1); + memcpy(car, (void *)CLOCK_BASE, 0x1000); + car[CLK_RST_CONTROLLER_CLK_SOURCE_TSEC / 4] = 2; + smmu_map(pdir, CLOCK_BASE, (u32)car, 1, _WRITABLE | _READABLE | _NONSECURE); + + // Fuse driver. + fuse = page_alloc(1); + memcpy((void *)&fuse[0x800/4], (void *)FUSE_BASE, 0x400); + fuse[0x82C / 4] = 0; + fuse[0x9E0 / 4] = (1 << (kb + 2)) - 1; + fuse[0x9E4 / 4] = (1 << (kb + 2)) - 1; + smmu_map(pdir, (FUSE_BASE - 0x800), (u32)fuse, 1, _READABLE | _NONSECURE); + + // Power management controller. + pmc = page_alloc(1); + smmu_map(pdir, RTC_BASE, (u32)pmc, 1, _READABLE | _NONSECURE); + + // Flow control. + flowctrl = page_alloc(1); + smmu_map(pdir, FLOW_CTLR_BASE, (u32)flowctrl, 1, _WRITABLE | _NONSECURE); + + // Security engine. + se = page_alloc(1); + memcpy(se, (void *)SE_BASE, 0x1000); + smmu_map(pdir, SE_BASE, (u32)se, 1, _READABLE | _WRITABLE | _NONSECURE); + + // Memory controller. + mc = page_alloc(1); + memcpy(mc, (void *)MC_BASE, 0x1000); + mc[MC_IRAM_BOM / 4] = 0; + mc[MC_IRAM_TOM / 4] = 0x80000000; + smmu_map(pdir, MC_BASE, (u32)mc, 1, _READABLE | _NONSECURE); + + // IRAM + iram = page_alloc(0x30); + memcpy(iram, tsec_ctxt->pkg1, 0x30000); + // PKG1.1 magic offset. + pkg11_magic_off = (u32 *)(iram + ((tsec_ctxt->pkg11_off + 0x20) / 4)); + smmu_map(pdir, 0x40010000, (u32)iram, 0x30, _READABLE | _WRITABLE | _NONSECURE); + + // Exception vectors + evec = page_alloc(1); + smmu_map(pdir, EXCP_VEC_BASE, (u32)evec, 1, _READABLE | _WRITABLE | _NONSECURE); + } + + //Execute firmware. + HOST1X(0x3300) = 0x34C2E1DA; + TSEC(TSEC_STATUS) = 0; + TSEC(TSEC_BOOTKEYVER) = 1; // HOS uses key version 1. + TSEC(TSEC_BOOTVEC) = 0; + TSEC(TSEC_CPUCTL) = TSEC_CPUCTL_STARTCPU; + + if (kb == KB_FIRMWARE_VERSION_620) + { + u32 start = get_tmr_us(); + u32 k = se[SE_KEYTABLE_DATA0_REG_OFFSET / 4]; + u32 key[16] = {0}; + u32 kidx = 0; + + while (*pkg11_magic_off != HOS_PKG11_MAGIC) + { + smmu_flush_all(); + + if (k != se[SE_KEYTABLE_DATA0_REG_OFFSET / 4]) + { + k = se[SE_KEYTABLE_DATA0_REG_OFFSET / 4]; + key[kidx++] = k; + } + + // Failsafe. + if ((u32)get_tmr_us() - start > 125000) + break; + } + + if (kidx != 8) + { + res = -6; + smmu_deinit_for_tsec(); + + goto out; + } + + // Give some extra time to make sure PKG1.1 is decrypted. + msleep(50); + + memcpy(tsec_keys, &key, 0x20); + memcpy(tsec_ctxt->pkg1, iram, 0x30000); + + smmu_deinit_for_tsec(); + + // for (int i = 0; i < kidx; i++) + // gfx_printf("key %08X\n", key[i]); + + // gfx_printf("cpuctl (%08X) mbox (%08X)\n", TSEC(TSEC_CPUCTL), TSEC(TSEC_STATUS)); + + // u32 errst = MC(MC_ERR_STATUS); + // gfx_printf(" MC %08X %08X %08X\n", MC(MC_INTSTATUS), errst, MC(MC_ERR_ADR)); + // gfx_printf(" type: %02X\n", errst >> 28); + // gfx_printf(" smmu: %02X\n", (errst >> 25) & 3); + // gfx_printf(" dir: %s\n", (errst >> 16) & 1 ? "W" : "R"); + // gfx_printf(" cid: %02x\n", errst & 0xFF); + } + else + { + if (!_tsec_dma_wait_idle()) + { + res = -3; + goto out_free; + } + u32 timeout = get_tmr_ms() + 2000; + while (!TSEC(TSEC_STATUS)) + if (get_tmr_ms() > timeout) + { + res = -4; + goto out_free; + } + if (TSEC(TSEC_STATUS) != 0xB0B0B0B0) + { + res = -5; + goto out_free; + } + + //Fetch result. + HOST1X(0x3300) = 0; + u32 buf[4]; + buf[0] = SOR1(SOR_NV_PDISP_SOR_DP_HDCP_BKSV_LSB); + buf[1] = SOR1(SOR_NV_PDISP_SOR_TMDS_HDCP_BKSV_LSB); + buf[2] = SOR1(SOR_NV_PDISP_SOR_TMDS_HDCP_CN_MSB); + buf[3] = SOR1(SOR_NV_PDISP_SOR_TMDS_HDCP_CN_LSB); + SOR1(SOR_NV_PDISP_SOR_DP_HDCP_BKSV_LSB) = 0; + SOR1(SOR_NV_PDISP_SOR_TMDS_HDCP_BKSV_LSB) = 0; + SOR1(SOR_NV_PDISP_SOR_TMDS_HDCP_CN_MSB) = 0; + SOR1(SOR_NV_PDISP_SOR_TMDS_HDCP_CN_LSB) = 0; + + memcpy(tsec_keys, &buf, 0x10); + } + +out_free:; + free(fwbuf); + +out:; + + //Disable clocks. + clock_disable_kfuse(); + clock_disable_sor1(); + clock_disable_sor0(); + clock_disable_sor_safe(); + clock_disable_tsec(); + clock_disable_host1x(); + bpmp_mmu_enable(); + bpmp_clk_rate_set(BPMP_CLK_SUPER_BOOST); + + return res; +} diff --git a/nyx/nyx_gui/sec/tsec.h b/nyx/nyx_gui/sec/tsec.h new file mode 100644 index 0000000..45d994c --- /dev/null +++ b/nyx/nyx_gui/sec/tsec.h @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2018 naehrwert +* Copyright (c) 2018 CTCaer +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef _TSEC_H_ +#define _TSEC_H_ + +#include "../utils/types.h" + +typedef struct _tsec_ctxt_t +{ + void *fw; + u32 size; + void *pkg1; + u32 pkg11_off; + u32 secmon_base; +} tsec_ctxt_t; + +int tsec_query(u8 *tsec_keys, u8 kb, tsec_ctxt_t *tsec_ctxt); + +#endif diff --git a/nyx/nyx_gui/sec/tsec_t210.h b/nyx/nyx_gui/sec/tsec_t210.h new file mode 100644 index 0000000..befe269 --- /dev/null +++ b/nyx/nyx_gui/sec/tsec_t210.h @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2018 CTCaer +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef _TSEC_T210_H_ +#define _TSEC_T210_H_ + +#define TSEC_BOOTKEYVER 0x1040 +#define TSEC_STATUS 0x1044 +#define TSEC_ITFEN 0x1048 +#define TSEC_ITFEN_CTXEN (1 << 0) +#define TSEC_ITFEN_MTHDEN (1 << 1) +#define TSEC_IRQMSET 0x1010 +#define TSEC_IRQMSET_WDTMR (1 << 1) +#define TSEC_IRQMSET_HALT (1 << 4) +#define TSEC_IRQMSET_EXTERR (1 << 5) +#define TSEC_IRQMSET_SWGEN0 (1 << 6) +#define TSEC_IRQMSET_SWGEN1 (1 << 7) +#define TSEC_IRQMSET_EXT(val) (((val) & 0xFF) << 8) +#define TSEC_IRQDEST 0x101C +#define TSEC_IRQDEST_HALT (1 << 4) +#define TSEC_IRQDEST_EXTERR (1 << 5) +#define TSEC_IRQDEST_SWGEN0 (1 << 6) +#define TSEC_IRQDEST_SWGEN1 (1 << 7) +#define TSEC_IRQDEST_EXT(val) (((val) & 0xFF) << 8) +#define TSEC_CPUCTL 0x1100 +#define TSEC_CPUCTL_STARTCPU (1 << 1) +#define TSEC_BOOTVEC 0x1104 +#define TSEC_DMACTL 0x110C +#define TSEC_DMATRFBASE 0x1110 +#define TSEC_DMATRFMOFFS 0x1114 +#define TSEC_DMATRFCMD 0x1118 +#define TSEC_DMATRFCMD_IDLE (1 << 1) +#define TSEC_DMATRFCMD_IMEM (1 << 4) +#define TSEC_DMATRFCMD_SIZE_256B (6 << 8) +#define TSEC_DMATRFFBOFFS 0x111C + +#endif diff --git a/nyx/nyx_gui/soc/bpmp.c b/nyx/nyx_gui/soc/bpmp.c new file mode 100644 index 0000000..0c61d85 --- /dev/null +++ b/nyx/nyx_gui/soc/bpmp.c @@ -0,0 +1,217 @@ +/* + * BPMP-Lite Cache/MMU and Frequency driver for Tegra X1 + * + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "bpmp.h" +#include "clock.h" +#include "t210.h" +#include "../utils/util.h" + +#define BPMP_CACHE_CONFIG 0x0 +#define CFG_ENABLE (1 << 0) +#define CFG_FORCE_WRITE_THROUGH (1 << 3) +#define CFG_DISABLE_WRITE_BUFFER (1 << 10) +#define CFG_DISABLE_READ_BUFFER (1 << 11) +#define CFG_FULL_LINE_DIRTY (1 << 13) +#define CFG_TAG_CHK_ABRT_ON_ERR (1 << 14) +#define BPMP_CACHE_LOCK 0x4 +#define BPMP_CACHE_SIZE 0xC +#define BPMP_CACHE_LFSR 0x10 +#define BPMP_CACHE_TAG_STATUS 0x14 +#define BPMP_CACHE_CLKEN_OVERRIDE 0x18 +#define BPMP_CACHE_MAINT_ADDR 0x20 +#define BPMP_CACHE_MAINT_DATA 0x24 +#define BPMP_CACHE_MAINT_REQ 0x28 +#define MAINT_REQ_WAY_BITMAP(x) ((x) << 8) + +#define BPMP_CACHE_INT_MASK 0x40 +#define BPMP_CACHE_INT_CLEAR 0x44 +#define INT_CLR_MAINT_DONE (1 << 0) + +#define BPMP_CACHE_INT_RAW_EVENT 0x48 +#define INT_RAW_EVENT_MAINT_DONE (1 << 0) +#define BPMP_CACHE_INT_STATUS 0x4C + +#define BPMP_CACHE_RB_CFG 0x80 +#define BPMP_CACHE_WB_CFG 0x84 + +#define BPMP_CACHE_MMU_FALLBACK_ENTRY 0xA0 +#define BPMP_CACHE_MMU_SHADOW_COPY_MASK 0xA4 +#define BPMP_CACHE_MMU_CFG 0xAC +#define MMU_CFG_SEQ_EN (1 << 1) +#define MMU_CFG_TLB_EN (1 << 2) +#define MMU_CFG_ABORT_STORE_LAST (1 << 4) +#define BPMP_CACHE_MMU_CMD 0xB0 +#define MMU_CMD_NOP 0 +#define MMU_CMD_INIT 1 +#define MMU_CMD_COPY_SHADOW 2 +#define BPMP_CACHE_MMU_ABORT_STAT 0xB4 +#define BPMP_CACHE_MMU_ABORT_ADDR 0xB8 +#define BPMP_CACHE_MMU_ACTIVE_ENTRIES 0xBC + +#define BPMP_MMU_SHADOW_ENTRY_BASE (BPMP_CACHE_BASE + 0x400) +#define BPMP_MMU_MAIN_ENTRY_BASE (BPMP_CACHE_BASE + 0x800) +#define MMU_ENTRY_ADDR_MASK 0xFFFFFFE0 + +#define MMU_EN_CACHED (1 << 0) +#define MMU_EN_EXEC (1 << 1) +#define MMU_EN_READ (1 << 2) +#define MMU_EN_WRITE (1 << 3) + +bpmp_mmu_entry_t mmu_entries[] = +{ + { 0x80000000, 0xFFFFFFFF, MMU_EN_READ | MMU_EN_WRITE | MMU_EN_EXEC | MMU_EN_CACHED, true }, + { NYX_LOAD_ADDR, 0x40040000, MMU_EN_READ | MMU_EN_WRITE | MMU_EN_EXEC | MMU_EN_CACHED, true } +}; + +void bpmp_mmu_maintenance(u32 op) +{ + if (!(BPMP_CACHE_CTRL(BPMP_CACHE_CONFIG) & CFG_ENABLE)) + return; + + //BPMP_CACHE_CTRL(BPMP_CACHE_INT_CLEAR) = INT_CLR_MAINT_DONE; + + // This is a blocking operation. + BPMP_CACHE_CTRL(BPMP_CACHE_MAINT_REQ) = MAINT_REQ_WAY_BITMAP(0xF) | op; + + //while(!(BPMP_CACHE_CTRL(BPMP_CACHE_INT_RAW_EVENT) & INT_RAW_EVENT_MAINT_DONE)) + // ; + + //BPMP_CACHE_CTRL(BPMP_CACHE_INT_CLEAR) = BPMP_CACHE_CTRL(BPMP_CACHE_INT_RAW_EVENT); +} + +void bpmp_mmu_set_entry(int idx, bpmp_mmu_entry_t *entry, bool apply) +{ + if (idx > 31) + return; + + volatile bpmp_mmu_entry_t *mmu_entry = (bpmp_mmu_entry_t *)(BPMP_MMU_SHADOW_ENTRY_BASE + sizeof(bpmp_mmu_entry_t) * idx); + + if (entry->enable) + { + mmu_entry->min_addr = entry->min_addr & MMU_ENTRY_ADDR_MASK; + mmu_entry->max_addr = entry->max_addr & MMU_ENTRY_ADDR_MASK; + mmu_entry->attr = entry->attr; + + BPMP_CACHE_CTRL(BPMP_CACHE_MMU_SHADOW_COPY_MASK) |= (1 << idx); + + if (apply) + BPMP_CACHE_CTRL(BPMP_CACHE_MMU_CMD) = MMU_CMD_COPY_SHADOW; + } +} + +void bpmp_mmu_enable() +{ + if (BPMP_CACHE_CTRL(BPMP_CACHE_CONFIG) & CFG_ENABLE) + return; + + // Init BPMP MMU. + BPMP_CACHE_CTRL(BPMP_CACHE_MMU_CMD) = MMU_CMD_INIT; + BPMP_CACHE_CTRL(BPMP_CACHE_MMU_FALLBACK_ENTRY) = MMU_EN_READ | MMU_EN_WRITE | MMU_EN_EXEC; // RWX for non-defined regions. + BPMP_CACHE_CTRL(BPMP_CACHE_MMU_CFG) = MMU_CFG_SEQ_EN | MMU_CFG_TLB_EN | MMU_CFG_ABORT_STORE_LAST; + + // Init BPMP MMU entries. + BPMP_CACHE_CTRL(BPMP_CACHE_MMU_SHADOW_COPY_MASK) = 0; + for (u32 idx = 0; idx < (sizeof(mmu_entries) / sizeof(bpmp_mmu_entry_t)); idx++) + bpmp_mmu_set_entry(idx, &mmu_entries[idx], false); + + BPMP_CACHE_CTRL(BPMP_CACHE_MMU_CMD) = MMU_CMD_COPY_SHADOW; + + // Invalidate cache. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY); + + // Enable cache. + BPMP_CACHE_CTRL(BPMP_CACHE_CONFIG) = CFG_ENABLE | CFG_FORCE_WRITE_THROUGH | CFG_TAG_CHK_ABRT_ON_ERR; + + // HW bug. Invalidate cache again. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY); +} + +void bpmp_mmu_disable() +{ + if (!(BPMP_CACHE_CTRL(BPMP_CACHE_CONFIG) & CFG_ENABLE)) + return; + + // Clean and invalidate cache. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY); + + // Enable cache. + BPMP_CACHE_CTRL(BPMP_CACHE_CONFIG) = 0; + + // HW bug. Invalidate cache again. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY); +} + +const u8 pllc4_divn[] = { + 0, // BPMP_CLK_NORMAL: 408MHz 0% - 136MHz APB. + 85, // BPMP_CLK_LOW_BOOST: 544MHz 33% - 136MHz APB. + 90, // BPMP_CLK_MID_BOOST: 576MHz 41% - 144MHz APB. + 95 // BPMP_CLK_SUPER_BOOST: 608MHz 49% - 152MHz APB. +}; + +bpmp_freq_t bpmp_clock_set = BPMP_CLK_NORMAL; + +void bpmp_clk_rate_set(bpmp_freq_t fid) +{ + if (fid > (BPMP_CLK_MAX - 1)) + fid = BPMP_CLK_MAX - 1; + + if (bpmp_clock_set == fid) + return; + + if (fid) + { + if (bpmp_clock_set) + { + // Restore to PLLP source during PLLC4 configuration. + CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = + (CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) & 0xFFFF8888) | 0x3333; // PLLP_OUT. + // Wait a bit for clock source change. + msleep(10); + } + + CLOCK(CLK_RST_CONTROLLER_PLLC4_MISC) = (1 << 30); + CLOCK(CLK_RST_CONTROLLER_PLLC4_BASE) = 4 | (pllc4_divn[fid] << 8) | (1 << 30); // DIVM: 4, DIVP: 1. + + while (!(CLOCK(CLK_RST_CONTROLLER_PLLC4_BASE) & (1 << 27))) + ; + + CLOCK(CLK_RST_CONTROLLER_PLLC4_OUT) = (1 << 8) | (1 << 1); // 1.5 div. + CLOCK(CLK_RST_CONTROLLER_PLLC4_OUT) |= 1; // Get divider out of reset. + + // Wait a bit for PLLC4 to stabilize. + msleep(10); + CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 3; // PCLK = HCLK / 4. + CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = + (CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) & 0xFFFF8888) | 0x3323; // PLLC4_OUT3. + + bpmp_clock_set = fid; + } + else + { + CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = + (CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) & 0xFFFF8888) | 0x3333; // PLLP_OUT. + + // Wait a bit for clock source change. + msleep(10); + + CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 2; // PCLK = HCLK / 3. + CLOCK(CLK_RST_CONTROLLER_PLLC4_BASE) &= ~(1<<30); + bpmp_clock_set = BPMP_CLK_NORMAL; + } +} + diff --git a/nyx/nyx_gui/soc/bpmp.h b/nyx/nyx_gui/soc/bpmp.h new file mode 100644 index 0000000..5c8f14b --- /dev/null +++ b/nyx/nyx_gui/soc/bpmp.h @@ -0,0 +1,51 @@ +/* + * BPMP-Lite Cache/MMU and Frequency driver for Tegra X1 + * + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _BPMP_H_ +#define _BPMP_H_ + +#include "../utils/types.h" + +#define BPMP_MMU_MAINT_CLEAN_WAY 17 +#define BPMP_MMU_MAINT_INVALID_WAY 18 +#define BPMP_MMU_MAINT_CLN_INV_WAY 19 + +typedef struct _bpmp_mmu_entry_t +{ + u32 min_addr; + u32 max_addr; + u32 attr; + u32 enable; +} bpmp_mmu_entry_t; + +typedef enum +{ + BPMP_CLK_NORMAL, // 408MHz 0% - 136MHz APB. + BPMP_CLK_LOW_BOOST, // 544MHz 33% - 136MHz APB. + BPMP_CLK_MID_BOOST, // 576MHz 41% - 144MHz APB. + BPMP_CLK_SUPER_BOOST, // 608MHz 49% - 152MHz APB. + BPMP_CLK_MAX +} bpmp_freq_t; + +void bpmp_mmu_maintenance(u32 op); +void bpmp_mmu_set_entry(int idx, bpmp_mmu_entry_t *entry, bool apply); +void bpmp_mmu_enable(); +void bpmp_mmu_disable(); +void bpmp_clk_rate_set(bpmp_freq_t fid); + +#endif diff --git a/nyx/nyx_gui/soc/clock.c b/nyx/nyx_gui/soc/clock.c new file mode 100644 index 0000000..2a472eb --- /dev/null +++ b/nyx/nyx_gui/soc/clock.c @@ -0,0 +1,529 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../soc/clock.h" +#include "../soc/t210.h" +#include "../utils/util.h" +#include "../storage/sdmmc.h" + +/* clock_t: reset, enable, source, index, clk_src, clk_div */ + +static const clock_t _clock_uart[] = { +/* UART A */ { CLK_RST_CONTROLLER_RST_DEVICES_L, CLK_RST_CONTROLLER_CLK_OUT_ENB_L, CLK_RST_CONTROLLER_CLK_SOURCE_UARTA, 6, 0, 0 }, +/* UART B */ { CLK_RST_CONTROLLER_RST_DEVICES_L, CLK_RST_CONTROLLER_CLK_OUT_ENB_L, CLK_RST_CONTROLLER_CLK_SOURCE_UARTB, 7, 0, 0 }, +/* UART C */ { CLK_RST_CONTROLLER_RST_DEVICES_H, CLK_RST_CONTROLLER_CLK_OUT_ENB_H, CLK_RST_CONTROLLER_CLK_SOURCE_UARTC, 0x17, 0, 0 }, +/* UART D */ { 0 }, +/* UART E */ { 0 } +}; + +static const clock_t _clock_i2c[] = { +/* I2C1 */ { CLK_RST_CONTROLLER_RST_DEVICES_L, CLK_RST_CONTROLLER_CLK_OUT_ENB_L, CLK_RST_CONTROLLER_CLK_SOURCE_I2C1, 0xC, 0, 19 }, //20.4MHz -> 100KHz +/* I2C2 */ { 0 }, +/* I2C3 */ { CLK_RST_CONTROLLER_RST_DEVICES_U, CLK_RST_CONTROLLER_CLK_OUT_ENB_U, CLK_RST_CONTROLLER_CLK_SOURCE_I2C3, 3, 0, 4 }, //81.6MHz -> 400KHz +/* I2C4 */ { 0 }, +/* I2C5 */ { CLK_RST_CONTROLLER_RST_DEVICES_H, CLK_RST_CONTROLLER_CLK_OUT_ENB_H, CLK_RST_CONTROLLER_CLK_SOURCE_I2C5, 0xF, 0, 4 }, //81.6MHz -> 400KHz +/* I2C6 */ { 0 } +}; + +static clock_t _clock_se = { + CLK_RST_CONTROLLER_RST_DEVICES_V, CLK_RST_CONTROLLER_CLK_OUT_ENB_V, CLK_RST_CONTROLLER_CLK_SOURCE_SE, 0x1F, 0, 0 +}; + +static clock_t _clock_tzram = { + CLK_RST_CONTROLLER_RST_DEVICES_V, CLK_RST_CONTROLLER_CLK_OUT_ENB_V, CLK_NO_SOURCE, 0x1E, 0, 0 +}; + +static clock_t _clock_host1x = { + CLK_RST_CONTROLLER_RST_DEVICES_L, CLK_RST_CONTROLLER_CLK_OUT_ENB_L, CLK_RST_CONTROLLER_CLK_SOURCE_HOST1X, 0x1C, 4, 3 +}; +static clock_t _clock_tsec = { + CLK_RST_CONTROLLER_RST_DEVICES_U, CLK_RST_CONTROLLER_CLK_OUT_ENB_U, CLK_RST_CONTROLLER_CLK_SOURCE_TSEC, 0x13, 0, 2 +}; +static clock_t _clock_sor_safe = { + CLK_RST_CONTROLLER_RST_DEVICES_Y, CLK_RST_CONTROLLER_CLK_OUT_ENB_Y, CLK_NO_SOURCE, 0x1E, 0, 0 +}; +static clock_t _clock_sor0 = { + CLK_RST_CONTROLLER_RST_DEVICES_X, CLK_RST_CONTROLLER_CLK_OUT_ENB_X, CLK_NO_SOURCE, 0x16, 0, 0 +}; +static clock_t _clock_sor1 = { + CLK_RST_CONTROLLER_RST_DEVICES_X, CLK_RST_CONTROLLER_CLK_OUT_ENB_X, CLK_RST_CONTROLLER_CLK_SOURCE_SOR1, 0x17, 0, 2 +}; +static clock_t _clock_kfuse = { + CLK_RST_CONTROLLER_RST_DEVICES_H, CLK_RST_CONTROLLER_CLK_OUT_ENB_H, CLK_NO_SOURCE, 8, 0, 0 +}; + +static clock_t _clock_cl_dvfs = { + CLK_RST_CONTROLLER_RST_DEVICES_W, CLK_RST_CONTROLLER_CLK_OUT_ENB_W, CLK_NO_SOURCE, 0x1B, 0, 0 +}; +static clock_t _clock_coresight = { + CLK_RST_CONTROLLER_RST_DEVICES_U, CLK_RST_CONTROLLER_CLK_OUT_ENB_U, CLK_RST_CONTROLLER_CLK_SOURCE_CSITE, 9, 0, 4 +}; + +static clock_t _clock_pwm = { + CLK_RST_CONTROLLER_RST_DEVICES_L, CLK_RST_CONTROLLER_CLK_OUT_ENB_L, CLK_RST_CONTROLLER_CLK_SOURCE_PWM, 0x11, 6, 4 +}; + +void clock_enable(const clock_t *clk) +{ + // Put clock into reset. + CLOCK(clk->reset) = (CLOCK(clk->reset) & ~(1 << clk->index)) | (1 << clk->index); + // Disable. + CLOCK(clk->enable) &= ~(1 << clk->index); + // Configure clock source if required. + if (clk->source) + CLOCK(clk->source) = clk->clk_div | (clk->clk_src << 29); + // Enable. + CLOCK(clk->enable) = (CLOCK(clk->enable) & ~(1 << clk->index)) | (1 << clk->index); + // Take clock off reset. + CLOCK(clk->reset) &= ~(1 << clk->index); +} + +void clock_disable(const clock_t *clk) +{ + // Put clock into reset. + CLOCK(clk->reset) = (CLOCK(clk->reset) & ~(1 << clk->index)) | (1 << clk->index); + // Disable. + CLOCK(clk->enable) &= ~(1 << clk->index); +} + +void clock_enable_fuse(bool enable) +{ + CLOCK(CLK_RST_CONTROLLER_MISC_CLK_ENB) = (CLOCK(CLK_RST_CONTROLLER_MISC_CLK_ENB) & 0xEFFFFFFF) | ((enable & 1) << 28); +} + +void clock_enable_uart(u32 idx) +{ + clock_enable(&_clock_uart[idx]); +} + +void clock_enable_i2c(u32 idx) +{ + clock_enable(&_clock_i2c[idx]); +} + +void clock_disable_i2c(u32 idx) +{ + clock_disable(&_clock_i2c[idx]); +} + +void clock_enable_se() +{ + clock_enable(&_clock_se); +} + +void clock_enable_tzram() +{ + clock_enable(&_clock_tzram); +} + +void clock_enable_host1x() +{ + clock_enable(&_clock_host1x); +} + +void clock_disable_host1x() +{ + clock_disable(&_clock_host1x); +} + +void clock_enable_tsec() +{ + clock_enable(&_clock_tsec); +} + +void clock_disable_tsec() +{ + clock_disable(&_clock_tsec); +} + +void clock_enable_sor_safe() +{ + clock_enable(&_clock_sor_safe); +} + +void clock_disable_sor_safe() +{ + clock_disable(&_clock_sor_safe); +} + +void clock_enable_sor0() +{ + clock_enable(&_clock_sor0); +} + +void clock_disable_sor0() +{ + clock_disable(&_clock_sor0); +} + +void clock_enable_sor1() +{ + clock_enable(&_clock_sor1); +} + +void clock_disable_sor1() +{ + clock_disable(&_clock_sor1); +} + +void clock_enable_kfuse() +{ + //clock_enable(&_clock_kfuse); + CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_H) = (CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_H) & 0xFFFFFEFF) | 0x100; + CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_H) &= 0xFFFFFEFF; + CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_H) = (CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_H) & 0xFFFFFEFF) | 0x100; + usleep(10); + CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_H) &= 0xFFFFFEFF; + usleep(20); +} + +void clock_disable_kfuse() +{ + clock_disable(&_clock_kfuse); +} + +void clock_enable_cl_dvfs() +{ + clock_enable(&_clock_cl_dvfs); +} + +void clock_disable_cl_dvfs() +{ + clock_disable(&_clock_cl_dvfs); +} + +void clock_enable_coresight() +{ + clock_enable(&_clock_coresight); +} + +void clock_disable_coresight() +{ + clock_disable(&_clock_coresight); +} + +void clock_enable_pwm() +{ + clock_enable(&_clock_pwm); +} + +void clock_disable_pwm() +{ + clock_disable(&_clock_pwm); +} + +#define L_SWR_SDMMC1_RST (1 << 14) +#define L_SWR_SDMMC2_RST (1 << 9) +#define L_SWR_SDMMC4_RST (1 << 15) +#define U_SWR_SDMMC3_RST (1 << 5) + +#define L_CLK_ENB_SDMMC1 (1 << 14) +#define L_CLK_ENB_SDMMC2 (1 << 9) +#define L_CLK_ENB_SDMMC4 (1 << 15) +#define U_CLK_ENB_SDMMC3 (1 << 5) + +#define L_SET_SDMMC1_RST (1 << 14) +#define L_SET_SDMMC2_RST (1 << 9) +#define L_SET_SDMMC4_RST (1 << 15) +#define U_SET_SDMMC3_RST (1 << 5) + +#define L_CLR_SDMMC1_RST (1 << 14) +#define L_CLR_SDMMC2_RST (1 << 9) +#define L_CLR_SDMMC4_RST (1 << 15) +#define U_CLR_SDMMC3_RST (1 << 5) + +#define L_SET_CLK_ENB_SDMMC1 (1 << 14) +#define L_SET_CLK_ENB_SDMMC2 (1 << 9) +#define L_SET_CLK_ENB_SDMMC4 (1 << 15) +#define U_SET_CLK_ENB_SDMMC3 (1 << 5) + +#define L_CLR_CLK_ENB_SDMMC1 (1 << 14) +#define L_CLR_CLK_ENB_SDMMC2 (1 << 9) +#define L_CLR_CLK_ENB_SDMMC4 (1 << 15) +#define U_CLR_CLK_ENB_SDMMC3 (1 << 5) + +static int _clock_sdmmc_is_reset(u32 id) +{ + switch (id) + { + case SDMMC_1: + return CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_L) & L_SWR_SDMMC1_RST; + case SDMMC_2: + return CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_L) & L_SWR_SDMMC2_RST; + case SDMMC_3: + return CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_U) & U_SWR_SDMMC3_RST; + case SDMMC_4: + return CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_L) & L_SWR_SDMMC4_RST; + } + return 0; +} + +static void _clock_sdmmc_set_reset(u32 id) +{ + switch (id) + { + case SDMMC_1: + CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = L_SET_SDMMC1_RST; + break; + case SDMMC_2: + CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = L_SET_SDMMC2_RST; + break; + case SDMMC_3: + CLOCK(CLK_RST_CONTROLLER_RST_DEV_U_SET) = U_SET_SDMMC3_RST; + break; + case SDMMC_4: + CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = L_SET_SDMMC4_RST; + break; + } +} + +static void _clock_sdmmc_clear_reset(u32 id) +{ + switch (id) + { + case SDMMC_1: + CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_CLR) = L_CLR_SDMMC1_RST; + break; + case SDMMC_2: + CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_CLR) = L_CLR_SDMMC2_RST; + break; + case SDMMC_3: + CLOCK(CLK_RST_CONTROLLER_RST_DEV_U_CLR) = U_CLR_SDMMC3_RST; + break; + case SDMMC_4: + CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_CLR) = L_CLR_SDMMC4_RST; + break; + } +} + +static int _clock_sdmmc_is_enabled(u32 id) +{ + switch (id) + { + case SDMMC_1: + return CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_L) & L_CLK_ENB_SDMMC1; + case SDMMC_2: + return CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_L) & L_CLK_ENB_SDMMC2; + case SDMMC_3: + return CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_U) & U_CLK_ENB_SDMMC3; + case SDMMC_4: + return CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_L) & L_CLK_ENB_SDMMC4; + } + return 0; +} + +static void _clock_sdmmc_set_enable(u32 id) +{ + switch (id) + { + case SDMMC_1: + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_SET) = L_SET_CLK_ENB_SDMMC1; + break; + case SDMMC_2: + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_SET) = L_SET_CLK_ENB_SDMMC2; + break; + case SDMMC_3: + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_U_SET) = U_SET_CLK_ENB_SDMMC3; + break; + case SDMMC_4: + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_SET) = L_SET_CLK_ENB_SDMMC4; + break; + } +} + +static void _clock_sdmmc_clear_enable(u32 id) +{ + switch (id) + { + case SDMMC_1: + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_CLR) = L_CLR_CLK_ENB_SDMMC1; + break; + case SDMMC_2: + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_CLR) = L_CLR_CLK_ENB_SDMMC2; + break; + case SDMMC_3: + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_U_CLR) = U_CLR_CLK_ENB_SDMMC3; + break; + case SDMMC_4: + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_CLR) = L_CLR_CLK_ENB_SDMMC4; + break; + } +} + +static u32 _clock_sdmmc_table[8] = { 0 }; + +#define PLLP_OUT0 0x0 + +static int _clock_sdmmc_config_clock_source_inner(u32 *pout, u32 id, u32 val) +{ + u32 divisor = 0; + u32 source = PLLP_OUT0; + + switch (val) + { + case 25000: + *pout = 24728; + divisor = 31; + break; + case 26000: + *pout = 25500; + divisor = 30; + break; + case 40800: + *pout = 40800; + divisor = 18; + break; + case 50000: + *pout = 48000; + divisor = 15; + break; + case 52000: + *pout = 51000; + divisor = 14; + break; + case 100000: + *pout = 90667; + divisor = 7; + break; + case 200000: + *pout = 163200; + divisor = 3; + break; + case 208000: + *pout = 204000; + divisor = 2; + break; + default: + *pout = 24728; + divisor = 31; + } + + _clock_sdmmc_table[2 * id] = val; + _clock_sdmmc_table[2 * id + 1] = *pout; + + switch (id) + { + case SDMMC_1: + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC1) = (source << 29) | divisor; + break; + case SDMMC_2: + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC2) = (source << 29) | divisor; + break; + case SDMMC_3: + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC3) = (source << 29) | divisor; + break; + case SDMMC_4: + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC4) = (source << 29) | divisor; + break; + } + + return 1; +} + +void clock_sdmmc_config_clock_source(u32 *pout, u32 id, u32 val) +{ + if (_clock_sdmmc_table[2 * id] == val) + { + *pout = _clock_sdmmc_table[2 * id + 1]; + } + else + { + int is_enabled = _clock_sdmmc_is_enabled(id); + if (is_enabled) + _clock_sdmmc_clear_enable(id); + _clock_sdmmc_config_clock_source_inner(pout, id, val); + if (is_enabled) + _clock_sdmmc_set_enable(id); + _clock_sdmmc_is_reset(id); + } +} + +void clock_sdmmc_get_params(u32 *pout, u16 *pdivisor, u32 type) +{ + switch (type) + { + case 0: + *pout = 26000; + *pdivisor = 66; + break; + case 1: + *pout = 26000; + *pdivisor = 1; + break; + case 2: + *pout = 52000; + *pdivisor = 1; + break; + case 3: + case 4: + case 11: + *pout = 200000; + *pdivisor = 1; + break; + case 5: + *pout = 25000; + *pdivisor = 64; + break; + case 6: + case 8: + *pout = 25000; + *pdivisor = 1; + break; + case 7: + *pout = 50000; + *pdivisor = 1; + break; + case 10: + *pout = 100000; + *pdivisor = 1; + break; + case 13: + *pout = 40800; + *pdivisor = 1; + break; + case 14: + *pout = 200000; + *pdivisor = 2; + break; + } +} + +int clock_sdmmc_is_not_reset_and_enabled(u32 id) +{ + return !_clock_sdmmc_is_reset(id) && _clock_sdmmc_is_enabled(id); +} + +void clock_sdmmc_enable(u32 id, u32 val) +{ + u32 div = 0; + + if (_clock_sdmmc_is_enabled(id)) + _clock_sdmmc_clear_enable(id); + _clock_sdmmc_set_reset(id); + _clock_sdmmc_config_clock_source_inner(&div, id, val); + _clock_sdmmc_set_enable(id); + _clock_sdmmc_is_reset(id); + usleep((100000 + div - 1) / div); + _clock_sdmmc_clear_reset(id); + _clock_sdmmc_is_reset(id); +} + +void clock_sdmmc_disable(u32 id) +{ + _clock_sdmmc_set_reset(id); + _clock_sdmmc_clear_enable(id); + _clock_sdmmc_is_reset(id); +} diff --git a/nyx/nyx_gui/soc/clock.h b/nyx/nyx_gui/soc/clock.h new file mode 100644 index 0000000..e4d6a05 --- /dev/null +++ b/nyx/nyx_gui/soc/clock.h @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CLOCK_H_ +#define _CLOCK_H_ + +#include "../utils/types.h" + +/*! Clock registers. */ +#define CLK_RST_CONTROLLER_RST_SOURCE 0x0 +#define CLK_RST_CONTROLLER_RST_DEVICES_L 0x4 +#define CLK_RST_CONTROLLER_RST_DEVICES_H 0x8 +#define CLK_RST_CONTROLLER_RST_DEVICES_U 0xC +#define CLK_RST_CONTROLLER_CLK_OUT_ENB_L 0x10 +#define CLK_RST_CONTROLLER_CLK_OUT_ENB_H 0x14 +#define CLK_RST_CONTROLLER_CLK_OUT_ENB_U 0x18 +#define CLK_RST_CONTROLLER_CCLK_BURST_POLICY 0x20 +#define CLK_RST_CONTROLLER_SUPER_CCLK_DIVIDER 0x24 +#define CLK_RST_CONTROLLER_SCLK_BURST_POLICY 0x28 +#define CLK_RST_CONTROLLER_SUPER_SCLK_DIVIDER 0x2C +#define CLK_RST_CONTROLLER_CLK_SYSTEM_RATE 0x30 +#define CLK_RST_CONTROLLER_MISC_CLK_ENB 0x48 +#define CLK_RST_CONTROLLER_OSC_CTRL 0x50 +#define CLK_RST_CONTROLLER_PLLC_BASE 0x80 +#define CLK_RST_CONTROLLER_PLLC_MISC 0x88 +#define CLK_RST_CONTROLLER_PLLM_BASE 0x90 +#define CLK_RST_CONTROLLER_PLLM_MISC1 0x98 +#define CLK_RST_CONTROLLER_PLLM_MISC2 0x9C +#define CLK_RST_CONTROLLER_PLLP_BASE 0xA0 +#define CLK_RST_CONTROLLER_PLLD_BASE 0xD0 +#define CLK_RST_CONTROLLER_PLLX_BASE 0xE0 +#define CLK_RST_CONTROLLER_PLLX_MISC 0xE4 +#define CLK_RST_CONTROLLER_PLLE_BASE 0xE8 +#define CLK_RST_CONTROLLER_PLLE_MISC 0xEC +#define CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRA 0xF8 +#define CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRB 0xFC +#define CLK_RST_CONTROLLER_CLK_SOURCE_PWM 0x110 +#define CLK_RST_CONTROLLER_CLK_SOURCE_I2C1 0x124 +#define CLK_RST_CONTROLLER_CLK_SOURCE_I2C5 0x128 +#define CLK_RST_CONTROLLER_CLK_SOURCE_VI 0x148 +#define CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC1 0x150 +#define CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC2 0x154 +#define CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC4 0x164 +#define CLK_RST_CONTROLLER_CLK_SOURCE_UARTA 0x178 +#define CLK_RST_CONTROLLER_CLK_SOURCE_UARTB 0x17C +#define CLK_RST_CONTROLLER_CLK_SOURCE_HOST1X 0x180 +#define CLK_RST_CONTROLLER_CLK_SOURCE_UARTC 0x1A0 +#define CLK_RST_CONTROLLER_CLK_SOURCE_I2C3 0x1B8 +#define CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC3 0x1BC +#define CLK_RST_CONTROLLER_CLK_SOURCE_CSITE 0x1D4 +#define CLK_RST_CONTROLLER_CLK_SOURCE_EMC 0x19C +#define CLK_RST_CONTROLLER_CLK_SOURCE_TSEC 0x1F4 +#define CLK_RST_CONTROLLER_CLK_OUT_ENB_X 0x280 +#define CLK_RST_CONTROLLER_CLK_ENB_X_SET 0x284 +#define CLK_RST_CONTROLLER_CLK_ENB_X_CLR 0x288 +#define CLK_RST_CONTROLLER_RST_DEVICES_X 0x28C +#define CLK_RST_CONTROLLER_RST_DEV_X_SET 0x290 +#define CLK_RST_CONTROLLER_RST_DEV_X_CLR 0x294 +#define CLK_RST_CONTROLLER_CLK_OUT_ENB_Y 0x298 +#define CLK_RST_CONTROLLER_CLK_ENB_Y_SET 0x29C +#define CLK_RST_CONTROLLER_CLK_ENB_Y_CLR 0x2A0 +#define CLK_RST_CONTROLLER_RST_DEVICES_Y 0x2A4 +#define CLK_RST_CONTROLLER_RST_DEV_Y_SET 0x2A8 +#define CLK_RST_CONTROLLER_RST_DEV_Y_CLR 0x2AC +#define CLK_RST_CONTROLLER_RST_DEV_L_SET 0x300 +#define CLK_RST_CONTROLLER_RST_DEV_L_CLR 0x304 +#define CLK_RST_CONTROLLER_RST_DEV_H_SET 0x308 +#define CLK_RST_CONTROLLER_RST_DEV_H_CLR 0x30C +#define CLK_RST_CONTROLLER_RST_DEV_U_SET 0x310 +#define CLK_RST_CONTROLLER_RST_DEV_U_CLR 0x314 +#define CLK_RST_CONTROLLER_CLK_ENB_L_SET 0x320 +#define CLK_RST_CONTROLLER_CLK_ENB_L_CLR 0x324 +#define CLK_RST_CONTROLLER_CLK_ENB_H_SET 0x328 +#define CLK_RST_CONTROLLER_CLK_ENB_H_CLR 0x32C +#define CLK_RST_CONTROLLER_CLK_ENB_U_SET 0x330 +#define CLK_RST_CONTROLLER_CLK_ENB_U_CLR 0x334 +#define CLK_RST_CONTROLLER_RST_DEVICES_V 0x358 +#define CLK_RST_CONTROLLER_RST_DEVICES_W 0x35C +#define CLK_RST_CONTROLLER_CLK_OUT_ENB_V 0x360 +#define CLK_RST_CONTROLLER_CLK_OUT_ENB_W 0x364 +#define CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2 0x388 +#define CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRC 0x3A0 +#define CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRD 0x3A4 +#define CLK_RST_CONTROLLER_CLK_SOURCE_MSELECT 0x3B4 +#define CLK_RST_CONTROLLER_CLK_SOURCE_SOR1 0x410 +#define CLK_RST_CONTROLLER_CLK_SOURCE_SE 0x42C +#define CLK_RST_CONTROLLER_CLK_ENB_V_SET 0x440 +//#define CLK_RST_CONTROLLER_CLK_ENB_V_CLR 0x444 +#define CLK_RST_CONTROLLER_CLK_ENB_W_SET 0x448 +#define CLK_RST_CONTROLLER_CLK_ENB_W_CLR 0x44C +#define CLK_RST_CONTROLLER_RST_CPUG_CMPLX_SET 0x450 +#define CLK_RST_CONTROLLER_RST_CPUG_CMPLX_CLR 0x454 +#define CLK_RST_CONTROLLER_UTMIP_PLL_CFG2 0x488 +#define CLK_RST_CONTROLLER_PLLE_AUX 0x48C +#define CLK_RST_CONTROLLER_AUDIO_SYNC_CLK_I2S0 0x4A0 +#define CLK_RST_CONTROLLER_PLLX_MISC_3 0x518 +#define CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRE 0x554 +#define CLK_RST_CONTROLLER_SPARE_REG0 0x55C +#define CLK_RST_CONTROLLER_PLLC4_BASE 0x5A4 +#define CLK_RST_CONTROLLER_PLLC4_MISC 0x5A8 +#define CLK_RST_CONTROLLER_PLLC4_OUT 0x5E4 +#define CLK_RST_CONTROLLER_PLLMB_BASE 0x5E8 +#define CLK_RST_CONTROLLER_CLK_SOURCE_DSIA_LP 0x620 +//#define CLK_RST_CONTROLLER_CLK_SOURCE_I2C6 0x65C +#define CLK_RST_CONTROLLER_CLK_SOURCE_EMC_DLL 0x664 +#define CLK_RST_CONTROLLER_CLK_SOURCE_UART_FST_MIP_CAL 0x66C +#define CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC_LEGACY_TM 0x694 +#define CLK_RST_CONTROLLER_CLK_SOURCE_NVENC 0x6A0 +#define CLK_RST_CONTROLLER_SE_SUPER_CLK_DIVIDER 0x704 + +#define CLK_NO_SOURCE 0x0 + +/*! Generic clock descriptor. */ +typedef struct _clock_t +{ + u32 reset; + u32 enable; + u32 source; + u8 index; + u8 clk_src; + u8 clk_div; +} clock_t; + +/*! Generic clock enable/disable. */ +void clock_enable(const clock_t *clk); +void clock_disable(const clock_t *clk); + +/*! Clock control for specific hardware portions. */ +void clock_enable_fuse(bool enable); +void clock_enable_uart(u32 idx); +void clock_enable_i2c(u32 idx); +void clock_disable_i2c(u32 idx); +void clock_enable_se(); +void clock_enable_tzram(); +void clock_enable_host1x(); +void clock_disable_host1x(); +void clock_enable_tsec(); +void clock_disable_tsec(); +void clock_enable_sor_safe(); +void clock_disable_sor_safe(); +void clock_enable_sor0(); +void clock_disable_sor0(); +void clock_enable_sor1(); +void clock_disable_sor1(); +void clock_enable_kfuse(); +void clock_disable_kfuse(); +void clock_enable_cl_dvfs(); +void clock_disable_cl_dvfs(); +void clock_enable_coresight(); +void clock_disable_coresight(); +void clock_enable_pwm(); +void clock_disable_pwm(); +void clock_sdmmc_config_clock_source(u32 *pout, u32 id, u32 val); +void clock_sdmmc_get_params(u32 *pout, u16 *pdivisor, u32 type); +int clock_sdmmc_is_not_reset_and_enabled(u32 id); +void clock_sdmmc_enable(u32 id, u32 val); +void clock_sdmmc_disable(u32 id); + +#endif diff --git a/nyx/nyx_gui/soc/cluster.c b/nyx/nyx_gui/soc/cluster.c new file mode 100644 index 0000000..1976e11 --- /dev/null +++ b/nyx/nyx_gui/soc/cluster.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../soc/cluster.h" +#include "../soc/i2c.h" +#include "../soc/clock.h" +#include "../utils/util.h" +#include "../soc/pmc.h" +#include "../soc/t210.h" +#include "../power/max77620.h" +#include "../power/max7762x.h" + +void _cluster_enable_power() +{ + u8 tmp = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_AME_GPIO); // Get current pinmuxing + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_AME_GPIO, tmp & ~(1 << 5)); // Disable GPIO5 pinmuxing. + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_GPIO5, MAX77620_CNFG_GPIO_DRV_PUSHPULL | MAX77620_CNFG_GPIO_OUTPUT_VAL_HIGH); + + // Enable cores power. + // 1-3.x: MAX77621_NFSR_ENABLE. + i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_CONTROL1_REG, + MAX77621_AD_ENABLE | MAX77621_NFSR_ENABLE | MAX77621_SNS_ENABLE); + // 1.0.0-3.x: MAX77621_T_JUNCTION_120 | MAX77621_CKKADV_TRIP_DISABLE | MAX77621_INDUCTOR_NOMINAL. + i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_CONTROL2_REG, + MAX77621_T_JUNCTION_120 | MAX77621_WDTMR_ENABLE | MAX77621_CKKADV_TRIP_75mV_PER_US| MAX77621_INDUCTOR_NOMINAL); + i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_VOUT_REG, MAX77621_VOUT_ENABLE | 0x37); + i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_VOUT_DVC_REG, MAX77621_VOUT_ENABLE | 0x37); +} + +int _cluster_pmc_enable_partition(u32 part, u32 toggle, bool enable) +{ + // Check if the partition has already been turned on. + if (enable && PMC(APBDEV_PMC_PWRGATE_STATUS) & part) + return 1; + + u32 i = 5001; + while (PMC(APBDEV_PMC_PWRGATE_TOGGLE) & 0x100) + { + usleep(1); + i--; + if (i < 1) + return 0; + } + + PMC(APBDEV_PMC_PWRGATE_TOGGLE) = toggle | (enable ? 0x100 : 0); + + i = 5001; + while (i > 0) + { + if (PMC(APBDEV_PMC_PWRGATE_STATUS) & part) + break; + usleep(1); + i--; + } + + return 1; +} + +void cluster_boot_cpu0(u32 entry) +{ + // Set ACTIVE_CLUSER to FAST. + FLOW_CTLR(FLOW_CTLR_BPMP_CLUSTER_CONTROL) &= 0xFFFFFFFE; + + _cluster_enable_power(); + + if (!(CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) & 0x40000000)) + { + CLOCK(CLK_RST_CONTROLLER_PLLX_MISC_3) &= 0xFFFFFFF7; + usleep(2); + CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) = 0x80404E02; + CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) = 0x404E02; + CLOCK(CLK_RST_CONTROLLER_PLLX_MISC) = (CLOCK(CLK_RST_CONTROLLER_PLLX_MISC) & 0xFFFBFFFF) | 0x40000; + CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) = 0x40404E02; + } + while (!(CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) & 0x8000000)) + ; + + // Configure MSELECT source and enable clock. + CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_MSELECT) = (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_MSELECT) & 0x1FFFFF00) | 6; + CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) = (CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) & 0xFFFFFFF7) | 8; + + // Configure initial CPU clock frequency and enable clock. + CLOCK(CLK_RST_CONTROLLER_CCLK_BURST_POLICY) = 0x20008888; + CLOCK(CLK_RST_CONTROLLER_SUPER_CCLK_DIVIDER) = 0x80000000; + CLOCK(CLK_RST_CONTROLLER_CLK_ENB_V_SET) = 1; + + clock_enable_coresight(); + + // CAR2PMC_CPU_ACK_WIDTH should be set to 0. + CLOCK(CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2) &= 0xFFFFF000; + + // Enable CPU rail. + _cluster_pmc_enable_partition(1, 0, true); + // Enable cluster 0 non-CPU. + _cluster_pmc_enable_partition(0x8000, 15, true); + // Enable CE0. + _cluster_pmc_enable_partition(0x4000, 14, true); + + // Request and wait for RAM repair. + FLOW_CTLR(FLOW_CTLR_RAM_REPAIR) = 1; + while (!(FLOW_CTLR(FLOW_CTLR_RAM_REPAIR) & 2)) + ; + + EXCP_VEC(EVP_CPU_RESET_VECTOR) = 0; + + // Set reset vector. + SB(SB_AA64_RESET_LOW) = entry | 1; + SB(SB_AA64_RESET_HIGH) = 0; + // Non-secure reset vector write disable. + SB(SB_CSR) = 2; + (void)SB(SB_CSR); + + // Clear MSELECT reset. + CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_V) &= 0xFFFFFFF7; + // Clear NONCPU reset. + CLOCK(CLK_RST_CONTROLLER_RST_CPUG_CMPLX_CLR) = 0x20000000; + // Clear CPU0 reset. + // < 5.x: 0x411F000F, Clear CPU{0,1,2,3} POR and CORE, CX0, L2, and DBG reset. + CLOCK(CLK_RST_CONTROLLER_RST_CPUG_CMPLX_CLR) = 0x41010001; +} diff --git a/nyx/nyx_gui/soc/cluster.h b/nyx/nyx_gui/soc/cluster.h new file mode 100644 index 0000000..5cecd19 --- /dev/null +++ b/nyx/nyx_gui/soc/cluster.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CLUSTER_H_ +#define _CLUSTER_H_ + +#include "../utils/types.h" + +/*! Flow controller registers. */ +#define FLOW_CTLR_HALT_CPU0_EVENTS 0x0 +#define FLOW_CTLR_HALT_CPU1_EVENTS 0x14 +#define FLOW_CTLR_HALT_CPU2_EVENTS 0x1C +#define FLOW_CTLR_HALT_CPU3_EVENTS 0x24 +#define FLOW_CTLR_HALT_COP_EVENTS 0x4 +#define FLOW_CTLR_CPU0_CSR 0x8 +#define FLOW_CTLR_CPU1_CSR 0x18 +#define FLOW_CTLR_CPU2_CSR 0x20 +#define FLOW_CTLR_CPU3_CSR 0x28 +#define FLOW_CTLR_RAM_REPAIR 0x40 +#define FLOW_CTLR_BPMP_CLUSTER_CONTROL 0x98 + +void cluster_boot_cpu0(u32 entry); + +#endif diff --git a/nyx/nyx_gui/soc/fuse.c b/nyx/nyx_gui/soc/fuse.c new file mode 100644 index 0000000..54a93a0 --- /dev/null +++ b/nyx/nyx_gui/soc/fuse.c @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 shuffle2 + * Copyright (c) 2018 balika011 + * Copyright (c) 2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "../soc/fuse.h" +#include "../soc/t210.h" + +#define ARRAYSIZE(x) (sizeof(x) / sizeof(*x)) + +static const u32 evp_thunk_template[] = { + 0xe92d0007, // STMFD SP!, {R0-R2} + 0xe1a0200e, // MOV R2, LR + 0xe2422002, // SUB R2, R2, #2 + 0xe5922000, // LDR R2, [R2] + 0xe20220ff, // AND R2, R2, #0xFF + 0xe1a02082, // MOV R2, R2,LSL#1 + 0xe59f001c, // LDR R0, =evp_thunk_template + 0xe59f101c, // LDR R1, =thunk_end + 0xe0411000, // SUB R1, R1, R0 + 0xe59f0018, // LDR R0, =iram_evp_thunks + 0xe0800001, // ADD R0, R0, R1 + 0xe0822000, // ADD R2, R2, R0 + 0xe3822001, // ORR R2, R2, #1 + 0xe8bd0003, // LDMFD SP!, {R0,R1} + 0xe12fff12, // BX R2 + 0x001007b0, // off_1007EC DCD evp_thunk_template + 0x001007f8, // off_1007F0 DCD thunk_end + 0x40004c30, // off_1007F4 DCD iram_evp_thunks + // thunk_end is here +}; +static const u32 evp_thunk_template_len = sizeof(evp_thunk_template); + +// treated as 12bit values +static const u32 hash_vals[] = {1, 2, 4, 8, 0, 3, 5, 6, 7, 9, 10, 11}; + +void fuse_disable_program() +{ + FUSE(FUSE_DISABLEREGPROGRAM) = 1; +} + +u32 fuse_read_odm(u32 idx) +{ + return FUSE(FUSE_RESERVED_ODMX(idx)); +} + +void fuse_wait_idle() +{ + u32 ctrl; + do + { + ctrl = FUSE(FUSE_CTRL); + } while (((ctrl >> 16) & 0x1f) != 4); +} + +u32 fuse_read(u32 addr) +{ + FUSE(FUSE_ADDR) = addr; + FUSE(FUSE_CTRL) = (FUSE(FUSE_ADDR) & ~FUSE_CMD_MASK) | FUSE_READ; + fuse_wait_idle(); + return FUSE(FUSE_RDATA); +} + +void fuse_read_array(u32 *words) +{ + for (u32 i = 0; i < 192; i++) + words[i] = fuse_read(i); +} + +static u32 _parity32_even(u32 *words, u32 count) +{ + u32 acc = words[0]; + for (u32 i = 1; i < count; i++) + { + acc ^= words[i]; + } + u32 lo = ((acc & 0xffff) ^ (acc >> 16)) & 0xff; + u32 hi = ((acc & 0xffff) ^ (acc >> 16)) >> 8; + u32 x = hi ^ lo; + lo = ((x & 0xf) ^ (x >> 4)) & 3; + hi = ((x & 0xf) ^ (x >> 4)) >> 2; + x = hi ^ lo; + + return (x & 1) ^ (x >> 1); +} + +static int _patch_hash_one(u32 *word) +{ + u32 bits20_31 = *word & 0xfff00000; + u32 parity_bit = _parity32_even(&bits20_31, 1); + u32 hash = 0; + for (u32 i = 0; i < 12; i++) + { + if (*word & (1 << (20 + i))) + { + hash ^= hash_vals[i]; + } + } + if (hash == 0) + { + if (parity_bit == 0) + { + return 0; + } + *word ^= 1 << 24; + return 1; + } + if (parity_bit == 0) + { + return 3; + } + for (u32 i = 0; i < ARRAYSIZE(hash_vals); i++) + { + if (hash_vals[i] == hash) + { + *word ^= 1 << (20 + i); + return 1; + } + } + return 2; +} + +static int _patch_hash_multi(u32 *words, u32 count) +{ + u32 parity_bit = _parity32_even(words, count); + u32 bits0_14 = words[0] & 0x7fff; + u32 bit15 = words[0] & 0x8000; + u32 bits16_19 = words[0] & 0xf0000; + + u32 hash = 0; + words[0] = bits16_19; + for (u32 i = 0; i < count; i++) + { + u32 w = words[i]; + if (w) + { + for (u32 bitpos = 0; bitpos < 32; bitpos++) + { + if ((w >> bitpos) & 1) + { + hash ^= 0x4000 + i * 32 + bitpos; + } + } + } + } + hash ^= bits0_14; + // stupid but this is what original code does. + // equivalent to original words[0] &= 0xfff00000 + words[0] = bits16_19 ^ bit15 ^ bits0_14; + + if (hash == 0) + { + if (parity_bit == 0) + { + return 0; + } + words[0] ^= 0x8000; + return 1; + } + if (parity_bit == 0) + { + return 3; + } + u32 bitcount = hash - 0x4000; + if (bitcount < 16 || bitcount >= count * 32) + { + u32 num_set = 0; + for (u32 bitpos = 0; bitpos < 15; bitpos++) + { + if ((hash >> bitpos) & 1) + { + num_set++; + } + } + if (num_set != 1) + { + return 2; + } + words[0] ^= hash; + return 1; + } + words[bitcount / 32] ^= 1 << (hash & 0x1f); + return 1; +} + +int fuse_read_ipatch(void (*ipatch)(u32 offset, u32 value)) +{ + u32 words[80]; + u32 word_count; + u32 word_addr; + u32 word0 = 0; + u32 total_read = 0; + + word_count = FUSE(FUSE_FIRST_BOOTROM_PATCH_SIZE); + word_count &= 0x7F; + word_addr = 191; + + while (word_count) + { + total_read += word_count; + if (total_read >= ARRAYSIZE(words)) + { + break; + } + + for (u32 i = 0; i < word_count; i++) + words[i] = fuse_read(word_addr--); + + word0 = words[0]; + if (_patch_hash_multi(words, word_count) >= 2) + { + return 1; + } + u32 ipatch_count = (words[0] >> 16) & 0xF; + if (ipatch_count) + { + for (u32 i = 0; i < ipatch_count; i++) + { + u32 word = words[i + 1]; + u32 addr = (word >> 16) * 2; + u32 data = word & 0xFFFF; + + ipatch(addr, data); + } + } + words[0] = word0; + if ((word0 >> 25) == 0) + break; + if (_patch_hash_one(&word0) >= 2) + { + return 3; + } + word_count = word0 >> 25; + } + + return 0; +} + +int fuse_read_evp_thunk(u32 *iram_evp_thunks, u32 *iram_evp_thunks_len) +{ + u32 words[80]; + u32 word_count; + u32 word_addr; + u32 word0 = 0; + u32 total_read = 0; + int evp_thunk_written = 0; + void *evp_thunk_dst_addr = 0; + + memset(iram_evp_thunks, 0, *iram_evp_thunks_len); + + word_count = FUSE(FUSE_FIRST_BOOTROM_PATCH_SIZE); + word_count &= 0x7F; + word_addr = 191; + + while (word_count) + { + total_read += word_count; + if (total_read >= ARRAYSIZE(words)) + { + break; + } + + for (u32 i = 0; i < word_count; i++) + words[i] = fuse_read(word_addr--); + + word0 = words[0]; + if (_patch_hash_multi(words, word_count) >= 2) + { + return 1; + } + u32 ipatch_count = (words[0] >> 16) & 0xF; + u32 insn_count = word_count - ipatch_count - 1; + if (insn_count) + { + if (!evp_thunk_written) + { + evp_thunk_dst_addr = (void *)iram_evp_thunks; + + memcpy(evp_thunk_dst_addr, (void *)evp_thunk_template, evp_thunk_template_len); + evp_thunk_dst_addr += evp_thunk_template_len; + evp_thunk_written = 1; + *iram_evp_thunks_len = evp_thunk_template_len; + + //write32(TEGRA_EXCEPTION_VECTORS_BASE + 0x208, iram_evp_thunks); + } + + u32 thunk_patch_len = insn_count * sizeof(u32); + memcpy(evp_thunk_dst_addr, &words[ipatch_count + 1], thunk_patch_len); + evp_thunk_dst_addr += thunk_patch_len; + *iram_evp_thunks_len += thunk_patch_len; + } + words[0] = word0; + if ((word0 >> 25) == 0) + break; + if (_patch_hash_one(&word0) >= 2) + { + return 3; + } + word_count = word0 >> 25; + } + + return 0; +} + +bool fuse_check_patched_rcm() +{ + // Check if XUSB in use. + if (FUSE(FUSE_RESERVED_SW) & (1<<7)) + return true; + + // Check if RCM is ipatched. + u32 word_count = FUSE(FUSE_FIRST_BOOTROM_PATCH_SIZE) & 0x7F; + u32 word_addr = 191; + + while (word_count) + { + u32 word0 = fuse_read(word_addr); + u32 ipatch_count = (word0 >> 16) & 0xF; + + for (u32 i = 0; i < ipatch_count; i++) + { + u32 word = fuse_read(word_addr - (i + 1)); + u32 addr = (word >> 16) * 2; + if (addr == 0x769A) + return true; + } + + word_addr -= word_count; + word_count = word0 >> 25; + } + + return false; +} diff --git a/nyx/nyx_gui/soc/fuse.h b/nyx/nyx_gui/soc/fuse.h new file mode 100644 index 0000000..614777f --- /dev/null +++ b/nyx/nyx_gui/soc/fuse.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 shuffle2 + * Copyright (c) 2018 balika011 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _FUSE_H_ +#define _FUSE_H_ + +#include "../utils/types.h" + +/*! Fuse registers. */ +#define FUSE_CTRL 0x0 +#define FUSE_ADDR 0x4 +#define FUSE_RDATA 0x8 +#define FUSE_WDATA 0xC +#define FUSE_TIME_RD1 0x10 +#define FUSE_TIME_RD2 0x14 +#define FUSE_TIME_PGM1 0x18 +#define FUSE_TIME_PGM2 0x1C +#define FUSE_PRIV2INTFC 0x20 +#define FUSE_FUSEBYPASS 0x24 +#define FUSE_PRIVATEKEYDISABLE 0x28 +#define FUSE_DISABLEREGPROGRAM 0x2C +#define FUSE_WRITE_ACCESS_SW 0x30 +#define FUSE_PWR_GOOD_SW 0x34 +#define FUSE_SKU_INFO 0x110 +#define FUSE_CPU_SPEEDO_0_CALIB 0x114 +#define FUSE_CPU_IDDQ_CALIB 0x118 +#define FUSE_OPT_FT_REV 0x128 +#define FUSE_CPU_SPEEDO_1_CALIB 0x12C +#define FUSE_CPU_SPEEDO_2_CALIB 0x130 +#define FUSE_SOC_SPEEDO_0_CALIB 0x134 +#define FUSE_SOC_SPEEDO_1_CALIB 0x138 +#define FUSE_SOC_SPEEDO_2_CALIB 0x13C +#define FUSE_SOC_IDDQ_CALIB 0x140 +#define FUSE_OPT_CP_REV 0x190 +#define FUSE_FIRST_BOOTROM_PATCH_SIZE 0x19c +#define FUSE_PRIVATE_KEY0 0x1A4 +#define FUSE_PRIVATE_KEY1 0x1A8 +#define FUSE_PRIVATE_KEY2 0x1AC +#define FUSE_PRIVATE_KEY3 0x1B0 +#define FUSE_PRIVATE_KEY4 0x1B4 +#define FUSE_RESERVED_SW 0x1C0 +#define FUSE_OPT_VENDOR_CODE 0x200 +#define FUSE_OPT_FAB_CODE 0x204 +#define FUSE_OPT_LOT_CODE_0 0x208 +#define FUSE_OPT_LOT_CODE_1 0x20C +#define FUSE_OPT_WAFER_ID 0x210 +#define FUSE_OPT_X_COORDINATE 0x214 +#define FUSE_OPT_Y_COORDINATE 0x218 +#define FUSE_GPU_IDDQ_CALIB 0x228 + +/*! Fuse commands. */ +#define FUSE_READ 0x1 +#define FUSE_WRITE 0x2 +#define FUSE_SENSE 0x3 +#define FUSE_CMD_MASK 0x3 + +/*! Fuse cache registers. */ +#define FUSE_RESERVED_ODMX(x) (0x1C8 + 4 * (x)) + +void fuse_disable_program(); +u32 fuse_read_odm(u32 idx); +void fuse_wait_idle(); +int fuse_read_ipatch(void (*ipatch)(u32 offset, u32 value)); +int fuse_read_evp_thunk(u32 *iram_evp_thunks, u32 *iram_evp_thunks_len); +void fuse_read_array(u32 *words); +bool fuse_check_patched_rcm(); + +#endif diff --git a/nyx/nyx_gui/soc/gpio.c b/nyx/nyx_gui/soc/gpio.c new file mode 100644 index 0000000..053c43a --- /dev/null +++ b/nyx/nyx_gui/soc/gpio.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../soc/gpio.h" +#include "../soc/t210.h" + +static const u16 _gpio_cnf[31] = { + 0x000, 0x004, 0x008, 0x00C, + 0x100, 0x104, 0x108, 0x10C, + 0x200, 0x204, 0x208, 0x20C, + 0x300, 0x304, 0x308, 0x30C, + 0x400, 0x404, 0x408, 0x40C, + 0x500, 0x504, 0x508, 0x50C, + 0x600, 0x604, 0x608, 0x60C, + 0x700, 0x704, 0x708 +}; + +static const u16 _gpio_oe[31] = { + 0x010, 0x014, 0x018, 0x01C, + 0x110, 0x114, 0x118, 0x11C, + 0x210, 0x214, 0x218, 0x21C, + 0x310, 0x314, 0x318, 0x31C, + 0x410, 0x414, 0x418, 0x41C, + 0x510, 0x514, 0x518, 0x51C, + 0x610, 0x614, 0x618, 0x61C, + 0x710, 0x714, 0x718 +}; + +static const u16 _gpio_out[31] = { + 0x020, 0x024, 0x028, 0x02C, + 0x120, 0x124, 0x128, 0x12C, + 0x220, 0x224, 0x228, 0x22C, + 0x320, 0x324, 0x328, 0x32C, + 0x420, 0x424, 0x428, 0x42C, + 0x520, 0x524, 0x528, 0x52C, + 0x620, 0x624, 0x628, 0x62C, + 0x720, 0x724, 0x728 +}; + +static const u16 _gpio_in[31] = { + 0x030, 0x034, 0x038, 0x03C, + 0x130, 0x134, 0x138, 0x13C, + 0x230, 0x234, 0x238, 0x23C, + 0x330, 0x334, 0x338, 0x33C, + 0x430, 0x434, 0x438, 0x43C, + 0x530, 0x534, 0x538, 0x53C, + 0x630, 0x634, 0x638, 0x63C, + 0x730, 0x734, 0x738 +}; + +void gpio_config(u32 port, u32 pins, int mode) +{ + if (mode) + GPIO(_gpio_cnf[port]) |= pins; + else + GPIO(_gpio_cnf[port]) &= ~pins; + (void)GPIO(_gpio_cnf[port]); +} + +void gpio_output_enable(u32 port, u32 pins, int enable) +{ + if (enable) + GPIO(_gpio_oe[port]) |= pins; + else + GPIO(_gpio_oe[port]) &= ~pins; + (void)GPIO(_gpio_oe[port]); +} + +void gpio_write(u32 port, u32 pins, int high) +{ + if (high) + GPIO(_gpio_out[port]) |= pins; + else + GPIO(_gpio_out[port]) &= ~pins; + (void)GPIO(_gpio_out[port]); +} + +int gpio_read(u32 port, u32 pins) +{ + return (GPIO(_gpio_in[port]) & pins) ? 1 : 0; +} diff --git a/nyx/nyx_gui/soc/gpio.h b/nyx/nyx_gui/soc/gpio.h new file mode 100644 index 0000000..83170b0 --- /dev/null +++ b/nyx/nyx_gui/soc/gpio.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _GPIO_H_ +#define _GPIO_H_ + +#include "../utils/types.h" + +#define GPIO_MODE_SPIO 0 +#define GPIO_MODE_GPIO 1 +#define GPIO_OUTPUT_DISABLE 0 +#define GPIO_OUTPUT_ENABLE 1 +#define GPIO_LOW 0 +#define GPIO_HIGH 1 + +/*! GPIO pins (0-7 for each port). */ +#define GPIO_PIN_0 (1 << 0) +#define GPIO_PIN_1 (1 << 1) +#define GPIO_PIN_2 (1 << 2) +#define GPIO_PIN_3 (1 << 3) +#define GPIO_PIN_4 (1 << 4) +#define GPIO_PIN_5 (1 << 5) +#define GPIO_PIN_6 (1 << 6) +#define GPIO_PIN_7 (1 << 7) + +/*! GPIO ports (A-EE). */ +#define GPIO_PORT_A 0 +#define GPIO_PORT_B 1 +#define GPIO_PORT_C 2 +#define GPIO_PORT_D 3 +#define GPIO_PORT_E 4 +#define GPIO_PORT_F 5 +#define GPIO_PORT_G 6 +#define GPIO_PORT_H 7 +#define GPIO_PORT_I 8 +#define GPIO_PORT_J 9 +#define GPIO_PORT_K 10 +#define GPIO_PORT_L 11 +#define GPIO_PORT_M 12 +#define GPIO_PORT_N 13 +#define GPIO_PORT_O 14 +#define GPIO_PORT_P 15 +#define GPIO_PORT_Q 16 +#define GPIO_PORT_R 17 +#define GPIO_PORT_S 18 +#define GPIO_PORT_T 19 +#define GPIO_PORT_U 20 +#define GPIO_PORT_V 21 +#define GPIO_PORT_W 22 +#define GPIO_PORT_X 23 +#define GPIO_PORT_Y 24 +#define GPIO_PORT_Z 25 +#define GPIO_PORT_AA 26 +#define GPIO_PORT_BB 27 +#define GPIO_PORT_CC 28 +#define GPIO_PORT_DD 29 +#define GPIO_PORT_EE 30 + +void gpio_config(u32 port, u32 pins, int mode); +void gpio_output_enable(u32 port, u32 pins, int enable); +void gpio_write(u32 port, u32 pins, int high); +int gpio_read(u32 port, u32 pins); + +#endif diff --git a/nyx/nyx_gui/soc/hw_init.c b/nyx/nyx_gui/soc/hw_init.c new file mode 100644 index 0000000..b354a5b --- /dev/null +++ b/nyx/nyx_gui/soc/hw_init.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018-2019 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "hw_init.h" +#include "bpmp.h" +#include "clock.h" +#include "gpio.h" +#include "pmc.h" +#include "t210.h" +#include "../mem/minerva.h" +#include "../gfx/di.h" +#include "../input/touch.h" +#include "../storage/sdmmc.h" +#include "../utils/util.h" + +extern sdmmc_t sd_sdmmc; + + +void reconfig_hw_workaround(bool extra_reconfig, u32 magic) +{ + // Flush and disable MMU. + bpmp_mmu_disable(); + bpmp_clk_rate_set(BPMP_CLK_NORMAL); + minerva_change_freq(FREQ_204); + + touch_power_off(); + + // Re-enable clocks to Audio Processing Engine as a workaround to hanging. + CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) |= (1 << 10); // Enable AHUB clock. + CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) |= (1 << 6); // Enable APE clock. + + if (extra_reconfig) + { + msleep(10); + PMC(APBDEV_PMC_PWR_DET_VAL) |= PMC_PWR_DET_SDMMC1_IO_EN; + + clock_disable_cl_dvfs(); + + // Disable Joy-con GPIOs. + gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO); + gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO); + gpio_config(GPIO_PORT_E, GPIO_PIN_6, GPIO_MODE_SPIO); + gpio_config(GPIO_PORT_H, GPIO_PIN_6, GPIO_MODE_SPIO); + } + + // Power off display. + display_end(); + + // Enable clock to USBD and init SDMMC1 to avoid hangs with bad hw inits. + if (magic == 0xBAADF00D) + { + CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_L) |= (1 << 22); + sdmmc_init(&sd_sdmmc, SDMMC_1, SDMMC_POWER_3_3, SDMMC_BUS_WIDTH_1, 5, 0); + clock_disable_cl_dvfs(); + + msleep(200); + } +} \ No newline at end of file diff --git a/nyx/nyx_gui/soc/hw_init.h b/nyx/nyx_gui/soc/hw_init.h new file mode 100644 index 0000000..fe4defa --- /dev/null +++ b/nyx/nyx_gui/soc/hw_init.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _HW_INIT_H_ +#define _HW_INIT_H_ + +#include "../utils/types.h" + +void reconfig_hw_workaround(bool extra_reconfig, u32 magic); + +#endif diff --git a/nyx/nyx_gui/soc/i2c.c b/nyx/nyx_gui/soc/i2c.c new file mode 100644 index 0000000..e845693 --- /dev/null +++ b/nyx/nyx_gui/soc/i2c.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "i2c.h" +#include "../utils/util.h" + +static u32 i2c_addrs[] = { + 0x7000C000, 0x7000C400, 0x7000C500, + 0x7000C700, 0x7000D000, 0x7000D100 +}; + +static void _i2c_wait(vu32 *base) +{ + base[I2C_CONFIG_LOAD] = 0x25; + for (u32 i = 0; i < 20; i++) + { + usleep(1); + if (!(base[I2C_CONFIG_LOAD] & 1)) + break; + } +} + +static int _i2c_send_pkt(u32 idx, u32 x, u8 *buf, u32 size) +{ + if (size > 4) + return 0; + + u32 tmp = 0; + memcpy(&tmp, buf, size); + + vu32 *base = (vu32 *)i2c_addrs[idx]; + base[I2C_CMD_ADDR0] = x << 1; //Set x (send mode). + base[I2C_CMD_DATA1] = tmp; //Set value. + base[I2C_CNFG] = (2 * size - 2) | 0x2800; //Set size and send mode. + _i2c_wait(base); //Kick transaction. + + base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200; + while (base[I2C_STATUS] & 0x100) + ; + + if (base[I2C_STATUS] << 28) + return 0; + + return 1; +} + +static int _i2c_recv_pkt(u32 idx, u8 *buf, u32 size, u32 x) +{ + if (size > 8) + return 0; + + vu32 *base = (vu32 *)i2c_addrs[idx]; + base[I2C_CMD_ADDR0] = (x << 1) | 1; // Set x (recv mode). + base[I2C_CNFG] = (size - 1) << 1 | 0x2840; // Set size and recv mode. + _i2c_wait(base); // Kick transaction. + + base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200; + while (base[I2C_STATUS] & 0x100) + ; + + if (base[I2C_STATUS] << 28) + return 0; + + u32 tmp = base[I2C_CMD_DATA1]; // Get LS value. + if (size > 4) + { + memcpy(buf, &tmp, 4); + tmp = base[I2C_CMD_DATA2]; // Get MS value. + memcpy(buf + 4, &tmp, size - 4); + } + else + memcpy(buf, &tmp, size); + + return 1; +} + +void i2c_init(u32 idx) +{ + vu32 *base = (vu32 *)i2c_addrs[idx]; + + base[I2C_CLK_DIVISOR_REGISTER] = 0x50001; + base[I2C_BUS_CLEAR_CONFIG] = 0x90003; + _i2c_wait(base); + + for (u32 i = 0; i < 10; i++) + { + usleep(20000); + if (base[INTERRUPT_STATUS_REGISTER] & 0x800) + break; + } + + (vu32)base[I2C_BUS_CLEAR_STATUS]; + base[INTERRUPT_STATUS_REGISTER] = base[INTERRUPT_STATUS_REGISTER]; +} + +int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size) +{ + u8 tmp[4]; + + if (size > 3) + return 0; + + tmp[0] = y; + memcpy(tmp + 1, buf, size); + + return _i2c_send_pkt(idx, x, tmp, size + 1); +} + +int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y) +{ + int res = _i2c_send_pkt(idx, x, (u8 *)&y, 1); + if (res) + res = _i2c_recv_pkt(idx, buf, size, x); + return res; +} + +int i2c_send_byte(u32 idx, u32 x, u32 y, u8 b) +{ + return i2c_send_buf_small(idx, x, y, &b, 1); +} + +u8 i2c_recv_byte(u32 idx, u32 x, u32 y) +{ + u8 tmp = 0; + i2c_recv_buf_small(&tmp, 1, idx, x, y); + return tmp; +} + diff --git a/nyx/nyx_gui/soc/i2c.h b/nyx/nyx_gui/soc/i2c.h new file mode 100644 index 0000000..e2b2af5 --- /dev/null +++ b/nyx/nyx_gui/soc/i2c.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _I2C_H_ +#define _I2C_H_ + +#include "../utils/types.h" + +#define I2C_1 0 +#define I2C_2 1 +#define I2C_3 2 +#define I2C_4 3 +#define I2C_5 4 +#define I2C_6 5 + +#define I2C_CNFG 0x00 +#define I2C_CMD_ADDR0 0x01 +#define I2C_CMD_DATA1 0x03 +#define I2C_CMD_DATA2 0x04 +#define I2C_STATUS 0x07 +#define INTERRUPT_STATUS_REGISTER 0x1A +#define I2C_CLK_DIVISOR_REGISTER 0x1B +#define I2C_BUS_CLEAR_CONFIG 0x21 +#define I2C_BUS_CLEAR_STATUS 0x22 +#define I2C_CONFIG_LOAD 0x23 + +void i2c_init(u32 idx); +int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size); +int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y); +int i2c_send_byte(u32 idx, u32 x, u32 y, u8 b); +u8 i2c_recv_byte(u32 idx, u32 x, u32 y); + +#endif diff --git a/nyx/nyx_gui/soc/kfuse.c b/nyx/nyx_gui/soc/kfuse.c new file mode 100644 index 0000000..16a7dbc --- /dev/null +++ b/nyx/nyx_gui/soc/kfuse.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../soc/kfuse.h" +#include "../soc/clock.h" +#include "../soc/t210.h" + +int kfuse_read(u32 *buf) +{ + int res = 0; + + clock_enable_kfuse(); + + while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE)) + ; + + if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS)) + goto out; + + KFUSE(KFUSE_KEYADDR) = KFUSE_KEYADDR_AUTOINC; + for (int i = 0; i < KFUSE_NUM_WORDS; i++) + buf[i] = KFUSE(KFUSE_KEYS); + + res = 1; + +out:; + clock_disable_kfuse(); + return res; +} diff --git a/nyx/nyx_gui/soc/kfuse.h b/nyx/nyx_gui/soc/kfuse.h new file mode 100644 index 0000000..f3d4903 --- /dev/null +++ b/nyx/nyx_gui/soc/kfuse.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _KFUSE_H_ +#define _KFUSE_H_ + +#include "../utils/types.h" + +#define KFUSE_STATE_SOFTRESET (1 << 31) +#define KFUSE_STATE_STOP (1 << 25) +#define KFUSE_STATE_RESTART (1 << 24) +#define KFUSE_STATE_CRCPASS (1 << 17) +#define KFUSE_STATE_DONE (1 << 16) +#define KFUSE_STATE_ERRBLOCK_MASK 0x3F00 +#define KFUSE_STATE_ERRBLOCK_SHIFT 8 +#define KFUSE_STATE_CURBLOCK_MASK 0x3F + +#define KFUSE_KEYADDR_AUTOINC (1<<16) + +#define KFUSE_STATE 0x80 +#define KFUSE_KEYADDR 0x88 +#define KFUSE_KEYS 0x8C + +#define KFUSE_NUM_WORDS 144 + +int kfuse_read(u32 *buf); + +#endif diff --git a/nyx/nyx_gui/soc/pinmux.c b/nyx/nyx_gui/soc/pinmux.c new file mode 100644 index 0000000..582ab29 --- /dev/null +++ b/nyx/nyx_gui/soc/pinmux.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../soc/pinmux.h" +#include "../soc/t210.h" + +void pinmux_config_uart(u32 idx) +{ + PINMUX_AUX(PINMUX_AUX_UARTX_TX(idx)) = 0; + PINMUX_AUX(PINMUX_AUX_UARTX_RX(idx)) = PINMUX_INPUT_ENABLE | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_UARTX_RTS(idx)) = 0; + PINMUX_AUX(PINMUX_AUX_UARTX_CTS(idx)) = PINMUX_INPUT_ENABLE | PINMUX_PULL_DOWN; +} + +void pinmux_config_i2c(u32 idx) +{ + PINMUX_AUX(PINMUX_AUX_X_I2C_SCL(idx)) = PINMUX_INPUT_ENABLE; + PINMUX_AUX(PINMUX_AUX_X_I2C_SDA(idx)) = PINMUX_INPUT_ENABLE; +} diff --git a/nyx/nyx_gui/soc/pinmux.h b/nyx/nyx_gui/soc/pinmux.h new file mode 100644 index 0000000..b17fb7f --- /dev/null +++ b/nyx/nyx_gui/soc/pinmux.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _PINMUX_H_ +#define _PINMUX_H_ + +#include "../utils/types.h" + +/*! APB MISC registers. */ +#define APB_MISC_GP_SDMMC1_CLK_LPBK_CONTROL 0x8D4 +#define APB_MISC_GP_SDMMC3_CLK_LPBK_CONTROL 0x8D8 +#define APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL 0xA98 +#define APB_MISC_GP_VGPIO_GPIO_MUX_SEL 0xB74 + +/*! Pinmux registers. */ +#define PINMUX_AUX_SDMMC1_CLK 0x00 +#define PINMUX_AUX_SDMMC1_CMD 0x04 +#define PINMUX_AUX_SDMMC1_DAT3 0x08 +#define PINMUX_AUX_SDMMC1_DAT2 0x0C +#define PINMUX_AUX_SDMMC1_DAT1 0x10 +#define PINMUX_AUX_SDMMC1_DAT0 0x14 +#define PINMUX_AUX_SDMMC3_CLK 0x1C +#define PINMUX_AUX_SDMMC3_CMD 0x20 +#define PINMUX_AUX_SDMMC3_DAT0 0x24 +#define PINMUX_AUX_SDMMC3_DAT1 0x28 +#define PINMUX_AUX_SDMMC3_DAT2 0x2C +#define PINMUX_AUX_SDMMC3_DAT3 0x30 +#define PINMUX_AUX_SATA_LED_ACTIVE 0x4C +#define PINMUX_AUX_DMIC3_CLK 0xB4 +#define PINMUX_AUX_DMIC3_DAT 0xB8 +#define PINMUX_AUX_CAM_I2C_SDA 0xD8 +#define PINMUX_AUX_UART2_TX 0xF4 +#define PINMUX_AUX_UART3_TX 0x104 +#define PINMUX_AUX_DAP4_DIN 0x148 +#define PINMUX_AUX_USB_VBUS_EN0 0x1A8 +#define PINMUX_AUX_WIFI_EN 0x1B4 +#define PINMUX_AUX_WIFI_RST 0x1B8 +#define PINMUX_AUX_DAP4_SCLK 0x150 +#define PINMUX_AUX_GPIO_X1_AUD 0x18C +#define PINMUX_AUX_GPIO_X3_AUD 0x190 +#define PINMUX_AUX_SPDIF_IN 0x1A4 +#define PINMUX_AUX_AP_WAKE_NFC 0x1CC +#define PINMUX_AUX_NFC_EN 0x1D0 +#define PINMUX_AUX_NFC_INT 0x1D4 +#define PINMUX_AUX_CAM1_PWDN 0x1EC +#define PINMUX_AUX_LCD_BL_PWM 0x1FC +#define PINMUX_AUX_LCD_BL_EN 0x200 +#define PINMUX_AUX_LCD_RST 0x204 +#define PINMUX_AUX_LCD_GPIO2 0x20C +#define PINMUX_AUX_TOUCH_INT 0x220 +#define PINMUX_AUX_MOTION_INT 0x224 +#define PINMUX_AUX_GPIO_PE6 0x248 +#define PINMUX_AUX_GPIO_PH6 0x250 +#define PINMUX_AUX_GPIO_PZ1 0x280 +/*! 0:UART-A, 1:UART-B, 3:UART-C, 3:UART-D */ +#define PINMUX_AUX_UARTX_TX(x) (0xE4 + 0x10 * (x)) +#define PINMUX_AUX_UARTX_RX(x) (0xE8 + 0x10 * (x)) +#define PINMUX_AUX_UARTX_RTS(x) (0xEC + 0x10 * (x)) +#define PINMUX_AUX_UARTX_CTS(x) (0xF0 + 0x10 * (x)) +/*! 0:GEN1, 1:GEN2, 2:GEN3, 3:CAM, 4:PWR */ +#define PINMUX_AUX_X_I2C_SCL(x) (0xBC + 8 * (x)) +#define PINMUX_AUX_X_I2C_SDA(x) (0xC0 + 8 * (x)) + +#define PINMUX_FUNC_MASK (3 << 0) + +#define PINMUX_PULL_MASK (3 << 2) +#define PINMUX_PULL_NONE (0 << 2) +#define PINMUX_PULL_DOWN (1 << 2) +#define PINMUX_PULL_UP (2 << 2) + +#define PINMUX_TRISTATE (1 << 4) +#define PINMUX_PARKED (1 << 5) +#define PINMUX_INPUT_ENABLE (1 << 6) +#define PINMUX_LOCK (1 << 7) +#define PINMUX_LPDR (1 << 8) +#define PINMUX_HSM (1 << 9) + +#define PINMUX_IO_HV (1 << 10) +#define PINMUX_OPEN_DRAIN (1 << 11) +#define PINMUX_SCHMT (1 << 12) + +#define PINMUX_DRIVE_1X (0 << 13) +#define PINMUX_DRIVE_2X (1 << 13) +#define PINMUX_DRIVE_3X (2 << 13) +#define PINMUX_DRIVE_4X (3 << 13) + +void pinmux_config_uart(u32 idx); +void pinmux_config_i2c(u32 idx); + +#endif diff --git a/nyx/nyx_gui/soc/pmc.h b/nyx/nyx_gui/soc/pmc.h new file mode 100644 index 0000000..ec8eb99 --- /dev/null +++ b/nyx/nyx_gui/soc/pmc.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 st4rk + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _PMC_H_ +#define _PMC_H_ + +/*! PMC registers. */ +#define APBDEV_PMC_CNTRL 0x0 +#define PMC_CNTRL_MAIN_RST (1 << 4) +#define APBDEV_PMC_SEC_DISABLE 0x4 +#define APBDEV_PMC_PWRGATE_TOGGLE 0x30 +#define APBDEV_PMC_PWRGATE_STATUS 0x38 +#define APBDEV_PMC_NO_IOPOWER 0x44 +#define APBDEV_PMC_SCRATCH0 0x50 +#define APBDEV_PMC_SCRATCH1 0x54 +#define APBDEV_PMC_SCRATCH20 0xA0 +#define APBDEV_PMC_PWR_DET_VAL 0xE4 +#define PMC_PWR_DET_SDMMC1_IO_EN (1 << 12) +#define APBDEV_PMC_DDR_PWR 0xE8 +#define APBDEV_PMC_CRYPTO_OP 0xF4 +#define PMC_CRYPTO_OP_SE_ENABLE 0 +#define PMC_CRYPTO_OP_SE_DISABLE 1 +#define APBDEV_PMC_SCRATCH33 0x120 +#define APBDEV_PMC_SCRATCH40 0x13C +#define APBDEV_PMC_OSC_EDPD_OVER 0x1A4 +#define APBDEV_PMC_RST_STATUS 0x1B4 +#define APBDEV_PMC_IO_DPD_REQ 0x1B8 +#define APBDEV_PMC_IO_DPD2_REQ 0x1C0 +#define APBDEV_PMC_VDDP_SEL 0x1CC +#define APBDEV_PMC_DDR_CFG 0x1D0 +#define APBDEV_PMC_SCRATCH45 0x234 +#define APBDEV_PMC_SCRATCH46 0x238 +#define APBDEV_PMC_SCRATCH49 0x244 +#define APBDEV_PMC_TSC_MULT 0x2B4 +#define APBDEV_PMC_SEC_DISABLE2 0x2C4 +#define APBDEV_PMC_WEAK_BIAS 0x2C8 +#define APBDEV_PMC_REG_SHORT 0x2CC +#define APBDEV_PMC_SEC_DISABLE3 0x2D8 +#define APBDEV_PMC_SECURE_SCRATCH21 0x334 +#define APBDEV_PMC_SECURE_SCRATCH32 0x360 +#define APBDEV_PMC_SECURE_SCRATCH49 0x3A4 +#define APBDEV_PMC_CNTRL2 0x440 +#define APBDEV_PMC_IO_DPD3_REQ 0x45C +#define APBDEV_PMC_IO_DPD4_REQ 0x464 +#define APBDEV_PMC_UTMIP_PAD_CFG1 0x4C4 +#define APBDEV_PMC_UTMIP_PAD_CFG3 0x4CC +#define APBDEV_PMC_DDR_CNTRL 0x4E4 +#define APBDEV_PMC_SEC_DISABLE4 0x5B0 +#define APBDEV_PMC_SEC_DISABLE5 0x5B4 +#define APBDEV_PMC_SEC_DISABLE6 0x5B8 +#define APBDEV_PMC_SEC_DISABLE7 0x5BC +#define APBDEV_PMC_SEC_DISABLE8 0x5C0 +#define APBDEV_PMC_SCRATCH188 0x810 +#define APBDEV_PMC_SCRATCH190 0x818 +#define APBDEV_PMC_SCRATCH200 0x840 + +#endif diff --git a/nyx/nyx_gui/soc/pmc_lp0_t210.h b/nyx/nyx_gui/soc/pmc_lp0_t210.h new file mode 100644 index 0000000..641d9f7 --- /dev/null +++ b/nyx/nyx_gui/soc/pmc_lp0_t210.h @@ -0,0 +1,564 @@ +/* + * Copyright (c) 2010-2015, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#ifndef _TEGRA210_PMC_H_ +#define _TEGRA210_PMC_H_ + +#include "../utils/types.h" + +struct tegra_pmc_regs +{ + u32 cntrl; + u32 sec_disable; + u32 pmc_swrst; + u32 wake_mask; + u32 wake_lvl; + u32 wake_status; + u32 sw_wake_status; + u32 dpd_pads_oride; + u32 dpd_sample; + u32 dpd_enable; + u32 pwrgate_timer_off; + u32 clamp_status; + u32 pwrgate_toggle; + u32 remove_clamping_cmd; + u32 pwrgate_status; + u32 pwrgood_timer; + u32 blink_timer; + u32 no_iopower; + u32 pwr_det; + u32 pwr_det_latch; + u32 scratch0; + u32 scratch1; + u32 scratch2; + u32 scratch3; + u32 scratch4; + u32 scratch5; + u32 scratch6; + u32 scratch7; + u32 scratch8; + u32 scratch9; + u32 scratch10; + u32 scratch11; + u32 scratch12; + u32 scratch13; + u32 scratch14; + u32 scratch15; + u32 scratch16; + u32 scratch17; + u32 scratch18; + u32 scratch19; + u32 odmdata; + u32 scratch21; + u32 scratch22; + u32 scratch23; + u32 secure_scratch0; + u32 secure_scratch1; + u32 secure_scratch2; + u32 secure_scratch3; + u32 secure_scratch4; + u32 secure_scratch5; + u32 cpupwrgood_timer; + u32 cpupwroff_timer; + u32 pg_mask; + u32 pg_mask_1; + u32 auto_wake_lvl; + u32 auto_wake_lvl_mask; + u32 wake_delay; + u32 pwr_det_val; + u32 ddr_pwr; + u32 usb_debounce_del; + u32 usb_a0; + u32 crypto_op; + u32 pllp_wb0_override; + u32 scratch24; + u32 scratch25; + u32 scratch26; + u32 scratch27; + u32 scratch28; + u32 scratch29; + u32 scratch30; + u32 scratch31; + u32 scratch32; + u32 scratch33; + u32 scratch34; + u32 scratch35; + u32 scratch36; + u32 scratch37; + u32 scratch38; + u32 scratch39; + u32 scratch40; + u32 scratch41; + u32 scratch42; + u32 bondout_mirror[3]; + u32 sys_33v_en; + u32 bondout_mirror_access; + u32 gate; + u32 wake2_mask; + u32 wake2_lvl; + u32 wake2_status; + u32 sw_wake2_status; + u32 auto_wake2_lvl_mask; + u32 pg_mask_2; + u32 pg_mask_ce1; + u32 pg_mask_ce2; + u32 pg_mask_ce3; + u32 pwrgate_timer_ce[7]; + u32 pcx_edpd_cntrl; + u32 osc_edpd_over; + u32 clk_out_cntrl; + u32 sata_pwrgt; + u32 sensor_ctrl; + u32 rst_status; + u32 io_dpd_req; + u32 io_dpd_status; + u32 io_dpd2_req; + u32 io_dpd2_status; + u32 sel_dpd_tim; + u32 vddp_sel; + u32 ddr_cfg; + u32 e_no_vttgen; + u8 _rsv0[4]; + u32 pllm_wb0_override_freq; + u32 test_pwrgate; + u32 pwrgate_timer_mult; + u32 dis_sel_dpd; + u32 utmip_uhsic_triggers; + u32 utmip_uhsic_saved_state; + u32 utmip_pad_cfg; + u32 utmip_term_pad_cfg; + u32 utmip_uhsic_sleep_cfg; + u32 utmip_uhsic_sleepwalk_cfg; + u32 utmip_sleepwalk_p[3]; + u32 uhsic_sleepwalk_p0; + u32 utmip_uhsic_status; + u32 utmip_uhsic_fake; + u32 bondout_mirror3[5 - 3]; + u32 secure_scratch6; + u32 secure_scratch7; + u32 scratch43; + u32 scratch44; + u32 scratch45; + u32 scratch46; + u32 scratch47; + u32 scratch48; + u32 scratch49; + u32 scratch50; + u32 scratch51; + u32 scratch52; + u32 scratch53; + u32 scratch54; + u32 scratch55; + u32 scratch0_eco; + u32 por_dpd_ctrl; + u32 scratch2_eco; + u32 utmip_uhsic_line_wakeup; + u32 utmip_bias_master_cntrl; + u32 utmip_master_config; + u32 td_pwrgate_inter_part_timer; + u32 utmip_uhsic2_triggers; + u32 utmip_uhsic2_saved_state; + u32 utmip_uhsic2_sleep_cfg; + u32 utmip_uhsic2_sleepwalk_cfg; + u32 uhsic2_sleepwalk_p1; + u32 utmip_uhsic2_status; + u32 utmip_uhsic2_fake; + u32 utmip_uhsic2_line_wakeup; + u32 utmip_master2_config; + u32 utmip_uhsic_rpd_cfg; + u32 pg_mask_ce0; + u32 pg_mask3[5 - 3]; + u32 pllm_wb0_override2; + u32 tsc_mult; + u32 cpu_vsense_override; + u32 glb_amap_cfg; + u32 sticky_bits; + u32 sec_disable2; + u32 weak_bias; + u32 reg_short; + u32 pg_mask_andor; + u8 _rsv1[0x2c]; + u32 secure_scratch8; /* offset 0x300 */ + u32 secure_scratch9; + u32 secure_scratch10; + u32 secure_scratch11; + u32 secure_scratch12; + u32 secure_scratch13; + u32 secure_scratch14; + u32 secure_scratch15; + u32 secure_scratch16; + u32 secure_scratch17; + u32 secure_scratch18; + u32 secure_scratch19; + u32 secure_scratch20; + u32 secure_scratch21; + u32 secure_scratch22; + u32 secure_scratch23; + u32 secure_scratch24; + u32 secure_scratch25; + u32 secure_scratch26; + u32 secure_scratch27; + u32 secure_scratch28; + u32 secure_scratch29; + u32 secure_scratch30; + u32 secure_scratch31; + u32 secure_scratch32; + u32 secure_scratch33; + u32 secure_scratch34; + u32 secure_scratch35; + u32 secure_scratch36; + u32 secure_scratch37; + u32 secure_scratch38; + u32 secure_scratch39; + u32 secure_scratch40; + u32 secure_scratch41; + u32 secure_scratch42; + u32 secure_scratch43; + u32 secure_scratch44; + u32 secure_scratch45; + u32 secure_scratch46; + u32 secure_scratch47; + u32 secure_scratch48; + u32 secure_scratch49; + u32 secure_scratch50; + u32 secure_scratch51; + u32 secure_scratch52; + u32 secure_scratch53; + u32 secure_scratch54; + u32 secure_scratch55; + u32 secure_scratch56; + u32 secure_scratch57; + u32 secure_scratch58; + u32 secure_scratch59; + u32 secure_scratch60; + u32 secure_scratch61; + u32 secure_scratch62; + u32 secure_scratch63; + u32 secure_scratch64; + u32 secure_scratch65; + u32 secure_scratch66; + u32 secure_scratch67; + u32 secure_scratch68; + u32 secure_scratch69; + u32 secure_scratch70; + u32 secure_scratch71; + u32 secure_scratch72; + u32 secure_scratch73; + u32 secure_scratch74; + u32 secure_scratch75; + u32 secure_scratch76; + u32 secure_scratch77; + u32 secure_scratch78; + u32 secure_scratch79; + u32 _rsv0x420[8]; + u32 cntrl2; /* 0x440 */ + u32 _rsv0x444[2]; + u32 event_counter; /* 0x44C */ + u32 fuse_control; + u32 scratch1_eco; + u32 _rsv0x458[1]; + u32 io_dpd3_req; /* 0x45C */ + u32 io_dpd3_status; + u32 io_dpd4_req; + u32 io_dpd4_status; + u32 _rsv0x46C[30]; + u32 ddr_cntrl; /* 0x4E4 */ + u32 _rsv0x4E8[70]; + u32 scratch56; /* 0x600 */ + u32 scratch57; + u32 scratch58; + u32 scratch59; + u32 scratch60; + u32 scratch61; + u32 scratch62; + u32 scratch63; + u32 scratch64; + u32 scratch65; + u32 scratch66; + u32 scratch67; + u32 scratch68; + u32 scratch69; + u32 scratch70; + u32 scratch71; + u32 scratch72; + u32 scratch73; + u32 scratch74; + u32 scratch75; + u32 scratch76; + u32 scratch77; + u32 scratch78; + u32 scratch79; + u32 scratch80; + u32 scratch81; + u32 scratch82; + u32 scratch83; + u32 scratch84; + u32 scratch85; + u32 scratch86; + u32 scratch87; + u32 scratch88; + u32 scratch89; + u32 scratch90; + u32 scratch91; + u32 scratch92; + u32 scratch93; + u32 scratch94; + u32 scratch95; + u32 scratch96; + u32 scratch97; + u32 scratch98; + u32 scratch99; + u32 scratch100; + u32 scratch101; + u32 scratch102; + u32 scratch103; + u32 scratch104; + u32 scratch105; + u32 scratch106; + u32 scratch107; + u32 scratch108; + u32 scratch109; + u32 scratch110; + u32 scratch111; + u32 scratch112; + u32 scratch113; + u32 scratch114; + u32 scratch115; + u32 scratch116; + u32 scratch117; + u32 scratch118; + u32 scratch119; + u32 scratch120; /* 0x700 */ + u32 scratch121; + u32 scratch122; + u32 scratch123; + u32 scratch124; + u32 scratch125; + u32 scratch126; + u32 scratch127; + u32 scratch128; + u32 scratch129; + u32 scratch130; + u32 scratch131; + u32 scratch132; + u32 scratch133; + u32 scratch134; + u32 scratch135; + u32 scratch136; + u32 scratch137; + u32 scratch138; + u32 scratch139; + u32 scratch140; + u32 scratch141; + u32 scratch142; + u32 scratch143; + u32 scratch144; + u32 scratch145; + u32 scratch146; + u32 scratch147; + u32 scratch148; + u32 scratch149; + u32 scratch150; + u32 scratch151; + u32 scratch152; + u32 scratch153; + u32 scratch154; + u32 scratch155; + u32 scratch156; + u32 scratch157; + u32 scratch158; + u32 scratch159; + u32 scratch160; + u32 scratch161; + u32 scratch162; + u32 scratch163; + u32 scratch164; + u32 scratch165; + u32 scratch166; + u32 scratch167; + u32 scratch168; + u32 scratch169; + u32 scratch170; + u32 scratch171; + u32 scratch172; + u32 scratch173; + u32 scratch174; + u32 scratch175; + u32 scratch176; + u32 scratch177; + u32 scratch178; + u32 scratch179; + u32 scratch180; + u32 scratch181; + u32 scratch182; + u32 scratch183; + u32 scratch184; + u32 scratch185; + u32 scratch186; + u32 scratch187; + u32 scratch188; + u32 scratch189; + u32 scratch190; + u32 scratch191; + u32 scratch192; + u32 scratch193; + u32 scratch194; + u32 scratch195; + u32 scratch196; + u32 scratch197; + u32 scratch198; + u32 scratch199; + u32 scratch200; + u32 scratch201; + u32 scratch202; + u32 scratch203; + u32 scratch204; + u32 scratch205; + u32 scratch206; + u32 scratch207; + u32 scratch208; + u32 scratch209; + u32 scratch210; + u32 scratch211; + u32 scratch212; + u32 scratch213; + u32 scratch214; + u32 scratch215; + u32 scratch216; + u32 scratch217; + u32 scratch218; + u32 scratch219; + u32 scratch220; + u32 scratch221; + u32 scratch222; + u32 scratch223; + u32 scratch224; + u32 scratch225; + u32 scratch226; + u32 scratch227; + u32 scratch228; + u32 scratch229; + u32 scratch230; + u32 scratch231; + u32 scratch232; + u32 scratch233; + u32 scratch234; + u32 scratch235; + u32 scratch236; + u32 scratch237; + u32 scratch238; + u32 scratch239; + u32 scratch240; + u32 scratch241; + u32 scratch242; + u32 scratch243; + u32 scratch244; + u32 scratch245; + u32 scratch246; + u32 scratch247; + u32 scratch248; + u32 scratch249; + u32 scratch250; + u32 scratch251; + u32 scratch252; + u32 scratch253; + u32 scratch254; + u32 scratch255; + u32 scratch256; + u32 scratch257; + u32 scratch258; + u32 scratch259; + u32 scratch260; + u32 scratch261; + u32 scratch262; + u32 scratch263; + u32 scratch264; + u32 scratch265; + u32 scratch266; + u32 scratch267; + u32 scratch268; + u32 scratch269; + u32 scratch270; + u32 scratch271; + u32 scratch272; + u32 scratch273; + u32 scratch274; + u32 scratch275; + u32 scratch276; + u32 scratch277; + u32 scratch278; + u32 scratch279; + u32 scratch280; + u32 scratch281; + u32 scratch282; + u32 scratch283; + u32 scratch284; + u32 scratch285; + u32 scratch286; + u32 scratch287; + u32 scratch288; + u32 scratch289; + u32 scratch290; + u32 scratch291; + u32 scratch292; + u32 scratch293; + u32 scratch294; + u32 scratch295; + u32 scratch296; + u32 scratch297; + u32 scratch298; + u32 scratch299; /* 0x9CC */ + u32 _rsv0x9D0[50]; + u32 secure_scratch80; /* 0xa98 */ + u32 secure_scratch81; + u32 secure_scratch82; + u32 secure_scratch83; + u32 secure_scratch84; + u32 secure_scratch85; + u32 secure_scratch86; + u32 secure_scratch87; + u32 secure_scratch88; + u32 secure_scratch89; + u32 secure_scratch90; + u32 secure_scratch91; + u32 secure_scratch92; + u32 secure_scratch93; + u32 secure_scratch94; + u32 secure_scratch95; + u32 secure_scratch96; + u32 secure_scratch97; + u32 secure_scratch98; + u32 secure_scratch99; + u32 secure_scratch100; + u32 secure_scratch101; + u32 secure_scratch102; + u32 secure_scratch103; + u32 secure_scratch104; + u32 secure_scratch105; + u32 secure_scratch106; + u32 secure_scratch107; + u32 secure_scratch108; + u32 secure_scratch109; + u32 secure_scratch110; + u32 secure_scratch111; + u32 secure_scratch112; + u32 secure_scratch113; + u32 secure_scratch114; + u32 secure_scratch115; + u32 secure_scratch116; + u32 secure_scratch117; + u32 secure_scratch118; + u32 secure_scratch119; +}; + +#endif /* _TEGRA210_PMC_H_ */ diff --git a/nyx/nyx_gui/soc/smmu.c b/nyx/nyx_gui/soc/smmu.c new file mode 100644 index 0000000..5aceaa4 --- /dev/null +++ b/nyx/nyx_gui/soc/smmu.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (c) 2018 balika011 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "smmu.h" +#include "../soc/cluster.h" +#include "../soc/t210.h" +#include "../mem/mc_t210.h" +#include "../utils/util.h" +#include "../utils/aarch64_util.h" + +bool smmu_used = false; +u8 *_pageheap = (u8 *)SMMU_HEAP_ADDR; + +//Enabling SMMU requires a TZ secure write: MC(MC_SMMU_CONFIG) = 1; +u8 smmu_payload[] __attribute__((aligned(16))) = { + 0x41, 0x01, 0x00, 0x58, // 0x00: LDR X1, =0x70019010 + 0x20, 0x00, 0x80, 0xD2, // 0x04: MOV X0, #0x1 + 0x20, 0x00, 0x00, 0xB9, // 0x08: STR W0, [X1] + 0x1F, 0x71, 0x08, 0xD5, // 0x0C: IC IALLUIS + 0x9F, 0x3B, 0x03, 0xD5, // 0x10: DSB ISH + 0xFE, 0xFF, 0xFF, 0x17, // 0x14: B loop + 0x00, 0x00, 0x80, 0xD2, // 0x18: MOV X0, #0x0 + 0x20, 0x00, 0x00, 0xB9, // 0x1C: STR W0, [X1] + 0x80, 0x00, 0x00, 0x58, // 0x20: LDR X0, =0x4002B000 + 0x00, 0x00, 0x1F, 0xD6, // 0x28: BR X0 + 0x10, 0x90, 0x01, 0x70, // 0x28: MC_SMMU_CONFIG + 0x00, 0x00, 0x00, 0x00, // 0x2C: + 0x00, 0x00, 0x00, 0x00, // 0x30: secmon address + 0x00, 0x00, 0x00, 0x00 // 0x34: +}; + +void *page_alloc(u32 num) +{ + u8 *res = _pageheap; + _pageheap += 0x1000 * num; + memset(res, 0, 0x1000 * num); + return res; +} + +u32 *smmu_alloc_pdir() +{ + u32 *pdir = (u32 *)page_alloc(1); + for (int pdn = 0; pdn < SMMU_PDIR_COUNT; pdn++) + pdir[pdn] = _PDE_VACANT(pdn); + return pdir; +} + +void smmu_flush_regs() +{ + (void)MC(MC_SMMU_PTB_DATA); +} + +void smmu_flush_all() +{ + MC(MC_SMMU_PTC_FLUSH) = 0; + smmu_flush_regs(); + MC(MC_SMMU_TLB_FLUSH) = 0; + smmu_flush_regs(); +} + +void smmu_init(u32 secmon_base) +{ + MC(MC_SMMU_PTB_ASID) = 0; + MC(MC_SMMU_PTB_DATA) = 0; + MC(MC_SMMU_TLB_CONFIG) = 0x30000030; + MC(MC_SMMU_PTC_CONFIG) = 0x28000F3F; + MC(MC_SMMU_PTC_FLUSH) = 0; + MC(MC_SMMU_TLB_FLUSH) = 0; + + // Set the secmon address + *(u32 *)(smmu_payload + 0x30) = secmon_base; +} + +void smmu_enable() +{ + if (smmu_used) + return; + + cluster_boot_cpu0((u32)smmu_payload); + smmu_used = true; + msleep(150); + + smmu_flush_all(); +} + +bool smmu_is_used() +{ + return smmu_used; +} + +void smmu_exit() +{ + *(uint32_t *)(smmu_payload + 0x14) = _NOP(); +} + +u32 *smmu_init_domain4(u32 dev_base, u32 asid) +{ + u32 *pdir = smmu_alloc_pdir(); + + MC(MC_SMMU_PTB_ASID) = asid; + MC(MC_SMMU_PTB_DATA) = SMMU_MK_PDIR((u32)pdir, _PDIR_ATTR); + smmu_flush_regs(); + + MC(dev_base) = 0x80000000 | (asid << 24) | (asid << 16) | (asid << 8) | (asid); + smmu_flush_regs(); + + return pdir; +} + +u32 *smmu_get_pte(u32 *pdir, u32 iova) +{ + u32 ptn = SMMU_ADDR_TO_PFN(iova); + u32 pdn = SMMU_ADDR_TO_PDN(iova); + u32 *ptbl; + + if (pdir[pdn] != _PDE_VACANT(pdn)) + ptbl = (u32 *)((pdir[pdn] & SMMU_PFN_MASK) << SMMU_PDIR_SHIFT); + else + { + ptbl = (u32 *)page_alloc(1); + u32 addr = SMMU_PDN_TO_ADDR(pdn); + for (int pn = 0; pn < SMMU_PTBL_COUNT; pn++, addr += SMMU_PAGE_SIZE) + ptbl[pn] = _PTE_VACANT(addr); + pdir[pdn] = SMMU_MK_PDE((u32)ptbl, _PDE_ATTR | _PDE_NEXT); + smmu_flush_all(); + } + + return &ptbl[ptn % SMMU_PTBL_COUNT]; +} + +void smmu_map(u32 *pdir, u32 addr, u32 page, int cnt, u32 attr) +{ + for (int i = 0; i < cnt; i++) + { + u32 *pte = smmu_get_pte(pdir, addr); + *pte = SMMU_ADDR_TO_PFN(page) | attr; + addr += 0x1000; + page += 0x1000; + } + smmu_flush_all(); +} + +u32 *smmu_init_for_tsec() +{ + return smmu_init_domain4(MC_SMMU_TSEC_ASID, 1); +} + +void smmu_deinit_for_tsec() +{ + MC(MC_SMMU_PTB_ASID) = 1; + MC(MC_SMMU_PTB_DATA) = 0; + MC(MC_SMMU_TSEC_ASID) = 0; + smmu_flush_regs(); +} + diff --git a/nyx/nyx_gui/soc/smmu.h b/nyx/nyx_gui/soc/smmu.h new file mode 100644 index 0000000..827d58b --- /dev/null +++ b/nyx/nyx_gui/soc/smmu.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../utils/types.h" + +#define SMMU_HEAP_ADDR 0xA0000000 + +#define MC_INTSTATUS 0x0 +#define MC_INTMASK 0x4 +#define MC_ERR_STATUS 0x8 +#define MC_ERR_ADR 0xc +#define MC_SMMU_CONFIG 0x10 +#define MC_SMMU_TLB_CONFIG 0x14 +#define MC_SMMU_PTC_CONFIG 0x18 +#define MC_SMMU_PTB_ASID 0x1c +#define MC_SMMU_PTB_DATA 0x20 +#define MC_SMMU_TLB_FLUSH 0x30 +#define MC_SMMU_PTC_FLUSH 0x34 +#define MC_SMMU_ASID_SECURITY 0x38 +#define MC_SMMU_TSEC_ASID 0x294 +#define MC_SMMU_TRANSLATION_ENABLE_0 0x228 +#define MC_SMMU_TRANSLATION_ENABLE_1 0x22c +#define MC_SMMU_TRANSLATION_ENABLE_2 0x230 +#define MC_SMMU_TRANSLATION_ENABLE_3 0x234 +#define MC_SMMU_TRANSLATION_ENABLE_4 0xb98 + +#define SMMU_PDE_NEXT_SHIFT 28 +#define MC_SMMU_PTB_DATA_0_ASID_NONSECURE_SHIFT 29 +#define MC_SMMU_PTB_DATA_0_ASID_WRITABLE_SHIFT 30 +#define MC_SMMU_PTB_DATA_0_ASID_READABLE_SHIFT 31 +#define SMMU_PAGE_SHIFT 12 +#define SMMU_PAGE_SIZE (1 << SMMU_PAGE_SHIFT) +#define SMMU_PDIR_COUNT 1024 +#define SMMU_PDIR_SIZE (sizeof(u32) * SMMU_PDIR_COUNT) +#define SMMU_PTBL_COUNT 1024 +#define SMMU_PTBL_SIZE (sizeof(u32) * SMMU_PTBL_COUNT) +#define SMMU_PDIR_SHIFT 12 +#define SMMU_PDE_SHIFT 12 +#define SMMU_PTE_SHIFT 12 +#define SMMU_PFN_MASK 0x000FFFFF +#define SMMU_ADDR_TO_PFN(addr) ((addr) >> 12) +#define SMMU_ADDR_TO_PDN(addr) ((addr) >> 22) +#define SMMU_PDN_TO_ADDR(addr) ((pdn) << 22) +#define _READABLE (1 << MC_SMMU_PTB_DATA_0_ASID_READABLE_SHIFT) +#define _WRITABLE (1 << MC_SMMU_PTB_DATA_0_ASID_WRITABLE_SHIFT) +#define _NONSECURE (1 << MC_SMMU_PTB_DATA_0_ASID_NONSECURE_SHIFT) +#define _PDE_NEXT (1 << SMMU_PDE_NEXT_SHIFT) +#define _MASK_ATTR (_READABLE | _WRITABLE | _NONSECURE) +#define _PDIR_ATTR (_READABLE | _WRITABLE | _NONSECURE) +#define _PDE_ATTR (_READABLE | _WRITABLE | _NONSECURE) +#define _PDE_VACANT(pdn) (((pdn) << 10) | _PDE_ATTR) +#define _PTE_ATTR (_READABLE | _WRITABLE | _NONSECURE) +#define _PTE_VACANT(addr) (((addr) >> SMMU_PAGE_SHIFT) | _PTE_ATTR) +#define SMMU_MK_PDIR(page, attr) (((page) >> SMMU_PDIR_SHIFT) | (attr)) +#define SMMU_MK_PDE(page, attr) (((page) >> SMMU_PDE_SHIFT) | (attr)) + +void *page_alloc(u32 num); +u32 *smmu_alloc_pdir(); +void smmu_flush_regs(); +void smmu_flush_all(); +void smmu_init(u32 secmon_base); +void smmu_enable(); +bool smmu_is_used(); +void smmu_exit(); +u32 *smmu_init_domain4(u32 dev_base, u32 asid); +u32 *smmu_get_pte(u32 *pdir, u32 iova); +void smmu_map(u32 *pdir, u32 addr, u32 page, int cnt, u32 attr); +u32 *smmu_init_for_tsec(); +void smmu_deinit_for_tsec(); diff --git a/nyx/nyx_gui/soc/t210.h b/nyx/nyx_gui/soc/t210.h new file mode 100644 index 0000000..1b11d72 --- /dev/null +++ b/nyx/nyx_gui/soc/t210.h @@ -0,0 +1,191 @@ +/* +* Copyright (c) 2018 naehrwert +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef _T210_H_ +#define _T210_H_ + +#include "../utils/types.h" + +#define BOOTROM_BASE 0x100000 +#define HOST1X_BASE 0x50000000 +#define BPMP_CACHE_BASE 0x50040000 +#define DISPLAY_A_BASE 0x54200000 +#define DSI_BASE 0x54300000 +#define VIC_BASE 0x54340000 +#define TSEC_BASE 0x54500000 +#define SOR1_BASE 0x54580000 +#define TMR_BASE 0x60005000 +#define CLOCK_BASE 0x60006000 +#define FLOW_CTLR_BASE 0x60007000 +#define SYSREG_BASE 0x6000C000 +#define SB_BASE (SYSREG_BASE + 0x200) +#define GPIO_BASE 0x6000D000 +#define GPIO_1_BASE (GPIO_BASE) +#define GPIO_2_BASE (GPIO_BASE + 0x100) +#define GPIO_3_BASE (GPIO_BASE + 0x200) +#define GPIO_4_BASE (GPIO_BASE + 0x300) +#define GPIO_5_BASE (GPIO_BASE + 0x400) +#define GPIO_6_BASE (GPIO_BASE + 0x500) +#define GPIO_7_BASE (GPIO_BASE + 0x600) +#define GPIO_8_BASE (GPIO_BASE + 0x700) +#define EXCP_VEC_BASE 0x6000F000 +#define IPATCH_BASE 0x6001DC00 +#define APB_MISC_BASE 0x70000000 +#define PINMUX_AUX_BASE 0x70003000 +#define UART_BASE 0x70006000 +#define PWM_BASE 0x7000A000 +#define RTC_BASE 0x7000E000 +#define PMC_BASE 0x7000E400 +#define SYSCTR0_BASE 0x700F0000 +#define FUSE_BASE 0x7000F800 +#define KFUSE_BASE 0x7000FC00 +#define SE_BASE 0x70012000 +#define MC_BASE 0x70019000 +#define EMC_BASE 0x7001B000 +#define MIPI_CAL_BASE 0x700E3000 +#define CL_DVFS_BASE 0x70110000 +#define I2S_BASE 0x702D1000 +#define TZRAM_BASE 0x7C010000 + +#define _REG(base, off) *(vu32 *)((base) + (off)) + +#define HOST1X(off) _REG(HOST1X_BASE, off) +#define BPMP_CACHE_CTRL(off) _REG(BPMP_CACHE_BASE, off) +#define DISPLAY_A(off) _REG(DISPLAY_A_BASE, off) +#define DSI(off) _REG(DSI_BASE, off) +#define VIC(off) _REG(VIC_BASE, off) +#define TSEC(off) _REG(TSEC_BASE, off) +#define SOR1(off) _REG(SOR1_BASE, off) +#define TMR(off) _REG(TMR_BASE, off) +#define CLOCK(off) _REG(CLOCK_BASE, off) +#define FLOW_CTLR(off) _REG(FLOW_CTLR_BASE, off) +#define SYSREG(off) _REG(SYSREG_BASE, off) +#define SB(off) _REG(SB_BASE, off) +#define GPIO(off) _REG(GPIO_BASE, off) +#define GPIO_1(off) _REG(GPIO_1_BASE, off) +#define GPIO_2(off) _REG(GPIO_2_BASE, off) +#define GPIO_3(off) _REG(GPIO_3_BASE, off) +#define GPIO_4(off) _REG(GPIO_4_BASE, off) +#define GPIO_5(off) _REG(GPIO_5_BASE, off) +#define GPIO_6(off) _REG(GPIO_6_BASE, off) +#define GPIO_7(off) _REG(GPIO_7_BASE, off) +#define GPIO_8(off) _REG(GPIO_8_BASE, off) +#define EXCP_VEC(off) _REG(EXCP_VEC_BASE, off) +#define APB_MISC(off) _REG(APB_MISC_BASE, off) +#define PINMUX_AUX(off) _REG(PINMUX_AUX_BASE, off) +#define PWM(off) _REG(PWM_BASE, off) +#define RTC(off) _REG(RTC_BASE, off) +#define PMC(off) _REG(PMC_BASE, off) +#define SYSCTR0(off) _REG(SYSCTR0_BASE, off) +#define FUSE(off) _REG(FUSE_BASE, off) +#define KFUSE(off) _REG(KFUSE_BASE, off) +#define SE(off) _REG(SE_BASE, off) +#define MC(off) _REG(MC_BASE, off) +#define EMC(off) _REG(EMC_BASE, off) +#define MIPI_CAL(off) _REG(MIPI_CAL_BASE, off) +#define I2S(off) _REG(I2S_BASE, off) +#define CL_DVFS(off) _REG(CL_DVFS_BASE, off) +#define TEST_REG(off) _REG(0x0, off) + +/*! EVP registers. */ +#define EVP_CPU_RESET_VECTOR 0x100 + +/*! Misc registers. */ +#define APB_MISC_PP_STRAPPING_OPT_A 0x08 +#define APB_MISC_PP_PINMUX_GLOBAL 0x40 +#define APB_MISC_GP_LCD_BL_PWM_CFGPADCTRL 0xA34 +#define APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL 0xA98 +#define APB_MISC_GP_EMMC4_PAD_CFGPADCTRL 0xAB4 +#define APB_MISC_GP_WIFI_EN_CFGPADCTRL 0xB64 +#define APB_MISC_GP_WIFI_RST_CFGPADCTRL 0xB68 + +/*! System registers. */ +#define AHB_ARBITRATION_XBAR_CTRL 0xE0 +#define AHB_AHB_SPARE_REG 0x110 + +/*! Secure boot registers. */ +#define SB_CSR 0x0 +#define SB_AA64_RESET_LOW 0x30 +#define SB_AA64_RESET_HIGH 0x34 + +/*! SOR registers. */ +#define SOR_NV_PDISP_SOR_DP_HDCP_BKSV_LSB 0x1E8 +#define SOR_NV_PDISP_SOR_TMDS_HDCP_BKSV_LSB 0x21C +#define SOR_NV_PDISP_SOR_TMDS_HDCP_CN_MSB 0x208 +#define SOR_NV_PDISP_SOR_TMDS_HDCP_CN_LSB 0x20C + +/*! RTC registers. */ +#define APBDEV_RTC_SECONDS 0x8 +#define APBDEV_RTC_SHADOW_SECONDS 0xC +#define APBDEV_RTC_MILLI_SECONDS 0x10 + +/*! SYSCTR0 registers. */ +#define SYSCTR0_CNTFID0 0x20 +#define SYSCTR0_CNTCR 0x00 +#define SYSCTR0_COUNTERID0 0xFE0 +#define SYSCTR0_COUNTERID1 0xFE4 +#define SYSCTR0_COUNTERID2 0xFE8 +#define SYSCTR0_COUNTERID3 0xFEC +#define SYSCTR0_COUNTERID4 0xFD0 +#define SYSCTR0_COUNTERID5 0xFD4 +#define SYSCTR0_COUNTERID6 0xFD8 +#define SYSCTR0_COUNTERID7 0xFDC +#define SYSCTR0_COUNTERID8 0xFF0 +#define SYSCTR0_COUNTERID9 0xFF4 +#define SYSCTR0_COUNTERID10 0xFF8 +#define SYSCTR0_COUNTERID11 0xFFC + +/*! TMR registers. */ +#define TIMERUS_CNTR_1US (0x10 + 0x0) +#define TIMERUS_USEC_CFG (0x10 + 0x4) +#define TIMER_TMR9_TMR_PTV 0x80 +#define TIMER_EN (1 << 31) +#define TIMER_PER_EN (1 << 30) +#define TIMER_WDT4_CONFIG (0x100 + 0x80) +#define TIMER_SRC(TMR) (TMR & 0xF) +#define TIMER_PER(PER) ((PER & 0xFF) << 4) +#define TIMER_SYSRESET_EN (1 << 14) +#define TIMER_PMCRESET_EN (1 << 15) +#define TIMER_WDT4_COMMAND (0x108 + 0x80) +#define TIMER_START_CNT (1 << 0) +#define TIMER_CNT_DISABLE (1 << 1) +#define TIMER_WDT4_UNLOCK_PATTERN (0x10C + 0x80) +#define TIMER_MAGIC_PTRN 0xC45A + +/*! I2S registers. */ +#define I2S1_CG 0x88 +#define I2S1_CTRL 0xA0 +#define I2S2_CG 0x188 +#define I2S2_CTRL 0x1A0 +#define I2S3_CG 0x288 +#define I2S3_CTRL 0x2A0 +#define I2S4_CG 0x388 +#define I2S4_CTRL 0x3A0 +#define I2S5_CG 0x488 +#define I2S5_CTRL 0x4A0 +#define I2S_CG_SLCG_ENABLE (1 << 0) +#define I2S_CTRL_MASTER_EN (1 << 10) + +/*! PWM registers. */ +#define PWM_CONTROLLER_PWM_CSR_0 0x00 +#define PWM_CONTROLLER_PWM_CSR_1 0x10 + +/*! Special registers. */ +#define EMC_SCRATCH0 0x324 +#define EMC_HEKA_UPD (1 << 30) +#define EMC_SEPT_RUN (1 << 31) + +#endif diff --git a/nyx/nyx_gui/soc/uart.c b/nyx/nyx_gui/soc/uart.c new file mode 100644 index 0000000..056f864 --- /dev/null +++ b/nyx/nyx_gui/soc/uart.c @@ -0,0 +1,83 @@ +/* +* Copyright (c) 2018 naehrwert +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#include "../soc/uart.h" +#include "../soc/t210.h" +#include "../utils/util.h" + +/* UART A, B, C, D and E. */ +static const u32 uart_baseoff[5] = { 0, 0x40, 0x200, 0x300, 0x400 }; + +void uart_init(u32 idx, u32 baud) +{ + uart_t *uart = (uart_t *)(UART_BASE + uart_baseoff[idx]); + + // Make sure no data is being sent. + uart_wait_idle(idx, UART_TX_IDLE); + + // Misc settings. + u32 rate = (8 * baud + 408000000) / (16 * baud); + uart->UART_IER_DLAB = 0; // Disable interrupts. + uart->UART_MCR = 0; // Disable hardware flow control. + uart->UART_LCR = UART_LCR_DLAB | UART_LCR_WORD_LENGTH_8; // Enable DLAB & set 8n1 mode. + uart->UART_THR_DLAB = (u8)rate; // Divisor latch LSB. + uart->UART_IER_DLAB = (u8)(rate >> 8); // Divisor latch MSB. + uart->UART_LCR = UART_LCR_WORD_LENGTH_8; // Diable DLAB. + + // Setup and flush fifo. + uart->UART_IIR_FCR = UART_IIR_FCR_EN_FIFO | UART_IIR_FCR_RX_CLR | UART_IIR_FCR_TX_CLR; + usleep(3 * ((baud + 999999) / baud)); + uart_wait_idle(idx, UART_TX_IDLE | UART_RX_IDLE); +} + +void uart_wait_idle(u32 idx, u32 which) +{ + uart_t *uart = (uart_t *)(UART_BASE + uart_baseoff[idx]); + if (UART_TX_IDLE & which) + { + while (!(uart->UART_LSR & UART_LSR_TMTY)) + ; + } + if (UART_RX_IDLE & which) + { + while (uart->UART_LSR & UART_LSR_RDR) + ; + } +} + +void uart_send(u32 idx, u8 *buf, u32 len) +{ + uart_t *uart = (uart_t *)(UART_BASE + uart_baseoff[idx]); + + for (u32 i = 0; i != len; i++) + { + while (!(uart->UART_LSR & UART_LSR_THRE)) + ; + uart->UART_THR_DLAB = buf[i]; + }; +} + +void uart_recv(u32 idx, u8 *buf, u32 len) +{ + uart_t *uart = (uart_t *)(UART_BASE + uart_baseoff[idx]); + + for (u32 i = 0; i != len; i++) + { + while (!(uart->UART_LSR & UART_LSR_RDR)) + ; + buf[i] = uart->UART_THR_DLAB; + }; +} diff --git a/nyx/nyx_gui/soc/uart.h b/nyx/nyx_gui/soc/uart.h new file mode 100644 index 0000000..78f3c15 --- /dev/null +++ b/nyx/nyx_gui/soc/uart.h @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2018 naehrwert +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef _UART_H_ +#define _UART_H_ + +#include "../utils/types.h" + +#define UART_A 0 +#define UART_B 1 +#define UART_C 2 +//TODO: define clock inits for those. +/*#define UART_D 3 +#define UART_E 4*/ + +#define BAUD_115200 115200 + +#define UART_TX_IDLE 0x1 +#define UART_RX_IDLE 0x2 + +#define UART_TX_FIFO_FULL 0x100 +#define UART_RX_FIFO_EMPTY 0x200 + +#define UART_LCR_DLAB 0x80 +#define UART_LCR_WORD_LENGTH_8 0x3 +#define UART_LSR_RDR 0x1 +#define UART_LSR_THRE 0x20 +#define UART_LSR_TMTY 0x40 +#define UART_IIR_FCR_TX_CLR 0x4 +#define UART_IIR_FCR_RX_CLR 0x2 +#define UART_IIR_FCR_EN_FIFO 0x1 + +typedef struct _uart_t +{ + /* 0x00 */ vu32 UART_THR_DLAB; + /* 0x04 */ vu32 UART_IER_DLAB; + /* 0x08 */ vu32 UART_IIR_FCR; + /* 0x0C */ vu32 UART_LCR; + /* 0x10 */ vu32 UART_MCR; + /* 0x14 */ vu32 UART_LSR; + /* 0x18 */ vu32 UART_MSR; + /* 0x1C */ vu32 UART_SPR; + /* 0x20 */ vu32 UART_IRDA_CSR; + /* 0x24 */ vu32 UART_RX_FIFO_CFG; + /* 0x28 */ vu32 UART_MIE; + /* 0x2C */ vu32 UART_VENDOR_STATUS; + /* 0x30 */ u8 _pad_30[0xC]; + /* 0x3C */ vu32 UART_ASR; +} uart_t; + +void uart_init(u32 idx, u32 baud); +void uart_wait_idle(u32 idx, u32 which); +void uart_send(u32 idx, u8 *buf, u32 len); +void uart_recv(u32 idx, u8 *buf, u32 len); + +#endif diff --git a/nyx/nyx_gui/start.S b/nyx/nyx_gui/start.S new file mode 100644 index 0000000..534f963 --- /dev/null +++ b/nyx/nyx_gui/start.S @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2018 naehrwert +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +.section .text._start +.arm + +.extern _reloc_ipl +.type _reloc_ipl, %function + +.extern memset +.type memset, %function + +.extern ipl_main +.type ipl_main, %function + +.globl _start +.type _start, %function +_start: + ADR R0, _start + LDR R1, =__ipl_start + CMP R0, R1 + BEQ _real_start + + /* If we are not in the right location already, copy a relocator to upper IRAM. */ + ADR R2, _reloc_ipl + LDR R3, =0x4003FF00 + MOV R4, #(_real_start - _reloc_ipl) +_copy_loop: + LDMIA R2!, {R5} + STMIA R3!, {R5} + SUBS R4, #4 + BNE _copy_loop + + /* Use the relocator to copy ourselves into the right place. */ + LDR R2, =__ipl_end + SUB R2, R2, R1 + LDR R3, =_real_start + LDR R4, =0x4003FF00 + BX R4 + +_reloc_ipl: + LDMIA R0!, {R4-R7} + STMIA R1!, {R4-R7} + SUBS R2, #0x10 + BNE _reloc_ipl + /* Jump to the relocated entry. */ + BX R3 + +_real_start: + /* Initially, we place our stack in IRAM but will move it to SDRAM later. */ + LDR SP, =0x4003FF00 + LDR R0, =__bss_start + EOR R1, R1, R1 + LDR R2, =__bss_end + SUB R2, R2, R0 + BL memset + BL ipl_main + B . + +.globl pivot_stack +.type pivot_stack, %function +pivot_stack: + MOV SP, R0 + BX LR diff --git a/nyx/nyx_gui/storage/mmc.h b/nyx/nyx_gui/storage/mmc.h new file mode 100644 index 0000000..dddb956 --- /dev/null +++ b/nyx/nyx_gui/storage/mmc.h @@ -0,0 +1,432 @@ +/* + * Header for MultiMediaCard (MMC) + * + * Copyright 2002 Hewlett-Packard Company + * + * Use consistent with the GNU GPL is permitted, + * provided that this copyright notice is + * preserved in its entirety in all copies and derived works. + * + * HEWLETT-PACKARD COMPANY MAKES NO WARRANTIES, EXPRESSED OR IMPLIED, + * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS + * FITNESS FOR ANY PARTICULAR PURPOSE. + * + * Many thanks to Alessandro Rubini and Jonathan Corbet! + * + * Based strongly on code by: + * + * Author: Yong-iL Joh + * + * Author: Andrew Christian + * 15 May 2002 + */ + +#ifndef LINUX_MMC_MMC_H +#define LINUX_MMC_MMC_H + +/* Standard MMC commands (4.1) type argument response */ +/* class 1 */ +#define MMC_GO_IDLE_STATE 0 /* bc */ +#define MMC_SEND_OP_COND 1 /* bcr [31:0] OCR R3 */ +#define MMC_ALL_SEND_CID 2 /* bcr R2 */ +#define MMC_SET_RELATIVE_ADDR 3 /* ac [31:16] RCA R1 */ +#define MMC_SET_DSR 4 /* bc [31:16] RCA */ +#define MMC_SLEEP_AWAKE 5 /* ac [31:16] RCA 15:flg R1b */ +#define MMC_SWITCH 6 /* ac [31:0] See below R1b */ +#define MMC_SELECT_CARD 7 /* ac [31:16] RCA R1 */ +#define MMC_SEND_EXT_CSD 8 /* adtc R1 */ +#define MMC_SEND_CSD 9 /* ac [31:16] RCA R2 */ +#define MMC_SEND_CID 10 /* ac [31:16] RCA R2 */ +#define MMC_READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */ +#define MMC_STOP_TRANSMISSION 12 /* ac R1b */ +#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */ +#define MMC_BUS_TEST_R 14 /* adtc R1 */ +#define MMC_GO_INACTIVE_STATE 15 /* ac [31:16] RCA */ +#define MMC_BUS_TEST_W 19 /* adtc R1 */ +#define MMC_SPI_READ_OCR 58 /* spi spi_R3 */ +#define MMC_SPI_CRC_ON_OFF 59 /* spi [0:0] flag spi_R1 */ + +/* class 2 */ +#define MMC_SET_BLOCKLEN 16 /* ac [31:0] block len R1 */ +#define MMC_READ_SINGLE_BLOCK 17 /* adtc [31:0] data addr R1 */ +#define MMC_READ_MULTIPLE_BLOCK 18 /* adtc [31:0] data addr R1 */ +#define MMC_SEND_TUNING_BLOCK 19 /* adtc R1 */ +#define MMC_SEND_TUNING_BLOCK_HS200 21 /* adtc R1 */ + +/* class 3 */ +#define MMC_WRITE_DAT_UNTIL_STOP 20 /* adtc [31:0] data addr R1 */ + +/* class 4 */ +#define MMC_SET_BLOCK_COUNT 23 /* adtc [31:0] data addr R1 */ +#define MMC_WRITE_BLOCK 24 /* adtc [31:0] data addr R1 */ +#define MMC_WRITE_MULTIPLE_BLOCK 25 /* adtc R1 */ +#define MMC_PROGRAM_CID 26 /* adtc R1 */ +#define MMC_PROGRAM_CSD 27 /* adtc R1 */ + +/* class 6 */ +#define MMC_SET_WRITE_PROT 28 /* ac [31:0] data addr R1b */ +#define MMC_CLR_WRITE_PROT 29 /* ac [31:0] data addr R1b */ +#define MMC_SEND_WRITE_PROT 30 /* adtc [31:0] wpdata addr R1 */ + +/* class 5 */ +#define MMC_ERASE_GROUP_START 35 /* ac [31:0] data addr R1 */ +#define MMC_ERASE_GROUP_END 36 /* ac [31:0] data addr R1 */ +#define MMC_ERASE 38 /* ac R1b */ + +/* class 9 */ +#define MMC_FAST_IO 39 /* ac R4 */ +#define MMC_GO_IRQ_STATE 40 /* bcr R5 */ + +/* class 7 */ +#define MMC_LOCK_UNLOCK 42 /* adtc R1b */ + +/* class 8 */ +#define MMC_APP_CMD 55 /* ac [31:16] RCA R1 */ +#define MMC_GEN_CMD 56 /* adtc [0] RD/WR R1 */ + +/* class 11 */ +#define MMC_QUE_TASK_PARAMS 44 /* ac [20:16] task id R1 */ +#define MMC_QUE_TASK_ADDR 45 /* ac [31:0] data addr R1 */ +#define MMC_EXECUTE_READ_TASK 46 /* adtc [20:16] task id R1 */ +#define MMC_EXECUTE_WRITE_TASK 47 /* adtc [20:16] task id R1 */ +#define MMC_CMDQ_TASK_MGMT 48 /* ac [20:16] task id R1b */ + +/* +* MMC_SWITCH argument format: +* +* [31:26] Always 0 +* [25:24] Access Mode +* [23:16] Location of target Byte in EXT_CSD +* [15:08] Value Byte +* [07:03] Always 0 +* [02:00] Command Set +*/ + +/* +MMC status in R1, for native mode (SPI bits are different) +Type +e : error bit +s : status bit +r : detected and set for the actual command response +x : detected and set during command execution. the host must poll +the card by sending status command in order to read these bits. +Clear condition +a : according to the card state +b : always related to the previous command. Reception of +a valid command will clear it (with a delay of one command) +c : clear by read +*/ + +#define R1_OUT_OF_RANGE (1 << 31) /* er, c */ +#define R1_ADDRESS_ERROR (1 << 30) /* erx, c */ +#define R1_BLOCK_LEN_ERROR (1 << 29) /* er, c */ +#define R1_ERASE_SEQ_ERROR (1 << 28) /* er, c */ +#define R1_ERASE_PARAM (1 << 27) /* ex, c */ +#define R1_WP_VIOLATION (1 << 26) /* erx, c */ +#define R1_CARD_IS_LOCKED (1 << 25) /* sx, a */ +#define R1_LOCK_UNLOCK_FAILED (1 << 24) /* erx, c */ +#define R1_COM_CRC_ERROR (1 << 23) /* er, b */ +#define R1_ILLEGAL_COMMAND (1 << 22) /* er, b */ +#define R1_CARD_ECC_FAILED (1 << 21) /* ex, c */ +#define R1_CC_ERROR (1 << 20) /* erx, c */ +#define R1_ERROR (1 << 19) /* erx, c */ +#define R1_UNDERRUN (1 << 18) /* ex, c */ +#define R1_OVERRUN (1 << 17) /* ex, c */ +#define R1_CID_CSD_OVERWRITE (1 << 16) /* erx, c, CID/CSD overwrite */ +#define R1_WP_ERASE_SKIP (1 << 15) /* sx, c */ +#define R1_CARD_ECC_DISABLED (1 << 14) /* sx, a */ +#define R1_ERASE_RESET (1 << 13) /* sr, c */ +#define R1_STATUS(x) (x & 0xFFFFE000) +#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */ +#define R1_READY_FOR_DATA (1 << 8) /* sx, a */ +#define R1_SWITCH_ERROR (1 << 7) /* sx, c */ +#define R1_EXCEPTION_EVENT (1 << 6) /* sr, a */ +#define R1_APP_CMD (1 << 5) /* sr, c */ + +#define R1_STATE_IDLE 0 +#define R1_STATE_READY 1 +#define R1_STATE_IDENT 2 +#define R1_STATE_STBY 3 +#define R1_STATE_TRAN 4 +#define R1_STATE_DATA 5 +#define R1_STATE_RCV 6 +#define R1_STATE_PRG 7 +#define R1_STATE_DIS 8 + +/* +* MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS +* R1 is the low order byte; R2 is the next highest byte, when present. +*/ +#define R1_SPI_IDLE (1 << 0) +#define R1_SPI_ERASE_RESET (1 << 1) +#define R1_SPI_ILLEGAL_COMMAND (1 << 2) +#define R1_SPI_COM_CRC (1 << 3) +#define R1_SPI_ERASE_SEQ (1 << 4) +#define R1_SPI_ADDRESS (1 << 5) +#define R1_SPI_PARAMETER (1 << 6) +/* R1 bit 7 is always zero */ +#define R2_SPI_CARD_LOCKED (1 << 8) +#define R2_SPI_WP_ERASE_SKIP (1 << 9) /* or lock/unlock fail */ +#define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP +#define R2_SPI_ERROR (1 << 10) +#define R2_SPI_CC_ERROR (1 << 11) +#define R2_SPI_CARD_ECC_ERROR (1 << 12) +#define R2_SPI_WP_VIOLATION (1 << 13) +#define R2_SPI_ERASE_PARAM (1 << 14) +#define R2_SPI_OUT_OF_RANGE (1 << 15) /* or CSD overwrite */ +#define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE + +/* +* OCR bits are mostly in host.h +*/ +#define MMC_CARD_BUSY 0x80000000 /* Card Power up status bit */ + +/* +* Card Command Classes (CCC) +*/ +#define CCC_BASIC (1<<0) /* (0) Basic protocol functions */ +/* (CMD0,1,2,3,4,7,9,10,12,13,15) */ +/* (and for SPI, CMD58,59) */ +#define CCC_STREAM_READ (1<<1) /* (1) Stream read commands */ +/* (CMD11) */ +#define CCC_BLOCK_READ (1<<2) /* (2) Block read commands */ +/* (CMD16,17,18) */ +#define CCC_STREAM_WRITE (1<<3) /* (3) Stream write commands */ +/* (CMD20) */ +#define CCC_BLOCK_WRITE (1<<4) /* (4) Block write commands */ +/* (CMD16,24,25,26,27) */ +#define CCC_ERASE (1<<5) /* (5) Ability to erase blocks */ +/* (CMD32,33,34,35,36,37,38,39) */ +#define CCC_WRITE_PROT (1<<6) /* (6) Able to write protect blocks */ +/* (CMD28,29,30) */ +#define CCC_LOCK_CARD (1<<7) /* (7) Able to lock down card */ +/* (CMD16,CMD42) */ +#define CCC_APP_SPEC (1<<8) /* (8) Application specific */ +/* (CMD55,56,57,ACMD*) */ +#define CCC_IO_MODE (1<<9) /* (9) I/O mode */ +/* (CMD5,39,40,52,53) */ +#define CCC_SWITCH (1<<10) /* (10) High speed switch */ +/* (CMD6,34,35,36,37,50) */ +/* (11) Reserved */ +/* (CMD?) */ + +/* +* CSD field definitions +*/ + +#define CSD_STRUCT_VER_1_0 0 /* Valid for system specification 1.0 - 1.2 */ +#define CSD_STRUCT_VER_1_1 1 /* Valid for system specification 1.4 - 2.2 */ +#define CSD_STRUCT_VER_1_2 2 /* Valid for system specification 3.1 - 3.2 - 3.31 - 4.0 - 4.1 */ +#define CSD_STRUCT_EXT_CSD 3 /* Version is coded in CSD_STRUCTURE in EXT_CSD */ + +#define CSD_SPEC_VER_0 0 /* Implements system specification 1.0 - 1.2 */ +#define CSD_SPEC_VER_1 1 /* Implements system specification 1.4 */ +#define CSD_SPEC_VER_2 2 /* Implements system specification 2.0 - 2.2 */ +#define CSD_SPEC_VER_3 3 /* Implements system specification 3.1 - 3.2 - 3.31 */ +#define CSD_SPEC_VER_4 4 /* Implements system specification 4.0 - 4.1 */ + +/* +* EXT_CSD fields +*/ + +#define EXT_CSD_CMDQ_MODE_EN 15 /* R/W */ +#define EXT_CSD_FLUSH_CACHE 32 /* W */ +#define EXT_CSD_CACHE_CTRL 33 /* R/W */ +#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */ +#define EXT_CSD_PACKED_FAILURE_INDEX 35 /* RO */ +#define EXT_CSD_PACKED_CMD_STATUS 36 /* RO */ +#define EXT_CSD_EXP_EVENTS_STATUS 54 /* RO, 2 bytes */ +#define EXT_CSD_EXP_EVENTS_CTRL 56 /* R/W, 2 bytes */ +#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ +#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */ +#define EXT_CSD_PARTITION_SETTING_COMPLETED 155 /* R/W */ +#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ +#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */ +#define EXT_CSD_HPI_MGMT 161 /* R/W */ +#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */ +#define EXT_CSD_BKOPS_EN 163 /* R/W */ +#define EXT_CSD_BKOPS_START 164 /* W */ +#define EXT_CSD_SANITIZE_START 165 /* W */ +#define EXT_CSD_WR_REL_PARAM 166 /* RO */ +#define EXT_CSD_RPMB_MULT 168 /* RO */ +#define EXT_CSD_FW_CONFIG 169 /* R/W */ +#define EXT_CSD_BOOT_WP 173 /* R/W */ +#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ +#define EXT_CSD_PART_CONFIG 179 /* R/W */ +#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ +#define EXT_CSD_BUS_WIDTH 183 /* R/W */ +#define EXT_CSD_STROBE_SUPPORT 184 /* RO */ +#define EXT_CSD_HS_TIMING 185 /* R/W */ +#define EXT_CSD_POWER_CLASS 187 /* R/W */ +#define EXT_CSD_REV 192 /* RO */ +#define EXT_CSD_STRUCTURE 194 /* RO */ +#define EXT_CSD_CARD_TYPE 196 /* RO */ +#define EXT_CSD_DRIVER_STRENGTH 197 /* RO */ +#define EXT_CSD_OUT_OF_INTERRUPT_TIME 198 /* RO */ +#define EXT_CSD_PART_SWITCH_TIME 199 /* RO */ +#define EXT_CSD_PWR_CL_52_195 200 /* RO */ +#define EXT_CSD_PWR_CL_26_195 201 /* RO */ +#define EXT_CSD_PWR_CL_52_360 202 /* RO */ +#define EXT_CSD_PWR_CL_26_360 203 /* RO */ +#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ +#define EXT_CSD_S_A_TIMEOUT 217 /* RO */ +#define EXT_CSD_REL_WR_SEC_C 222 /* RO */ +#define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */ +#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */ +#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */ +#define EXT_CSD_BOOT_MULT 226 /* RO */ +#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */ +#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */ +#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */ +#define EXT_CSD_TRIM_MULT 232 /* RO */ +#define EXT_CSD_PWR_CL_200_195 236 /* RO */ +#define EXT_CSD_PWR_CL_200_360 237 /* RO */ +#define EXT_CSD_PWR_CL_DDR_52_195 238 /* RO */ +#define EXT_CSD_PWR_CL_DDR_52_360 239 /* RO */ +#define EXT_CSD_BKOPS_STATUS 246 /* RO */ +#define EXT_CSD_POWER_OFF_LONG_TIME 247 /* RO */ +#define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */ +#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */ +#define EXT_CSD_PWR_CL_DDR_200_360 253 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION 254 /* RO, 8 bytes */ +#define EXT_CSD_DEVICE_VERSION 262 /* RO, 2 bytes */ +#define EXT_CSD_PRE_EOL_INFO 267 /* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A 268 /* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B 269 /* RO */ +#define EXT_CSD_CMDQ_DEPTH 307 /* RO */ +#define EXT_CSD_CMDQ_SUPPORT 308 /* RO */ +#define EXT_CSD_SUPPORTED_MODE 493 /* RO */ +#define EXT_CSD_TAG_UNIT_SIZE 498 /* RO */ +#define EXT_CSD_DATA_TAG_SUPPORT 499 /* RO */ +#define EXT_CSD_MAX_PACKED_WRITES 500 /* RO */ +#define EXT_CSD_MAX_PACKED_READS 501 /* RO */ +#define EXT_CSD_BKOPS_SUPPORT 502 /* RO */ +#define EXT_CSD_HPI_FEATURES 503 /* RO */ + +/* +* EXT_CSD field definitions +*/ + +#define EXT_CSD_WR_REL_PARAM_EN (1<<2) + +#define EXT_CSD_BOOT_WP_B_PWR_WP_DIS (0x40) +#define EXT_CSD_BOOT_WP_B_PERM_WP_DIS (0x10) +#define EXT_CSD_BOOT_WP_B_PERM_WP_EN (0x04) +#define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01) + +#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7) +#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) +#define EXT_CSD_PART_CONFIG_ACC_RPMB (0x3) +#define EXT_CSD_PART_CONFIG_ACC_GP0 (0x4) + +#define EXT_CSD_PART_SETTING_COMPLETED (0x1) +#define EXT_CSD_PART_SUPPORT_PART_EN (0x1) + +#define EXT_CSD_CMD_SET_NORMAL (1<<0) +#define EXT_CSD_CMD_SET_SECURE (1<<1) +#define EXT_CSD_CMD_SET_CPSECURE (1<<2) + +#define EXT_CSD_CARD_TYPE_HS_26 (1<<0) /* Card can run at 26MHz */ +#define EXT_CSD_CARD_TYPE_HS_52 (1<<1) /* Card can run at 52MHz */ +#define EXT_CSD_CARD_TYPE_HS (EXT_CSD_CARD_TYPE_HS_26 | \ + EXT_CSD_CARD_TYPE_HS_52) +#define EXT_CSD_CARD_TYPE_DDR_1_8V (1<<2) /* Card can run at 52MHz */ +/* DDR mode @1.8V or 3V I/O */ +#define EXT_CSD_CARD_TYPE_DDR_1_2V (1<<3) /* Card can run at 52MHz */ +/* DDR mode @1.2V I/O */ +#define EXT_CSD_CARD_TYPE_DDR_52 (EXT_CSD_CARD_TYPE_DDR_1_8V \ + | EXT_CSD_CARD_TYPE_DDR_1_2V) +#define EXT_CSD_CARD_TYPE_HS200_1_8V (1<<4) /* Card can run at 200MHz */ +#define EXT_CSD_CARD_TYPE_HS200_1_2V (1<<5) /* Card can run at 200MHz */ +/* SDR mode @1.2V I/O */ +#define EXT_CSD_CARD_TYPE_HS200 (EXT_CSD_CARD_TYPE_HS200_1_8V | \ + EXT_CSD_CARD_TYPE_HS200_1_2V) +#define EXT_CSD_CARD_TYPE_HS400_1_8V (1<<6) /* Card can run at 200MHz DDR, 1.8V */ +#define EXT_CSD_CARD_TYPE_HS400_1_2V (1<<7) /* Card can run at 200MHz DDR, 1.2V */ +#define EXT_CSD_CARD_TYPE_HS400 (EXT_CSD_CARD_TYPE_HS400_1_8V | \ + EXT_CSD_CARD_TYPE_HS400_1_2V) +#define EXT_CSD_CARD_TYPE_HS400ES (1<<8) /* Card can run at HS400ES */ + +#define EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */ +#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */ +#define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */ +#define EXT_CSD_DDR_BUS_WIDTH_4 5 /* Card is in 4 bit DDR mode */ +#define EXT_CSD_DDR_BUS_WIDTH_8 6 /* Card is in 8 bit DDR mode */ +#define EXT_CSD_BUS_WIDTH_STROBE (1<<7) /* Enhanced strobe mode */ + +#define EXT_CSD_TIMING_BC 0 /* Backwards compatility */ +#define EXT_CSD_TIMING_HS 1 /* High speed */ +#define EXT_CSD_TIMING_HS200 2 /* HS200 */ +#define EXT_CSD_TIMING_HS400 3 /* HS400 */ +#define EXT_CSD_DRV_STR_SHIFT 4 /* Driver Strength shift */ + +#define EXT_CSD_SEC_ER_EN (1<<0) +#define EXT_CSD_SEC_BD_BLK_EN (1<<2) +#define EXT_CSD_SEC_GB_CL_EN (1<<4) +#define EXT_CSD_SEC_SANITIZE (1<<6) /* v4.5 only */ + +#define EXT_CSD_RST_N_EN_MASK 0x3 +#define EXT_CSD_RST_N_ENABLED 1 /* RST_n is enabled on card */ + +#define EXT_CSD_NO_POWER_NOTIFICATION 0 +#define EXT_CSD_POWER_ON 1 +#define EXT_CSD_POWER_OFF_SHORT 2 +#define EXT_CSD_POWER_OFF_LONG 3 + +#define EXT_CSD_PWR_CL_8BIT_MASK 0xF0 /* 8 bit PWR CLS */ +#define EXT_CSD_PWR_CL_4BIT_MASK 0x0F /* 8 bit PWR CLS */ +#define EXT_CSD_PWR_CL_8BIT_SHIFT 4 +#define EXT_CSD_PWR_CL_4BIT_SHIFT 0 + +#define EXT_CSD_PACKED_EVENT_EN (1<<3) + +/* +* EXCEPTION_EVENT_STATUS field +*/ +#define EXT_CSD_URGENT_BKOPS (1<<0) +#define EXT_CSD_DYNCAP_NEEDED (1<<1) +#define EXT_CSD_SYSPOOL_EXHAUSTED (1<<2) +#define EXT_CSD_PACKED_FAILURE (1<<3) + +#define EXT_CSD_PACKED_GENERIC_ERROR (1<<0) +#define EXT_CSD_PACKED_INDEXED_ERROR (1<<1) + +/* +* BKOPS status level +*/ +#define EXT_CSD_BKOPS_LEVEL_2 0x2 + +/* +* BKOPS modes +*/ +#define EXT_CSD_MANUAL_BKOPS_MASK 0x01 +#define EXT_CSD_AUTO_BKOPS_MASK 0x02 + +/* +* Command Queue +*/ +#define EXT_CSD_CMDQ_MODE_ENABLED (1<<0) +#define EXT_CSD_CMDQ_DEPTH_MASK 0x1F +#define EXT_CSD_CMDQ_SUPPORTED (1<<0) + +/* +* MMC_SWITCH access modes +*/ +#define MMC_SWITCH_MODE_CMD_SET 0x00 /* Change the command set */ +#define MMC_SWITCH_MODE_SET_BITS 0x01 /* Set bits which are 1 in value */ +#define MMC_SWITCH_MODE_CLEAR_BITS 0x02 /* Clear bits which are 1 in value */ +#define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */ + +/* +* Erase/trim/discard +*/ +#define MMC_ERASE_ARG 0x00000000 +#define MMC_SECURE_ERASE_ARG 0x80000000 +#define MMC_TRIM_ARG 0x00000001 +#define MMC_DISCARD_ARG 0x00000003 +#define MMC_SECURE_TRIM1_ARG 0x80000001 +#define MMC_SECURE_TRIM2_ARG 0x80008000 +#define MMC_SECURE_ARGS 0x80000000 +#define MMC_TRIM_ARGS 0x00008001 + +#endif /* LINUX_MMC_MMC_H */ diff --git a/nyx/nyx_gui/storage/nx_emmc.c b/nyx/nyx_gui/storage/nx_emmc.c new file mode 100644 index 0000000..a65dced --- /dev/null +++ b/nyx/nyx_gui/storage/nx_emmc.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "nx_emmc.h" +#include "../mem/heap.h" +#include "../utils/list.h" + +void nx_emmc_gpt_parse(link_t *gpt, sdmmc_storage_t *storage) +{ + u8 *buf = (u8 *)malloc(NX_GPT_NUM_BLOCKS * NX_EMMC_BLOCKSIZE); + + sdmmc_storage_read(storage, NX_GPT_FIRST_LBA, NX_GPT_NUM_BLOCKS, buf); + + gpt_header_t *hdr = (gpt_header_t *)buf; + for (u32 i = 0; i < hdr->num_part_ents; i++) + { + gpt_entry_t *ent = (gpt_entry_t *)(buf + (hdr->part_ent_lba - 1) * NX_EMMC_BLOCKSIZE + i * sizeof(gpt_entry_t)); + emmc_part_t *part = (emmc_part_t *)malloc(sizeof(emmc_part_t)); + part->lba_start = ent->lba_start; + part->lba_end = ent->lba_end; + part->attrs = ent->attrs; + + //HACK + for (u32 i = 0; i < 36; i++) + part->name[i] = ent->name[i]; + part->name[36] = 0; + + list_append(gpt, &part->link); + } + + free(buf); +} + +void nx_emmc_gpt_free(link_t *gpt) +{ + LIST_FOREACH_SAFE(iter, gpt) + free(CONTAINER_OF(iter, emmc_part_t, link)); +} + +emmc_part_t *nx_emmc_part_find(link_t *gpt, const char *name) +{ + LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link) + if (!strcmp(part->name, name)) + return part; + return NULL; +} + +int nx_emmc_part_read(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf) +{ + // The last LBA is inclusive. + if (part->lba_start + sector_off > part->lba_end) + return 0; + return sdmmc_storage_read(storage, part->lba_start + sector_off, num_sectors, buf); +} + +int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf) +{ + // The last LBA is inclusive. + if (part->lba_start + sector_off > part->lba_end) + return 0; + return sdmmc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf); +} diff --git a/nyx/nyx_gui/storage/nx_emmc.h b/nyx/nyx_gui/storage/nx_emmc.h new file mode 100644 index 0000000..753d5aa --- /dev/null +++ b/nyx/nyx_gui/storage/nx_emmc.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _NX_EMMC_H_ +#define _NX_EMMC_H_ + +#include "../utils/types.h" +#include "../utils/list.h" +#include "sdmmc.h" + +typedef struct _gpt_entry_t +{ + u8 type_guid[0x10]; + u8 part_guid[0x10]; + u64 lba_start; + u64 lba_end; + u64 attrs; + u16 name[36]; +} gpt_entry_t; + +typedef struct _gpt_header_t +{ + u64 signature; + u32 revision; + u32 size; + u32 crc32; + u32 res1; + u64 my_lba; + u64 alt_lba; + u64 first_use_lba; + u64 last_use_lba; + u8 disk_guid[0x10]; + u64 part_ent_lba; + u32 num_part_ents; + u32 part_ent_size; + u32 part_ents_crc32; + u8 res2[420]; +} gpt_header_t; + +#define NX_GPT_FIRST_LBA 1 +#define NX_GPT_NUM_BLOCKS 33 +#define NX_EMMC_BLOCKSIZE 512 + +typedef struct _emmc_part_t +{ + u32 lba_start; + u32 lba_end; + u64 attrs; + char name[37]; + link_t link; +} emmc_part_t; + +void nx_emmc_gpt_parse(link_t *gpt, sdmmc_storage_t *storage); +void nx_emmc_gpt_free(link_t *gpt); +emmc_part_t *nx_emmc_part_find(link_t *gpt, const char *name); +int nx_emmc_part_read(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf); +int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf); + +#endif diff --git a/nyx/nyx_gui/storage/sd.h b/nyx/nyx_gui/storage/sd.h new file mode 100644 index 0000000..c3bf82b --- /dev/null +++ b/nyx/nyx_gui/storage/sd.h @@ -0,0 +1,124 @@ +/* + * include/linux/mmc/sd.h + * + * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + */ + +#ifndef LINUX_MMC_SD_H +#define LINUX_MMC_SD_H + +/* SD commands type argument response */ +/* class 0 */ +/* This is basically the same command as for MMC with some quirks. */ +#define SD_SEND_RELATIVE_ADDR 3 /* bcr R6 */ +#define SD_SEND_IF_COND 8 /* bcr [11:0] See below R7 */ +#define SD_SWITCH_VOLTAGE 11 /* ac R1 */ + +/* class 10 */ +#define SD_SWITCH 6 /* adtc [31:0] See below R1 */ + +/* class 5 */ +#define SD_ERASE_WR_BLK_START 32 /* ac [31:0] data addr R1 */ +#define SD_ERASE_WR_BLK_END 33 /* ac [31:0] data addr R1 */ + +/* Application commands */ +#define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */ +#define SD_APP_SD_STATUS 13 /* adtc R1 */ +#define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */ +#define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */ +#define SD_APP_SET_CLR_CARD_DETECT 42 +#define SD_APP_SEND_SCR 51 /* adtc R1 */ + +/* OCR bit definitions */ +#define SD_OCR_S18R (1 << 24) /* 1.8V switching request */ +#define SD_ROCR_S18A SD_OCR_S18R /* 1.8V switching accepted by card */ +#define SD_OCR_XPC (1 << 28) /* SDXC power control */ +#define SD_OCR_CCS (1 << 30) /* Card Capacity Status */ +#define SD_OCR_VDD_32_33 (1 << 20) /* VDD voltage 3.2 ~ 3.3 */ + +/* +* SD_SWITCH argument format: +* +* [31] Check (0) or switch (1) +* [30:24] Reserved (0) +* [23:20] Function group 6 +* [19:16] Function group 5 +* [15:12] Function group 4 +* [11:8] Function group 3 +* [7:4] Function group 2 +* [3:0] Function group 1 +*/ + +/* +* SD_SEND_IF_COND argument format: +* +* [31:12] Reserved (0) +* [11:8] Host Voltage Supply Flags +* [7:0] Check Pattern (0xAA) +*/ + +/* +* SCR field definitions +*/ +#define SCR_SPEC_VER_0 0 /* Implements system specification 1.0 - 1.01 */ +#define SCR_SPEC_VER_1 1 /* Implements system specification 1.10 */ +#define SCR_SPEC_VER_2 2 /* Implements system specification 2.00-3.0X */ +#define SD_SCR_BUS_WIDTH_1 (1<<0) +#define SD_SCR_BUS_WIDTH_4 (1<<2) + +/* +* SD bus widths +*/ +#define SD_BUS_WIDTH_1 0 +#define SD_BUS_WIDTH_4 2 + +/* +* SD bus speeds +*/ +#define UHS_SDR12_BUS_SPEED 0 +#define HIGH_SPEED_BUS_SPEED 1 +#define UHS_SDR25_BUS_SPEED 1 +#define UHS_SDR50_BUS_SPEED 2 +#define UHS_SDR104_BUS_SPEED 3 +#define UHS_DDR50_BUS_SPEED 4 +#define HS400_BUS_SPEED 5 + +#define SD_MODE_HIGH_SPEED (1 << HIGH_SPEED_BUS_SPEED) +#define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED) +#define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED) +#define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED) +#define SD_MODE_UHS_SDR104 (1 << UHS_SDR104_BUS_SPEED) +#define SD_MODE_UHS_DDR50 (1 << UHS_DDR50_BUS_SPEED) + +#define SD_DRIVER_TYPE_B 0x01 +#define SD_DRIVER_TYPE_A 0x02 + +#define SD_SET_CURRENT_LIMIT_200 0 +#define SD_SET_CURRENT_LIMIT_400 1 +#define SD_SET_CURRENT_LIMIT_600 2 +#define SD_SET_CURRENT_LIMIT_800 3 + +/* +* SD_SWITCH mode +*/ +#define SD_SWITCH_CHECK 0 +#define SD_SWITCH_SET 1 + +/* +* SD_SWITCH function groups +*/ +#define SD_SWITCH_GRP_ACCESS 0 + +/* +* SD_SWITCH access modes +*/ +#define SD_SWITCH_ACCESS_DEF 0 +#define SD_SWITCH_ACCESS_HS 1 + +#endif /* LINUX_MMC_SD_H */ diff --git a/nyx/nyx_gui/storage/sdmmc.c b/nyx/nyx_gui/storage/sdmmc.c new file mode 100644 index 0000000..a28d3dd --- /dev/null +++ b/nyx/nyx_gui/storage/sdmmc.c @@ -0,0 +1,1201 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "sdmmc.h" +#include "mmc.h" +#include "sd.h" +#include "../config/config.h" +#include "../gfx/gfx.h" +#include "../mem/heap.h" +#include "../utils/util.h" + +//#define DPRINTF(...) gfx_printf(__VA_ARGS__) +#define DPRINTF(...) + +extern hekate_config h_cfg; + +static inline u32 unstuff_bits(u32 *resp, u32 start, u32 size) +{ + const u32 mask = (size < 32 ? 1 << size : 0) - 1; + const u32 off = 3 - ((start) / 32); + const u32 shft = (start) & 31; + u32 res = resp[off] >> shft; + if (size + shft > 32) + res |= resp[off - 1] << ((32 - shft) % 32); + return res & mask; +} + +/* +* Common functions for SD and MMC. +*/ + +static int _sdmmc_storage_check_result(u32 res) +{ + //Error mask: + //R1_OUT_OF_RANGE, R1_ADDRESS_ERROR, R1_BLOCK_LEN_ERROR, + //R1_ERASE_SEQ_ERROR, R1_ERASE_PARAM, R1_WP_VIOLATION, + //R1_LOCK_UNLOCK_FAILED, R1_COM_CRC_ERROR, R1_ILLEGAL_COMMAND, + //R1_CARD_ECC_FAILED, R1_CC_ERROR, R1_ERROR, R1_CID_CSD_OVERWRITE, + //R1_WP_ERASE_SKIP, R1_ERASE_RESET, R1_SWITCH_ERROR + if (!(res & 0xFDF9A080)) + return 1; + //TODO: R1_SWITCH_ERROR we can skip for certain card types. + return 0; +} + +static int _sdmmc_storage_execute_cmd_type1_ex(sdmmc_storage_t *storage, u32 *resp, u32 cmd, u32 arg, u32 check_busy, u32 expected_state, u32 mask) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, cmd, arg, SDMMC_RSP_TYPE_1, check_busy); + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, 0, 0)) + return 0; + + sdmmc_get_rsp(storage->sdmmc, resp, 4, SDMMC_RSP_TYPE_1); + if (mask) + *resp &= ~mask; + + if (_sdmmc_storage_check_result(*resp)) + if (expected_state == 0x10 || R1_CURRENT_STATE(*resp) == expected_state) + return 1; + return 0; +} + +static int _sdmmc_storage_execute_cmd_type1(sdmmc_storage_t *storage, u32 cmd, u32 arg, u32 check_busy, u32 expected_state) +{ + u32 tmp; + return _sdmmc_storage_execute_cmd_type1_ex(storage, &tmp, cmd, arg, check_busy, expected_state, 0); +} + +static int _sdmmc_storage_go_idle_state(sdmmc_storage_t *storage) +{ + sdmmc_cmd_t cmd; + sdmmc_init_cmd(&cmd, MMC_GO_IDLE_STATE, 0, SDMMC_RSP_TYPE_0, 0); + return sdmmc_execute_cmd(storage->sdmmc, &cmd, 0, 0); +} + +static int _sdmmc_storage_get_cid(sdmmc_storage_t *storage, void *buf) +{ + sdmmc_cmd_t cmd; + sdmmc_init_cmd(&cmd, MMC_ALL_SEND_CID, 0, SDMMC_RSP_TYPE_2, 0); + if (!sdmmc_execute_cmd(storage->sdmmc, &cmd, 0, 0)) + return 0; + sdmmc_get_rsp(storage->sdmmc, buf, 0x10, SDMMC_RSP_TYPE_2); + return 1; +} + +static int _sdmmc_storage_select_card(sdmmc_storage_t *storage) +{ + return _sdmmc_storage_execute_cmd_type1(storage, MMC_SELECT_CARD, storage->rca << 16, 1, 0x10); +} + +static int _sdmmc_storage_get_csd(sdmmc_storage_t *storage, void *buf) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, MMC_SEND_CSD, storage->rca << 16, SDMMC_RSP_TYPE_2, 0); + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, 0, 0)) + return 0; + sdmmc_get_rsp(storage->sdmmc, buf, 0x10, SDMMC_RSP_TYPE_2); + return 1; +} + +static int _sdmmc_storage_set_blocklen(sdmmc_storage_t *storage, u32 blocklen) +{ + return _sdmmc_storage_execute_cmd_type1(storage, MMC_SET_BLOCKLEN, blocklen, 0, R1_STATE_TRAN); +} + +static int _sdmmc_storage_get_status(sdmmc_storage_t *storage, u32 *resp, u32 mask) +{ + return _sdmmc_storage_execute_cmd_type1_ex(storage, resp, MMC_SEND_STATUS, storage->rca << 16, 0, R1_STATE_TRAN, mask); +} + +static int _sdmmc_storage_check_status(sdmmc_storage_t *storage) +{ + u32 tmp; + return _sdmmc_storage_get_status(storage, &tmp, 0); +} + +static int _sdmmc_storage_readwrite_ex(sdmmc_storage_t *storage, u32 *blkcnt_out, u32 sector, u32 num_sectors, void *buf, u32 is_write) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, is_write ? MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK, sector, SDMMC_RSP_TYPE_1, 0); + + sdmmc_req_t reqbuf; + reqbuf.buf = buf; + reqbuf.num_sectors = num_sectors; + reqbuf.blksize = 512; + reqbuf.is_write = is_write; + reqbuf.is_multi_block = 1; + reqbuf.is_auto_cmd12 = 1; + + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, blkcnt_out)) + { + u32 tmp = 0; + sdmmc_stop_transmission(storage->sdmmc, &tmp); + _sdmmc_storage_get_status(storage, &tmp, 0); + return 0; + } + return 1; +} + +int sdmmc_storage_end(sdmmc_storage_t *storage) +{ + if (!_sdmmc_storage_go_idle_state(storage)) + return 0; + sdmmc_end(storage->sdmmc); + return 1; +} + +static int _sdmmc_storage_readwrite(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf, u32 is_write) +{ + u8 *bbuf = (u8 *)buf; + + while (num_sectors) + { + u32 blkcnt = 0; + //Retry 9 times on error. + u32 retries = 10; + do + { + if (_sdmmc_storage_readwrite_ex(storage, &blkcnt, sector, MIN(num_sectors, 0xFFFF), bbuf, is_write)) + goto out; + else + retries--; + + msleep(100); + } while (retries); + return 0; + +out:; + DPRINTF("readwrite: %08X\n", blkcnt); + sector += blkcnt; + num_sectors -= blkcnt; + bbuf += 512 * blkcnt; + } + return 1; +} + +int sdmmc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf) +{ + return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 0); +} + +int sdmmc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf) +{ + return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 1); +} + +/* +* MMC specific functions. +*/ + +static int _mmc_storage_get_op_cond_inner(sdmmc_storage_t *storage, u32 *pout, u32 power) +{ + sdmmc_cmd_t cmd; + + u32 arg = 0; + switch (power) + { + case SDMMC_POWER_1_8: + arg = 0x40000080; //Sector access, voltage. + break; + case SDMMC_POWER_3_3: + arg = 0x403F8000; //Sector access, voltage. + break; + default: + return 0; + } + + sdmmc_init_cmd(&cmd, MMC_SEND_OP_COND, arg, SDMMC_RSP_TYPE_3, 0); + if (!sdmmc_execute_cmd(storage->sdmmc, &cmd, 0, 0)) + return 0; + + return sdmmc_get_rsp(storage->sdmmc, pout, 4, SDMMC_RSP_TYPE_3); +} + +static int _mmc_storage_get_op_cond(sdmmc_storage_t *storage, u32 power) +{ + u32 timeout = get_tmr_ms() + 1500; + + while (1) + { + u32 cond = 0; + if (!_mmc_storage_get_op_cond_inner(storage, &cond, power)) + break; + if (cond & MMC_CARD_BUSY) + { + if (cond & 0x40000000) + storage->has_sector_access = 1; + return 1; + } + if (get_tmr_ms() > timeout) + break; + usleep(1000); + } + + return 0; +} + +static int _mmc_storage_set_relative_addr(sdmmc_storage_t *storage) +{ + return _sdmmc_storage_execute_cmd_type1(storage, MMC_SET_RELATIVE_ADDR, storage->rca << 16, 0, 0x10); +} + +static void _mmc_storage_parse_cid(sdmmc_storage_t *storage) +{ + u32 *raw_cid = (u32 *)&(storage->raw_cid); + + switch (storage->csd.mmca_vsn) + { + case 0: /* MMC v1.0 - v1.2 */ + case 1: /* MMC v1.4 */ + storage->cid.prod_name[6] = unstuff_bits(raw_cid, 48, 8); + storage->cid.manfid = unstuff_bits(raw_cid, 104, 24); + storage->cid.hwrev = unstuff_bits(raw_cid, 44, 4); + storage->cid.fwrev = unstuff_bits(raw_cid, 40, 4); + storage->cid.serial = unstuff_bits(raw_cid, 16, 24); + break; + case 2: /* MMC v2.0 - v2.2 */ + case 3: /* MMC v3.1 - v3.3 */ + case 4: /* MMC v4 */ + storage->cid.manfid = unstuff_bits(raw_cid, 120, 8); + storage->cid.card_bga = unstuff_bits(raw_cid, 112, 2); + storage->cid.oemid = unstuff_bits(raw_cid, 104, 8); + storage->cid.prv = unstuff_bits(raw_cid, 48, 8); + storage->cid.serial = unstuff_bits(raw_cid, 16, 32); + break; + default: + break; + } + + storage->cid.prod_name[0] = unstuff_bits(raw_cid, 96, 8); + storage->cid.prod_name[1] = unstuff_bits(raw_cid, 88, 8); + storage->cid.prod_name[2] = unstuff_bits(raw_cid, 80, 8); + storage->cid.prod_name[3] = unstuff_bits(raw_cid, 72, 8); + storage->cid.prod_name[4] = unstuff_bits(raw_cid, 64, 8); + storage->cid.prod_name[5] = unstuff_bits(raw_cid, 56, 8); + + storage->cid.month = unstuff_bits(raw_cid, 12, 4); + storage->cid.year = unstuff_bits(raw_cid, 8, 4) + 1997; + if (storage->ext_csd.rev >= 5) + { + if (storage->cid.year < 2010) + storage->cid.year += 16; + } +} + +static void _mmc_storage_parse_csd(sdmmc_storage_t *storage) +{ + u32 *raw_csd = (u32 *)&(storage->raw_csd); + + storage->csd.mmca_vsn = unstuff_bits(raw_csd, 122, 4); + storage->csd.structure = unstuff_bits(raw_csd, 126, 2); + storage->csd.cmdclass = unstuff_bits(raw_csd, 84, 12); + storage->csd.read_blkbits = unstuff_bits(raw_csd, 80, 4); + storage->csd.capacity = (1 + unstuff_bits(raw_csd, 62, 12)) << (unstuff_bits(raw_csd, 47, 3) + 2); +} + +static void _mmc_storage_parse_ext_csd(sdmmc_storage_t *storage, u8 *buf) +{ + storage->ext_csd.rev = buf[EXT_CSD_REV]; + storage->ext_csd.ext_struct = buf[EXT_CSD_STRUCTURE]; + storage->ext_csd.card_type = buf[EXT_CSD_CARD_TYPE]; + storage->ext_csd.dev_version = *(u16 *)&buf[EXT_CSD_DEVICE_VERSION]; + storage->ext_csd.boot_mult = buf[EXT_CSD_BOOT_MULT]; + storage->ext_csd.rpmb_mult = buf[EXT_CSD_RPMB_MULT]; + storage->ext_csd.sectors = *(u32 *)&buf[EXT_CSD_SEC_CNT]; + storage->ext_csd.bkops = buf[EXT_CSD_BKOPS_SUPPORT]; + storage->ext_csd.bkops_en = buf[EXT_CSD_BKOPS_EN]; + storage->ext_csd.bkops_status = buf[EXT_CSD_BKOPS_STATUS]; + + storage->sec_cnt = *(u32 *)&buf[EXT_CSD_SEC_CNT]; +} + +static int _mmc_storage_get_ext_csd(sdmmc_storage_t *storage, void *buf) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, MMC_SEND_EXT_CSD, 0, SDMMC_RSP_TYPE_1, 0); + + sdmmc_req_t reqbuf; + reqbuf.buf = buf; + reqbuf.blksize = 512; + reqbuf.num_sectors = 1; + reqbuf.is_write = 0; + reqbuf.is_multi_block = 0; + reqbuf.is_auto_cmd12 = 0; + + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, 0)) + return 0; + + u32 tmp = 0; + sdmmc_get_rsp(storage->sdmmc, &tmp, 4, SDMMC_RSP_TYPE_1); + _mmc_storage_parse_ext_csd(storage, buf); + + return _sdmmc_storage_check_result(tmp); +} + +static int _mmc_storage_switch(sdmmc_storage_t *storage, u32 arg) +{ + return _sdmmc_storage_execute_cmd_type1(storage, MMC_SWITCH, arg, 1, 0x10); +} + +static int _mmc_storage_switch_buswidth(sdmmc_storage_t *storage, u32 bus_width) +{ + if (bus_width == SDMMC_BUS_WIDTH_1) + return 1; + + u32 arg = 0; + switch (bus_width) + { + case SDMMC_BUS_WIDTH_4: + arg = SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4); + break; + case SDMMC_BUS_WIDTH_8: + arg = SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8); + break; + } + + if (_mmc_storage_switch(storage, arg)) + if (_sdmmc_storage_check_status(storage)) + { + sdmmc_set_bus_width(storage->sdmmc, bus_width); + return 1; + } + + return 0; +} + +static int _mmc_storage_enable_HS(sdmmc_storage_t *storage, int check) +{ + if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS))) + return 0; + if (check && !_sdmmc_storage_check_status(storage)) + return 0; + if (!sdmmc_setup_clock(storage->sdmmc, 2)) + return 0; + DPRINTF("[MMC] switched to HS\n"); + storage->csd.busspeed = 52; + if (check || _sdmmc_storage_check_status(storage)) + return 1; + return 0; +} + +static int _mmc_storage_enable_HS200(sdmmc_storage_t *storage) +{ + if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS200))) + return 0; + if (!sdmmc_setup_clock(storage->sdmmc, 3)) + return 0; + if (!sdmmc_config_tuning(storage->sdmmc, 3, MMC_SEND_TUNING_BLOCK_HS200)) + return 0; + DPRINTF("[MMC] switched to HS200\n"); + storage->csd.busspeed = 200; + return _sdmmc_storage_check_status(storage); +} + +static int _mmc_storage_enable_HS400(sdmmc_storage_t *storage) +{ + if (!_mmc_storage_enable_HS200(storage)) + return 0; + sdmmc_get_venclkctl(storage->sdmmc); + if (!_mmc_storage_enable_HS(storage, 0)) + return 0; + if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_BUS_WIDTH, EXT_CSD_DDR_BUS_WIDTH_8))) + return 0; + if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS400))) + return 0; + if (!sdmmc_setup_clock(storage->sdmmc, 4)) + return 0; + DPRINTF("[MMC] switched to HS400\n"); + storage->csd.busspeed = 400; + return _sdmmc_storage_check_status(storage); +} + +static int _mmc_storage_enable_highspeed(sdmmc_storage_t *storage, u32 card_type, u32 type) +{ + //TODO: this should be a config item. + // --v + if (!1 || sdmmc_get_voltage(storage->sdmmc) != SDMMC_POWER_1_8) + goto out; + + if (sdmmc_get_bus_width(storage->sdmmc) == SDMMC_BUS_WIDTH_8 && + card_type & EXT_CSD_CARD_TYPE_HS400_1_8V && + type == 4) + return _mmc_storage_enable_HS400(storage); + + if (sdmmc_get_bus_width(storage->sdmmc) == SDMMC_BUS_WIDTH_8 || + (sdmmc_get_bus_width(storage->sdmmc) == SDMMC_BUS_WIDTH_4 + && card_type & EXT_CSD_CARD_TYPE_HS200_1_8V + && (type == 4 || type == 3))) + return _mmc_storage_enable_HS200(storage); + +out:; + if (card_type & EXT_CSD_CARD_TYPE_HS_52) + return _mmc_storage_enable_HS(storage, 1); + return 1; +} + +static int _mmc_storage_enable_bkops(sdmmc_storage_t *storage) +{ + if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_SET_BITS, EXT_CSD_BKOPS_EN, EXT_CSD_BKOPS_LEVEL_2))) + return 0; + return _sdmmc_storage_check_status(storage); +} + +int sdmmc_storage_init_mmc(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 id, u32 bus_width, u32 type) +{ + memset(storage, 0, sizeof(sdmmc_storage_t)); + storage->sdmmc = sdmmc; + storage->rca = 2; //TODO: this could be a config item. + + if (!sdmmc_init(sdmmc, id, SDMMC_POWER_1_8, SDMMC_BUS_WIDTH_1, 0, 0)) + return 0; + DPRINTF("[MMC] after init\n"); + + usleep(1000 + (74000 + sdmmc->divisor - 1) / sdmmc->divisor); + + if (!_sdmmc_storage_go_idle_state(storage)) + return 0; + DPRINTF("[MMC] went to idle state\n"); + + if (!_mmc_storage_get_op_cond(storage, SDMMC_POWER_1_8)) + return 0; + DPRINTF("[MMC] got op cond\n"); + + if (!_sdmmc_storage_get_cid(storage, storage->raw_cid)) + return 0; + DPRINTF("[MMC] got cid\n"); + + if (!_mmc_storage_set_relative_addr(storage)) + return 0; + DPRINTF("[MMC] set relative addr\n"); + + if (!_sdmmc_storage_get_csd(storage, storage->raw_csd)) + return 0; + DPRINTF("[MMC] got csd\n"); + _mmc_storage_parse_csd(storage); + + if (!sdmmc_setup_clock(storage->sdmmc, 1)) + return 0; + DPRINTF("[MMC] after setup clock\n"); + + if (!_sdmmc_storage_select_card(storage)) + return 0; + DPRINTF("[MMC] card selected\n"); + + if (!_sdmmc_storage_set_blocklen(storage, 512)) + return 0; + DPRINTF("[MMC] set blocklen to 512\n"); + + u32 *csd = (u32 *)storage->raw_csd; + //Check system specification version, only version 4.0 and later support below features. + if (unstuff_bits(csd, 122, 4) < CSD_SPEC_VER_4) + { + storage->sec_cnt = (1 + unstuff_bits(csd, 62, 12)) << (unstuff_bits(csd, 47, 3) + 2); + return 1; + } + + if (!_mmc_storage_switch_buswidth(storage, bus_width)) + return 0; + DPRINTF("[MMC] switched buswidth\n"); + + u8 *ext_csd = (u8 *)malloc(512); + if (!_mmc_storage_get_ext_csd(storage, ext_csd)) + { + free(ext_csd); + return 0; + } + free(ext_csd); + DPRINTF("[MMC] got ext_csd\n"); + _mmc_storage_parse_cid(storage); //This needs to be after csd and ext_csd + //gfx_hexdump(0, ext_csd, 512); + + /* When auto BKOPS is enabled the mmc device should be powered all the time until we disable this and check status. + Disable it for now until BKOPS disable added to power down sequence at sdmmc_storage_end(). + Additionally this works only when we put the device in idle mode which we don't after enabling it. */ + if (storage->ext_csd.bkops & 0x1 && !(storage->ext_csd.bkops_en & EXT_CSD_BKOPS_LEVEL_2) && 0) + { + _mmc_storage_enable_bkops(storage); + DPRINTF("[MMC] BKOPS enabled\n"); + } + else + { + DPRINTF("[MMC] BKOPS disabled\n"); + } + + if (!_mmc_storage_enable_highspeed(storage, storage->ext_csd.card_type, type)) + return 0; + DPRINTF("[MMC] succesfully switched to highspeed mode\n"); + + sdmmc_sd_clock_ctrl(storage->sdmmc, 1); + + return 1; +} + +int sdmmc_storage_set_mmc_partition(sdmmc_storage_t *storage, u32 partition) +{ + if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_PART_CONFIG, partition))) + return 0; + if (!_sdmmc_storage_check_status(storage)) + return 0; + storage->partition = partition; + return 1; +} + +/* +* SD specific functions. +*/ + +static int _sd_storage_execute_app_cmd(sdmmc_storage_t *storage, u32 expected_state, u32 mask, sdmmc_cmd_t *cmd, sdmmc_req_t *req, u32 *blkcnt_out) +{ + u32 tmp; + if (!_sdmmc_storage_execute_cmd_type1_ex(storage, &tmp, MMC_APP_CMD, storage->rca << 16, 0, expected_state, mask)) + return 0; + return sdmmc_execute_cmd(storage->sdmmc, cmd, req, blkcnt_out); +} + +static int _sd_storage_execute_app_cmd_type1(sdmmc_storage_t *storage, u32 *resp, u32 cmd, u32 arg, u32 check_busy, u32 expected_state) +{ + if (!_sdmmc_storage_execute_cmd_type1(storage, MMC_APP_CMD, storage->rca << 16, 0, R1_STATE_TRAN)) + return 0; + return _sdmmc_storage_execute_cmd_type1_ex(storage, resp, cmd, arg, check_busy, expected_state, 0); +} + +static int _sd_storage_send_if_cond(sdmmc_storage_t *storage) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, SD_SEND_IF_COND, 0x1AA, SDMMC_RSP_TYPE_5, 0); + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, 0, 0)) + return 1; // The SD Card is version 1.X + + u32 resp = 0; + if (!sdmmc_get_rsp(storage->sdmmc, &resp, 4, SDMMC_RSP_TYPE_5)) + return 2; + + return (resp & 0xFF) == 0xAA ? 0 : 2; +} + +static int _sd_storage_get_op_cond_once(sdmmc_storage_t *storage, u32 *cond, int is_version_1, int supports_low_voltage) +{ + sdmmc_cmd_t cmdbuf; + // Support for Current > 150mA + u32 arg = (~is_version_1 & 1) ? SD_OCR_XPC : 0; + // Support for handling block-addressed SDHC cards + arg |= (~is_version_1 & 1) ? SD_OCR_CCS : 0; + // Support for 1.8V + arg |= (supports_low_voltage & ~is_version_1 & 1) ? SD_OCR_S18R : 0; + // This is needed for most cards. Do not set bit7 even if 1.8V is supported. + arg |= SD_OCR_VDD_32_33; + sdmmc_init_cmd(&cmdbuf, SD_APP_OP_COND, arg, SDMMC_RSP_TYPE_3, 0); + if (!_sd_storage_execute_app_cmd(storage, 0x10, is_version_1 ? 0x400000 : 0, &cmdbuf, 0, 0)) + return 0; + return sdmmc_get_rsp(storage->sdmmc, cond, 4, SDMMC_RSP_TYPE_3); +} + +static int _sd_storage_get_op_cond(sdmmc_storage_t *storage, int is_version_1, int supports_low_voltage) +{ + u32 timeout = get_tmr_ms() + 1500; + + while (1) + { + u32 cond = 0; + if (!_sd_storage_get_op_cond_once(storage, &cond, is_version_1, supports_low_voltage)) + break; + if (cond & MMC_CARD_BUSY) + { + if (cond & SD_OCR_CCS) + storage->has_sector_access = 1; + + if (cond & SD_ROCR_S18A && supports_low_voltage) + { + //The low voltage regulator configuration is valid for SDMMC1 only. + if (storage->sdmmc->id == SDMMC_1 && + _sdmmc_storage_execute_cmd_type1(storage, SD_SWITCH_VOLTAGE, 0, 0, R1_STATE_READY)) + { + if (!sdmmc_enable_low_voltage(storage->sdmmc)) + return 0; + storage->is_low_voltage = 1; + + DPRINTF("-> switched to low voltage\n"); + } + } + + return 1; + } + if (get_tmr_ms() > timeout) + break; + msleep(10); // Needs to be at least 10ms for some SD Cards + } + + return 0; +} + +static int _sd_storage_get_rca(sdmmc_storage_t *storage) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, SD_SEND_RELATIVE_ADDR, 0, SDMMC_RSP_TYPE_4, 0); + + u32 timeout = get_tmr_ms() + 1500; + + while (1) + { + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, 0, 0)) + break; + + u32 resp = 0; + if (!sdmmc_get_rsp(storage->sdmmc, &resp, 4, SDMMC_RSP_TYPE_4)) + break; + + if (resp >> 16) + { + storage->rca = resp >> 16; + return 1; + } + + if (get_tmr_ms() > timeout) + break; + usleep(1000); + } + + return 0; +} + +static void _sd_storage_parse_scr(sdmmc_storage_t *storage) +{ + // unstuff_bits can parse only 4 u32 + u32 resp[4]; + + resp[3] = *(u32 *)&storage->raw_scr[4]; + resp[2] = *(u32 *)&storage->raw_scr[0]; + + storage->scr.sda_vsn = unstuff_bits(resp, 56, 4); + storage->scr.bus_widths = unstuff_bits(resp, 48, 4); + if (storage->scr.sda_vsn == SCR_SPEC_VER_2) + /* Check if Physical Layer Spec v3.0 is supported */ + storage->scr.sda_spec3 = unstuff_bits(resp, 47, 1); + if (storage->scr.sda_spec3) + storage->scr.cmds = unstuff_bits(resp, 32, 2); +} + +int _sd_storage_get_scr(sdmmc_storage_t *storage, u8 *buf) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, SD_APP_SEND_SCR, 0, SDMMC_RSP_TYPE_1, 0); + + sdmmc_req_t reqbuf; + reqbuf.buf = buf; + reqbuf.blksize = 8; + reqbuf.num_sectors = 1; + reqbuf.is_write = 0; + reqbuf.is_multi_block = 0; + reqbuf.is_auto_cmd12 = 0; + + if (!_sd_storage_execute_app_cmd(storage, R1_STATE_TRAN, 0, &cmdbuf, &reqbuf, 0)) + return 0; + + u32 tmp = 0; + sdmmc_get_rsp(storage->sdmmc, &tmp, 4, SDMMC_RSP_TYPE_1); + //Prepare buffer for unstuff_bits + for (int i = 0; i < 8; i+=4) + { + storage->raw_scr[i + 3] = buf[i]; + storage->raw_scr[i + 2] = buf[i + 1]; + storage->raw_scr[i + 1] = buf[i + 2]; + storage->raw_scr[i] = buf[i + 3]; + } + _sd_storage_parse_scr(storage); + //gfx_hexdump(0, storage->raw_scr, 8); + + return _sdmmc_storage_check_result(tmp); +} + +int _sd_storage_switch_get(sdmmc_storage_t *storage, void *buf) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, SD_SWITCH, 0xFFFFFF, SDMMC_RSP_TYPE_1, 0); + + sdmmc_req_t reqbuf; + reqbuf.buf = buf; + reqbuf.blksize = 64; + reqbuf.num_sectors = 1; + reqbuf.is_write = 0; + reqbuf.is_multi_block = 0; + reqbuf.is_auto_cmd12 = 0; + + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, 0)) + return 0; + + u32 tmp = 0; + sdmmc_get_rsp(storage->sdmmc, &tmp, 4, SDMMC_RSP_TYPE_1); + return _sdmmc_storage_check_result(tmp); +} + +int _sd_storage_switch(sdmmc_storage_t *storage, void *buf, int mode, int group, u32 arg) +{ + sdmmc_cmd_t cmdbuf; + u32 switchcmd = mode << 31 | 0x00FFFFFF; + switchcmd &= ~(0xF << (group * 4)); + switchcmd |= arg << (group * 4); + sdmmc_init_cmd(&cmdbuf, SD_SWITCH, switchcmd, SDMMC_RSP_TYPE_1, 0); + + sdmmc_req_t reqbuf; + reqbuf.buf = buf; + reqbuf.blksize = 64; + reqbuf.num_sectors = 1; + reqbuf.is_write = 0; + reqbuf.is_multi_block = 0; + reqbuf.is_auto_cmd12 = 0; + + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, 0)) + return 0; + + u32 tmp = 0; + sdmmc_get_rsp(storage->sdmmc, &tmp, 4, SDMMC_RSP_TYPE_1); + return _sdmmc_storage_check_result(tmp); +} + +void _sd_storage_set_current_limit(sdmmc_storage_t *storage, u8 *buf) +{ + u32 pwr = SD_SET_CURRENT_LIMIT_800; + _sd_storage_switch(storage, buf, SD_SWITCH_SET, 3, pwr); + + while (pwr > 0) + { + pwr--; + _sd_storage_switch(storage, buf, SD_SWITCH_SET, 3, pwr); + if (((buf[15] >> 4) & 0x0F) == pwr) + break; + } + + switch (pwr) + { + case SD_SET_CURRENT_LIMIT_800: + DPRINTF("[SD] Power limit raised to 800mA\n"); + break; + case SD_SET_CURRENT_LIMIT_600: + DPRINTF("[SD] Power limit raised to 600mA\n"); + break; + case SD_SET_CURRENT_LIMIT_400: + DPRINTF("[SD] Power limit raised to 800mA\n"); + break; + default: + case SD_SET_CURRENT_LIMIT_200: + DPRINTF("[SD] Power limit defaulted to 200mA\n"); + break; + } +} + +int _sd_storage_enable_highspeed(sdmmc_storage_t *storage, u32 hs_type, u8 *buf) +{ + if (!_sd_storage_switch(storage, buf, SD_SWITCH_CHECK, 0, hs_type)) + return 0; + + u32 type_out = buf[16] & 0xF; + if (type_out != hs_type) + return 0; + + if ((((u16)buf[0] << 8) | buf[1]) < 0x320) + { + if (!_sd_storage_switch(storage, buf, SD_SWITCH_SET, 0, hs_type)) + return 0; + + if (type_out != (buf[16] & 0xF)) + return 0; + } + + return 1; +} + +int _sd_storage_enable_highspeed_low_volt(sdmmc_storage_t *storage, u32 type, u8 *buf) +{ + // Try to raise the current limit to let the card perform better. + _sd_storage_set_current_limit(storage, buf); + + if (sdmmc_get_bus_width(storage->sdmmc) != SDMMC_BUS_WIDTH_4) + return 0; + + if (!_sd_storage_switch_get(storage, buf)) + return 0; + //gfx_hexdump(0, (u8 *)buf, 64); + + u32 hs_type = 0; + switch (type) + { + case 11: + // Fall through if not supported. + if (buf[13] & SD_MODE_UHS_SDR104) + { + type = 11; + hs_type = UHS_SDR104_BUS_SPEED; + DPRINTF("[SD] Bus speed set to SDR104\n"); + storage->csd.busspeed = 104; + break; + } + case 10: + if (buf[13] & SD_MODE_UHS_SDR50) + { + type = 10; + hs_type = UHS_SDR50_BUS_SPEED; + DPRINTF("[SD] Bus speed set to SDR50\n"); + storage->csd.busspeed = 50; + break; + } + case 8: + if (!(buf[13] & SD_MODE_UHS_SDR12)) + return 0; + type = 8; + hs_type = UHS_SDR12_BUS_SPEED; + DPRINTF("[SD] Bus speed set to SDR12\n"); + storage->csd.busspeed = 12; + break; + default: + return 0; + break; + } + + if (!_sd_storage_enable_highspeed(storage, hs_type, buf)) + return 0; + if (!sdmmc_setup_clock(storage->sdmmc, type)) + return 0; + if (!sdmmc_config_tuning(storage->sdmmc, type, MMC_SEND_TUNING_BLOCK)) + return 0; + return _sdmmc_storage_check_status(storage); +} + +int _sd_storage_enable_highspeed_high_volt(sdmmc_storage_t *storage, u8 *buf) +{ + if (!_sd_storage_switch_get(storage, buf)) + return 0; + //gfx_hexdump(0, (u8 *)buf, 64); + if (!(buf[13] & SD_MODE_HIGH_SPEED)) + return 1; + + if (!_sd_storage_enable_highspeed(storage, 1, buf)) + return 0; + if (!_sdmmc_storage_check_status(storage)) + return 0; + return sdmmc_setup_clock(storage->sdmmc, 7); +} + +static void _sd_storage_parse_ssr(sdmmc_storage_t *storage) +{ + // unstuff_bits supports only 4 u32 so break into 2 x 16byte groups + u32 raw_ssr1[4]; + u32 raw_ssr2[4]; + + raw_ssr1[3] = *(u32 *)&storage->raw_ssr[12]; + raw_ssr1[2] = *(u32 *)&storage->raw_ssr[8]; + raw_ssr1[1] = *(u32 *)&storage->raw_ssr[4]; + raw_ssr1[0] = *(u32 *)&storage->raw_ssr[0]; + + raw_ssr2[3] = *(u32 *)&storage->raw_ssr[28]; + raw_ssr2[2] = *(u32 *)&storage->raw_ssr[24]; + raw_ssr2[1] = *(u32 *)&storage->raw_ssr[20]; + raw_ssr2[0] = *(u32 *)&storage->raw_ssr[16]; + + storage->ssr.bus_width = (unstuff_bits(raw_ssr1, 510 - 384, 2) & SD_BUS_WIDTH_4) ? 4 : 1; + switch(unstuff_bits(raw_ssr1, 440 - 384, 8)) + { + case 0: + storage->ssr.speed_class = 0; + break; + case 1: + storage->ssr.speed_class = 2; + break; + case 2: + storage->ssr.speed_class = 4; + break; + case 3: + storage->ssr.speed_class = 6; + break; + case 4: + storage->ssr.speed_class = 10; + break; + default: + storage->ssr.speed_class = unstuff_bits(raw_ssr1, 440 - 384, 8); + break; + } + storage->ssr.uhs_grade = unstuff_bits(raw_ssr1, 396 - 384, 4); + storage->ssr.video_class = unstuff_bits(raw_ssr1, 384 - 384, 8); + + storage->ssr.app_class = unstuff_bits(raw_ssr2, 336 - 256, 4); +} + +static int _sd_storage_get_ssr(sdmmc_storage_t *storage, u8 *buf) +{ + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, SD_APP_SD_STATUS, 0, SDMMC_RSP_TYPE_1, 0); + + sdmmc_req_t reqbuf; + reqbuf.buf = buf; + reqbuf.blksize = 64; + reqbuf.num_sectors = 1; + reqbuf.is_write = 0; + reqbuf.is_multi_block = 0; + reqbuf.is_auto_cmd12 = 0; + + if (!(storage->csd.cmdclass & CCC_APP_SPEC)) + { + DPRINTF("[SD] ssr: Card lacks mandatory SD Status function\n"); + return 0; + } + + if (!_sd_storage_execute_app_cmd(storage, R1_STATE_TRAN, 0, &cmdbuf, &reqbuf, 0)) + return 0; + + u32 tmp = 0; + sdmmc_get_rsp(storage->sdmmc, &tmp, 4, SDMMC_RSP_TYPE_1); + //Prepare buffer for unstuff_bits + for (int i = 0; i < 64; i+=4) + { + storage->raw_ssr[i + 3] = buf[i]; + storage->raw_ssr[i + 2] = buf[i + 1]; + storage->raw_ssr[i + 1] = buf[i + 2]; + storage->raw_ssr[i] = buf[i + 3]; + } + _sd_storage_parse_ssr(storage); + //gfx_hexdump(0, storage->raw_ssr, 64); + + return _sdmmc_storage_check_result(tmp); +} + +static void _sd_storage_parse_cid(sdmmc_storage_t *storage) +{ + u32 *raw_cid = (u32 *)&(storage->raw_cid); + + storage->cid.manfid = unstuff_bits(raw_cid, 120, 8); + storage->cid.oemid = unstuff_bits(raw_cid, 104, 16); + storage->cid.prod_name[0] = unstuff_bits(raw_cid, 96, 8); + storage->cid.prod_name[1] = unstuff_bits(raw_cid, 88, 8); + storage->cid.prod_name[2] = unstuff_bits(raw_cid, 80, 8); + storage->cid.prod_name[3] = unstuff_bits(raw_cid, 72, 8); + storage->cid.prod_name[4] = unstuff_bits(raw_cid, 64, 8); + storage->cid.hwrev = unstuff_bits(raw_cid, 60, 4); + storage->cid.fwrev = unstuff_bits(raw_cid, 56, 4); + storage->cid.serial = unstuff_bits(raw_cid, 24, 32); + storage->cid.month = unstuff_bits(raw_cid, 8, 4); + storage->cid.year = unstuff_bits(raw_cid, 12, 8) + 2000; +} + +static void _sd_storage_parse_csd(sdmmc_storage_t *storage) +{ + u32 *raw_csd = (u32 *)&(storage->raw_csd); + + storage->csd.structure = unstuff_bits(raw_csd, 126, 2); + storage->csd.cmdclass = unstuff_bits(raw_csd, 84, 12); + storage->csd.read_blkbits = unstuff_bits(raw_csd, 80, 4); + storage->csd.write_protect = unstuff_bits(raw_csd, 12, 2); + switch(storage->csd.structure) + { + case 0: + storage->csd.capacity = (1 + unstuff_bits(raw_csd, 62, 12)) << (unstuff_bits(raw_csd, 47, 3) + 2); + break; + case 1: + storage->csd.c_size = (1 + unstuff_bits(raw_csd, 48, 22)); + storage->csd.capacity = storage->csd.c_size << 10; + storage->csd.read_blkbits = 9; + break; + } +} + +int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 id, u32 bus_width, u32 type) +{ + int is_version_1 = 0; + + // Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms. + u32 sd_poweroff_time = (u32)get_tmr_ms() - h_cfg.sd_timeoff; + if (id == SDMMC_1 && (sd_poweroff_time < 100)) + msleep(100 - sd_poweroff_time); + + memset(storage, 0, sizeof(sdmmc_storage_t)); + storage->sdmmc = sdmmc; + + if (!sdmmc_init(sdmmc, id, SDMMC_POWER_3_3, SDMMC_BUS_WIDTH_1, 5, 0)) + return 0; + DPRINTF("[SD] after init\n"); + + usleep(1000 + (74000 + sdmmc->divisor - 1) / sdmmc->divisor); + + if (!_sdmmc_storage_go_idle_state(storage)) + return 0; + DPRINTF("[SD] went to idle state\n"); + + is_version_1 = _sd_storage_send_if_cond(storage); + if (is_version_1 == 2) + return 0; + DPRINTF("[SD] after send if cond\n"); + + if (!_sd_storage_get_op_cond(storage, is_version_1, bus_width == SDMMC_BUS_WIDTH_4 && type == 11)) + return 0; + DPRINTF("[SD] got op cond\n"); + + if (!_sdmmc_storage_get_cid(storage, storage->raw_cid)) + return 0; + DPRINTF("[SD] got cid\n"); + _sd_storage_parse_cid(storage); + + if (!_sd_storage_get_rca(storage)) + return 0; + DPRINTF("[SD] got rca (= %04X)\n", storage->rca); + + if (!_sdmmc_storage_get_csd(storage, storage->raw_csd)) + return 0; + DPRINTF("[SD] got csd\n"); + + //Parse CSD. + _sd_storage_parse_csd(storage); + switch (storage->csd.structure) + { + case 0: + storage->sec_cnt = storage->csd.capacity; + break; + case 1: + storage->sec_cnt = storage->csd.c_size << 10; + break; + default: + DPRINTF("[SD] Unknown CSD structure %d\n", storage->csd.structure); + break; + } + + if (!storage->is_low_voltage) + { + if (!sdmmc_setup_clock(storage->sdmmc, 6)) + return 0; + DPRINTF("[SD] after setup clock\n"); + } + + if (!_sdmmc_storage_select_card(storage)) + return 0; + DPRINTF("[SD] card selected\n"); + + if (!_sdmmc_storage_set_blocklen(storage, 512)) + return 0; + DPRINTF("[SD] set blocklen to 512\n"); + + u32 tmp = 0; + if (!_sd_storage_execute_app_cmd_type1(storage, &tmp, SD_APP_SET_CLR_CARD_DETECT, 0, 0, R1_STATE_TRAN)) + return 0; + DPRINTF("[SD] cleared card detect\n"); + + u8 *buf = (u8 *)malloc(512); + if (!_sd_storage_get_scr(storage, buf)) + { + free(buf); + return 0; + } + + //gfx_hexdump(0, storage->raw_scr, 8); + DPRINTF("[SD] got scr\n"); + + // Check if card supports a wider bus and if it's not SD Version 1.X + if (bus_width == SDMMC_BUS_WIDTH_4 && (storage->scr.bus_widths & 4) && (storage->scr.sda_vsn & 0xF)) + { + if (!_sd_storage_execute_app_cmd_type1(storage, &tmp, SD_APP_SET_BUS_WIDTH, SD_BUS_WIDTH_4, 0, R1_STATE_TRAN)) + { + free(buf); + return 0; + } + sdmmc_set_bus_width(storage->sdmmc, SDMMC_BUS_WIDTH_4); + DPRINTF("[SD] switched to wide bus width\n"); + } + else + { + DPRINTF("[SD] SD does not support wide bus width\n"); + } + + if (storage->is_low_voltage) + { + if (!_sd_storage_enable_highspeed_low_volt(storage, type, buf)) + { + free(buf); + return 0; + } + DPRINTF("[SD] enabled highspeed (low voltage)\n"); + } + else if (type != 6 && (storage->scr.sda_vsn & 0xF) != 0) + { + if (!_sd_storage_enable_highspeed_high_volt(storage, buf)) + { + free(buf); + return 0; + } + DPRINTF("[SD] enabled highspeed (high voltage)\n"); + storage->csd.busspeed = 25; + } + + sdmmc_sd_clock_ctrl(sdmmc, 1); + + // Parse additional card info from sd status. + if (_sd_storage_get_ssr(storage, buf)) + { + DPRINTF("[SD] got sd status\n"); + } + + free(buf); + return 1; +} + +/* +* Gamecard specific functions. +*/ + +int _gc_storage_custom_cmd(sdmmc_storage_t *storage, void *buf) +{ + u32 resp; + sdmmc_cmd_t cmdbuf; + sdmmc_init_cmd(&cmdbuf, 60, 0, SDMMC_RSP_TYPE_1, 1); + + sdmmc_req_t reqbuf; + reqbuf.buf = buf; + reqbuf.blksize = 64; + reqbuf.num_sectors = 1; + reqbuf.is_write = 1; + reqbuf.is_multi_block = 0; + reqbuf.is_auto_cmd12 = 0; + + if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, 0)) + { + sdmmc_stop_transmission(storage->sdmmc, &resp); + return 0; + } + + if (!sdmmc_get_rsp(storage->sdmmc, &resp, 4, SDMMC_RSP_TYPE_1)) + return 0; + if (!_sdmmc_storage_check_result(resp)) + return 0; + return _sdmmc_storage_check_status(storage); +} + +int sdmmc_storage_init_gc(sdmmc_storage_t *storage, sdmmc_t *sdmmc) +{ + memset(storage, 0, sizeof(sdmmc_storage_t)); + storage->sdmmc = sdmmc; + + if (!sdmmc_init(sdmmc, SDMMC_2, SDMMC_POWER_1_8, SDMMC_BUS_WIDTH_8, 14, 0)) + return 0; + DPRINTF("[gc] after init\n"); + + usleep(1000 + (10000 + sdmmc->divisor - 1) / sdmmc->divisor); + + if (!sdmmc_config_tuning(storage->sdmmc, 14, MMC_SEND_TUNING_BLOCK_HS200)) + return 0; + DPRINTF("[gc] after tuning\n"); + + sdmmc_sd_clock_ctrl(sdmmc, 1); + + return 1; +} diff --git a/nyx/nyx_gui/storage/sdmmc.h b/nyx/nyx_gui/storage/sdmmc.h new file mode 100644 index 0000000..7ae20e3 --- /dev/null +++ b/nyx/nyx_gui/storage/sdmmc.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _SDMMC_H_ +#define _SDMMC_H_ + +#include "../utils/types.h" +#include "sdmmc_driver.h" + +typedef struct _mmc_cid +{ + u32 manfid; + u8 prod_name[8]; + u8 card_bga; + u8 prv; + u32 serial; + u16 oemid; + u16 year; + u8 hwrev; + u8 fwrev; + u8 month; +} mmc_cid_t; + +typedef struct _mmc_csd +{ + u8 structure; + u8 mmca_vsn; + u16 cmdclass; + u32 c_size; + u32 r2w_factor; + u32 max_dtr; + u32 erase_size; /* In sectors */ + u32 read_blkbits; + u32 write_blkbits; + u32 capacity; + u8 write_protect; + u16 busspeed; +} mmc_csd_t; + +typedef struct _mmc_ext_csd +{ + u8 rev; + u32 sectors; + int bkops; /* background support bit */ + int bkops_en; /* manual bkops enable bit */ + u8 ext_struct; /* 194 */ + u8 card_type; /* 196 */ + u8 bkops_status; /* 246 */ + u16 dev_version; + u8 boot_mult; + u8 rpmb_mult; +} mmc_ext_csd_t; + +typedef struct _sd_scr +{ + u8 sda_vsn; + u8 sda_spec3; + u8 bus_widths; + u8 cmds; +} sd_scr_t; + +typedef struct _sd_ssr +{ + u8 bus_width; + u8 speed_class; + u8 uhs_grade; + u8 video_class; + u8 app_class; +} sd_ssr_t; + +/*! SDMMC storage context. */ +typedef struct _sdmmc_storage_t +{ + sdmmc_t *sdmmc; + u32 rca; + int has_sector_access; + u32 sec_cnt; + int is_low_voltage; + u32 partition; + u8 raw_cid[0x10]; + u8 raw_csd[0x10]; + u8 raw_scr[8]; + u8 raw_ssr[0x40]; + mmc_cid_t cid; + mmc_csd_t csd; + mmc_ext_csd_t ext_csd; + sd_scr_t scr; + sd_ssr_t ssr; +} sdmmc_storage_t; + +int sdmmc_storage_end(sdmmc_storage_t *storage); +int sdmmc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf); +int sdmmc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf); +int sdmmc_storage_init_mmc(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 id, u32 bus_width, u32 type); +int sdmmc_storage_set_mmc_partition(sdmmc_storage_t *storage, u32 partition); +int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 id, u32 bus_width, u32 type); +int sdmmc_storage_init_gc(sdmmc_storage_t *storage, sdmmc_t *sdmmc); + +#endif diff --git a/nyx/nyx_gui/storage/sdmmc_driver.c b/nyx/nyx_gui/storage/sdmmc_driver.c new file mode 100644 index 0000000..bf990e9 --- /dev/null +++ b/nyx/nyx_gui/storage/sdmmc_driver.c @@ -0,0 +1,1128 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "mmc.h" +#include "sdmmc.h" +#include "../config/config.h" +#include "../gfx/gfx.h" +#include "../power/max7762x.h" +#include "../soc/bpmp.h" +#include "../soc/clock.h" +#include "../soc/gpio.h" +#include "../soc/pinmux.h" +#include "../soc/pmc.h" +#include "../soc/t210.h" +#include "../utils/util.h" + +//#define DPRINTF(...) gfx_printf(__VA_ARGS__) +#define DPRINTF(...) + +extern hekate_config h_cfg; + +/*! SCMMC controller base addresses. */ +static const u32 _sdmmc_bases[4] = { + 0x700B0000, + 0x700B0200, + 0x700B0400, + 0x700B0600, +}; + +int sdmmc_get_voltage(sdmmc_t *sdmmc) +{ + u32 p = sdmmc->regs->pwrcon; + if (!(p & TEGRA_MMC_PWRCTL_SD_BUS_POWER)) + return SDMMC_POWER_OFF; + if (p & TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V1_8) + return SDMMC_POWER_1_8; + if (p & TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V3_3) + return SDMMC_POWER_3_3; + return -1; +} + +static int _sdmmc_set_voltage(sdmmc_t *sdmmc, u32 power) +{ + u8 pwr = 0; + + switch (power) + { + case SDMMC_POWER_OFF: + sdmmc->regs->pwrcon &= ~TEGRA_MMC_PWRCTL_SD_BUS_POWER; + break; + case SDMMC_POWER_1_8: + sdmmc->regs->pwrcon = TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V1_8; + pwr = TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V1_8; + break; + case SDMMC_POWER_3_3: + sdmmc->regs->pwrcon = TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V3_3; + pwr = TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V3_3; + break; + default: + return 0; + } + + if (power != SDMMC_POWER_OFF) + { + pwr |= TEGRA_MMC_PWRCTL_SD_BUS_POWER; + sdmmc->regs->pwrcon = pwr; + } + + return 1; +} + +u32 sdmmc_get_bus_width(sdmmc_t *sdmmc) +{ + u32 h = sdmmc->regs->hostctl; + if (h & TEGRA_MMC_HOSTCTL_8BIT) + return SDMMC_BUS_WIDTH_8; + if (h & TEGRA_MMC_HOSTCTL_4BIT) + return SDMMC_BUS_WIDTH_4; + return SDMMC_BUS_WIDTH_1; +} + +void sdmmc_set_bus_width(sdmmc_t *sdmmc, u32 bus_width) +{ + if (bus_width == SDMMC_BUS_WIDTH_1) + sdmmc->regs->hostctl &= ~(TEGRA_MMC_HOSTCTL_4BIT | TEGRA_MMC_HOSTCTL_8BIT); + else if (bus_width == SDMMC_BUS_WIDTH_4) + { + sdmmc->regs->hostctl |= TEGRA_MMC_HOSTCTL_4BIT; + sdmmc->regs->hostctl &= ~TEGRA_MMC_HOSTCTL_8BIT; + } + else if (bus_width == SDMMC_BUS_WIDTH_8) + sdmmc->regs->hostctl |= TEGRA_MMC_HOSTCTL_8BIT; +} + +void sdmmc_get_venclkctl(sdmmc_t *sdmmc) +{ + sdmmc->venclkctl_tap = sdmmc->regs->venclkctl >> 16; + sdmmc->venclkctl_set = 1; +} + +static int _sdmmc_config_ven_ceata_clk(sdmmc_t *sdmmc, u32 id) +{ + u32 tap_val = 0; + + if (id == 4) + sdmmc->regs->venceatactl = (sdmmc->regs->venceatactl & 0xFFFFC0FF) | 0x2800; + sdmmc->regs->ventunctl0 &= 0xFFFDFFFF; + if (id == 4) + { + if (!sdmmc->venclkctl_set) + return 0; + tap_val = sdmmc->venclkctl_tap; + } + else + { + static const u32 tap_values[] = { 4, 0, 3, 0 }; + tap_val = tap_values[sdmmc->id]; + } + sdmmc->regs->venclkctl = (sdmmc->regs->venclkctl & 0xFF00FFFF) | (tap_val << 16); + + return 1; +} + +static int _sdmmc_get_clkcon(sdmmc_t *sdmmc) +{ + return sdmmc->regs->clkcon; +} + +static void _sdmmc_pad_config_fallback(sdmmc_t *sdmmc, u32 power) +{ + _sdmmc_get_clkcon(sdmmc); + switch (sdmmc->id) + { + case SDMMC_1: + if (power == SDMMC_POWER_OFF) + break; + if (power == SDMMC_POWER_1_8) + APB_MISC(APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL) = 0x304; // Up: 3, Dn: 4. + else if (power == SDMMC_POWER_3_3) + APB_MISC(APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL) = 0x808; // Up: 8, Dn: 8. + break; + case SDMMC_4: + APB_MISC(APB_MISC_GP_EMMC4_PAD_CFGPADCTRL) = (APB_MISC(APB_MISC_GP_EMMC4_PAD_CFGPADCTRL) & 0x3FFC) | 0x1040; + break; + } + //TODO: load standard values for other controllers, can depend on power. +} + +static int _sdmmc_wait_type4(sdmmc_t *sdmmc) +{ + int res = 1, should_disable_sd_clock = 0; + + if (!(sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE)) + { + should_disable_sd_clock = 1; + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + } + + sdmmc->regs->vendllcal |= 0x80000000; + _sdmmc_get_clkcon(sdmmc); + + u32 timeout = get_tmr_ms() + 5; + while (sdmmc->regs->vendllcal & 0x80000000) + { + if (get_tmr_ms() > timeout) + { + res = 0; + goto out; + } + } + + timeout = get_tmr_ms() + 10; + while (sdmmc->regs->dllcfgstatus & 0x80000000) + { + if (get_tmr_ms() > timeout) + { + res = 0; + goto out; + } + } + +out:; + if (should_disable_sd_clock) + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + return res; +} + +int sdmmc_setup_clock(sdmmc_t *sdmmc, u32 type) +{ + // Disable the SD clock if it was enabled, and reenable it later. + bool should_enable_sd_clock = false; + if (sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE) + { + should_enable_sd_clock = true; + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + } + + _sdmmc_config_ven_ceata_clk(sdmmc, type); + + switch (type) + { + case 0: + case 1: + case 5: + case 6: + sdmmc->regs->hostctl &= 0xFB; // Should this be 0xFFFB (~4) ? + sdmmc->regs->hostctl2 &= SDHCI_CTRL_VDD_330; + break; + case 2: + case 7: + sdmmc->regs->hostctl |= 4; + sdmmc->regs->hostctl2 &= SDHCI_CTRL_VDD_330; + break; + case 3: + case 11: + case 13: + case 14: + sdmmc->regs->hostctl2 = (sdmmc->regs->hostctl2 & SDHCI_CTRL_UHS_MASK) | UHS_SDR104_BUS_SPEED; + sdmmc->regs->hostctl2 |= SDHCI_CTRL_VDD_180; + break; + case 4: + // Non standard + sdmmc->regs->hostctl2 = (sdmmc->regs->hostctl2 & SDHCI_CTRL_UHS_MASK) | HS400_BUS_SPEED; + sdmmc->regs->hostctl2 |= SDHCI_CTRL_VDD_180; + break; + case 8: + sdmmc->regs->hostctl2 = (sdmmc->regs->hostctl2 & SDHCI_CTRL_UHS_MASK) | UHS_SDR12_BUS_SPEED; + sdmmc->regs->hostctl2 |= SDHCI_CTRL_VDD_180; + break; + case 10: + // T210 Errata for SDR50, the host must be set to SDR104. + sdmmc->regs->hostctl2 = (sdmmc->regs->hostctl2 & SDHCI_CTRL_UHS_MASK) | UHS_SDR104_BUS_SPEED; + sdmmc->regs->hostctl2 |= SDHCI_CTRL_VDD_180; + break; + } + + _sdmmc_get_clkcon(sdmmc); + + u32 tmp; + u16 divisor; + clock_sdmmc_get_params(&tmp, &divisor, type); + clock_sdmmc_config_clock_source(&tmp, sdmmc->id, tmp); + sdmmc->divisor = (tmp + divisor - 1) / divisor; + + //if divisor != 1 && divisor << 31 -> error + + u16 div = divisor >> 1; + divisor = 0; + if (div > 0xFF) + divisor = div >> 8; + sdmmc->regs->clkcon = (sdmmc->regs->clkcon & 0x3F) | (div << 8) | (divisor << 6); + + // Enable the SD clock again. + if (should_enable_sd_clock) + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + + if (type == 4) + return _sdmmc_wait_type4(sdmmc); + return 1; +} + +static void _sdmmc_sd_clock_enable(sdmmc_t *sdmmc) +{ + if (!sdmmc->no_sd) + { + if (!(sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE)) + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + } + sdmmc->sd_clock_enabled = 1; +} + +static void _sdmmc_sd_clock_disable(sdmmc_t *sdmmc) +{ + sdmmc->sd_clock_enabled = 0; + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; +} + +void sdmmc_sd_clock_ctrl(sdmmc_t *sdmmc, int no_sd) +{ + sdmmc->no_sd = no_sd; + if (no_sd) + { + if (!(sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE)) + return; + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + return; + } + if (sdmmc->sd_clock_enabled) + if (!(sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE)) + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; +} + +static int _sdmmc_cache_rsp(sdmmc_t *sdmmc, u32 *rsp, u32 size, u32 type) +{ + switch (type) + { + case SDMMC_RSP_TYPE_1: + case SDMMC_RSP_TYPE_3: + case SDMMC_RSP_TYPE_4: + case SDMMC_RSP_TYPE_5: + if (size < 4) + return 0; + rsp[0] = sdmmc->regs->rspreg0; + break; + case SDMMC_RSP_TYPE_2: + if (size < 0x10) + return 0; + // CRC is stripped, so shifting is needed. + u32 tempreg; + for (int i = 0; i < 4; i++) + { + switch(i) + { + case 0: + tempreg = sdmmc->regs->rspreg3; + break; + case 1: + tempreg = sdmmc->regs->rspreg2; + break; + case 2: + tempreg = sdmmc->regs->rspreg1; + break; + case 3: + tempreg = sdmmc->regs->rspreg0; + break; + } + rsp[i] = tempreg << 8; + + if (i != 0) + rsp[i - 1] |= (tempreg >> 24) & 0xFF; + } + break; + default: + return 0; + break; + } + + return 1; +} + +int sdmmc_get_rsp(sdmmc_t *sdmmc, u32 *rsp, u32 size, u32 type) +{ + if (!rsp || sdmmc->expected_rsp_type != type) + return 0; + + switch (type) + { + case SDMMC_RSP_TYPE_1: + case SDMMC_RSP_TYPE_3: + case SDMMC_RSP_TYPE_4: + case SDMMC_RSP_TYPE_5: + if (size < 4) + return 0; + rsp[0] = sdmmc->rsp[0]; + break; + case SDMMC_RSP_TYPE_2: + if (size < 0x10) + return 0; + rsp[0] = sdmmc->rsp[0]; + rsp[1] = sdmmc->rsp[1]; + rsp[2] = sdmmc->rsp[2]; + rsp[3] = sdmmc->rsp[3]; + break; + default: + return 0; + break; + } + + return 1; +} + +static void _sdmmc_reset(sdmmc_t *sdmmc) +{ + sdmmc->regs->swrst |= + TEGRA_MMC_SWRST_SW_RESET_FOR_CMD_LINE | TEGRA_MMC_SWRST_SW_RESET_FOR_DAT_LINE; + _sdmmc_get_clkcon(sdmmc); + u32 timeout = get_tmr_ms() + 2000; + while (sdmmc->regs->swrst << 29 >> 30 && get_tmr_ms() < timeout) + ; +} + +static int _sdmmc_wait_prnsts_type0(sdmmc_t *sdmmc, u32 wait_dat) +{ + _sdmmc_get_clkcon(sdmmc); + + u32 timeout = get_tmr_ms() + 2000; + while(sdmmc->regs->prnsts & 1) // CMD inhibit. + if (get_tmr_ms() > timeout) + { + _sdmmc_reset(sdmmc); + return 0; + } + + if (wait_dat) + { + timeout = get_tmr_ms() + 2000; + while (sdmmc->regs->prnsts & 2) // DAT inhibit. + if (get_tmr_ms() > timeout) + { + _sdmmc_reset(sdmmc); + return 0; + } + } + + return 1; +} + +static int _sdmmc_wait_prnsts_type1(sdmmc_t *sdmmc) +{ + _sdmmc_get_clkcon(sdmmc); + + u32 timeout = get_tmr_ms() + 2000; + while (!(sdmmc->regs->prnsts & 0x100000)) // DAT0 line level. + if (get_tmr_ms() > timeout) + { + _sdmmc_reset(sdmmc); + return 0; + } + + return 1; +} + +static int _sdmmc_setup_read_small_block(sdmmc_t *sdmmc) +{ + switch (sdmmc_get_bus_width(sdmmc)) + { + case SDMMC_BUS_WIDTH_1: + return 0; + break; + case SDMMC_BUS_WIDTH_4: + sdmmc->regs->blksize = 0x40; + break; + case SDMMC_BUS_WIDTH_8: + sdmmc->regs->blksize = 0x80; + break; + } + sdmmc->regs->blkcnt = 1; + sdmmc->regs->trnmod = TEGRA_MMC_TRNMOD_DATA_XFER_DIR_SEL_READ; + return 1; +} + +static int _sdmmc_parse_cmdbuf(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, bool is_data_present) +{ + u16 cmdflags = 0; + + switch (cmd->rsp_type) + { + case SDMMC_RSP_TYPE_0: + break; + case SDMMC_RSP_TYPE_1: + case SDMMC_RSP_TYPE_4: + case SDMMC_RSP_TYPE_5: + if (cmd->check_busy) + cmdflags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48_BUSY | + TEGRA_MMC_TRNMOD_CMD_INDEX_CHECK | + TEGRA_MMC_TRNMOD_CMD_CRC_CHECK; + else + cmdflags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48 | + TEGRA_MMC_TRNMOD_CMD_INDEX_CHECK | + TEGRA_MMC_TRNMOD_CMD_CRC_CHECK; + break; + case SDMMC_RSP_TYPE_2: + cmdflags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_136 | + TEGRA_MMC_TRNMOD_CMD_CRC_CHECK; + break; + case SDMMC_RSP_TYPE_3: + cmdflags = TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48; + break; + default: + return 0; + break; + } + + if (is_data_present) + cmdflags |= TEGRA_MMC_TRNMOD_DATA_PRESENT_SELECT_DATA_TRANSFER; + sdmmc->regs->argument = cmd->arg; + sdmmc->regs->cmdreg = (cmd->cmd << 8) | cmdflags; + + return 1; +} + +static void _sdmmc_parse_cmd_48(sdmmc_t *sdmmc, u32 cmd) +{ + sdmmc_cmd_t cmdbuf; + cmdbuf.cmd = cmd; + cmdbuf.arg = 0; + cmdbuf.rsp_type = SDMMC_RSP_TYPE_1; + cmdbuf.check_busy = 0; + _sdmmc_parse_cmdbuf(sdmmc, &cmdbuf, true); +} + +static int _sdmmc_config_tuning_once(sdmmc_t *sdmmc, u32 cmd) +{ + if (sdmmc->no_sd) + return 0; + if (!_sdmmc_wait_prnsts_type0(sdmmc, 1)) + return 0; + + _sdmmc_setup_read_small_block(sdmmc); + sdmmc->regs->norintstsen |= TEGRA_MMC_NORINTSTSEN_BUFFER_READ_READY; + sdmmc->regs->norintsts = sdmmc->regs->norintsts; + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + _sdmmc_parse_cmd_48(sdmmc, cmd); + _sdmmc_get_clkcon(sdmmc); + usleep(1); + _sdmmc_reset(sdmmc); + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + _sdmmc_get_clkcon(sdmmc); + + u32 timeout = get_tmr_us() + 5000; + while (get_tmr_us() < timeout) + { + if (sdmmc->regs->norintsts & 0x20) + { + sdmmc->regs->norintsts = 0x20; + sdmmc->regs->norintstsen &= 0xFFDF; + _sdmmc_get_clkcon(sdmmc); + usleep((1000 * 8 + sdmmc->divisor - 1) / sdmmc->divisor); + return 1; + } + } + _sdmmc_reset(sdmmc); + sdmmc->regs->norintstsen &= 0xFFDF; + _sdmmc_get_clkcon(sdmmc); + usleep((1000 * 8 + sdmmc->divisor - 1) / sdmmc->divisor); + return 0; +} + +int sdmmc_config_tuning(sdmmc_t *sdmmc, u32 type, u32 cmd) +{ + u32 max = 0, flag = 0; + + sdmmc->regs->field_1C4 = 0; + switch (type) + { + case 3: + case 4: + case 11: + max = 0x80; + flag = 0x4000; + break; + case 10: + case 13: + case 14: + max = 0x100; + flag = 0x8000; + break; + default: + return 0; + } + + sdmmc->regs->ventunctl0 = (sdmmc->regs->ventunctl0 & 0xFFFF1FFF) | flag; + sdmmc->regs->ventunctl0 = (sdmmc->regs->ventunctl0 & 0xFFFFE03F) | 0x40; + sdmmc->regs->ventunctl0 |= 0x20000; + sdmmc->regs->hostctl2 |= SDHCI_CTRL_EXEC_TUNING; + + for (u32 i = 0; i < max; i++) + { + _sdmmc_config_tuning_once(sdmmc, cmd); + if (!(sdmmc->regs->hostctl2 & SDHCI_CTRL_EXEC_TUNING)) + break; + } + + if (sdmmc->regs->hostctl2 & SDHCI_CTRL_TUNED_CLK) + return 1; + return 0; +} + +static int _sdmmc_enable_internal_clock(sdmmc_t *sdmmc) +{ + //Enable internal clock and wait till it is stable. + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_INTERNAL_CLOCK_ENABLE; + _sdmmc_get_clkcon(sdmmc); + u32 timeout = get_tmr_ms() + 2000; + while (!(sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_INTERNAL_CLOCK_STABLE)) + { + if (get_tmr_ms() > timeout) + return 0; + } + + sdmmc->regs->hostctl2 &= ~SDHCI_CTRL_PRESET_VAL_EN; + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_CLKGEN_SELECT; + sdmmc->regs->hostctl2 |= SDHCI_HOST_VERSION_4_EN; + + if (!(sdmmc->regs->capareg & 0x10000000)) + return 0; + + sdmmc->regs->hostctl2 |= SDHCI_ADDRESSING_64BIT_EN; + sdmmc->regs->hostctl &= 0xE7; + sdmmc->regs->timeoutcon = (sdmmc->regs->timeoutcon & 0xF0) | 0xE; + + return 1; +} + +static int _sdmmc_autocal_config_offset(sdmmc_t *sdmmc, u32 power) +{ + u32 off_pd = 0; + u32 off_pu = 0; + + switch (sdmmc->id) + { + case SDMMC_2: + case SDMMC_4: + if (power != SDMMC_POWER_1_8) + return 0; + off_pd = 5; + off_pu = 5; + break; + case SDMMC_1: + case SDMMC_3: + if (power == SDMMC_POWER_1_8) + { + off_pd = 123; + off_pu = 123; + } + else if (power == SDMMC_POWER_3_3) + { + off_pd = 125; + off_pu = 0; + } + else + return 0; + break; + } + + sdmmc->regs->autocalcfg = (((sdmmc->regs->autocalcfg & 0xFFFF80FF) | (off_pd << 8)) >> 7 << 7) | off_pu; + return 1; +} + +static void _sdmmc_autocal_execute(sdmmc_t *sdmmc, u32 power) +{ + bool should_enable_sd_clock = false; + if (sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE) + { + should_enable_sd_clock = true; + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + } + + if (!(sdmmc->regs->sdmemcmppadctl & 0x80000000)) + { + sdmmc->regs->sdmemcmppadctl |= 0x80000000; + _sdmmc_get_clkcon(sdmmc); + usleep(1); + } + + sdmmc->regs->autocalcfg |= 0xA0000000; + _sdmmc_get_clkcon(sdmmc); + usleep(1); + + u32 timeout = get_tmr_ms() + 10; + while (sdmmc->regs->autocalcfg & 0x80000000) + { + if (get_tmr_ms() > timeout) + { + // In case autocalibration fails, we load suggested standard values. + _sdmmc_pad_config_fallback(sdmmc, power); + sdmmc->regs->autocalcfg &= 0xDFFFFFFF; + break; + } + } + + sdmmc->regs->sdmemcmppadctl &= 0x7FFFFFFF; + + if(should_enable_sd_clock) + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; +} + +static void _sdmmc_enable_interrupts(sdmmc_t *sdmmc) +{ + sdmmc->regs->norintstsen |= 0xB; + sdmmc->regs->errintstsen |= 0x17F; + sdmmc->regs->norintsts = sdmmc->regs->norintsts; + sdmmc->regs->errintsts = sdmmc->regs->errintsts; +} + +static void _sdmmc_mask_interrupts(sdmmc_t *sdmmc) +{ + sdmmc->regs->errintstsen &= 0xFE80; + sdmmc->regs->norintstsen &= 0xFFF4; +} + +static int _sdmmc_check_mask_interrupt(sdmmc_t *sdmmc, u16 *pout, u16 mask) +{ + u16 norintsts = sdmmc->regs->norintsts; + u16 errintsts = sdmmc->regs->errintsts; + + DPRINTF("norintsts %08X; errintsts %08X\n", norintsts, errintsts); + + if (pout) + *pout = norintsts; + + // Check for error interrupt. + if (norintsts & TEGRA_MMC_NORINTSTS_ERR_INTERRUPT) + { + sdmmc->regs->errintsts = errintsts; + return SDMMC_MASKINT_ERROR; + } + else if (norintsts & mask) + { + sdmmc->regs->norintsts = norintsts & mask; + return SDMMC_MASKINT_MASKED; + } + + return SDMMC_MASKINT_NOERROR; +} + +static int _sdmmc_wait_request(sdmmc_t *sdmmc) +{ + _sdmmc_get_clkcon(sdmmc); + + u32 timeout = get_tmr_ms() + 2000; + while (1) + { + int res = _sdmmc_check_mask_interrupt(sdmmc, 0, TEGRA_MMC_NORINTSTS_CMD_COMPLETE); + if (res == SDMMC_MASKINT_MASKED) + break; + if (res != SDMMC_MASKINT_NOERROR || get_tmr_ms() > timeout) + { + _sdmmc_reset(sdmmc); + return 0; + } + } + + return 1; +} + +static int _sdmmc_stop_transmission_inner(sdmmc_t *sdmmc, u32 *rsp) +{ + sdmmc_cmd_t cmd; + + if (!_sdmmc_wait_prnsts_type0(sdmmc, 0)) + return 0; + + _sdmmc_enable_interrupts(sdmmc); + cmd.cmd = MMC_STOP_TRANSMISSION; + cmd.arg = 0; + cmd.rsp_type = SDMMC_RSP_TYPE_1; + cmd.check_busy = 1; + _sdmmc_parse_cmdbuf(sdmmc, &cmd, false); + int res = _sdmmc_wait_request(sdmmc); + _sdmmc_mask_interrupts(sdmmc); + + if (!res) + return 0; + + _sdmmc_cache_rsp(sdmmc, rsp, 4, SDMMC_RSP_TYPE_1); + return _sdmmc_wait_prnsts_type1(sdmmc); +} + +int sdmmc_stop_transmission(sdmmc_t *sdmmc, u32 *rsp) +{ + if (!sdmmc->sd_clock_enabled) + return 0; + + bool should_disable_sd_clock = false; + if (!(sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE)) + { + should_disable_sd_clock = true; + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + _sdmmc_get_clkcon(sdmmc); + usleep((8000 + sdmmc->divisor - 1) / sdmmc->divisor); + } + + int res = _sdmmc_stop_transmission_inner(sdmmc, rsp); + usleep((8000 + sdmmc->divisor - 1) / sdmmc->divisor); + if (should_disable_sd_clock) + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + + return res; +} + +static int _sdmmc_config_dma(sdmmc_t *sdmmc, u32 *blkcnt_out, sdmmc_req_t *req) +{ + if (!req->blksize || !req->num_sectors) + return 0; + + u32 blkcnt = req->num_sectors; + if (blkcnt >= 0xFFFF) + blkcnt = 0xFFFF; + u32 admaaddr = (u32)req->buf; + + // Check alignment. + if (admaaddr << 29) + return 0; + + sdmmc->regs->admaaddr = admaaddr; + sdmmc->regs->admaaddr_hi = 0; + + sdmmc->dma_addr_next = (admaaddr + 0x80000) & 0xFFF80000; + + sdmmc->regs->blksize = req->blksize | 0x7000; + sdmmc->regs->blkcnt = blkcnt; + + if (blkcnt_out) + *blkcnt_out = blkcnt; + + u32 trnmode = TEGRA_MMC_TRNMOD_DMA_ENABLE; + if (req->is_multi_block) + trnmode = TEGRA_MMC_TRNMOD_MULTI_BLOCK_SELECT | + TEGRA_MMC_TRNMOD_BLOCK_COUNT_ENABLE | + TEGRA_MMC_TRNMOD_DMA_ENABLE; + if (!req->is_write) + trnmode |= TEGRA_MMC_TRNMOD_DATA_XFER_DIR_SEL_READ; + if (req->is_auto_cmd12) + trnmode = (trnmode & 0xFFF3) | TEGRA_MMC_TRNMOD_AUTO_CMD12; + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY); + sdmmc->regs->trnmod = trnmode; + + return 1; +} + +static int _sdmmc_update_dma(sdmmc_t *sdmmc) +{ + u16 blkcnt = 0; + do + { + blkcnt = sdmmc->regs->blkcnt; + u32 timeout = get_tmr_ms() + 1500; + do + { + int res = 0; + while (1) + { + u16 intr = 0; + res = _sdmmc_check_mask_interrupt(sdmmc, &intr, + TEGRA_MMC_NORINTSTS_XFER_COMPLETE | TEGRA_MMC_NORINTSTS_DMA_INTERRUPT); + if (res < 0) + break; + if (intr & TEGRA_MMC_NORINTSTS_XFER_COMPLETE) + { + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY); + return 1; // Transfer complete. + } + if (intr & TEGRA_MMC_NORINTSTS_DMA_INTERRUPT) + { + // Update DMA. + sdmmc->regs->admaaddr = sdmmc->dma_addr_next; + sdmmc->regs->admaaddr_hi = 0; + sdmmc->dma_addr_next += 0x80000; + } + } + if (res != SDMMC_MASKINT_NOERROR) + { + _sdmmc_reset(sdmmc); + return 0; + } + } while (get_tmr_ms() < timeout); + } while (sdmmc->regs->blkcnt != blkcnt); + + _sdmmc_reset(sdmmc); + return 0; +} + +static int _sdmmc_execute_cmd_inner(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *req, u32 *blkcnt_out) +{ + int has_req_or_check_busy = req || cmd->check_busy; + if (!_sdmmc_wait_prnsts_type0(sdmmc, has_req_or_check_busy)) + return 0; + + u32 blkcnt = 0; + bool is_data_present = false; + if (req) + { + _sdmmc_config_dma(sdmmc, &blkcnt, req); + _sdmmc_enable_interrupts(sdmmc); + is_data_present = true; + } + else + { + _sdmmc_enable_interrupts(sdmmc); + is_data_present = false; + } + + _sdmmc_parse_cmdbuf(sdmmc, cmd, is_data_present); + + int res = _sdmmc_wait_request(sdmmc); + DPRINTF("rsp(%d): %08X, %08X, %08X, %08X\n", res, + sdmmc->regs->rspreg0, sdmmc->regs->rspreg1, sdmmc->regs->rspreg2, sdmmc->regs->rspreg3); + if (res) + { + if (cmd->rsp_type) + { + sdmmc->expected_rsp_type = cmd->rsp_type; + _sdmmc_cache_rsp(sdmmc, sdmmc->rsp, 0x10, cmd->rsp_type); + } + if (req) + _sdmmc_update_dma(sdmmc); + } + + _sdmmc_mask_interrupts(sdmmc); + + if (res) + { + if (req) + { + if (blkcnt_out) + *blkcnt_out = blkcnt; + if (req->is_auto_cmd12) + sdmmc->rsp3 = sdmmc->regs->rspreg3; + } + + if (cmd->check_busy || req) + return _sdmmc_wait_prnsts_type1(sdmmc); + } + + return res; +} + +static int _sdmmc_config_sdmmc1() +{ + // Configure SD card detect. + PINMUX_AUX(PINMUX_AUX_GPIO_PZ1) = PINMUX_INPUT_ENABLE | PINMUX_PULL_UP | 1; //GPIO control, pull up. + APB_MISC(APB_MISC_GP_VGPIO_GPIO_MUX_SEL) = 0; + gpio_config(GPIO_PORT_Z, GPIO_PIN_1, GPIO_MODE_GPIO); + gpio_output_enable(GPIO_PORT_Z, GPIO_PIN_1, GPIO_OUTPUT_DISABLE); + usleep(100); + if(!!gpio_read(GPIO_PORT_Z, GPIO_PIN_1)) + return 0; + + /* + * Pinmux config: + * DRV_TYPE = DRIVE_2X + * E_SCHMT = ENABLE (for 1.8V), DISABLE (for 3.3V) + * E_INPUT = ENABLE + * TRISTATE = PASSTHROUGH + * APB_MISC_GP_SDMMCx_CLK_LPBK_CONTROL = SDMMCx_CLK_PAD_E_LPBK for CLK + */ + + // Configure SDMMC1 pinmux. + APB_MISC(APB_MISC_GP_SDMMC1_CLK_LPBK_CONTROL) = 1; + PINMUX_AUX(PINMUX_AUX_SDMMC1_CLK) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED; + PINMUX_AUX(PINMUX_AUX_SDMMC1_CMD) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT3) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT2) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT1) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT0) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + + // Make sure the SDMMC1 controller is powered. + PMC(APBDEV_PMC_NO_IOPOWER) &= ~(1 << 12); + // Assume 3.3V SD card voltage. + PMC(APBDEV_PMC_PWR_DET_VAL) |= (1 << 12); + + // Set enable SD card power. + PINMUX_AUX(PINMUX_AUX_DMIC3_CLK) = PINMUX_INPUT_ENABLE | PINMUX_PULL_DOWN | 1; //GPIO control, pull down. + gpio_config(GPIO_PORT_E, GPIO_PIN_4, GPIO_MODE_GPIO); + gpio_write(GPIO_PORT_E, GPIO_PIN_4, GPIO_HIGH); + gpio_output_enable(GPIO_PORT_E, GPIO_PIN_4, GPIO_OUTPUT_ENABLE); + + usleep(1000); + + // Enable SD card power. + max77620_regulator_set_voltage(REGULATOR_LDO2, 3300000); + max77620_regulator_enable(REGULATOR_LDO2, 1); + + usleep(1000); + + // For good measure. + APB_MISC(APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL) = 0x10000000; + + usleep(1000); + + return 1; +} + +int sdmmc_init(sdmmc_t *sdmmc, u32 id, u32 power, u32 bus_width, u32 type, int no_sd) +{ + if (id > SDMMC_4) + return 0; + + if (id == SDMMC_1) + if (!_sdmmc_config_sdmmc1()) + return 0; + + memset(sdmmc, 0, sizeof(sdmmc_t)); + + sdmmc->regs = (t210_sdmmc_t *)_sdmmc_bases[id]; + sdmmc->id = id; + sdmmc->clock_stopped = 1; + + if (clock_sdmmc_is_not_reset_and_enabled(id)) + { + _sdmmc_sd_clock_disable(sdmmc); + _sdmmc_get_clkcon(sdmmc); + } + + u32 clock; + u16 divisor; + clock_sdmmc_get_params(&clock, &divisor, type); + clock_sdmmc_enable(id, clock); + + sdmmc->clock_stopped = 0; + + //TODO: make this skip-able. + sdmmc->regs->iospare |= 0x80000; + sdmmc->regs->veniotrimctl &= 0xFFFFFFFB; + static const u32 trim_values[] = { 2, 8, 3, 8 }; + sdmmc->regs->venclkctl = (sdmmc->regs->venclkctl & 0xE0FFFFFF) | (trim_values[sdmmc->id] << 24); + sdmmc->regs->sdmemcmppadctl = (sdmmc->regs->sdmemcmppadctl & 0xF) | 7; + if (!_sdmmc_autocal_config_offset(sdmmc, power)) + return 0; + _sdmmc_autocal_execute(sdmmc, power); + if (_sdmmc_enable_internal_clock(sdmmc)) + { + sdmmc_set_bus_width(sdmmc, bus_width); + _sdmmc_set_voltage(sdmmc, power); + if (sdmmc_setup_clock(sdmmc, type)) + { + sdmmc_sd_clock_ctrl(sdmmc, no_sd); + _sdmmc_sd_clock_enable(sdmmc); + _sdmmc_get_clkcon(sdmmc); + return 1; + } + return 0; + } + return 0; +} + +void sdmmc_end(sdmmc_t *sdmmc) +{ + if (!sdmmc->clock_stopped) + { + _sdmmc_sd_clock_disable(sdmmc); + // Disable SDMMC power. + _sdmmc_set_voltage(sdmmc, SDMMC_POWER_OFF); + + // Disable SD card power. + if (sdmmc->id == SDMMC_1) + { + gpio_output_enable(GPIO_PORT_E, GPIO_PIN_4, GPIO_OUTPUT_DISABLE); + max77620_regulator_enable(REGULATOR_LDO2, 0); + h_cfg.sd_timeoff = get_tmr_ms(); // Some sandisc U1 cards need 100ms for a power cycle. + msleep(1); // To power cycle, min 1ms without power is needed. + } + + _sdmmc_get_clkcon(sdmmc); + clock_sdmmc_disable(sdmmc->id); + sdmmc->clock_stopped = 1; + } +} + +void sdmmc_init_cmd(sdmmc_cmd_t *cmdbuf, u16 cmd, u32 arg, u32 rsp_type, u32 check_busy) +{ + cmdbuf->cmd = cmd; + cmdbuf->arg = arg; + cmdbuf->rsp_type = rsp_type; + cmdbuf->check_busy = check_busy; +} + +int sdmmc_execute_cmd(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *req, u32 *blkcnt_out) +{ + if (!sdmmc->sd_clock_enabled) + return 0; + + // Recalibrate periodically for SDMMC1. + if (sdmmc->id == SDMMC_1 && sdmmc->no_sd) + _sdmmc_autocal_execute(sdmmc, sdmmc_get_voltage(sdmmc)); + + int should_disable_sd_clock = 0; + if (!(sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE)) + { + should_disable_sd_clock = 1; + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + _sdmmc_get_clkcon(sdmmc); + usleep((8000 + sdmmc->divisor - 1) / sdmmc->divisor); + } + + int res = _sdmmc_execute_cmd_inner(sdmmc, cmd, req, blkcnt_out); + usleep((8000 + sdmmc->divisor - 1) / sdmmc->divisor); + if (should_disable_sd_clock) + sdmmc->regs->clkcon &= ~TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + + return res; +} + +int sdmmc_enable_low_voltage(sdmmc_t *sdmmc) +{ + if(sdmmc->id != SDMMC_1) + return 0; + + if (!sdmmc_setup_clock(sdmmc, 8)) + return 0; + + _sdmmc_get_clkcon(sdmmc); + + // Enable schmitt trigger for better duty cycle and low jitter clock. + PINMUX_AUX(PINMUX_AUX_SDMMC1_CLK) |= PINMUX_SCHMT; + PINMUX_AUX(PINMUX_AUX_SDMMC1_CMD) |= PINMUX_SCHMT; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT3) |= PINMUX_SCHMT; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT2) |= PINMUX_SCHMT; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT1) |= PINMUX_SCHMT; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT0) |= PINMUX_SCHMT; + + max77620_regulator_set_voltage(REGULATOR_LDO2, 1800000); + PMC(APBDEV_PMC_PWR_DET_VAL) &= ~(1 << 12); + + _sdmmc_autocal_config_offset(sdmmc, SDMMC_POWER_1_8); + _sdmmc_autocal_execute(sdmmc, SDMMC_POWER_1_8); + _sdmmc_set_voltage(sdmmc, SDMMC_POWER_1_8); + _sdmmc_get_clkcon(sdmmc); + msleep(5); + + if (sdmmc->regs->hostctl2 & SDHCI_CTRL_VDD_180) + { + sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE; + _sdmmc_get_clkcon(sdmmc); + msleep(1); + if ((sdmmc->regs->prnsts & 0xF00000) == 0xF00000) + return 1; + } + + return 0; +} diff --git a/nyx/nyx_gui/storage/sdmmc_driver.h b/nyx/nyx_gui/storage/sdmmc_driver.h new file mode 100644 index 0000000..cf9b9e1 --- /dev/null +++ b/nyx/nyx_gui/storage/sdmmc_driver.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _SDMMC_DRIVER_H_ +#define _SDMMC_DRIVER_H_ + +#include "../utils/types.h" +#include "sdmmc_t210.h" + +/*! SDMMC controller IDs. */ +#define SDMMC_1 0 +#define SDMMC_2 1 +#define SDMMC_3 2 +#define SDMMC_4 3 + +/*! SDMMC power types. */ +#define SDMMC_POWER_OFF 0 +#define SDMMC_POWER_1_8 1 +#define SDMMC_POWER_3_3 2 + +/*! SDMMC bus widths. */ +#define SDMMC_BUS_WIDTH_1 0 +#define SDMMC_BUS_WIDTH_4 1 +#define SDMMC_BUS_WIDTH_8 2 + +/*! SDMMC response types. */ +#define SDMMC_RSP_TYPE_0 0 +#define SDMMC_RSP_TYPE_1 1 +#define SDMMC_RSP_TYPE_2 2 +#define SDMMC_RSP_TYPE_3 3 +#define SDMMC_RSP_TYPE_4 4 +#define SDMMC_RSP_TYPE_5 5 + +/*! SDMMC mask interrupt status. */ +#define SDMMC_MASKINT_MASKED 0 +#define SDMMC_MASKINT_NOERROR -1 +#define SDMMC_MASKINT_ERROR -2 + +/*! SDMMC host control 2 */ +#define SDHCI_CTRL_UHS_MASK 0xFFF8 +#define SDHCI_CTRL_VDD_330 0xFFF7 +#define SDHCI_CTRL_VDD_180 8 +#define SDHCI_CTRL_EXEC_TUNING 0x40 +#define SDHCI_CTRL_TUNED_CLK 0x80 +#define SDHCI_HOST_VERSION_4_EN 0x1000 +#define SDHCI_ADDRESSING_64BIT_EN 0x2000 +#define SDHCI_CTRL_PRESET_VAL_EN 0x8000 + +/*! SD bus speeds. */ +#define UHS_SDR12_BUS_SPEED 0 +#define HIGH_SPEED_BUS_SPEED 1 +#define UHS_SDR25_BUS_SPEED 1 +#define UHS_SDR50_BUS_SPEED 2 +#define UHS_SDR104_BUS_SPEED 3 +#define UHS_DDR50_BUS_SPEED 4 +#define HS400_BUS_SPEED 5 + +/*! Helper for SWITCH command argument. */ +#define SDMMC_SWITCH(mode, index, value) (((mode) << 24) | ((index) << 16) | ((value) << 8)) + +/*! SDMMC controller context. */ +typedef struct _sdmmc_t +{ + t210_sdmmc_t *regs; + u32 id; + u32 divisor; + u32 clock_stopped; + int no_sd; + int sd_clock_enabled; + int venclkctl_set; + u32 venclkctl_tap; + u32 expected_rsp_type; + u32 dma_addr_next; + u32 rsp[4]; + u32 rsp3; +} sdmmc_t; + +/*! SDMMC command. */ +typedef struct _sdmmc_cmd_t +{ + u16 cmd; + u32 arg; + u32 rsp_type; + u32 check_busy; +} sdmmc_cmd_t; + +/*! SDMMC request. */ +typedef struct _sdmmc_req_t +{ + void *buf; + u32 blksize; + u32 num_sectors; + int is_write; + int is_multi_block; + int is_auto_cmd12; +} sdmmc_req_t; + +int sdmmc_get_voltage(sdmmc_t *sdmmc); +u32 sdmmc_get_bus_width(sdmmc_t *sdmmc); +void sdmmc_set_bus_width(sdmmc_t *sdmmc, u32 bus_width); +void sdmmc_get_venclkctl(sdmmc_t *sdmmc); +int sdmmc_setup_clock(sdmmc_t *sdmmc, u32 type); +void sdmmc_sd_clock_ctrl(sdmmc_t *sdmmc, int no_sd); +int sdmmc_get_rsp(sdmmc_t *sdmmc, u32 *rsp, u32 size, u32 type); +int sdmmc_config_tuning(sdmmc_t *sdmmc, u32 type, u32 cmd); +int sdmmc_stop_transmission(sdmmc_t *sdmmc, u32 *rsp); +int sdmmc_init(sdmmc_t *sdmmc, u32 id, u32 power, u32 bus_width, u32 type, int no_sd); +void sdmmc_end(sdmmc_t *sdmmc); +void sdmmc_init_cmd(sdmmc_cmd_t *cmdbuf, u16 cmd, u32 arg, u32 rsp_type, u32 check_busy); +int sdmmc_execute_cmd(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *req, u32 *blkcnt_out); +int sdmmc_enable_low_voltage(sdmmc_t *sdmmc); + +#endif diff --git a/nyx/nyx_gui/storage/sdmmc_t210.h b/nyx/nyx_gui/storage/sdmmc_t210.h new file mode 100644 index 0000000..e11c3ff --- /dev/null +++ b/nyx/nyx_gui/storage/sdmmc_t210.h @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _SDMMC_T210_H_ +#define _SDMMC_T210_H_ + +#include "../utils/types.h" + +#define TEGRA_MMC_PWRCTL_SD_BUS_POWER 0x1 +#define TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V1_8 0xA +#define TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V3_0 0xC +#define TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_V3_3 0xE +#define TEGRA_MMC_PWRCTL_SD_BUS_VOLTAGE_MASK 0xF1 + +#define TEGRA_MMC_HOSTCTL_1BIT 0x00 +#define TEGRA_MMC_HOSTCTL_4BIT 0x02 +#define TEGRA_MMC_HOSTCTL_8BIT 0x20 + +#define TEGRA_MMC_CLKCON_INTERNAL_CLOCK_ENABLE 0x1 +#define TEGRA_MMC_CLKCON_INTERNAL_CLOCK_STABLE 0x2 +#define TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE 0x4 +#define TEGRA_MMC_CLKCON_CLKGEN_SELECT 0x20 + +#define TEGRA_MMC_SWRST_SW_RESET_FOR_ALL 0x1 +#define TEGRA_MMC_SWRST_SW_RESET_FOR_CMD_LINE 0x2 +#define TEGRA_MMC_SWRST_SW_RESET_FOR_DAT_LINE 0x4 + +#define TEGRA_MMC_TRNMOD_DMA_ENABLE 0x1 +#define TEGRA_MMC_TRNMOD_BLOCK_COUNT_ENABLE 0x2 +#define TEGRA_MMC_TRNMOD_AUTO_CMD12 0x4 +#define TEGRA_MMC_TRNMOD_DATA_XFER_DIR_SEL_WRITE 0x0 +#define TEGRA_MMC_TRNMOD_DATA_XFER_DIR_SEL_READ 0x10 +#define TEGRA_MMC_TRNMOD_MULTI_BLOCK_SELECT 0x20 + +#define TEGRA_MMC_TRNMOD_CMD_CRC_CHECK 0x8 +#define TEGRA_MMC_TRNMOD_CMD_INDEX_CHECK 0x10 +#define TEGRA_MMC_TRNMOD_DATA_PRESENT_SELECT_DATA_TRANSFER 0x20 + +#define TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_MASK 0x3 +#define TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_NO_RESPONSE 0x0 +#define TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_136 0x1 +#define TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48 0x2 +#define TEGRA_MMC_CMDREG_RESP_TYPE_SELECT_LENGTH_48_BUSY 0x3 + +#define TEGRA_MMC_NORINTSTS_CMD_COMPLETE 0x1 +#define TEGRA_MMC_NORINTSTS_XFER_COMPLETE 0x2 +#define TEGRA_MMC_NORINTSTS_DMA_INTERRUPT 0x8 +#define TEGRA_MMC_NORINTSTS_ERR_INTERRUPT 0x8000 +#define TEGRA_MMC_NORINTSTS_CMD_TIMEOUT 0x10000 + +#define TEGRA_MMC_NORINTSTSEN_BUFFER_READ_READY 0x20 + +typedef struct _t210_sdmmc_t +{ + vu32 sysad; + vu16 blksize; + vu16 blkcnt; + vu32 argument; + vu16 trnmod; + vu16 cmdreg; + vu32 rspreg0; + vu32 rspreg1; + vu32 rspreg2; + vu32 rspreg3; + vu32 bdata; + vu32 prnsts; + vu8 hostctl; + vu8 pwrcon; + vu8 blkgap; + vu8 wakcon; + vu16 clkcon; + vu8 timeoutcon; + vu8 swrst; + vu16 norintsts; + vu16 errintsts; + vu16 norintstsen; + vu16 errintstsen; + vu16 norintsigen; + vu16 errintsigen; + vu16 acmd12errsts; + vu16 hostctl2; + vu32 capareg; + vu32 capareg_1; + vu32 maxcurr; + vu8 res3[4]; + vu16 setacmd12err; + vu16 setinterr; + vu8 admaerr; + vu8 res4[3]; + vu32 admaaddr; + vu32 admaaddr_hi; + vu8 res5[156]; + vu16 slotintstatus; + vu16 hcver; + vu32 venclkctl; + vu32 venspictl; + vu32 venspiintsts; + vu32 venceatactl; + vu32 venbootctl; + vu32 venbootacktout; + vu32 venbootdattout; + vu32 vendebouncecnt; + vu32 venmiscctl; + vu32 res6[34]; + vu32 veniotrimctl; + vu32 vendllcal; + vu8 res7[8]; + vu32 dllcfgstatus; + vu32 ventunctl0; + vu32 field_1C4; + vu8 field_1C8[24]; + vu32 sdmemcmppadctl; + vu32 autocalcfg; + vu32 autocalintval; + vu32 autocalsts; + vu32 iospare; +} t210_sdmmc_t; + +#endif diff --git a/nyx/nyx_gui/thermal/fan.c b/nyx/nyx_gui/thermal/fan.c new file mode 100644 index 0000000..f7c967a --- /dev/null +++ b/nyx/nyx_gui/thermal/fan.c @@ -0,0 +1,101 @@ +/* + * Fan driver for Nintendo Switch + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "fan.h" +#include "../gfx/gfx.h" +#include "../soc/gpio.h" +#include "../soc/pinmux.h" +#include "../soc/t210.h" +#include "../utils/util.h" + +bool fan_init = false; + +void set_fan_duty(u32 duty) +{ + if (!fan_init) + { + // Fan power from internal 5V regulator (battery). + PINMUX_AUX(PINMUX_AUX_SATA_LED_ACTIVE) = 3; + gpio_config(GPIO_PORT_A, GPIO_PIN_5, GPIO_MODE_GPIO); + gpio_output_enable(GPIO_PORT_A, GPIO_PIN_5, GPIO_OUTPUT_ENABLE); + gpio_write(GPIO_PORT_A, GPIO_PIN_5, GPIO_HIGH); + + // Fan power from USB 5V vdd. + PINMUX_AUX(PINMUX_AUX_USB_VBUS_EN0) = 3; + gpio_config(GPIO_PORT_CC, GPIO_PIN_4, GPIO_MODE_GPIO); + gpio_output_enable(GPIO_PORT_CC, GPIO_PIN_4, GPIO_OUTPUT_ENABLE); + gpio_write(GPIO_PORT_CC, GPIO_PIN_4, GPIO_HIGH); + + // Fan tachometer. + PINMUX_AUX(PINMUX_AUX_CAM1_PWDN) = PINMUX_PULL_UP | PINMUX_TRISTATE | PINMUX_INPUT_ENABLE | 3; + gpio_output_enable(GPIO_PORT_S, GPIO_PIN_7, GPIO_OUTPUT_DISABLE); + gpio_config(GPIO_PORT_S, GPIO_PIN_7, GPIO_MODE_GPIO); + gpio_write(GPIO_PORT_S, GPIO_PIN_7, GPIO_LOW); + + PWM(PWM_CONTROLLER_PWM_CSR_1) = (1 << 31) | (255 << 16); // Max PWM to disable fan. + + PINMUX_AUX(PINMUX_AUX_LCD_GPIO2) = 1; // Set source to PWM1. + gpio_config(GPIO_PORT_V, GPIO_PIN_4, GPIO_MODE_SPIO); // Fan power mode. + + fan_init = true; + } + + if (duty > 236) + duty = 236; + + // Inverted polarity. + u32 inv_duty = 236 - duty; + if (inv_duty == 236) + inv_duty = 255; + + // Set PWM duty. + if (inv_duty) + PWM(PWM_CONTROLLER_PWM_CSR_1) = (1 << 31) | (inv_duty << 16); + else + PWM(PWM_CONTROLLER_PWM_CSR_1) = 0; +} + +void get_fan_speed(u32 *duty, u32 *rpm) +{ + if (rpm) + { + u32 irq_count = 0; + bool should_read = true; + bool irq_val = 0; + + // Poll irqs for 2 seconds. + int timer = get_tmr_us() + 1000000; + while (timer - get_tmr_us()) + { + irq_val = gpio_read(GPIO_PORT_S, GPIO_PIN_7); + if (irq_val && should_read) + { + irq_count++; + should_read = false; + } + else if (!irq_val) + should_read = true; + } + + // Calculate rpm based on triggered interrupts. + *rpm = 60000000 / ((1000000 * 2) / irq_count); + } + + if (duty) + *duty = 236 - ((PWM(PWM_CONTROLLER_PWM_CSR_1) >> 16) & 0xFF); +} diff --git a/nyx/nyx_gui/thermal/fan.h b/nyx/nyx_gui/thermal/fan.h new file mode 100644 index 0000000..d5b9946 --- /dev/null +++ b/nyx/nyx_gui/thermal/fan.h @@ -0,0 +1,29 @@ +/* + * Fan driver for Nintendo Switch + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __FAN_H_ +#define __FAN_H_ + +#include "../utils/types.h" + +// Disable: 0 (0 RPM), min duty: 1 (960 RPM), max duty 235 (11000 RPM). +void set_fan_duty(u32 duty); +// Passing NULL ptr on either of the two, disables parsing of it. +void get_fan_speed(u32 *duty, u32 *rpm); + +#endif /* __FAN_H_ */ diff --git a/nyx/nyx_gui/thermal/tmp451.c b/nyx/nyx_gui/thermal/tmp451.c new file mode 100644 index 0000000..b077a50 --- /dev/null +++ b/nyx/nyx_gui/thermal/tmp451.c @@ -0,0 +1,52 @@ +/* + * SOC/PCB Temperature driver for Nintendo Switch's TI TMP451 + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "tmp451.h" +#include "../soc/i2c.h" + +u16 tmp451_get_soc_temp(bool intenger) +{ + u8 val; + u16 temp = 0; + + val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TEMP_REG); + if (intenger) + return val; + + temp = val << 8; + val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_DEC_REG); + temp |= ((val >> 4) * 625) / 100; + + return temp; +} + +u16 tmp451_get_pcb_temp(bool intenger) +{ + u8 val; + u16 temp = 0; + + val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_PCB_TEMP_REG); + if (intenger) + return val; + + temp = val << 8; + val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_PCB_TMP_DEC_REG); + temp |= ((val >> 4) * 625) / 100; + + return temp; +} diff --git a/nyx/nyx_gui/thermal/tmp451.h b/nyx/nyx_gui/thermal/tmp451.h new file mode 100644 index 0000000..cd626ac --- /dev/null +++ b/nyx/nyx_gui/thermal/tmp451.h @@ -0,0 +1,37 @@ +/* + * SOC/PCB Temperature driver for Nintendo Switch's TI TMP451 + * + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __TMP451_H_ +#define __TMP451_H_ + +#include "../utils/types.h" + +#define TMP451_I2C_ADDR 0x4C + +#define TMP451_PCB_TEMP_REG 0x00 +#define TMP451_SOC_TEMP_REG 0x01 +#define TMP451_SOC_TMP_DEC_REG 0x10 +#define TMP451_PCB_TMP_DEC_REG 0x15 + +// If input is false, the return value is packed. MSByte is the integer in oC +// and the LSByte is the decimal point truncated to 2 decimal places. +// Otherwise it's an integer oC. +u16 tmp451_get_soc_temp(bool integer); +u16 tmp451_get_pcb_temp(bool integer); + +#endif /* __TMP451_H_ */ diff --git a/nyx/nyx_gui/utils/aarch64_util.h b/nyx/nyx_gui/utils/aarch64_util.h new file mode 100644 index 0000000..3fa0188 --- /dev/null +++ b/nyx/nyx_gui/utils/aarch64_util.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _ARM64_H_ +#define _ARM64_H_ + +#include "types.h" + +#define LSL0 0 +#define LSL16 16 +#define LSL32 32 + +#define _PAGEOFF(x) ((x) & 0xFFFFF000) + +#define _ADRP(r, o) 0x90000000 | ((((o) >> 12) & 0x3) << 29) | ((((o) >> 12) & 0x1FFFFC) << 3) | ((r) & 0x1F) +#define _BL(a, o) 0x94000000 | ((((o) - (a)) >> 2) & 0x3FFFFFF) +#define _B(a, o) 0x14000000 | ((((o) - (a)) >> 2) & 0x3FFFFFF) +#define _MOVKX(r, i, s) 0xF2800000 | (((s) & 0x30) << 17) | (((i) & 0xFFFF) << 5) | ((r) & 0x1F) +#define _MOVZX(r, i, s) 0xD2800000 | (((s) & 0x30) << 17) | (((i) & 0xFFFF) << 5) | ((r) & 0x1F) +#define _NOP() 0xD503201F + +#endif diff --git a/nyx/nyx_gui/utils/btn.c b/nyx/nyx_gui/utils/btn.c new file mode 100644 index 0000000..f0a8ffc --- /dev/null +++ b/nyx/nyx_gui/utils/btn.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "btn.h" +#include "../soc/i2c.h" +#include "../soc/gpio.h" +#include "../soc/t210.h" +#include "util.h" +#include "../power/max77620.h" + +u8 btn_read() +{ + u8 res = 0; + if (!gpio_read(GPIO_PORT_X, GPIO_PIN_7)) + res |= BTN_VOL_DOWN; + if (!gpio_read(GPIO_PORT_X, GPIO_PIN_6)) + res |= BTN_VOL_UP; + if (i2c_recv_byte(4, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFSTAT) & 0x4) + res |= BTN_POWER; + return res; +} + +u8 btn_wait() +{ + u8 res = 0, btn = btn_read(); + bool pwr = false; + + //Power button down, raise a filter. + if (btn & BTN_POWER) + { + pwr = true; + btn &= ~BTN_POWER; + } + + do + { + res = btn_read(); + //Power button up, remove filter. + if (!(res & BTN_POWER) && pwr) + pwr = false; + else if (pwr) //Power button still down. + res &= ~BTN_POWER; + } while (btn == res); + + return res; +} + +u8 btn_wait_timeout(u32 time_ms, u8 mask) +{ + u32 timeout = get_tmr_ms() + time_ms; + u8 res = btn_read() & mask; + + while (get_tmr_ms() < timeout) + { + if (res == mask) + break; + else + res = btn_read() & mask; + }; + + return res; +} diff --git a/nyx/nyx_gui/utils/btn.h b/nyx/nyx_gui/utils/btn.h new file mode 100644 index 0000000..ede13ac --- /dev/null +++ b/nyx/nyx_gui/utils/btn.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _BTN_H_ +#define _BTN_H_ + +#include "types.h" + +#define BTN_POWER (1 << 0) +#define BTN_VOL_DOWN (1 << 1) +#define BTN_VOL_UP (1 << 2) + +u8 btn_read(); +u8 btn_wait(); +u8 btn_wait_timeout(u32 time_ms, u8 mask); + +#endif diff --git a/nyx/nyx_gui/utils/dirlist.c b/nyx/nyx_gui/utils/dirlist.c new file mode 100644 index 0000000..6d443bf --- /dev/null +++ b/nyx/nyx_gui/utils/dirlist.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "../libs/fatfs/ff.h" +#include "../mem/heap.h" +#include "../utils/types.h" + +char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs) +{ + u8 max_entries = 61; + + int res = 0; + u32 i = 0, j = 0, k = 0; + DIR dir; + FILINFO fno; + + char *dir_entries = (char *)calloc(max_entries, 256); + char *temp = (char *)calloc(1, 256); + + if (!pattern && !f_opendir(&dir, directory)) + { + for (;;) + { + res = f_readdir(&dir, &fno); + if (res || !fno.fname[0]) + break; + + bool curr_parse = parse_dirs ? (fno.fattrib & AM_DIR) : !(fno.fattrib & AM_DIR); + + if (curr_parse) + { + if ((fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) + { + memcpy(dir_entries + (k * 256), fno.fname, strlen(fno.fname) + 1); + k++; + if (k > (max_entries - 1)) + break; + } + } + } + f_closedir(&dir); + } + else if (pattern && !f_findfirst(&dir, &fno, directory, pattern) && fno.fname[0]) + { + do + { + if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) + { + memcpy(dir_entries + (k * 256), fno.fname, strlen(fno.fname) + 1); + k++; + if (k > (max_entries - 1)) + break; + } + res = f_findnext(&dir, &fno); + } while (fno.fname[0] && !res); + f_closedir(&dir); + } + + if (!k) + { + free(temp); + free(dir_entries); + + return NULL; + } + + // Reorder ini files by ASCII ordering. + for (i = 0; i < k - 1 ; i++) + { + for (j = i + 1; j < k; j++) + { + if (strcmp(&dir_entries[i * 256], &dir_entries[j * 256]) > 0) + { + memcpy(temp, &dir_entries[i * 256], strlen(&dir_entries[i * 256]) + 1); + memcpy(&dir_entries[i * 256], &dir_entries[j * 256], strlen(&dir_entries[j * 256]) + 1); + memcpy(&dir_entries[j * 256], temp, strlen(temp) + 1); + } + } + } + + free(temp); + + return dir_entries; +} \ No newline at end of file diff --git a/nyx/nyx_gui/utils/dirlist.h b/nyx/nyx_gui/utils/dirlist.h new file mode 100644 index 0000000..9ad3c38 --- /dev/null +++ b/nyx/nyx_gui/utils/dirlist.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../utils/types.h" + +char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs); diff --git a/nyx/nyx_gui/utils/list.h b/nyx/nyx_gui/utils/list.h new file mode 100644 index 0000000..7d43e36 --- /dev/null +++ b/nyx/nyx_gui/utils/list.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2018 naehrwert + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _LIST_H_ +#define _LIST_H_ + +#include "types.h" + +/*! Initialize list. */ +#define LIST_INIT(name) link_t name = {&name, &name} + +/*! Initialize static list. */ +#define LIST_INIT_STATIC(name) static link_t name = {&name, &name} + +/*! Iterate over all list links. */ +#define LIST_FOREACH(iter, list) \ + for(link_t *iter = (list)->next; iter != (list); iter = iter->next) + +/*! Safely iterate over all list links. */ +#define LIST_FOREACH_SAFE(iter, list) \ + for(link_t *iter = (list)->next, *safe = iter->next; iter != (list); iter = safe, safe = iter->next) + +/*! Iterate over all list members. */ +#define LIST_FOREACH_ENTRY(etype, iter, list, mn) \ + for(etype *iter = CONTAINER_OF((list)->next, etype, mn); &iter->mn != (list); iter = CONTAINER_OF(iter->mn.next, etype, mn)) + +typedef struct _link_t +{ + struct _link_t *prev; + struct _link_t *next; +} link_t; + +static inline void link_init(link_t *l) +{ + l->prev = NULL; + l->next = NULL; +} + +static inline int link_used(link_t *l) +{ + if(l->next == NULL) + return 1; + return 0; +} + +static inline void list_init(link_t *lh) +{ + lh->prev = lh; + lh->next = lh; +} + +static inline void list_prepend(link_t *lh, link_t *l) +{ + l->next = lh->next; + l->prev = lh; + lh->next->prev = l; + lh->next = l; +} + +static inline void list_append(link_t *lh, link_t *l) +{ + l->prev = lh->prev; + l->next = lh; + lh->prev->next = l; + lh->prev = l; +} + +static inline void list_remove(link_t *l) +{ + l->next->prev = l->prev; + l->prev->next = l->next; + link_init(l); +} + +static inline int list_empty(link_t *lh) +{ + if(lh->next == lh) + return 1; + return 0; +} + +#endif diff --git a/nyx/nyx_gui/utils/sprintf.c b/nyx/nyx_gui/utils/sprintf.c new file mode 100644 index 0000000..ba42a66 --- /dev/null +++ b/nyx/nyx_gui/utils/sprintf.c @@ -0,0 +1,149 @@ +/* +* Copyright (c) 2018 naehrwert +* Copyright (c) 2019 CTCaer +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#include +#include + +#include "types.h" + +char **sout_buf; + +static void _s_putc(char c) +{ + **sout_buf = c; + *sout_buf += 1; +} + +static void _s_puts(const char *s) +{ + for (; *s; s++) + _s_putc(*s); +} + +static void _s_putn(u32 v, int base, char fill, int fcnt) +{ + char buf[65]; + static const char digits[] = "0123456789ABCDEFghijklmnopqrstuvwxyz"; + char *p; + int c = fcnt; + + if (base > 36) + return; + + p = buf + 64; + *p = 0; + do + { + c--; + *--p = digits[v % base]; + v /= base; + } while (v); + + if (fill != 0) + { + while (c > 0) + { + *--p = fill; + c--; + } + } + + _s_puts(p); +} + +static void _s_putp(u32 *v, int base, char fill, int fcnt) +{ + _s_putn(*v, base, fill, fcnt); +} + +void s_printf(char *out_buf, const char *fmt, ...) +{ + va_list ap; + int fill, fcnt; + + sout_buf = &out_buf; + + va_start(ap, fmt); + while(*fmt) + { + if(*fmt == '%') + { + fmt++; + fill = 0; + fcnt = 0; + if ((*fmt >= '0' && *fmt <= '9') || *fmt == ' ') + { + fcnt = *fmt; + fmt++; + if (*fmt >= '0' && *fmt <= '9') + { + fill = fcnt; + fcnt = *fmt - '0'; + fmt++; + } + else + { + fill = ' '; + fcnt -= '0'; + } + } + switch(*fmt) + { + case 'c': + _s_putc(va_arg(ap, u32)); + break; + case 's': + _s_puts(va_arg(ap, char *)); + break; + case 'd': + _s_putn(va_arg(ap, u32), 10, fill, fcnt); + break; + case 'p': + case 'P': + _s_putp(va_arg(ap, u32*), 16, fill, fcnt); + break; + case 'x': + case 'X': + _s_putn(va_arg(ap, u32), 16, fill, fcnt); + break; + case 'k': + //gfx_con.fgcol = va_arg(ap, u32); + break; + case 'K': + //gfx_con.bgcol = va_arg(ap, u32); + //gfx_con.fillbg = 1; + break; + case '%': + _s_putc('%'); + break; + case '\0': + goto out; + default: + _s_putc('%'); + _s_putc(*fmt); + break; + } + } + else + _s_putc(*fmt); + fmt++; + } + +out: + **sout_buf = '\0'; + va_end(ap); +} \ No newline at end of file diff --git a/nyx/nyx_gui/utils/sprintf.h b/nyx/nyx_gui/utils/sprintf.h new file mode 100644 index 0000000..96aeea8 --- /dev/null +++ b/nyx/nyx_gui/utils/sprintf.h @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2019 CTCaer +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef _SPRINTF_H_ +#define _SPRINTF_H_ + +#include "types.h" + +void s_printf(char *out_buf, const char *fmt, ...); + +#endif \ No newline at end of file diff --git a/nyx/nyx_gui/utils/types.h b/nyx/nyx_gui/utils/types.h new file mode 100644 index 0000000..bbddae0 --- /dev/null +++ b/nyx/nyx_gui/utils/types.h @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2018 naehrwert +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef _TYPES_H_ +#define _TYPES_H_ + +#define NULL ((void *)0) + +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +#define OFFSET_OF(t, m) ((u32)&((t *)NULL)->m) +#define CONTAINER_OF(mp, t, mn) ((t *)((u32)mp - OFFSET_OF(t, mn))) + +typedef signed char s8; +typedef short s16; +typedef short SHORT; +typedef int s32; +typedef int INT; +typedef long LONG; +typedef long long int s64; +typedef unsigned char u8; +typedef unsigned char BYTE; +typedef unsigned short u16; +typedef unsigned short WORD; +typedef unsigned short WCHAR; +typedef unsigned int u32; +typedef unsigned int UINT; +typedef unsigned long DWORD; +typedef unsigned long long QWORD; +typedef unsigned long long int u64; +typedef volatile unsigned char vu8; +typedef volatile unsigned short vu16; +typedef volatile unsigned int vu32; + +typedef int bool; +#define true 1 +#define false 0 + +#define BOOT_CFG_AUTOBOOT_EN (1 << 0) +#define BOOT_CFG_FROM_LAUNCH (1 << 1) +#define BOOT_CFG_SEPT_RUN (1 << 7) + +#define EXTRA_CFG_KEYS (1 << 0) +#define EXTRA_CFG_PAYLOAD (1 << 1) +#define EXTRA_CFG_MODULE (1 << 2) + +#define EXTRA_CFG_NYX_RELOAD (1 << 6) +#define EXTRA_CFG_NYX_DUMP (1 << 7) + +typedef struct __attribute__((__packed__)) _boot_cfg_t +{ + u8 boot_cfg; + u8 autoboot; + u8 autoboot_list; + u8 extra_cfg; + u8 rsvd[128]; +} boot_cfg_t; + +typedef struct __attribute__((__packed__)) _ipl_ver_meta_t +{ + u32 magic; + u32 version; + u16 rsvd0; + u16 rsvd1; +} ipl_ver_meta_t; + +typedef struct __attribute__((__packed__)) _reloc_meta_t +{ + u32 start; + u32 stack; + u32 end; + u32 ep; +} reloc_meta_t; + +#endif diff --git a/nyx/nyx_gui/utils/util.c b/nyx/nyx_gui/utils/util.c new file mode 100644 index 0000000..fc13566 --- /dev/null +++ b/nyx/nyx_gui/utils/util.c @@ -0,0 +1,109 @@ +/* +* Copyright (c) 2018 naehrwert +* Copyright (C) 2018 CTCaer +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#include "util.h" +#include "../gfx/di.h" +#include "../power/max77620.h" +#include "../soc/bpmp.h" +#include "../soc/i2c.h" +#include "../soc/pmc.h" +#include "../soc/t210.h" + +extern void sd_unmount(bool deinit); + +u32 get_tmr_s() +{ + return RTC(APBDEV_RTC_SECONDS); +} + +u32 get_tmr_ms() +{ + // The registers must be read with the following order: + // RTC_MILLI_SECONDS (0x10) -> RTC_SHADOW_SECONDS (0xC) + return (RTC(APBDEV_RTC_MILLI_SECONDS) | (RTC(APBDEV_RTC_SHADOW_SECONDS) << 10)); +} + +u32 get_tmr_us() +{ + return TMR(TIMERUS_CNTR_1US); //TIMERUS_CNTR_1US +} + +void msleep(u32 milliseconds) +{ + u32 start = RTC(APBDEV_RTC_MILLI_SECONDS) | (RTC(APBDEV_RTC_SHADOW_SECONDS) << 10); + while (((RTC(APBDEV_RTC_MILLI_SECONDS) | (RTC(APBDEV_RTC_SHADOW_SECONDS) << 10)) - start) <= milliseconds) + ; +} + +void usleep(u32 microseconds) +{ + u32 start = TMR(TIMERUS_CNTR_1US); + // Casting to u32 is important! + while ((u32)(TMR(TIMERUS_CNTR_1US) - start) <= microseconds) + ; +} + +void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops) +{ + for(u32 i = 0; i < num_ops; i++) + base[ops[i].off] = ops[i].val; +} + +void panic(u32 val) +{ + // Set panic code. + PMC(APBDEV_PMC_SCRATCH200) = val; + //PMC(APBDEV_PMC_CRYPTO_OP) = PMC_CRYPTO_OP_SE_DISABLE; + TMR(TIMER_WDT4_UNLOCK_PATTERN) = TIMER_MAGIC_PTRN; + TMR(TIMER_TMR9_TMR_PTV) = TIMER_EN | TIMER_PER_EN; + TMR(TIMER_WDT4_CONFIG) = TIMER_SRC(9) | TIMER_PER(1) | TIMER_PMCRESET_EN; + TMR(TIMER_WDT4_COMMAND) = TIMER_START_CNT; + while (1) + ; +} + +void reboot_normal() +{ + bpmp_mmu_disable(); + + sd_unmount(true); + display_end(); + + panic(0x21); // Bypass fuse programming in package1. +} + +void reboot_rcm() +{ + bpmp_mmu_disable(); + + sd_unmount(true); + display_end(); + + PMC(APBDEV_PMC_SCRATCH0) = 2; // Reboot into rcm. + PMC(APBDEV_PMC_CNTRL) |= PMC_CNTRL_MAIN_RST; + + while (true) + usleep(1); +} + +void power_off() +{ + sd_unmount(true); + display_end(); + + i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF); +} diff --git a/nyx/nyx_gui/utils/util.h b/nyx/nyx_gui/utils/util.h new file mode 100644 index 0000000..ae736dd --- /dev/null +++ b/nyx/nyx_gui/utils/util.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018 naehrwert + * Copyright (C) 2018 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _UTIL_H_ +#define _UTIL_H_ + +#include "types.h" +#include "../mem/minerva.h" + +#define NYX_CFG_DUMP (1 << 7) +#define NYX_CFG_MINERVA (1 << 8) + +#define byte_swap_32(num) (((num >> 24) & 0xff) | ((num << 8) & 0xff0000) | \ + ((num >> 8 )& 0xff00) | ((num << 24) & 0xff000000)) + +typedef struct _cfg_op_t +{ + u32 off; + u32 val; +} cfg_op_t; + +typedef struct _nyx_storage_t +{ + u32 version; + u32 cfg; + u8 irama[0x8000]; + u8 hekate[0x30000]; + u8 rsvd[0x800000]; + mtc_config_t mtc_cfg; +} nyx_storage_t; + +u32 get_tmr_us(); +u32 get_tmr_ms(); +u32 get_tmr_s(); +void usleep(u32 ticks); +void msleep(u32 milliseconds); +void panic(u32 val); +void reboot_normal(); +void reboot_rcm(); +void power_off(); +void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops); + +#endif