-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
input: add some initial keyboard matrix library stubs
We currently have three keyboard scanning drivers in the code base (npcx, it8xxx2 and mchp_xec, last two yet to be converted to input). These have been largely copy pasted from each other and share a lot of the same structure and code. This PR lays a foundation to start decoupling feature from those drivers into a common code base, and it is heavily inspired by the current regulator common data/config one. Feature wise this only moves the thread struct, stack and initialization to the common code and declares the thread callback as the only API, but the intent is to move as much code as possible in there an only abstract device specific callbacks in the api structures. Signed-off-by: Fabio Baltieri <[email protected]>
- Loading branch information
1 parent
01aa800
commit 88b4ff3
Showing
9 changed files
with
142 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2023 Google LLC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config INPUT_KBD_MATRIX | ||
bool | ||
help | ||
Enable library used for keyboard matrix drivers. | ||
|
||
if INPUT_KBD_MATRIX | ||
|
||
config INPUT_KBD_THREAD_STACK_SIZE | ||
int "Stack size for the keyboard matrix thread" | ||
default 1024 | ||
help | ||
Size of the stack used for the keyboard matrix thread. | ||
|
||
endif # INPUT_KBD_MATRIX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/device.h> | ||
#include <zephyr/kernel.h> | ||
|
||
#include "input_kbd_matrix.h" | ||
|
||
int input_kbd_matrix_common_init(const struct device *dev) | ||
{ | ||
const struct input_kbd_matrix_common_config *cfg = dev->config; | ||
const struct input_kbd_matrix_api *api = &cfg->api; | ||
struct input_kbd_matrix_common_data *const data = dev->data; | ||
|
||
k_thread_create(&data->thread, data->thread_stack, | ||
CONFIG_INPUT_KBD_THREAD_STACK_SIZE, | ||
api->polling_thread, (void *)dev, NULL, NULL, | ||
K_PRIO_COOP(4), 0, K_NO_WAIT); | ||
|
||
k_thread_name_set(&data->thread, dev->name); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/device.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/toolchain.h> | ||
|
||
/** | ||
* @brief Keyboard matrix internal APIs. | ||
*/ | ||
struct input_kbd_matrix_api { | ||
k_thread_entry_t polling_thread; | ||
}; | ||
|
||
/** | ||
* @brief Common keyboard matrix config. | ||
* | ||
* This structure **must** be placed first in the driver's config structure. | ||
*/ | ||
struct input_kbd_matrix_common_config { | ||
struct input_kbd_matrix_api api; | ||
}; | ||
|
||
/** | ||
* @brief Initialize common keyboard matrix config from devicetree. | ||
* | ||
* @param api Pointer to a :c:struct:`input_kbd_matrix_api` structure. | ||
*/ | ||
#define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(node_id, _api) \ | ||
{ \ | ||
.api = _api, \ | ||
} | ||
|
||
/** | ||
* @brief Initialize common keyboard matrix config from devicetree instance. | ||
* | ||
* @param inst Instance. | ||
* @param api Pointer to a :c:struct:`input_kbd_matrix_api` structure. | ||
*/ | ||
#define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT(inst, api) \ | ||
INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst), api) | ||
|
||
/** | ||
* @brief Common keyboard matrix data. | ||
* | ||
* This structure **must** be placed first in the driver's data structure. | ||
*/ | ||
struct input_kbd_matrix_common_data { | ||
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_INPUT_KBD_THREAD_STACK_SIZE); | ||
struct k_thread thread; | ||
}; | ||
|
||
/** | ||
* @brief Validate the offset of the common data structures. | ||
* | ||
* @param config Name of the config structure. | ||
* @param data Name of the data structure. | ||
*/ | ||
#define INPUT_KBD_STRUCT_CHECK(config, data) \ | ||
BUILD_ASSERT(offsetof(config, common) == 0, \ | ||
"struct input_kbd_matrix_common_config must be placed first"); \ | ||
BUILD_ASSERT(offsetof(data, common) == 0, \ | ||
"struct input_kbd_matrix_common_data must be placed first") | ||
|
||
/** | ||
* @brief Common function to initialize a keyboard matrix device at init time. | ||
* | ||
* This function must be called at the end of the device init function. | ||
* | ||
* @param dev Keyboard matrix device instance. | ||
* | ||
* @retval 0 If initialized successfully. | ||
* @retval -errno Negative errno in case of failure. | ||
*/ | ||
int input_kbd_matrix_common_init(const struct device *dev); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright 2023 Google LLC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: Keyboard matrix device | ||
|
||
include: base.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters