Skip to content

Commit

Permalink
[hal/gpio] rename vsf_hw_gpio_pin_interrupt_init to vsf_hw_gpio_pin_i…
Browse files Browse the repository at this point in the history
…nterrupt_enable
  • Loading branch information
versaloon committed Aug 29, 2023
1 parent db78996 commit fc19a57
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 28 deletions.
6 changes: 3 additions & 3 deletions example/template/demo/hal_demo/gpio_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ static vsf_err_t __gpio_demo_pin_interrupt_init(gpio_test_t *test, vsf_arch_prio
VSF_ASSERT(NULL != test);
vsf_gpio_t *gpio_ptr = test->in.gpio;

vsf_err_t err = vsf_gpio_pin_interrupt_init(gpio_ptr, arch_prio);
vsf_err_t err = vsf_gpio_pin_interrupt_enable(gpio_ptr, test->in.pin_mask, arch_prio);
if (test->verbose >= 2) {
vsf_trace_debug("vsf_gpio_pin_interrupt_init(&%s, vsf_arch_prio_%d) = %d/*vsf_err_t*/" VSF_TRACE_CFG_LINEEND,
test->in.name, hal_demo_arch_prio_to_num(arch_prio), err);
vsf_trace_debug("vsf_gpio_pin_interrupt_enable(&%s, %d, vsf_arch_prio_%d) = %d/*vsf_err_t*/" VSF_TRACE_CFG_LINEEND,
test->in.name, test->in.pin_mask, hal_demo_arch_prio_to_num(arch_prio), err);
}
return err;
}
Expand Down
36 changes: 25 additions & 11 deletions source/hal/driver/AIC/AIC8800/gpio/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ typedef struct vsf_hw_gpio_t {
#endif

GPIO_REG_T *GPIO;
uint32_t output_reg;
uint8_t is_pmic;
uint16_t gpio_pin_mask; // in pmic port, must set bit to 1 in MR register

AIC_IOMUX_TypeDef *IOMUX;
vsf_gpio_isr_t *isrs;

uint16_t output_reg;
uint8_t is_pmic;
IRQn_Type irqn;

vsf_gpio_isr_t *isrs;
uint16_t gpio_pin_mask; // in pmic port, must set bit to 1 in MR register
uint16_t gpio_pin_isr_mask;
} vsf_hw_gpio_t;

/*============================ IMPLEMENTATION ================================*/
Expand Down Expand Up @@ -191,19 +190,35 @@ vsf_gpio_capability_t vsf_hw_gpio_capability(vsf_hw_gpio_t *hw_gpio_ptr)
return gpio_capability;
}

