Add jump to slave bootloader command.

This commit is contained in:
László Monda
2017-10-12 19:57:41 +02:00
parent d2fd7bc613
commit ef34094004
4 changed files with 36 additions and 1 deletions

View File

@@ -174,6 +174,19 @@ status_t UhkModuleSlaveDriver_Update(uint8_t uhkModuleDriverId)
BoolBitsToBytes(rxMessage->data, CurrentKeyStates[slotId], uhkModuleState->features.keyCount);
}
status = kStatus_Uhk_NoTransfer;
*uhkModulePhase = UhkModulePhase_JumpToBootloader;
break;
// Jump to bootloader
case UhkModulePhase_JumpToBootloader:
if (uhkModuleState->jumpToBootloader) {
txMessage.data[0] = SlaveCommand_JumpToBootloader;
txMessage.length = 1;
status = tx(i2cAddress);
uhkModuleState->jumpToBootloader = false;
} else {
status = kStatus_Uhk_NoTransfer;
}
*uhkModulePhase = UhkModulePhase_SetTestLed;
break;

View File

@@ -47,8 +47,9 @@
UhkModulePhase_ProcessKeystates,
// Misc phases
UhkModulePhase_SetLedPwmBrightness,
UhkModulePhase_JumpToBootloader,
UhkModulePhase_SetTestLed,
UhkModulePhase_SetLedPwmBrightness,
} uhk_module_phase_t;
@@ -67,6 +68,7 @@
uint8_t firmwareI2cAddress;
uint8_t bootloaderI2cAddress;
uhk_module_features_t features;
bool jumpToBootloader;
} uhk_module_state_t;
typedef struct {

View File

@@ -265,6 +265,18 @@ void getDebugInfo(void)
GenericHidOutBuffer[8] = (ticks >> 56) & 0xff;
*/}
void jumpToSlaveBootloader(void)
{
uint8_t uhkModuleDriverId = GenericHidInBuffer[1];
if (uhkModuleDriverId >= UHK_MODULE_MAX_COUNT) {
setError(JumpToBootloaderError_InvalidModuleDriverId);
return;
}
UhkModuleStates[uhkModuleDriverId].jumpToBootloader = true;
}
// The main protocol handler function
void UsbProtocolHandler(void)
@@ -316,6 +328,9 @@ void UsbProtocolHandler(void)
case UsbCommand_GetDebugInfo:
getDebugInfo();
break;
case UsbCommand_JumpToSlaveBootloader:
jumpToSlaveBootloader();
break;
default:
break;
}

View File

@@ -23,6 +23,7 @@
UsbCommand_ReadUserConfiguration = 15,
UsbCommand_GetKeyboardState = 16,
UsbCommand_GetDebugInfo = 17,
UsbCommand_JumpToSlaveBootloader = 18,
} usb_command_t;
typedef enum {
@@ -35,6 +36,10 @@
ConfigTransferResponse_BufferOutOfBounds = 2,
} config_transfer_response_t;
typedef enum {
JumpToBootloaderError_InvalidModuleDriverId = 1,
} jump_to_bootloader_error_t;
// Functions:
void UsbProtocolHandler(void);