Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion docs/mchose-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ used directly when the mouse is on a cable:
| A7 V2 Ultra | `0x4019` | 42000 | 0.7 mm, 1 mm, 2 mm |
| A7 V2 Ultra+ | `0x4021` | 42000 | 0.7 mm, 1 mm, 2 mm |
| L7 Pro+ | `0x4015` | 26000 | 1 mm, 2 mm (indices 1 and 2) |
| L7 Ultra | `0x00b1` | 42000 | 0.7 mm, 1 mm, 2 mm |

MCHOSE's own firmware-version table cross-checks this: the Ultra reports
`5.44.2.4` and the Ultra+ `5.46.2.4`. The test hardware reported `5.46.2.4`.
Expand Down Expand Up @@ -261,7 +262,28 @@ Observed on an 8K receiver (macOS, `node-hid`):
byte-identical config.

Because other MCHOSE product lines share `0x5253`, the picker filter and the
driver match it only together with these two PIDs.
driver match it only together with these known PIDs.

## L7 Ultra

Firmware 5.14.5.0 uses wired ID `5253:00b1` and an 8K receiver at `5253:1020`.
The feature report bodies are 20 bytes for `0x11` and 64 bytes for `0x12`.
The receiver can answer `0x06` with zeros before reporting the mouse's ID
and battery. Its connection flag is bit 3 of battery payload byte 8. An
unidentified `5253:1020` receiver keeps trying identity, battery and config
on later reads. A connected `0x03` reply that explicitly names the L7 Ultra
can also complete discovery when battery telemetry is unavailable.

Once identified, the L7 Ultra keeps its model through empty replies. Battery
(`0x06`) and config (`0x67`) stay retryable on later reads so the mouse can
recover after sleep. Identified legacy models retain empty-response suppression.

The 63-byte `0x67` payload stores the X table at offsets 4–15, the enabled
stage count at offset 16, and the Y table at offsets 51–62. The L7 Ultra
uses `0x40` to apply both DPI tables, the stage count and the active indices.
The packet carries the reserved byte at config offset 3 and the observed
`diff` value of `0xff`. Post-cleanup physical testing was reported successful.
The L7 Pro+ retains the previously hardware-tested `0x57` write path.

## L7 Pro+

Expand Down
224 changes: 218 additions & 6 deletions src/drivers/mchose/hid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ function fakeDevice(overrides?: Partial<HIDDevice>) {
profile: 0,
sleepEnabled: 0,
mouseProductId: 0x4021,
batteryPayload: null as number[] | null,
identityPayload: IDENTITY,
emptyShortReplies: [] as number[],
emptyConfigReplies: false,
buttonNames: {} as Record<number, string>,
unansweredButtonNames: [] as number[],
};
Expand Down Expand Up @@ -150,10 +153,20 @@ function fakeDevice(overrides?: Partial<HIDDevice>) {
if (command === MCHOSE_COMMAND.writeConfig) {
// The write layout is the read layout with the command byte in front.
state.writes.push(tokens);
state.config = tokens.slice(1, 1 + CONFIG.length);
state.config = tokens.slice(1, 1 + state.config.length);
pendingLong = MCHOSE_COMMAND.writeConfig;
return;
}
if (command === MCHOSE_COMMAND.writeDpi) {
state.writes.push(tokens);
state.config[1] = (state.config[1]! & 0xf0) | tokens[1]!;
state.config[2] = (state.config[2]! & 0xf0) | tokens[2]!;
state.config.splice(4, 12, ...tokens.slice(4, 16));
state.config[16] = tokens[16]!;
state.config.splice(51, 12, ...tokens.slice(18, 30));
pendingLong = command;
return;
}
if (command === MCHOSE_COMMAND.setButton) {
// A standalone command: it touches one button's four bytes and nothing
// else, which is what the hardware was observed to do.
Expand All @@ -173,10 +186,10 @@ function fakeDevice(overrides?: Partial<HIDDevice>) {
if (state.emptyShortReplies.includes(pendingShort)) {
return wireReply(id, pendingShort, new Array(MCHOSE_SHORT_TOKENS - 1).fill(0));
}
const payload = pendingShort === MCHOSE_COMMAND.identity ? IDENTITY
const payload = pendingShort === MCHOSE_COMMAND.identity ? state.identityPayload
: pendingShort === MCHOSE_COMMAND.version ? VERSION
: pendingShort === MCHOSE_COMMAND.battery
? [...BATTERY.slice(0, 2), state.mouseProductId & 0xff, (state.mouseProductId >> 8) & 0xff, ...BATTERY.slice(4)]
? state.batteryPayload ?? [...BATTERY.slice(0, 2), state.mouseProductId & 0xff, (state.mouseProductId >> 8) & 0xff, ...BATTERY.slice(4)]
: [];
return wireReply(id, pendingShort, payload);
}
Expand All @@ -191,15 +204,192 @@ function fakeDevice(overrides?: Partial<HIDDevice>) {
const name = state.buttonNames[pendingButton] ?? "";
return wireReply(id, pendingLong, [pendingButton, name.length, ...[...name].map((c) => c.charCodeAt(0))]);
}
return wireReply(id, MCHOSE_COMMAND.config, state.config);
const config = state.emptyConfigReplies ? new Array(MCHOSE_LONG_TOKENS - 1).fill(0) : state.config;
return wireReply(id, MCHOSE_COMMAND.config, config);
},
...overrides,
} as unknown as HIDDevice;

