Branch to BusPal vs keyboard function depending on Wormhole->enumerationMode
This commit is contained in:
@@ -112,7 +112,7 @@
|
|||||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.cref.742351963" name="Cross reference (-Xlinker --cref)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.cref" value="false" valueType="boolean"/>
|
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.cref.742351963" name="Cross reference (-Xlinker --cref)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.cref" value="false" valueType="boolean"/>
|
||||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.printgcsections.192927503" name="Print removed sections (-Xlinker --print-gc-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.printgcsections" value="false" valueType="boolean"/>
|
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.printgcsections.192927503" name="Print removed sections (-Xlinker --print-gc-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.printgcsections" value="false" valueType="boolean"/>
|
||||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.strip.1437487702" name="Omit all symbol information (-s)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.strip" value="false" valueType="boolean"/>
|
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.strip.1437487702" name="Omit all symbol information (-s)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.strip" value="false" valueType="boolean"/>
|
||||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.other.237939626" name="Other linker flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.other" value=" -Wall --specs=nano.specs -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -Xlinker -static -Xlinker -z -Xlinker muldefs" valueType="string"/>
|
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.other.237939626" name="Other linker flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.other" value=" -Wall --specs=nano.specs -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -Xlinker -static -Xlinker -z -Xlinker muldefs -Wl,-u,move_sp" valueType="string"/>
|
||||||
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.input.1959593877" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.input">
|
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.input.1959593877" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.input">
|
||||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include "hid_bootloader.h"
|
#include "hid_bootloader.h"
|
||||||
#include "usb_device_config.h"
|
#include "usb_device_config.h"
|
||||||
|
#include "bm_usb/usb_descriptor.h"
|
||||||
|
|
||||||
#define CONTROLLER_ID kUSB_ControllerKhci0
|
#define CONTROLLER_ID kUSB_ControllerKhci0
|
||||||
#define USB_DEVICE_INTERRUPT_PRIORITY 4
|
|
||||||
|
|
||||||
typedef struct _usb_device_composite_struct {
|
typedef struct _usb_device_composite_struct {
|
||||||
usb_device_handle device_handle; // USB device handle.
|
usb_device_handle device_handle; // USB device handle.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "fsl_rtos_abstraction.h"
|
#include "fsl_rtos_abstraction.h"
|
||||||
#include "bootloader_hid_report_ids.h"
|
#include "bootloader_hid_report_ids.h"
|
||||||
|
#include "bm_usb/usb_descriptor.h"
|
||||||
|
|
||||||
enum { // Request parameters
|
enum { // Request parameters
|
||||||
kAppRequestParam_IdleRate = 0,
|
kAppRequestParam_IdleRate = 0,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "microseconds/microseconds.h"
|
#include "microseconds/microseconds.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "peripherals/test_led.h"
|
#include "peripherals/test_led.h"
|
||||||
|
#include "usb_composite_device.h"
|
||||||
|
|
||||||
bool is_usb_active();
|
bool is_usb_active();
|
||||||
static status_t usb_device_full_init(const peripheral_descriptor_t *self, serial_byte_receive_func_t function);
|
static status_t usb_device_full_init(const peripheral_descriptor_t *self, serial_byte_receive_func_t function);
|
||||||
@@ -38,7 +39,7 @@ const peripheral_descriptor_t g_peripherals[] = {
|
|||||||
{ 0 } // Terminator
|
{ 0 } // Terminator
|
||||||
};
|
};
|
||||||
|
|
||||||
static usb_device_composite_struct_t g_device_composite;
|
usb_device_composite_struct_t BuspalCompositeUsbDevice;
|
||||||
usb_status_t usb_device_callback(usb_device_handle handle, uint32_t event, void *param);
|
usb_status_t usb_device_callback(usb_device_handle handle, uint32_t event, void *param);
|
||||||
|
|
||||||
static i2c_user_config_t s_i2cUserConfig = {.slaveAddress = 0x10, //!< The slave's 7-bit address
|
static i2c_user_config_t s_i2cUserConfig = {.slaveAddress = 0x10, //!< The slave's 7-bit address
|
||||||
@@ -70,7 +71,7 @@ bool usb_clock_init(void)
|
|||||||
|
|
||||||
bool is_usb_active()
|
bool is_usb_active()
|
||||||
{
|
{
|
||||||
return g_device_composite.attach && g_device_composite.hid_generic.hid_packet.didReceiveFirstReport;
|
return BuspalCompositeUsbDevice.attach && BuspalCompositeUsbDevice.hid_generic.hid_packet.didReceiveFirstReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_status_t usb_device_callback(usb_device_handle handle, uint32_t event, void *param)
|
usb_status_t usb_device_callback(usb_device_handle handle, uint32_t event, void *param)
|
||||||
@@ -83,27 +84,27 @@ usb_status_t usb_device_callback(usb_device_handle handle, uint32_t event, void
|
|||||||
{
|
{
|
||||||
case kUSB_DeviceEventBusReset:
|
case kUSB_DeviceEventBusReset:
|
||||||
{
|
{
|
||||||
g_device_composite.attach = 0;
|
BuspalCompositeUsbDevice.attach = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kUSB_DeviceEventSetConfiguration:
|
case kUSB_DeviceEventSetConfiguration:
|
||||||
if (param)
|
if (param)
|
||||||
{
|
{
|
||||||
g_device_composite.attach = 1;
|
BuspalCompositeUsbDevice.attach = 1;
|
||||||
g_device_composite.current_configuration = *temp8;
|
BuspalCompositeUsbDevice.current_configuration = *temp8;
|
||||||
error = usb_device_hid_generic_set_configure(g_device_composite.hid_generic.hid_handle, *temp8);
|
error = usb_device_hid_generic_set_configure(BuspalCompositeUsbDevice.hid_generic.hid_handle, *temp8);
|
||||||
error = kStatus_USB_Success;
|
error = kStatus_USB_Success;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kUSB_DeviceEventSetInterface:
|
case kUSB_DeviceEventSetInterface:
|
||||||
if (g_device_composite.attach)
|
if (BuspalCompositeUsbDevice.attach)
|
||||||
{
|
{
|
||||||
uint8_t interface = (uint8_t)((*temp16 & 0xFF00U) >> 0x08U);
|
uint8_t interface = (uint8_t)((*temp16 & 0xFF00U) >> 0x08U);
|
||||||
uint8_t alternate_setting = (uint8_t)(*temp16 & 0x00FFU);
|
uint8_t alternate_setting = (uint8_t)(*temp16 & 0x00FFU);
|
||||||
if (interface < USB_COMPOSITE_INTERFACE_COUNT)
|
if (interface < USB_COMPOSITE_INTERFACE_COUNT)
|
||||||
{
|
{
|
||||||
g_device_composite.current_interface_alternate_setting[interface] = alternate_setting;
|
BuspalCompositeUsbDevice.current_interface_alternate_setting[interface] = alternate_setting;
|
||||||
usb_device_hid_generic_set_interface(g_device_composite.hid_generic.hid_handle, interface,
|
usb_device_hid_generic_set_interface(BuspalCompositeUsbDevice.hid_generic.hid_handle, interface,
|
||||||
alternate_setting);
|
alternate_setting);
|
||||||
error = kStatus_USB_Success;
|
error = kStatus_USB_Success;
|
||||||
}
|
}
|
||||||
@@ -112,7 +113,7 @@ usb_status_t usb_device_callback(usb_device_handle handle, uint32_t event, void
|
|||||||
case kUSB_DeviceEventGetConfiguration:
|
case kUSB_DeviceEventGetConfiguration:
|
||||||
if (param)
|
if (param)
|
||||||
{
|
{
|
||||||
*temp8 = g_device_composite.current_configuration;
|
*temp8 = BuspalCompositeUsbDevice.current_configuration;
|
||||||
error = kStatus_USB_Success;
|
error = kStatus_USB_Success;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -122,7 +123,7 @@ usb_status_t usb_device_callback(usb_device_handle handle, uint32_t event, void
|
|||||||
uint8_t interface = (uint8_t)((*temp16 & 0xFF00) >> 0x08);
|
uint8_t interface = (uint8_t)((*temp16 & 0xFF00) >> 0x08);
|
||||||
if (interface < USB_COMPOSITE_INTERFACE_COUNT)
|
if (interface < USB_COMPOSITE_INTERFACE_COUNT)
|
||||||
{
|
{
|
||||||
*temp16 = (*temp16 & 0xFF00) | g_device_composite.current_interface_alternate_setting[interface];
|
*temp16 = (*temp16 & 0xFF00) | BuspalCompositeUsbDevice.current_interface_alternate_setting[interface];
|
||||||
error = kStatus_USB_Success;
|
error = kStatus_USB_Success;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -183,29 +184,29 @@ status_t usb_device_full_init(const peripheral_descriptor_t *self, serial_byte_r
|
|||||||
irqNumber = usbDeviceKhciIrq[CONTROLLER_ID - kUSB_ControllerKhci0];
|
irqNumber = usbDeviceKhciIrq[CONTROLLER_ID - kUSB_ControllerKhci0];
|
||||||
|
|
||||||
// Init the state info.
|
// Init the state info.
|
||||||
memset(&g_device_composite, 0, sizeof(g_device_composite));
|
memset(&BuspalCompositeUsbDevice, 0, sizeof(BuspalCompositeUsbDevice));
|
||||||
|
|
||||||
usb_clock_init();
|
usb_clock_init();
|
||||||
|
|
||||||
g_language_ptr = &g_language_list;
|
g_language_ptr = &g_language_list;
|
||||||
|
|
||||||
g_device_composite.speed = USB_SPEED_FULL;
|
BuspalCompositeUsbDevice.speed = USB_SPEED_FULL;
|
||||||
g_device_composite.attach = 0;
|
BuspalCompositeUsbDevice.attach = 0;
|
||||||
g_device_composite.hid_generic.hid_handle = (class_handle_t)NULL;
|
BuspalCompositeUsbDevice.hid_generic.hid_handle = (class_handle_t)NULL;
|
||||||
g_device_composite.device_handle = NULL;
|
BuspalCompositeUsbDevice.device_handle = NULL;
|
||||||
|
|
||||||
if (kStatus_USB_Success != USB_DeviceClassInit(CONTROLLER_ID, &g_composite_device_config_list, &g_device_composite.device_handle)) {
|
if (kStatus_USB_Success != USB_DeviceClassInit(CONTROLLER_ID, &g_composite_device_config_list, &BuspalCompositeUsbDevice.device_handle)) {
|
||||||
return kStatus_Fail;
|
return kStatus_Fail;
|
||||||
} else {
|
} else {
|
||||||
g_device_composite.hid_generic.hid_handle = g_composite_device_config_list.config[0].classHandle;
|
BuspalCompositeUsbDevice.hid_generic.hid_handle = g_composite_device_config_list.config[0].classHandle;
|
||||||
usb_device_hid_generic_init(&g_device_composite);
|
usb_device_hid_generic_init(&BuspalCompositeUsbDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Install isr, set priority, and enable IRQ. */
|
/* Install isr, set priority, and enable IRQ. */
|
||||||
NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
|
NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
|
||||||
NVIC_EnableIRQ((IRQn_Type)irqNumber);
|
NVIC_EnableIRQ((IRQn_Type)irqNumber);
|
||||||
|
|
||||||
USB_DeviceRun(g_device_composite.device_handle);
|
USB_DeviceRun(BuspalCompositeUsbDevice.device_handle);
|
||||||
|
|
||||||
return kStatus_Success;
|
return kStatus_Success;
|
||||||
}
|
}
|
||||||
@@ -216,7 +217,7 @@ void usb_device_full_shutdown(const peripheral_descriptor_t *self)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_device_hid_generic_deinit(&g_device_composite); // Shutdown class driver
|
usb_device_hid_generic_deinit(&BuspalCompositeUsbDevice); // Shutdown class driver
|
||||||
|
|
||||||
// Make sure we are clocking to the peripheral to ensure there are no bus errors
|
// Make sure we are clocking to the peripheral to ensure there are no bus errors
|
||||||
if (SIM->SCGC4 & SIM_SCGC4_USBOTG_MASK) {
|
if (SIM->SCGC4 & SIM_SCGC4_USBOTG_MASK) {
|
||||||
@@ -228,11 +229,11 @@ void usb_device_full_shutdown(const peripheral_descriptor_t *self)
|
|||||||
|
|
||||||
status_t usb_hid_packet_init(const peripheral_descriptor_t *self)
|
status_t usb_hid_packet_init(const peripheral_descriptor_t *self)
|
||||||
{
|
{
|
||||||
sync_init(&g_device_composite.hid_generic.hid_packet.receiveSync, false);
|
sync_init(&BuspalCompositeUsbDevice.hid_generic.hid_packet.receiveSync, false);
|
||||||
sync_init(&g_device_composite.hid_generic.hid_packet.sendSync, false);
|
sync_init(&BuspalCompositeUsbDevice.hid_generic.hid_packet.sendSync, false);
|
||||||
|
|
||||||
// Check for any received data that may be pending
|
// Check for any received data that may be pending
|
||||||
sync_signal(&g_device_composite.hid_generic.hid_packet.receiveSync);
|
sync_signal(&BuspalCompositeUsbDevice.hid_generic.hid_packet.receiveSync);
|
||||||
return kStatus_Success;
|
return kStatus_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,26 +270,26 @@ status_t usb_hid_packet_read(const peripheral_descriptor_t *self,
|
|||||||
// we request more. This mechanism prevents data loss
|
// we request more. This mechanism prevents data loss
|
||||||
// by allowing the USB controller to hold off the host with NAKs
|
// by allowing the USB controller to hold off the host with NAKs
|
||||||
// on the interrupt out pipe until we are ready.
|
// on the interrupt out pipe until we are ready.
|
||||||
if (g_device_composite.hid_generic.hid_packet.isReceiveDataRequestRequired)
|
if (BuspalCompositeUsbDevice.hid_generic.hid_packet.isReceiveDataRequestRequired)
|
||||||
{
|
{
|
||||||
// Initiate receive on interrupt out pipe.
|
// Initiate receive on interrupt out pipe.
|
||||||
USB_DeviceHidRecv(g_device_composite.hid_generic.hid_handle, USB_HID_GENERIC_ENDPOINT_OUT,
|
USB_DeviceHidRecv(BuspalCompositeUsbDevice.hid_generic.hid_handle, USB_HID_GENERIC_ENDPOINT_OUT,
|
||||||
(uint8_t *)&g_device_composite.hid_generic.hid_packet.report.header,
|
(uint8_t *)&BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header,
|
||||||
sizeof(g_device_composite.hid_generic.hid_packet.report));
|
sizeof(BuspalCompositeUsbDevice.hid_generic.hid_packet.report));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_device_composite.hid_generic.hid_packet.isReceiveDataRequestRequired = true;
|
BuspalCompositeUsbDevice.hid_generic.hid_packet.isReceiveDataRequestRequired = true;
|
||||||
|
|
||||||
// Wait until we have received a report.
|
// Wait until we have received a report.
|
||||||
|
|
||||||
sync_wait(&g_device_composite.hid_generic.hid_packet.receiveSync, kSyncWaitForever);
|
sync_wait(&BuspalCompositeUsbDevice.hid_generic.hid_packet.receiveSync, kSyncWaitForever);
|
||||||
|
|
||||||
// Check the report ID, the first byte of the report buffer.
|
// Check the report ID, the first byte of the report buffer.
|
||||||
if (g_device_composite.hid_generic.hid_packet.report.header.reportID != reportID)
|
if (BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header.reportID != reportID)
|
||||||
{
|
{
|
||||||
// If waiting for a command but get data, this is a flush after a data abort.
|
// If waiting for a command but get data, this is a flush after a data abort.
|
||||||
if ((reportID == kBootloaderReportID_CommandOut) &&
|
if ((reportID == kBootloaderReportID_CommandOut) &&
|
||||||
(g_device_composite.hid_generic.hid_packet.report.header.reportID == kBootloaderReportID_DataOut))
|
(BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header.reportID == kBootloaderReportID_DataOut))
|
||||||
{
|
{
|
||||||
return -1; // kStatus_AbortDataPhase;
|
return -1; // kStatus_AbortDataPhase;
|
||||||
}
|
}
|
||||||
@@ -299,13 +300,13 @@ status_t usb_hid_packet_read(const peripheral_descriptor_t *self,
|
|||||||
|
|
||||||
// Extract the packet length encoded as bytes 1 and 2 of the report. The packet length
|
// Extract the packet length encoded as bytes 1 and 2 of the report. The packet length
|
||||||
// is transferred in little endian byte order.
|
// is transferred in little endian byte order.
|
||||||
uint16_t lengthOfPacket = g_device_composite.hid_generic.hid_packet.report.header.packetLengthLsb |
|
uint16_t lengthOfPacket = BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header.packetLengthLsb |
|
||||||
(g_device_composite.hid_generic.hid_packet.report.header.packetLengthMsb << 8);
|
(BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header.packetLengthMsb << 8);
|
||||||
|
|
||||||
// Make sure we got all of the packet. Some hosts (Windows) may send up to the maximum
|
// Make sure we got all of the packet. Some hosts (Windows) may send up to the maximum
|
||||||
// report size, so there may be extra trailing bytes.
|
// report size, so there may be extra trailing bytes.
|
||||||
if ((g_device_composite.hid_generic.hid_packet.reportSize -
|
if ((BuspalCompositeUsbDevice.hid_generic.hid_packet.reportSize -
|
||||||
sizeof(g_device_composite.hid_generic.hid_packet.report.header)) < lengthOfPacket)
|
sizeof(BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header)) < lengthOfPacket)
|
||||||
{
|
{
|
||||||
// debug_printf("usbhid: received only %d bytes of packet with length %d\r\n",
|
// debug_printf("usbhid: received only %d bytes of packet with length %d\r\n",
|
||||||
// s_hidInfo[hidInfoIndex].reportSize - 3, lengthOfPacket);
|
// s_hidInfo[hidInfoIndex].reportSize - 3, lengthOfPacket);
|
||||||
@@ -313,7 +314,7 @@ status_t usb_hid_packet_read(const peripheral_descriptor_t *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return packet to caller.
|
// Return packet to caller.
|
||||||
*packet = g_device_composite.hid_generic.hid_packet.report.packet;
|
*packet = BuspalCompositeUsbDevice.hid_generic.hid_packet.report.packet;
|
||||||
*packetLength = lengthOfPacket;
|
*packetLength = lengthOfPacket;
|
||||||
}
|
}
|
||||||
return kStatus_Success;
|
return kStatus_Success;
|
||||||
@@ -349,31 +350,31 @@ status_t usb_hid_packet_write(const peripheral_descriptor_t *self,
|
|||||||
|
|
||||||
// Check for data phase aborted by receiver.
|
// Check for data phase aborted by receiver.
|
||||||
lock_acquire();
|
lock_acquire();
|
||||||
if (g_device_composite.hid_generic.hid_packet.didReceiveDataPhaseAbort)
|
if (BuspalCompositeUsbDevice.hid_generic.hid_packet.didReceiveDataPhaseAbort)
|
||||||
{
|
{
|
||||||
g_device_composite.hid_generic.hid_packet.didReceiveDataPhaseAbort = false;
|
BuspalCompositeUsbDevice.hid_generic.hid_packet.didReceiveDataPhaseAbort = false;
|
||||||
lock_release();
|
lock_release();
|
||||||
return -1; // kStatus_AbortDataPhase;
|
return -1; // kStatus_AbortDataPhase;
|
||||||
}
|
}
|
||||||
lock_release();
|
lock_release();
|
||||||
|
|
||||||
// Construct report contents.
|
// Construct report contents.
|
||||||
g_device_composite.hid_generic.hid_packet.report.header.reportID = reportID;
|
BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header.reportID = reportID;
|
||||||
g_device_composite.hid_generic.hid_packet.report.header._padding = 0;
|
BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header._padding = 0;
|
||||||
g_device_composite.hid_generic.hid_packet.report.header.packetLengthLsb = byteCount & 0xff;
|
BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header.packetLengthLsb = byteCount & 0xff;
|
||||||
g_device_composite.hid_generic.hid_packet.report.header.packetLengthMsb = (byteCount >> 8) & 0xff;
|
BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header.packetLengthMsb = (byteCount >> 8) & 0xff;
|
||||||
if (packet && byteCount > 0)
|
if (packet && byteCount > 0)
|
||||||
{
|
{
|
||||||
memcpy(&g_device_composite.hid_generic.hid_packet.report.packet, packet, byteCount);
|
memcpy(&BuspalCompositeUsbDevice.hid_generic.hid_packet.report.packet, packet, byteCount);
|
||||||
}
|
}
|
||||||
if (g_device_composite.hid_generic.attach == 1)
|
if (BuspalCompositeUsbDevice.hid_generic.attach == 1)
|
||||||
{
|
{
|
||||||
// Send the maximum report size since that's what the host expects.
|
// Send the maximum report size since that's what the host expects.
|
||||||
// There may be extra trailing bytes.
|
// There may be extra trailing bytes.
|
||||||
USB_DeviceHidSend(g_device_composite.hid_generic.hid_handle, USB_HID_GENERIC_ENDPOINT_IN,
|
USB_DeviceHidSend(BuspalCompositeUsbDevice.hid_generic.hid_handle, USB_HID_GENERIC_ENDPOINT_IN,
|
||||||
(uint8_t *)&g_device_composite.hid_generic.hid_packet.report.header,
|
(uint8_t *)&BuspalCompositeUsbDevice.hid_generic.hid_packet.report.header,
|
||||||
sizeof(g_device_composite.hid_generic.hid_packet.report));
|
sizeof(BuspalCompositeUsbDevice.hid_generic.hid_packet.report));
|
||||||
sync_wait(&g_device_composite.hid_generic.hid_packet.sendSync, kSyncWaitForever);
|
sync_wait(&BuspalCompositeUsbDevice.hid_generic.hid_packet.sendSync, kSyncWaitForever);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return kStatus_Success;
|
return kStatus_Success;
|
||||||
@@ -399,13 +400,6 @@ static uint32_t usb_hid_packet_get_max_packet_size(const peripheral_descriptor_t
|
|||||||
return kMinPacketBufferSize;
|
return kMinPacketBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_BUSPAL
|
|
||||||
void USB0_IRQHandler(void)
|
|
||||||
{
|
|
||||||
USB_DeviceKhciIsrFunction(g_device_composite.device_handle);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint32_t get_bus_clock(void)
|
uint32_t get_bus_clock(void)
|
||||||
{
|
{
|
||||||
uint32_t busClockDivider = ((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV2_MASK) >> SIM_CLKDIV1_OUTDIV2_SHIFT) + 1;
|
uint32_t busClockDivider = ((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV2_MASK) >> SIM_CLKDIV1_OUTDIV2_SHIFT) + 1;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "fsl_i2c.h"
|
#include "fsl_i2c.h"
|
||||||
#include "bl_peripheral.h"
|
#include "bl_peripheral.h"
|
||||||
|
#include "composite.h"
|
||||||
|
|
||||||
typedef struct _i2c_user_config {
|
typedef struct _i2c_user_config {
|
||||||
uint8_t slaveAddress;
|
uint8_t slaveAddress;
|
||||||
@@ -22,5 +23,6 @@ status_t receive_i2c_data(uint8_t *dest, uint32_t readLength);
|
|||||||
status_t usb_hid_packet_init(const peripheral_descriptor_t *self);
|
status_t usb_hid_packet_init(const peripheral_descriptor_t *self);
|
||||||
status_t usb_hid_packet_read(const peripheral_descriptor_t *self, uint8_t **packet, uint32_t *packetLength, packet_type_t packetType);
|
status_t usb_hid_packet_read(const peripheral_descriptor_t *self, uint8_t **packet, uint32_t *packetLength, packet_type_t packetType);
|
||||||
status_t usb_hid_packet_write(const peripheral_descriptor_t *self, const uint8_t *packet, uint32_t byteCount,packet_type_t packetType);
|
status_t usb_hid_packet_write(const peripheral_descriptor_t *self, const uint8_t *packet, uint32_t byteCount,packet_type_t packetType);
|
||||||
|
extern usb_device_composite_struct_t BuspalCompositeUsbDevice;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -91,11 +91,16 @@ void UpdateUsbReports()
|
|||||||
IsUsbBasicKeyboardReportSent = false;
|
IsUsbBasicKeyboardReportSent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wormhole_t wormhole;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
InitPeripherials();
|
InitPeripherials();
|
||||||
InitClock();
|
InitClock();
|
||||||
if (false/* || Wormhole->magicNumber == WORMHOLE_MAGIC_NUMBER*/) {
|
Wormhole = &wormhole; // TODO: Remove this as soon as the wormhole stabilizes.
|
||||||
Wormhole->magicNumber = 0;
|
Wormhole->enumerationMode = EnumerationMode_NormalKeyboard;
|
||||||
|
// Wormhole->enumerationMode = EnumerationMode_BusPal;
|
||||||
|
if (/*Wormhole->magicNumber == WORMHOLE_MAGIC_NUMBER && */ Wormhole->enumerationMode == EnumerationMode_BusPal) {
|
||||||
|
//Wormhole->magicNumber = 0;
|
||||||
init_hardware();
|
init_hardware();
|
||||||
handleUsbBusPalCommand();
|
handleUsbBusPalCommand();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "usb_descriptors/usb_descriptor_hid.h"
|
#include "usb_descriptors/usb_descriptor_hid.h"
|
||||||
#include "usb_descriptors/usb_descriptor_strings.h"
|
#include "usb_descriptors/usb_descriptor_strings.h"
|
||||||
#include "bootloader_config.h"
|
#include "bootloader_config.h"
|
||||||
|
#include "bus_pal_hardware.h"
|
||||||
|
#include "wormhole.h"
|
||||||
|
|
||||||
static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param);
|
static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param);
|
||||||
usb_composite_device_t UsbCompositeDevice;
|
usb_composite_device_t UsbCompositeDevice;
|
||||||
@@ -97,12 +99,12 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event,
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ENABLE_BUSPAL
|
void USB0_IRQHandler(void)
|
||||||
void USB0_IRQHandler()
|
|
||||||
{
|
{
|
||||||
USB_DeviceKhciIsrFunction(UsbCompositeDevice.deviceHandle);
|
USB_DeviceKhciIsrFunction(Wormhole->enumerationMode == EnumerationMode_BusPal
|
||||||
|
? BuspalCompositeUsbDevice.device_handle
|
||||||
|
: UsbCompositeDevice.deviceHandle);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void InitUsb()
|
void InitUsb()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ wormhole_t *Wormhole NO_INIT_GCC;
|
|||||||
void* getSP(void)
|
void* getSP(void)
|
||||||
{
|
{
|
||||||
void *sp;
|
void *sp;
|
||||||
// __asm__ __volatile__ ("mov %0, sp" : "=r"(sp));
|
__asm__ __volatile__ ("mov %0, sp" : "=r"(sp));
|
||||||
__asm__ __volatile__ ("mrs %0, msp" : "=r"(sp));
|
// __asm__ __volatile__ ("mrs %0, msp" : "=r"(sp));
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__ ((__section__ (".init3"), __naked__)) move_sp(void) {
|
void __attribute__ ((__section__ (".init3"), __naked__)) move_sp(void) {
|
||||||
void* SP = getSP();
|
void* SP = getSP();
|
||||||
// SP -= sizeof(wormhole_t);
|
SP -= sizeof(wormhole_t);
|
||||||
Wormhole = (wormhole_t*)(SP + 1);
|
Wormhole = (wormhole_t*)(SP + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,13 @@
|
|||||||
|
|
||||||
// Typedefs:
|
// Typedefs:
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EnumerationMode_Bootloader,
|
||||||
|
EnumerationMode_NormalKeyboard,
|
||||||
|
EnumerationMode_CompatibleKeyboard,
|
||||||
|
EnumerationMode_BusPal,
|
||||||
|
} enumeration_mode_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t magicNumber;
|
uint64_t magicNumber;
|
||||||
uint8_t enumerationMode;
|
uint8_t enumerationMode;
|
||||||
|
|||||||
Reference in New Issue
Block a user