vsf_err_t vsf_hw_gpio_pin_interrupt_init(vsf_hw_gpio_t *hw_gpio_ptr, vsf_arch_prio_t prio)
vsf_err_t vsf_hw_gpio_pin_interrupt_enable(vsf_hw_gpio_t *hw_gpio_ptr, vsf_gpio_pin_mask_t pin_mask, vsf_arch_prio_t prio)
{
VSF_HAL_ASSERT(NULL != hw_gpio_ptr);
uint16_t pin_mask_orig;
vsf_protect_t orig;

if (hw_gpio_ptr->is_pmic) {
return VSF_ERR_NOT_SUPPORT;
}

if (prio == vsf_arch_prio_invalid) {
NVIC_DisableIRQ(hw_gpio_ptr->irqn);
orig = __vsf_gpio_protect();
hw_gpio_ptr->gpio_pin_isr_mask &= ~pin_mask;
pin_mask_orig = hw_gpio_ptr->gpio_pin_isr_mask;
__vsf_gpio_unprotect(orig);

if (!pin_mask_orig) {
NVIC_DisableIRQ(hw_gpio_ptr->irqn);
}
} else {
NVIC_SetPriority(hw_gpio_ptr->irqn, prio);
NVIC_EnableIRQ(hw_gpio_ptr->irqn);
orig = __vsf_gpio_protect();
pin_mask_orig = hw_gpio_ptr->gpio_pin_isr_mask;
hw_gpio_ptr->gpio_pin_isr_mask |= pin_mask;
__vsf_gpio_unprotect(orig);

if (!pin_mask_orig) {
NVIC_SetPriority(hw_gpio_ptr->irqn, prio);
NVIC_EnableIRQ(hw_gpio_ptr->irqn);
}
}

return VSF_ERR_NONE;
Expand Down Expand Up @@ -323,7 +338,6 @@ void __vsf_hw_gpio_irq_handler(vsf_hw_gpio_t *hw_gpio_ptr)
.IOMUX = ((AIC_IOMUX_TypeDef *)VSF_HW_IO_PORT ## __COUNT ## _IOMUX_REG_BASE),\
.is_pmic = VSF_HW_IO_PORT ## __COUNT ## _IS_PMIC, \
.gpio_pin_mask = VSF_HW_IO_PORT ## __COUNT ## _GPIO_PIN_MASK, \
.output_reg = 0, \
.isrs = VSF_HW_IO_PORT ## __COUNT ## _IS_PMIC ? \
NULL : __vsf_hw_gpio ## __COUNT ## isr, \
__HAL_OP \
Expand Down
6 changes: 3 additions & 3 deletions source/hal/driver/common/gpio/gpio_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ vsf_gpio_capability_t vsf_gpio_capability(vsf_gpio_t *gpio_ptr)
}


vsf_err_t vsf_gpio_pin_interrupt_init(vsf_gpio_t *gpio_ptr, vsf_arch_prio_t prio)
vsf_err_t vsf_gpio_pin_interrupt_enable(vsf_gpio_t *gpio_ptr, vsf_gpio_pin_mask_t pin_mask, vsf_arch_prio_t prio)
{
VSF_HAL_ASSERT(gpio_ptr != NULL);
VSF_HAL_ASSERT(gpio_ptr->op != NULL);
VSF_HAL_ASSERT(gpio_ptr->op->pin_interrupt_init != NULL);
VSF_HAL_ASSERT(gpio_ptr->op->pin_interrupt_enable != NULL);

return gpio_ptr->op->pin_interrupt_init(gpio_ptr, prio);
return gpio_ptr->op->pin_interrupt_enable(gpio_ptr, pin_mask, prio);
}

vsf_err_t vsf_gpio_pin_interrupt_config(vsf_gpio_t *gpio_ptr, vsf_gpio_pin_irq_cfg_t *cfg)
Expand Down
20 changes: 12 additions & 8 deletions source/hal/driver/common/template/vsf_template_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ extern "C" {
__VSF_HAL_TEMPLATE_API(__prefix_name, void, gpio, toggle, VSF_MCONNECT(__prefix_name, _gpio_t) *gpio_ptr, vsf_gpio_pin_mask_t pin_mask) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, gpio, output_and_set, VSF_MCONNECT(__prefix_name, _gpio_t) *gpio_ptr, vsf_gpio_pin_mask_t pin_mask) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, gpio, output_and_clear, VSF_MCONNECT(__prefix_name, _gpio_t) *gpio_ptr, vsf_gpio_pin_mask_t pin_mask) \
__VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, gpio, pin_interrupt_init, VSF_MCONNECT(__prefix_name, _gpio_t) *gpio_ptr, vsf_arch_prio_t prio) \
__VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, gpio, pin_interrupt_enable, VSF_MCONNECT(__prefix_name, _gpio_t) *gpio_ptr, vsf_gpio_pin_mask_t pin_mask, vsf_arch_prio_t prio) \
__VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, gpio, pin_interrupt_config, VSF_MCONNECT(__prefix_name, _gpio_t) *gpio_ptr, vsf_gpio_pin_irq_cfg_t *cfg_ptr)

/*============================ TYPES =========================================*/
Expand Down Expand Up @@ -575,20 +575,24 @@ extern vsf_gpio_capability_t vsf_gpio_capability(vsf_gpio_t *gpio_ptr);

/**
\~english
@brief Configure one or more pins of the gpio instance
@brief Enable interrupt of a pin
@param[in] gpio_ptr: a pointer to structure @ref vsf_gpio_t
@param[in] cfg: a pointer to structure @ref vsf_gpio_pin_irq_cfg_t
@param[in] pin_mask: pin mask, each pin corresponds to one bit, 1 means the bit
@param[in] prio: priority of the interrupt or vsf_arch_prio_invalid for disable
@note For some devices, prio parameter maybe shared between pins on the gpio.
\~chinese
@brief 配置 gpio 实例的一个或者多个引脚
@brief 使能指定引脚的中断
@param[in] gpio_ptr: 结构体 vsf_gpio_t 的指针,参考 @ref vsf_gpio_t
@param[in] cfg: 结构体 vsf_gpio_pin_irq_cfg_t 的指针,参考 @ref vsf_gpio_pin_irq_cfg_t
@param[in] pin_mask: 引脚掩码,每一个引脚对应一个位,1表示该位需要使能,0表示该位不需要使能
@param[in] prio: 中断优先级,或者用 vsf_arch_prio_invalid 表示关闭中断
@note 对于一些芯片, 中断优先级可能是 gpio 上所有引脚公用的.
*/
extern vsf_err_t vsf_gpio_pin_interrupt_init(vsf_gpio_t *gpio_ptr, vsf_arch_prio_t prio);
extern vsf_err_t vsf_gpio_pin_interrupt_enable(vsf_gpio_t *gpio_ptr, vsf_gpio_pin_mask_t pin_mask, vsf_arch_prio_t prio);

