From 8ae8349d20230ef45828fe4d67bf5d94c7825be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Sat, 15 Apr 2017 01:50:32 +0200 Subject: [PATCH] Wipe out s_dHidActivity because it doesn't make a fucking sense the way it works. Use is_usb_active() instead. --- right/src/buspal/bus_pal_hardware.c | 22 ++++------------------ right/src/buspal/bus_pal_hardware.h | 2 -- right/src/buspal/command.c | 7 ++----- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/right/src/buspal/bus_pal_hardware.c b/right/src/buspal/bus_pal_hardware.c index c3594ca..861888c 100644 --- a/right/src/buspal/bus_pal_hardware.c +++ b/right/src/buspal/bus_pal_hardware.c @@ -7,7 +7,7 @@ #include "i2c.h" #include "peripherals/test_led.h" -bool usb_hid_poll_for_activity(const peripheral_descriptor_t *self); +bool is_usb_active(); 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); @@ -17,8 +17,6 @@ static status_t usb_hid_packet_finalize(const peripheral_descriptor_t *self); static uint32_t usb_hid_packet_get_max_packet_size(const peripheral_descriptor_t *self); static void init_i2c(uint32_t instance); -static bool s_dHidActivity = false; - const peripheral_control_interface_t g_usbHidControlInterface = {.init = usb_device_full_init, .shutdown = usb_device_full_shutdown}; @@ -71,7 +69,7 @@ bool usb_clock_init(void) return true; } -bool usb_hid_poll_for_activity(const peripheral_descriptor_t *self) +bool is_usb_active() { return g_device_composite.attach && g_device_composite.hid_generic.hid_packet.didReceiveFirstReport; } @@ -229,18 +227,6 @@ void usb_device_full_shutdown(const peripheral_descriptor_t *self) } } -/*FUNCTION********************************************************************** - * - * Function Name : usb_msc_pump - * Description : This function is called repeatedly by the main application - * loop. We use it to run the state machine from non-interrupt context - * - *END**************************************************************************/ -void usb_msc_pump(const peripheral_descriptor_t *self) -{ - s_dHidActivity = true; -} - status_t usb_hid_packet_init(const peripheral_descriptor_t *self) { sync_init(&g_device_composite.hid_generic.hid_packet.receiveSync, false); @@ -277,7 +263,7 @@ status_t usb_hid_packet_read(const peripheral_descriptor_t *self, // debug_printf("usbhid: unsupported packet type %d\r\n", (int)packetType); return kStatus_Fail; }; - if (s_dHidActivity) + if (is_usb_active()) { // The first receive data request was initiated after enumeration. // After that we wait until we are ready to read data before @@ -339,7 +325,7 @@ status_t usb_hid_packet_write(const peripheral_descriptor_t *self, uint32_t byteCount, packet_type_t packetType) { - if (s_dHidActivity) + if (is_usb_active()) { if (byteCount > kMinPacketBufferSize) { diff --git a/right/src/buspal/bus_pal_hardware.h b/right/src/buspal/bus_pal_hardware.h index 3df5e45..fc536a8 100644 --- a/right/src/buspal/bus_pal_hardware.h +++ b/right/src/buspal/bus_pal_hardware.h @@ -19,10 +19,8 @@ void configure_i2c_address(uint8_t address); void configure_i2c_speed(uint32_t speedkhz); status_t send_i2c_data(uint8_t *src, uint32_t writeLength); status_t receive_i2c_data(uint8_t *dest, uint32_t readLength); -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_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); -extern void usb_msc_pump(const peripheral_descriptor_t *self); #endif diff --git a/right/src/buspal/command.c b/right/src/buspal/command.c index 29d9486..1264dd4 100644 --- a/right/src/buspal/command.c +++ b/right/src/buspal/command.c @@ -23,11 +23,8 @@ void handleUsbBusPalCommand() { g_commandData.state = kCommandState_CommandPhase; - while (1) - { - usb_msc_pump(g_peripherals); + while (1) { bootloader_command_pump(); - usb_msc_pump(g_peripherals); } } @@ -377,7 +374,7 @@ status_t bootloader_command_pump() status = usb_hid_packet_read(&g_peripherals[0], &g_commandData.packet, &g_commandData.packetLength, kPacketType_Command); -//if (g_commandData.packet[12] == 0x64) TEST_LED_OFF(); + if (status != kStatus_Success) { debug_printf("Error: readPacket returned status 0x%x\r\n", status);