return { device, state };
}

/** Synthetic L7 Ultra configuration using observed DPI tables: one enabled stage, six stored X/Y stages. */
function l7UltraDevice(wired = false) {
const fake = fakeDevice({
vendorId: 0x5253,
productId: wired ? 0x00b1 : 0x1020,
productName: "",
} as Partial<HIDDevice>);
fake.state.batteryPayload = [0x53, 0x52, 0xb1, 0x00, 0x0e, 0x05, 0x05, 0x00, 0x09, 0x64, 0x00];
fake.state.config = [...CONFIG, ...new Array<number>(63 - CONFIG.length).fill(0)];
fake.state.config[1] = 0x50;
fake.state.config[2] = 0x40;
const stages = [4000, 40000, 2000, 3200, 6400, 42000];
stages.forEach((value, stage) => {
fake.state.config[4 + stage * 2] = value & 0xff;
fake.state.config[5 + stage * 2] = value >> 8;
fake.state.config[51 + stage * 2] = value & 0xff;
fake.state.config[52 + stage * 2] = value >> 8;
});
fake.state.config[16] = 1;
fake.state.config[17] = 0xc0;
fake.state.config[18] = 0;
fake.state.config[19] = 5;
return fake;
}

describe("MchoseHidClient", () => {
it("reads L7 Ultra on both links and sends X/Y writes through the Bridge", async () => {
for (const wired of [false, true]) {
const { device, state } = l7UltraDevice(wired);
const send = device.sendFeatureReport;
const read = device.receiveFeatureReport;
device.collections[0]!.featureReports = [{ reportId: MCHOSE_SHORT_REPORT_ID, items: [{ reportCount: 20, reportSize: 8 }] }] as HIDReportInfo[];
device.sendFeatureReport = async (id, body) => {
if (id === MCHOSE_SHORT_REPORT_ID) assert.equal(body.byteLength, 20);
return send(id, body);
};
device.receiveFeatureReport = async (id) => {
const reply = await read(id);
return new DataView(reply.buffer, reply.byteOffset + 1, reply.byteLength - 1);
};
const client = new MchoseHidClient(device);
assert.equal(MchoseHidClient.isSupported(device), true);
const status = await client.readStatus();
assert.equal(status.name, "MCHOSE L7 Ultra");
assert.equal(status.connectionType, wired ? "Wired" : "Wireless");
assert.equal(status.batteryPercent, 100);
assert.deepEqual(status.dpiStages, [4000]);
assert.deepEqual(status.dpiStagesY, [4000]);
assert.deepEqual(status.dpiStoredStages, [4000, 40000, 2000, 3200, 6400, 42000]);
assert.equal(typeof client.setDpiStageAxes, "function");
await client.setDpiStageAxes!(0, 1600, 2400);
assert.equal(state.writes.at(-1)?.[0], MCHOSE_COMMAND.writeDpi);
const after = await client.readStatus();
assert.deepEqual(after.dpiStages, [1600]);
assert.deepEqual(after.dpiStagesY, [2400]);
assert.deepEqual(after.dpiStoredStagesY?.slice(1), status.dpiStoredStagesY?.slice(1));
}
});

it("recovers L7 Ultra battery and config after a sleeping receiver poll", async () => {
const { device, state } = l7UltraDevice();
const client = new MchoseHidClient(device);
assert.equal((await client.readStatus()).supportsSeparateDpiAxes, true);

const send = device.sendFeatureReport;
device.sendFeatureReport = async (id, body) => {
const bytes = body instanceof Uint8Array ? body : new Uint8Array(body as ArrayBuffer);
if (id === MCHOSE_SHORT_REPORT_ID && bytes[0] === (~MCHOSE_COMMAND.identity & 0xff)) {
throw new Error("Cannot send identity request");
}
return send(id, body);
};
state.emptyShortReplies = [MCHOSE_COMMAND.battery];
state.emptyConfigReplies = true;
const status = await client.readStatus();
assert.equal(status.name, "MCHOSE L7 Ultra");
assert.equal(status.batteryPercent, null);
assert.equal(status.supportsSeparateDpiAxes, true);
assert.equal(status.dpiStages, undefined);
await assert.rejects(() => client.setDpiStageValue(0, 2400), /did not return its configuration/);

device.sendFeatureReport = send;
state.emptyShortReplies = [];
state.emptyConfigReplies = false;
const awake = await client.readStatus();
assert.equal(awake.batteryPercent, 100);
assert.deepEqual(awake.dpiStagesY, [4000]);
await client.setDpiStageValue(0, 2400);
assert.equal(state.writes.at(-1)?.[0], MCHOSE_COMMAND.writeDpi);
assert.equal(state.config[51], 0x60);
});

it("discovers an L7 Ultra after an unnamed receiver's initial poll is empty", async () => {
for (const usingBattery of [true, false]) {
const { device, state } = l7UltraDevice();
const client = new MchoseHidClient(device);
state.emptyShortReplies = [MCHOSE_COMMAND.identity, MCHOSE_COMMAND.battery];
state.emptyConfigReplies = true;
const unidentified = await client.readStatus();
assert.equal(unidentified.name, "MCHOSE");
assert.equal(unidentified.supportsSeparateDpiAxes, false);
assert.equal(unidentified.dpiStages, undefined);

state.emptyShortReplies = usingBattery ? [] : [MCHOSE_COMMAND.battery];
if (!usingBattery) state.identityPayload = [1, 0x53, 0x52, 0xb1, 0x00, 1, 0];
state.emptyConfigReplies = false;
const identified = await client.readStatus();
assert.equal(identified.name, "MCHOSE L7 Ultra");
assert.equal(identified.batteryPercent, usingBattery ? 100 : null);
assert.deepEqual(identified.dpiStagesY, [4000]);
}
});

it("enables stored L7 stages and keeps both active indices in range when shrinking", async () => {
const { device, state } = l7UltraDevice();
const client = new MchoseHidClient(device);
await client.readStatus();
await client.setDpiStageCount(6);
assert.equal(state.writes.at(-1)?.[0], MCHOSE_COMMAND.writeDpi);
assert.deepEqual((await client.readStatus()).dpiStages, [4000, 40000, 2000, 3200, 6400, 42000]);
await client.setActiveDpiStage(5);
// Exercise the inactive link too, not just the wireless setter above.
state.config[1] = (state.config[1]! & 0xf0) | 4;
await client.setDpiStageCount(1);
const status = await client.readStatus();
assert.deepEqual(status.dpiStages, [4000]);
assert.equal(status.activeDpiStage, 0);
assert.equal(state.config[1]! & 0x0f, 0);
assert.equal(state.config[2]! & 0x0f, 0);
assert.deepEqual(status.dpiStoredStages, [4000, 40000, 2000, 3200, 6400, 42000]);
});

it("rejects DPI writes on an unidentified shared receiver until discovery", async () => {
const { device, state } = l7UltraDevice();
const client = new MchoseHidClient(device);
await assert.rejects(() => client.setDpiStageValue(0, 2400), /Identify the mouse/);
await assert.rejects(() => client.setDpi(2400), /Identify the mouse/);
await assert.rejects(() => client.setDpiStageCount(2), /Identify the mouse/);
await assert.rejects(() => client.setActiveDpiStage(0), /Identify the mouse/);
assert.equal(state.writes.length, 0);
await client.readStatus();
await client.setDpiStageValue(0, 2400);
assert.equal(state.writes.at(-1)?.[0], MCHOSE_COMMAND.writeDpi);
});

it("keeps the name fallback for an unlisted battery PID", async () => {
const { device, state } = fakeDevice({
vendorId: 0x5253, productId: 0x1020, productName: "MCHOSE A7 V2 Ultra+",
} as Partial<HIDDevice>);
state.mouseProductId = 0x7fff;
const client = new MchoseHidClient(device);
const status = await client.readStatus();
assert.equal(status.name, "MCHOSE A7 V2 Ultra+");
assert.ok(status.supportedPollingRates?.includes(1000));
await client.setPollingRate(1000);
assert.equal(state.writes.at(-1)?.[0], MCHOSE_COMMAND.writeConfig);
});

it("sizes short setter reports for L7 Ultra and retains the legacy fallback", async () => {
for (const ultra of [true, false]) {
const { device } = ultra ? l7UltraDevice() : fakeDevice();
if (ultra) {
device.collections[0]!.featureReports = [{ reportId: MCHOSE_SHORT_REPORT_ID, items: [{ reportCount: 20, reportSize: 8 }] }] as HIDReportInfo[];
}
const send = device.sendFeatureReport;
device.sendFeatureReport = async (id, body) => {
if (id === MCHOSE_SHORT_REPORT_ID) assert.equal(body.byteLength, ultra ? 20 : 64);
return send(id, body);
};
const client = new MchoseHidClient(device);
await client.readStatus();
await client.setMotionSync(true);
await client.setSleepTimeout(120);
await client.setProfile(3);
}
});

it("matches an MCHOSE device exposing the 0xff01 config collection", () => {
assert.equal(MchoseHidClient.isSupported(fakeDevice().device), true);
});
Expand Down Expand Up @@ -229,21 +419,43 @@ describe("MchoseHidClient", () => {
assert.equal(status.ui?.dpiStageEditor?.maxDpi, 42000);
});

it("stops polling commands the 0x5253 receiver only ever answers empty", async () => {
const { device } = a7UltraDevice();
it("suppresses repeatedly empty identity, battery and version replies for a named legacy receiver", async () => {
const { device, state } = a7UltraDevice();
state.emptyShortReplies.push(MCHOSE_COMMAND.identity);
const counts = countCommands(device);
const client = new MchoseHidClient(device);
await client.readStatus();
assert.ok((counts.get(MCHOSE_COMMAND.battery) ?? 0) > 1, "the first read polls in full");

counts.clear();
const status = await client.readStatus();
assert.equal(counts.get(MCHOSE_COMMAND.identity), undefined);
assert.equal(counts.get(MCHOSE_COMMAND.battery), undefined);
assert.equal(counts.get(MCHOSE_COMMAND.version), undefined);
assert.ok(counts.get(MCHOSE_COMMAND.config), "config is still read");
assert.equal(status.pollingRateHz, 2000);
});

it("suppresses empty polls once battery has identified L7 Pro+ on an unnamed receiver", async () => {
const { device, state } = l7UltraDevice();
state.batteryPayload = [0x37, 0x38, 0x15, 0x40, ...BATTERY.slice(4)];
const counts = countCommands(device);
const client = new MchoseHidClient(device);
assert.equal((await client.readStatus()).name, "MCHOSE L7 Pro+");
assert.equal(client.setDpiStageAxes, undefined);
await client.setDpiStageValue(0, 2400);
assert.equal(state.writes.at(-1)?.[0], MCHOSE_COMMAND.writeConfig);

state.emptyShortReplies = [MCHOSE_COMMAND.identity, MCHOSE_COMMAND.battery];
state.emptyConfigReplies = true;
await client.readStatus();
counts.clear();
assert.equal((await client.readStatus()).name, "MCHOSE L7 Pro+");
assert.equal(counts.get(MCHOSE_COMMAND.identity), undefined);
assert.equal(counts.get(MCHOSE_COMMAND.battery), undefined);
assert.equal(counts.get(MCHOSE_COMMAND.config), undefined);
});

it("keeps polling empty replies in full on a 0x3837 receiver", async () => {
const { device, state } = fakeDevice();
state.emptyShortReplies = [MCHOSE_COMMAND.battery];
Expand Down
Loading