/**
\~english
@brief Configure one or more pins of the gpio instance
@brief Configure interrupt of one or more pins of the gpio instance
@param[in] gpio_ptr: a pointer to structure @ref vsf_gpio_t
@param[in] cfg: a pointer to structure @ref vsf_gpio_pin_irq_cfg_t
Expand Down Expand Up @@ -618,7 +622,7 @@ extern vsf_err_t vsf_gpio_pin_interrupt_config(vsf_gpio_t *gpio_ptr, vsf_gpio_pi
# define vsf_gpio_output_and_set(__GPIO, ...) VSF_MCONNECT(VSF_GPIO_CFG_PREFIX, _gpio_output_and_set) ((__vsf_gpio_t *)__GPIO, ##__VA_ARGS__)
# define vsf_gpio_output_and_clear(__GPIO, ...) VSF_MCONNECT(VSF_GPIO_CFG_PREFIX, _gpio_output_and_clear) ((__vsf_gpio_t *)__GPIO, ##__VA_ARGS__)
# define vsf_gpio_toggle(__GPIO, ...) VSF_MCONNECT(VSF_GPIO_CFG_PREFIX, _gpio_toggle) ((__vsf_gpio_t *)__GPIO, ##__VA_ARGS__)
# define vsf_gpio_pin_interrupt_init(__GPIO, ...) VSF_MCONNECT(VSF_GPIO_CFG_PREFIX, _gpio_pin_interrupt_init) ((__vsf_gpio_t *)__GPIO, ##__VA_ARGS__)
# define vsf_gpio_pin_interrupt_enable(__GPIO, ...) VSF_MCONNECT(VSF_GPIO_CFG_PREFIX, _gpio_pin_interrupt_enable) ((__vsf_gpio_t *)__GPIO, ##__VA_ARGS__)
# define vsf_gpio_pin_interrupt_config(__GPIO, ...) VSF_MCONNECT(VSF_GPIO_CFG_PREFIX, _gpio_pin_interrupt_config) ((__vsf_gpio_t *)__GPIO, ##__VA_ARGS__)
#endif

Expand Down
2 changes: 1 addition & 1 deletion source/hal/driver/vsf/distbus/gpio/vsf_hal_distbus_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void vsf_hal_distbus_gpio_set_direction(vsf_hal_distbus_gpio_t *gpio, vsf_gpio_p
__vsf_gpio_unprotect(orig);
}

vsf_err_t vsf_hal_distbus_gpio_pin_interrupt_init(vsf_hal_distbus_gpio_t *gpio, vsf_arch_prio_t prio)
vsf_err_t vsf_hal_distbus_gpio_pin_interrupt_enable(vsf_hal_distbus_gpio_t *gpio, vsf_gpio_pin_mask_t pin_mask, vsf_arch_prio_t prio)
{
return VSF_ERR_NOT_SUPPORT;
}
Expand Down
4 changes: 2 additions & 2 deletions source/hal/utilities/remap/gpio/vsf_remapped_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ vsf_gpio_capability_t vsf_remapped_gpio_capability(vsf_remapped_gpio_t *gpio)
return vsf_gpio_capability(gpio->target);
}

vsf_err_t vsf_remapped_gpio_pin_interrupt_init(vsf_remapped_gpio_t *gpio, vsf_arch_prio_t prio)
vsf_err_t vsf_remapped_gpio_pin_interrupt_enable(vsf_remapped_gpio_t *gpio, vsf_gpio_pin_mask_t pin_mask, vsf_arch_prio_t prio)
{
VSF_HAL_ASSERT((gpio != NULL) && (gpio->target != NULL));
return vsf_gpio_pin_interrupt_init(gpio->target, prio);
return vsf_gpio_pin_interrupt_enable(gpio->target, pin_mask, prio);
}

vsf_err_t vsf_remapped_gpio_pin_interrupt_config(vsf_remapped_gpio_t *gpio, vsf_gpio_pin_irq_cfg_t *cfg_ptr)
Expand Down

0 comments on commit fc19a57

Please sign in to comment.