mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 21:04:32 +01:00
- Board support from main (Melodee's BOARD_SMK37, the v0.9.18 line), adapted to V10.8.48: build.py --board smk37
--model pro|elite (identities SMK-37 Pro_909 / Elite_909, ota-... _900 / _016), fm1pkg_make --board smk37 (stock
v016 region table, flash.bin 0x9D000), the flash map and its guards, the store (V10.8: 6 songs in store A/B, the
JAM takes in store C), the owner tag, the stock marker release, OTA staging at 0xBB000 with the board check, the
loader's app-area-only writes, the LCD and pad LEDs, the input HAL. RAM-only unless FELUCCA_SMK_FLASH=1, now also
enforced at compile time in storage_hw.c / ota_hw.c (SMK_MAY_WRITE).
- V10.8 specifics: no Bluetooth segment on the SMK (its 0xEA000.. sectors are USRFLASH / store C / USR): FELUCCA_BT 0
(#error otherwise), the segment's code in the app image, no bt.bin in the package, the SMK loader refuses one;
USB HOST off; vel.c / vel_diag.c (the FM-1's carbon pills) out, the HAL's velocity with MENU > VELOCITY's curve;
the sound's pinned layout per board (tools/audio_layout_smk37.txt, its own layout.ld / app.ld in build/smk37-*).
- The new layout (firmware/src/smk.c, smk_kb.c, smk_map.h): all 37 keys always play the selected track at their
velocity, C3..C6 moved by OCT (never out of 0..127, never two keys alike), as MIDI in from the audio block, out to
MIDI OUT; PITCH bend, MOD CC1, SUSTAIN CC64 on the selected track; pads = white keys in layers / NAME / the DRUM
grid / STEP FX / song pages, steps on the other SEQ pages (hold + K1..K4: a lock), else T1..T6 (PATCH held: mute),
UNDO, TAP and 8 page shortcuts; K5 SELECT, K6 PRESETS, K7 ALGORITHM, K8 MASTER ("PNS6"); KNOB BANK: T1..T6 cutoff,
delay MIX, reverb SIZE; FADER BANK A T1..T4 levels, B T5 T6 levels + the selected track's DLY / REV sends, with
pick-up; < > pages; the pads' and bank LEDs.
- Tests: smk_map_test (rewritten: every key id at every octave and track, wheels, pedal, pads, banks, pick-up),
smk_flash_test (V10.8's table), smk_keys_test (pads via GRID), smk_ldr_test (a bt.bin package refused),
smk_pkg_test (no bt.bin), run_tests.sh's RAM-only and page-shortcut checks, its missing vel_diag_test skipped.
- The FM-1 build is byte-identical to V10.8.48's (felucca.bin, felucca.fwsc, loader/ota.bin, bt.bin); regress: 218
golden renders, 0 changed. SMK image 581072 B of 584336 (3264 B free). docs/SMK37.md updated. Untested on hardware.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVqsRpEnNJfjWWrH3C4opq
127 lines
4.6 KiB
C
127 lines
4.6 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
|
|
/* Felucca update loader (device side). Runs from RAM, started by the SPL from
|
|
* an update record, with interrupts off: USB is polled from the main loop.
|
|
* It is a USB-MIDI device "Felucca Update" (1209:0002) that answers the
|
|
* M-UPGRADE update protocol as "ota-FM-1_900" (hosts look for "ota-"), and
|
|
* writes the app area only (ldr_core.c). The UBOOT soft key works here too.
|
|
* Single compilation unit. */
|
|
#include <stdint.h>
|
|
#define FELUCCA_LOADER 1
|
|
#define FELUCCA_CDC 0
|
|
#define FELUCCA_OTA 1
|
|
#define FELUCCA_OTA_DRYRUN 0
|
|
#define FELUCCA_USB_PID 0x0002
|
|
#include "fm1_cc.h" /* BOARD_SMK37, SMK_MODEL */
|
|
#if BOARD_SMK37
|
|
#define FELUCCA_ID "ota-" SMK_MODEL "_900" /* (SMK-37, after Melodee) e.g. "ota-SMK-37 Pro_900" */
|
|
#else
|
|
#define FELUCCA_ID "ota-FM-1_900"
|
|
#endif
|
|
#define RING_PUBLISH() __asm__ volatile("" ::: "memory")
|
|
#include "fm1_time.h"
|
|
#include "fm1_sys.h"
|
|
#if BOARD_SMK37
|
|
/* (SMK-37) the loader may write the app area [0x4000, 0x9D000) and erase update records in the OTA area
|
|
* [0xBB000, 0xC0000) only (hal/fm1_flash_map.h FL_LDR_RANGE_OK); the RAM driver's FL_PROTECTED refuses the head,
|
|
* BTIF / USRTRIM, USR and key_mac on top of it */
|
|
#define FL_RANGE_OK(off, n) FL_LDR_RANGE_OK(off, n)
|
|
#else
|
|
/* the loader may write the app area and erase update records; never the head, nor Felucca's store
|
|
* [0x97000, 0xE0000) (user data, never a record: ldr_core.c) */
|
|
#define FL_RANGE_OK(off, n) (FL_IN(off, n, 0x4000u, 0x97000u) || FL_IN(off, n, 0xE0000u, 0xFC000u))
|
|
#endif
|
|
#include "fm1_flash.h"
|
|
#include "../src/libc.c"
|
|
#include "../src/usb.c"
|
|
|
|
static uint32_t ldr_ms(void) /* monotonic ms; survives the TIMER4 wrap (178.9 s) */
|
|
{
|
|
static uint32_t last, acc, ms;
|
|
uint32_t now = fm1_ticks();
|
|
acc += now - last;
|
|
last = now;
|
|
ms += acc / (1000u * FM1_TICKS_PER_US);
|
|
acc %= 1000u * FM1_TICKS_PER_US;
|
|
return ms;
|
|
}
|
|
|
|
static void ldr_poll(void) /* USB at ~2 kHz, watchdog */
|
|
{
|
|
static uint32_t last;
|
|
uint32_t now = fm1_ticks();
|
|
fm1_wdt_feed();
|
|
if (now - last >= 500u * FM1_TICKS_PER_US) {
|
|
last = now;
|
|
usb_poll();
|
|
}
|
|
}
|
|
|
|
/* ---- ota.c hooks (the SysEx frame hooks are in usb.c) ---- */
|
|
static uint32_t ota_now_ms(void) { return ldr_ms(); }
|
|
static void ota_idle(void) { ldr_poll(); }
|
|
/* step-1 hooks of ota.c: not used by the loader */
|
|
static int ota_erase(uint32_t off) { (void)off; return -1; }
|
|
static int ota_prog(uint32_t off, const void *p, uint32_t n) { (void)off; (void)p; (void)n; return -1; }
|
|
static int ota_fread(uint32_t off, void *p, uint32_t n) { return fl_read_ram(off, p, n); }
|
|
static void ota_show(uint32_t step, int32_t code) { (void)step; (void)code; }
|
|
static void ota_commit(const uint8_t *parm) { (void)parm; }
|
|
#include "../src/ota.c"
|
|
|
|
/* ---- ldr_core.c hooks: interrupts are off for the whole loader ---- */
|
|
static int ldr_fread(uint32_t off, void *p, uint32_t n) { return fl_read_ram(off, p, n); }
|
|
static int ldr_erase(uint32_t off)
|
|
{
|
|
uint32_t took;
|
|
return fl_erase4k_ram(off, &took);
|
|
}
|
|
static int ldr_prog(uint32_t off, const void *p, uint32_t n)
|
|
{
|
|
uint32_t took;
|
|
return fl_prog_ram(off, p, n, &took);
|
|
}
|
|
static void ldr_record_clear(void)
|
|
{
|
|
fm1_updata_parm_clear(); /* CRC 0: the SPL ignores it on a warm reset */
|
|
}
|
|
static void ldr_progress(uint32_t done, uint32_t total) { (void)done; (void)total; ldr_poll(); }
|
|
#include "ldr_core.c"
|
|
|
|
extern uint32_t _bss_start[], _bss_end[];
|
|
|
|
void ldr_main(void)
|
|
{
|
|
fm1_wdt_arm(0x0D); /* ~8 s, fed by ldr_poll */
|
|
fm1_time_init();
|
|
usb_start();
|
|
for (;;) {
|
|
ldr_poll();
|
|
usb_retry(ldr_ms());
|
|
if (usb.uboot_req) { /* soft key: mask-ROM UBOOT, as in Felucca */
|
|
usb_detach();
|
|
fm1_delay_ms(30);
|
|
fm1_enter_uboot();
|
|
}
|
|
ota_service(); /* handshake */
|
|
if (usb.ota_req) {
|
|
usb.ota_req = 0;
|
|
if (ldr_session() == 0) {
|
|
fm1_delay_ms(200); /* the "success" reply leaves */
|
|
usb_detach();
|
|
fm1_delay_ms(30);
|
|
fm1_core_reset(); /* the SPL boots the new app */
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void ldr_cstart(void)
|
|
{
|
|
uint32_t *p;
|
|
ldr_record_clear(); /* first thing: a crash below cannot loop through a
|
|
* warm reset; resume after power loss uses the flash record */
|
|
for (p = _bss_start; p < _bss_end; p++)
|
|
*p = 0;
|
|
ldr_main();
|
|
}
|