diff --git a/app/module/drivers/kscan/Kconfig b/app/module/drivers/kscan/Kconfig index 88848dff939..21398c8e349 100644 --- a/app/module/drivers/kscan/Kconfig +++ b/app/module/drivers/kscan/Kconfig @@ -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 diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index 245e78b50cc..f83a2d240d2 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -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 diff --git a/app/module/drivers/kscan/kscan_gpio_matrix.c b/app/module/drivers/kscan/kscan_gpio_matrix.c index e0c76395f63..0495ba86a4a 100644 --- a/app/module/drivers/kscan/kscan_gpio_matrix.c +++ b/app/module/drivers/kscan/kscan_gpio_matrix.c @@ -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; } diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index 6e9aab02abe..6fa148a7ee1 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -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