drivers: interrupt_controller: initial support for GD32 EXTI

Add initial support for the GigaDevice External Interrupt Controller.
This driver is required to manage GPIO interrupts. Only EXTI lines 0 to
15 are supported for now (no LVD, RTC, etc.). Driver can be extended in
the future to add support for extra EXTI lines.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
Gerard Marull-Paretas 2021-12-07 18:59:00 +01:00 committed by Anas Nashif
commit 996a708abd
5 changed files with 277 additions and 0 deletions

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2021 Teslabs Engineering S.L.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_INTERRUPT_CONTROLLER_GD32_EXTI_H_
#define ZEPHYR_INCLUDE_DRIVERS_INTERRUPT_CONTROLLER_GD32_EXTI_H_
#include <stdint.h>
#include <sys/util_macro.h>
/**
* @name EXTI trigger modes.
* @anchor GD32_EXTI_TRIG
* @{
*/
/** No trigger */
#define GD32_EXTI_TRIG_NONE 0U
/** Trigger on rising edge */
#define GD32_EXTI_TRIG_RISING BIT(0)
/** Trigger on falling endge */
#define GD32_EXTI_TRIG_FALLING BIT(1)
/** Trigger on rising and falling edge */
#define GD32_EXTI_TRIG_BOTH (GD32_EXTI_TRIG_RISING | GD32_EXTI_TRIG_FALLING)
/** @} */
/** Callback for EXTI interrupt. */
typedef void (*gd32_exti_cb_t)(uint8_t line, void *user);
/**
* @brief Enable EXTI interrupt for the given line.
*
* @param line EXTI line.
*/
void gd32_exti_enable(uint8_t line);
/**
* @brief Disable EXTI interrupt for the given line.
*
* @param line EXTI line.
*/
void gd32_exti_disable(uint8_t line);
/**
* @brief Configure EXTI interrupt trigger mode for the given line.
*
* @param line EXTI line.
* @param trigger Trigger mode (see @ref GD32_EXTI_TRIG).
*/
void gd32_exti_trigger(uint8_t line, uint8_t trigger);
/**
* @brief Configure EXTI interrupt callback.
*
* @param line EXTI line.
* @param cb Callback (NULL to disable).
* @param user User data (optional).
*
* @retval 0 On success.
* @retval -EALREADY If callback is already set and @p cb is not NULL.
*/
int gd32_exti_configure(uint8_t line, gd32_exti_cb_t cb, void *user);
#endif /* ZEPHYR_INCLUDE_DRIVERS_INTERRUPT_CONTROLLER_GD32_EXTI_H_ */