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

Document syncing layer change callback across halves #23298

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Simpler way to sync layer update
  • Loading branch information
BlueDrink9 committed Mar 17, 2024
commit 9cac017483e9a1a1070ab23c8b60bf7b009da93d
38 changes: 12 additions & 26 deletions docs/feature_layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,39 +181,25 @@ Outside of `layer_state_set_*` functions, you can use the `IS_LAYER_ON(layer)` a

### Running on slave half as well as master (for split keyboards)

By default `layer_state_set_*` functions only run on master. A workaround for this is to use split custom communication to call the slave half.
By default `layer_state_set_*` functions only run on master. A workaround is to manually update it in housekeeping.

In `keymap.c`:

```c
#include "transactions.h"

void update_layer_state_set(uint8_t state, const void* unused, uint8_t unused2, void* unused3) {
layer_state_set_user(state);
static uint32_t last_layer_state = 0;

void update_layer_state_set(void){
if (!is_keyboard_master()) {
if (last_layer_state != layer_state) {
last_layer_state = layer_state;
layer_state_set_user(layer_state);
}
}
}

void keyboard_post_init_user(void) {
// Register callback to update layer LEDs on layer change.
transaction_register_rpc(SYNC_LAYER_CHANGE, update_layer_state_set);
void housekeeping_task_user(void) {
update_layer_state_set();
}

layer_state_t layer_state_set_user(layer_state_t state) {
/* Other config code
...
*/
if (is_keyboard_master()){
transaction_rpc_exec(SYNC_LAYER_CHANGE, state, NULL, 0, NULL);
}
return state;
```

In `config.h`:

```c
// Transaction ID for inter-half coms.
#define SPLIT_TRANSACTION_IDS_USER SYNC_LAYER_CHANGE

#define SPLIT_LAYER_STATE_ENABLE
```


Expand Down
Loading