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

Host driver (wireless) rework, phase 1. #24365

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

tzarc
Copy link
Member

@tzarc tzarc commented Sep 5, 2024

Description

As per discussion on Discord. Draft raised for visibility, intent is to ensure we can swap around outputs dynamically.

Raw HID needs a new function added.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@tzarc tzarc requested a review from a team September 5, 2024 12:00
Comment on lines -76 to -81
#ifdef BLUETOOTH_ENABLE
if (where_to_send() == OUTPUT_BLUETOOTH) {
bluetooth_send_keyboard(report);
return;
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this change (and other similar changes in this file) removes all usages of where_to_send(), and effectively removes the existing support for the OUTPUT_AUTO mode. Where would this logic go after the rework?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OUTPUT_AUTO is indeterminate when you have a Bluetooth + 2.4GHz capable board. For that reason, it's been aliased to OUTPUT_NEXT which will cycle through the different connections instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you don't plan to support the current OUTPUT_AUTO behavior (when USB connection is detected, switch output to USB; when USB connection is dropped, switch back to BT), and would require some keypresses in this case to switch to the wired connection and back?

.init = NULL,
.connect = NULL,
.disconnect = NULL,
.is_connected = NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use usb_connected_state()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably -- I wouldn't read too much into the current implementation right now; it's raised as a draft for visibility and discussion purposes. Nowhere near ready for merge.

Comment on lines +61 to +64
if (driver && host_get_driver() != driver) {
host_set_driver(driver);
set_output(OUTPUT_BLUETOOTH);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably would need to be refactored to a helper function, and do a bit more:

  1. clear_keyboard(), so that keys are not left reported as held down when the output is off.
  2. Something needs to be done with the NKRO state (many older implementations don't support NKRO over wireless connections). Although the proper way to handle that may be to add a bool (*nkro_enabled)(void) function to the host driver interface, and change all non-USB code to use that function instead of the keyboard_protocol global variable (the variable itself would still be needed inside the USB driver, but may become static there). In that case we may not need to touch keymap_config.nkro in the output switching code (if the wireless connection does not support NKRO, it would look as if the host is using the boot keyboard protocol).

Also what would be the role of set_output() now — just something which triggers the set_output_user() hook? Or should we make set_output() actually switch the host driver, and have just a bunch of set_output() calls in this keycode processing function?

Comment on lines -76 to -81
#ifdef BLUETOOTH_ENABLE
if (where_to_send() == OUTPUT_BLUETOOTH) {
bluetooth_send_keyboard(report);
return;
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you don't plan to support the current OUTPUT_AUTO behavior (when USB connection is detected, switch output to USB; when USB connection is dropped, switch back to BT), and would require some keypresses in this case to switch to the wired connection and back?

.init = NULL,
.connect = NULL,
.disconnect = NULL,
.is_connected = NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My proposal is to move has_init_executed and is_connected flags and probably others not implemented yet into a state enum. Like it is already done for usb_device_state with callbacks for state changes. As the driver can hardly be connected without running init first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants