feat: WASM modules based simulation in Companion (#6435)

This commit is contained in:
Raphael Coeffic
2026-03-20 12:19:17 +10:00
committed by GitHub
parent 5f8a38bb18
commit 04a2231aee
80 changed files with 3126 additions and 2220 deletions
+29 -9
View File
@@ -366,8 +366,6 @@ static uint32_t apply_low_pass_filter(uint32_t v, uint32_t v_prev,
static uint32_t apply_calibration(const CalibData* calib, uint32_t v)
{
// Simu uses normed inputs
#if !defined(SIMU)
// Apply calibration relative to mid-point
int32_t s = v - 2 * calib->mid;
s = s * (int32_t)RESX /
@@ -383,10 +381,7 @@ static uint32_t apply_calibration(const CalibData* calib, uint32_t v)
s = 4 * RESX;
}
v = s;
#endif
return v;
return s;
}
static uint32_t apply_multipos(const StepsCalibData* calib, uint32_t v)
@@ -407,6 +402,24 @@ static uint32_t apply_multipos(const StepsCalibData* calib, uint32_t v)
return ANAFILT_MAX;
}
#if defined(SIMU)
// In simulation, assume equally spaced positions across full ADC range
static uint32_t apply_multipos_simu(uint32_t v)
{
constexpr uint32_t ALPHA_MULT = JITTER_ALPHA * ANALOG_MULTIPLIER;
constexpr uint32_t ANAFILT_MAX = 2 * RESX * ALPHA_MULT;
constexpr uint32_t N = XPOTS_MULTIPOS_COUNT;
constexpr uint32_t COUNT = N - 1;
uint32_t pos = v * N / (ANAFILT_MAX + 1);
if (pos > COUNT) pos = COUNT;
return (pos < COUNT)
? (pos * (ANAFILT_MAX + ALPHA_MULT)) / COUNT
: ANAFILT_MAX;
}
#endif
void getADC()
{
auto max_analogs = adcGetMaxInputs(ADC_INPUT_ALL);
@@ -435,14 +448,17 @@ void getADC()
bool is_flex_input = (x >= pot_offset) && (x < pot_offset + max_pots);
bool is_multipos = is_flex_input && IS_POT_MULTIPOS(x - pot_offset);
// 1st: apply calibration
uint32_t v = getAnalogValue(x);
#if !defined(SIMU)
// Apply hardware calibration (not needed in simulation:
// the host already provides normalized ADC-range values)
if (x < max_calib_analogs && !is_multipos) {
v = apply_calibration(&g_eeGeneral.calib[x], v);
}
#endif
// 2nd: apply inversion
// Apply inversion
if (x < pot_offset && getStickInversion(inputMappingConvertMode(x))) {
v = 4 * RESX - v;
}
@@ -451,14 +467,18 @@ void getADC()
v = 4 * RESX - v;
}
// 3rd: apply filtering
// Apply filtering
s_anaFilt[x] = apply_low_pass_filter(v, s_anaFilt[x], x < max_mains);
if (is_multipos) {
#if defined(SIMU)
s_anaFilt[x] = apply_multipos_simu(s_anaFilt[x]);
#else
const auto* calib = (const StepsCalibData*)&g_eeGeneral.calib[x];
if (IS_MULTIPOS_CALIBRATED(calib)) {
s_anaFilt[x] = apply_multipos(calib, s_anaFilt[x]);
}
#endif
}
#if defined(JITTER_MEASURE)