Finalize usb protocol (#515)

* Change UsbCommandId_SetTestLed from 0x02 to 0x14

* Change UsbCommandId_JumpToModuleBootloader from 0x12 to 0x02.

* Change UsbCommandId_SendKbootCommandToModule from 0x13 to 0x03.

* Replace UsbCommandId_ReadHardwareConfig and UsbCommandId_ReadUserConfig with UsbCommandId_ReadConfig.

* Change UsbCommandId_WriteHardwareConfig and UsbCommandId_WriteUserConfig to 0x05 and 0x06.

* Change UsbCommandId_ApplyConfig to 0x07.

* Change the arguments of UsbCommandId_LaunchEepromTransfer and its id to 0x08.

* Change the value of UsbCommandId_{GetDeviceState,SetTestLed,GetDebugBuffer,GetAdcValue,SetLedPwmBrightness}.

* Use firmware 6.0.0
This commit is contained in:
László Monda
2017-12-13 01:20:23 +01:00
committed by GitHub
parent 8e121d88ab
commit 2702a74035
9 changed files with 100 additions and 59 deletions
+4 -4
View File
@@ -2,15 +2,15 @@
const uhk = require('./uhk');
const eepromTransferType = process.argv[2];
const eepromTransferId = uhk.eepromTransfer[eepromTransferType];
const eepromTransfer = uhk.eepromTransfer[eepromTransferType];
if (eepromTransferId === undefined) {
if (eepromTransfer === undefined) {
console.error(`Gotta provide one of ${Object.keys(uhk.eepromTransfer).join(', ')}`);
process.exit(1);
}
const device = uhk.getUhkDevice();
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.launchEepromTransferLegacy, eepromTransferId])));
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.launchEepromTransfer, eepromTransfer.operation, eepromTransfer.configBuffer])));
const buffer = Buffer.from(device.readSync());
const responseCode = buffer[0];
if (responseCode !== 0) {
@@ -20,7 +20,7 @@ if (responseCode !== 0) {
function waitUntilKeyboardBusy() {
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.getKeyboardState])));
device.write(uhk.getTransferData(new Buffer([uhk.usbCommands.getDeviceState])));
const keyboardStateBuffer = Buffer.from(device.readSync());
if (keyboardStateBuffer[1] === 1) {
@@ -3,7 +3,7 @@ const uhk = require('./uhk');
const device = uhk.getUhkDevice();
function readKeyboardState() {
const payload = new Buffer([uhk.usbCommands.getKeyboardState]);
const payload = new Buffer([uhk.usbCommands.getDeviceState]);
console.log('Sending ', uhk.bufferToString(payload));
device.write(uhk.getTransferData(payload));
const receivedBuffer = device.readSync();
+3 -3
View File
@@ -23,10 +23,10 @@ device.write(uhk.getTransferData(payload));
let buffer = Buffer.from(device.readSync());
configSize = buffer[1] + (buffer[2]<<8);
console.log(`${configTypeString}configSize:`, configSize);
while(offset < configSize) {
const usbCommand = isHardwareConfig ? uhk.usbCommands.readHardwareConfig : uhk.usbCommands.readUserConfig;
while (offset < configSize) {
const configBufferId = isHardwareConfig ? uhk.configBufferIds.hardwareConfig : uhk.configBufferIds.validatedUserConfig;
chunkSizeToRead = Math.min(chunkSize, configSize - offset);
buffer = Buffer.from([usbCommand, chunkSizeToRead, offset & 0xff, offset >> 8]);
buffer = Buffer.from([uhk.usbCommands.readConfig, configBufferId, chunkSizeToRead, offset & 0xff, offset >> 8]);
console.log('write to keyboard', uhk.bufferToString(buffer));
device.write(uhk.getTransferData(buffer));
buffer = Buffer.from(device.readSync());
+43 -19
View File
@@ -44,6 +44,17 @@ function getBootloaderDevice() {
return foundDevice;
}
let configBufferIds = {
hardwareConfig: 0,
stagingUserConfig: 1,
validatedUserConfig: 2,
};
let eepromOperations = {
read: 0,
write: 1,
};
exports = module.exports = moduleExports = {
bufferToString,
getUhkDevice,
@@ -51,21 +62,20 @@ exports = module.exports = moduleExports = {
getTransferData,
checkModuleSlot,
usbCommands: {
getProperty: 0,
reenumerate: 1,
setTestLed: 2,
writeUserConfig: 8,
applyConfig: 9,
setLedPwmBrightness: 10,
getAdcValue: 11,
launchEepromTransferLegacy: 12,
readHardwareConfig: 13,
writeHardwareConfig: 14,
readUserConfig: 15,
getKeyboardState: 16,
getDebugInfo: 17,
jumpToModuleBootloader: 18,
sendKbootCommandToModule: 19,
getProperty : 0x00,
reenumerate : 0x01,
jumpToModuleBootloader : 0x02,
sendKbootCommandToModule: 0x03,
readConfig : 0x04,
writeHardwareConfig : 0x05,
writeStagingUserConfig : 0x06,
applyConfig : 0x07,
launchEepromTransfer : 0x08,
getDeviceState : 0x09,
setTestLed : 0x0a,
getDebugBuffer : 0x0b,
getAdcValue : 0x0c,
setLedPwmBrightness : 0x0d,
},
enumerationModes: {
bootloader: 0,
@@ -94,11 +104,25 @@ exports = module.exports = moduleExports = {
hardwareConfigSize: 4,
userConfigSize: 5,
},
configBufferIds,
eepromOperations,
eepromTransfer: {
readHardwareConfig: 0,
writeHardwareConfig: 1,
readUserConfig: 2,
writeUserConfig: 3,
readHardwareConfig: {
operation: eepromOperations.read,
configBuffer: configBufferIds.hardwareConfig,
},
writeHardwareConfig: {
operation: eepromOperations.write,
configBuffer:configBufferIds.hardwareConfig,
},
readUserConfig: {
operation: eepromOperations.read,
configBuffer: configBufferIds.validatedUserConfig,
},
writeUserConfig: {
operation: eepromOperations.write,
configBuffer: configBufferIds.validatedUserConfig,
},
},
kbootCommands: {
idle: 0,
+2 -2
View File
@@ -24,8 +24,8 @@ let buffer = Buffer.from(device.readSync());
configSize = buffer[1] + (buffer[2]<<8);
console.log(`${configTypeString}configSize:`, configSize);
while (offset < configSize){
const usbCommand = isHardwareConfig ? uhk.usbCommands.writeHardwareConfig : uhk.usbCommands.writeUserConfig;
while (offset < configSize) {
const usbCommand = isHardwareConfig ? uhk.usbCommands.writeHardwareConfig : uhk.usbCommands.writeStagingUserConfig;
chunkSizeToRead = Math.min(chunkSize, configSize - offset);
buffer = Buffer.concat([
new Buffer([usbCommand, chunkSizeToRead, offset & 0xff, offset >> 8]),