From 9a5862b57c595b816032911183a2ce45e839f8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Wed, 8 Nov 2017 03:47:51 +0100 Subject: [PATCH] Make update-slave-firmware expect a module slot name, too. --- packages/usb/uhk.js | 5 +++++ packages/usb/update-slave-firmware.js | 28 +++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/usb/uhk.js b/packages/usb/uhk.js index a045832a..c1da2200 100755 --- a/packages/usb/uhk.js +++ b/packages/usb/uhk.js @@ -98,6 +98,11 @@ exports = module.exports = moduleExports = { ping: 1, reset: 2, }, + moduleSlotToI2cAddress: { + leftHalf: 0x10, + leftAddon: 0x20, + rightAddon: 0x30, + }, leftLedDriverAddress: 0b1110100, rightLedDriverAddress: 0b1110111, sendLog: sendLog, diff --git a/packages/usb/update-slave-firmware.js b/packages/usb/update-slave-firmware.js index e41d4397..b1de57f2 100755 --- a/packages/usb/update-slave-firmware.js +++ b/packages/usb/update-slave-firmware.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +const uhk = require('./uhk'); const program = require('commander'); require('shelljs/global'); require('./shared') @@ -7,18 +8,29 @@ const extension = '.bin'; config.fatal = true; program - .usage(`update-slave-firmware `) + .usage(`update-slave-firmware `) .parse(process.argv) -const firmwareImage = program.args[0]; -const usbDir = `${__dirname}`; -const blhostUsb = getBlhostCmd(0x6121); -const blhostBuspal = `${blhostUsb} --buspal i2c,0x10,100k`; +let moduleSlot = program.args[0]; +let i2cAddress = uhk.moduleSlotToI2cAddress[moduleSlot]; +if (!i2cAddress) { + echo(`Invalid module slot specified.`); + echo(`Valid slots are: ${Object.keys(uhk.moduleSlotToI2cAddress).join(', ')}.`); + exit(1); +} + +i2cAddress = `0x${i2cAddress.toString(16)}`; + +const firmwareImage = program.args[1]; checkFirmwareImage(firmwareImage, extension); +const usbDir = `${__dirname}`; +const blhostUsb = getBlhostCmd(0x6121); +const blhostBuspal = `${blhostUsb} --buspal i2c,${i2cAddress},100k`; + config.verbose = true; -exec(`${usbDir}/send-kboot-command-to-slave.js ping 0x10`); +exec(`${usbDir}/send-kboot-command-to-slave.js ping ${i2cAddress}`); exec(`${usbDir}/jump-to-slave-bootloader.js`); exec(`${usbDir}/reenumerate.js buspal`); execRetry(`${blhostBuspal} get-property 1`); @@ -26,7 +38,7 @@ exec(`${blhostBuspal} flash-erase-all-unsecure`); exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`); exec(`${blhostUsb} reset`); exec(`${usbDir}/reenumerate.js normalKeyboard`); -execRetry(`${usbDir}/send-kboot-command-to-slave.js reset 0x10`); +execRetry(`${usbDir}/send-kboot-command-to-slave.js reset ${i2cAddress}`); config.verbose = false; -echo('Firmware updated successfully'); +echo('Firmware updated successfully.');