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

Interface Selection #2

Open
wants to merge 2 commits into
base: feature/keyboard-support
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(USB_Sources
src/usb/usbh_pipes.c
src/usb/usbh_hid.c
src/usb/usbh_hid_mouse.c
src/usb/usbh_hid_keyboard.c
)

add_definitions(
Expand Down
8 changes: 6 additions & 2 deletions src/gfx_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,13 @@ void gfx_set_byte_offsets_text(void)
hid_data_location_t * button = xlat_get_button_location();
hid_data_location_t * x = xlat_get_x_location();
hid_data_location_t * y = xlat_get_y_location();
hid_data_location_t * key = xlat_get_key_location();
uint8_t interface = xlat_get_found_interface();

if (button->found && x->found && y->found) {
sprintf(text, "Data: click@%d motion@%d,%d", button->byte_offset, x->byte_offset, y->byte_offset);
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);
} else if (key->found && XLAT_MODE_KEY == xlat_get_mode()) {
sprintf(text, "Keyboard Data (#%d): pressed@%d", interface, key->byte_offset);
} else {
// offsets not found
sprintf(text, "Data: offsets not found");
Expand Down
72 changes: 61 additions & 11 deletions src/gfx_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ lv_dropdown_t *edge_dropdown;
lv_slider_t *debounce_dropdown;
lv_dropdown_t *trigger_dropdown;
lv_dropdown_t *detection_dropdown;
lv_dropdown_t *interface_dropdown;
lv_obj_t *prev_screen = NULL; // Pointer to store previous screen

LV_IMG_DECLARE(xlat_logo);
Expand Down Expand Up @@ -92,12 +93,36 @@ static void event_handler(lv_event_t* e)
else if (obj == (lv_obj_t *)detection_dropdown) {
// Detection mode changed
uint16_t sel = lv_dropdown_get_selected(obj);
if (sel == 0) {
// Click
xlat_set_mode(XLAT_MODE_CLICK);
} else {
// Motion
xlat_set_mode(XLAT_MODE_MOTION);

switch (sel) {
// Motion [M]
case 1:
xlat_set_mode(XLAT_MODE_MOTION);
break;

// Key [K]
case 2:
xlat_set_mode(XLAT_MODE_KEY);
break;

// Click [M]
default:
xlat_set_mode(XLAT_MODE_CLICK);
}
}
else if (obj == (lv_obj_t *)interface_dropdown) {
// Interface number changed
uint16_t sel = lv_dropdown_get_selected(obj);

switch (sel) {
// Auto
case 0:
xlat_set_interface_selection(XLAT_INTERFACE_AUTO);
break;

// Any specific interface number
default:
xlat_set_interface_selection(XLAT_INTERFACE_0 + sel - 1);
}
}
else {
Expand Down Expand Up @@ -146,16 +171,26 @@ void gfx_settings_create_page(lv_obj_t *previous_screen)
lv_obj_add_event_cb((struct _lv_obj_t *) trigger_dropdown, event_handler, LV_EVENT_VALUE_CHANGED, NULL);


// Click vs. motion detection label
// Click, motion & key detection label
lv_obj_t *detection_mode = lv_label_create(settings_screen);
lv_label_set_text(detection_mode, "Detection Mode:");
lv_obj_align_to(detection_mode, trigger_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 30);

// Click vs. motion detection dropdown
// Click, motion & key detection dropdown
detection_dropdown = (lv_dropdown_t *) lv_dropdown_create(settings_screen);
lv_dropdown_set_options((lv_obj_t *) detection_dropdown, "Click\nMotion");
lv_dropdown_set_options((lv_obj_t *) detection_dropdown, "Click [M]\nMotion [M]\nKey [K]");
lv_obj_add_event_cb((struct _lv_obj_t *) detection_dropdown, event_handler, LV_EVENT_VALUE_CHANGED, NULL);

// Interface selection label
lv_obj_t *interface_label = lv_label_create(settings_screen);
lv_label_set_text(interface_label, "Interface Number:");
lv_obj_align_to(interface_label, detection_mode, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 30);

// Interface selection dropdown
interface_dropdown = (lv_dropdown_t *) lv_dropdown_create(settings_screen);
lv_dropdown_set_options((lv_obj_t *) interface_dropdown, "AUTO\n0\n1\n2\n3\n4\n5\n6\n7\n8");
lv_obj_add_event_cb((struct _lv_obj_t *) interface_dropdown, event_handler, LV_EVENT_VALUE_CHANGED, NULL);

// If we don't add this label, the y-value of the last item will be 0
lv_obj_t *debounce_label2 = lv_label_create(settings_screen);
lv_label_set_text(debounce_label2, "");
Expand All @@ -173,6 +208,7 @@ void gfx_settings_create_page(lv_obj_t *previous_screen)
lv_obj_align((struct _lv_obj_t *) debounce_dropdown, LV_ALIGN_DEFAULT, max_width + widget_gap, lv_obj_get_y(debounce_label) - 10);
lv_obj_align((struct _lv_obj_t *) trigger_dropdown, LV_ALIGN_DEFAULT, max_width + widget_gap, lv_obj_get_y(trigger_label) - 10);
lv_obj_align((struct _lv_obj_t *) detection_dropdown, LV_ALIGN_DEFAULT, max_width + widget_gap, lv_obj_get_y(detection_mode) - 10);
lv_obj_align((struct _lv_obj_t *) interface_dropdown, LV_ALIGN_DEFAULT, max_width + widget_gap, lv_obj_get_y(interface_label) - 10);

// Print all y-values for debugging
//printf("edge_label y: %d\n", lv_obj_get_y(edge_label));
Expand Down Expand Up @@ -222,7 +258,7 @@ void gfx_settings_create_page(lv_obj_t *previous_screen)
lv_dropdown_set_selected((lv_obj_t *) debounce_dropdown, debounce_index);

// Display current detection mode
lv_dropdown_set_selected((lv_obj_t *) detection_dropdown, xlat_get_mode() == XLAT_MODE_MOTION);
lv_dropdown_set_selected((lv_obj_t *) detection_dropdown, xlat_get_mode());


// Display current detection edge
Expand All @@ -231,5 +267,19 @@ void gfx_settings_create_page(lv_obj_t *previous_screen)
// Display current auto-trigger level
lv_dropdown_set_selected((lv_obj_t *) trigger_dropdown, xlat_auto_trigger_level_is_high());

}

// Display current interface selection
uint16_t interface_index = 0;
xlat_interface_t interface_selection = xlat_get_interface_selection();

switch (interface_selection) {
case XLAT_INTERFACE_AUTO:
interface_index = 0;
break;

default:
interface_index = 1 + interface_selection - XLAT_INTERFACE_0;
}

lv_dropdown_set_selected((lv_obj_t *) interface_dropdown, interface_index);
}
22 changes: 17 additions & 5 deletions src/usb/usbh_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "usbh_hid_parser.h"
#include "xlat.h"
#include "usbh_hid_mouse.h"
#include "usbh_hid_keyboard.h"


static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost);
Expand Down Expand Up @@ -65,12 +66,20 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost)
uint8_t num = 0U;
uint8_t interface;

