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

refactor: address transport switch enumeration warning #1994

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

xudongzheng
Copy link
Contributor

When building without USB or Bluetooth, the compiler would emit a warning due to ZMK_TRANSPORT_USB or ZMK_TRANSPORT_BLE not being handled.

@xudongzheng xudongzheng requested a review from a team as a code owner November 9, 2023 15:46
case ZMK_TRANSPORT_USB: {
#if IS_ENABLED(CONFIG_ZMK_USB)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this cause this to fall through to the next label with this change? Maybe better to only define the given transport in the enum if that feature is enabled, instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

enum zmk_transport is written to settings, so conditionally defining values could cause the meaning of a saved value to change from one build to another. Sort of a theoretical problem when we only have two transports, and disabling one means you can't switch at all, but that could become a problem if we ever added another RF protocol as a transport for example.

I'd recommend changing these to something more like

case ZMK_TRANSPORT_USB:
#if IS_ENABLED(CONFIG_ZMK_USB)
    return ...
#else
    return -ENOTSUP;
#endif

to avoid the fallthrough.

Alternatively, you could add a default case, but then you wouldn't get a warning if a new transport is added and someone forgot to add handling for it somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call on the settings storage issue. I agree with the -ENOTSUP version you proposed.

@caksoylar caksoylar added core Core functionality/behavior of ZMK refactor labels Nov 23, 2023
@xudongzheng xudongzheng force-pushed the transport-switch-pr branch 4 times, most recently from bc16b1f to 82f76d4 Compare November 28, 2023 23:13
Copy link
Collaborator

@joelspadin joelspadin left a comment

Choose a reason for hiding this comment

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

Looks good to me, Some existing error messages could be improved a bit if you want though.

#endif /* IS_ENABLED(CONFIG_ZMK_BLE) */
}
}

LOG_ERR("Unsupported endpoint transport %d", current_instance.transport);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
LOG_ERR("Unsupported endpoint transport %d", current_instance.transport);
LOG_ERR("Unhandled endpoint transport %d", current_instance.transport);

Now that we only fall into this case if current_instance.transport isn't a valid enum value, or we add a new enum value and forget to add handling for it above, the error message could be improved a little.

#endif /* IS_ENABLED(CONFIG_ZMK_BLE) */
}
}

LOG_ERR("Unsupported endpoint transport %d", current_instance.transport);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

@petejohanson
Copy link
Contributor

Can you please rebase this so we can get it merged? Updated version LGTM.

@petejohanson petejohanson self-assigned this Feb 20, 2024
When building without USB or Bluetooth, the compiler emits a warning due to
ZMK_TRANSPORT_USB or ZMK_TRANSPORT_BLE not being handled.
@xudongzheng
Copy link
Contributor Author

Rebased as requested, and the mouse report should be handled as well.

@petejohanson petejohanson merged commit 104c73d into zmkfirmware:main Feb 20, 2024
45 checks passed
@xudongzheng xudongzheng deleted the transport-switch-pr branch February 20, 2024 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionality/behavior of ZMK refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants