mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-05 16:32:34 +00:00
refactor(usb): Rename mock class files
- Rename "test_usb_mock_..." class files to "mock_..." - Fixed some codespell issues - Fixed comment spacing
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
idf_component_register(SRCS "test_usb_common.c" "test_usb_mock_msc.c" "test_usb_mock_hid.c"
|
||||
idf_component_register(SRCS "mock_hid.c"
|
||||
"mock_msc.c"
|
||||
"test_usb_common.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES usb unity)
|
||||
|
||||
@@ -9,33 +9,33 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "usb/usb_types_ch9.h"
|
||||
#include "test_usb_mock_hid.h"
|
||||
#include "mock_hid.h"
|
||||
|
||||
// ---------------------------------------------------- HID Mouse ------------------------------------------------------
|
||||
|
||||
const usb_ep_desc_t mock_hid_mouse_in_ep_desc = {
|
||||
.bLength = sizeof(usb_ep_desc_t),
|
||||
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
.bEndpointAddress = MOCK_HID_MOUSE_INTR_IN_EP_ADDR, //EP 1 IN
|
||||
.bEndpointAddress = MOCK_HID_MOUSE_INTR_IN_EP_ADDR, // EP 1 IN
|
||||
.bmAttributes = USB_BM_ATTRIBUTES_XFER_INT,
|
||||
.wMaxPacketSize = MOCK_HID_MOUSE_INTR_IN_MPS,
|
||||
.bInterval = 10, //Interval of 10ms
|
||||
.bInterval = 10, // Interval of 10ms
|
||||
};
|
||||
|
||||
void mock_hid_process_report(mock_hid_mouse_report_t *report, int iter)
|
||||
{
|
||||
static int x_pos = 0;
|
||||
static int y_pos = 0;
|
||||
//Update X position
|
||||
if (report->x_movement & 0x80) { //Positive movement
|
||||
// Update X position
|
||||
if (report->x_movement & 0x80) { // Positive movement
|
||||
x_pos += report->x_movement & 0x7F;
|
||||
} else { //Negative movement
|
||||
} else { // Negative movement
|
||||
x_pos -= report->x_movement & 0x7F;
|
||||
}
|
||||
//Update Y position
|
||||
if (report->y_movement & 0x80) { //Positive movement
|
||||
// Update Y position
|
||||
if (report->y_movement & 0x80) { // Positive movement
|
||||
y_pos += report->y_movement & 0x7F;
|
||||
} else { //Negative movement
|
||||
} else { // Negative movement
|
||||
y_pos -= report->y_movement & 0x7F;
|
||||
}
|
||||
printf("\rX:%d\tY:%d\tIter: %d\n", x_pos, y_pos, iter);
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "usb/usb_types_ch9.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
|
||||
// ---------------------------------------------------- MSC SCSI -------------------------------------------------------
|
||||
|
||||
@@ -41,7 +41,7 @@ static const usb_config_desc_t mock_msc_config_desc = {
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = 0x80,
|
||||
.bMaxPower = 0x70, //224mA
|
||||
.bMaxPower = 0x70, // 224mA
|
||||
};
|
||||
|
||||
static const usb_intf_desc_t mock_msc_intf_desc = {
|
||||
@@ -51,8 +51,8 @@ static const usb_intf_desc_t mock_msc_intf_desc = {
|
||||
.bAlternateSetting = MOCK_MSC_SCSI_INTF_ALT_SETTING,
|
||||
.bNumEndpoints = 2,
|
||||
.bInterfaceClass = USB_CLASS_MASS_STORAGE,
|
||||
.bInterfaceSubClass = 0x06, //SCSI
|
||||
.bInterfaceProtocol = 0x50, //Bulk only
|
||||
.bInterfaceSubClass = 0x06, // SCSI
|
||||
.bInterfaceProtocol = 0x50, // Bulk only
|
||||
.iInterface = 0,
|
||||
};
|
||||
|
||||
@@ -66,18 +66,18 @@ usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc;
|
||||
const usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc_fs = {
|
||||
.bLength = sizeof(usb_ep_desc_t),
|
||||
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
.bEndpointAddress = MOCK_MSC_SCSI_BULK_OUT_EP_ADDR, //EP 1 OUT
|
||||
.bEndpointAddress = MOCK_MSC_SCSI_BULK_OUT_EP_ADDR, // EP 1 OUT
|
||||
.bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK,
|
||||
.wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_FS, //MPS of 64 bytes
|
||||
.wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_FS, // MPS of 64 bytes
|
||||
.bInterval = 0,
|
||||
};
|
||||
|
||||
const usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc_hs = {
|
||||
.bLength = sizeof(usb_ep_desc_t),
|
||||
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
.bEndpointAddress = MOCK_MSC_SCSI_BULK_OUT_EP_ADDR, //EP 1 OUT
|
||||
.bEndpointAddress = MOCK_MSC_SCSI_BULK_OUT_EP_ADDR, // EP 1 OUT
|
||||
.bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK,
|
||||
.wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_HS, //MPS of 512 bytes
|
||||
.wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_HS, // MPS of 512 bytes
|
||||
.bInterval = 0,
|
||||
};
|
||||
|
||||
@@ -86,7 +86,7 @@ const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc_fs = {
|
||||
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
.bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR,
|
||||
.bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK,
|
||||
.wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_FS, //MPS of 64 bytes
|
||||
.wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_FS, // MPS of 64 bytes
|
||||
.bInterval = 0,
|
||||
};
|
||||
|
||||
@@ -95,20 +95,20 @@ const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc_hs = {
|
||||
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
.bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR,
|
||||
.bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK,
|
||||
.wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_HS, //MPS of 512 bytes
|
||||
.wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_HS, // MPS of 512 bytes
|
||||
.bInterval = 0,
|
||||
};
|
||||
|
||||
void mock_msc_scsi_init_cbw(mock_msc_bulk_cbw_t *cbw, bool is_read, int offset, int num_sectors, uint32_t tag)
|
||||
{
|
||||
cbw->dCBWSignature = 0x43425355; //Fixed value
|
||||
cbw->dCBWTag = tag; //Random value that is echoed back
|
||||
cbw->dCBWSignature = 0x43425355; // Fixed value
|
||||
cbw->dCBWTag = tag; // Random value that is echoed back
|
||||
cbw->dCBWDataTransferLength = num_sectors * MOCK_MSC_SCSI_SECTOR_SIZE;
|
||||
cbw->bmCBWFlags = (is_read) ? (1 << 7) : 0; //If this is a read, set the direction flag
|
||||
cbw->bmCBWFlags = (is_read) ? (1 << 7) : 0; // If this is a read, set the direction flag
|
||||
cbw->bCBWLUN = MOCK_MSC_SCSI_LUN;
|
||||
cbw->bCBWCBLength = 10; //The length of the SCSI command
|
||||
//Initialize SCSI CMD as READ10 or WRITE 10
|
||||
cbw->CBWCB.opcode = (is_read) ? 0x28 : 0x2A; //SCSI CMD READ10 or WRITE10
|
||||
cbw->bCBWCBLength = 10; // The length of the SCSI command
|
||||
// Initialize SCSI CMD as READ10 or WRITE 10
|
||||
cbw->CBWCB.opcode = (is_read) ? 0x28 : 0x2A; // SCSI CMD READ10 or WRITE10
|
||||
cbw->CBWCB.flags = 0;
|
||||
cbw->CBWCB.lba_3 = (offset >> 24);
|
||||
cbw->CBWCB.lba_2 = (offset >> 16);
|
||||
@@ -17,12 +17,12 @@ static usb_phy_handle_t phy_hdl = NULL;
|
||||
|
||||
void test_usb_init_phy(void)
|
||||
{
|
||||
//Initialize the internal USB PHY to connect to the USB OTG peripheral
|
||||
// Initialize the internal USB PHY to connect to the USB OTG peripheral
|
||||
usb_phy_config_t phy_config = {
|
||||
.controller = USB_PHY_CTRL_OTG,
|
||||
.target = USB_PHY_TARGET_INT,
|
||||
.otg_mode = USB_OTG_MODE_HOST,
|
||||
.otg_speed = USB_PHY_SPEED_UNDEFINED, //In Host mode, the speed is determined by the connected device
|
||||
.otg_speed = USB_PHY_SPEED_UNDEFINED, // In Host mode, the speed is determined by the connected device
|
||||
.ext_io_conf = NULL,
|
||||
.otg_io_conf = NULL,
|
||||
};
|
||||
@@ -31,7 +31,7 @@ void test_usb_init_phy(void)
|
||||
|
||||
void test_usb_deinit_phy(void)
|
||||
{
|
||||
//Deinitialize the internal USB PHY
|
||||
// Deinitialize the internal USB PHY
|
||||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_del_phy(phy_hdl), "Failed to delete PHY");
|
||||
phy_hdl = NULL;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ void test_usb_deinit_phy(void)
|
||||
void test_usb_set_phy_state(bool connected, TickType_t delay_ticks)
|
||||
{
|
||||
if (delay_ticks > 0) {
|
||||
//Delay of 0 ticks causes a yield. So skip if delay_ticks is 0.
|
||||
// Delay of 0 ticks causes a yield. So skip if delay_ticks is 0.
|
||||
vTaskDelay(delay_ticks);
|
||||
}
|
||||
ESP_ERROR_CHECK(usb_phy_action(phy_hdl, (connected) ? USB_PHY_ACTION_HOST_ALLOW_CONN : USB_PHY_ACTION_HOST_FORCE_DISCONN));
|
||||
|
||||
Reference in New Issue
Block a user