// First try to find a Mouse interface, specifically:
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, HID_MOUSE_BOOT_CODE);
// Handle the AUTO interface detection mode
if (XLAT_INTERFACE_AUTO == xlat_get_interface_selection()) {
// First try to find a Mouse or Keyboard interface depending on the detection mode, specifically:
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, (XLAT_MODE_KEY == xlat_get_mode()) ? HID_KEYBRD_BOOT_CODE : HID_MOUSE_BOOT_CODE);

// Broaden the search criteria to no specific protocol
if (interface == 0xFFU) {
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFFU);
// Broaden the search criteria to no specific protocol
if (interface == 0xFFU) {
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFFU);
}
}
// Use the selected interface
else
{
interface = xlat_get_interface_selection() - XLAT_INTERFACE_0;;
}

#if 0
Expand All @@ -97,6 +106,8 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost)
return USBH_FAIL;
}

xlat_set_found_interface(interface);

phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc(sizeof(HID_HandleTypeDef));
HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;

Expand All @@ -113,6 +124,7 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost)
/*Decode Bootclass Protocol: Mouse or Keyboard, see HID_KEYBRD_BOOT_CODE, HID_MOUSE_BOOT_CODE */
if (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE) {
USBH_UsrLog("KeyBoard device found! (iface: %d)", interface);
HID_Handle->Init = USBH_HID_KeyboardInit;
} else if (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE) {
USBH_UsrLog("Mouse device found! (iface: %d)", interface);
HID_Handle->Init = USBH_HID_MouseInit;
Expand Down
Loading
Loading