Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong reportID usage #4

Open
wants to merge 5 commits into
base: feature/interface-selection
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Build XLAT firmware
on:
push:
branches:
- main
- '**'
pull_request:
branches:
- main
- '**'

jobs:
build:
Expand Down
6 changes: 3 additions & 3 deletions src/gfx_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ void gfx_set_byte_offsets_text(void)
uint8_t interface = xlat_get_found_interface();

if (button->found && x->found && y->found && XLAT_MODE_KEY != xlat_get_mode()) {
sprintf(text, "Mouse Data (#%d): click@%d motion@%d,%d", interface, button->byte_offset, x->byte_offset, y->byte_offset);
sprintf(text, "Mouse Data (#%d): id@%d click@%d motion@%d,%d", interface, xlat_get_reportid(), button->byte_offset, x->byte_offset, y->byte_offset);
} else if (key->found && XLAT_MODE_KEY == xlat_get_mode()) {
sprintf(text, "Keyboard Data (#%d): pressed@%d", interface, key->byte_offset);
sprintf(text, "Keyboard Data (#%d): id@%d pressed@%d", interface, xlat_get_reportid(), key->byte_offset);
} else {
// offsets not found
sprintf(text, "Data: offsets not found");
sprintf(text, (XLAT_MODE_KEY == xlat_get_mode()) ? "Keyboard Data: offsets not found" : "Mouse Data: offsets not found");
}

lv_checkbox_set_text(hid_offsets_label, text);
Expand Down
3 changes: 2 additions & 1 deletion src/usb/usb_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
break;
}

