diff --git a/bdk/soc/gpio.c b/bdk/soc/gpio.c index 7e98ef3..8575333 100644 --- a/bdk/soc/gpio.c +++ b/bdk/soc/gpio.c @@ -110,6 +110,26 @@ int gpio_read(u32 port, u32 pins) return (GPIO(port_offset) & pins) ? 1 : 0; } +void gpio_set_debounce(u32 port, u32 pins, u32 ms) +{ + const u32 db_ctrl_offset = GPIO_DB_CTRL_OFFSET(port); + const u32 db_cnt_offset = GPIO_DB_CNT_OFFSET(port); + + if (ms) + { + if (ms > 255) + ms = 255; + + // Debounce time affects all pins of the same port. + GPIO(db_cnt_offset) = ms; + GPIO(db_ctrl_offset) = (pins << 8) | pins; + } + else + GPIO(db_ctrl_offset) = (pins << 8) | 0; + + (void)GPIO(db_ctrl_offset); // Commit the write. +} + static void _gpio_interrupt_clear(u32 port, u32 pins) { const u32 port_offset = GPIO_INT_CLR_OFFSET(port); diff --git a/bdk/soc/gpio.h b/bdk/soc/gpio.h index 09c29cf..7f94de5 100644 --- a/bdk/soc/gpio.h +++ b/bdk/soc/gpio.h @@ -89,6 +89,7 @@ void gpio_direction_input(u32 port, u32 pins); void gpio_direction_output(u32 port, u32 pins, int high); void gpio_write(u32 port, u32 pins, int high); int gpio_read(u32 port, u32 pins); +void gpio_set_debounce(u32 port, u32 pins, u32 ms); int gpio_interrupt_status(u32 port, u32 pins); void gpio_interrupt_enable(u32 port, u32 pins, int enable); void gpio_interrupt_level(u32 port, u32 pins, int high, int edge, int delta);