├── .gitignore ├── LICENSE ├── Makefile ├── Versions.inc ├── bdk ├── bdk.h ├── display │ ├── di.c │ ├── di.h │ └── di.inl ├── exception_handlers.S ├── fatfs_cfg.h ├── fatfs_conf.h ├── gfx_utils.h ├── ianos │ ├── elfload │ │ ├── elf.h │ │ ├── elfarch.h │ │ ├── elfload.c │ │ ├── elfload.h │ │ ├── elfreloc_aarch64.c │ │ └── elfreloc_arm.c │ ├── ianos.c │ └── ianos.h ├── input │ ├── als.c │ ├── als.h │ ├── joycon.c │ ├── joycon.h │ ├── touch.c │ └── touch.h ├── libs │ ├── compr │ │ ├── blz.c │ │ ├── blz.h │ │ ├── lz.c │ │ ├── lz.h │ │ ├── lz4.c │ │ └── lz4.h │ ├── fatfs │ │ ├── diskio.h │ │ ├── ff.c │ │ ├── ff.h │ │ └── ffunicode.c │ ├── lv_conf.h │ └── lvgl │ │ ├── docs │ │ ├── CODE_OF_CONDUCT.md │ │ ├── CONTRIBUTING.md │ │ ├── astyle_c │ │ └── astyle_h │ │ ├── licence.txt │ │ ├── lv_core │ │ ├── lv_core.mk │ │ ├── lv_group.c │ │ ├── lv_group.h │ │ ├── lv_indev.c │ │ ├── lv_indev.h │ │ ├── lv_lang.c │ │ ├── lv_lang.h │ │ ├── lv_obj.c │ │ ├── lv_obj.h │ │ ├── lv_refr.c │ │ ├── lv_refr.h │ │ ├── lv_style.c │ │ ├── lv_style.h │ │ ├── lv_vdb.c │ │ └── lv_vdb.h │ │ ├── lv_draw │ │ ├── lv_draw.c │ │ ├── lv_draw.h │ │ ├── lv_draw.mk │ │ ├── lv_draw_arc.c │ │ ├── lv_draw_arc.h │ │ ├── lv_draw_img.c │ │ ├── lv_draw_img.h │ │ ├── lv_draw_label.c │ │ ├── lv_draw_label.h │ │ ├── lv_draw_line.c │ │ ├── lv_draw_line.h │ │ ├── lv_draw_rbasic.c │ │ ├── lv_draw_rbasic.h │ │ ├── lv_draw_rect.c │ │ ├── lv_draw_rect.h │ │ ├── lv_draw_triangle.c │ │ ├── lv_draw_triangle.h │ │ ├── lv_draw_vbasic.c │ │ └── lv_draw_vbasic.h │ │ ├── lv_fonts │ │ ├── hekate_symbol_120.c │ │ ├── hekate_symbol_20.c │ │ ├── hekate_symbol_30.c │ │ ├── interui_20.c │ │ ├── interui_30.c │ │ ├── lv_font_builtin.c │ │ ├── lv_font_builtin.h │ │ ├── lv_fonts.mk │ │ └── ubuntu_mono.c │ │ ├── lv_hal │ │ ├── lv_hal.h │ │ ├── lv_hal.mk │ │ ├── lv_hal_disp.c │ │ ├── lv_hal_disp.h │ │ ├── lv_hal_indev.c │ │ ├── lv_hal_indev.h │ │ ├── lv_hal_tick.c │ │ └── lv_hal_tick.h │ │ ├── lv_misc │ │ ├── lv_anim.c │ │ ├── lv_anim.h │ │ ├── lv_area.c │ │ ├── lv_area.h │ │ ├── lv_circ.c │ │ ├── lv_circ.h │ │ ├── lv_color.c │ │ ├── lv_color.h │ │ ├── lv_font.c │ │ ├── lv_font.h │ │ ├── lv_fs.c │ │ ├── lv_fs.h │ │ ├── lv_gc.c │ │ ├── lv_gc.h │ │ ├── lv_ll.c │ │ ├── lv_ll.h │ │ ├── lv_log.c │ │ ├── lv_log.h │ │ ├── lv_math.c │ │ ├── lv_math.h │ │ ├── lv_mem.c │ │ ├── lv_mem.h │ │ ├── lv_misc.mk │ │ ├── lv_symbol_def.h │ │ ├── lv_task.c │ │ ├── lv_task.h │ │ ├── lv_templ.c │ │ ├── lv_templ.h │ │ ├── lv_txt.c │ │ ├── lv_txt.h │ │ ├── lv_ufs.c │ │ └── lv_ufs.h │ │ ├── lv_objx │ │ ├── lv_arc.c │ │ ├── lv_arc.h │ │ ├── lv_bar.c │ │ ├── lv_bar.h │ │ ├── lv_btn.c │ │ ├── lv_btn.h │ │ ├── lv_btnm.c │ │ ├── lv_btnm.h │ │ ├── lv_calendar.c │ │ ├── lv_calendar.h │ │ ├── lv_canvas.c │ │ ├── lv_canvas.h │ │ ├── lv_cb.c │ │ ├── lv_cb.h │ │ ├── lv_chart.c │ │ ├── lv_chart.h │ │ ├── lv_cont.c │ │ ├── lv_cont.h │ │ ├── lv_ddlist.c │ │ ├── lv_ddlist.h │ │ ├── lv_gauge.c │ │ ├── lv_gauge.h │ │ ├── lv_img.c │ │ ├── lv_img.h │ │ ├── lv_imgbtn.c │ │ ├── lv_imgbtn.h │ │ ├── lv_kb.c │ │ ├── lv_kb.h │ │ ├── lv_label.c │ │ ├── lv_label.h │ │ ├── lv_led.c │ │ ├── lv_led.h │ │ ├── lv_line.c │ │ ├── lv_line.h │ │ ├── lv_list.c │ │ ├── lv_list.h │ │ ├── lv_lmeter.c │ │ ├── lv_lmeter.h │ │ ├── lv_mbox.c │ │ ├── lv_mbox.h │ │ ├── lv_objx.mk │ │ ├── lv_objx_templ.c │ │ ├── lv_objx_templ.h │ │ ├── lv_page.c │ │ ├── lv_page.h │ │ ├── lv_preload.c │ │ ├── lv_preload.h │ │ ├── lv_roller.c │ │ ├── lv_roller.h │ │ ├── lv_slider.c │ │ ├── lv_slider.h │ │ ├── lv_spinbox.c │ │ ├── lv_spinbox.h │ │ ├── lv_sw.c │ │ ├── lv_sw.h │ │ ├── lv_ta.c │ │ ├── lv_ta.h │ │ ├── lv_table.c │ │ ├── lv_table.h │ │ ├── lv_tabview.c │ │ ├── lv_tabview.h │ │ ├── lv_tileview.c │ │ ├── lv_tileview.h │ │ ├── lv_win.c │ │ └── lv_win.h │ │ ├── lv_themes │ │ ├── lv_theme.c │ │ ├── lv_theme.h │ │ ├── lv_theme_hekate.c │ │ ├── lv_theme_hekate.h │ │ └── lv_themes.mk │ │ ├── lv_version.h │ │ ├── lvgl.h │ │ └── lvgl.mk ├── mem │ ├── emc.h │ ├── heap.c │ ├── heap.h │ ├── mc.c │ ├── mc.h │ ├── mc_t210.h │ ├── minerva.c │ ├── minerva.h │ ├── mtc_table.h │ ├── sdram.c │ ├── sdram.h │ ├── sdram_config.inl │ ├── sdram_config_t210b01.inl │ ├── sdram_lp0.c │ ├── sdram_lp0_param_t210.h │ ├── sdram_lp0_param_t210b01.h │ ├── sdram_param_t210.h │ ├── sdram_param_t210b01.h │ ├── smmu.c │ └── smmu.h ├── memory_map.h ├── module.h ├── power │ ├── bm92t36.c │ ├── bm92t36.h │ ├── bq24193.c │ ├── bq24193.h │ ├── max17050.c │ ├── max17050.h │ ├── max77620.h │ ├── max7762x.c │ ├── max7762x.h │ ├── max77812.h │ ├── regulator_5v.c │ └── regulator_5v.h ├── rtc │ ├── max77620-rtc.c │ └── max77620-rtc.h ├── sec │ ├── se.c │ ├── se.h │ ├── se_t210.h │ ├── tsec.c │ ├── tsec.h │ └── tsec_t210.h ├── soc │ ├── actmon.c │ ├── actmon.h │ ├── bpmp.c │ ├── bpmp.h │ ├── ccplex.c │ ├── ccplex.h │ ├── clock.c │ ├── clock.h │ ├── fuse.c │ ├── fuse.h │ ├── gpio.c │ ├── gpio.h │ ├── hw_init.c │ ├── hw_init.h │ ├── i2c.c │ ├── i2c.h │ ├── irq.c │ ├── irq.h │ ├── kfuse.c │ ├── kfuse.h │ ├── pinmux.c │ ├── pinmux.h │ ├── pmc.c │ ├── pmc.h │ ├── pmc_lp0_t210.h │ ├── t210.h │ ├── uart.c │ └── uart.h ├── storage │ ├── emmc.c │ ├── emmc.h │ ├── mbr_gpt.h │ ├── mmc.h │ ├── nx_emmc_bis.c │ ├── nx_emmc_bis.h │ ├── ramdisk.c │ ├── ramdisk.h │ ├── sd.c │ ├── sd.h │ ├── sd_def.h │ ├── sdmmc.c │ ├── sdmmc.h │ ├── sdmmc_driver.c │ ├── sdmmc_driver.h │ └── sdmmc_t210.h ├── thermal │ ├── fan.c │ ├── fan.h │ ├── tmp451.c │ └── tmp451.h ├── usb │ ├── usb_descriptor_types.h │ ├── usb_descriptors.c │ ├── usb_gadget_hid.c │ ├── usb_gadget_ums.c │ ├── usb_t210.h │ ├── usbd.c │ ├── usbd.h │ └── xusbd.c └── utils │ ├── aarch64_util.h │ ├── btn.c │ ├── btn.h │ ├── dirlist.c │ ├── dirlist.h │ ├── ini.c │ ├── ini.h │ ├── list.h │ ├── sprintf.c │ ├── sprintf.h │ ├── types.h │ ├── util.c │ └── util.h └── toolbox ├── config.c ├── config.h ├── gfx ├── gfx.c ├── gfx.h ├── tui.c └── tui.h ├── hwfly.c ├── hwfly.h ├── libs └── fatfs │ ├── diskio.c │ ├── ffconf.h │ └── ffsystem.c ├── link.ld ├── main.c └── start.S /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | .vscode 3 | build/* 4 | output/* 5 | loader/payload_00.h 6 | loader/payload_01.h 7 | tools/bin2c/bin2c 8 | tools/lz/lz77 9 | -------------------------------------------------------------------------------- /Versions.inc: -------------------------------------------------------------------------------- 1 | # IPL Version. 2 | BLVERSION_MAJOR := 1 3 | BLVERSION_MINOR := 1 4 | BLVERSION_HOTFX := 1 5 | BLVERSION_RSVD := 0 6 | -------------------------------------------------------------------------------- /bdk/bdk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef BDK_H 18 | #define BDK_H 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | 75 | #include 76 | 77 | #endif -------------------------------------------------------------------------------- /bdk/fatfs_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _FATFS_CFG_H_ 18 | #define _FATFS_CFG_H_ 19 | 20 | // define FFCFG_INC in a project to use a specific FatFS configuration. 21 | // Example: FFCFG_INC := '"../$(PROJECT_DIR)/libs/fatfs/ffconf.h"' 22 | #ifdef FFCFG_INC 23 | #include FFCFG_INC 24 | #else 25 | #include "fatfs_conf.h" 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /bdk/gfx_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _GFX_UTILS_H_ 18 | #define _GFX_UTILS_H_ 19 | 20 | #ifdef GFX_INC 21 | #include GFX_INC 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /bdk/ianos/elfload/elfarch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014, Owen Shepherd 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef ELFARCH_H 18 | #define ELFARCH_H 19 | 20 | #if defined(__i386__) 21 | #define EM_THIS EM_386 22 | #define EL_ARCH_USES_REL 23 | #elif defined(__amd64__) 24 | #define EM_THIS EM_AMD64 25 | #define EL_ARCH_USES_RELA 26 | #elif defined(__arm__) 27 | #define EM_THIS EM_ARM 28 | #define EL_ARCH_USES_REL 29 | #elif defined(__aarch64__) 30 | #define EM_THIS EM_AARCH64 31 | #define EL_ARCH_USES_RELA 32 | #define EL_ARCH_USES_REL 33 | #else 34 | #error specify your ELF architecture 35 | #endif 36 | 37 | #if defined(__LP64__) || defined(__LLP64__) 38 | #define ELFSIZE 64 39 | #else 40 | #define ELFSIZE 32 41 | #endif 42 | 43 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 44 | #define ELFDATATHIS ELFDATA2LSB 45 | #else 46 | #define ELFDATATHIS ELFDATA2MSB 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /bdk/ianos/elfload/elfload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018, M4xw 3 | * Copyright © 2014, Owen Shepherd 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 14 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef ELFLOAD_H 19 | #define ELFLOAD_H 20 | #include 21 | 22 | #include "elfarch.h" 23 | #include "elf.h" 24 | 25 | #ifdef DEBUG 26 | #include 27 | #define EL_DEBUG(format, ...) \ 28 | gfx_printf(format __VA_OPT__(, ) __VA_ARGS__) 29 | #else 30 | #define EL_DEBUG(...) \ 31 | do \ 32 | { \ 33 | } while (0) 34 | #endif 35 | 36 | typedef enum 37 | { 38 | EL_OK = 0, 39 | 40 | EL_EIO, 41 | EL_ENOMEM, 42 | 43 | EL_NOTELF, 44 | EL_WRONGBITS, 45 | EL_WRONGENDIAN, 46 | EL_WRONGARCH, 47 | EL_WRONGOS, 48 | EL_NOTEXEC, 49 | EL_NODYN, 50 | EL_BADREL, 51 | 52 | } el_status; 53 | 54 | typedef struct el_ctx 55 | { 56 | bool (*pread)(struct el_ctx *ctx, void *dest, size_t nb, size_t offset); 57 | 58 | /* base_load_* -> address we are actually going to load at 59 | */ 60 | Elf_Addr 61 | base_load_paddr, 62 | base_load_vaddr; 63 | 64 | /* size in memory of binary */ 65 | Elf_Addr memsz; 66 | 67 | /* required alignment */ 68 | Elf_Addr align; 69 | 70 | /* ELF header */ 71 | Elf_Ehdr ehdr; 72 | 73 | // Section Header Str Table 74 | Elf_Shdr shstr; 75 | Elf_Shdr symtab; 76 | 77 | /* Offset of dynamic table (0 if not ET_DYN) */ 78 | Elf_Off dynoff; 79 | /* Size of dynamic table (0 if not ET_DYN) */ 80 | Elf_Addr dynsize; 81 | } el_ctx; 82 | 83 | el_status el_pread(el_ctx *ctx, void *def, size_t nb, size_t offset); 84 | 85 | el_status el_init(el_ctx *ctx); 86 | typedef void *(*el_alloc_cb)( 87 | el_ctx *ctx, 88 | Elf_Addr phys, 89 | Elf_Addr virt, 90 | Elf_Addr size); 91 | 92 | el_status el_load(el_ctx *ctx, el_alloc_cb alloccb); 93 | 94 | /* find the next phdr of type \p type, starting at \p *i. 95 | * On success, returns EL_OK with *i set to the phdr number, and the phdr loaded 96 | * in *phdr. 97 | * 98 | * If the end of the phdrs table was reached, *i is set to -1 and the contents 99 | * of *phdr are undefined 100 | */ 101 | el_status el_findphdr(el_ctx *ctx, Elf_Phdr *phdr, u32 type, unsigned *i); 102 | 103 | /* Relocate the loaded executable */ 104 | el_status el_relocate(el_ctx *ctx); 105 | 106 | /* find a dynamic table entry 107 | * returns the entry on success, dyn->d_tag = DT_NULL on failure 108 | */ 109 | el_status el_finddyn(el_ctx *ctx, Elf_Dyn *dyn, u32 type); 110 | 111 | typedef struct 112 | { 113 | Elf_Off tableoff; 114 | Elf_Addr tablesize; 115 | Elf_Addr entrysize; 116 | } el_relocinfo; 117 | 118 | /* find all information regarding relocations of a specific type. 119 | * 120 | * pass DT_REL or DT_RELA for type 121 | * sets ri->entrysize = 0 if not found 122 | */ 123 | el_status el_findrelocs(el_ctx *ctx, el_relocinfo *ri, u32 type); 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /bdk/ianos/elfload/elfreloc_aarch64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014, Owen Shepherd 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "elfload.h" 18 | 19 | #if defined(__aarch64__) 20 | 21 | #define R_AARCH64_NONE 0 22 | #define R_AARCH64_RELATIVE 1027 23 | 24 | el_status el_applyrela(el_ctx *ctx, Elf_RelA *rel) 25 | { 26 | uptr *p = (uptr *)(rel->r_offset + ctx->base_load_paddr); 27 | u32 type = ELF_R_TYPE(rel->r_info); 28 | u32 sym = ELF_R_SYM(rel->r_info); 29 | 30 | switch (type) 31 | { 32 | case R_AARCH64_NONE: 33 | EL_DEBUG("R_AARCH64_NONE\n"); 34 | break; 35 | case R_AARCH64_RELATIVE: 36 | if (sym) 37 | { 38 | EL_DEBUG("R_AARCH64_RELATIVE with symbol ref!\n"); 39 | return EL_BADREL; 40 | } 41 | 42 | EL_DEBUG("Applying R_AARCH64_RELATIVE reloc @%p\n", p); 43 | *p = rel->r_addend + ctx->base_load_vaddr; 44 | break; 45 | 46 | default: 47 | EL_DEBUG("Bad relocation %u\n", type); 48 | return EL_BADREL; 49 | } 50 | 51 | return EL_OK; 52 | } 53 | 54 | el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel) 55 | { 56 | uptr *p = (uptr *)(rel->r_offset + ctx->base_load_paddr); 57 | u32 type = ELF_R_TYPE(rel->r_info); 58 | u32 sym = ELF_R_SYM(rel->r_info); 59 | 60 | switch (type) 61 | { 62 | case R_AARCH64_NONE: 63 | EL_DEBUG("R_AARCH64_NONE\n"); 64 | break; 65 | case R_AARCH64_RELATIVE: 66 | if (sym) 67 | { 68 | EL_DEBUG("R_AARCH64_RELATIVE with symbol ref!\n"); 69 | return EL_BADREL; 70 | } 71 | 72 | EL_DEBUG("Applying R_AARCH64_RELATIVE reloc @%p\n", p); 73 | *p += ctx->base_load_vaddr; 74 | break; 75 | 76 | default: 77 | EL_DEBUG("Bad relocation %u\n", type); 78 | return EL_BADREL; 79 | } 80 | 81 | return EL_OK; 82 | } 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /bdk/ianos/elfload/elfreloc_arm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * wrote this file. As long as you retain this notice you can do 5 | * whatever you want with this stuff. If we meet some day, and you think this 6 | * stuff is worth it, you can buy me a beer in return. M4xw 7 | * ---------------------------------------------------------------------------- 8 | */ 9 | 10 | #include "elfload.h" 11 | 12 | #if defined(__arm__) 13 | 14 | // Taken from http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf 15 | #define R_ARM_NONE 0 16 | #define R_ARM_ABS32 2 17 | #define R_ARM_JUMP_SLOT 22 18 | #define R_ARM_GLOB_DAT 21 19 | #define R_ARM_RELATIVE 23 20 | 21 | el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel) 22 | { 23 | u32 sym = ELF_R_SYM(rel->r_info); // Symbol offset 24 | u32 type = ELF_R_TYPE(rel->r_info); // Relocation Type 25 | uptr *p = (uptr *)(rel->r_offset + ctx->base_load_paddr); // Target Addr 26 | 27 | #if 0 // For later symbol usage 28 | Elf32_Sym *elfSym; 29 | const char *symbolName; 30 | 31 | // We resolve relocs from the originating elf-image 32 | elfSym = (Elf32_Sym *)(ctx->symtab.sh_offset + (char *)buffteg) + sym; 33 | int strtab_offset = ctx->shstr.sh_offset; 34 | char *strtab = (char *)buffteg + strtab_offset; 35 | symbolName = strtab + elfSym->st_name; 36 | //EL_DEBUG("Str: %s sz: %x val: %x\n", symbolName, elfSym->st_size, elfSym->st_value); 37 | #endif 38 | 39 | switch (type) 40 | { 41 | case R_ARM_NONE: 42 | EL_DEBUG("R_ARM_NONE\n"); 43 | break; 44 | case R_ARM_JUMP_SLOT: 45 | case R_ARM_ABS32: 46 | case R_ARM_GLOB_DAT: 47 | // Stubbed for later purpose 48 | //*p += elfSym->st_value; // + vaddr from sec 49 | //*p |= 0; // 1 if Thumb && STT_FUNC, ignored for now 50 | break; 51 | case R_ARM_RELATIVE: // Needed for PIE 52 | if (sym) 53 | { 54 | return EL_BADREL; 55 | } 56 | *p += ctx->base_load_vaddr; 57 | break; 58 | 59 | default: 60 | return EL_BADREL; 61 | } 62 | 63 | return EL_OK; 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /bdk/ianos/ianos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 M4xw 3 | * Copyright (c) 2018-2019 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | #include "ianos.h" 21 | #include "elfload/elfload.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #define IRAM_LIB_ADDR 0x4002B000 31 | #define DRAM_LIB_ADDR 0xE0000000 32 | 33 | extern heap_t _heap; 34 | 35 | void *elfBuf = NULL; 36 | void *fileBuf = NULL; 37 | 38 | static void _ianos_call_ep(moduleEntrypoint_t entrypoint, void *moduleConfig) 39 | { 40 | bdkParams_t bdkParameters = (bdkParams_t)malloc(sizeof(struct _bdkParams_t)); 41 | bdkParameters->gfxCon = (void *)&gfx_con; 42 | bdkParameters->gfxCtx = (void *)&gfx_ctxt; 43 | bdkParameters->memcpy = (memcpy_t)&memcpy; 44 | bdkParameters->memset = (memset_t)&memset; 45 | bdkParameters->sharedHeap = &_heap; 46 | 47 | // Extra functions. 48 | bdkParameters->extension_magic = IANOS_EXT0; 49 | bdkParameters->reg_voltage_set = (reg_voltage_set_t)&max7762x_regulator_set_voltage; 50 | 51 | entrypoint(moduleConfig, bdkParameters); 52 | } 53 | 54 | static void *_ianos_alloc_cb(el_ctx *ctx, Elf_Addr phys, Elf_Addr virt, Elf_Addr size) 55 | { 56 | (void)ctx; 57 | (void)phys; 58 | (void)size; 59 | return (void *)virt; 60 | } 61 | 62 | static bool _ianos_read_cb(el_ctx *ctx, void *dest, size_t numberBytes, size_t offset) 63 | { 64 | (void)ctx; 65 | 66 | memcpy(dest, fileBuf + offset, numberBytes); 67 | 68 | return true; 69 | } 70 | 71 | //TODO: Support shared libraries. 72 | uintptr_t ianos_loader(char *path, elfType_t type, void *moduleConfig) 73 | { 74 | el_ctx ctx; 75 | uintptr_t epaddr = 0; 76 | 77 | if (!sd_mount()) 78 | goto elfLoadFinalOut; 79 | 80 | // Read library. 81 | fileBuf = sd_file_read(path, NULL); 82 | 83 | if (!fileBuf) 84 | goto elfLoadFinalOut; 85 | 86 | ctx.pread = _ianos_read_cb; 87 | 88 | if (el_init(&ctx)) 89 | goto elfLoadFinalOut; 90 | 91 | // Set our relocated library's buffer. 92 | switch (type & 0xFFFF) 93 | { 94 | case EXEC_ELF: 95 | case AR64_ELF: 96 | elfBuf = (void *)DRAM_LIB_ADDR; 97 | break; 98 | default: 99 | elfBuf = malloc(ctx.memsz); // Aligned to 0x10 by default. 100 | } 101 | 102 | if (!elfBuf) 103 | goto elfLoadFinalOut; 104 | 105 | // Load and relocate library. 106 | ctx.base_load_vaddr = ctx.base_load_paddr = (uintptr_t)elfBuf; 107 | if (el_load(&ctx, _ianos_alloc_cb)) 108 | goto elfFreeOut; 109 | 110 | if (el_relocate(&ctx)) 111 | goto elfFreeOut; 112 | 113 | // Launch. 114 | epaddr = ctx.ehdr.e_entry + (uintptr_t)elfBuf; 115 | moduleEntrypoint_t ep = (moduleEntrypoint_t)epaddr; 116 | 117 | _ianos_call_ep(ep, moduleConfig); 118 | 119 | elfFreeOut: 120 | free(fileBuf); 121 | elfBuf = NULL; 122 | fileBuf = NULL; 123 | 124 | elfLoadFinalOut: 125 | return epaddr; 126 | } -------------------------------------------------------------------------------- /bdk/ianos/ianos.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 M4xw 3 | * Copyright (c) 2018 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef IANOS_H 19 | #define IANOS_H 20 | 21 | #include 22 | 23 | typedef enum 24 | { 25 | DRAM_LIB = 0, // DRAM library. 26 | EXEC_ELF = 1, // Executable elf that does not return. 27 | DR64_LIB = 2, // AARCH64 DRAM library. 28 | AR64_ELF = 3, // Executable elf that does not return. 29 | KEEP_IN_RAM = (1 << 31) // Shared library mask. 30 | } elfType_t; 31 | 32 | uintptr_t ianos_loader(char *path, elfType_t type, void* config); 33 | 34 | #endif -------------------------------------------------------------------------------- /bdk/input/als.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ambient light sensor driver for Nintendo Switch's Rohm BH1730 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __ALS_H_ 20 | #define __ALS_H_ 21 | 22 | #include 23 | 24 | #define BH1730_I2C_ADDR 0x29 25 | 26 | #define BH1730_CMD_MAGIC 0x80 27 | #define BH1730_CMD_SETADDR 0x00 28 | #define BH1730_CMD_SPECCMD 0x60 29 | #define BH1730_SPECCMD_RESET 0x4 30 | 31 | #define BH1730_CONTROL_REG 0x00 32 | #define BH1730_CTL_ADC_VALID 0x10 33 | #define BH1730_CTL_ONE_TIME 0x08 34 | #define BH1730_CTL_DAT0_ONLY 0x04 35 | #define BH1730_CTL_ADC_EN 0x02 36 | #define BH1730_CTL_POWER_ON 0x01 37 | #define BH1730_TIMING_REG 0x01 38 | #define BH1730_GAIN_REG 0x07 39 | #define BH1730_GAIN_1X 0x00 40 | #define BH1730_GAIN_2X 0x01 41 | #define BH1730_GAIN_64X 0x02 42 | #define BH1730_GAIN_128X 0x03 43 | #define BH1730_DATA0LOW_REG 0x14 44 | #define BH1730_DATA0HIGH_REG 0x15 45 | #define BH1730_DATA1LOW_REG 0x16 46 | #define BH1730_DATA1HIGH_REG 0x17 47 | 48 | #define BH1730_ADDR(reg) (BH1730_CMD_MAGIC | BH1730_CMD_SETADDR | (reg)) 49 | #define BH1730_SPEC(cmd) (BH1730_CMD_MAGIC | BH1730_CMD_SPECCMD | (cmd)) 50 | 51 | typedef struct _als_ctxt_t 52 | { 53 | u32 lux; 54 | bool over_limit; 55 | u32 vi_light; 56 | u32 ir_light; 57 | u8 gain; 58 | u8 cycle; 59 | } als_ctxt_t; 60 | 61 | void set_als_cfg(als_ctxt_t *als_ctxt, u8 gain, u8 cycle); 62 | void get_als_lux(als_ctxt_t *als_ctxt); 63 | u8 als_power_on(als_ctxt_t *als_ctxt); 64 | 65 | #endif /* __ALS_H_ */ 66 | -------------------------------------------------------------------------------- /bdk/input/joycon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ambient light sensor driver for Nintendo Switch's Rohm BH1730 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __JOYCON_H_ 20 | #define __JOYCON_H_ 21 | 22 | #include 23 | 24 | #define JC_BTNS_DIRECTION_PAD 0xF0000 25 | #define JC_BTNS_PREV_NEXT 0x800080 26 | #define JC_BTNS_ENTER 0x400008 27 | #define JC_BTNS_ESC 0x4 28 | 29 | #define JC_BTNS_ALL (JC_BTNS_PREV_NEXT | JC_BTNS_ENTER | JC_BTNS_DIRECTION_PAD | JC_BTNS_ESC) 30 | 31 | typedef struct _jc_bt_conn_t 32 | { 33 | u8 type; 34 | u8 mac[6]; 35 | u8 host_mac[6]; 36 | u8 ltk[16]; 37 | } jc_bt_conn_t; 38 | 39 | typedef struct _jc_gamepad_rpt_t 40 | { 41 | union 42 | { 43 | struct 44 | { 45 | // Joy-Con (R). 46 | u32 y:1; 47 | u32 x:1; 48 | u32 b:1; 49 | u32 a:1; 50 | u32 sr_r:1; 51 | u32 sl_r:1; 52 | u32 r:1; 53 | u32 zr:1; 54 | 55 | // Shared 56 | u32 minus:1; 57 | u32 plus:1; 58 | u32 r3:1; 59 | u32 l3:1; 60 | u32 home:1; 61 | u32 cap:1; 62 | u32 pad:1; 63 | u32 wired:1; 64 | 65 | // Joy-Con (L). 66 | u32 down:1; 67 | u32 up:1; 68 | u32 right:1; 69 | u32 left:1; 70 | u32 sr_l:1; 71 | u32 sl_l:1; 72 | u32 l:1; 73 | u32 zl:1; 74 | }; 75 | u32 buttons; 76 | }; 77 | 78 | u16 lstick_x; 79 | u16 lstick_y; 80 | u16 rstick_x; 81 | u16 rstick_y; 82 | bool center_stick_l; 83 | bool center_stick_r; 84 | bool conn_l; 85 | bool conn_r; 86 | u8 batt_info_l; 87 | u8 batt_info_r; 88 | jc_bt_conn_t bt_conn_l; 89 | jc_bt_conn_t bt_conn_r; 90 | } jc_gamepad_rpt_t; 91 | 92 | void jc_power_supply(u8 uart, bool enable); 93 | void jc_init_hw(); 94 | void jc_deinit(); 95 | jc_gamepad_rpt_t *joycon_poll(); 96 | jc_gamepad_rpt_t *jc_get_bt_pairing_info(bool *is_l_hos, bool *is_r_hos); 97 | 98 | #endif -------------------------------------------------------------------------------- /bdk/libs/compr/blz.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 rajkosto 3 | * Copyright (c) 2018 SciresM 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include "blz.h" 22 | 23 | const blz_footer *blz_get_footer(const unsigned char *compData, unsigned int compDataLen, blz_footer *outFooter) 24 | { 25 | if (compDataLen < sizeof(blz_footer)) 26 | return NULL; 27 | 28 | const blz_footer *srcFooter = (const blz_footer*)&compData[compDataLen - sizeof(blz_footer)]; 29 | if (outFooter != NULL) 30 | memcpy(outFooter, srcFooter, sizeof(blz_footer)); // Must be a memcpy because no umaligned accesses on ARMv4. 31 | 32 | return srcFooter; 33 | } 34 | 35 | // From https://github.com/SciresM/hactool/blob/master/kip.c which is exactly how kernel does it, thanks SciresM! 36 | int blz_uncompress_inplace(unsigned char *dataBuf, unsigned int compSize, const blz_footer *footer) 37 | { 38 | u32 addl_size = footer->addl_size; 39 | u32 header_size = footer->header_size; 40 | u32 cmp_and_hdr_size = footer->cmp_and_hdr_size; 41 | 42 | unsigned char* cmp_start = &dataBuf[compSize] - cmp_and_hdr_size; 43 | u32 cmp_ofs = cmp_and_hdr_size - header_size; 44 | u32 out_ofs = cmp_and_hdr_size + addl_size; 45 | 46 | while (out_ofs) 47 | { 48 | unsigned char control = cmp_start[--cmp_ofs]; 49 | for (unsigned int i=0; i<8; i++) 50 | { 51 | if (control & 0x80) 52 | { 53 | if (cmp_ofs < 2) 54 | return 0; // Out of bounds. 55 | 56 | cmp_ofs -= 2; 57 | u16 seg_val = ((unsigned int)(cmp_start[cmp_ofs + 1]) << 8) | cmp_start[cmp_ofs]; 58 | u32 seg_size = ((seg_val >> 12) & 0xF) + 3; 59 | u32 seg_ofs = (seg_val & 0x0FFF) + 3; 60 | if (out_ofs < seg_size) // Kernel restricts segment copy to stay in bounds. 61 | seg_size = out_ofs; 62 | 63 | out_ofs -= seg_size; 64 | 65 | for (unsigned int j = 0; j < seg_size; j++) 66 | cmp_start[out_ofs + j] = cmp_start[out_ofs + j + seg_ofs]; 67 | } 68 | else 69 | { 70 | // Copy directly. 71 | if (cmp_ofs < 1) 72 | return 0; //out of bounds 73 | 74 | cmp_start[--out_ofs] = cmp_start[--cmp_ofs]; 75 | } 76 | control <<= 1; 77 | if (out_ofs == 0) // Blz works backwards, so if it reaches byte 0, it's done. 78 | return 1; 79 | } 80 | } 81 | 82 | return 1; 83 | } 84 | 85 | int blz_uncompress_srcdest(const unsigned char *compData, unsigned int compDataLen, unsigned char *dstData, unsigned int dstSize) 86 | { 87 | blz_footer footer; 88 | const blz_footer *compFooterPtr = blz_get_footer(compData, compDataLen, &footer); 89 | if (compFooterPtr == NULL) 90 | return 0; 91 | 92 | // Decompression must be done in-place, so need to copy the relevant compressed data first. 93 | unsigned int numCompBytes = (const unsigned char*)(compFooterPtr)-compData; 94 | memcpy(dstData, compData, numCompBytes); 95 | memset(&dstData[numCompBytes], 0, dstSize - numCompBytes); 96 | 97 | return blz_uncompress_inplace(dstData, compDataLen, &footer); 98 | } 99 | -------------------------------------------------------------------------------- /bdk/libs/compr/blz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 rajkosto 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _BLZ_H_ 18 | #define _BLZ_H_ 19 | 20 | #include 21 | 22 | typedef struct _blz_footer 23 | { 24 | u32 cmp_and_hdr_size; 25 | u32 header_size; 26 | u32 addl_size; 27 | } blz_footer; 28 | 29 | // Returns pointer to footer in compData if present, additionally copies it to outFooter if not NULL. 30 | const blz_footer *blz_get_footer(const unsigned char *compData, unsigned int compDataLen, blz_footer *outFooter); 31 | // Returns 0 on failure. 32 | int blz_uncompress_inplace(unsigned char *dataBuf, unsigned int compSize, const blz_footer *footer); 33 | // Returns 0 on failure. 34 | int blz_uncompress_srcdest(const unsigned char *compData, unsigned int compDataLen, unsigned char *dstData, unsigned int dstSize); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /bdk/libs/compr/lz.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Name: lz.h 3 | * Author: Marcus Geelnard 4 | * Description: LZ77 coder/decoder interface. 5 | * Reentrant: Yes 6 | *------------------------------------------------------------------------- 7 | * Copyright (c) 2003-2006 Marcus Geelnard 8 | * 9 | * This software is provided 'as-is', without any express or implied 10 | * warranty. In no event will the authors be held liable for any damages 11 | * arising from the use of this software. 12 | * 13 | * Permission is granted to anyone to use this software for any purpose, 14 | * including commercial applications, and to alter it and redistribute it 15 | * freely, subject to the following restrictions: 16 | * 17 | * 1. The origin of this software must not be misrepresented; you must not 18 | * claim that you wrote the original software. If you use this software 19 | * in a product, an acknowledgment in the product documentation would 20 | * be appreciated but is not required. 21 | * 22 | * 2. Altered source versions must be plainly marked as such, and must not 23 | * be misrepresented as being the original software. 24 | * 25 | * 3. This notice may not be removed or altered from any source 26 | * distribution. 27 | * 28 | * Marcus Geelnard 29 | * marcus.geelnard at home.se 30 | *************************************************************************/ 31 | 32 | #ifndef _lz_h_ 33 | #define _lz_h_ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /************************************************************************* 41 | * Function prototypes 42 | *************************************************************************/ 43 | 44 | unsigned int LZ_Uncompress( const unsigned char *in, unsigned char *out, 45 | unsigned int insize ); 46 | 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* _lz_h_ */ 53 | -------------------------------------------------------------------------------- /bdk/libs/fatfs/diskio.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------/ 2 | / Low level disk interface modlue include file (C)ChaN, 2014 / 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include 13 | 14 | /* Status of Disk Functions */ 15 | typedef BYTE DSTATUS; 16 | 17 | /* Results of Disk Functions */ 18 | typedef enum { 19 | RES_OK = 0, /* 0: Successful */ 20 | RES_ERROR, /* 1: R/W Error */ 21 | RES_WRPRT, /* 2: Write Protected */ 22 | RES_NOTRDY, /* 3: Not Ready */ 23 | RES_PARERR /* 4: Invalid Parameter */ 24 | } DRESULT; 25 | 26 | typedef enum { 27 | DRIVE_SD = 0, 28 | DRIVE_RAM = 1, 29 | DRIVE_EMMC = 2, 30 | DRIVE_BIS = 3, 31 | DRIVE_EMU = 4 32 | } DDRIVE; 33 | 34 | 35 | /*---------------------------------------*/ 36 | /* Prototypes for disk control functions */ 37 | 38 | 39 | DSTATUS disk_initialize (BYTE pdrv); 40 | DSTATUS disk_status (BYTE pdrv); 41 | DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); 42 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); 43 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); 44 | DRESULT disk_set_info (BYTE pdrv, BYTE cmd, void *buff); 45 | 46 | 47 | /* Disk Status Bits (DSTATUS) */ 48 | 49 | #define STA_NOINIT 0x01 /* Drive not initialized */ 50 | #define STA_NODISK 0x02 /* No medium in the drive */ 51 | #define STA_PROTECT 0x04 /* Write protected */ 52 | 53 | 54 | /* Command code for disk_ioctrl fucntion */ 55 | 56 | /* Generic command (Used by FatFs) */ 57 | #define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */ 58 | #define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */ 59 | #define SET_SECTOR_COUNT 1 /* Set media size (needed at FF_USE_MKFS == 1) */ 60 | #define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */ 61 | #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */ 62 | #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */ 63 | #define SET_SECTOR_OFFSET 5 /* Set media logical offset */ 64 | 65 | /* Generic command (Not used by FatFs) */ 66 | #define CTRL_POWER 5 /* Get/Set power status */ 67 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 68 | #define CTRL_EJECT 7 /* Eject media */ 69 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 70 | 71 | /* MMC/SDC specific ioctl command */ 72 | #define MMC_GET_TYPE 10 /* Get card type */ 73 | #define MMC_GET_CSD 11 /* Get CSD */ 74 | #define MMC_GET_CID 12 /* Get CID */ 75 | #define MMC_GET_OCR 13 /* Get OCR */ 76 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 77 | #define ISDIO_READ 55 /* Read data form SD iSDIO register */ 78 | #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ 79 | #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ 80 | 81 | /* ATA/CF specific ioctl command */ 82 | #define ATA_GET_REV 20 /* Get F/W revision */ 83 | #define ATA_GET_MODEL 21 /* Get model name */ 84 | #define ATA_GET_SN 22 /* Get serial number */ 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/docs/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [atom@github.com](mailto:atom@github.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/docs/astyle_c: -------------------------------------------------------------------------------- 1 | --style=kr --convert-tabs --indent=spaces=4 --indent-switches --pad-oper --unpad-paren --align-pointer=middle --suffix=.bak --lineend=linux --min-conditional-indent= 2 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/docs/astyle_h: -------------------------------------------------------------------------------- 1 | --convert-tabs --indent=spaces=4 2 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/licence.txt: -------------------------------------------------------------------------------- 1 | MIT licence 2 | Copyright (c) 2016 Gábor Kiss-Vámosi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_core/lv_core.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_group.c 2 | CSRCS += lv_indev.c 3 | CSRCS += lv_obj.c 4 | CSRCS += lv_refr.c 5 | CSRCS += lv_style.c 6 | CSRCS += lv_vdb.c 7 | CSRCS += lv_lang.c 8 | 9 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_core 10 | VPATH += :$(LVGL_DIR)/lvgl/lv_core 11 | 12 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core" 13 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_core/lv_lang.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_lang.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "lv_lang.h" 10 | #if USE_LV_MULTI_LANG 11 | 12 | #include "lv_obj.h" 13 | #include "../lv_misc/lv_gc.h" 14 | 15 | /********************* 16 | * DEFINES 17 | *********************/ 18 | 19 | /********************** 20 | * TYPEDEFS 21 | **********************/ 22 | 23 | /********************** 24 | * STATIC PROTOTYPES 25 | **********************/ 26 | static void lang_set_core(lv_obj_t * obj); 27 | 28 | /********************** 29 | * STATIC VARIABLES 30 | **********************/ 31 | static uint8_t lang_act = 0; 32 | static const void * (*get_txt)(uint16_t); 33 | 34 | /********************** 35 | * MACROS 36 | **********************/ 37 | 38 | /********************** 39 | * GLOBAL FUNCTIONS 40 | **********************/ 41 | 42 | /** 43 | * Change the language 44 | * @param lang_id the id of the 45 | */ 46 | void lv_lang_set(uint8_t lang_id) 47 | { 48 | lang_act = lang_id; 49 | 50 | lv_obj_t * i; 51 | LL_READ(LV_GC_ROOT(_lv_scr_ll), i) { 52 | i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL); 53 | 54 | lang_set_core(i); 55 | } 56 | 57 | lang_set_core(lv_scr_act()); 58 | } 59 | 60 | /** 61 | * Set a function to get the texts of the set languages from a `txt_id` 62 | * @param fp a function pointer to get the texts 63 | */ 64 | void lv_lang_set_text_func(const void * (*fp)(uint16_t)) 65 | { 66 | get_txt = fp; 67 | } 68 | 69 | /** 70 | * Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language 71 | * @param txt_id an ID of the text to get 72 | * @return the `txt_id` txt on the set language 73 | */ 74 | const void * lv_lang_get_text(uint16_t txt_id) 75 | { 76 | if(get_txt == NULL) { 77 | LV_LOG_WARN("lv_lang_get_text: text_func is not specified"); 78 | return NULL; /*No text_get function specified */ 79 | } 80 | if(txt_id == LV_LANG_TXT_ID_NONE) { 81 | LV_LOG_WARN("lv_lang_get_text: attempts to get invalid text ID"); 82 | return NULL; /*Invalid txt_id*/ 83 | } 84 | 85 | return get_txt(txt_id); 86 | } 87 | 88 | 89 | /** 90 | * Return with ID of the currently selected language 91 | * @return pointer to the active screen object (loaded by 'lv_scr_load()') 92 | */ 93 | uint8_t lv_lang_act(void) 94 | { 95 | return lang_act; 96 | } 97 | 98 | 99 | /********************** 100 | * STATIC FUNCTIONS 101 | **********************/ 102 | 103 | /** 104 | * Change the language of the children. (Called recursively) 105 | * @param obj pointer to an object 106 | */ 107 | static void lang_set_core(lv_obj_t * obj) 108 | { 109 | lv_obj_t * i; 110 | LL_READ(obj->child_ll, i) { 111 | i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL); 112 | 113 | lang_set_core(i); 114 | } 115 | } 116 | 117 | #endif /*USE_LV_MULTI_LANG*/ 118 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_core/lv_lang.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_lang.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LANG_H 7 | #define LV_LANG_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_MULTI_LANG 23 | 24 | #include 25 | 26 | /********************* 27 | * DEFINES 28 | *********************/ 29 | #define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/ 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | 35 | /********************** 36 | * GLOBAL PROTOTYPES 37 | **********************/ 38 | 39 | /** 40 | * Change the language 41 | * @param lang_id the id of the 42 | */ 43 | void lv_lang_set(uint8_t lang_id); 44 | 45 | /** 46 | * Set a function to get the texts of the set languages from a `txt_id` 47 | * @param fp a function pointer to get the texts 48 | */ 49 | void lv_lang_set_text_func(const void * (*fp)(uint16_t)); 50 | 51 | /** 52 | * Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language 53 | * @param txt_id an ID of the text to get 54 | * @return the `txt_id` txt on the set language 55 | */ 56 | const void * lv_lang_get_text(uint16_t txt_id); 57 | 58 | /** 59 | * Return with ID of the currently selected language 60 | * @return pointer to the active screen object (loaded by 'lv_scr_load()') 61 | */ 62 | uint8_t lv_lang_act(void); 63 | 64 | /********************** 65 | * MACROS 66 | **********************/ 67 | 68 | #endif /*USE_LV_MULTI_LANG*/ 69 | 70 | #ifdef __cplusplus 71 | } /* extern "C" */ 72 | #endif 73 | 74 | #endif /*LV_LANG_H*/ 75 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_core/lv_refr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_refr.h 3 | * 4 | */ 5 | 6 | #ifndef LV_REFR_H 7 | #define LV_REFR_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_obj.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * STATIC PROTOTYPES 28 | **********************/ 29 | 30 | /********************** 31 | * STATIC VARIABLES 32 | **********************/ 33 | 34 | /********************** 35 | * MACROS 36 | **********************/ 37 | 38 | /********************** 39 | * GLOBAL FUNCTIONS 40 | **********************/ 41 | 42 | /** 43 | * Initialize the screen refresh subsystem 44 | */ 45 | void lv_refr_init(void); 46 | 47 | /** 48 | * Redraw the invalidated areas now. 49 | * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can 50 | * prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar) 51 | * this function can be called when the screen should be updated. 52 | */ 53 | void lv_refr_now(void); 54 | 55 | /** 56 | * Invalidate an area 57 | * @param area_p pointer to area which should be invalidated 58 | */ 59 | void lv_inv_area(const lv_area_t * area_p); 60 | 61 | /** 62 | * Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels 63 | * @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num)) 64 | */ 65 | void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)); 66 | 67 | /** 68 | * Called when an area is invalidated to modify the coordinates of the area. 69 | * Special display controllers may require special coordinate rounding 70 | * @param cb pointer to the a function which will modify the area 71 | */ 72 | void lv_refr_set_round_cb(void(*cb)(lv_area_t*)); 73 | 74 | /** 75 | * Get the number of areas in the buffer 76 | * @return number of invalid areas 77 | */ 78 | uint16_t lv_refr_get_buf_size(void); 79 | 80 | /** 81 | * Pop (delete) the last 'num' invalidated areas from the buffer 82 | * @param num number of areas to delete 83 | */ 84 | void lv_refr_pop_from_buf(uint16_t num); 85 | /********************** 86 | * STATIC FUNCTIONS 87 | **********************/ 88 | 89 | 90 | #ifdef __cplusplus 91 | } /* extern "C" */ 92 | #endif 93 | 94 | #endif /*LV_REFR_H*/ 95 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_core/lv_vdb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_vdb.h 3 | * 4 | */ 5 | 6 | #ifndef LV_VDB_H 7 | #define LV_VDB_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #if LV_VDB_SIZE != 0 23 | 24 | #include "../lv_misc/lv_color.h" 25 | #include "../lv_misc/lv_area.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | /*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()`*/ 31 | #define LV_VDB_ADR_INV 8 /*8 is still too small to be valid but it's aligned on 64 bit machines as well*/ 32 | 33 | #ifndef LV_VDB_PX_BPP 34 | #define LV_VDB_PX_BPP LV_COLOR_SIZE /* Default is LV_COLOR_SIZE */ 35 | #endif 36 | 37 | 38 | #if LV_VDB_TRUE_DOUBLE_BUFFERED && (LV_VDB_SIZE != LV_HOR_RES * LV_VER_RES || LV_VDB_DOUBLE == 0) 39 | #error "With LV_VDB_TRUE_DOUBLE_BUFFERED: (LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES and LV_VDB_DOUBLE = 1 is required" 40 | #endif 41 | 42 | 43 | /* The size of VDB in bytes. 44 | * (LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3): just divide by 8 to convert bits to bytes 45 | * (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0): add an extra byte to round up. 46 | * E.g. if LV_VDB_SIZE = 10 and LV_VDB_PX_BPP = 1 -> 10 bits -> 2 bytes*/ 47 | #define LV_VDB_SIZE_IN_BYTES ((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0) 48 | 49 | /********************** 50 | * TYPEDEFS 51 | **********************/ 52 | 53 | typedef struct 54 | { 55 | lv_area_t area; 56 | lv_color_t *buf; 57 | } lv_vdb_t; 58 | 59 | /********************** 60 | * GLOBAL PROTOTYPES 61 | **********************/ 62 | 63 | /** 64 | * Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode 65 | * @return pointer to a 'vdb' variable 66 | */ 67 | lv_vdb_t * lv_vdb_get(void); 68 | 69 | /** 70 | * Flush the content of the vdb 71 | */ 72 | void lv_vdb_flush(void); 73 | 74 | /** 75 | * 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`. 76 | * It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES` 77 | * @param buf1 address of the VDB. 78 | * @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0` 79 | */ 80 | void lv_vdb_set_adr(void * buf1, void * buf2); 81 | 82 | /** 83 | * Call in the display driver's 'disp_flush' function when the flushing is finished 84 | */ 85 | void lv_flush_ready(void); 86 | 87 | /** 88 | * Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1` 89 | * @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB 90 | */ 91 | lv_vdb_t * lv_vdb_get_active(void); 92 | 93 | /** 94 | * Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1` 95 | * @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB 96 | */ 97 | lv_vdb_t * lv_vdb_get_inactive(void); 98 | 99 | /** 100 | * Whether the flushing is in progress or not 101 | * @return true: flushing is in progress; false: flushing ready 102 | */ 103 | bool lv_vdb_is_flushing(void); 104 | 105 | /********************** 106 | * MACROS 107 | **********************/ 108 | 109 | #else /*LV_VDB_SIZE != 0*/ 110 | 111 | /*Just for compatibility*/ 112 | void lv_flush_ready(void); 113 | #endif 114 | 115 | #ifdef __cplusplus 116 | } /* extern "C" */ 117 | #endif 118 | 119 | #endif /*LV_VDB_H*/ 120 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_H 7 | #define LV_DRAW_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #include "../lv_core/lv_style.h" 23 | #include "../lv_misc/lv_txt.h" 24 | 25 | /********************* 26 | * DEFINES 27 | *********************/ 28 | /*If image pixels contains alpha we need to know how much byte is a pixel*/ 29 | #if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8 30 | # define LV_IMG_PX_SIZE_ALPHA_BYTE 2 31 | #elif LV_COLOR_DEPTH == 16 32 | # define LV_IMG_PX_SIZE_ALPHA_BYTE 3 33 | #elif LV_COLOR_DEPTH == 32 34 | # define LV_IMG_PX_SIZE_ALPHA_BYTE 4 35 | #endif 36 | 37 | /********************** 38 | * TYPEDEFS 39 | **********************/ 40 | 41 | enum { 42 | LV_IMG_SRC_VARIABLE, 43 | LV_IMG_SRC_FILE, 44 | LV_IMG_SRC_SYMBOL, 45 | LV_IMG_SRC_UNKNOWN, 46 | }; 47 | typedef uint8_t lv_img_src_t; 48 | 49 | 50 | /********************** 51 | * GLOBAL PROTOTYPES 52 | **********************/ 53 | 54 | #if LV_ANTIALIAS != 0 55 | 56 | /** 57 | * Get the opacity of a pixel based it's position in a line segment 58 | * @param seg segment length 59 | * @param px_id position of of a pixel which opacity should be get [0..seg-1] 60 | * @param base_opa the base opacity 61 | * @return the opacity of the given pixel 62 | */ 63 | lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa); 64 | 65 | /** 66 | * Add a vertical anti-aliasing segment (pixels with decreasing opacity) 67 | * @param x start point x coordinate 68 | * @param y start point y coordinate 69 | * @param length length of segment (negative value to start from 0 opacity) 70 | * @param mask draw only in this area 71 | * @param color color of pixels 72 | * @param opa maximum opacity 73 | */ 74 | 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); 75 | 76 | /** 77 | * Add a horizontal anti-aliasing segment (pixels with decreasing opacity) 78 | * @param x start point x coordinate 79 | * @param y start point y coordinate 80 | * @param length length of segment (negative value to start from 0 opacity) 81 | * @param mask draw only in this area 82 | * @param color color of pixels 83 | * @param opa maximum opacity 84 | */ 85 | 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); 86 | #endif 87 | 88 | /********************** 89 | * GLOBAL VARIABLES 90 | **********************/ 91 | 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); 92 | extern void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); 93 | 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); 94 | extern void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p, 95 | const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, 96 | lv_color_t recolor, lv_opa_t recolor_opa); 97 | 98 | /********************** 99 | * MACROS 100 | **********************/ 101 | 102 | /********************** 103 | * POST INCLUDES 104 | *********************/ 105 | #include "lv_draw_rect.h" 106 | #include "lv_draw_label.h" 107 | #include "lv_draw_img.h" 108 | #include "lv_draw_line.h" 109 | #include "lv_draw_triangle.h" 110 | 111 | #ifdef __cplusplus 112 | } /* extern "C" */ 113 | #endif 114 | 115 | #endif /*LV_DRAW_H*/ 116 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_draw_vbasic.c 2 | CSRCS += lv_draw_rbasic.c 3 | CSRCS += lv_draw.c 4 | CSRCS += lv_draw_rect.c 5 | CSRCS += lv_draw_label.c 6 | CSRCS += lv_draw_line.c 7 | CSRCS += lv_draw_img.c 8 | CSRCS += lv_draw_arc.c 9 | CSRCS += lv_draw_triangle.c 10 | 11 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_draw 12 | VPATH += :$(LVGL_DIR)/lvgl/lv_draw 13 | 14 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw" 15 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_arc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_arc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_ARC_H 7 | #define LV_DRAW_ARC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Draw an arc. (Can draw pie too with great thickness.) 32 | * @param center_x the x coordinate of the center of the arc 33 | * @param center_y the y coordinate of the center of the arc 34 | * @param radius the radius of the arc 35 | * @param mask the arc will be drawn only in this mask 36 | * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) 37 | * @param end_angle the end angle of the arc 38 | * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) 39 | * @param opa_scale scale down all opacities by the factor 40 | */ 41 | void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask, 42 | uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale); 43 | 44 | /********************** 45 | * MACROS 46 | **********************/ 47 | 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif 52 | 53 | #endif /*LV_DRAW_ARC*/ 54 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_label.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_label.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_LABEL_H 7 | #define LV_DRAW_LABEL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Write a text 32 | * @param coords coordinates of the label 33 | * @param mask the label will be drawn only in this area 34 | * @param style pointer to a style 35 | * @param opa_scale scale down all opacities by the factor 36 | * @param txt 0 terminated text to write 37 | * @param flag settings for the text from 'txt_flag_t' enum 38 | * @param offset text offset in x and y direction (NULL if unused) 39 | * 40 | */ 41 | void lv_draw_label(const lv_area_t * coords,const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale, 42 | const char * txt, lv_txt_flag_t flag, lv_point_t * offset); 43 | 44 | /********************** 45 | * MACROS 46 | **********************/ 47 | 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif 52 | 53 | #endif /*LV_DRAW_LABEL_H*/ 54 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_line.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_line.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_LINE_H 7 | #define LV_DRAW_LINE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | 29 | /** 30 | * Draw a line 31 | * @param point1 first point of the line 32 | * @param point2 second point of the line 33 | * @param mask the line will be drawn only on this area 34 | * @param style pointer to a line's style 35 | * @param opa_scale scale down all opacities by the factor 36 | */ 37 | void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, 38 | const lv_style_t * style, lv_opa_t opa_scale); 39 | 40 | /********************** 41 | * MACROS 42 | **********************/ 43 | 44 | 45 | #ifdef __cplusplus 46 | } /* extern "C" */ 47 | #endif 48 | 49 | #endif /*LV_DRAW_LINE_H*/ 50 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_rbasic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_rbasic..h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_RBASIC_H 7 | #define LV_DRAW_RBASIC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_REAL_DRAW != 0 23 | 24 | #include "../lv_misc/lv_color.h" 25 | #include "../lv_misc/lv_area.h" 26 | #include "../lv_misc/lv_font.h" 27 | 28 | /********************* 29 | * DEFINES 30 | *********************/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | 40 | 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); 41 | 42 | /** 43 | * Fill an area on the display 44 | * @param cords_p coordinates of the area to fill 45 | * @param mask_p fill only o this mask 46 | * @param color fill color 47 | * @param opa opacity (ignored, only for compatibility with lv_vfill) 48 | */ 49 | void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p, 50 | lv_color_t color, lv_opa_t opa); 51 | 52 | /** 53 | * Draw a letter to the display 54 | * @param pos_p left-top coordinate of the latter 55 | * @param mask_p the letter will be drawn only on this area 56 | * @param font_p pointer to font 57 | * @param letter a letter to draw 58 | * @param color color of letter 59 | * @param opa opacity of letter (ignored, only for compatibility with lv_vletter) 60 | */ 61 | void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p, 62 | const lv_font_t * font_p, uint32_t letter, 63 | lv_color_t color, lv_opa_t opa); 64 | 65 | /** 66 | * When the letter is ant-aliased it needs to know the background color 67 | * @param bg_color the background color of the currently drawn letter 68 | */ 69 | void lv_rletter_set_background(lv_color_t color); 70 | 71 | 72 | /** 73 | * Draw a color map to the display (image) 74 | * @param cords_p coordinates the color map 75 | * @param mask_p the map will drawn only on this area 76 | * @param map_p pointer to a lv_color_t array 77 | * @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap') 78 | * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels 79 | * @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it) 80 | * @param recolor mix the pixels with this color 81 | * @param recolor_opa the intense of recoloring 82 | */ 83 | void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p, 84 | const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, 85 | lv_color_t recolor, lv_opa_t recolor_opa); 86 | /********************** 87 | * MACROS 88 | **********************/ 89 | 90 | #endif /*USE_LV_REAL_DRAW*/ 91 | 92 | #ifdef __cplusplus 93 | } /* extern "C" */ 94 | #endif 95 | 96 | #endif /*LV_DRAW_RBASIC_H*/ 97 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_rect.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_rect.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_RECT_H 7 | #define LV_DRAW_RECT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Draw a rectangle 32 | * @param coords the coordinates of the rectangle 33 | * @param mask the rectangle will be drawn only in this mask 34 | * @param style pointer to a style 35 | * @param opa_scale scale down all opacities by the factor 36 | */ 37 | void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); 38 | 39 | /********************** 40 | * MACROS 41 | **********************/ 42 | 43 | 44 | #ifdef __cplusplus 45 | } /* extern "C" */ 46 | #endif 47 | 48 | #endif /*LV_DRAW_RECT_H*/ 49 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_triangle.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_triangle.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_TRIANGLE_H 7 | #define LV_DRAW_TRIANGLE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | /*Experimental use for 3D modeling*/ 30 | #define USE_LV_TRIANGLE 1 31 | 32 | #if USE_LV_TRIANGLE != 0 33 | /** 34 | * 35 | * @param points pointer to an array with 3 points 36 | * @param mask the triangle will be drawn only in this mask 37 | * @param color color of the triangle 38 | */ 39 | void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color); 40 | #endif 41 | 42 | /********************** 43 | * MACROS 44 | **********************/ 45 | 46 | 47 | #ifdef __cplusplus 48 | } /* extern "C" */ 49 | #endif 50 | 51 | #endif /*LV_DRAW_TRIANGLE_H*/ 52 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_vbasic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_vbasic.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_VBASIC_H 7 | #define LV_DRAW_VBASIC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #if LV_VDB_SIZE != 0 23 | 24 | #include "../lv_misc/lv_color.h" 25 | #include "../lv_misc/lv_area.h" 26 | #include "../lv_misc/lv_font.h" 27 | 28 | /********************* 29 | * DEFINES 30 | *********************/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | 40 | 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); 41 | /** 42 | * Fill an area in the Virtual Display Buffer 43 | * @param cords_p coordinates of the area to fill 44 | * @param mask_p fill only o this mask 45 | * @param color fill color 46 | * @param opa opacity of the area (0..255) 47 | */ 48 | void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p, 49 | lv_color_t color, lv_opa_t opa); 50 | 51 | /** 52 | * Draw a letter in the Virtual Display Buffer 53 | * @param pos_p left-top coordinate of the latter 54 | * @param mask_p the letter will be drawn only on this area 55 | * @param font_p pointer to font 56 | * @param letter a letter to draw 57 | * @param color color of letter 58 | * @param opa opacity of letter (0..255) 59 | */ 60 | void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p, 61 | const lv_font_t * font_p, uint32_t letter, 62 | lv_color_t color, lv_opa_t opa); 63 | 64 | /** 65 | * Draw a color map to the display (image) 66 | * @param cords_p coordinates the color map 67 | * @param mask_p the map will drawn only on this area (truncated to VDB area) 68 | * @param map_p pointer to a lv_color_t array 69 | * @param opa opacity of the map 70 | * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels 71 | * @param alpha_byte true: extra alpha byte is inserted for every pixel 72 | * @param recolor mix the pixels with this color 73 | * @param recolor_opa the intense of recoloring 74 | */ 75 | void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p, 76 | const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, 77 | lv_color_t recolor, lv_opa_t recolor_opa); 78 | 79 | /********************** 80 | * MACROS 81 | **********************/ 82 | 83 | #endif /*LV_VDB_SIZE != 0*/ 84 | 85 | #ifdef __cplusplus 86 | } /* extern "C" */ 87 | #endif 88 | 89 | #endif /*LV_DRAW_RBASIC_H*/ 90 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_fonts/hekate_symbol_120.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include "../lv_misc/lv_font.h" 18 | 19 | #include 20 | 21 | #if USE_HEKATE_SYMBOL_120 != 0 /*Can be enabled in lv_conf.h*/ 22 | 23 | /*********************************************************************************** 24 | * hekate-symbols-huge.ttf 120 px Font in U+f002 () .. U+f007 () range with all bpp 25 | * Sparse font with only these characters:  26 | ***********************************************************************************/ 27 | 28 | /*Store the glyph descriptions*/ 29 | static const lv_font_glyph_dsc_t hekate_symbol_120_glyph_dsc[] = 30 | { 31 | #if USE_HEKATE_SYMBOL_120 == 8 32 | {.w_px = 103, .glyph_index = 0}, /*Unicode: U+f002 ()*/ 33 | {.w_px = 103, .glyph_index = 12360}, /*Unicode: U+f003 ()*/ 34 | {.w_px = 103, .glyph_index = 24720}, /*Unicode: U+f005 ()*/ 35 | {.w_px = 103, .glyph_index = 37080}, /*Unicode: U+f007 ()*/ 36 | 37 | #endif 38 | }; 39 | 40 | lv_font_t hekate_symbol_120 = 41 | { 42 | .unicode_first = LV_SYMBOL_GLYPH_FIRST, /*First Unicode letter in this font*/ 43 | .unicode_last = LV_SYMBOL_GLYPH_LAST, /*Last Unicode letter in this font*/ 44 | .h_px = 120, /*Font height in pixels*/ 45 | .glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x36E00), /*Bitmap of glyphs*/ 46 | .glyph_dsc = hekate_symbol_120_glyph_dsc, /*Description of glyphs*/ 47 | .glyph_cnt = 4, /*Number of glyphs in the font*/ 48 | .unicode_list = NULL, /*List of unicode characters*/ 49 | .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ 50 | .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ 51 | #if USE_HEKATE_SYMBOL_120 == 8 52 | .bpp = 8, /*Bit per pixel*/ 53 | #endif 54 | .monospace = 0, /*Fix width (0: if not used)*/ 55 | .next_page = NULL, /*Pointer to a font extension*/ 56 | }; 57 | 58 | #endif /*USE_HEKATE_SYMBOL_100*/ 59 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_fonts/lv_font_builtin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /** 18 | * @file lv_font_built_in.c 19 | * 20 | */ 21 | 22 | /********************* 23 | * INCLUDES 24 | *********************/ 25 | #include "lv_font_builtin.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | 35 | /********************** 36 | * STATIC PROTOTYPES 37 | **********************/ 38 | 39 | /********************** 40 | * STATIC VARIABLES 41 | **********************/ 42 | 43 | /********************** 44 | * MACROS 45 | **********************/ 46 | 47 | /********************** 48 | * GLOBAL FUNCTIONS 49 | **********************/ 50 | 51 | /** 52 | * Initialize the built-in fonts 53 | */ 54 | void lv_font_builtin_init(void) 55 | { 56 | /*InterUI 20*/ 57 | #if USE_INTERUI_20 != 0 58 | lv_font_add(&interui_20, NULL); 59 | #endif 60 | 61 | /*SYMBOL 20*/ 62 | #if USE_HEKATE_SYMBOL_20 != 0 63 | #if USE_INTERUI_20 != 0 64 | lv_font_add(&hekate_symbol_20, &interui_20); 65 | #else 66 | lv_font_add(&hekate_symbol_20, NULL); 67 | #endif 68 | #endif 69 | 70 | /*InterUI 30*/ 71 | #if USE_INTERUI_30 != 0 72 | lv_font_add(&interui_30, NULL); 73 | #endif 74 | 75 | /*SYMBOL 30*/ 76 | #if USE_HEKATE_SYMBOL_30 != 0 77 | #if USE_INTERUI_30 != 0 78 | lv_font_add(&hekate_symbol_30, &interui_30); 79 | #else 80 | lv_font_add(&hekate_symbol_30, NULL); 81 | #endif 82 | #endif 83 | 84 | /*MONO 12*/ 85 | #if USE_UBUNTU_MONO != 0 86 | lv_font_add(&ubuntu_mono, NULL); 87 | #if USE_INTERUI_20 != 0 88 | lv_font_add(&hekate_symbol_20, &ubuntu_mono); 89 | #endif 90 | #endif 91 | 92 | /*Symbol 120*/ 93 | #if USE_HEKATE_SYMBOL_120 != 0 94 | lv_font_add(&hekate_symbol_120, NULL); 95 | #endif 96 | } 97 | 98 | /********************** 99 | * STATIC FUNCTIONS 100 | **********************/ 101 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_fonts/lv_font_builtin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /** 18 | * @file lv_font_builtin.h 19 | * 20 | */ 21 | 22 | #ifndef LV_FONT_BUILTIN_H 23 | #define LV_FONT_BUILTIN_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /********************* 30 | * INCLUDES 31 | *********************/ 32 | #ifdef LV_CONF_INCLUDE_SIMPLE 33 | #include "lv_conf.h" 34 | #else 35 | #include "../../lv_conf.h" 36 | #endif 37 | 38 | #include "../lv_misc/lv_font.h" 39 | 40 | /********************* 41 | * DEFINES 42 | *********************/ 43 | 44 | /********************** 45 | * TYPEDEFS 46 | **********************/ 47 | 48 | /********************** 49 | * GLOBAL PROTOTYPES 50 | **********************/ 51 | 52 | /** 53 | * Initialize the built-in fonts 54 | */ 55 | void lv_font_builtin_init(void); 56 | 57 | /********************** 58 | * MACROS 59 | **********************/ 60 | 61 | /********************** 62 | * FONT DECLARATIONS 63 | **********************/ 64 | 65 | /*20 px */ 66 | #if USE_INTERUI_20 67 | LV_FONT_DECLARE(interui_20); 68 | #endif 69 | 70 | #if USE_HEKATE_SYMBOL_20 71 | LV_FONT_DECLARE(hekate_symbol_20); 72 | #endif 73 | 74 | /*30 px */ 75 | #if USE_INTERUI_30 76 | LV_FONT_DECLARE(interui_30); 77 | #endif 78 | 79 | #if USE_HEKATE_SYMBOL_30 80 | LV_FONT_DECLARE(hekate_symbol_30); 81 | #endif 82 | 83 | #if USE_UBUNTU_MONO 84 | LV_FONT_DECLARE(ubuntu_mono); 85 | #endif 86 | 87 | #if USE_HEKATE_SYMBOL_120 88 | LV_FONT_DECLARE(hekate_symbol_120); 89 | #endif 90 | 91 | #ifdef __cplusplus 92 | } /* extern "C" */ 93 | #endif 94 | 95 | #endif /*LV_FONT_BUILTIN_H*/ 96 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_fonts/lv_fonts.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_font_builtin.c 2 | CSRCS += hekate_symbol_10.c 3 | CSRCS += hekate_symbol_20.c 4 | CSRCS += hekate_symbol_30.c 5 | CSRCS += hekate_symbol_40.c 6 | CSRCS += interui_12.c 7 | CSRCS += interui_20.c 8 | CSRCS += interui_30.c 9 | CSRCS += interui_40.c 10 | 11 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_fonts 12 | VPATH += :$(LVGL_DIR)/lvgl/lv_fonts 13 | 14 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_fonts" 15 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_hal/lv_hal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hal.h 3 | * 4 | */ 5 | 6 | #ifndef HAL_H 7 | #define HAL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_hal_disp.h" 17 | #include "lv_hal_indev.h" 18 | #include "lv_hal_tick.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | #ifdef __cplusplus 37 | } /* extern "C" */ 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_hal/lv_hal.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_hal_disp.c 2 | CSRCS += lv_hal_indev.c 3 | CSRCS += lv_hal_tick.c 4 | 5 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_hal 6 | VPATH += :$(LVGL_DIR)/lvgl/lv_hal 7 | 8 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal" 9 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_hal/lv_hal_tick.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file systick.c 3 | * Provide access to the system tick with 1 millisecond resolution 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #ifdef LV_CONF_INCLUDE_SIMPLE 10 | #include "lv_conf.h" 11 | #else 12 | #include "../../lv_conf.h" 13 | #endif 14 | 15 | #include "lv_hal_tick.h" 16 | #include 17 | 18 | #if LV_TICK_CUSTOM == 1 19 | #include LV_TICK_CUSTOM_INCLUDE 20 | #endif 21 | 22 | /********************* 23 | * DEFINES 24 | *********************/ 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | /********************** 31 | * STATIC PROTOTYPES 32 | **********************/ 33 | 34 | /********************** 35 | * STATIC VARIABLES 36 | **********************/ 37 | static uint32_t sys_time = 0; 38 | static volatile uint8_t tick_irq_flag; 39 | 40 | /********************** 41 | * MACROS 42 | **********************/ 43 | 44 | /********************** 45 | * GLOBAL FUNCTIONS 46 | **********************/ 47 | 48 | /** 49 | * You have to call this function periodically 50 | * @param tick_period the call period of this function in milliseconds 51 | */ 52 | LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period) 53 | { 54 | tick_irq_flag = 0; 55 | sys_time += tick_period; 56 | } 57 | 58 | /** 59 | * Get the elapsed milliseconds since start up 60 | * @return the elapsed milliseconds 61 | */ 62 | uint32_t lv_tick_get(void) 63 | { 64 | #if LV_TICK_CUSTOM == 0 65 | uint32_t result; 66 | do { 67 | tick_irq_flag = 1; 68 | result = sys_time; 69 | } while(!tick_irq_flag); /*'lv_tick_inc()' clears this flag which can be in an interrupt. Continue until make a non interrupted cycle */ 70 | 71 | return result; 72 | #else 73 | return LV_TICK_CUSTOM_SYS_TIME_EXPR; 74 | #endif 75 | } 76 | 77 | /** 78 | * Get the elapsed milliseconds since a previous time stamp 79 | * @param prev_tick a previous time stamp (return value of systick_get() ) 80 | * @return the elapsed milliseconds since 'prev_tick' 81 | */ 82 | uint32_t lv_tick_elaps(uint32_t prev_tick) 83 | { 84 | uint32_t act_time = lv_tick_get(); 85 | 86 | /*If there is no overflow in sys_time simple subtract*/ 87 | if(act_time >= prev_tick) { 88 | prev_tick = act_time - prev_tick; 89 | } else { 90 | prev_tick = UINT32_MAX - prev_tick + 1; 91 | prev_tick += act_time; 92 | } 93 | 94 | return prev_tick; 95 | } 96 | 97 | /********************** 98 | * STATIC FUNCTIONS 99 | **********************/ 100 | 101 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_hal/lv_hal_tick.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_hal_tick.h 3 | * Provide access to the system tick with 1 millisecond resolution 4 | */ 5 | 6 | #ifndef LV_HAL_TICK_H 7 | #define LV_HAL_TICK_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | #include 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | #ifndef LV_ATTRIBUTE_TICK_INC 27 | #define LV_ATTRIBUTE_TICK_INC 28 | #endif 29 | 30 | /********************** 31 | * TYPEDEFS 32 | **********************/ 33 | 34 | /********************** 35 | * GLOBAL PROTOTYPES 36 | **********************/ 37 | 38 | /** 39 | * You have to call this function periodically 40 | * @param tick_period the call period of this function in milliseconds 41 | */ 42 | LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period); 43 | 44 | /** 45 | * Get the elapsed milliseconds since start up 46 | * @return the elapsed milliseconds 47 | */ 48 | uint32_t lv_tick_get(void); 49 | 50 | /** 51 | * Get the elapsed milliseconds since a previous time stamp 52 | * @param prev_tick a previous time stamp (return value of systick_get() ) 53 | * @return the elapsed milliseconds since 'prev_tick' 54 | */ 55 | uint32_t lv_tick_elaps(uint32_t prev_tick); 56 | 57 | /********************** 58 | * MACROS 59 | **********************/ 60 | 61 | #ifdef __cplusplus 62 | } /* extern "C" */ 63 | #endif 64 | 65 | #endif /*LV_HAL_TICK_H*/ 66 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_circ.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_circ.c 3 | * Circle drawing algorithm (with Bresenham) 4 | * Only a 1/8 circle is calculated. Use CIRC_OCT1_X, CIRC_OCT1_Y macros to get 5 | * the other octets. 6 | */ 7 | 8 | /********************* 9 | * INCLUDES 10 | *********************/ 11 | #include "lv_circ.h" 12 | 13 | /********************* 14 | * DEFINES 15 | *********************/ 16 | 17 | /********************** 18 | * TYPEDEFS 19 | **********************/ 20 | 21 | /********************** 22 | * STATIC PROTOTYPES 23 | **********************/ 24 | 25 | /********************** 26 | * STATIC VARIABLES 27 | **********************/ 28 | 29 | /********************** 30 | * MACROS 31 | **********************/ 32 | 33 | /********************** 34 | * GLOBAL FUNCTIONS 35 | **********************/ 36 | 37 | /** 38 | * Initialize the circle drawing 39 | * @param c pointer to a point. The coordinates will be calculated here 40 | * @param tmp point to a variable. It will store temporary data 41 | * @param radius radius of the circle 42 | */ 43 | void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius) 44 | { 45 | c->x = radius; 46 | c->y = 0; 47 | *tmp = 1 - radius; 48 | } 49 | 50 | /** 51 | * Test the circle drawing is ready or not 52 | * @param c same as in circ_init 53 | * @return true if the circle is not ready yet 54 | */ 55 | bool lv_circ_cont(lv_point_t * c) 56 | { 57 | return c->y <= c->x ? true : false; 58 | } 59 | 60 | /** 61 | * Get the next point from the circle 62 | * @param c same as in circ_init. The next point stored here. 63 | * @param tmp same as in circ_init. 64 | */ 65 | void lv_circ_next(lv_point_t * c, lv_coord_t * tmp) 66 | { 67 | c->y++; 68 | 69 | if(*tmp <= 0) { 70 | (*tmp) += 2 * c->y + 1; // Change in decision criterion for y -> y+1 71 | } else { 72 | c->x--; 73 | (*tmp) += 2 * (c->y - c->x) + 1; // Change for y -> y+1, x -> x-1 74 | } 75 | } 76 | 77 | /********************** 78 | * STATIC FUNCTIONS 79 | **********************/ 80 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_circ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_circ.h 3 | * 4 | */ 5 | 6 | #ifndef LV_CIRC_H 7 | #define LV_CIRC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #include 18 | #include "lv_area.h" 19 | #include 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | #define LV_CIRC_OCT1_X(p) (p.x) 25 | #define LV_CIRC_OCT1_Y(p) (p.y) 26 | #define LV_CIRC_OCT2_X(p) (p.y) 27 | #define LV_CIRC_OCT2_Y(p) (p.x) 28 | #define LV_CIRC_OCT3_X(p) (-p.y) 29 | #define LV_CIRC_OCT3_Y(p) (p.x) 30 | #define LV_CIRC_OCT4_X(p) (-p.x) 31 | #define LV_CIRC_OCT4_Y(p) (p.y) 32 | #define LV_CIRC_OCT5_X(p) (-p.x) 33 | #define LV_CIRC_OCT5_Y(p) (-p.y) 34 | #define LV_CIRC_OCT6_X(p) (-p.y) 35 | #define LV_CIRC_OCT6_Y(p) (-p.x) 36 | #define LV_CIRC_OCT7_X(p) (p.y) 37 | #define LV_CIRC_OCT7_Y(p) (-p.x) 38 | #define LV_CIRC_OCT8_X(p) (p.x) 39 | #define LV_CIRC_OCT8_Y(p) (-p.y) 40 | 41 | /********************** 42 | * TYPEDEFS 43 | **********************/ 44 | 45 | /********************** 46 | * GLOBAL PROTOTYPES 47 | **********************/ 48 | 49 | /** 50 | * Initialize the circle drawing 51 | * @param c pointer to a point. The coordinates will be calculated here 52 | * @param tmp point to a variable. It will store temporary data 53 | * @param radius radius of the circle 54 | */ 55 | void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius); 56 | 57 | /** 58 | * Test the circle drawing is ready or not 59 | * @param c same as in circ_init 60 | * @return true if the circle is not ready yet 61 | */ 62 | bool lv_circ_cont(lv_point_t * c); 63 | 64 | /** 65 | * Get the next point from the circle 66 | * @param c same as in circ_init. The next point stored here. 67 | * @param tmp same as in circ_init. 68 | */ 69 | void lv_circ_next(lv_point_t * c, lv_coord_t * tmp); 70 | 71 | /********************** 72 | * MACROS 73 | **********************/ 74 | 75 | #ifdef __cplusplus 76 | } /* extern "C" */ 77 | #endif 78 | 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_gc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_gc.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | 10 | #include "lv_gc.h" 11 | 12 | /********************* 13 | * DEFINES 14 | *********************/ 15 | 16 | /********************** 17 | * TYPEDEFS 18 | **********************/ 19 | 20 | /********************** 21 | * STATIC PROTOTYPES 22 | **********************/ 23 | 24 | /********************** 25 | * STATIC VARIABLES 26 | **********************/ 27 | #if (!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0 28 | LV_ROOTS 29 | #endif /* LV_ENABLE_GC */ 30 | /********************** 31 | * MACROS 32 | **********************/ 33 | 34 | /********************** 35 | * GLOBAL FUNCTIONS 36 | **********************/ 37 | 38 | /********************** 39 | * STATIC FUNCTIONS 40 | **********************/ 41 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_gc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_gc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_GC_H 7 | #define LV_GC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #ifdef LV_CONF_INCLUDE_SIMPLE 18 | #include "lv_conf.h" 19 | #else 20 | #include "../../lv_conf.h" 21 | #endif 22 | 23 | #include 24 | #include "lv_mem.h" 25 | #include "lv_ll.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | 31 | #define LV_GC_ROOTS(prefix) \ 32 | prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \ 33 | prefix lv_ll_t _lv_scr_ll; /*Linked list of screens*/ \ 34 | prefix lv_ll_t _lv_drv_ll;\ 35 | prefix lv_ll_t _lv_file_ll;\ 36 | prefix lv_ll_t _lv_anim_ll;\ 37 | prefix void * _lv_def_scr;\ 38 | prefix void * _lv_act_scr;\ 39 | prefix void * _lv_top_layer;\ 40 | prefix void * _lv_sys_layer;\ 41 | prefix void * _lv_task_act;\ 42 | prefix void * _lv_indev_list;\ 43 | prefix void * _lv_disp_list;\ 44 | 45 | #define LV_NO_PREFIX 46 | #define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX) 47 | 48 | #if LV_ENABLE_GC == 1 49 | # if LV_MEM_CUSTOM != 1 50 | # error "GC requires CUSTOM_MEM" 51 | # endif /* LV_MEM_CUSTOM */ 52 | #else /* LV_ENABLE_GC */ 53 | # define LV_GC_ROOT(x) x 54 | LV_GC_ROOTS(extern) 55 | #endif /* LV_ENABLE_GC */ 56 | 57 | 58 | /********************** 59 | * TYPEDEFS 60 | **********************/ 61 | 62 | /********************** 63 | * GLOBAL PROTOTYPES 64 | **********************/ 65 | 66 | /********************** 67 | * MACROS 68 | **********************/ 69 | 70 | 71 | #ifdef __cplusplus 72 | } /* extern "C" */ 73 | #endif 74 | 75 | #endif /*LV_GC_H*/ 76 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_log.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_log.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "lv_log.h" 10 | #if USE_LV_LOG 11 | 12 | #if LV_LOG_PRINTF 13 | #include 14 | #include 15 | #include 16 | #include 17 | #endif 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * STATIC PROTOTYPES 28 | **********************/ 29 | 30 | /********************** 31 | * STATIC VARIABLES 32 | **********************/ 33 | static void (*print_cb)(lv_log_level_t, const char *, uint32_t, const char *); 34 | 35 | /********************** 36 | * MACROS 37 | **********************/ 38 | 39 | /********************** 40 | * GLOBAL FUNCTIONS 41 | **********************/ 42 | 43 | /** 44 | * Register custom print (or anything else) function to call when log is added 45 | * @param f a function pointer: 46 | * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` 47 | */ 48 | void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)) 49 | { 50 | print_cb = f; 51 | } 52 | 53 | /** 54 | * Add a log 55 | * @param level the level of log. (From `lv_log_level_t` enum) 56 | * @param file name of the file when the log added 57 | * @param line line number in the source code where the log added 58 | * @param dsc description of the log 59 | */ 60 | void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc) 61 | { 62 | if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/ 63 | 64 | if(level >= LV_LOG_LEVEL) { 65 | 66 | #if LV_LOG_PRINTF && defined(DEBUG_UART_PORT) 67 | static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"}; 68 | char *log = (char *)malloc(0x1000); 69 | s_printf(log, "%s: %s \t(%s #%d)\r\n", lvl_prefix[level], dsc, file, line); 70 | uart_send(DEBUG_UART_PORT, (u8 *)log, strlen(log) + 1); 71 | //gfx_printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line); 72 | #else 73 | if(print_cb) print_cb(level, file, line, dsc); 74 | #endif 75 | } 76 | } 77 | 78 | /********************** 79 | * STATIC FUNCTIONS 80 | **********************/ 81 | 82 | #endif /*USE_LV_LOG*/ 83 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_log.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_log.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LOG_H 7 | #define LV_LOG_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | #include 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/ 28 | 29 | #define LV_LOG_LEVEL_TRACE 0 /*A lot of logs to give detailed information*/ 30 | #define LV_LOG_LEVEL_INFO 1 /*Log important events*/ 31 | #define LV_LOG_LEVEL_WARN 2 /*Log if something unwanted happened but didn't caused problem*/ 32 | #define LV_LOG_LEVEL_ERROR 3 /*Only critical issue, when the system may fail*/ 33 | #define _LV_LOG_LEVEL_NUM 4 34 | 35 | typedef int8_t lv_log_level_t; 36 | 37 | #if USE_LV_LOG 38 | /********************** 39 | * TYPEDEFS 40 | **********************/ 41 | 42 | 43 | /********************** 44 | * GLOBAL PROTOTYPES 45 | **********************/ 46 | 47 | /** 48 | * Register custom print (or anything else) function to call when log is added 49 | * @param f a function pointer: 50 | * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` 51 | */ 52 | void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)); 53 | 54 | /** 55 | * Add a log 56 | * @param level the level of log. (From `lv_log_level_t` enum) 57 | * @param file name of the file when the log added 58 | * @param line line number in the source code where the log added 59 | * @param dsc description of the log 60 | */ 61 | void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc); 62 | 63 | /********************** 64 | * MACROS 65 | **********************/ 66 | 67 | #define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc); 68 | #define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc); 69 | #define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc); 70 | #define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc); 71 | 72 | #else /*USE_LV_LOG*/ 73 | 74 | /*Do nothing if `USE_LV_LOG 0`*/ 75 | #define lv_log_add(level, file, line, dsc) {;} 76 | #define LV_LOG_TRACE(dsc) {;} 77 | #define LV_LOG_INFO(dsc) {;} 78 | #define LV_LOG_WARN(dsc) {;} 79 | #define LV_LOG_ERROR(dsc) {;} 80 | #endif /*USE_LV_LOG*/ 81 | 82 | #ifdef __cplusplus 83 | } /* extern "C" */ 84 | #endif 85 | 86 | #endif /*LV_LOG_H*/ 87 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_math.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file math_base.h 3 | * 4 | */ 5 | 6 | #ifndef LV_MATH_H 7 | #define LV_MATH_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | #define LV_MATH_MIN(a,b) ((a) < (b) ? (a) : (b)) 23 | #define LV_MATH_MAX(a,b) ((a) > (b) ? (a) : (b)) 24 | #define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x))) 25 | 26 | #define LV_TRIGO_SIN_MAX 32767 27 | #define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/ 28 | 29 | #define LV_BEZIER_VAL_MAX 1024 /*Max time in Bezier functions (not [0..1] to use integers) */ 30 | #define LV_BEZIER_VAL_SHIFT 10 /*log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | /** 40 | * Convert a number to string 41 | * @param num a number 42 | * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) 43 | * @return same as `buf` (just for convenience) 44 | */ 45 | char * lv_math_num_to_str(int32_t num, char * buf); 46 | 47 | /** 48 | * Return with sinus of an angle 49 | * @param angle 50 | * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 51 | */ 52 | int16_t lv_trigo_sin(int16_t angle); 53 | 54 | /** 55 | * Calculate a value of a Cubic Bezier function. 56 | * @param t time in range of [0..LV_BEZIER_VAL_MAX] 57 | * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] 58 | * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] 59 | * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] 60 | * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] 61 | * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] 62 | */ 63 | int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3); 64 | 65 | /********************** 66 | * MACROS 67 | **********************/ 68 | 69 | #ifdef __cplusplus 70 | } /* extern "C" */ 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_mem.h 3 | * 4 | */ 5 | 6 | #ifndef LV_MEM_H 7 | #define LV_MEM_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #ifdef LV_CONF_INCLUDE_SIMPLE 18 | #include "lv_conf.h" 19 | #else 20 | #include "../../lv_conf.h" 21 | #endif 22 | 23 | #include 24 | #include 25 | #include "lv_log.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | // Check windows 31 | #ifdef __WIN64 32 | //# define LV_MEM_ENV64 33 | #endif 34 | 35 | // Check GCC 36 | #ifdef __GNUC__ 37 | # if defined(__x86_64__) || defined(__ppc64__) 38 | //# define LV_MEM_ENV64 39 | # endif 40 | #endif 41 | 42 | /********************** 43 | * TYPEDEFS 44 | **********************/ 45 | 46 | typedef struct 47 | { 48 | uint32_t total_size; 49 | uint32_t free_cnt; 50 | uint32_t free_size; 51 | uint32_t free_biggest_size; 52 | uint32_t used_cnt; 53 | uint8_t used_pct; 54 | uint8_t frag_pct; 55 | } lv_mem_monitor_t; 56 | 57 | /********************** 58 | * GLOBAL PROTOTYPES 59 | **********************/ 60 | 61 | 62 | /** 63 | * Initiaize the dyn_mem module (work memory and other variables) 64 | */ 65 | void lv_mem_init(void); 66 | 67 | /** 68 | * Allocate a memory dynamically 69 | * @param size size of the memory to allocate in bytes 70 | * @return pointer to the allocated memory 71 | */ 72 | void * lv_mem_alloc(uint32_t size); 73 | 74 | /** 75 | * Free an allocated data 76 | * @param data pointer to an allocated memory 77 | */ 78 | void lv_mem_free(const void * data); 79 | 80 | /** 81 | * Reallocate a memory with a new size. The old content will be kept. 82 | * @param data pointer to an allocated memory. 83 | * Its content will be copied to the new memory block and freed 84 | * @param new_size the desired new size in byte 85 | * @return pointer to the new memory 86 | */ 87 | void * lv_mem_realloc(void * data_p, uint32_t new_size); 88 | 89 | /** 90 | * Join the adjacent free memory blocks 91 | */ 92 | void lv_mem_defrag(void); 93 | 94 | /** 95 | * Give information about the work memory of dynamic allocation 96 | * @param mon_p pointer to a dm_mon_p variable, 97 | * the result of the analysis will be stored here 98 | */ 99 | void lv_mem_monitor(lv_mem_monitor_t * mon_p); 100 | 101 | /** 102 | * Give the size of an allocated memory 103 | * @param data pointer to an allocated memory 104 | * @return the size of data memory in bytes 105 | */ 106 | uint32_t lv_mem_get_size(const void * data); 107 | 108 | 109 | /********************** 110 | * MACROS 111 | **********************/ 112 | 113 | /** 114 | * Halt on NULL pointer 115 | * p pointer to a memory 116 | */ 117 | #if USE_LV_LOG == 0 118 | # define lv_mem_assert(p) {if(p == NULL) while(1); } 119 | #else 120 | # define lv_mem_assert(p) {if(p == NULL) {LV_LOG_ERROR("Out of memory!"); while(1); }} 121 | #endif 122 | #ifdef __cplusplus 123 | } /* extern "C" */ 124 | #endif 125 | 126 | #endif /*LV_MEM_H*/ 127 | 128 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_misc.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_font.c 2 | CSRCS += lv_circ.c 3 | CSRCS += lv_area.c 4 | CSRCS += lv_task.c 5 | CSRCS += lv_fs.c 6 | CSRCS += lv_anim.c 7 | CSRCS += lv_mem.c 8 | CSRCS += lv_ll.c 9 | CSRCS += lv_color.c 10 | CSRCS += lv_txt.c 11 | CSRCS += lv_ufs.c 12 | CSRCS += lv_math.c 13 | CSRCS += lv_log.c 14 | CSRCS += lv_gc.c 15 | 16 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_misc 17 | VPATH += :$(LVGL_DIR)/lvgl/lv_misc 18 | 19 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc" 20 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_templ.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | 10 | /********************* 11 | * DEFINES 12 | *********************/ 13 | 14 | /********************** 15 | * TYPEDEFS 16 | **********************/ 17 | 18 | /********************** 19 | * STATIC PROTOTYPES 20 | **********************/ 21 | 22 | /********************** 23 | * STATIC VARIABLES 24 | **********************/ 25 | 26 | /********************** 27 | * MACROS 28 | **********************/ 29 | 30 | /********************** 31 | * GLOBAL FUNCTIONS 32 | **********************/ 33 | 34 | /********************** 35 | * STATIC FUNCTIONS 36 | **********************/ 37 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEMPL_H 7 | #define LV_TEMPL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | 29 | /********************** 30 | * MACROS 31 | **********************/ 32 | 33 | 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif 37 | 38 | #endif /*LV_TEMPL_H*/ 39 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_objx/lv_arc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_arc.h 3 | * 4 | */ 5 | 6 | 7 | #ifndef LV_ARC_H 8 | #define LV_ARC_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #ifdef LV_CONF_INCLUDE_SIMPLE 18 | #include "lv_conf.h" 19 | #else 20 | #include "../../lv_conf.h" 21 | #endif 22 | 23 | #if USE_LV_ARC != 0 24 | 25 | #include "../lv_core/lv_obj.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | /*Data of arc*/ 35 | typedef struct { 36 | /*New data for this type */ 37 | lv_coord_t angle_start; 38 | lv_coord_t angle_end; 39 | } lv_arc_ext_t; 40 | 41 | 42 | /*Styles*/ 43 | enum { 44 | LV_ARC_STYLE_MAIN, 45 | }; 46 | typedef uint8_t lv_arc_style_t; 47 | 48 | 49 | 50 | /********************** 51 | * GLOBAL PROTOTYPES 52 | **********************/ 53 | 54 | /** 55 | * Create a arc objects 56 | * @param par pointer to an object, it will be the parent of the new arc 57 | * @param copy pointer to a arc object, if not NULL then the new object will be copied from it 58 | * @return pointer to the created arc 59 | */ 60 | lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy); 61 | 62 | /*====================== 63 | * Add/remove functions 64 | *=====================*/ 65 | 66 | 67 | /*===================== 68 | * Setter functions 69 | *====================*/ 70 | 71 | /** 72 | * Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc. 73 | * @param arc pointer to an arc object 74 | * @param start the start angle [0..360] 75 | * @param end the end angle [0..360] 76 | */ 77 | void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end); 78 | 79 | /** 80 | * Set a style of a arc. 81 | * @param arc pointer to arc object 82 | * @param type which style should be set 83 | * @param style pointer to a style 84 | * */ 85 | void lv_arc_set_style(lv_obj_t * arc, lv_arc_style_t type, lv_style_t *style); 86 | 87 | /*===================== 88 | * Getter functions 89 | *====================*/ 90 | 91 | /** 92 | * Get the start angle of an arc. 93 | * @param arc pointer to an arc object 94 | * @return the start angle [0..360] 95 | */ 96 | uint16_t lv_arc_get_angle_start(lv_obj_t * arc); 97 | 98 | /** 99 | * Get the end angle of an arc. 100 | * @param arc pointer to an arc object 101 | * @return the end angle [0..360] 102 | */ 103 | uint16_t lv_arc_get_angle_end(lv_obj_t * arc); 104 | 105 | /** 106 | * Get style of a arc. 107 | * @param arc pointer to arc object 108 | * @param type which style should be get 109 | * @return style pointer to the style 110 | * */ 111 | lv_style_t * lv_arc_get_style(const lv_obj_t * arc, lv_arc_style_t type); 112 | 113 | /*===================== 114 | * Other functions 115 | *====================*/ 116 | 117 | /********************** 118 | * MACROS 119 | **********************/ 120 | 121 | #endif /*USE_LV_ARC*/ 122 | 123 | #ifdef __cplusplus 124 | } /* extern "C" */ 125 | #endif 126 | 127 | #endif /*LV_ARC_H*/ 128 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_objx/lv_led.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_led.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LED_H 7 | #define LV_LED_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_LED != 0 23 | 24 | #include "../lv_core/lv_obj.h" 25 | 26 | /********************* 27 | * DEFINES 28 | *********************/ 29 | 30 | /********************** 31 | * TYPEDEFS 32 | **********************/ 33 | 34 | /*Data of led*/ 35 | typedef struct 36 | { 37 | /*No inherited ext.*/ 38 | /*New data for this type */ 39 | uint8_t bright; /*Current brightness of the LED (0..255)*/ 40 | } lv_led_ext_t; 41 | 42 | /********************** 43 | * GLOBAL PROTOTYPES 44 | **********************/ 45 | 46 | /** 47 | * Create a led objects 48 | * @param par pointer to an object, it will be the parent of the new led 49 | * @param copy pointer to a led object, if not NULL then the new object will be copied from it 50 | * @return pointer to the created led 51 | */ 52 | lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy); 53 | 54 | /** 55 | * Set the brightness of a LED object 56 | * @param led pointer to a LED object 57 | * @param bright 0 (max. dark) ... 255 (max. light) 58 | */ 59 | void lv_led_set_bright(lv_obj_t * led, uint8_t bright); 60 | 61 | /** 62 | * Light on a LED 63 | * @param led pointer to a LED object 64 | */ 65 | void lv_led_on(lv_obj_t * led); 66 | 67 | /** 68 | * Light off a LED 69 | * @param led pointer to a LED object 70 | */ 71 | void lv_led_off(lv_obj_t * led); 72 | 73 | /** 74 | * Toggle the state of a LED 75 | * @param led pointer to a LED object 76 | */ 77 | void lv_led_toggle(lv_obj_t * led); 78 | 79 | /** 80 | * Set the style of a led 81 | * @param led pointer to a led object 82 | * @param style pointer to a style 83 | */ 84 | static inline void lv_led_set_style(lv_obj_t *led, lv_style_t *style) 85 | { 86 | lv_obj_set_style(led, style); 87 | } 88 | 89 | /** 90 | * Get the brightness of a LEd object 91 | * @param led pointer to LED object 92 | * @return bright 0 (max. dark) ... 255 (max. light) 93 | */ 94 | uint8_t lv_led_get_bright(const lv_obj_t * led); 95 | 96 | /** 97 | * Get the style of an led object 98 | * @param led pointer to an led object 99 | * @return pointer to the led's style 100 | */ 101 | static inline lv_style_t* lv_led_get_style(const lv_obj_t *led) 102 | { 103 | return lv_obj_get_style(led); 104 | } 105 | 106 | /********************** 107 | * MACROS 108 | **********************/ 109 | 110 | #endif /*USE_LV_LED*/ 111 | 112 | #ifdef __cplusplus 113 | } /* extern "C" */ 114 | #endif 115 | 116 | #endif /*LV_LED_H*/ 117 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_objx/lv_objx.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_arc.c 2 | CSRCS += lv_bar.c 3 | CSRCS += lv_cb.c 4 | CSRCS += lv_ddlist.c 5 | CSRCS += lv_kb.c 6 | CSRCS += lv_line.c 7 | CSRCS += lv_mbox.c 8 | CSRCS += lv_preload.c 9 | CSRCS += lv_roller.c 10 | CSRCS += lv_table.c 11 | CSRCS += lv_tabview.c 12 | CSRCS += lv_tileview.c 13 | CSRCS += lv_btn.c 14 | CSRCS += lv_calendar.c 15 | CSRCS += lv_chart.c 16 | CSRCS += lv_canvas.c 17 | CSRCS += lv_gauge.c 18 | CSRCS += lv_label.c 19 | CSRCS += lv_list.c 20 | CSRCS += lv_slider.c 21 | CSRCS += lv_ta.c 22 | CSRCS += lv_spinbox.c 23 | CSRCS += lv_btnm.c 24 | CSRCS += lv_cont.c 25 | CSRCS += lv_img.c 26 | CSRCS += lv_imgbtn.c 27 | CSRCS += lv_led.c 28 | CSRCS += lv_lmeter.c 29 | CSRCS += lv_page.c 30 | CSRCS += lv_sw.c 31 | CSRCS += lv_win.c 32 | 33 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_objx 34 | VPATH += :$(LVGL_DIR)/lvgl/lv_objx 35 | 36 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_objx" 37 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_objx/lv_objx_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | 7 | /* TODO Remove these instructions 8 | * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) 9 | * templ -> object short name with lower case(e.g. btn, label etc) 10 | * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) 11 | * 12 | */ 13 | 14 | #ifndef LV_TEMPL_H 15 | #define LV_TEMPL_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /********************* 22 | * INCLUDES 23 | *********************/ 24 | #ifdef LV_CONF_INCLUDE_SIMPLE 25 | #include "lv_conf.h" 26 | #else 27 | #include "../../lv_conf.h" 28 | #endif 29 | 30 | #if USE_LV_TEMPL != 0 31 | 32 | #include "../lv_core/lv_obj.h" 33 | 34 | /********************* 35 | * DEFINES 36 | *********************/ 37 | 38 | /********************** 39 | * TYPEDEFS 40 | **********************/ 41 | /*Data of template*/ 42 | typedef struct { 43 | lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ 44 | /*New data for this type */ 45 | } lv_templ_ext_t; 46 | 47 | 48 | /*Styles*/ 49 | enum { 50 | LV_TEMPL_STYLE_X, 51 | LV_TEMPL_STYLE_Y, 52 | }; 53 | typedef uint8_t lv_templ_style_t; 54 | 55 | 56 | /********************** 57 | * GLOBAL PROTOTYPES 58 | **********************/ 59 | 60 | /** 61 | * Create a template objects 62 | * @param par pointer to an object, it will be the parent of the new template 63 | * @param copy pointer to a template object, if not NULL then the new object will be copied from it 64 | * @return pointer to the created template 65 | */ 66 | lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy); 67 | 68 | /*====================== 69 | * Add/remove functions 70 | *=====================*/ 71 | 72 | 73 | /*===================== 74 | * Setter functions 75 | *====================*/ 76 | 77 | /** 78 | * Set a style of a template. 79 | * @param templ pointer to template object 80 | * @param type which style should be set 81 | * @param style pointer to a style 82 | */ 83 | void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *style); 84 | 85 | /*===================== 86 | * Getter functions 87 | *====================*/ 88 | 89 | /** 90 | * Get style of a template. 91 | * @param templ pointer to template object 92 | * @param type which style should be get 93 | * @return style pointer to the style 94 | */ 95 | lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type); 96 | 97 | /*===================== 98 | * Other functions 99 | *====================*/ 100 | 101 | /********************** 102 | * MACROS 103 | **********************/ 104 | 105 | #endif /*USE_LV_TEMPL*/ 106 | 107 | #ifdef __cplusplus 108 | } /* extern "C" */ 109 | #endif 110 | 111 | #endif /*LV_TEMPL_H*/ 112 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_themes/lv_theme.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "lv_theme.h" 10 | #include "../lv_core/lv_obj.h" 11 | 12 | /********************* 13 | * DEFINES 14 | *********************/ 15 | 16 | /********************** 17 | * TYPEDEFS 18 | **********************/ 19 | 20 | /********************** 21 | * STATIC PROTOTYPES 22 | **********************/ 23 | 24 | /********************** 25 | * STATIC VARIABLES 26 | **********************/ 27 | 28 | #if LV_THEME_LIVE_UPDATE == 0 29 | static lv_theme_t * current_theme; 30 | #else 31 | /* 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. 32 | * On `lv_theme_set_current` the styles of the theme are copied to this array. 33 | * The pointers in `current_theme` are initialized to point to the styles in the array. 34 | * This way the theme styles will always point to the same memory address even after theme is change. 35 | * (The pointers in the theme points to the styles declared by the theme itself) */ 36 | 37 | /* Store the styles in this array. 38 | * Can't determine the size in compile time because sizeof is not evaluated (should be `sizeof(lv_theme_t) / sizeof(lv_style_t*)`). 39 | * Error will be generated in run time if too small.*/ 40 | static lv_style_t th_styles[120]; 41 | static bool inited = false; 42 | static lv_theme_t current_theme; 43 | #endif 44 | 45 | /********************** 46 | * MACROS 47 | **********************/ 48 | 49 | /********************** 50 | * GLOBAL FUNCTIONS 51 | **********************/ 52 | 53 | /** 54 | * Set a theme for the system. 55 | * From now, all the created objects will use styles from this theme by default 56 | * @param th pointer to theme (return value of: 'lv_theme_init_xxx()') 57 | */ 58 | void lv_theme_set_current(lv_theme_t * th) 59 | { 60 | #if LV_THEME_LIVE_UPDATE == 0 61 | current_theme = th; 62 | #else 63 | uint32_t style_num = sizeof(lv_theme_t) / sizeof(lv_style_t *); /*Number of styles in a theme*/ 64 | 65 | if(!inited) { 66 | /*It's not sure `th_styles` is big enough. Check it now!*/ 67 | if(style_num > sizeof(th_styles) / sizeof(lv_style_t)) { 68 | LV_LOG_ERROR("Themes: th_styles array is too small. Increase it's size!"); 69 | while(1); 70 | } 71 | 72 | /*Initialize the style pointers `current_theme` to point to the `th_styles` style array */ 73 | uint16_t i; 74 | lv_style_t ** cur_th_style_p = (lv_style_t **) ¤t_theme; 75 | for(i = 0; i < style_num; i++) { 76 | uintptr_t adr = (uintptr_t)&th_styles[i]; 77 | memcpy(&cur_th_style_p[i], &adr, sizeof(lv_style_t *)); 78 | } 79 | inited = true; 80 | } 81 | 82 | 83 | /*Copy the styles pointed by the new theme to the `th_styles` style array*/ 84 | uint16_t i; 85 | lv_style_t ** th_style = (lv_style_t **) th; 86 | for(i = 0; i < style_num; i++) { 87 | uintptr_t s = (uintptr_t)th_style[i]; 88 | if(s) memcpy(&th_styles[i], (void *)s, sizeof(lv_style_t)); 89 | } 90 | 91 | /*Let the object know their style might change*/ 92 | lv_obj_report_style_mod(NULL); 93 | #endif 94 | } 95 | 96 | /** 97 | * Get the current system theme. 98 | * @return pointer to the current system theme. NULL if not set. 99 | */ 100 | lv_theme_t * lv_theme_get_current(void) 101 | { 102 | #if LV_THEME_LIVE_UPDATE == 0 103 | return current_theme; 104 | #else 105 | if(!inited) return NULL; 106 | else return ¤t_theme; 107 | #endif 108 | } 109 | 110 | /********************** 111 | * STATIC FUNCTIONS 112 | **********************/ 113 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_themes/lv_theme_hekate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef LV_THEME_HEKATE_H 18 | #define LV_THEME_HEKATE_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /********************* 25 | * INCLUDES 26 | *********************/ 27 | #ifdef LV_CONF_INCLUDE_SIMPLE 28 | #include "lv_conf.h" 29 | #else 30 | #include "../../lv_conf.h" 31 | #endif 32 | 33 | #if USE_LV_THEME_HEKATE 34 | 35 | /********************* 36 | * DEFINES 37 | *********************/ 38 | 39 | /********************** 40 | * TYPEDEFS 41 | **********************/ 42 | 43 | /********************** 44 | * GLOBAL PROTOTYPES 45 | **********************/ 46 | 47 | /** 48 | * Initialize the material theme 49 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 50 | * @param font pointer to a font (NULL to use the default) 51 | * @return pointer to the initialized theme 52 | */ 53 | lv_theme_t * lv_theme_hekate_init(uint16_t hue, lv_font_t *font); 54 | 55 | /** 56 | * Get a pointer to the theme 57 | * @return pointer to the theme 58 | */ 59 | lv_theme_t * lv_theme_get_hekate(void); 60 | 61 | /********************** 62 | * MACROS 63 | **********************/ 64 | 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } /* extern "C" */ 69 | #endif 70 | 71 | #endif /*LV_THEME_MATERIAL_H*/ 72 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_themes/lv_themes.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_theme.c 2 | CSRCS += lv_theme_default.c 3 | CSRCS += lv_theme_templ.c 4 | CSRCS += lv_theme_material.c 5 | 6 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_themes 7 | VPATH += :$(LVGL_DIR)/lvgl/lv_themes 8 | 9 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_themes" 10 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_version.h 3 | * 4 | */ 5 | 6 | #ifndef LV_VERSION_H 7 | #define LV_VERSION_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | /*Current version of LittlevGL*/ 17 | #define LVGL_VERSION_MAJOR 5 18 | #define LVGL_VERSION_MINOR 3 19 | #define LVGL_VERSION_PATCH 0 20 | #define LVGL_VERSION_INFO "hekate" 21 | 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /********************** 28 | * TYPEDEFS 29 | **********************/ 30 | 31 | /********************** 32 | * GLOBAL PROTOTYPES 33 | **********************/ 34 | 35 | /********************** 36 | * MACROS 37 | **********************/ 38 | /* Gives 1 if the x.y.z version is supported in the current version 39 | * Usage: 40 | * 41 | * - Require v6 42 | * #if LV_VERSION_CHECK(6,0,0) 43 | * new_func_in_v6(); 44 | * #endif 45 | * 46 | * 47 | * - Require at least v5.3 48 | * #if LV_VERSION_CHECK(5,3,0) 49 | * new_feature_from_v5_3(); 50 | * #endif 51 | * 52 | * 53 | * - Require v5.3.2 bugfixes 54 | * #if LV_VERSION_CHECK(5,3,2) 55 | * bugfix_in_v5_3_2(); 56 | * #endif 57 | * 58 | * */ 59 | #define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) 60 | 61 | 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | #endif /*LV_VERSION_H*/ 67 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lvgl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lvgl.h 3 | * Include all LittleV GL related headers 4 | */ 5 | 6 | #ifndef LVGL_H 7 | #define LVGL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #include "lv_version.h" 18 | 19 | #include "lv_misc/lv_log.h" 20 | #include "lv_misc/lv_task.h" 21 | 22 | #include "lv_hal/lv_hal.h" 23 | 24 | #include "lv_core/lv_obj.h" 25 | #include "lv_core/lv_group.h" 26 | #include "lv_core/lv_lang.h" 27 | #include "lv_core/lv_vdb.h" 28 | #include "lv_core/lv_refr.h" 29 | 30 | #include "lv_themes/lv_theme.h" 31 | 32 | #include "lv_objx/lv_btn.h" 33 | #include "lv_objx/lv_imgbtn.h" 34 | #include "lv_objx/lv_img.h" 35 | #include "lv_objx/lv_label.h" 36 | #include "lv_objx/lv_line.h" 37 | #include "lv_objx/lv_page.h" 38 | #include "lv_objx/lv_cont.h" 39 | #include "lv_objx/lv_list.h" 40 | #include "lv_objx/lv_chart.h" 41 | #include "lv_objx/lv_table.h" 42 | #include "lv_objx/lv_cb.h" 43 | #include "lv_objx/lv_bar.h" 44 | #include "lv_objx/lv_slider.h" 45 | #include "lv_objx/lv_led.h" 46 | #include "lv_objx/lv_btnm.h" 47 | #include "lv_objx/lv_kb.h" 48 | #include "lv_objx/lv_ddlist.h" 49 | #include "lv_objx/lv_roller.h" 50 | #include "lv_objx/lv_ta.h" 51 | #include "lv_objx/lv_canvas.h" 52 | #include "lv_objx/lv_win.h" 53 | #include "lv_objx/lv_tabview.h" 54 | #include "lv_objx/lv_tileview.h" 55 | #include "lv_objx/lv_mbox.h" 56 | #include "lv_objx/lv_gauge.h" 57 | #include "lv_objx/lv_lmeter.h" 58 | #include "lv_objx/lv_sw.h" 59 | #include "lv_objx/lv_kb.h" 60 | #include "lv_objx/lv_arc.h" 61 | #include "lv_objx/lv_preload.h" 62 | #include "lv_objx/lv_calendar.h" 63 | #include "lv_objx/lv_spinbox.h" 64 | 65 | /********************* 66 | * DEFINES 67 | *********************/ 68 | 69 | /********************** 70 | * TYPEDEFS 71 | **********************/ 72 | 73 | /********************** 74 | * GLOBAL PROTOTYPES 75 | **********************/ 76 | 77 | /********************** 78 | * MACROS 79 | **********************/ 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /*LVGL_H*/ 86 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lvgl.mk: -------------------------------------------------------------------------------- 1 | include $(LVGL_DIR)/lvgl/lv_core/lv_core.mk 2 | include $(LVGL_DIR)/lvgl/lv_hal/lv_hal.mk 3 | include $(LVGL_DIR)/lvgl/lv_objx/lv_objx.mk 4 | include $(LVGL_DIR)/lvgl/lv_fonts/lv_fonts.mk 5 | include $(LVGL_DIR)/lvgl/lv_misc/lv_misc.mk 6 | include $(LVGL_DIR)/lvgl/lv_themes/lv_themes.mk 7 | include $(LVGL_DIR)/lvgl/lv_draw/lv_draw.mk 8 | 9 | -------------------------------------------------------------------------------- /bdk/mem/heap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2020 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _HEAP_H_ 19 | #define _HEAP_H_ 20 | 21 | #include 22 | 23 | typedef struct _hnode 24 | { 25 | int used; 26 | u32 size; 27 | struct _hnode *prev; 28 | struct _hnode *next; 29 | u32 align[4]; // Align to arch cache line size. 30 | } hnode_t; 31 | 32 | typedef struct _heap 33 | { 34 | u32 start; 35 | hnode_t *first; 36 | } heap_t; 37 | 38 | typedef struct 39 | { 40 | u32 total; 41 | u32 used; 42 | } heap_monitor_t; 43 | 44 | void heap_init(u32 base); 45 | void heap_copy(heap_t *heap); 46 | void *malloc(u32 size); 47 | void *calloc(u32 num, u32 size); 48 | void free(void *buf); 49 | void heap_monitor(heap_monitor_t *mon, bool print_node_stats); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /bdk/mem/mc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _MC_H_ 18 | #define _MC_H_ 19 | 20 | #include 21 | #include 22 | 23 | void mc_config_tsec_carveout(u32 bom, u32 size1mb, bool lock); 24 | void mc_config_carveout(); 25 | void mc_config_carveout_finalize(); 26 | void mc_enable_ahb_redirect(bool full_aperture); 27 | void mc_disable_ahb_redirect(); 28 | void mc_enable(); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /bdk/mem/minerva.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _FE_MINERVA_H_ 18 | #define _FE_MINERVA_H_ 19 | 20 | #include "mtc_table.h" 21 | #include 22 | 23 | #define MTC_INIT_MAGIC 0x3043544D 24 | #define MTC_NEW_MAGIC 0x5243544D 25 | 26 | #define EMC_PERIODIC_TRAIN_MS 250 27 | 28 | typedef struct 29 | { 30 | u32 rate_to; 31 | u32 rate_from; 32 | emc_table_t *mtc_table; 33 | u32 table_entries; 34 | emc_table_t *current_emc_table; 35 | u32 train_mode; 36 | u32 sdram_id; 37 | u32 prev_temp; 38 | bool emc_2X_clk_src_is_pllmb; 39 | bool fsp_for_src_freq; 40 | bool train_ram_patterns; 41 | bool init_done; 42 | } mtc_config_t; 43 | 44 | enum train_mode_t 45 | { 46 | OP_SWITCH = 0, 47 | OP_TRAIN = 1, 48 | OP_TRAIN_SWITCH = 2, 49 | OP_PERIODIC_TRAIN = 3, 50 | OP_TEMP_COMP = 4 51 | }; 52 | 53 | typedef enum 54 | { 55 | FREQ_204 = 204000, 56 | FREQ_666 = 665600, 57 | FREQ_800 = 800000, 58 | FREQ_1600 = 1600000 59 | } minerva_freq_t; 60 | 61 | extern void (*minerva_cfg)(mtc_config_t *mtc_cfg, void *); 62 | u32 minerva_init(); 63 | void minerva_change_freq(minerva_freq_t freq); 64 | void minerva_prep_boot_freq(); 65 | void minerva_prep_boot_l4t(); 66 | void minerva_periodic_training(); 67 | emc_table_t *minerva_get_mtc_table(); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /bdk/mem/smmu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | 19 | #define SMMU_HEAP_ADDR 0xA0000000 20 | 21 | #define MC_INTSTATUS 0x0 22 | #define MC_INTMASK 0x4 23 | #define MC_ERR_STATUS 0x8 24 | #define MC_ERR_ADR 0xc 25 | #define MC_SMMU_CONFIG 0x10 26 | #define MC_SMMU_TLB_CONFIG 0x14 27 | #define MC_SMMU_PTC_CONFIG 0x18 28 | #define MC_SMMU_PTB_ASID 0x1c 29 | #define MC_SMMU_PTB_DATA 0x20 30 | #define MC_SMMU_TLB_FLUSH 0x30 31 | #define MC_SMMU_PTC_FLUSH 0x34 32 | #define MC_SMMU_ASID_SECURITY 0x38 33 | #define MC_SMMU_AVPC_ASID 0x23C 34 | #define MC_SMMU_TSEC_ASID 0x294 35 | #define MC_SMMU_TRANSLATION_ENABLE_0 0x228 36 | #define MC_SMMU_TRANSLATION_ENABLE_1 0x22c 37 | #define MC_SMMU_TRANSLATION_ENABLE_2 0x230 38 | #define MC_SMMU_TRANSLATION_ENABLE_3 0x234 39 | #define MC_SMMU_TRANSLATION_ENABLE_4 0xb98 40 | 41 | #define SMMU_PDE_NEXT_SHIFT 28 42 | #define MC_SMMU_PTB_DATA_0_ASID_NONSECURE_SHIFT 29 43 | #define MC_SMMU_PTB_DATA_0_ASID_WRITABLE_SHIFT 30 44 | #define MC_SMMU_PTB_DATA_0_ASID_READABLE_SHIFT 31 45 | #define SMMU_PAGE_SHIFT 12 46 | #define SMMU_PAGE_SIZE (1 << SMMU_PAGE_SHIFT) 47 | #define SMMU_PDIR_COUNT 1024 48 | #define SMMU_PDIR_SIZE (sizeof(u32) * SMMU_PDIR_COUNT) 49 | #define SMMU_PTBL_COUNT 1024 50 | #define SMMU_PTBL_SIZE (sizeof(u32) * SMMU_PTBL_COUNT) 51 | #define SMMU_PDIR_SHIFT 12 52 | #define SMMU_PDE_SHIFT 12 53 | #define SMMU_PTE_SHIFT 12 54 | #define SMMU_PFN_MASK 0x000FFFFF 55 | #define SMMU_ADDR_TO_PFN(addr) ((addr) >> 12) 56 | #define SMMU_ADDR_TO_PDN(addr) ((addr) >> 22) 57 | #define SMMU_PDN_TO_ADDR(addr) ((pdn) << 22) 58 | #define _READABLE (1 << MC_SMMU_PTB_DATA_0_ASID_READABLE_SHIFT) 59 | #define _WRITABLE (1 << MC_SMMU_PTB_DATA_0_ASID_WRITABLE_SHIFT) 60 | #define _NONSECURE (1 << MC_SMMU_PTB_DATA_0_ASID_NONSECURE_SHIFT) 61 | #define _PDE_NEXT (1 << SMMU_PDE_NEXT_SHIFT) 62 | #define _MASK_ATTR (_READABLE | _WRITABLE | _NONSECURE) 63 | #define _PDIR_ATTR (_READABLE | _WRITABLE | _NONSECURE) 64 | #define _PDE_ATTR (_READABLE | _WRITABLE | _NONSECURE) 65 | #define _PDE_VACANT(pdn) (((pdn) << 10) | _PDE_ATTR) 66 | #define _PTE_ATTR (_READABLE | _WRITABLE | _NONSECURE) 67 | #define _PTE_VACANT(addr) (((addr) >> SMMU_PAGE_SHIFT) | _PTE_ATTR) 68 | #define SMMU_MK_PDIR(page, attr) (((page) >> SMMU_PDIR_SHIFT) | (attr)) 69 | #define SMMU_MK_PDE(page, attr) (((page) >> SMMU_PDE_SHIFT) | (attr)) 70 | 71 | void *page_alloc(u32 num); 72 | u32 *smmu_alloc_pdir(); 73 | void smmu_flush_regs(); 74 | void smmu_flush_all(); 75 | void smmu_init(u32 secmon_base); 76 | void smmu_enable(); 77 | bool smmu_is_used(); 78 | void smmu_exit(); 79 | u32 *smmu_init_domain4(u32 dev_base, u32 asid); 80 | u32 *smmu_get_pte(u32 *pdir, u32 iova); 81 | void smmu_map(u32 *pdir, u32 addr, u32 page, int cnt, u32 attr); 82 | u32 *smmu_init_for_tsec(); 83 | void smmu_deinit_for_tsec(); 84 | -------------------------------------------------------------------------------- /bdk/module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Common Module Header 3 | * Copyright (c) 2018 M4xw 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _MODULE_H_ 19 | #define _MODULE_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define IANOS_EXT0 0x304E4149 25 | 26 | // Module Callback 27 | typedef void (*cbMainModule_t)(const char *s); 28 | typedef void (*memcpy_t)(void *, void *, size_t); 29 | typedef void (*memset_t)(void *, int, size_t); 30 | typedef int (*reg_voltage_set_t)(u32, u32); 31 | 32 | typedef struct _bdkParams_t 33 | { 34 | void *gfxCon; 35 | void *gfxCtx; 36 | heap_t *sharedHeap; 37 | memcpy_t memcpy; 38 | memset_t memset; 39 | u32 extension_magic; 40 | reg_voltage_set_t reg_voltage_set; 41 | } *bdkParams_t; 42 | 43 | // Module Entrypoint 44 | typedef void (*moduleEntrypoint_t)(void *, bdkParams_t); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /bdk/power/bm92t36.c: -------------------------------------------------------------------------------- 1 | /* 2 | * USB-PD driver for Nintendo Switch's TI BM92T36 3 | * 4 | * Copyright (c) 2020 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include "bm92t36.h" 22 | #include 23 | #include 24 | 25 | #define ALERT_STATUS_REG 0x2 26 | #define STATUS1_REG 0x3 27 | #define STATUS2_REG 0x4 28 | #define COMMAND_REG 0x5 29 | #define CONFIG1_REG 0x6 30 | #define DEV_CAPS_REG 0x7 31 | #define READ_PDOS_SRC_REG 0x8 32 | #define CONFIG2_REG 0x17 33 | #define DP_STATUS_REG 0x18 34 | #define DP_ALERT_EN_REG 0x19 35 | #define VENDOR_CONFIG_REG 0x1A 36 | #define AUTO_NGT_FIXED_REG 0x20 37 | #define AUTO_NGT_BATT_REG 0x23 38 | #define SYS_CONFIG1_REG 0x26 39 | #define SYS_CONFIG2_REG 0x27 40 | #define CURRENT_PDO_REG 0x28 41 | #define CURRENT_RDO_REG 0x2B 42 | #define ALERT_ENABLE_REG 0x2E 43 | #define SYS_CONFIG3_REG 0x2F 44 | #define SET_RDO_REG 0x30 45 | #define PDOS_SNK_REG 0x33 46 | #define PDOS_SRC_PROV_REG 0x3C 47 | #define FW_TYPE_REG 0x4B 48 | #define FW_REVISION_REG 0x4C 49 | #define MAN_ID_REG 0x4D 50 | #define DEV_ID_REG 0x4E 51 | #define REV_ID_REG 0x4F 52 | #define INCOMING_VDM_REG 0x50 53 | #define OUTGOING_VDM_REG 0x60 54 | 55 | #define STATUS1_INSERT BIT(7) // Cable inserted. 56 | 57 | typedef struct _pd_object_t { 58 | unsigned int amp:10; 59 | unsigned int volt:10; 60 | unsigned int info:10; 61 | unsigned int type:2; 62 | } __attribute__((packed)) pd_object_t; 63 | 64 | static int _bm92t36_read_reg(u8 *buf, u32 size, u32 reg) 65 | { 66 | return i2c_recv_buf_big(buf, size, I2C_1, BM92T36_I2C_ADDR, reg); 67 | } 68 | 69 | void bm92t36_get_sink_info(bool *inserted, usb_pd_objects_t *usb_pd) 70 | { 71 | u8 buf[32]; 72 | pd_object_t pdos[7]; 73 | 74 | if (inserted) 75 | { 76 | _bm92t36_read_reg(buf, 2, STATUS1_REG); 77 | *inserted = buf[0] & STATUS1_INSERT ? true : false; 78 | } 79 | 80 | if (usb_pd) 81 | { 82 | _bm92t36_read_reg(buf, 29, READ_PDOS_SRC_REG); 83 | memcpy(pdos, &buf[1], 28); 84 | 85 | memset(usb_pd, 0, sizeof(usb_pd_objects_t)); 86 | usb_pd->pdo_no = buf[0] / sizeof(pd_object_t); 87 | 88 | for (u32 i = 0; i < usb_pd->pdo_no; i++) 89 | { 90 | usb_pd->pdos[i].amperage = pdos[i].amp * 10; 91 | usb_pd->pdos[i].voltage = (pdos[i].volt * 50) / 1000; 92 | } 93 | 94 | _bm92t36_read_reg(buf, 5, CURRENT_PDO_REG); 95 | memcpy(pdos, &buf[1], 4); 96 | usb_pd->selected_pdo.amperage = pdos[0].amp * 10; 97 | usb_pd->selected_pdo.voltage = (pdos[0].volt * 50) / 1000; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /bdk/power/bm92t36.h: -------------------------------------------------------------------------------- 1 | /* 2 | * USB-PD driver for Nintendo Switch's TI BM92T36 3 | * 4 | * Copyright (c) 2020 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __BM92T36_H_ 20 | #define __BM92T36_H_ 21 | 22 | #include 23 | 24 | #define BM92T36_I2C_ADDR 0x18 25 | 26 | typedef struct _usb_pd_object_t 27 | { 28 | u32 amperage; 29 | u32 voltage; 30 | } usb_pd_object_t; 31 | 32 | typedef struct _usb_pd_objects_t 33 | { 34 | u32 pdo_no; 35 | usb_pd_object_t pdos[7]; 36 | usb_pd_object_t selected_pdo; 37 | } usb_pd_objects_t; 38 | 39 | void bm92t36_get_sink_info(bool *inserted, usb_pd_objects_t *usb_pd); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /bdk/power/regulator_5v.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _REGULATOR_5V_H_ 18 | #define _REGULATOR_5V_H_ 19 | 20 | #include 21 | 22 | enum 23 | { 24 | REGULATOR_5V_FAN = BIT(0), 25 | REGULATOR_5V_JC_R = BIT(1), 26 | REGULATOR_5V_JC_L = BIT(2), 27 | REGULATOR_5V_ALL = 0xFF 28 | }; 29 | 30 | void regulator_5v_enable(u8 dev); 31 | void regulator_5v_disable(u8 dev); 32 | bool regulator_5v_get_dev_enabled(u8 dev); 33 | void regulator_5v_usb_src_enable(bool enable); 34 | 35 | #endif -------------------------------------------------------------------------------- /bdk/rtc/max77620-rtc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PMIC Real Time Clock driver for Nintendo Switch's MAX77620-RTC 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _MFD_MAX77620_RTC_H_ 20 | #define _MFD_MAX77620_RTC_H_ 21 | 22 | #include 23 | 24 | #define MAX77620_RTC_I2C_ADDR 0x68 25 | 26 | #define MAX77620_RTC_NR_TIME_REGS 7 27 | 28 | #define MAX77620_RTC_CONTROLM_REG 0x02 29 | #define MAX77620_RTC_CONTROL_REG 0x03 30 | #define MAX77620_RTC_BIN_FORMAT BIT(0) 31 | #define MAX77620_RTC_24H BIT(1) 32 | 33 | #define MAX77620_RTC_UPDATE0_REG 0x04 34 | #define MAX77620_RTC_WRITE_UPDATE BIT(0) 35 | #define MAX77620_RTC_READ_UPDATE BIT(4) 36 | 37 | #define MAX77620_RTC_SEC_REG 0x07 38 | #define MAX77620_RTC_MIN_REG 0x08 39 | #define MAX77620_RTC_HOUR_REG 0x09 40 | #define MAX77620_RTC_HOUR_PM_MASK BIT(6) 41 | #define MAX77620_RTC_WEEKDAY_REG 0x0A 42 | #define MAX77620_RTC_MONTH_REG 0x0B 43 | #define MAX77620_RTC_YEAR_REG 0x0C 44 | #define MAX77620_RTC_DATE_REG 0x0D 45 | 46 | #define MAX77620_ALARM1_SEC_REG 0x0E 47 | #define MAX77620_ALARM1_MIN_REG 0x0F 48 | #define MAX77620_ALARM1_HOUR_REG 0x10 49 | #define MAX77620_ALARM1_WEEKDAY_REG 0x11 50 | #define MAX77620_ALARM1_MONTH_REG 0x12 51 | #define MAX77620_ALARM1_YEAR_REG 0x13 52 | #define MAX77620_ALARM1_DATE_REG 0x14 53 | #define MAX77620_ALARM2_SEC_REG 0x15 54 | #define MAX77620_ALARM2_MIN_REG 0x16 55 | #define MAX77620_ALARM2_HOUR_REG 0x17 56 | #define MAX77620_ALARM2_WEEKDAY_REG 0x18 57 | #define MAX77620_ALARM2_MONTH_REG 0x19 58 | #define MAX77620_ALARM2_YEAR_REG 0x1A 59 | #define MAX77620_ALARM2_DATE_REG 0x1B 60 | #define MAX77620_RTC_ALARM_EN_MASK BIT(7) 61 | 62 | typedef struct _rtc_time_t { 63 | u8 weekday; 64 | u8 sec; 65 | u8 min; 66 | u8 hour; 67 | u8 day; 68 | u8 month; 69 | u16 year; 70 | } rtc_time_t; 71 | 72 | void max77620_rtc_get_time(rtc_time_t *time); 73 | void max77620_rtc_stop_alarm(); 74 | void max77620_rtc_epoch_to_date(u32 epoch, rtc_time_t *time); 75 | u32 max77620_rtc_date_to_epoch(const rtc_time_t *time); 76 | 77 | #endif /* _MFD_MAX77620_RTC_H_ */ 78 | -------------------------------------------------------------------------------- /bdk/sec/se.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019-2022 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _SE_H_ 19 | #define _SE_H_ 20 | 21 | #include "se_t210.h" 22 | #include 23 | 24 | void se_rsa_acc_ctrl(u32 rs, u32 flags); 25 | void se_key_acc_ctrl(u32 ks, u32 flags); 26 | u32 se_key_acc_ctrl_get(u32 ks); 27 | void se_get_aes_keys(u8 *buf, u8 *keys, u32 keysize); 28 | void se_aes_key_set(u32 ks, void *key, u32 size); 29 | void se_aes_iv_set(u32 ks, void *iv); 30 | void se_aes_key_get(u32 ks, void *key, u32 size); 31 | void se_aes_key_clear(u32 ks); 32 | void se_aes_iv_clear(u32 ks); 33 | int se_aes_unwrap_key(u32 ks_dst, u32 ks_src, const void *input); 34 | int se_aes_crypt_cbc(u32 ks, u32 enc, void *dst, u32 dst_size, const void *src, u32 src_size); 35 | int se_aes_crypt_ecb(u32 ks, u32 enc, void *dst, u32 dst_size, const void *src, u32 src_size); 36 | int se_aes_crypt_block_ecb(u32 ks, u32 enc, void *dst, const void *src); 37 | int se_aes_xts_crypt_sec(u32 tweak_ks, u32 crypt_ks, u32 enc, u64 sec, void *dst, void *src, u32 secsize); 38 | int se_aes_xts_crypt_sec_nx(u32 tweak_ks, u32 crypt_ks, u32 enc, u64 sec, u8 *tweak, bool regen_tweak, u32 tweak_exp, void *dst, void *src, u32 sec_size); 39 | int se_aes_xts_crypt(u32 tweak_ks, u32 crypt_ks, u32 enc, u64 sec, void *dst, void *src, u32 secsize, u32 num_secs); 40 | int se_aes_crypt_ctr(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size, void *ctr); 41 | int se_calc_sha256(void *hash, u32 *msg_left, const void *src, u32 src_size, u64 total_size, u32 sha_cfg, bool is_oneshot); 42 | int se_calc_sha256_oneshot(void *hash, const void *src, u32 src_size); 43 | int se_calc_sha256_finalize(void *hash, u32 *msg_left); 44 | int se_gen_prng128(void *dst); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /bdk/sec/tsec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _TSEC_H_ 19 | #define _TSEC_H_ 20 | 21 | #include 22 | 23 | enum tsec_fw_type 24 | { 25 | // Retail Hovi Keygen. 26 | TSEC_FW_TYPE_OLD = 0, // 1.0.0 - 6.1.0. 27 | TSEC_FW_TYPE_EMU = 1, // 6.2.0 emulated enviroment. 28 | TSEC_FW_TYPE_NEW = 2, // 7.0.0+. 29 | }; 30 | 31 | typedef struct _tsec_ctxt_t 32 | { 33 | void *fw; 34 | u32 size; 35 | u32 type; 36 | void *pkg1; 37 | u32 pkg11_off; 38 | u32 secmon_base; 39 | } tsec_ctxt_t; 40 | 41 | int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /bdk/sec/tsec_t210.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _TSEC_T210_H_ 18 | #define _TSEC_T210_H_ 19 | 20 | #define TSEC_BOOTKEYVER 0x1040 21 | #define TSEC_STATUS 0x1044 22 | #define TSEC_ITFEN 0x1048 23 | #define TSEC_ITFEN_CTXEN BIT(0) 24 | #define TSEC_ITFEN_MTHDEN BIT(1) 25 | #define TSEC_IRQMSET 0x1010 26 | #define TSEC_IRQMSET_WDTMR BIT(1) 27 | #define TSEC_IRQMSET_HALT BIT(4) 28 | #define TSEC_IRQMSET_EXTERR BIT(5) 29 | #define TSEC_IRQMSET_SWGEN0 BIT(6) 30 | #define TSEC_IRQMSET_SWGEN1 BIT(7) 31 | #define TSEC_IRQMSET_EXT(val) (((val) & 0xFF) << 8) 32 | #define TSEC_IRQDEST 0x101C 33 | #define TSEC_IRQDEST_HALT BIT(4) 34 | #define TSEC_IRQDEST_EXTERR BIT(5) 35 | #define TSEC_IRQDEST_SWGEN0 BIT(6) 36 | #define TSEC_IRQDEST_SWGEN1 BIT(7) 37 | #define TSEC_IRQDEST_EXT(val) (((val) & 0xFF) << 8) 38 | #define TSEC_CPUCTL 0x1100 39 | #define TSEC_CPUCTL_STARTCPU BIT(1) 40 | #define TSEC_BOOTVEC 0x1104 41 | #define TSEC_DMACTL 0x110C 42 | #define TSEC_DMATRFBASE 0x1110 43 | #define TSEC_DMATRFMOFFS 0x1114 44 | #define TSEC_DMATRFCMD 0x1118 45 | #define TSEC_DMATRFCMD_IDLE BIT(1) 46 | #define TSEC_DMATRFCMD_IMEM BIT(4) 47 | #define TSEC_DMATRFCMD_SIZE_256B (6 << 8) 48 | #define TSEC_DMATRFFBOFFS 0x111C 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /bdk/soc/actmon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Activity Monitor driver for Tegra X1 3 | * 4 | * Copyright (c) 2021 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __ACTMON_H_ 20 | #define __ACTMON_H_ 21 | 22 | #include 23 | 24 | typedef enum _actmon_dev_t 25 | { 26 | ACTMON_DEV_CPU, 27 | ACTMON_DEV_BPMP, 28 | ACTMON_DEV_AHB, 29 | ACTMON_DEV_APB, 30 | ACTMON_DEV_CPU_FREQ, 31 | ACTMON_DEV_MC_ALL, 32 | ACTMON_DEV_MC_CPU, 33 | 34 | ACTMON_DEV_NUM, 35 | } actmon_dev_t; 36 | 37 | typedef enum _actmon_hist_src_t 38 | { 39 | ACTMON_HIST_SRC_NONE = 0, 40 | ACTMON_HIST_SRC_AHB = 1, 41 | ACTMON_HIST_SRC_APB = 2, 42 | ACTMON_HIST_SRC_BPMP = 3, 43 | ACTMON_HIST_SRC_CPU = 4, 44 | ACTMON_HIST_SRC_MC_ALL = 5, 45 | ACTMON_HIST_SRC_MC_CPU = 6, 46 | ACTMON_HIST_SRC_CPU_FREQ = 7, 47 | ACTMON_HIST_SRC_NA = 8, 48 | ACTMON_HIST_SRC_APB_MMIO = 9, 49 | } actmon_hist_src_t; 50 | 51 | void actmon_hist_enable(actmon_hist_src_t src); 52 | void actmon_hist_disable(); 53 | void actmon_hist_get(u32 *histogram); 54 | void actmon_dev_enable(actmon_dev_t dev); 55 | void actmon_dev_disable(actmon_dev_t dev); 56 | u32 actmon_dev_get_load(actmon_dev_t dev); 57 | u32 actmon_dev_get_load_avg(actmon_dev_t dev); 58 | void atmon_dev_all_disable(); 59 | void actmon_init(); 60 | void actmon_end(); 61 | 62 | #endif -------------------------------------------------------------------------------- /bdk/soc/bpmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BPMP-Lite Cache/MMU and Frequency driver for Tegra X1 3 | * 4 | * Copyright (c) 2019-2021 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _BPMP_H_ 20 | #define _BPMP_H_ 21 | 22 | #include 23 | 24 | typedef enum 25 | { 26 | BPMP_MMU_MAINT_NOP = 0, 27 | BPMP_MMU_MAINT_CLEAN_PHY = 1, 28 | BPMP_MMU_MAINT_INVALID_PHY = 2, 29 | BPMP_MMU_MAINT_CLEAN_INVALID_PHY = 3, 30 | BPMP_MMU_MAINT_CLEAN_LINE = 9, 31 | BPMP_MMU_MAINT_INVALID_LINE = 10, 32 | BPMP_MMU_MAINT_CLEAN_INVALID_LINE = 11, 33 | BPMP_MMU_MAINT_CLEAN_WAY = 17, 34 | BPMP_MMU_MAINT_INVALID_WAY = 18, 35 | BPMP_MMU_MAINT_CLN_INV_WAY = 19 36 | } bpmp_maintenance_t; 37 | 38 | typedef struct _bpmp_mmu_entry_t 39 | { 40 | u32 start_addr; 41 | u32 end_addr; 42 | u32 attr; 43 | u32 enable; 44 | } bpmp_mmu_entry_t; 45 | 46 | typedef enum 47 | { 48 | BPMP_CLK_NORMAL, // 408MHz 0% - 136MHz APB. 49 | BPMP_CLK_HIGH_BOOST, // 544MHz 33% - 136MHz APB. 50 | BPMP_CLK_SUPER_BOOST, // 576MHz 41% - 144MHz APB. 51 | BPMP_CLK_HYPER_BOOST, // 589MHz 44% - 147MHz APB. 52 | //BPMP_CLK_DEV_BOOST, // 608MHz 49% - 152MHz APB. 53 | BPMP_CLK_MAX 54 | } bpmp_freq_t; 55 | 56 | #define BPMP_CLK_LOWER_BOOST BPMP_CLK_SUPER_BOOST 57 | #define BPMP_CLK_DEFAULT_BOOST BPMP_CLK_HYPER_BOOST 58 | 59 | void bpmp_mmu_maintenance(u32 op, bool force); 60 | void bpmp_mmu_set_entry(int idx, bpmp_mmu_entry_t *entry, bool apply); 61 | void bpmp_mmu_enable(); 62 | void bpmp_mmu_disable(); 63 | void bpmp_clk_rate_get(); 64 | bpmp_freq_t bpmp_clk_rate_set(bpmp_freq_t fid); 65 | void bpmp_usleep(u32 us); 66 | void bpmp_msleep(u32 ms); 67 | void bpmp_halt(); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /bdk/soc/ccplex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _CCPLEX_H_ 18 | #define _CCPLEX_H_ 19 | 20 | #include 21 | 22 | void ccplex_boot_cpu0(u32 entry); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /bdk/soc/fuse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018 shuffle2 4 | * Copyright (c) 2018 balika011 5 | * Copyright (c) 2019-2021 CTCaer 6 | * 7 | * This program is free software; you can redistribute it and/or modify it 8 | * under the terms and conditions of the GNU General Public License, 9 | * version 2, as published by the Free Software Foundation. 10 | * 11 | * This program is distributed in the hope it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _FUSE_H_ 21 | #define _FUSE_H_ 22 | 23 | #include 24 | 25 | /*! Fuse registers. */ 26 | #define FUSE_CTRL 0x0 27 | #define FUSE_ADDR 0x4 28 | #define FUSE_RDATA 0x8 29 | #define FUSE_WDATA 0xC 30 | #define FUSE_TIME_RD1 0x10 31 | #define FUSE_TIME_RD2 0x14 32 | #define FUSE_TIME_PGM1 0x18 33 | #define FUSE_TIME_PGM2 0x1C 34 | #define FUSE_PRIV2INTFC 0x20 35 | #define FUSE_FUSEBYPASS 0x24 36 | #define FUSE_PRIVATEKEYDISABLE 0x28 37 | #define FUSE_DISABLEREGPROGRAM 0x2C 38 | #define FUSE_WRITE_ACCESS_SW 0x30 39 | #define FUSE_PWR_GOOD_SW 0x34 40 | 41 | /*! Fuse Cached registers */ 42 | #define FUSE_SKU_INFO 0x110 43 | #define FUSE_CPU_SPEEDO_0_CALIB 0x114 44 | #define FUSE_CPU_IDDQ_CALIB 0x118 45 | #define FUSE_OPT_FT_REV 0x128 46 | #define FUSE_CPU_SPEEDO_1_CALIB 0x12C 47 | #define FUSE_CPU_SPEEDO_2_CALIB 0x130 48 | #define FUSE_SOC_SPEEDO_0_CALIB 0x134 49 | #define FUSE_SOC_SPEEDO_1_CALIB 0x138 50 | #define FUSE_SOC_SPEEDO_2_CALIB 0x13C 51 | #define FUSE_SOC_IDDQ_CALIB 0x140 52 | #define FUSE_OPT_CP_REV 0x190 53 | #define FUSE_FIRST_BOOTROM_PATCH_SIZE 0x19c 54 | #define FUSE_PRIVATE_KEY0 0x1A4 55 | #define FUSE_PRIVATE_KEY1 0x1A8 56 | #define FUSE_PRIVATE_KEY2 0x1AC 57 | #define FUSE_PRIVATE_KEY3 0x1B0 58 | #define FUSE_PRIVATE_KEY4 0x1B4 59 | #define FUSE_RESERVED_SW 0x1C0 60 | #define FUSE_USB_CALIB 0x1F0 61 | #define FUSE_SKU_DIRECT_CONFIG 0x1F4 62 | #define FUSE_OPT_VENDOR_CODE 0x200 63 | #define FUSE_OPT_FAB_CODE 0x204 64 | #define FUSE_OPT_LOT_CODE_0 0x208 65 | #define FUSE_OPT_LOT_CODE_1 0x20C 66 | #define FUSE_OPT_WAFER_ID 0x210 67 | #define FUSE_OPT_X_COORDINATE 0x214 68 | #define FUSE_OPT_Y_COORDINATE 0x218 69 | #define FUSE_OPT_OPS_RESERVED 0x220 70 | #define FUSE_GPU_IDDQ_CALIB 0x228 71 | #define FUSE_USB_CALIB_EXT 0x350 72 | #define FUSE_RESERVED_FIELD 0x354 73 | 74 | #define FUSE_RESERVED_ODM28_T210B01 0x240 75 | 76 | /*! Fuse commands. */ 77 | #define FUSE_READ 0x1 78 | #define FUSE_WRITE 0x2 79 | #define FUSE_SENSE 0x3 80 | #define FUSE_CMD_MASK 0x3 81 | 82 | /*! Fuse cache registers. */ 83 | #define FUSE_RESERVED_ODMX(x) (0x1C8 + 4 * (x)) 84 | 85 | enum 86 | { 87 | FUSE_NX_HW_TYPE_ICOSA, 88 | FUSE_NX_HW_TYPE_IOWA, 89 | FUSE_NX_HW_TYPE_HOAG, 90 | FUSE_NX_HW_TYPE_AULA 91 | }; 92 | 93 | enum 94 | { 95 | FUSE_NX_HW_STATE_PROD, 96 | FUSE_NX_HW_STATE_DEV 97 | }; 98 | 99 | void fuse_disable_program(); 100 | u32 fuse_read_odm(u32 idx); 101 | u32 fuse_read_odm_keygen_rev(); 102 | u32 fuse_read_dramid(bool raw_id); 103 | u32 fuse_read_hw_state(); 104 | u32 fuse_read_hw_type(); 105 | int fuse_set_sbk(); 106 | void fuse_wait_idle(); 107 | int fuse_read_ipatch(void (*ipatch)(u32 offset, u32 value)); 108 | int fuse_read_evp_thunk(u32 *iram_evp_thunks, u32 *iram_evp_thunks_len); 109 | void fuse_read_array(u32 *words); 110 | bool fuse_check_patched_rcm(); 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /bdk/soc/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _GPIO_H_ 19 | #define _GPIO_H_ 20 | 21 | #include 22 | 23 | #define GPIO_MODE_SPIO 0 24 | #define GPIO_MODE_GPIO 1 25 | 26 | #define GPIO_OUTPUT_DISABLE 0 27 | #define GPIO_OUTPUT_ENABLE 1 28 | 29 | #define GPIO_IRQ_DISABLE 0 30 | #define GPIO_IRQ_ENABLE 1 31 | 32 | #define GPIO_LOW 0 33 | #define GPIO_HIGH 1 34 | #define GPIO_FALLING 0 35 | #define GPIO_RISING 1 36 | 37 | #define GPIO_LEVEL 0 38 | #define GPIO_EDGE 1 39 | 40 | #define GPIO_CONFIGURED_EDGE 0 41 | #define GPIO_ANY_EDGE_CHANGE 1 42 | 43 | /*! GPIO pins (0-7 for each port). */ 44 | #define GPIO_PIN_0 BIT(0) 45 | #define GPIO_PIN_1 BIT(1) 46 | #define GPIO_PIN_2 BIT(2) 47 | #define GPIO_PIN_3 BIT(3) 48 | #define GPIO_PIN_4 BIT(4) 49 | #define GPIO_PIN_5 BIT(5) 50 | #define GPIO_PIN_6 BIT(6) 51 | #define GPIO_PIN_7 BIT(7) 52 | 53 | /*! GPIO ports (A-EE). */ 54 | #define GPIO_PORT_A 0 55 | #define GPIO_PORT_B 1 56 | #define GPIO_PORT_C 2 57 | #define GPIO_PORT_D 3 58 | #define GPIO_PORT_E 4 59 | #define GPIO_PORT_F 5 60 | #define GPIO_PORT_G 6 61 | #define GPIO_PORT_H 7 62 | #define GPIO_PORT_I 8 63 | #define GPIO_PORT_J 9 64 | #define GPIO_PORT_K 10 65 | #define GPIO_PORT_L 11 66 | #define GPIO_PORT_M 12 67 | #define GPIO_PORT_N 13 68 | #define GPIO_PORT_O 14 69 | #define GPIO_PORT_P 15 70 | #define GPIO_PORT_Q 16 71 | #define GPIO_PORT_R 17 72 | #define GPIO_PORT_S 18 73 | #define GPIO_PORT_T 19 74 | #define GPIO_PORT_U 20 75 | #define GPIO_PORT_V 21 76 | #define GPIO_PORT_W 22 77 | #define GPIO_PORT_X 23 78 | #define GPIO_PORT_Y 24 79 | #define GPIO_PORT_Z 25 80 | #define GPIO_PORT_AA 26 81 | #define GPIO_PORT_BB 27 82 | #define GPIO_PORT_CC 28 83 | #define GPIO_PORT_DD 29 84 | #define GPIO_PORT_EE 30 85 | 86 | void gpio_config(u32 port, u32 pins, int mode); 87 | void gpio_output_enable(u32 port, u32 pins, int enable); 88 | void gpio_write(u32 port, u32 pins, int high); 89 | int gpio_read(u32 port, u32 pins); 90 | int gpio_interrupt_status(u32 port, u32 pins); 91 | void gpio_interrupt_enable(u32 port, u32 pins, int enable); 92 | void gpio_interrupt_level(u32 port, u32 pins, int high, int edge, int delta); 93 | u32 gpio_get_bank_irq_id(u32 port); 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /bdk/soc/hw_init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _HW_INIT_H_ 19 | #define _HW_INIT_H_ 20 | 21 | #include 22 | 23 | #define BL_MAGIC_CRBOOT_SLD 0x30444C53 // SLD0, seamless display type 0. 24 | #define BL_MAGIC_HEKATF_SLD 0x31444C53 // SLD1, seamless display type 1. 25 | #define BL_MAGIC_BROKEN_HWI 0xBAADF00D // Broken hwinit. 26 | 27 | extern u32 hw_rst_status; 28 | extern u32 hw_rst_reason; 29 | 30 | void hw_init(); 31 | void hw_reinit_workaround(bool coreboot, u32 magic); 32 | u32 hw_get_chip_id(); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /bdk/soc/i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2020 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _I2C_H_ 19 | #define _I2C_H_ 20 | 21 | #include 22 | 23 | #define I2C_1 0 24 | #define I2C_2 1 25 | #define I2C_3 2 26 | #define I2C_4 3 27 | #define I2C_5 4 28 | #define I2C_6 5 29 | 30 | void i2c_init(u32 i2c_idx); 31 | int i2c_recv_buf(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr); 32 | int i2c_send_buf_big(u32 i2c_idx, u32 dev_addr, u8 *buf, u32 size); 33 | int i2c_recv_buf_big(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg); 34 | int i2c_send_buf_small(u32 i2c_idx, u32 dev_addr, u32 reg, u8 *buf, u32 size); 35 | int i2c_recv_buf_small(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg); 36 | int i2c_send_byte(u32 i2c_idx, u32 dev_addr, u32 reg, u8 val); 37 | u8 i2c_recv_byte(u32 i2c_idx, u32 dev_addr, u32 reg); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /bdk/soc/kfuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | int kfuse_wait_ready() 22 | { 23 | // Wait for KFUSE to finish init and verification of data. 24 | while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE)) 25 | ; 26 | 27 | if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS)) 28 | return 0; 29 | 30 | return 1; 31 | } 32 | 33 | int kfuse_read(u32 *buf) 34 | { 35 | int res = 0; 36 | 37 | clock_enable_kfuse(); 38 | 39 | if (!kfuse_wait_ready()) 40 | goto out; 41 | 42 | KFUSE(KFUSE_KEYADDR) = KFUSE_KEYADDR_AUTOINC; 43 | for (int i = 0; i < KFUSE_NUM_WORDS; i++) 44 | buf[i] = KFUSE(KFUSE_KEYS); 45 | 46 | res = 1; 47 | 48 | out: 49 | clock_disable_kfuse(); 50 | return res; 51 | } 52 | -------------------------------------------------------------------------------- /bdk/soc/kfuse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _KFUSE_H_ 18 | #define _KFUSE_H_ 19 | 20 | #include 21 | 22 | #define KFUSE_STATE_CURBLOCK_MASK 0x3F 23 | #define KFUSE_STATE_ERRBLOCK_SHIFT 8 24 | #define KFUSE_STATE_ERRBLOCK_MASK 0x3F00 25 | #define KFUSE_STATE_DONE BIT(16) 26 | #define KFUSE_STATE_CRCPASS BIT(17) 27 | #define KFUSE_STATE_RESTART BIT(24) 28 | #define KFUSE_STATE_STOP BIT(25) 29 | #define KFUSE_STATE_SOFTRESET BIT(31) 30 | 31 | #define KFUSE_KEYADDR_AUTOINC BIT(16) 32 | 33 | #define KFUSE_STATE 0x80 34 | #define KFUSE_KEYADDR 0x88 35 | #define KFUSE_KEYS 0x8C 36 | 37 | #define KFUSE_NUM_WORDS 144 38 | 39 | int kfuse_wait_ready(); 40 | int kfuse_read(u32 *buf); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /bdk/soc/pinmux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | void pinmux_config_uart(u32 idx) 21 | { 22 | PINMUX_AUX(PINMUX_AUX_UARTX_TX(idx)) = 0; 23 | PINMUX_AUX(PINMUX_AUX_UARTX_RX(idx)) = PINMUX_INPUT_ENABLE | PINMUX_PULL_UP; 24 | PINMUX_AUX(PINMUX_AUX_UARTX_RTS(idx)) = 0; 25 | PINMUX_AUX(PINMUX_AUX_UARTX_CTS(idx)) = PINMUX_INPUT_ENABLE | PINMUX_PULL_DOWN; 26 | } 27 | 28 | void pinmux_config_i2c(u32 idx) 29 | { 30 | PINMUX_AUX(PINMUX_AUX_X_I2C_SCL(idx)) = PINMUX_INPUT_ENABLE; 31 | PINMUX_AUX(PINMUX_AUX_X_I2C_SDA(idx)) = PINMUX_INPUT_ENABLE; 32 | } 33 | -------------------------------------------------------------------------------- /bdk/soc/uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019-2020 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _UART_H_ 19 | #define _UART_H_ 20 | 21 | #include 22 | 23 | #define UART_A 0 24 | #define UART_B 1 25 | #define UART_C 2 26 | #define UART_D 3 27 | #define UART_E 4 28 | 29 | #define BAUD_115200 115200 30 | 31 | #define UART_TX_IDLE 0x1 32 | #define UART_RX_IDLE 0x2 33 | 34 | #define UART_TX_FIFO_FULL 0x100 35 | #define UART_RX_FIFO_EMPTY 0x200 36 | 37 | #define UART_INVERT_RXD 0x01 38 | #define UART_INVERT_TXD 0x02 39 | #define UART_INVERT_CTS 0x04 40 | #define UART_INVERT_RTS 0x08 41 | 42 | #define UART_IER_DLAB_IE_EORD 0x20 43 | 44 | #define UART_LCR_DLAB 0x80 45 | #define UART_LCR_STOP 0x4 46 | #define UART_LCR_WORD_LENGTH_8 0x3 47 | 48 | #define UART_LSR_RDR 0x1 49 | #define UART_LSR_THRE 0x20 50 | #define UART_LSR_TMTY 0x40 51 | #define UART_LSR_FIFOE 0x80 52 | 53 | #define UART_IIR_FCR_TX_CLR 0x4 54 | #define UART_IIR_FCR_RX_CLR 0x2 55 | #define UART_IIR_FCR_EN_FIFO 0x1 56 | 57 | #define UART_IIR_NO_INT BIT(0) 58 | #define UART_IIR_INT_MASK 0xF 59 | /* Custom returned interrupt results. Actual interrupts are -1 */ 60 | #define UART_IIR_NOI 0 // No interrupt. 61 | #define UART_IIR_MSI 1 // Modem status interrupt. 62 | #define UART_IIR_THRI 2 // Transmitter holding register empty. 63 | #define UART_IIR_RDI 3 // Receiver data interrupt. 64 | #define UART_IIR_ERROR 4 // Overrun Error, Parity Error, Framing Error, Break. 65 | #define UART_IIR_REDI 5 // Receiver end of data interrupt. 66 | #define UART_IIR_RDTI 7 // Receiver data timeout interrupt. 67 | 68 | #define UART_MCR_RTS 0x2 69 | #define UART_MCR_DTR 0x1 70 | 71 | typedef struct _uart_t 72 | { 73 | /* 0x00 */ vu32 UART_THR_DLAB; 74 | /* 0x04 */ vu32 UART_IER_DLAB; 75 | /* 0x08 */ vu32 UART_IIR_FCR; 76 | /* 0x0C */ vu32 UART_LCR; 77 | /* 0x10 */ vu32 UART_MCR; 78 | /* 0x14 */ vu32 UART_LSR; 79 | /* 0x18 */ vu32 UART_MSR; 80 | /* 0x1C */ vu32 UART_SPR; 81 | /* 0x20 */ vu32 UART_IRDA_CSR; 82 | /* 0x24 */ vu32 UART_RX_FIFO_CFG; 83 | /* 0x28 */ vu32 UART_MIE; 84 | /* 0x2C */ vu32 UART_VENDOR_STATUS; 85 | /* 0x30 */ u8 _pad_30[0xC]; 86 | /* 0x3C */ vu32 UART_ASR; 87 | } uart_t; 88 | 89 | void uart_init(u32 idx, u32 baud); 90 | void uart_wait_idle(u32 idx, u32 which); 91 | void uart_send(u32 idx, const u8 *buf, u32 len); 92 | u32 uart_recv(u32 idx, u8 *buf, u32 len); 93 | void uart_invert(u32 idx, bool enable, u32 invert_mask); 94 | u32 uart_get_IIR(u32 idx); 95 | void uart_set_IIR(u32 idx); 96 | void uart_empty_fifo(u32 idx, u32 which); 97 | #ifdef DEBUG_UART_PORT 98 | void uart_print(const char *fmt, ...); 99 | #endif 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /bdk/storage/emmc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019-2022 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _EMMC_H_ 19 | #define _EMMC_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #define GPT_FIRST_LBA 1 28 | #define GPT_NUM_BLOCKS 33 29 | #define EMMC_BLOCKSIZE 512 30 | 31 | enum 32 | { 33 | EMMC_INIT_FAIL = 0, 34 | EMMC_1BIT_HS52 = 1, 35 | EMMC_8BIT_HS52 = 2, 36 | EMMC_MMC_HS200 = 3, 37 | EMMC_MMC_HS400 = 4, 38 | }; 39 | 40 | enum 41 | { 42 | EMMC_ERROR_INIT_FAIL = 0, 43 | EMMC_ERROR_RW_FAIL = 1, 44 | EMMC_ERROR_RW_RETRY = 2 45 | }; 46 | 47 | typedef struct _emmc_part_t 48 | { 49 | u32 index; 50 | u32 lba_start; 51 | u32 lba_end; 52 | u64 attrs; 53 | char name[37]; 54 | link_t link; 55 | } emmc_part_t; 56 | 57 | extern sdmmc_t emmc_sdmmc; 58 | extern sdmmc_storage_t emmc_storage; 59 | extern FATFS emmc_fs; 60 | 61 | void emmc_error_count_increment(u8 type); 62 | u16 *emmc_get_error_count(); 63 | u32 emmc_get_mode(); 64 | int emmc_init_retry(bool power_cycle); 65 | bool emmc_initialize(bool power_cycle); 66 | 67 | void emmc_gpt_parse(link_t *gpt); 68 | void emmc_gpt_free(link_t *gpt); 69 | emmc_part_t *emmc_part_find(link_t *gpt, const char *name); 70 | int emmc_part_read(emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf); 71 | int emmc_part_write(emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf); 72 | 73 | void nx_emmc_get_autorcm_masks(u8 *mod0, u8 *mod1); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /bdk/storage/mbr_gpt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef MBR_GPT_H 19 | #define MBR_GPT_H 20 | 21 | #include 22 | 23 | typedef struct _mbr_chs_t 24 | { 25 | u8 head; 26 | u8 sector; 27 | u8 cylinder; 28 | } __attribute__((packed)) mbr_chs_t; 29 | 30 | typedef struct _mbr_part_t 31 | { 32 | u8 status; 33 | mbr_chs_t start_sct_chs; 34 | u8 type; 35 | mbr_chs_t end_sct_chs; 36 | u32 start_sct; 37 | u32 size_sct; 38 | } __attribute__((packed)) mbr_part_t; 39 | 40 | typedef struct _mbr_t 41 | { 42 | u8 bootstrap[440]; 43 | u32 signature; 44 | u16 copy_protected; 45 | mbr_part_t partitions[4]; 46 | u16 boot_signature; 47 | } __attribute__((packed)) mbr_t; 48 | 49 | typedef struct _gpt_entry_t 50 | { 51 | u8 type_guid[0x10]; 52 | u8 part_guid[0x10]; 53 | u64 lba_start; 54 | u64 lba_end; 55 | u64 attrs; 56 | u16 name[36]; 57 | } gpt_entry_t; 58 | 59 | typedef struct _gpt_header_t 60 | { 61 | u64 signature; // "EFI PART" 62 | u32 revision; 63 | u32 size; 64 | u32 crc32; 65 | u32 res1; 66 | u64 my_lba; 67 | u64 alt_lba; 68 | u64 first_use_lba; 69 | u64 last_use_lba; 70 | u8 disk_guid[0x10]; 71 | u64 part_ent_lba; 72 | u32 num_part_ents; 73 | u32 part_ent_size; 74 | u32 part_ents_crc32; 75 | u8 res2[420]; // Used as first 3 partition entries backup for HOS. 76 | } gpt_header_t; 77 | 78 | typedef struct _gpt_t 79 | { 80 | gpt_header_t header; 81 | gpt_entry_t entries[128]; 82 | } gpt_t; 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /bdk/storage/ramdisk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Ramdisk driver for Tegra X1 3 | * 4 | * Copyright (c) 2019-2021 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include "ramdisk.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | static u32 disk_size = 0; 30 | 31 | int ram_disk_init(void *ram_fs, u32 ramdisk_size) 32 | { 33 | int res = 0; 34 | disk_size = ramdisk_size; 35 | FATFS *ram_fatfs = (FATFS *)ram_fs; 36 | 37 | // If ramdisk is not raw, format it. 38 | if (ram_fs) 39 | { 40 | u8 *buf = malloc(0x400000); 41 | 42 | // Set ramdisk size. 43 | ramdisk_size >>= 9; 44 | disk_set_info(DRIVE_RAM, SET_SECTOR_COUNT, &ramdisk_size); 45 | 46 | // Unmount ramdisk. 47 | f_mount(NULL, "ram:", 1); 48 | 49 | // Format as exFAT w/ 32KB cluster with no MBR. 50 | res = f_mkfs("ram:", FM_EXFAT | FM_SFD, RAMDISK_CLUSTER_SZ, buf, 0x400000); 51 | 52 | // Mount ramdisk. 53 | if (!res) 54 | res = f_mount(ram_fatfs, "ram:", 1); 55 | 56 | free(buf); 57 | } 58 | 59 | return res; 60 | } 61 | 62 | int ram_disk_read(u32 sector, u32 sector_count, void *buf) 63 | { 64 | u32 sector_off = RAM_DISK_ADDR + (sector << 9); 65 | u32 bytes_count = sector_count << 9; 66 | 67 | if ((sector_off - RAM_DISK_ADDR) > disk_size) 68 | return 1; 69 | 70 | memcpy(buf, (void *)sector_off, bytes_count); 71 | 72 | return 0; 73 | } 74 | 75 | int ram_disk_write(u32 sector, u32 sector_count, const void *buf) 76 | { 77 | u32 sector_off = RAM_DISK_ADDR + (sector << 9); 78 | u32 bytes_count = sector_count << 9; 79 | 80 | if ((sector_off - RAM_DISK_ADDR) > disk_size) 81 | return 1; 82 | 83 | memcpy((void *)sector_off, buf, bytes_count); 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /bdk/storage/ramdisk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ramdisk driver for Tegra X1 3 | * 4 | * Copyright (c) 2019-2021 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef RAM_DISK_H 20 | #define RAM_DISK_H 21 | 22 | #include 23 | 24 | #define RAMDISK_CLUSTER_SZ 32768 25 | 26 | int ram_disk_init(void *ram_fs, u32 ramdisk_size); 27 | int ram_disk_read(u32 sector, u32 sector_count, void *buf); 28 | int ram_disk_write(u32 sector, u32 sector_count, const void *buf); 29 | 30 | #endif -------------------------------------------------------------------------------- /bdk/storage/sd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef SD_H 19 | #define SD_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | enum 26 | { 27 | SD_INIT_FAIL = 0, 28 | SD_1BIT_HS25 = 1, 29 | SD_4BIT_HS25 = 2, 30 | SD_UHS_SDR82 = 3, 31 | SD_UHS_SDR104 = 4 32 | }; 33 | 34 | enum 35 | { 36 | SD_ERROR_INIT_FAIL = 0, 37 | SD_ERROR_RW_FAIL = 1, 38 | SD_ERROR_RW_RETRY = 2 39 | }; 40 | 41 | extern sdmmc_t sd_sdmmc; 42 | extern sdmmc_storage_t sd_storage; 43 | extern FATFS sd_fs; 44 | 45 | void sd_error_count_increment(u8 type); 46 | u16 *sd_get_error_count(); 47 | bool sd_get_card_removed(); 48 | bool sd_get_card_initialized(); 49 | bool sd_get_card_mounted(); 50 | u32 sd_get_mode(); 51 | int sd_init_retry(bool power_cycle); 52 | bool sd_initialize(bool power_cycle); 53 | bool sd_mount(); 54 | void sd_unmount(); 55 | void sd_end(); 56 | bool sd_is_gpt(); 57 | void *sd_file_read(const char *path, u32 *fsize); 58 | int sd_save_to_file(void *buf, u32 size, const char *filename); 59 | 60 | #endif -------------------------------------------------------------------------------- /bdk/storage/sdmmc_t210.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2019 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _SDMMC_T210_H_ 19 | #define _SDMMC_T210_H_ 20 | 21 | #include 22 | 23 | #define TEGRA_MMC_VNDR_TUN_CTRL0_TAP_VAL_UPDATED_BY_HW 0x20000 24 | #define TEGRA_MMC_DLLCAL_CFG_EN_CALIBRATE 0x80000000 25 | #define TEGRA_MMC_DLLCAL_CFG_STATUS_DLL_ACTIVE 0x80000000 26 | #define TEGRA_MMC_SDMEMCOMPPADCTRL_PAD_E_INPUT_PWRD 0x80000000 27 | #define TEGRA_MMC_SDMEMCOMPPADCTRL_COMP_VREF_SEL_MASK 0xFFFFFFF0 28 | #define TEGRA_MMC_AUTOCALCFG_AUTO_CAL_ENABLE 0x20000000 29 | #define TEGRA_MMC_AUTOCALCFG_AUTO_CAL_START 0x80000000 30 | #define TEGRA_MMC_AUTOCALSTS_AUTO_CAL_ACTIVE 0x80000000 31 | 32 | typedef struct _t210_sdmmc_t 33 | { 34 | vu32 sysad; 35 | vu16 blksize; 36 | vu16 blkcnt; 37 | vu32 argument; 38 | vu16 trnmod; 39 | vu16 cmdreg; 40 | vu32 rspreg0; 41 | vu32 rspreg1; 42 | vu32 rspreg2; 43 | vu32 rspreg3; 44 | vu32 bdata; 45 | vu32 prnsts; 46 | vu8 hostctl; 47 | vu8 pwrcon; 48 | vu8 blkgap; 49 | vu8 wakcon; 50 | vu16 clkcon; 51 | vu8 timeoutcon; 52 | vu8 swrst; 53 | vu16 norintsts; 54 | vu16 errintsts; 55 | vu16 norintstsen; // Enable irq status. 56 | vu16 errintstsen; // Enable irq status. 57 | vu16 norintsigen; // Enable irq signal to LIC/GIC. 58 | vu16 errintsigen; // Enable irq signal to LIC/GIC. 59 | vu16 acmd12errsts; 60 | vu16 hostctl2; 61 | vu32 capareg; 62 | vu32 capareg_1; 63 | vu32 maxcurr; 64 | vu8 rsvd0[4]; // 4C-4F reserved for more max current. 65 | vu16 setacmd12err; 66 | vu16 setinterr; 67 | vu8 admaerr; 68 | vu8 rsvd1[3]; // 55-57 reserved. 69 | vu32 admaaddr; 70 | vu32 admaaddr_hi; 71 | vu8 rsvd2[156]; // 60-FB reserved. 72 | vu16 slotintsts; 73 | vu16 hcver; 74 | vu32 venclkctl; 75 | vu32 vensysswctl; 76 | vu32 venerrintsts; 77 | vu32 vencapover; 78 | vu32 venbootctl; 79 | vu32 venbootacktout; 80 | vu32 venbootdattout; 81 | vu32 vendebouncecnt; 82 | vu32 venmiscctl; 83 | vu32 maxcurrover; 84 | vu32 maxcurrover_hi; 85 | vu32 unk0[32]; // 0x12C 86 | vu32 veniotrimctl; 87 | vu32 vendllcalcfg; 88 | vu32 vendllctl0; 89 | vu32 vendllctl1; 90 | vu32 vendllcalcfgsts; 91 | vu32 ventunctl0; 92 | vu32 ventunctl1; 93 | vu32 ventunsts0; 94 | vu32 ventunsts1; 95 | vu32 venclkgatehystcnt; 96 | vu32 venpresetval0; 97 | vu32 venpresetval1; 98 | vu32 venpresetval2; 99 | vu32 sdmemcmppadctl; 100 | vu32 autocalcfg; 101 | vu32 autocalintval; 102 | vu32 autocalsts; 103 | vu32 iospare; 104 | vu32 mcciffifoctl; 105 | vu32 timeoutwcoal; 106 | vu32 unk1; 107 | } t210_sdmmc_t; 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /bdk/thermal/fan.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Fan driver for Nintendo Switch 3 | * 4 | * Copyright (c) 2018-2021 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | void set_fan_duty(u32 duty) 28 | { 29 | static bool fan_init = false; 30 | static u16 curr_duty = -1; 31 | 32 | if (duty > 236) 33 | duty = 236; 34 | 35 | if (curr_duty == duty) 36 | return; 37 | 38 | curr_duty = duty; 39 | 40 | //! TODO: Add HOAG/AULA support. 41 | u32 hw_type = fuse_read_hw_type(); 42 | if (hw_type != FUSE_NX_HW_TYPE_ICOSA && 43 | hw_type != FUSE_NX_HW_TYPE_IOWA) 44 | return; 45 | 46 | if (!fan_init) 47 | { 48 | // Fan tachometer. 49 | PINMUX_AUX(PINMUX_AUX_CAM1_PWDN) = PINMUX_TRISTATE | PINMUX_INPUT_ENABLE | PINMUX_PULL_UP | 1; 50 | gpio_config(GPIO_PORT_S, GPIO_PIN_7, GPIO_MODE_GPIO); 51 | gpio_output_enable(GPIO_PORT_S, GPIO_PIN_7, GPIO_OUTPUT_DISABLE); 52 | 53 | PWM(PWM_CONTROLLER_PWM_CSR_1) = PWM_CSR_EN | (0x100 << 16); // Max PWM to disable fan. 54 | 55 | PINMUX_AUX(PINMUX_AUX_LCD_GPIO2) = 1; // Set source to PWM1. 56 | gpio_config(GPIO_PORT_V, GPIO_PIN_4, GPIO_MODE_SPIO); // Fan power mode. 57 | 58 | fan_init = true; 59 | } 60 | 61 | // Inverted polarity. 62 | u32 inv_duty = 236 - duty; 63 | 64 | // If disabled send a 0 duty. 65 | if (inv_duty == 236) 66 | { 67 | PWM(PWM_CONTROLLER_PWM_CSR_1) = PWM_CSR_EN | (0x100 << 16); // Bit 24 is absolute 0%. 68 | regulator_5v_disable(REGULATOR_5V_FAN); 69 | 70 | // Disable fan. 71 | PINMUX_AUX(PINMUX_AUX_LCD_GPIO2) = 72 | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_TRISTATE | PINMUX_PULL_DOWN; // Set source to PWM1. 73 | } 74 | else // Set PWM duty. 75 | { 76 | // Fan power supply. 77 | regulator_5v_enable(REGULATOR_5V_FAN); 78 | PWM(PWM_CONTROLLER_PWM_CSR_1) = PWM_CSR_EN | (inv_duty << 16); 79 | 80 | // Enable fan. 81 | PINMUX_AUX(PINMUX_AUX_LCD_GPIO2) = 1; // Set source to PWM1. 82 | } 83 | } 84 | 85 | void get_fan_speed(u32 *duty, u32 *rpm) 86 | { 87 | if (rpm) 88 | { 89 | u32 irq_count = 0; 90 | bool should_read = true; 91 | 92 | // Poll irqs for 2 seconds. (5 seconds for accurate count). 93 | int timer = get_tmr_us() + 2000000; 94 | while ((timer - get_tmr_us()) > 0) 95 | { 96 | bool irq_val = gpio_read(GPIO_PORT_S, GPIO_PIN_7); 97 | if (irq_val && should_read) 98 | { 99 | irq_count++; 100 | should_read = false; 101 | } 102 | else if (!irq_val) 103 | should_read = true; 104 | } 105 | 106 | // Halve the irq count. 107 | irq_count /= 2; 108 | 109 | // Calculate rpm based on triggered interrupts. 110 | *rpm = irq_count * (60 / 2); 111 | } 112 | 113 | if (duty) 114 | *duty = 236 - ((PWM(PWM_CONTROLLER_PWM_CSR_1) >> 16) & 0xFF); 115 | } 116 | -------------------------------------------------------------------------------- /bdk/thermal/fan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fan driver for Nintendo Switch 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __FAN_H_ 20 | #define __FAN_H_ 21 | 22 | #include 23 | 24 | // Disable: 0 (0 RPM), min duty: 1 (960 RPM), max duty 235 (11000 RPM). 25 | void set_fan_duty(u32 duty); 26 | // Passing NULL ptr on either of the two, disables parsing of it. 27 | void get_fan_speed(u32 *duty, u32 *rpm); 28 | 29 | #endif /* __FAN_H_ */ 30 | -------------------------------------------------------------------------------- /bdk/thermal/tmp451.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SOC/PCB Temperature driver for Nintendo Switch's TI TMP451 3 | * 4 | * Copyright (c) 2018-2020 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | u16 tmp451_get_soc_temp(bool intenger) 25 | { 26 | u8 val; 27 | u16 temp = 0; 28 | 29 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TEMP_REG); 30 | if (intenger) 31 | return val; 32 | 33 | temp = val << 8; 34 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_DEC_REG); 35 | temp |= ((val >> 4) * 625) / 100; 36 | 37 | return temp; 38 | } 39 | 40 | u16 tmp451_get_pcb_temp(bool intenger) 41 | { 42 | u8 val; 43 | u16 temp = 0; 44 | 45 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_PCB_TEMP_REG); 46 | if (intenger) 47 | return val; 48 | 49 | temp = val << 8; 50 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_PCB_TMP_DEC_REG); 51 | temp |= ((val >> 4) * 625) / 100; 52 | 53 | return temp; 54 | } 55 | 56 | void tmp451_init() 57 | { 58 | // Disable ALARM and Range to 0 - 127 oC. 59 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CONFIG_REG, 0x80); 60 | 61 | // Set remote sensor offsets based on SoC. 62 | if (hw_get_chip_id() == GP_HIDREV_MAJOR_T210) 63 | { 64 | // Set offset to 0 oC for Erista. 65 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_OFH_REG, 0); 66 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_OFL_REG, 0); 67 | } 68 | else 69 | { 70 | // Set offset to -12.5 oC for Mariko. 71 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_OFH_REG, 0xF3); // - 13 oC. 72 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_OFL_REG, 0x80); // + 0.5 oC. 73 | } 74 | 75 | // Set conversion rate to 32/s and make a read to update the reg. 76 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CNV_RATE_REG, 9); 77 | tmp451_get_soc_temp(false); 78 | 79 | // Set rate to every 4 seconds. 80 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CNV_RATE_REG, 2); 81 | } 82 | 83 | void tmp451_end() 84 | { 85 | // Place into shutdown mode to conserve power. 86 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CONFIG_REG, 0xC0); 87 | } 88 | -------------------------------------------------------------------------------- /bdk/thermal/tmp451.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SOC/PCB Temperature driver for Nintendo Switch's TI TMP451 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __TMP451_H_ 20 | #define __TMP451_H_ 21 | 22 | #include 23 | 24 | #define TMP451_I2C_ADDR 0x4C 25 | 26 | #define TMP451_PCB_TEMP_REG 0x00 27 | #define TMP451_SOC_TEMP_REG 0x01 28 | 29 | #define TMP451_CONFIG_REG 0x09 30 | #define TMP451_CNV_RATE_REG 0x0A 31 | 32 | #define TMP451_SOC_TMP_DEC_REG 0x10 33 | #define TMP451_PCB_TMP_DEC_REG 0x15 34 | 35 | #define TMP451_SOC_TMP_OFH_REG 0x11 36 | #define TMP451_SOC_TMP_OFL_REG 0x12 37 | 38 | // If input is false, the return value is packed. MSByte is the integer in oC 39 | // and the LSByte is the decimal point truncated to 2 decimal places. 40 | // Otherwise it's an integer oC. 41 | u16 tmp451_get_soc_temp(bool integer); 42 | u16 tmp451_get_pcb_temp(bool integer); 43 | void tmp451_init(); 44 | void tmp451_end(); 45 | 46 | #endif /* __TMP451_H_ */ 47 | -------------------------------------------------------------------------------- /bdk/utils/aarch64_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _ARM64_H_ 19 | #define _ARM64_H_ 20 | 21 | #include 22 | 23 | #define LSL0 0 24 | #define LSL16 16 25 | #define LSL32 32 26 | 27 | #define _PAGEOFF(x) ((x) & 0xFFFFF000) 28 | 29 | #define _ADRP(r, o) (0x90000000 | ((((o) >> 12) & 0x3) << 29) | ((((o) >> 12) & 0x1FFFFC) << 3) | ((r) & 0x1F)) 30 | #define _BL(a, o) (0x94000000 | ((((o) - (a)) >> 2) & 0x3FFFFFF)) 31 | #define _B(a, o) (0x14000000 | ((((o) - (a)) >> 2) & 0x3FFFFFF)) 32 | #define _MOVKX(r, i, s) (0xF2800000 | (((s) & 0x30) << 17) | (((i) & 0xFFFF) << 5) | ((r) & 0x1F)) 33 | #define _MOVZX(r, i, s) (0xD2800000 | (((s) & 0x30) << 17) | (((i) & 0xFFFF) << 5) | ((r) & 0x1F)) 34 | #define _MOVZW(r, i, s) (0x52800000 | (((s) & 0x30) << 17) | (((i) & 0xFFFF) << 5) | ((r) & 0x1F)) 35 | #define _NOP() 0xD503201F 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /bdk/utils/btn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2022 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "btn.h" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | u8 btn_read() 26 | { 27 | u8 res = 0; 28 | if (!gpio_read(GPIO_PORT_X, GPIO_PIN_7)) 29 | res |= BTN_VOL_DOWN; 30 | if (!gpio_read(GPIO_PORT_X, GPIO_PIN_6)) 31 | res |= BTN_VOL_UP; 32 | if (i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFSTAT) & MAX77620_ONOFFSTAT_EN0) 33 | res |= BTN_POWER; 34 | return res; 35 | } 36 | 37 | u8 btn_read_vol() 38 | { 39 | u8 res = 0; 40 | if (!gpio_read(GPIO_PORT_X, GPIO_PIN_7)) 41 | res |= BTN_VOL_DOWN; 42 | if (!gpio_read(GPIO_PORT_X, GPIO_PIN_6)) 43 | res |= BTN_VOL_UP; 44 | return res; 45 | } 46 | 47 | u8 btn_read_home() 48 | { 49 | return (!gpio_read(GPIO_PORT_Y, GPIO_PIN_1)) ? BTN_HOME : 0; 50 | } 51 | 52 | u8 btn_wait() 53 | { 54 | u8 res = 0, btn = btn_read(); 55 | bool pwr = false; 56 | 57 | //Power button down, raise a filter. 58 | if (btn & BTN_POWER) 59 | { 60 | pwr = true; 61 | btn &= ~BTN_POWER; 62 | } 63 | 64 | do 65 | { 66 | res = btn_read(); 67 | //Power button up, remove filter. 68 | if (!(res & BTN_POWER) && pwr) 69 | pwr = false; 70 | else if (pwr) //Power button still down. 71 | res &= ~BTN_POWER; 72 | } while (btn == res); 73 | 74 | return res; 75 | } 76 | 77 | u8 btn_wait_timeout(u32 time_ms, u8 mask) 78 | { 79 | u32 timeout = get_tmr_ms() + time_ms; 80 | u8 res = btn_read() & mask; 81 | 82 | while (get_tmr_ms() < timeout) 83 | { 84 | if (res == mask) 85 | break; 86 | else 87 | res = btn_read() & mask; 88 | }; 89 | 90 | return res; 91 | } 92 | 93 | u8 btn_wait_timeout_single(u32 time_ms, u8 mask) 94 | { 95 | u8 single_button = mask & BTN_SINGLE; 96 | mask &= ~BTN_SINGLE; 97 | 98 | u32 timeout = get_tmr_ms() + time_ms; 99 | u8 res = btn_read(); 100 | 101 | while (get_tmr_ms() < timeout) 102 | { 103 | if ((res & mask) == mask) 104 | { 105 | if (single_button && (res & ~mask)) // Undesired button detected. 106 | res = btn_read(); 107 | else 108 | return (res & mask); 109 | } 110 | else 111 | res = btn_read(); 112 | }; 113 | 114 | // Timed out. 115 | if (!single_button || !time_ms) 116 | return (res & mask); 117 | else 118 | return 0; // Return no button press if single button requested. 119 | } 120 | -------------------------------------------------------------------------------- /bdk/utils/btn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2022 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _BTN_H_ 19 | #define _BTN_H_ 20 | 21 | #include 22 | 23 | #define BTN_POWER BIT(0) 24 | #define BTN_VOL_DOWN BIT(1) 25 | #define BTN_VOL_UP BIT(2) 26 | #define BTN_HOME BIT(3) 27 | #define BTN_SINGLE BIT(7) 28 | 29 | u8 btn_read(); 30 | u8 btn_read_vol(); 31 | u8 btn_read_home(); 32 | u8 btn_wait(); 33 | u8 btn_wait_timeout(u32 time_ms, u8 mask); 34 | u8 btn_wait_timeout_single(u32 time_ms, u8 mask); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /bdk/utils/dirlist.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define MAX_ENTRIES 64 25 | 26 | char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs) 27 | { 28 | int res = 0; 29 | u32 i = 0, j = 0, k = 0; 30 | DIR dir; 31 | FILINFO fno; 32 | 33 | char *dir_entries = (char *)calloc(MAX_ENTRIES, 256); 34 | char *temp = (char *)calloc(1, 256); 35 | 36 | if (!pattern && !f_opendir(&dir, directory)) 37 | { 38 | for (;;) 39 | { 40 | res = f_readdir(&dir, &fno); 41 | if (res || !fno.fname[0]) 42 | break; 43 | 44 | bool curr_parse = parse_dirs ? (fno.fattrib & AM_DIR) : !(fno.fattrib & AM_DIR); 45 | 46 | if (curr_parse) 47 | { 48 | if ((fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) 49 | { 50 | strcpy(dir_entries + (k * 256), fno.fname); 51 | k++; 52 | if (k > (MAX_ENTRIES - 1)) 53 | break; 54 | } 55 | } 56 | } 57 | f_closedir(&dir); 58 | } 59 | else if (pattern && !f_findfirst(&dir, &fno, directory, pattern) && fno.fname[0]) 60 | { 61 | do 62 | { 63 | if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) 64 | { 65 | strcpy(dir_entries + (k * 256), fno.fname); 66 | k++; 67 | if (k > (MAX_ENTRIES - 1)) 68 | break; 69 | } 70 | res = f_findnext(&dir, &fno); 71 | } while (fno.fname[0] && !res); 72 | f_closedir(&dir); 73 | } 74 | 75 | if (!k) 76 | { 77 | free(temp); 78 | free(dir_entries); 79 | 80 | return NULL; 81 | } 82 | 83 | // Reorder ini files by ASCII ordering. 84 | for (i = 0; i < k - 1 ; i++) 85 | { 86 | for (j = i + 1; j < k; j++) 87 | { 88 | if (strcmp(&dir_entries[i * 256], &dir_entries[j * 256]) > 0) 89 | { 90 | strcpy(temp, &dir_entries[i * 256]); 91 | strcpy(&dir_entries[i * 256], &dir_entries[j * 256]); 92 | strcpy(&dir_entries[j * 256], temp); 93 | } 94 | } 95 | } 96 | 97 | free(temp); 98 | 99 | return dir_entries; 100 | } 101 | -------------------------------------------------------------------------------- /bdk/utils/dirlist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | 19 | char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs); 20 | -------------------------------------------------------------------------------- /bdk/utils/ini.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _INI_H_ 19 | #define _INI_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define INI_CHOICE 3 25 | #define INI_CAPTION 5 26 | #define INI_CHGLINE 6 27 | #define INI_NEWLINE 0xFE 28 | #define INI_COMMENT 0xFF 29 | 30 | typedef struct _ini_kv_t 31 | { 32 | char *key; 33 | char *val; 34 | link_t link; 35 | } ini_kv_t; 36 | 37 | typedef struct _ini_sec_t 38 | { 39 | char *name; 40 | link_t kvs; 41 | link_t link; 42 | u32 type; 43 | u32 color; 44 | } ini_sec_t; 45 | 46 | int ini_parse(link_t *dst, char *ini_path, bool is_dir); 47 | char *ini_check_payload_section(ini_sec_t *cfg); 48 | 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /bdk/utils/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2020 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _LIST_H_ 19 | #define _LIST_H_ 20 | 21 | #include 22 | 23 | /*! Initialize list. */ 24 | #define LIST_INIT(name) link_t name = {&name, &name} 25 | 26 | /*! Initialize static list. */ 27 | #define LIST_INIT_STATIC(name) static link_t name = {&name, &name} 28 | 29 | /*! Iterate over all list links. */ 30 | #define LIST_FOREACH(iter, list) \ 31 | for(link_t *iter = (list)->next; iter != (list); iter = iter->next) 32 | 33 | /*! Safely iterate over all list links. */ 34 | #define LIST_FOREACH_SAFE(iter, list) \ 35 | for(link_t *iter = (list)->next, *safe = iter->next; iter != (list); iter = safe, safe = iter->next) 36 | 37 | /*! Iterate over all list members and make sure that the list has at least one entry. */ 38 | #define LIST_FOREACH_ENTRY(etype, iter, list, mn) \ 39 | if ((list)->next != (list)) \ 40 | for(etype *iter = CONTAINER_OF((list)->next, etype, mn); &iter->mn != (list); iter = CONTAINER_OF(iter->mn.next, etype, mn)) 41 | 42 | typedef struct _link_t 43 | { 44 | struct _link_t *prev; 45 | struct _link_t *next; 46 | } link_t; 47 | 48 | static inline void link_init(link_t *l) 49 | { 50 | l->prev = NULL; 51 | l->next = NULL; 52 | } 53 | 54 | static inline int link_used(link_t *l) 55 | { 56 | if(l->next == NULL) 57 | return 1; 58 | return 0; 59 | } 60 | 61 | static inline void list_init(link_t *lh) 62 | { 63 | lh->prev = lh; 64 | lh->next = lh; 65 | } 66 | 67 | static inline void list_prepend(link_t *lh, link_t *l) 68 | { 69 | l->next = lh->next; 70 | l->prev = lh; 71 | lh->next->prev = l; 72 | lh->next = l; 73 | } 74 | 75 | static inline void list_append(link_t *lh, link_t *l) 76 | { 77 | l->prev = lh->prev; 78 | l->next = lh; 79 | lh->prev->next = l; 80 | lh->prev = l; 81 | } 82 | 83 | static inline void list_remove(link_t *l) 84 | { 85 | l->next->prev = l->prev; 86 | l->prev->next = l->next; 87 | link_init(l); 88 | } 89 | 90 | static inline int list_empty(link_t *lh) 91 | { 92 | if(lh->next == lh) 93 | return 1; 94 | return 0; 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /bdk/utils/sprintf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _SPRINTF_H_ 18 | #define _SPRINTF_H_ 19 | 20 | #include 21 | 22 | #include 23 | 24 | void s_printf(char *out_buf, const char *fmt, ...); 25 | void s_vprintf(char *out_buf, const char *fmt, va_list ap); 26 | 27 | #endif -------------------------------------------------------------------------------- /bdk/utils/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2022 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _UTIL_H_ 19 | #define _UTIL_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define NYX_NEW_INFO 0x3058594E 25 | 26 | typedef enum 27 | { 28 | REBOOT_RCM, // PMC reset. Enter RCM mode. 29 | REBOOT_BYPASS_FUSES, // PMC reset via watchdog. Enter Normal mode. Bypass fuse programming in package1. 30 | 31 | POWER_OFF, // Power off PMIC. Do not reset regulators. 32 | POWER_OFF_RESET, // Power off PMIC. Reset regulators. 33 | POWER_OFF_REBOOT, // Power off PMIC. Reset regulators. Power on. 34 | } power_state_t; 35 | 36 | typedef enum 37 | { 38 | NYX_CFG_UMS = BIT(6), 39 | 40 | NYX_CFG_EXTRA = 0xFF << 24 41 | } nyx_cfg_t; 42 | 43 | typedef enum 44 | { 45 | ERR_LIBSYS_LP0 = BIT(0), 46 | ERR_SYSOLD_NYX = BIT(1), 47 | ERR_LIBSYS_MTC = BIT(2), 48 | ERR_SD_BOOT_EN = BIT(3), 49 | ERR_PANIC_CODE = BIT(4), 50 | ERR_L4T_KERNEL = BIT(24), 51 | ERR_EXCEPTION = BIT(31), 52 | } hekate_errors_t; 53 | 54 | typedef struct _cfg_op_t 55 | { 56 | u32 off; 57 | u32 val; 58 | } cfg_op_t; 59 | 60 | typedef struct _nyx_info_t 61 | { 62 | u32 magic; 63 | u32 sd_init; 64 | u32 sd_errors[3]; 65 | u8 rsvd[0x1000]; 66 | u32 disp_id; 67 | u32 errors; 68 | } nyx_info_t; 69 | 70 | typedef struct _nyx_storage_t 71 | { 72 | u32 version; 73 | u32 cfg; 74 | u8 irama[0x8000]; 75 | u8 hekate[0x30000]; 76 | u8 rsvd[SZ_8M - sizeof(nyx_info_t)]; 77 | nyx_info_t info; 78 | mtc_config_t mtc_cfg; 79 | emc_table_t mtc_table[10]; 80 | } nyx_storage_t; 81 | 82 | u8 bit_count(u32 val); 83 | u32 bit_count_mask(u8 bits); 84 | char *strcpy_ns(char *dst, char *src); 85 | 86 | void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops); 87 | u32 crc32_calc(u32 crc, const u8 *buf, u32 len); 88 | 89 | u32 get_tmr_us(); 90 | u32 get_tmr_ms(); 91 | u32 get_tmr_s(); 92 | void usleep(u32 us); 93 | void msleep(u32 ms); 94 | 95 | void panic(u32 val); 96 | void power_set_state(power_state_t state); 97 | void power_set_state_ex(void *param); 98 | 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /toolbox/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _CONFIG_H_ 18 | #define _CONFIG_H_ 19 | 20 | #include 21 | 22 | typedef struct _hekate_config 23 | { 24 | // Non-volatile config. 25 | u32 autoboot; 26 | u32 autoboot_list; 27 | u32 bootwait; 28 | u32 backlight; 29 | u32 autohosoff; 30 | u32 autonogc; 31 | u32 updater2p; 32 | u32 bootprotect; 33 | // Global temporary config. 34 | bool t210b01; 35 | bool emummc_force_disable; 36 | bool rcm_patched; 37 | u32 errors; 38 | } hekate_config; 39 | 40 | void set_default_configuration(); 41 | int create_config_entry(); 42 | 43 | #endif /* _CONFIG_H_ */ 44 | -------------------------------------------------------------------------------- /toolbox/gfx/gfx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * Copyright (c) 2018 M4xw 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _GFX_H_ 20 | #define _GFX_H_ 21 | 22 | #include 23 | 24 | #define EPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) 25 | #define EPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) 26 | #define WPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) 27 | #define WPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC) 28 | 29 | typedef struct _gfx_ctxt_t 30 | { 31 | u32 *fb; 32 | u32 width; 33 | u32 height; 34 | u32 stride; 35 | } gfx_ctxt_t; 36 | 37 | typedef struct _gfx_con_t 38 | { 39 | gfx_ctxt_t *gfx_ctxt; 40 | u32 fntsz; 41 | u32 x; 42 | u32 y; 43 | u32 savedx; 44 | u32 savedy; 45 | u32 fgcol; 46 | int fillbg; 47 | u32 bgcol; 48 | bool mute; 49 | } gfx_con_t; 50 | 51 | // Global gfx console and context. 52 | extern gfx_ctxt_t gfx_ctxt; 53 | extern gfx_con_t gfx_con; 54 | 55 | void gfx_init_ctxt(u32 *fb, u32 width, u32 height, u32 stride); 56 | void gfx_clear_grey(u8 color); 57 | void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height); 58 | void gfx_clear_color(u32 color); 59 | void gfx_con_init(); 60 | void gfx_con_setcol(u32 fgcol, int fillbg, u32 bgcol); 61 | void gfx_con_getpos(u32 *x, u32 *y); 62 | void gfx_con_setpos(u32 x, u32 y); 63 | void gfx_putc(char c); 64 | void gfx_puts(char *s); 65 | void gfx_printf(const char *fmt, ...); 66 | void gfx_hexdump(u32 base, const void *buf, u32 len); 67 | 68 | void gfx_set_pixel(u32 x, u32 y, u32 color); 69 | void gfx_line(int x0, int y0, int x1, int y1, u32 color); 70 | void gfx_put_small_sep(); 71 | void gfx_put_big_sep(); 72 | void gfx_set_rect_grey(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); 73 | void gfx_set_rect_rgb(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); 74 | void gfx_set_rect_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); 75 | void gfx_render_bmp_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /toolbox/gfx/tui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _TUI_H_ 19 | #define _TUI_H_ 20 | 21 | #include 22 | 23 | #define MENT_END 0 24 | #define MENT_HANDLER 1 25 | #define MENT_MENU 2 26 | #define MENT_DATA 3 27 | #define MENT_BACK 4 28 | #define MENT_CAPTION 5 29 | #define MENT_CHGLINE 6 30 | #define MENT_HDLR_RE 7 31 | 32 | typedef struct _ment_t 33 | { 34 | u32 type; 35 | const char *caption; 36 | u32 color; 37 | void *data; 38 | union 39 | { 40 | void(*handler)(void *); 41 | struct _menu_t *menu; 42 | }; 43 | } ment_t; 44 | 45 | typedef struct _menu_t 46 | { 47 | ment_t *ents; 48 | const char *caption; 49 | u32 x; 50 | u32 y; 51 | } menu_t; 52 | 53 | #define MDEF_END() {MENT_END} 54 | #define MDEF_HANDLER(caption, _handler) { MENT_HANDLER, caption, 0, NULL, { .handler = _handler } } 55 | #define MDEF_HANDLER_EX(caption, data, _handler) { MENT_HANDLER, caption, 0, data, { .handler = _handler } } 56 | #define MDEF_MENU(caption, _menu) { MENT_MENU, caption, 0, NULL, { .menu = _menu } } 57 | #define MDEF_BACK() { MENT_BACK, "Back" } 58 | #define MDEF_CAPTION(caption, color) { MENT_CAPTION, caption, color } 59 | #define MDEF_CHGLINE() {MENT_CHGLINE} 60 | 61 | void tui_sbar(bool force_update); 62 | void tui_pbar(int x, int y, u32 val, u32 fgcol, u32 bgcol); 63 | void *tui_do_menu(menu_t *menu); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /toolbox/hwfly.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 HWFLY 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _HWFLY_H_ 18 | #define _HWFLY_H_ 19 | 20 | #include 21 | 22 | #define CONFIG_MAGIC 0x01584E54 23 | #define SESSION_INFO_FORMAT_VER 2 24 | #define SESSION_INFO_MAGIC 0x80B54D 25 | 26 | typedef struct 27 | { 28 | uint16_t offset; 29 | uint8_t width; 30 | uint32_t success; 31 | } timing_t; 32 | 33 | typedef struct 34 | { 35 | uint32_t magic; 36 | uint32_t count; 37 | timing_t timings[32]; 38 | uint8_t reflash; 39 | } config_t; 40 | 41 | typedef struct 42 | { 43 | uint16_t offset; // 12-bit counter marking number of eMMC clock cycles to wait after completed sector 0x13 READ_SINGLE_BLOCK command 44 | uint8_t subcycle_delay; // 3-bit counter for number of additional pulses at 4x eMMC clock to delay after 'offset' above 45 | uint8_t width; // glitch pulse width in clock cycles @ 48MHz starting after subcycle_delay. 46 | uint8_t timeout; // delay as ~1.2ms*timeout value after which glitch_flag:timeout is set when no eMMC bus activity is detected 47 | } glitch_cfg_t; 48 | 49 | enum DEVICE_TYPE 50 | { 51 | DEVICE_TYPE_UNKNOWN = 0, 52 | DEVICE_TYPE_ERISTA, 53 | DEVICE_TYPE_MARIKO, 54 | DEVICE_TYPE_LITE 55 | }; 56 | 57 | enum BOARD_ID 58 | { 59 | BOARD_ID_UNKNOWN = 0, 60 | BOARD_ID_CORE, 61 | BOARD_ID_LITE 62 | }; 63 | 64 | typedef struct 65 | { 66 | uint16_t startup_adc_value; 67 | uint16_t glitch_attempt; 68 | uint32_t power_threshold_reached_us; 69 | uint32_t adc_goal_reached_us; 70 | uint32_t glitch_complete_us; 71 | uint32_t glitch_confirm_us; 72 | uint32_t flag_reads_before_glitch_confirmed; 73 | uint32_t total_time_us; 74 | 75 | uint8_t was_the_device_reset : 1; 76 | uint8_t payload_flashed : 1; 77 | uint8_t reserved : 6; 78 | 79 | enum DEVICE_TYPE device_type; 80 | enum BOARD_ID board_id; 81 | uint32_t fpga_type; 82 | 83 | glitch_cfg_t glitch_cfg; 84 | 85 | } __attribute__((packed)) session_info_t; 86 | 87 | void hwfly_dump_fw(); 88 | void hwfly_update_fw(); 89 | void hwfly_enter_deep_sleep(); 90 | uint32_t hwfly_reset_train_data(); 91 | uint32_t hwfly_get_train_data(uint32_t *load_result, config_t *si); 92 | uint32_t hwfly_set_train_data(config_t *si); 93 | uint32_t hwfly_session_info(uint8_t *fmt, session_info_t *si); 94 | 95 | void hwfly_exit_dfu_and_launch_firmware(); 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /toolbox/libs/fatfs/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */ 3 | /*-----------------------------------------------------------------------*/ 4 | /* If a working storage control module is available, it should be */ 5 | /* attached to the FatFs via a glue function rather than modifying it. */ 6 | /* This is an example of glue functions to attach various exsisting */ 7 | /* storage control modules to the FatFs module with a defined API. */ 8 | /*-----------------------------------------------------------------------*/ 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include /* FatFs lower layer API */ 15 | 16 | /*-----------------------------------------------------------------------*/ 17 | /* Get Drive Status */ 18 | /*-----------------------------------------------------------------------*/ 19 | DSTATUS disk_status ( 20 | BYTE pdrv /* Physical drive nmuber to identify the drive */ 21 | ) 22 | { 23 | return 0; 24 | } 25 | 26 | /*-----------------------------------------------------------------------*/ 27 | /* Inidialize a Drive */ 28 | /*-----------------------------------------------------------------------*/ 29 | DSTATUS disk_initialize ( 30 | BYTE pdrv /* Physical drive nmuber to identify the drive */ 31 | ) 32 | { 33 | return 0; 34 | } 35 | 36 | /*-----------------------------------------------------------------------*/ 37 | /* Read Sector(s) */ 38 | /*-----------------------------------------------------------------------*/ 39 | DRESULT disk_read ( 40 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 41 | BYTE *buff, /* Data buffer to store read data */ 42 | DWORD sector, /* Start sector in LBA */ 43 | UINT count /* Number of sectors to read */ 44 | ) 45 | { 46 | return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; 47 | } 48 | 49 | /*-----------------------------------------------------------------------*/ 50 | /* Write Sector(s) */ 51 | /*-----------------------------------------------------------------------*/ 52 | DRESULT disk_write ( 53 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 54 | const BYTE *buff, /* Data to be written */ 55 | DWORD sector, /* Start sector in LBA */ 56 | UINT count /* Number of sectors to write */ 57 | ) 58 | { 59 | return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; 60 | } 61 | 62 | /*-----------------------------------------------------------------------*/ 63 | /* Miscellaneous Functions */ 64 | /*-----------------------------------------------------------------------*/ 65 | DRESULT disk_ioctl ( 66 | BYTE pdrv, /* Physical drive nmuber (0..) */ 67 | BYTE cmd, /* Control code */ 68 | void *buff /* Buffer to send/receive control data */ 69 | ) 70 | { 71 | return RES_OK; 72 | } 73 | -------------------------------------------------------------------------------- /toolbox/libs/fatfs/ffsystem.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Sample Code of OS Dependent Functions for FatFs */ 3 | /* (C) ChaN, 2018 */ 4 | /* (C) CTCaer, 2018 */ 5 | /*------------------------------------------------------------------------*/ 6 | 7 | #include 8 | 9 | #if FF_USE_LFN == 3 /* Dynamic memory allocation */ 10 | 11 | /*------------------------------------------------------------------------*/ 12 | /* Allocate a memory block */ 13 | /*------------------------------------------------------------------------*/ 14 | 15 | void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */ 16 | UINT msize /* Number of bytes to allocate */ 17 | ) 18 | { 19 | return malloc(msize); /* Allocate a new memory block with POSIX API */ 20 | } 21 | 22 | 23 | /*------------------------------------------------------------------------*/ 24 | /* Free a memory block */ 25 | /*------------------------------------------------------------------------*/ 26 | 27 | void ff_memfree ( 28 | void* mblock /* Pointer to the memory block to free (nothing to do if null) */ 29 | ) 30 | { 31 | free(mblock); /* Free the memory block with POSIX API */ 32 | } 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /toolbox/link.ld: -------------------------------------------------------------------------------- 1 | ENTRY(_start) 2 | 3 | SECTIONS { 4 | PROVIDE(__ipl_start = IPL_LOAD_ADDR); 5 | . = __ipl_start; 6 | .text : { 7 | *(.text._start); 8 | KEEP(*(._ipl_version)); 9 | *(.text._irq_setup); 10 | *(.text*); 11 | } 12 | .data : { 13 | *(.data*); 14 | *(.rodata*); 15 | } 16 | . = ALIGN(0x10); 17 | __ipl_end = .; 18 | .bss : { 19 | __bss_start = .; 20 | *(COMMON) 21 | *(.bss*) 22 | __bss_end = .; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /toolbox/start.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | .section .text._start 18 | .arm 19 | 20 | .extern _reloc_ipl 21 | .type _reloc_ipl, %function 22 | 23 | .extern memset 24 | .type memset, %function 25 | 26 | .extern _irq_setup 27 | .type _irq_setup, %function 28 | 29 | .globl _start 30 | .type _start, %function 31 | _start: 32 | ADR R0, _start 33 | LDR R1, =__ipl_start 34 | CMP R0, R1 35 | BEQ _real_start 36 | 37 | /* If we are not in the right location already, copy a relocator to upper IRAM. */ 38 | ADR R2, _reloc_ipl 39 | LDR R3, =0x4003FF00 40 | MOV R4, #(_real_start - _reloc_ipl) 41 | _copy_loop: 42 | LDMIA R2!, {R5} 43 | STMIA R3!, {R5} 44 | SUBS R4, #4 45 | BNE _copy_loop 46 | 47 | /* Use the relocator to copy ourselves into the right place. */ 48 | LDR R2, =__ipl_end 49 | SUB R2, R2, R1 50 | LDR R3, =_real_start 51 | LDR R4, =0x4003FF00 52 | BX R4 53 | 54 | _reloc_ipl: 55 | LDMIA R0!, {R4-R7} 56 | STMIA R1!, {R4-R7} 57 | SUBS R2, #0x10 58 | BNE _reloc_ipl 59 | /* Jump to the relocated entry. */ 60 | BX R3 61 | 62 | _real_start: 63 | /* Initially, we place our stack in IRAM but will move it to SDRAM later. */ 64 | LDR SP, =0x4003FF00 65 | LDR R0, =__bss_start 66 | EOR R1, R1, R1 67 | LDR R2, =__bss_end 68 | SUB R2, R2, R0 69 | BL memset 70 | BL _irq_setup 71 | B . 72 | 73 | .globl pivot_stack 74 | .type pivot_stack, %function 75 | pivot_stack: 76 | MOV SP, R0 77 | BX LR 78 | --------------------------------------------------------------------------------