Introduce redesigned project homepage; Fix #64 #65

- loaderConfigurator now renamed to pages, with configurator section supporting both v2 and v3 Cust
This commit is contained in:
KazushiM
2023-01-25 18:58:43 +08:00
parent 120367cf7c
commit f33a59370a
23 changed files with 1810 additions and 4952 deletions

View File

@@ -71,7 +71,6 @@ volatile CustomizeTable C = {
.marikoEmcVolt = 0,
/* Erista CPU:
* Not tested but enabled by default.
* - Max Voltage in mV
*/
.eristaCpuMaxVolt = 1235,

View File

@@ -31,8 +31,8 @@ Result MemFreqPllmLimit(u32* ptr) {
void SafetyCheck() {
if (C.custRev != CUST_REV ||
C.marikoCpuMaxVolt >= 1300 ||
C.eristaCpuMaxVolt >= 1300 ||
C.marikoCpuMaxVolt > 1300 ||
C.eristaCpuMaxVolt > 1300 ||
(C.eristaEmcVolt && (C.eristaEmcVolt < 600'000 || C.eristaEmcVolt > 1250'000)) ||
(C.marikoEmcVolt && (C.marikoEmcVolt < 600'000 || C.marikoEmcVolt > 650'000)))
{

View File

@@ -31,7 +31,7 @@ file_replace_str(ldr_process_creation,
namespace ams::ldr {""",
"""#include "ldr_ro_manager.hpp"
#include "oc/oc_suite.hpp"
#include "oc/oc_loader.hpp"
namespace ams::ldr {"""),
(""" NsoHeader g_nso_headers[Nso_Count];

View File

@@ -1,2 +0,0 @@
node_modules/
package-lock.json

View File

@@ -1,6 +0,0 @@
#!/bin/bash
[ -d "./dist" ] || mkdir ./dist
cp -Rf ./src/*.html ./dist/
tsc ./src/main.ts --outDir ./dist/ -lib es2015,dom -t es2015
npx tailwindcss -i ./src/style.css -o ./dist/output.css

View File

@@ -1,22 +0,0 @@
<!DOCTYPE html>
<html class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./output.css" rel="stylesheet">
</head>
<body class="bg-slate-200 dark:bg-slate-900">
<div class="flex justify-center">
<div id="form" class="form-group p-6 rounded-lg shadow-lg max-w-md my-10 bg-slate-100 dark:bg-slate-800">
<label for="file" class="form-entry">Upload loader.kip</label>
<a href="https://github.com/KazushiMe/Switch-OC-Suite/releases/latest" target="_blank" class="link-primary">Get latest here</a>
<input id="file" type="file" class="form-control form-entry">
<div class="btn">
<button id="load" class="hide btn btn-secondary">Load Default</button>
<button id="save" class="hide btn btn-primary">Save</button>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="./main.js"></script>
</html>

View File

@@ -1,234 +0,0 @@
const CUST_REV = 2;
var buffer;
function FindMagicOffset(buffer) {
let view = new DataView(buffer);
for (let i = 0; i < view.byteLength; i += 4) {
if (view.getUint32(i, true) == 0x54535543) { // "CUST"
return i;
}
}
throw new Error("Invalid loader.kip file");
}
function CustEntry(name, size, desc, defval, minmax = [0, 1000000], step = 1, extra_validator) {
this.name = name;
this.size = size;
this.desc = desc;
this.defval = defval;
this.min = minmax[0];
this.max = minmax[1];
this.step = step;
this.validator = extra_validator;
this.value = null;
this.offset = null;
}
function InitCustTable() {
let cust = [
new CustEntry("mtcConf", 2, "<b>DRAM Timing</b>\
<li><b>0</b>: AUTO_ADJ_MARIKO_SAFE: Auto adjust timings for LPDDR4 ≤3733 Mbps specs, 8Gb density.</li>\
<li><b>1</b>: AUTO_ADJ_MARIKO_4266: Auto adjust timings for LPDDR4X 4266 Mbps specs, 8Gb density.</li>", 0, [0, 3]),
new CustEntry("marikoCpuMaxClock", 4, "<b>Mariko CPU Max Clock in kHz</b>\
<li>System default: 1785000</li>\
<li>≥ 2397000 will enable overvolting (> 1120 mV)</li>", 2397000, [1785000, 3000000], 100, (x) => (x % 100) == 0),
new CustEntry("marikoCpuBoostClock", 4, "<b>Mariko CPU Boost Clock in kHz</b>\
<li>System default: 1785000</li>\
<li>Must not be higher than marikoCpuMaxClock</li>", 1785000, [1785000, 3000000], 100, (x) => (x % 100) == 0),
new CustEntry("marikoCpuMaxVolt", 4, "<b>Mariko CPU Max Voltage in mV</b>\
<li>System default: 1120</li>\
<li>Acceptable range: 1100 ≤ x ≤ 1300</li>", 1235, [1100, 1300]),
new CustEntry("marikoGpuMaxClock", 4, "<b>Mariko GPU Max Clock in kHz</b>\
<li>System default: 921600</li>\
<li>Tegra X1+ official maximum: 1267200</li>", 1305600, [768000, 1536000], 100, (x) => (x % 100) == 0),
new CustEntry("marikoEmcMaxClock", 4, "<b>Mariko RAM Max Clock in kHz</b>\
<li>Values should be > 1600000, and divided evenly by 3200.</li>\
<li><b>WARNING:</b> RAM overclock could be UNSTABLE if timing parameters are not suitable for your DRAM</li>", 1996800, [1612800, 2400000], 3200, (x) => (x % 3200) == 0),
new CustEntry("eristaCpuOCEnable", 4, "<b>Erista CPU Enable Overclock</b>\
<li>Not tested</li>", 1, [0, 1]),
new CustEntry("eristaCpuMaxVolt", 4, "<b>Erista CPU Max Voltage in mV</b>\
<li>Acceptable range: 1100 ≤ x ≤ 1400</li>", 1257, [0, 1400], 100, (x) => x >= 1100),
new CustEntry("eristaEmcMaxClock", 4, "<b>Erista RAM Max Clock in kHz</b>\
<li>Values should be > 1600000, and divided evenly by 3200.</li>\
<li><b>WARNING:</b> RAM overclock could be UNSTABLE if timing parameters are not suitable for your DRAM</li>", 1862400, [1600000, 2400000], 3200, (x) => (x % 3200) == 0),
new CustEntry("eristaEmcVolt", 4, "<b>Erista RAM Voltage in uV</b>\
<li>Acceptable range: 1100000 ≤ x ≤ 1250000, and it should be divided evenly by 12500.</li>\
<li>Not enabled by default</li>", 0, [0, 1250000], 12500, (x) => (x % 12500) == 0 && x >= 1100000),
];
return cust;
}
function ValidateCust(cust) {
for (let i of cust) {
if (i.value == 0)
continue;
if (i.value < i.min || i.value > i.max) {
document.getElementById(i.name).focus();
throw new Error(`Expected range: ${i.min}${i.name}${i.max}, got ${i.value}`);
}
if (i.validator && !i.validator(i.value)) {
document.getElementById(i.name).focus();
throw new Error(`Invalid value: ${i.value}(${i.name})\nValidator: ${i.validator}`);
}
}
}
function SaveCust(cust, buffer) {
let dict = Object.assign({}, ...cust.map((x) => ({ [x.name]: x })));
let view = new DataView(buffer);
let storage = {};
for (let i of cust) {
let id = i.name;
i.value = document.getElementById(id).value;
storage[i.name] = i.value;
switch (i.size) {
case 2:
view.setUint16(i.offset, i.value, true);
break;
case 4:
view.setUint32(i.offset, i.value, true);
break;
default:
document.getElementById(i.name).focus();
throw new Error("Unknown size at " + i);
}
}
ValidateCust(cust);
storage["custRev"] = CUST_REV;
localStorage.setItem("last_saved", JSON.stringify(storage));
let a = document.createElement("a");
a.href = window.URL.createObjectURL(new Blob([buffer], { type: "application/octet-stream" }));
a.download = "loader.kip";
a.click();
}
function LastSaved() {
let storage = localStorage.getItem("last_saved");
if (!storage) {
return false;
}
let sObj = JSON.parse(storage);
if (!sObj["custRev"] || sObj["custRev"] != CUST_REV) {
localStorage.removeItem("last_saved");
return false;
}
return true;
}
function LoadLastSaved() {
if (LastSaved()) {
let storage = localStorage.getItem("last_saved");
let sObj = JSON.parse(storage);
for (let key in sObj) {
if (key == "custRev") {
continue;
}
document.getElementById(key).value = sObj[key];
}
}
}
function LoadDefault(cust) {
let dict = Object.assign({}, ...cust.map((x) => ({ [x.name]: x })));
for (let i of cust) {
let id = i.name;
document.getElementById(id).value = i.defval;
}
}
function UpdateHTMLForm(cust) {
let dict = Object.assign({}, ...cust.map((x) => ({ [x.name]: x })));
let form = document.getElementById("form");
for (let i of cust) {
let id = i.name;
let input = document.getElementById(id);
if (!input) {
let div = document.createElement("div");
div.classList.add("form-floating", "my-3");
let label = document.createElement("label");
label.setAttribute("for", id);
label.innerHTML = id;
label.classList.add("form-entry");
input = document.createElement("input");
input.classList.add("form-control", "form-entry");
input.min = dict[i.name].min;
input.max = dict[i.name].max;
input.id = id;
input.type = "number";
input.step = dict[i.name].step;
div.appendChild(input);
div.appendChild(label);
let desc = dict[i.name].desc;
if (desc) {
let tip = document.createElement("small");
tip.innerHTML = desc;
tip.classList.add("form-entry");
tip.setAttribute("for", id);
div.appendChild(tip);
}
form === null || form === void 0 ? void 0 : form.appendChild(div);
}
input.value = dict[i.name].value;
}
let btn = document.getElementById("load");
btn.classList.remove("hide");
if (LastSaved()) {
btn.innerHTML = "Load Last Saved";
btn.addEventListener('click', () => {
LoadLastSaved();
});
}
else {
btn.addEventListener('click', () => {
LoadDefault(cust);
});
}
btn = document.getElementById("save");
btn.classList.remove("hide");
btn.addEventListener('click', () => {
try {
SaveCust(cust, buffer);
}
catch (e) {
console.log(e);
alert(e);
}
});
}
function ParseCust(magicOffset, buffer) {
let view = new DataView(buffer);
let cust = InitCustTable();
let offset = magicOffset + 4;
let rev = view.getUint16(offset, true);
if (rev != CUST_REV) {
throw new Error("Unsupported custRev, expected: " + CUST_REV + ", got " + rev);
}
offset += 2;
for (let i of cust) {
i.offset = offset;
switch (i.size) {
case 2:
i.value = view.getUint16(offset, true);
break;
case 4:
i.value = view.getUint32(offset, true);
break;
default:
document.getElementById(i.name).focus();
throw new Error("Unknown size at " + i);
}
offset += i.size;
}
ValidateCust(cust);
UpdateHTMLForm(cust);
}
const fileInput = document.getElementById("file");
fileInput.addEventListener('change', (event) => {
let reader = new FileReader();
reader.readAsArrayBuffer(event.target.files[0]);
reader.onloadend = (progEvent) => {
if (progEvent.target.readyState === FileReader.DONE) {
try {
buffer = progEvent.target.result;
let offset = FindMagicOffset(buffer);
ParseCust(offset, buffer);
}
catch (e) {
console.log(e);
alert(e);
fileInput.value = "";
}
}
};
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,173 +0,0 @@
#!python3
cust_conf = {
# DRAM Timing:
# 0: AUTO_ADJ_MARIKO_SAFE: Auto adjust timings for LPDDR4 ≤3733 Mbps specs, 8Gb density (Default).
# 1: AUTO_ADJ_MARIKO_4266: Auto adjust timings for LPDDR4X 4266 Mbps specs, 8Gb density.
# 2: ENTIRE_TABLE_ERISTA:
# 3: ENTIRE_TABLE_MARIKO: Replace the entire max mtc table with customized one (provided by user).
"mtcConf": 0,
# Mariko CPU:
# - Max Clock in kHz:
# Default: 1785000
# >= 2193000 will enable overvolting (> 1120 mV)
# - Boost Clock in kHz:
# Default: 1785000
# Boost clock will be applied when applications request higher CPU frequency for quicker loading.
# - Max Voltage in mV:
# Default voltage: 1120
# Haven't tested anything higher than 1220.
"marikoCpuMaxClock": 2397000,
"marikoCpuBoostClock": 1785000,
"marikoCpuMaxVolt": 1220,
# Mariko GPU:
# - Max Clock in kHz:
# Default: 921600
# NVIDIA Maximum: 1267200
"marikoGpuMaxClock": 1305600,
# Mariko EMC:
# - RAM Clock in kHz:
# Values should be > 1600000, and divided evenly by 9600.
# [WARNING]
# RAM overclock could be UNSTABLE if timing parameters are not suitable for your DRAM:
# - Graphical glitches
# - System instabilities
# - NAND corruption
# Timings from auto-adjustment have been tested safe for up to 1996.8 MHz for all DRAM chips.
"marikoEmcMaxClock": 1996800,
# Erista CPU:
# Not tested and not enabled by default.
# - Enable Overclock
# Require modificaitions towards NewCpuTables!
# - Max Voltage in mV
"eristaCpuOCEnable": 0,
"eristaCpuMaxVolt": 0,
# Erista EMC:
# - RAM Clock in kHz
# [WARNING]
# RAM overclock could be UNSTABLE if timing parameters are not suitable for your DRAM:
# - Graphical glitches
# - System instabilities
# - NAND corruption
# - RAM Voltage in uV
# Range: 600'000 to 1250'000 uV
# Value should be divided evenly by 12'500
# Default(HOS): 1125'000
# Not enabled by default.
"eristaEmcMaxClock": 1862400,
"eristaEmcVolt": 0
}
cust_range = {
"mtcConf": (0, 3),
"marikoCpuMaxClock": (1785000, 3000000),
"marikoCpuBoostClock": (1785000, 3000000),
"marikoCpuMaxVolt": (1100, 1300),
"marikoGpuMaxClock": (768000, 1536000),
"marikoEmcMaxClock": (1612800, 2400000),
"eristaCpuMaxVolt": (1100, 1400),
"eristaEmcMaxClock": (1600000, 2400000),
"eristaEmcVolt": (1100000, 1250000)
}
import struct
import argparse
cust_rev = 2
cust_head = ["cust", "custRev"]
cust_body = ["mtcConf",
"marikoCpuMaxClock", "marikoCpuBoostClock", "marikoCpuMaxVolt", "marikoGpuMaxClock", "marikoEmcMaxClock",
"eristaCpuOCEnable", "eristaCpuMaxVolt", "eristaEmcMaxClock", "eristaEmcVolt"]
cust_key = [*cust_head, *cust_body]
cust_val_num = len(cust_conf) - 1
cust_fmt = '<4s2H' + str(cust_val_num) + 'I'
cust_head_fmt = '<4s1H'
cust_body_fmt = '<1H' + str(cust_val_num) + 'I'
parser = argparse.ArgumentParser(description='Loader Configurator v'+str(cust_rev))
parser.add_argument("file", help="Path of loader.kip")
parser.add_argument("--save", "-s", action="store_true", help="Save configuration to loader.kip")
parser.add_argument("--ignore", action="store_true", help="Ignore range safety check")
args = parser.parse_args()
def KIPCustParse(file_loc, conf_print=True) -> (int, dict):
with open(file_loc, "rb") as file:
header_str = b'KIP1Loader'
header = file.read(len(header_str))
file.seek(0)
cust_magic = b'CUST'
cust_pos = file.read().find(cust_magic)
if header != header_str or cust_pos == -1:
raise Exception("\n Invalid kip file!")
file.seek(cust_pos)
cust_size = struct.calcsize(cust_fmt)
cust_buf = file.read(cust_size)
cust_val = struct.unpack(cust_fmt, cust_buf)
cust_dict = dict(zip(cust_key, cust_val))
if cust_dict['custRev'] != cust_rev:
raise Exception(f"\n custRev does NOT match, expected: {cust_rev}, got: {cust_dict['custRev']}!")
[cust_dict.pop(key) for key in cust_head]
if conf_print:
print("Configuration from file")
[print(f"- {i:20s} : {cust_dict[i]:8d}") for i in cust_dict]
return (cust_pos, cust_dict)
def CustRangeCheck(cust):
range_error_str = ""
for i in cust_range:
val = int(cust[i])
if val and (val < cust_range[i][0] or val > cust_range[i][1]) :
range_error_str += f"\n- {i:20s} = {val:8d}, Expected range: {[*cust_range[i]]}"
if range_error_str:
raise ValueError(range_error_str)
def KIPCustSave(file_loc, cust_pos, cust_dict, range_check=True, cust_to_save={}):
missing = set(cust_body) - set(cust_to_save.keys())
if missing:
missing_str = "\n Invalid cust! Missing: "
for i in missing:
missing_str += f"\n- {i}"
raise Exception(missing_str)
if range_check:
CustRangeCheck(cust_to_save)
diff_count = 0
for i in cust_body:
diff_str = ""
if cust_dict[i] != cust_conf[i]:
diff_str = f"-> {cust_conf[i]:8d}"
diff_count += 1
print(f"- {i:20s} : {cust_dict[i]:8d} {diff_str}")
if not diff_count:
print("Cust is identical, abort saving!")
return
with open(file_loc, "rb+") as file:
cust_bin = struct.pack(cust_body_fmt, *[cust_to_save[i] for i in cust_body])
file.seek(cust_pos + struct.calcsize(cust_head_fmt))
file.write(cust_bin)
print("Done!")
def main(file_loc, ignore=False, save=False):
(cust_pos, cust_dict) = KIPCustParse(file_loc, conf_print=(not save))
if save:
print("Saving new configuration...")
KIPCustSave(file_loc, cust_pos, cust_dict, range_check=(not ignore), cust_to_save=cust_conf)
if __name__ == "__main__":
main(args.file, args.ignore, args.save)

View File

@@ -1,8 +0,0 @@
{
"devDependencies": {
"tailwindcss": "^3.2.2"
},
"dependencies": {
"tw-elements": "^1.0.0-alpha12"
}
}

View File

@@ -1,22 +0,0 @@
<!DOCTYPE html>
<html class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./output.css" rel="stylesheet">
</head>
<body class="bg-slate-200 dark:bg-slate-900">
<div class="flex justify-center">
<div id="form" class="form-group p-6 rounded-lg shadow-lg max-w-md my-10 bg-slate-100 dark:bg-slate-800">
<label for="file" class="form-entry">Upload loader.kip</label>
<a href="https://github.com/KazushiMe/Switch-OC-Suite/releases/latest" target="_blank" class="link-primary">Get latest here</a>
<input id="file" type="file" class="form-control form-entry">
<div class="btn">
<button id="load" class="hide btn btn-secondary">Load Default</button>
<button id="save" class="hide btn btn-primary">Save</button>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="./main.js"></script>
</html>

View File

@@ -1,320 +0,0 @@
const CUST_REV = 2;
var buffer: string | ArrayBuffer;
function FindMagicOffset(buffer) {
let view = new DataView(buffer);
for (let i = 0; i < view.byteLength; i += 4) {
if (view.getUint32(i, true) == 0x54535543) { // "CUST"
return i;
}
}
throw new Error("Invalid loader.kip file");
}
function CustEntry(name: string, size: number, desc: string, defval: number, minmax = [0, 1_000_000], step = 1, extra_validator?) {
this.name = name;
this.size = size;
this.desc = desc;
this.defval = defval;
this.min = minmax[0];
this.max = minmax[1];
this.step = step;
this.validator = extra_validator;
this.value = null;
this.offset = null;
}
function InitCustTable() {
let cust = [
new CustEntry(
"mtcConf",
2,
"<b>DRAM Timing</b>\
<li><b>0</b>: AUTO_ADJ_MARIKO_SAFE: Auto adjust timings for LPDDR4 ≤3733 Mbps specs, 8Gb density.</li>\
<li><b>1</b>: AUTO_ADJ_MARIKO_4266: Auto adjust timings for LPDDR4X 4266 Mbps specs, 8Gb density.</li>",
0,
[0, 3],
),
new CustEntry(
"marikoCpuMaxClock",
4,
"<b>Mariko CPU Max Clock in kHz</b>\
<li>System default: 1785000</li>\
<li>≥ 2397000 will enable overvolting (> 1120 mV)</li>",
2397_000,
[1785_000, 3000_000],
100,
(x: number) => (x % 100) == 0
),
new CustEntry(
"marikoCpuBoostClock",
4,
"<b>Mariko CPU Boost Clock in kHz</b>\
<li>System default: 1785000</li>\
<li>Must not be higher than marikoCpuMaxClock</li>",
1785_000,
[1785_000, 3000_000],
100,
(x: number) => (x % 100) == 0
),
new CustEntry(
"marikoCpuMaxVolt",
4,
"<b>Mariko CPU Max Voltage in mV</b>\
<li>System default: 1120</li>\
<li>Acceptable range: 1100 ≤ x ≤ 1300</li>",
1235,
[1100, 1300],
),
new CustEntry(
"marikoGpuMaxClock",
4,
"<b>Mariko GPU Max Clock in kHz</b>\
<li>System default: 921600</li>\
<li>Tegra X1+ official maximum: 1267200</li>",
1305_600,
[768_000, 1536_000],
100,
(x: number) => (x % 100) == 0
),
new CustEntry(
"marikoEmcMaxClock",
4,
"<b>Mariko RAM Max Clock in kHz</b>\
<li>Values should be > 1600000, and divided evenly by 3200.</li>\
<li><b>WARNING:</b> RAM overclock could be UNSTABLE if timing parameters are not suitable for your DRAM</li>",
1996_800,
[1612_800, 2400_000],
3200,
(x: number) => (x % 3200) == 0
),
new CustEntry(
"eristaCpuOCEnable",
4,
"<b>Erista CPU Enable Overclock</b>\
<li>Not tested</li>",
1,
[0, 1]
),
new CustEntry(
"eristaCpuMaxVolt",
4,
"<b>Erista CPU Max Voltage in mV</b>\
<li>Acceptable range: 1100 ≤ x ≤ 1400</li>",
1257,
[0, 1400],
100,
(x: number) => x >= 1100
),
new CustEntry(
"eristaEmcMaxClock",
4,
"<b>Erista RAM Max Clock in kHz</b>\
<li>Values should be > 1600000, and divided evenly by 3200.</li>\
<li><b>WARNING:</b> RAM overclock could be UNSTABLE if timing parameters are not suitable for your DRAM</li>",
1862_400,
[1600_000, 2400_000],
3200,
(x: number) => (x % 3200) == 0
),
new CustEntry(
"eristaEmcVolt",
4,
"<b>Erista RAM Voltage in uV</b>\
<li>Acceptable range: 1100000 ≤ x ≤ 1250000, and it should be divided evenly by 12500.</li>\
<li>Not enabled by default</li>",
0,
[0, 1250_000],
12500,
(x: number) => (x % 12500) == 0 && x >= 1100000
),
];
return cust;
}
function ValidateCust(cust) {
for (let i of cust) {
if (i.value == 0)
continue;
if (i.value < i.min || i.value > i.max) {
document.getElementById(i.name)!.focus();
throw new Error(`Expected range: ${i.min}${i.name}${i.max}, got ${i.value}`);
}
if (i.validator && !i.validator(i.value)) {
document.getElementById(i.name)!.focus();
throw new Error(`Invalid value: ${i.value}(${i.name})\nValidator: ${i.validator}`);
}
}
}
function SaveCust(cust, buffer) {
let dict = Object.assign({}, ...cust.map((x: { name: any; }) => ({[x.name]: x})));
let view = new DataView(buffer);
let storage = {};
for (let i of cust) {
let id = i.name;
i.value = (document.getElementById(id) as HTMLInputElement).value;
storage[i.name] = i.value;
switch (i.size) {
case 2:
view.setUint16(i.offset, i.value, true);
break;
case 4:
view.setUint32(i.offset, i.value, true);
break;
default:
document.getElementById(i.name)!.focus();
throw new Error("Unknown size at " + i);
}
}
ValidateCust(cust);
storage["custRev"] = CUST_REV;
localStorage.setItem("last_saved", JSON.stringify(storage));
let a = document.createElement("a");
a.href = window.URL.createObjectURL(new Blob([buffer], {type: "application/octet-stream"}));
a.download = "loader.kip";
a.click();
}
function LastSaved() {
let storage = localStorage.getItem("last_saved");
if (!storage) {
return false;
}
let sObj = JSON.parse(storage);
if (!sObj["custRev"] || sObj["custRev"] != CUST_REV) {
localStorage.removeItem("last_saved");
return false;
}
return true;
}
function LoadLastSaved() {
if (LastSaved()) {
let storage = localStorage.getItem("last_saved");
let sObj = JSON.parse(storage!);
for (let key in sObj) {
if (key == "custRev") {
continue;
}
(document.getElementById(key) as HTMLInputElement).value = sObj[key];
}
}
}
function LoadDefault(cust: any[]) {
let dict = Object.assign({}, ...cust.map((x: { name: any; }) => ({[x.name]: x})));
for (let i of cust) {
let id = i.name;
(document.getElementById(id) as HTMLInputElement).value = i.defval;
}
}
function UpdateHTMLForm(cust: any[]) {
let dict = Object.assign({}, ...cust.map((x: { name: any; }) => ({[x.name]: x})));
let form = document.getElementById("form");
for (let i of cust) {
let id = i.name;
let input = document.getElementById(id) as HTMLInputElement;
if (!input) {
let div = document.createElement("div");
div.classList.add("form-floating", "my-3");
let label = document.createElement("label");
label.setAttribute("for", id);
label.innerHTML = id;
label.classList.add("form-entry");
input = document.createElement("input");
input.classList.add("form-control", "form-entry");
input.min = dict[i.name].min;
input.max = dict[i.name].max;
input.id = id;
input.type = "number";
input.step = dict[i.name].step;
div.appendChild(input);
div.appendChild(label);
let desc = dict[i.name].desc;
if (desc) {
let tip = document.createElement("small");
tip.innerHTML = desc;
tip.classList.add("form-entry");
tip.setAttribute("for", id);
div.appendChild(tip);
}
form?.appendChild(div);
}
input.value = dict[i.name].value;
}
let btn = document.getElementById("load")!;
btn.classList.remove("hide");
if (LastSaved()) {
btn.innerHTML = "Load Last Saved";
btn.addEventListener('click', () => {
LoadLastSaved();
});
} else {
btn.addEventListener('click', () => {
LoadDefault(cust);
});
}
btn = document.getElementById("save")!;
btn.classList.remove("hide");
btn.addEventListener('click', () => {
try {
SaveCust(cust, buffer);
} catch (e) {
console.log(e);
alert(e);
}
});
}
function ParseCust(magicOffset, buffer) {
let view = new DataView(buffer);
let cust = InitCustTable();
let offset = magicOffset + 4;
let rev = view.getUint16(offset, true);
if (rev != CUST_REV) {
throw new Error("Unsupported custRev, expected: " + CUST_REV + ", got " + rev);
}
offset += 2;
for (let i of cust) {
i.offset = offset;
switch (i.size) {
case 2:
i.value = view.getUint16(offset, true);
break;
case 4:
i.value = view.getUint32(offset, true);
break;
default:
document.getElementById(i.name)!.focus();
throw new Error("Unknown size at " + i);
}
offset += i.size;
}
ValidateCust(cust);
UpdateHTMLForm(cust);
}
const fileInput = document.getElementById("file") as HTMLInputElement;
fileInput.addEventListener('change', (event) => {
let reader = new FileReader();
reader.readAsArrayBuffer((event.target as HTMLInputElement).files![0]);
reader.onloadend = (progEvent) => {
if (progEvent.target!.readyState === FileReader.DONE) {
buffer = progEvent.target!.result!;
try {
let offset = FindMagicOffset(buffer);
ParseCust(offset, buffer);
} catch (e) {
console.log(e);
alert(e);
fileInput.value = "";
}
}
}
})

View File

@@ -1,39 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
label.form-entry {
@apply inline-block mb-2 text-slate-700 dark:text-slate-200;
}
input.form-entry {
@apply block w-full px-3 py-1.5 text-base font-normal text-slate-600 dark:text-slate-300 bg-slate-100 dark:bg-slate-900 bg-clip-padding border border-solid border-slate-300 dark:border-gray-600 rounded transition ease-in-out m-0 focus:text-slate-700 dark:focus:text-slate-200 focus:bg-slate-100 dark:focus:bg-slate-800 focus:border-blue-600 dark:focus:border-blue-300 focus:outline-none;
}
small.form-entry {
@apply block mt-1 text-xs text-slate-600 dark:text-slate-400 px-3 py-1.5;
}
a.link-primary {
@apply text-blue-500 hover:text-blue-600 active:text-blue-700 transition duration-300 ease-in-out mb-4;
}
div.btn {
@apply grid grid-cols-2 gap-x-6 mt-3;
}
button.btn {
@apply inline-block px-6 py-2.5 text-slate-100 font-medium text-xs leading-tight uppercase rounded shadow-md hover:shadow-lg focus:shadow-lg focus:outline-none focus:ring-0 active:shadow-lg transition duration-150 ease-in-out;
}
button.btn-primary {
@apply bg-blue-600 hover:bg-blue-700 focus:bg-blue-700 active:bg-blue-900;
}
button.btn-secondary {
@apply bg-slate-600 hover:bg-slate-700 focus:bg-slate-700 active:bg-slate-900;
}
.hide {
display: none !important;
}

View File

@@ -1,10 +0,0 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./dist/*.html', './dist/*.js', './node_modules/tw-elements/dist/js/**/*.js'],
theme: {
extend: {},
},
plugins: [
require('tw-elements/dist/plugin')
],
}

View File

@@ -10,6 +10,10 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "types.h"
#include "../config.h"
#include "../clocks.h"
@@ -40,3 +44,7 @@ static inline Result sysclkIpcRemoveOverride(SysClkModule module)
{
return sysclkIpcSetOverride(module, 0);
}
#ifdef __cplusplus
}
#endif

View File

@@ -22,13 +22,5 @@
#include "ipc.h"
#if defined(__SWITCH__) && defined(__cplusplus)
extern "C" {
#endif
#include <sysclk.h>
#include <sysclk/client/ipc.h>
#if defined(__SWITCH__) && defined(__cplusplus)
}
#endif

View File

@@ -10,14 +10,5 @@
#pragma once
#if defined(__cplusplus)
extern "C"
{
#endif
#include <sysclk.h>
#include <sysclk/client/ipc.h>
#if defined(__cplusplus)
}
#endif