case HOST_USER_NO_SUPPORTED_CLASS:
case HOST_USER_CLASS_ACTIVE: {
// Compose vidpid string
uint16_t vid = phost->device.DevDesc.idVendor;
uint16_t pid = phost->device.DevDesc.idProduct;
printf("USB HID device connected: 0x%04X:%04X\n", vid, pid);
printf("USB device connected: 0x%04X:%04X\n", vid, pid);
memset(vidpid_string, 0, sizeof(vidpid_string));
snprintf(vidpid_string, sizeof(vidpid_string), "0x%04X:%04X", vid, pid);
vidpid_string[sizeof(vidpid_string) - 1] = '\0';
Expand Down
28 changes: 22 additions & 6 deletions src/usb/usbh_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "usbh_core.h"
#include "usbh_hid.h"
#include "usb_host.h"
#include "Common/Common.h"


/** @addtogroup USBH_LIB
Expand Down Expand Up @@ -480,6 +481,8 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
{
__IO USBH_StatusTypeDef status = USBH_FAIL;
uint8_t idx = 0U;
uint8_t i = 0U;
bool stop = false;

/* check for Host pending port disconnect event */
if (phost->device.is_disconnected == 1U)
Expand Down Expand Up @@ -706,12 +709,16 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
{
phost->pActiveClass = NULL;

for (idx = 0U; idx < USBH_MAX_NUM_SUPPORTED_CLASS; idx++)
for (idx = 0U, stop = false; idx < USBH_MAX_NUM_SUPPORTED_CLASS && !stop; idx++)
{
if (phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass)
// Check if the device has an interface where the class is supported
for (i = 0U; i < USBH_MAX_NUM_INTERFACES && !stop; i++)
{
phost->pActiveClass = phost->pClass[idx];
break;
if (phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[i].bInterfaceClass)
{
phost->pActiveClass = phost->pClass[idx];
stop = true;
}
}
}

Expand All @@ -722,8 +729,11 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
phost->gState = HOST_CLASS_REQUEST;
USBH_UsrLog("%s class started.", phost->pActiveClass->Name);

/* Inform user that a class has been activated */
phost->pUser(phost, HOST_USER_CLASS_SELECTED);
if (phost->pUser != NULL)
{
/* Inform user that a class has been activated */
phost->pUser(phost, HOST_USER_CLASS_SELECTED);
}
}
else
{
Expand All @@ -735,6 +745,12 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
{
phost->gState = HOST_ABORT_STATE;
USBH_UsrLog("No registered class for this device.");

if (phost->pUser != NULL)
{
/* Inform user that a class has been activated */
phost->pUser(phost, HOST_USER_NO_SUPPORTED_CLASS);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/usb/usbh_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern "C" {
#define HOST_USER_CONNECTION 0x04U
#define HOST_USER_DISCONNECTION 0x05U
#define HOST_USER_UNRECOVERED_ERROR 0x06U
#define HOST_USER_NO_SUPPORTED_CLASS 0x07U


/**
Expand Down
23 changes: 13 additions & 10 deletions src/usb/usbh_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost)
USBH_UsrLog("Mouse device found! (iface: %d)", interface);
HID_Handle->Init = USBH_HID_MouseInit;
} else {
USBH_UsrLog("bInterfaceProtocol %d not supported. Assuming Mouse... (iface: %d)",
phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol, interface);
HID_Handle->Init = USBH_HID_MouseInit;
USBH_UsrLog("bInterfaceProtocol %d not supported. Assuming %s... (iface: %d)",
phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol, (XLAT_MODE_KEY == xlat_get_mode()) ? "Keyboard" : "Mouse", interface);
HID_Handle->Init = (XLAT_MODE_KEY == xlat_get_mode()) ? USBH_HID_KeyboardInit : USBH_HID_MouseInit;
}

HID_Handle->state = USBH_HID_INIT;
Expand Down Expand Up @@ -272,8 +272,11 @@ static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost)
if (classReqStatus == USBH_OK) {
HID_Handle->ctl_state = USBH_HID_REQ_IDLE;

/* all requests performed*/
phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
if (phost->pUser != NULL)
{
/* all requests performed*/
phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
}
status = USBH_OK;
} else if (classReqStatus == USBH_NOT_SUPPORTED) {
USBH_ErrLog("Control error: HID: Device Set protocol request failed");
Expand Down Expand Up @@ -537,7 +540,7 @@ USBH_StatusTypeDef USBH_HID_SetIdle(USBH_HandleTypeDef *phost,
phost->Control.setup.b.bRequest = USB_HID_SET_IDLE;
phost->Control.setup.b.wValue.w = (uint16_t)(((uint32_t)duration << 8U) | (uint32_t)reportId);

phost->Control.setup.b.wIndex.w = 0U;
phost->Control.setup.b.wIndex.w = phost->device.current_interface;
phost->Control.setup.b.wLength.w = 0U;

return USBH_CtlReq(phost, NULL, 0U);
Expand Down Expand Up @@ -568,7 +571,7 @@ USBH_StatusTypeDef USBH_HID_SetReport(USBH_HandleTypeDef *phost,
phost->Control.setup.b.bRequest = USB_HID_SET_REPORT;
phost->Control.setup.b.wValue.w = (uint16_t)(((uint32_t)reportType << 8U) | (uint32_t)reportId);

phost->Control.setup.b.wIndex.w = 0U;
phost->Control.setup.b.wIndex.w = phost->device.current_interface;
phost->Control.setup.b.wLength.w = reportLen;

return USBH_CtlReq(phost, reportBuff, (uint16_t)reportLen);
Expand Down Expand Up @@ -599,7 +602,7 @@ USBH_StatusTypeDef USBH_HID_GetReport(USBH_HandleTypeDef *phost,
phost->Control.setup.b.bRequest = USB_HID_GET_REPORT;
phost->Control.setup.b.wValue.w = (uint16_t)(((uint32_t)reportType << 8U) | (uint32_t)reportId);

phost->Control.setup.b.wIndex.w = 0U;
phost->Control.setup.b.wIndex.w = phost->device.current_interface;
phost->Control.setup.b.wLength.w = reportLen;

return USBH_CtlReq(phost, reportBuff, (uint16_t)reportLen);
Expand All @@ -625,7 +628,7 @@ USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost,
phost->Control.setup.b.wValue.w = 1U;
}

phost->Control.setup.b.wIndex.w = 0U;
phost->Control.setup.b.wIndex.w = phost->device.current_interface;
phost->Control.setup.b.wLength.w = 0U;

return USBH_CtlReq(phost, NULL, 0U);
Expand Down Expand Up @@ -698,7 +701,7 @@ HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost)
} else if (InterfaceProtocol == HID_MOUSE_BOOT_CODE) {
type = HID_MOUSE;
} else {
type = HID_MOUSE; // fallback to mouse as well
type = HID_UNKNOWN;
}
}
return type;
Expand Down
Loading
Loading