Skip to content

Commit 82dbe3c

Browse files
committed
refactor: Fixes for review feedback.
1 parent ecac94d commit 82dbe3c

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

app/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ if ZMK_KSCAN_SIDEBAND_BEHAVIORS
504504

505505
config ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY
506506
int "Keyboard scan sideband behaviors driver init priority"
507-
# The default kscan init priority is 90, so be sure we are lower.
507+
# The default kscan init priority is 90, so be sure we are initialized later.
508508
default 95
509509

510510
endif # ZMK_KSCAN_SIDEBAND_BEHAVIORS

app/src/kscan_sideband_behaviors.c

+11-14
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,41 @@ struct ksbb_data {
4141
// KSBBs to check when a kscan callback from the "wrapped" inner kscan fires.
4242
static const struct device *ksbbs[] = {DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)};
4343

44-
int find_ksbb_for_inner(const struct device *inner_dev, const struct device **ksbb_dev) {
44+
const struct device *find_ksbb_for_inner(const struct device *inner_dev) {
4545
for (int i = 0; i < ARRAY_SIZE(ksbbs); i++) {
4646
const struct device *ksbb = ksbbs[i];
4747
const struct ksbb_config *cfg = ksbb->config;
4848

4949
if (cfg->kscan == inner_dev) {
50-
*ksbb_dev = ksbb;
51-
return 0;
50+
return ksbb;
5251
}
5352
}
5453

55-
return -ENODEV;
54+
return NULL;
5655
}
5756

58-
int find_sideband_behavior(const struct device *dev, uint32_t row, uint32_t column,
59-
struct ksbb_entry **entry) {
57+
struct ksbb_entry *find_sideband_behavior(const struct device *dev, uint32_t row, uint32_t column) {
6058
const struct ksbb_config *cfg = dev->config;
6159

6260
for (int e = 0; e < cfg->entries_len; e++) {
6361
struct ksbb_entry *candidate = &cfg->entries[e];
6462

6563
if (candidate->row == row && candidate->column == column) {
66-
*entry = candidate;
67-
return 0;
64+
return candidate;
6865
}
6966
}
7067

71-
return -ENODEV;
68+
return NULL;
7269
}
7370

7471
void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column,
7572
bool pressed) {
76-
struct ksbb_entry *entry = NULL;
77-
const struct device *ksbb = NULL;
78-
79-
if (find_ksbb_for_inner(dev, &ksbb) >= 0) {
73+
const struct device *ksbb = find_ksbb_for_inner(dev);
74+
if (ksbb) {
8075
struct ksbb_data *data = ksbb->data;
81-
if (find_sideband_behavior(ksbb, row, column, &entry) >= 0) {
76+
77+
struct ksbb_entry *entry = find_sideband_behavior(ksbb, row, column);
78+
if (entry) {
8279
struct zmk_behavior_binding_event event = {.position = INT32_MAX,
8380
.timestamp = k_uptime_get()};
8481

0 commit comments

Comments
 (0)