diff --git a/left/build/kds/blhost-unix.sh b/left/build/kds/blhost-unix.sh index f2a5a0f..1ad1f0d 100755 --- a/left/build/kds/blhost-unix.sh +++ b/left/build/kds/blhost-unix.sh @@ -36,5 +36,5 @@ $blhost flash-erase-all-unsecure $blhost write-memory 0x0 "$firmware_image" $blhost reset sleep 4 -$usb_dir/send-kboot-reset.js -../../../lib/bootloader/bin/Tools/blhost/$blhost_path/blhost --usb 0x1d50,0x6121 reset +$usb_dir/send-kboot-command.js reset 0x10 +#../../../lib/bootloader/bin/Tools/blhost/$blhost_path/blhost --usb 0x1d50,0x6121 reset diff --git a/lib/agent b/lib/agent index 1a0fa5b..1b22a2e 160000 --- a/lib/agent +++ b/lib/agent @@ -1 +1 @@ -Subproject commit 1a0fa5b5bae88ce0cd5e6c07d35e3bc0195a8f53 +Subproject commit 1b22a2e739ed32d34608b70c3f694ad62b64468a diff --git a/right/src/slave_drivers/kboot_driver.c b/right/src/slave_drivers/kboot_driver.c index db38e42..275a659 100644 --- a/right/src/slave_drivers/kboot_driver.c +++ b/right/src/slave_drivers/kboot_driver.c @@ -7,6 +7,7 @@ kboot_driver_state_t KbootDriverState; static uint8_t rxBuffer[MAX_KBOOT_COMMAND_LENGTH]; static uint8_t resetCommand[] = {0x5a, 0xa4, 0x04, 0x00, 0x6f, 0x46, 0x0b, 0x00, 0x00, 0x00}; static uint8_t ackMessage[] = {0x5a, 0xa1}; + static status_t tx(uint8_t *buffer, uint8_t length) { return I2cAsyncWrite(KbootDriverState.i2cAddress, buffer, length); @@ -25,23 +26,31 @@ status_t KbootSlaveDriver_Update(uint8_t kbootInstanceId) { status_t status = kStatus_Uhk_IdleSlave; - if (!KbootDriverState.isTransferScheduled) { - return status; - } - - switch (KbootDriverState.phase++) { - case 0: - status = tx(resetCommand, sizeof(resetCommand)); + switch (KbootDriverState.commandType) { + case KbootCommand_Idle: break; - case 1: - status = rx(2); + case KbootCommand_Ping: break; - case 2: - status = rx(18); + case KbootCommand_Reset: + switch (KbootDriverState.phase) { + case 0: + status = tx(resetCommand, sizeof(resetCommand)); + KbootDriverState.phase++; + break; + case 1: + status = rx(2); + KbootDriverState.phase++; + break; + case 2: + status = rx(18); + KbootDriverState.phase++; + break; + case 3: + status = tx(ackMessage, sizeof(ackMessage)); + KbootDriverState.commandType = KbootCommand_Idle; + break; + } break; - case 3: - status = tx(ackMessage, sizeof(ackMessage)); - KbootDriverState.isTransferScheduled = false; } return status; diff --git a/right/src/slave_drivers/kboot_driver.h b/right/src/slave_drivers/kboot_driver.h index af0b82b..16bbf3a 100644 --- a/right/src/slave_drivers/kboot_driver.h +++ b/right/src/slave_drivers/kboot_driver.h @@ -15,8 +15,14 @@ KbootDriverId_Singleton, } kboot_driver_id_t; + typedef enum { + KbootCommand_Idle, + KbootCommand_Ping, + KbootCommand_Reset, + } kboot_command_t; + typedef struct { - bool isTransferScheduled; + kboot_command_t commandType; uint8_t i2cAddress; uint8_t phase; } kboot_driver_state_t; diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index 6be65b0..8cdff7e 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -281,9 +281,9 @@ void jumpToSlaveBootloader(void) void sendKbootCommand(void) { - uint8_t i2cAddress = GenericHidInBuffer[1]; - KbootDriverState.i2cAddress = i2cAddress; - KbootDriverState.isTransferScheduled = true; + KbootDriverState.phase = 0; + KbootDriverState.i2cAddress = GenericHidInBuffer[2]; + KbootDriverState.commandType = GenericHidInBuffer[1]; } // The main protocol handler function