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

Get bootmagic working with shared sn32f24xb matrix #356

Closed
wants to merge 1 commit into from

Conversation

karliss
Copy link

@karliss karliss commented Oct 10, 2023

Description

Fix bootmagic lite when using sn32f24xb shared rgb/key matrix driver.

Bootmagic lite gets checked as early as possible -> after key matrix has been initialized but before other optional subystems like RGB are running. Even if bootmagic check happened after rgb is initialized the actual scanning code runs at it's own pace based on timer interrupts, which makes it's usage during early init somewhat problematic. As a result bootmagic_lite doesn't work probably for most sonix keyboards using shared matrix and the corresponding driver.

This PR adds single manual key only scan to ensure there is meaningful data when the default bootmagic implementation reads it.

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).

@github-actions github-actions bot added the core label Oct 10, 2023
@karliss
Copy link
Author

karliss commented Oct 10, 2023

Currently keeping as draft as I want to test it compiles with all the relevant sonix boards currently in sn32_develop.

@karliss karliss marked this pull request as ready for review October 11, 2023 19:33
@karliss
Copy link
Author

karliss commented Oct 11, 2023

Tested:

  • that it works in combination with Add PERIBOARD-428 support. #355 but with custom boot magic removed
  • compiles with all the keyboards in sn32_develop that have `"driver": "sn32f24xb", (while doing noticed unrelated issue in one of keychron configs, but that's for separate PR)

@@ -548,6 +548,26 @@ void sn32f24xb_set_color_all(uint8_t r, uint8_t g, uint8_t b) {
}
}

#if defined(SHARED_MATRIX) && defined(BOOTMAGIC_LITE)
void matrix_init_kb(void) {

Choose a reason for hiding this comment

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

using matrix_init_kb outside of a keyboard directory is non standard and probably bad practice. A more sane approach would be to hijack the bootmagic_lite declaration directly - this would probably be more reliable since bootmagic gets called before matrix functions. Code handling it might be a bit uglier however

Copy link
Author

@karliss karliss Oct 13, 2023

Choose a reason for hiding this comment

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

Ok, will try that approach. When making this I felt unsure what the agreed QMK convention for use of _kb, _custom methods are. Looking through the existing keyboard seems like many keyboards use matrix_init_kb as general purpose hardware initialization hook, not just initializing matrix. If that's a recommended usecase then it would indeed be wrong to use matrix_init_kb in the driver level.

I also tried using matrix_init_custom, but that didn't work because that's only called when CUSTOM_MATRIX is enabled. Currently sn32f24xb driver uses in my opinion somewhat hacky way of on hand being quite somewhat custom matrix, but instead of using CUSTOM_MATRIX=yes or lite, disabling parts of quantum/matrix.c with if !defined(SHARED_MATRIX) .

Maybe it would be cleaner if the SHARED sn32f24 matrix was handled same as other CUSTOM_MATRIX?

In longer term it might be worth reconsidering how matrix customization works. It doesn't feel like current architecture encourages reusable non standard key matrix. Maybe move it to similar driver pattern as other subystems?

Choose a reason for hiding this comment

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

Currently, the shared implementation does indeed hack into the matrix routines. This was done in order to ease up on maintenance ( doing it full CUSTOM_MATRIX requires a carbon copy of matrix.c with the current code - lite is not much better). Upstream QMK did not feel at ease exposing matrix.c functions for us too hook up to, or allowing a CUSTOM_MATRIX=shared option, so we went with the current approach and added scan availability flags to be able to control it transparently.

Going forward, we should probably introduce a new platform variant, sn32f240b_shared to house all relevant shared configs/flags and/or a keyboard/sonixqmk/sn32f240b ( getting called from all shared matrix keyboards). We also need to get the driver specific configs in data driven format.

Keep in mind that while all that is doable in a couple different ways, a least intrusive approach must be taken so that upstream merges are clean-ish/plug and play in order to be able to keep up regularly with latest upstream and not have to rebase from scratch. We opt to be an extension of QMK to the sn32 world, not to butcher it up.

Copy link

Thank you for your contribution!
This pull request has been automatically marked as stale because it has not had activity in the last 45 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, or re-open when it's ready.
For maintainers: Please label with bug, awaiting review, breaking_change, in progress, or on hold to prevent the issue from being re-flagged.

@github-actions github-actions bot added the stale label Nov 28, 2023
Copy link

Thank you for your contribution!
This pull request has been automatically closed because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, or re-open when it's ready.
// [stale-action-closed]

@github-actions github-actions bot closed this Dec 29, 2023
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.

2 participants