Merge branch 'master' into add-device-name

This commit is contained in:
László Monda
2017-10-28 18:46:46 +02:00
34 changed files with 347 additions and 460 deletions

View File

@@ -1,6 +0,0 @@
#ifndef __BOOTLOADER_CONFIG_H__
#define __BOOTLOADER_CONFIG_H__
//#define ENABLE_BUSPAL
#endif

View File

@@ -2,7 +2,6 @@
#include "usb_descriptor.h"
#include "usb_device_config.h"
#include "composite.h"
#include "bootloader_config.h"
#include "microseconds/microseconds.h"
#include "i2c.h"
#include "peripherals/test_led.h"

View File

@@ -3,9 +3,10 @@
#include "crc16.h"
#include "bus_pal_hardware.h"
#include "peripherals/test_led.h"
#if FIXED_BUSPAL_BOOTLOADER
#include "microseconds/microseconds.h"
#endif
#include "microseconds/microseconds.h"
#include "bootloader/wormhole.h"
#define FIXED_BUSPAL_BOOTLOADER 1 // Used to mark the fixed BusPal bootloader. Macro usage can be removed in the future.
command_processor_data_t g_commandData;
buspal_state_t g_buspalState = kBuspal_Idle;
@@ -483,6 +484,10 @@ status_t bootloader_command_pump()
handle_write_memory_command(g_commandData.packet, g_commandData.packetLength);
g_commandData.state = kCommandState_DataPhaseWrite;
} else if (cmdTag == kCommandTag_Reset) {
Wormhole.magicNumber = WORMHOLE_MAGIC_NUMBER;
Wormhole.enumerationMode = EnumerationMode_NormalKeyboard;
NVIC_SystemReset();
}
status = handle_command_internal(g_commandData.packet, g_commandData.packetLength);

View File

@@ -5,7 +5,5 @@
#define I2C_WATCHDOG
// #define LED_DRIVER_STRESS_TEST
#define FIXED_BUSPAL_BOOTLOADER 1 // Used to mark the fixed BusPal bootloader. Macro usage can be removed in the future.
// #define FORCE_BUSPAL 1
#endif

View File

@@ -9,8 +9,8 @@
#include "peripherals/test_led.h"
#include "usb_interfaces/usb_interface_basic_keyboard.h"
#include "usb_interfaces/usb_interface_media_keyboard.h"
#include "usb_protocol_handler.h"
#include "bus_pal_hardware.h"
#include "bootloader_config.h"
#include "command.h"
#include "bootloader/wormhole.h"
#include "eeprom.h"
@@ -44,13 +44,14 @@ void UpdateUsbReports(void)
return;
}
KeyMatrix_Scan(&KeyMatrix);
memcpy(CurrentKeyStates[SlotId_RightKeyboardHalf], KeyMatrix.keyStates, MAX_KEY_COUNT_PER_MODULE);
ResetActiveUsbBasicKeyboardReport();
ResetActiveUsbMediaKeyboardReport();
ResetActiveUsbSystemKeyboardReport();
KeyMatrix_Scan(&KeyMatrix);
memcpy(CurrentKeyStates[SlotId_RightKeyboardHalf], KeyMatrix.keyStates, MAX_KEY_COUNT_PER_MODULE);
UpdateActiveUsbReports();
SwitchActiveUsbBasicKeyboardReport();
@@ -79,11 +80,6 @@ void main(void)
InitPeripherals();
EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_HardwareConfig, hardwareConfigurationReadFinished);
#ifdef FORCE_BUSPAL
Wormhole.magicNumber = WORMHOLE_MAGIC_NUMBER;
Wormhole.enumerationMode = EnumerationMode_BusPal;
#endif
if (Wormhole.magicNumber == WORMHOLE_MAGIC_NUMBER && Wormhole.enumerationMode == EnumerationMode_BusPal) {
Wormhole.magicNumber = 0;
init_hardware();

View File

@@ -70,7 +70,7 @@ void LedSlaveDriver_Init(uint8_t ledDriverId) {
currentLedDriverState->phase = LedDriverPhase_SetFunctionFrame;
currentLedDriverState->ledIndex = 0;
memset(LedDriverValues[ledDriverId], LED_BRIGHTNESS_LEVEL, LED_DRIVER_LED_COUNT);
LedDisplay_SetText(3, "ABC");
LedDisplay_SetText(3, "FTY");
}
status_t LedSlaveDriver_Update(uint8_t ledDriverId) {

View File

@@ -0,0 +1,80 @@
#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 pingCommand[] = {0x5a, 0xa6};
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;
switch (KbootDriverState.commandType) {
case KbootCommand_Idle:
break;
case KbootCommand_Ping:
switch (KbootDriverState.phase) {
case 0:
status = tx(pingCommand, sizeof(pingCommand));
KbootDriverState.phase++;
break;
case 1:
KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus;
KbootDriverState.phase = KbootDriverState.status == kStatus_Success ? 2 : 0;
return kStatus_Uhk_NoTransfer;
case 2:
status = rx(10);
KbootDriverState.phase++;
break;
case 3:
KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus;
if (KbootDriverState.status == kStatus_Success) {
KbootDriverState.commandType = KbootCommand_Idle;
} else {
KbootDriverState.phase = 0;
return kStatus_Uhk_NoTransfer;
}
}
break;
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;
}
return status;
}

View File

@@ -0,0 +1,40 @@
#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 enum {
KbootCommand_Idle,
KbootCommand_Ping,
KbootCommand_Reset,
} kboot_command_t;
typedef struct {
kboot_command_t commandType;
uint8_t i2cAddress;
uint8_t phase;
uint32_t status;
} 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 "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)
@@ -51,6 +57,8 @@ static void slaveSchedulerCallback(I2C_Type *base, i2c_master_handle_t *handle,
uhk_slave_t *previousSlave = Slaves + previousSlaveId;
uhk_slave_t *currentSlave = Slaves + currentSlaveId;
previousSlave->previousStatus = previousStatus;
if (isFirstIteration) {
bool wasPreviousSlaveConnected = previousSlave->isConnected;
previousSlave->isConnected = previousStatus == kStatus_Success;

View File

@@ -13,6 +13,7 @@
SlaveId_RightAddon,
SlaveId_RightLedDriver,
SlaveId_LeftLedDriver,
SlaveId_KbootDriver,
} slave_id_t;
typedef void (slave_init_t)(uint8_t);
@@ -25,6 +26,7 @@
slave_update_t *update;
slave_disconnect_t *disconnect;
bool isConnected;
status_t previousStatus;
} uhk_slave_t;
typedef enum {

View File

@@ -2,7 +2,6 @@
#include "usb_composite_device.h"
#include "usb_descriptors/usb_descriptor_hid.h"
#include "usb_descriptors/usb_descriptor_strings.h"
#include "bootloader_config.h"
#include "bus_pal_hardware.h"
#include "bootloader/wormhole.h"
@@ -12,9 +11,9 @@ usb_composite_device_t UsbCompositeDevice;
usb_device_class_config_struct_t UsbDeviceCompositeClassConfig[USB_DEVICE_CONFIG_HID] = {
{UsbGenericHidCallback, (class_handle_t)NULL, &UsbGenericHidClass},
{UsbBasicKeyboardCallback, (class_handle_t)NULL, &UsbBasicKeyboardClass},
{UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass},
{UsbMediaKeyboardCallback, (class_handle_t)NULL, &UsbMediaKeyboardClass},
{UsbSystemKeyboardCallback, (class_handle_t)NULL, &UsbSystemKeyboardClass},
{UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass},
};
usb_device_class_config_list_struct_t UsbDeviceCompositeConfigList = {
@@ -43,9 +42,9 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event,
UsbCompositeDevice.currentConfiguration = *temp8;
UsbGenericHidSetConfiguration(UsbCompositeDevice.genericHidHandle, *temp8);
UsbBasicKeyboardSetConfiguration(UsbCompositeDevice.basicKeyboardHandle, *temp8);
UsbMouseSetConfiguration(UsbCompositeDevice.mouseHandle, *temp8);
UsbMediaKeyboardSetConfiguration(UsbCompositeDevice.mediaKeyboardHandle, *temp8);
UsbSystemKeyboardSetConfiguration(UsbCompositeDevice.systemKeyboardHandle, *temp8);
UsbMouseSetConfiguration(UsbCompositeDevice.mouseHandle, *temp8);
error = kStatus_USB_Success;
break;
case kUSB_DeviceEventGetConfiguration:
@@ -60,9 +59,9 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event,
UsbCompositeDevice.currentInterfaceAlternateSetting[interface] = alternateSetting;
UsbGenericHidSetInterface(UsbCompositeDevice.genericHidHandle, interface, alternateSetting);
UsbBasicKeyboardSetInterface(UsbCompositeDevice.basicKeyboardHandle, interface, alternateSetting);
UsbMouseSetInterface(UsbCompositeDevice.mouseHandle, interface, alternateSetting);
UsbMediaKeyboardSetInterface(UsbCompositeDevice.mediaKeyboardHandle, interface, alternateSetting);
UsbSystemKeyboardSetInterface(UsbCompositeDevice.systemKeyboardHandle, interface, alternateSetting);
UsbMouseSetInterface(UsbCompositeDevice.mouseHandle, interface, alternateSetting);
error = kStatus_USB_Success;
}
}
@@ -118,9 +117,9 @@ void InitUsb(void)
USB_DeviceClassInit(CONTROLLER_ID, &UsbDeviceCompositeConfigList, &UsbCompositeDevice.deviceHandle);
UsbCompositeDevice.genericHidHandle = UsbDeviceCompositeConfigList.config[USB_GENERIC_HID_INTERFACE_INDEX].classHandle;
UsbCompositeDevice.basicKeyboardHandle = UsbDeviceCompositeConfigList.config[USB_BASIC_KEYBOARD_INTERFACE_INDEX].classHandle;
UsbCompositeDevice.mouseHandle = UsbDeviceCompositeConfigList.config[USB_MOUSE_INTERFACE_INDEX].classHandle;
UsbCompositeDevice.mediaKeyboardHandle = UsbDeviceCompositeConfigList.config[USB_MEDIA_KEYBOARD_INTERFACE_INDEX].classHandle;
UsbCompositeDevice.systemKeyboardHandle = UsbDeviceCompositeConfigList.config[USB_SYSTEM_KEYBOARD_INTERFACE_INDEX].classHandle;
UsbCompositeDevice.mouseHandle = UsbDeviceCompositeConfigList.config[USB_MOUSE_INTERFACE_INDEX].classHandle;
NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
NVIC_EnableIRQ((IRQn_Type)irqNumber);

