diff --git a/left/build/kds/blhost-unix.sh b/left/build/kds/blhost-unix.sh index e796507..f2a5a0f 100755 --- a/left/build/kds/blhost-unix.sh +++ b/left/build/kds/blhost-unix.sh @@ -35,4 +35,6 @@ $blhost get-property 1 $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 diff --git a/lib/agent b/lib/agent index ce91d88..1a0fa5b 160000 --- a/lib/agent +++ b/lib/agent @@ -1 +1 @@ -Subproject commit ce91d8844892270bd5d628519338e301f0814885 +Subproject commit 1a0fa5b5bae88ce0cd5e6c07d35e3bc0195a8f53 diff --git a/right/src/slave_drivers/kboot_driver.c b/right/src/slave_drivers/kboot_driver.c new file mode 100644 index 0000000..db38e42 --- /dev/null +++ b/right/src/slave_drivers/kboot_driver.c @@ -0,0 +1,48 @@ +#include "slave_drivers/kboot_driver.h" +#include "slave_scheduler.h" +#include "i2c.h" + +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); +} + +static status_t rx(uint8_t length) +{ + return I2cAsyncRead(KbootDriverState.i2cAddress, rxBuffer, length); +} + +void KbootSlaveDriver_Init(uint8_t kbootInstanceId) +{ +} + +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)); + break; + case 1: + status = rx(2); + break; + case 2: + status = rx(18); + 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 new file mode 100644 index 0000000..af0b82b --- /dev/null +++ b/right/src/slave_drivers/kboot_driver.h @@ -0,0 +1,33 @@ +#ifndef __KBOOT_DRIVER_H__ +#define __KBOOT_DRIVER_H__ + +// Includes: + + #include "fsl_common.h" + +// Macros: + + #define MAX_KBOOT_COMMAND_LENGTH 32 + +// Typedefs: + + typedef enum { + KbootDriverId_Singleton, + } kboot_driver_id_t; + + typedef struct { + bool isTransferScheduled; + uint8_t i2cAddress; + uint8_t phase; + } kboot_driver_state_t; + +// Variables: + + extern kboot_driver_state_t KbootDriverState; + +// Functions: + + void KbootSlaveDriver_Init(uint8_t kbootInstanceId); + status_t KbootSlaveDriver_Update(uint8_t kbootInstanceId); + +#endif diff --git a/right/src/slave_scheduler.c b/right/src/slave_scheduler.c index f01aa10..b25e9c4 100644 --- a/right/src/slave_scheduler.c +++ b/right/src/slave_scheduler.c @@ -4,6 +4,7 @@ #include "main.h" #include "slave_drivers/is31fl3731_driver.h" #include "slave_drivers/uhk_module_driver.h" +#include "slave_drivers/kboot_driver.h" #include "i2c.h" #include "i2c_addresses.h" @@ -39,6 +40,11 @@ uhk_slave_t Slaves[] = { .update = LedSlaveDriver_Update, .perDriverId = LedDriverId_Left, }, + { + .init = KbootSlaveDriver_Init, + .update = KbootSlaveDriver_Update, + .perDriverId = KbootDriverId_Singleton, + }, }; static void slaveSchedulerCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t previousStatus, void *userData) diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index d22d07d..6be65b0 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -9,12 +9,14 @@ #include "led_pwm.h" #include "slave_scheduler.h" #include "slave_drivers/uhk_module_driver.h" +#include "slave_drivers/kboot_driver.h" #include "bootloader/wormhole.h" #include "peripherals/adc.h" #include "eeprom.h" #include "keymaps.h" #include "microseconds/microseconds_pit.c" #include "i2c_watchdog.h" + // Functions for setting error statuses void setError(uint8_t error) @@ -277,6 +279,13 @@ void jumpToSlaveBootloader(void) UhkModuleStates[uhkModuleDriverId].jumpToBootloader = true; } +void sendKbootCommand(void) +{ + uint8_t i2cAddress = GenericHidInBuffer[1]; + KbootDriverState.i2cAddress = i2cAddress; + KbootDriverState.isTransferScheduled = true; +} + // The main protocol handler function void UsbProtocolHandler(void) @@ -331,6 +340,9 @@ void UsbProtocolHandler(void) case UsbCommand_JumpToSlaveBootloader: jumpToSlaveBootloader(); break; + case UsbCommand_SendKbootCommand: + sendKbootCommand(); + break; default: break; } diff --git a/right/src/usb_protocol_handler.h b/right/src/usb_protocol_handler.h index f4808df..450375d 100644 --- a/right/src/usb_protocol_handler.h +++ b/right/src/usb_protocol_handler.h @@ -24,6 +24,7 @@ UsbCommand_GetKeyboardState = 16, UsbCommand_GetDebugInfo = 17, UsbCommand_JumpToSlaveBootloader = 18, + UsbCommand_SendKbootCommand = 19, } usb_command_t; typedef enum {