Make BusPal relay command between USB and I2C.

This commit is contained in:
László Monda
2017-04-14 14:31:42 +02:00
parent a9b18355fc
commit fc202d8dde
5 changed files with 15 additions and 6 deletions

View File

@@ -5,11 +5,12 @@
#include "bootloader_config.h" #include "bootloader_config.h"
#include "microseconds/microseconds.h" #include "microseconds/microseconds.h"
#include "i2c.h" #include "i2c.h"
#include "peripherials/test_led.h"
bool usb_hid_poll_for_activity(const peripheral_descriptor_t *self); bool usb_hid_poll_for_activity(const peripheral_descriptor_t *self);
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);
static void usb_device_full_shutdown(const peripheral_descriptor_t *self); static void usb_device_full_shutdown(const peripheral_descriptor_t *self);
static void usb_msc_pump(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);
static void usb_hid_packet_abort_data_phase(const peripheral_descriptor_t *self); static void usb_hid_packet_abort_data_phase(const peripheral_descriptor_t *self);
static status_t usb_hid_packet_finalize(const peripheral_descriptor_t *self); static status_t usb_hid_packet_finalize(const peripheral_descriptor_t *self);
@@ -50,8 +51,6 @@ static i2c_user_config_t s_i2cUserConfig = {.slaveAddress = 0x10, //!< The slave
static i2c_master_handle_t s_i2cHandle; static i2c_master_handle_t s_i2cHandle;
uint32_t g_calculatedBaudRate;
bool usb_clock_init(void) bool usb_clock_init(void)
{ {
SIM->CLKDIV2 = (uint32_t)0x0UL; /* Update USB clock prescalers */ SIM->CLKDIV2 = (uint32_t)0x0UL; /* Update USB clock prescalers */
@@ -243,6 +242,7 @@ void usb_device_full_shutdown(const peripheral_descriptor_t *self)
void usb_msc_pump(const peripheral_descriptor_t *self) void usb_msc_pump(const peripheral_descriptor_t *self)
{ {
s_dHidActivity = true; s_dHidActivity = true;
TEST_LED_OFF();
} }
status_t usb_hid_packet_init(const peripheral_descriptor_t *self) status_t usb_hid_packet_init(const peripheral_descriptor_t *self)

View File

@@ -23,5 +23,6 @@ bool usb_hid_poll_for_activity(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);
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 void usb_msc_pump(const peripheral_descriptor_t *self);
#endif #endif

View File

@@ -1,6 +1,7 @@
#include "command.h" #include "command.h"
#include "crc16.h" #include "crc16.h"
#include "bus_pal_hardware.h" #include "bus_pal_hardware.h"
#include "peripherials/test_led.h"
command_processor_data_t g_commandData; command_processor_data_t g_commandData;
buspal_state_t g_buspalState = kBuspal_Idle; buspal_state_t g_buspalState = kBuspal_Idle;
@@ -25,12 +26,15 @@ void handleUsbBusPalCommand()
while (1) while (1)
{ {
usb_msc_pump(g_peripherals);
bootloader_command_pump(); bootloader_command_pump();
usb_msc_pump(g_peripherals);
} }
} }
static void handle_config_i2c(uint8_t *packet, uint32_t packetLength) static void handle_config_i2c(uint8_t *packet, uint32_t packetLength)
{ {
// TEST_LED_OFF();
configure_i2c_packet_t *command = (configure_i2c_packet_t *)packet; configure_i2c_packet_t *command = (configure_i2c_packet_t *)packet;
configure_i2c_address(command->address); configure_i2c_address(command->address);
configure_i2c_speed(command->speed); configure_i2c_speed(command->speed);
@@ -384,19 +388,19 @@ status_t bootloader_command_pump()
status = usb_hid_packet_read(&g_peripherals[0], &g_commandData.packet, &g_commandData.packetLength, status = usb_hid_packet_read(&g_peripherals[0], &g_commandData.packet, &g_commandData.packetLength,
kPacketType_Command); kPacketType_Command);
//if (g_commandData.packet[12] == 0x64) TEST_LED_OFF();
if (status != kStatus_Success) if (status != kStatus_Success)
{ {
debug_printf("Error: readPacket returned status 0x%x\r\n", status); debug_printf("Error: readPacket returned status 0x%x\r\n", status);
break; break;
} }
// TEST_LED_OFF();
if (g_commandData.packetLength == 0) if (g_commandData.packetLength == 0)
{ {
// No command packet is available. Return success. // No command packet is available. Return success.
break; break;
} }
cmdPacket = (command_packet_t *)g_commandData.packet; cmdPacket = (command_packet_t *)g_commandData.packet;
cmdTag = cmdPacket->commandTag; cmdTag = cmdPacket->commandTag;

View File

@@ -49,6 +49,8 @@ typedef struct CommandInterface {
// Default command interface. // Default command interface.
extern command_interface_t g_commandInterface; extern command_interface_t g_commandInterface;
void handleUsbBusPalCommand();
// Initialize the command processor component. // Initialize the command processor component.
status_t bootloader_command_init(void); status_t bootloader_command_init(void);

View File

@@ -11,6 +11,7 @@
#include "usb_interfaces/usb_interface_media_keyboard.h" #include "usb_interfaces/usb_interface_media_keyboard.h"
#include "bus_pal_hardware.h" #include "bus_pal_hardware.h"
#include "bootloader_config.h" #include "bootloader_config.h"
#include "command.h"
key_matrix_t KeyMatrix = { key_matrix_t KeyMatrix = {
.colNum = KEYBOARD_MATRIX_COLS_NUM, .colNum = KEYBOARD_MATRIX_COLS_NUM,
@@ -90,13 +91,13 @@ void main() {
InitClock(); InitClock();
#ifdef ENABLE_BUSPAL #ifdef ENABLE_BUSPAL
init_hardware(); init_hardware();
handleUsbBusPalCommand();
#else #else
LedDriver_InitAllLeds(1); LedDriver_InitAllLeds(1);
InitBridgeProtocolScheduler(); InitBridgeProtocolScheduler();
KeyMatrix_Init(&KeyMatrix); KeyMatrix_Init(&KeyMatrix);
UpdateUsbReports(); UpdateUsbReports();
InitUsb(); InitUsb();
#endif
// deserialize_Layer(testData, 0); // deserialize_Layer(testData, 0);
@@ -104,4 +105,5 @@ void main() {
UpdateUsbReports(); UpdateUsbReports();
asm("wfi"); asm("wfi");
} }
#endif
} }