Skip to content

Commit

Permalink
feat(kscan): Add config to control int trigger
Browse files Browse the repository at this point in the history
* Allow using either level or edge interrupts for matrix/direct
  kscan drivers.
petejohanson committed Dec 7, 2024
1 parent b26058b commit 4865e12
Showing 4 changed files with 44 additions and 10 deletions.
26 changes: 26 additions & 0 deletions app/module/drivers/kscan/Kconfig
Original file line number Diff line number Diff line change
@@ -70,8 +70,34 @@ config ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS
scenario, set this value to a positive value to configure the number of
ticks to wait after reading each column of keys.

choice ZMK_KSCAN_GPIO_MATRIX_INTERRUPT_TYPE
prompt "Matrix interrupt type for key press detection"

config ZMK_KSCAN_GPIO_MATRIX_INTERRUPT_TYPE_LEVEL
bool "Level active"

config ZMK_KSCAN_GPIO_MATRIX_INTERRUPT_TYPE_EDGE
bool "Edge to active"

endchoice

endif # ZMK_KSCAN_GPIO_MATRIX

if ZMK_KSCAN_GPIO_DIRECT

choice ZMK_KSCAN_GPIO_DIRECT_INTERRUPT_TYPE
prompt "Direct interrupt type for key press detection"

config ZMK_KSCAN_GPIO_DIRECT_INTERRUPT_TYPE_LEVEL
bool "Level active"

config ZMK_KSCAN_GPIO_DIRECT_INTERRUPT_TYPE_EDGE
bool "Edge to active"

endchoice

endif

if ZMK_KSCAN_GPIO_CHARLIEPLEX

config ZMK_KSCAN_CHARLIEPLEX_WAIT_BEFORE_INPUTS
4 changes: 3 additions & 1 deletion app/module/drivers/kscan/kscan_gpio_direct.c
Original file line number Diff line number Diff line change
@@ -98,7 +98,9 @@ static int kscan_direct_interrupt_configure(const struct device *dev, const gpio

#if USE_INTERRUPTS
static int kscan_direct_interrupt_enable(const struct device *dev) {
return kscan_direct_interrupt_configure(dev, GPIO_INT_LEVEL_ACTIVE);
return kscan_direct_interrupt_configure(
dev, COND_CODE_1(IS_ENABLED(CONFIG_ZMK_KSCAN_GPIO_DIRECT_INTERRUPT_TYPE_EDGE),
(GPIO_INT_EDGE_TO_ACTIVE), (GPIO_INT_LEVEL_ACTIVE)));
}
#endif

4 changes: 3 additions & 1 deletion app/module/drivers/kscan/kscan_gpio_matrix.c
Original file line number Diff line number Diff line change
@@ -151,7 +151,9 @@ static int kscan_matrix_interrupt_configure(const struct device *dev, const gpio

#if USE_INTERRUPTS
static int kscan_matrix_interrupt_enable(const struct device *dev) {
int err = kscan_matrix_interrupt_configure(dev, GPIO_INT_LEVEL_ACTIVE);
int err = kscan_matrix_interrupt_configure(
dev, COND_CODE_1(IS_ENABLED(CONFIG_ZMK_KSCAN_GPIO_MATRIX_INTERRUPT_TYPE_EDGE),
(GPIO_INT_EDGE_TO_ACTIVE), (GPIO_INT_LEVEL_ACTIVE)));
if (err) {
return err;
}
20 changes: 12 additions & 8 deletions docs/docs/config/kscan.md
Original file line number Diff line number Diff line change
@@ -61,9 +61,11 @@ Keyboard scan driver where each key has a dedicated GPIO.

Definition file: [zmk/app/module/drivers/kscan/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/module/drivers/kscan/Kconfig)

| Config | Type | Description | Default |
| --------------------------------- | ---- | ------------------------------------------------ | ------- |
| `CONFIG_ZMK_KSCAN_DIRECT_POLLING` | bool | Poll for key presses instead of using interrupts | n |
| Config | Type | Description | Default |
| --------------------------------------------------- | ---- | ------------------------------------------------ | ------- |
| `CONFIG_ZMK_KSCAN_DIRECT_POLLING` | bool | Poll for key presses instead of using interrupts | n |
| `CONFIG_ZMK_KSCAN_GPIO_DIRECT_INTERRUPT_TYPE_LEVEL` | bool | Use level active interrupts to detect presses | y |
| `CONFIG_ZMK_KSCAN_GPIO_DIRECT_INTERRUPT_TYPE_EDGE` | bool | Use edge to active interrupts to detect presses | n |

### Devicetree

@@ -121,11 +123,13 @@ Keyboard scan driver where keys are arranged on a matrix with one GPIO per row a

Definition file: [zmk/app/module/drivers/kscan/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/module/drivers/kscan/Kconfig)

| Config | Type | Description | Default |
| ---------------------------------------------- | ----------- | ------------------------------------------------------------------------- | ------- |
| `CONFIG_ZMK_KSCAN_MATRIX_POLLING` | bool | Poll for key presses instead of using interrupts | n |
| `CONFIG_ZMK_KSCAN_MATRIX_WAIT_BEFORE_INPUTS` | int (ticks) | How long to wait before reading input pins after setting output active | 0 |
| `CONFIG_ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS` | int (ticks) | How long to wait between each output to allow previous output to "settle" | 0 |
| Config | Type | Description | Default |
| --------------------------------------------------- | ----------- | ------------------------------------------------------------------------- | ------- |
| `CONFIG_ZMK_KSCAN_MATRIX_POLLING` | bool | Poll for key presses instead of using interrupts | n |
| `CONFIG_ZMK_KSCAN_MATRIX_WAIT_BEFORE_INPUTS` | int (ticks) | How long to wait before reading input pins after setting output active | 0 |
| `CONFIG_ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS` | int (ticks) | How long to wait between each output to allow previous output to "settle" | 0 |
| `CONFIG_ZMK_KSCAN_GPIO_MATRIX_INTERRUPT_TYPE_LEVEL` | bool | Use level active interrupts to detect presses | y |
| `CONFIG_ZMK_KSCAN_GPIO_MATRIX_INTERRUPT_TYPE_EDGE` | bool | Use edge to active interrupts to detect presses | n |

### Devicetree

0 comments on commit 4865e12

Please sign in to comment.