Add KBOOT I2C slave driver, its related USB command, and make the firmware updater script of the left half successfully reset the left half after firmware update.

This commit is contained in:
László Monda
2017-10-22 02:17:43 +02:00
parent e57d199b40
commit 92ee3b5606
7 changed files with 103 additions and 1 deletions

View File

@@ -35,4 +35,6 @@ $blhost get-property 1
$blhost flash-erase-all-unsecure $blhost flash-erase-all-unsecure
$blhost write-memory 0x0 "$firmware_image" $blhost write-memory 0x0 "$firmware_image"
$blhost reset $blhost reset
sleep 4
$usb_dir/send-kboot-reset.js
../../../lib/bootloader/bin/Tools/blhost/$blhost_path/blhost --usb 0x1d50,0x6121 reset ../../../lib/bootloader/bin/Tools/blhost/$blhost_path/blhost --usb 0x1d50,0x6121 reset

View File

@@ -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;
}

View File

@@ -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

View File

@@ -4,6 +4,7 @@
#include "main.h" #include "main.h"
#include "slave_drivers/is31fl3731_driver.h" #include "slave_drivers/is31fl3731_driver.h"
#include "slave_drivers/uhk_module_driver.h" #include "slave_drivers/uhk_module_driver.h"
#include "slave_drivers/kboot_driver.h"
#include "i2c.h" #include "i2c.h"
#include "i2c_addresses.h" #include "i2c_addresses.h"
@@ -39,6 +40,11 @@ uhk_slave_t Slaves[] = {
.update = LedSlaveDriver_Update, .update = LedSlaveDriver_Update,
.perDriverId = LedDriverId_Left, .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) static void slaveSchedulerCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t previousStatus, void *userData)

View File

@@ -9,12 +9,14 @@
#include "led_pwm.h" #include "led_pwm.h"
#include "slave_scheduler.h" #include "slave_scheduler.h"
#include "slave_drivers/uhk_module_driver.h" #include "slave_drivers/uhk_module_driver.h"
#include "slave_drivers/kboot_driver.h"
#include "bootloader/wormhole.h" #include "bootloader/wormhole.h"
#include "peripherals/adc.h" #include "peripherals/adc.h"
#include "eeprom.h" #include "eeprom.h"
#include "keymaps.h" #include "keymaps.h"
#include "microseconds/microseconds_pit.c" #include "microseconds/microseconds_pit.c"
#include "i2c_watchdog.h" #include "i2c_watchdog.h"
// Functions for setting error statuses // Functions for setting error statuses
void setError(uint8_t error) void setError(uint8_t error)
@@ -277,6 +279,13 @@ void jumpToSlaveBootloader(void)
UhkModuleStates[uhkModuleDriverId].jumpToBootloader = true; UhkModuleStates[uhkModuleDriverId].jumpToBootloader = true;
} }
void sendKbootCommand(void)
{
uint8_t i2cAddress = GenericHidInBuffer[1];
KbootDriverState.i2cAddress = i2cAddress;
KbootDriverState.isTransferScheduled = true;
}
// The main protocol handler function // The main protocol handler function
void UsbProtocolHandler(void) void UsbProtocolHandler(void)
@@ -331,6 +340,9 @@ void UsbProtocolHandler(void)
case UsbCommand_JumpToSlaveBootloader: case UsbCommand_JumpToSlaveBootloader:
jumpToSlaveBootloader(); jumpToSlaveBootloader();
break; break;
case UsbCommand_SendKbootCommand:
sendKbootCommand();
break;
default: default:
break; break;
} }

View File

@@ -24,6 +24,7 @@
UsbCommand_GetKeyboardState = 16, UsbCommand_GetKeyboardState = 16,
UsbCommand_GetDebugInfo = 17, UsbCommand_GetDebugInfo = 17,
UsbCommand_JumpToSlaveBootloader = 18, UsbCommand_JumpToSlaveBootloader = 18,
UsbCommand_SendKbootCommand = 19,
} usb_command_t; } usb_command_t;
typedef enum { typedef enum {