View File

@@ -89,37 +89,6 @@ uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] =
USB_SHORT_GET_HIGH(USB_BASIC_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
USB_BASIC_KEYBOARD_INTERRUPT_IN_INTERVAL,
// Mouse interface descriptor
USB_DESCRIPTOR_LENGTH_INTERFACE,
USB_DESCRIPTOR_TYPE_INTERFACE,
USB_MOUSE_INTERFACE_INDEX,
USB_INTERFACE_ALTERNATE_SETTING_NONE,
USB_MOUSE_ENDPOINT_COUNT,
USB_CLASS_HID,
USB_HID_SUBCLASS_BOOT,
USB_HID_PROTOCOL_MOUSE,
USB_STRING_DESCRIPTOR_NONE,
// Mouse HID descriptor
USB_DESCRIPTOR_LENGTH_HID,
USB_DESCRIPTOR_TYPE_HID,
USB_SHORT_GET_LOW(USB_HID_VERSION),
USB_SHORT_GET_HIGH(USB_HID_VERSION),
USB_HID_COUNTRY_CODE_NOT_SUPPORTED,
USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE,
USB_DESCRIPTOR_TYPE_HID_REPORT,
USB_SHORT_GET_LOW(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH),
USB_SHORT_GET_HIGH(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH),
// Mouse endpoint descriptor
USB_DESCRIPTOR_LENGTH_ENDPOINT,
USB_DESCRIPTOR_TYPE_ENDPOINT,
USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
USB_ENDPOINT_INTERRUPT,
USB_SHORT_GET_LOW(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE),
USB_SHORT_GET_HIGH(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE),
USB_MOUSE_INTERRUPT_IN_INTERVAL,
// Media keyboard interface descriptor
USB_DESCRIPTOR_LENGTH_INTERFACE,
USB_DESCRIPTOR_TYPE_INTERFACE,
@@ -181,6 +150,37 @@ uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] =
USB_SHORT_GET_LOW(USB_SYSTEM_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
USB_SHORT_GET_HIGH(USB_SYSTEM_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
USB_SYSTEM_KEYBOARD_INTERRUPT_IN_INTERVAL,
// Mouse interface descriptor
USB_DESCRIPTOR_LENGTH_INTERFACE,
USB_DESCRIPTOR_TYPE_INTERFACE,
USB_MOUSE_INTERFACE_INDEX,
USB_INTERFACE_ALTERNATE_SETTING_NONE,
USB_MOUSE_ENDPOINT_COUNT,
USB_CLASS_HID,
USB_HID_SUBCLASS_BOOT,
USB_HID_PROTOCOL_MOUSE,
USB_STRING_DESCRIPTOR_NONE,
// Mouse HID descriptor
USB_DESCRIPTOR_LENGTH_HID,
USB_DESCRIPTOR_TYPE_HID,
USB_SHORT_GET_LOW(USB_HID_VERSION),
USB_SHORT_GET_HIGH(USB_HID_VERSION),
USB_HID_COUNTRY_CODE_NOT_SUPPORTED,
USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE,
USB_DESCRIPTOR_TYPE_HID_REPORT,
USB_SHORT_GET_LOW(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH),
USB_SHORT_GET_HIGH(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH),
// Mouse endpoint descriptor
USB_DESCRIPTOR_LENGTH_ENDPOINT,
USB_DESCRIPTOR_TYPE_ENDPOINT,
USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
USB_ENDPOINT_INTERRUPT,
USB_SHORT_GET_LOW(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE),
USB_SHORT_GET_HIGH(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE),
USB_MOUSE_INTERRUPT_IN_INTERVAL,
};
usb_status_t USB_DeviceGetConfigurationDescriptor(

View File

@@ -12,9 +12,9 @@ usb_status_t USB_DeviceGetHidDescriptor(
usb_status_t USB_DeviceGetHidReportDescriptor(
usb_device_handle handle, usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor)
{
if (USB_MOUSE_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
hidReportDescriptor->buffer = UsbMouseReportDescriptor;
hidReportDescriptor->length = USB_MOUSE_REPORT_DESCRIPTOR_LENGTH;
if (USB_GENERIC_HID_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
hidReportDescriptor->buffer = UsbGenericHidReportDescriptor;
hidReportDescriptor->length = USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH;
} else if (USB_BASIC_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
hidReportDescriptor->buffer = UsbBasicKeyboardReportDescriptor;
hidReportDescriptor->length = USB_BASIC_KEYBOARD_REPORT_DESCRIPTOR_LENGTH;
@@ -24,9 +24,9 @@ usb_status_t USB_DeviceGetHidReportDescriptor(
} else if (USB_SYSTEM_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
hidReportDescriptor->buffer = UsbSystemKeyboardReportDescriptor;
hidReportDescriptor->length = USB_MEDIA_KEYBOARD_REPORT_DESCRIPTOR_LENGTH;
} else if (USB_GENERIC_HID_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
hidReportDescriptor->buffer = UsbGenericHidReportDescriptor;
hidReportDescriptor->length = USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH;
} else if (USB_MOUSE_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
hidReportDescriptor->buffer = UsbMouseReportDescriptor;
hidReportDescriptor->length = USB_MOUSE_REPORT_DESCRIPTOR_LENGTH;
} else {
return kStatus_USB_InvalidRequest;
}

View File

@@ -6,12 +6,13 @@ uint8_t UsbSystemKeyboardReportDescriptor[USB_SYSTEM_KEYBOARD_REPORT_DESCRIPTOR_
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_SYSTEM_CONTROL),
HID_RI_COLLECTION(8, HID_RI_COLLECTION_APPLICATION),
// System key
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
HID_RI_USAGE_MINIMUM(8, 0x00),
HID_RI_USAGE_MAXIMUM(8, 0xFF),
HID_RI_REPORT_SIZE(8, 2),
HID_RI_REPORT_COUNT(8, USB_SYSTEM_KEYBOARD_MAX_KEYS),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
HID_RI_LOGICAL_MINIMUM(8, 1),
HID_RI_LOGICAL_MAXIMUM(8, 3),
HID_RI_USAGE(8, 0x82),
HID_RI_USAGE(8, 0x81),
HID_RI_USAGE(8, 0x83),
HID_RI_INPUT(8, HID_IOF_NO_PREFERRED_STATE | HID_IOF_NULLSTATE),
HID_RI_END_COLLECTION(0),
};

View File

@@ -3,7 +3,7 @@
// Macros:
#define USB_SYSTEM_KEYBOARD_REPORT_DESCRIPTOR_LENGTH 21
#define USB_SYSTEM_KEYBOARD_REPORT_DESCRIPTOR_LENGTH 23
#define USB_SYSTEM_KEYBOARD_MAX_KEYS 1
// Variables:

View File

@@ -4,22 +4,22 @@
// KHCI instance count
#define USB_DEVICE_CONFIG_KHCI 1
#include "usb_interfaces/usb_interface_generic_hid.h"
#include "usb_interfaces/usb_interface_basic_keyboard.h"
#include "usb_interfaces/usb_interface_media_keyboard.h"
#include "usb_interfaces/usb_interface_system_keyboard.h"
#include "usb_interfaces/usb_interface_mouse.h"
#include "usb_interfaces/usb_interface_generic_hid.h"
// Device instance count, the sum of KHCI and EHCI instance counts
#define USB_DEVICE_CONFIG_NUM 1
// HID instance count
#define USB_DEVICE_CONFIG_HID ( \
USB_GENERIC_HID_INTERFACE_COUNT +\
USB_BASIC_KEYBOARD_INTERFACE_COUNT + \
USB_MEDIA_KEYBOARD_INTERFACE_COUNT + \
USB_SYSTEM_KEYBOARD_INTERFACE_COUNT + \
USB_MOUSE_INTERFACE_COUNT + \
USB_GENERIC_HID_INTERFACE_COUNT \
USB_MOUSE_INTERFACE_COUNT \
)
// Whether the device is self-powered: 1 supported, 0 not supported
@@ -34,11 +34,11 @@
// How many endpoints are supported in the stack
#define USB_DEVICE_CONFIG_ENDPOINTS ( \
USB_CONTROL_ENDPOINT_COUNT + \
USB_GENERIC_HID_ENDPOINT_COUNT + \
USB_BASIC_KEYBOARD_ENDPOINT_COUNT + \
USB_MEDIA_KEYBOARD_ENDPOINT_COUNT + \
USB_SYSTEM_KEYBOARD_ENDPOINT_COUNT + \
USB_MOUSE_ENDPOINT_COUNT + \
USB_GENERIC_HID_ENDPOINT_COUNT \
USB_MOUSE_ENDPOINT_COUNT \
)
// The maximum buffer length for the KHCI DMA workaround

View File

@@ -1,5 +1,6 @@
#include "usb_composite_device.h"
#include "usb_interface_generic_hid.h"
#include "usb_protocol_handler.h"
static usb_device_endpoint_struct_t UsbGenericHidEndpoints[USB_GENERIC_HID_ENDPOINT_COUNT] =
{

View File

@@ -5,7 +5,6 @@
#include "usb_api.h"
#include "usb_descriptors/usb_descriptor_device.h"
#include "usb_protocol_handler.h"
// Macros:

View File

@@ -9,10 +9,10 @@
// Macros:
#define USB_MEDIA_KEYBOARD_INTERFACE_INDEX 3
#define USB_MEDIA_KEYBOARD_INTERFACE_INDEX 2
#define USB_MEDIA_KEYBOARD_INTERFACE_COUNT 1
#define USB_MEDIA_KEYBOARD_ENDPOINT_INDEX 5
#define USB_MEDIA_KEYBOARD_ENDPOINT_INDEX 4
#define USB_MEDIA_KEYBOARD_ENDPOINT_COUNT 1
#define USB_MEDIA_KEYBOARD_INTERRUPT_IN_PACKET_SIZE 8

View File

@@ -8,10 +8,10 @@
// Macros:
#define USB_MOUSE_INTERFACE_INDEX 2
#define USB_MOUSE_INTERFACE_INDEX 4
#define USB_MOUSE_INTERFACE_COUNT 1
#define USB_MOUSE_ENDPOINT_INDEX 4
#define USB_MOUSE_ENDPOINT_INDEX 6
#define USB_MOUSE_ENDPOINT_COUNT 1
#define USB_MOUSE_INTERRUPT_IN_PACKET_SIZE 8

View File

@@ -10,10 +10,10 @@
// Macros:
#define USB_SYSTEM_KEYBOARD_INTERFACE_INDEX 4
#define USB_SYSTEM_KEYBOARD_INTERFACE_INDEX 3
#define USB_SYSTEM_KEYBOARD_INTERFACE_COUNT 1
#define USB_SYSTEM_KEYBOARD_ENDPOINT_INDEX 6
#define USB_SYSTEM_KEYBOARD_ENDPOINT_INDEX 5
#define USB_SYSTEM_KEYBOARD_ENDPOINT_COUNT 1
#define USB_SYSTEM_KEYBOARD_INTERRUPT_IN_PACKET_SIZE 1

View File

@@ -9,12 +9,16 @@
#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"
uint8_t UsbDebugInfo[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
// Functions for setting error statuses
void setError(uint8_t error)
@@ -72,8 +76,8 @@ void reenumerate(void)
{
Wormhole.magicNumber = WORMHOLE_MAGIC_NUMBER;
Wormhole.enumerationMode = GenericHidInBuffer[1];
SCB->AIRCR = 0x5FA<<SCB_AIRCR_VECTKEY_Pos | SCB_AIRCR_SYSRESETREQ_Msk; // Reset the MCU.
for (;;);
Wormhole.timeoutMs = *((uint32_t*)(GenericHidInBuffer+2));
NVIC_SystemReset();
}
void setTestLed(void)
@@ -231,26 +235,29 @@ void getKeyboardState(void)
void getDebugInfo(void)
{
GenericHidOutBuffer[1] = I2C_Watchdog >> 0;
GenericHidOutBuffer[2] = I2C_Watchdog >> 8;
GenericHidOutBuffer[3] = I2C_Watchdog >> 16;
GenericHidOutBuffer[4] = I2C_Watchdog >> 24;
UsbDebugInfo[0] = I2C_Watchdog >> 0;
UsbDebugInfo[1] = I2C_Watchdog >> 8;
UsbDebugInfo[2] = I2C_Watchdog >> 16;
UsbDebugInfo[3] = I2C_Watchdog >> 24;
GenericHidOutBuffer[5] = I2cSchedulerCounter >> 0;
GenericHidOutBuffer[6] = I2cSchedulerCounter >> 8;
GenericHidOutBuffer[7] = I2cSchedulerCounter >> 16;
GenericHidOutBuffer[8] = I2cSchedulerCounter >> 24;
UsbDebugInfo[4] = I2cSchedulerCounter >> 0;
UsbDebugInfo[5] = I2cSchedulerCounter >> 8;
UsbDebugInfo[6] = I2cSchedulerCounter >> 16;
UsbDebugInfo[7] = I2cSchedulerCounter >> 24;
GenericHidOutBuffer[9] = I2cWatchdog_OuterCounter >> 0;
GenericHidOutBuffer[10] = I2cWatchdog_OuterCounter >> 8;
GenericHidOutBuffer[11] = I2cWatchdog_OuterCounter >> 16;
GenericHidOutBuffer[12] = I2cWatchdog_OuterCounter >> 24;
UsbDebugInfo[8] = I2cWatchdog_OuterCounter >> 0;
UsbDebugInfo[9] = I2cWatchdog_OuterCounter >> 8;
UsbDebugInfo[10] = I2cWatchdog_OuterCounter >> 16;
UsbDebugInfo[11] = I2cWatchdog_OuterCounter >> 24;
GenericHidOutBuffer[13] = I2cWatchdog_InnerCounter >> 0;
GenericHidOutBuffer[14] = I2cWatchdog_InnerCounter >> 8;
GenericHidOutBuffer[15] = I2cWatchdog_InnerCounter >> 16;
GenericHidOutBuffer[16] = I2cWatchdog_InnerCounter >> 24;
/*
UsbDebugInfo[12] = I2cWatchdog_InnerCounter >> 0;
UsbDebugInfo[13] = I2cWatchdog_InnerCounter >> 8;
UsbDebugInfo[14] = I2cWatchdog_InnerCounter >> 16;
UsbDebugInfo[15] = I2cWatchdog_InnerCounter >> 24;
memcpy(GenericHidOutBuffer, UsbDebugInfo, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
/*
uint64_t ticks = microseconds_get_ticks();
uint32_t microseconds = microseconds_convert_to_microseconds(ticks);
uint32_t milliseconds = microseconds/1000;
@@ -277,6 +284,13 @@ void jumpToSlaveBootloader(void)
UhkModuleStates[uhkModuleDriverId].jumpToBootloader = true;
}
void sendKbootCommand(void)
{
KbootDriverState.phase = 0;
KbootDriverState.i2cAddress = GenericHidInBuffer[2];
KbootDriverState.commandType = GenericHidInBuffer[1];
}
// The main protocol handler function
void UsbProtocolHandler(void)
@@ -331,6 +345,9 @@ void UsbProtocolHandler(void)
case UsbCommand_JumpToSlaveBootloader:
jumpToSlaveBootloader();
break;
case UsbCommand_SendKbootCommand:
sendKbootCommand();
break;
default:
break;
}

View File

@@ -23,7 +23,8 @@
UsbCommand_ReadUserConfiguration = 15,
UsbCommand_GetKeyboardState = 16,
UsbCommand_GetDebugInfo = 17,
UsbCommand_JumpToSlaveBootloader = 18,
UsbCommand_JumpToSlaveBootloader = 18,
UsbCommand_SendKbootCommand = 19,
} usb_command_t;
typedef enum {
@@ -40,6 +41,10 @@
JumpToBootloaderError_InvalidModuleDriverId = 1,
} jump_to_bootloader_error_t;
// Variables:
extern uint8_t UsbDebugInfo[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
// Functions:
void UsbProtocolHandler(void);