Files
xteink-web-emulator/scripts/test-web.mjs
T
evan 90981ad154 feat(web): auto-merge CrossPoint release app image into a 16 MB flash
Accept the ~5 MB release firmware.bin directly: place it at 0x10000 in a
0xFF-erased 16 MB image alongside the bundled ESP32-C3 bootloader (0x0) and
CrossPoint partition table (0x8000). m25p80 requires a full chip-size backing,
so the 16 MB image is still built, but the user no longer pre-merges. Full
16 MB images are still accepted as-is.
2026-07-20 08:21:38 -04:00

32 lines
1.2 KiB
JavaScript

import assert from 'node:assert/strict';
import { BUTTONS, setButton, mergeFirmware } from '../web/app.js';
// Merge - app image is placed at 0x10000 in a 0xFF-erased 16 MB flash with bootloader and partitions.
const bootloader = new Uint8Array([1, 2, 3]);
const partitions = new Uint8Array([4, 5, 6]);
const app = new Uint8Array(1024);
app[0] = 0xe9;
const flash = mergeFirmware(app, bootloader, partitions);
assert.equal(flash.length, 16 * 1024 * 1024);
assert.deepEqual(flash.slice(0, 3), bootloader);
assert.deepEqual(flash.slice(0x8000, 0x8003), partitions);
assert.equal(flash[0x10000], 0xe9);
assert.equal(flash[0x20000], 0xff);
assert.throws(() => mergeFirmware(new Uint8Array([0x00]), bootloader, partitions), /0xE9/);
const calls = [];
const module = {
_xteink_wasm_set_adc: (...args) => calls.push(['adc', ...args]),
_xteink_wasm_set_gpio: (...args) => calls.push(['gpio', ...args]),
};
setButton(module, 'confirm', true);
setButton(module, 'confirm', false);
setButton(module, 'power', true);
setButton(module, 'power', false);
assert.deepEqual(calls, [
['adc', BUTTONS.confirm.channel, BUTTONS.confirm.value],
['adc', BUTTONS.confirm.channel, 4095],
['gpio', 3, 0],
['gpio', 3, 1],
]);