Skip to content

Conversation

@soburi
Copy link
Member

@soburi soburi commented Oct 2, 2022

The GPIO pin interruption depends on the EXTI.
Add "select" to clarify the dependency.

Signed-off-by: TOKITA Hiroshi tokita.hiroshi@gmail.com

Copy link
Member

@cfriedt cfriedt Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks as though clkid will be padded out to 32-bits if CONFIG_GD32_EXTI=n, so the #ifdef can be removed here. Then you can switch to using if (IS_ENABLED(CONFIG_GD32_EXTI) elsewhere and remove the #ifdef around static void gpio_gd32_isr(uint8_t line, void *arg)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks as though clkid will be padded out to 32-bits if CONFIG_GD32_EXTI=n, so the #ifdef can be removed here.

Insightful!
Removed the #ifdef.

Then you can switch to using if (IS_ENABLED(CONFIG_GD32_EXTI) elsewhere and remove the #ifdef around static void gpio_gd32_isr(uint8_t line, void *arg)

Commenting in follows topics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (IS_ENABLED(CONFIG_GD32_EXTI))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (IS_ENABLED(CONFIG_GD32_EXTI))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#ifdef can be removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This #ifdef suppressing unused-function warning.
It should be better not to remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be enabled by default?

Copy link
Member Author

@soburi soburi Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.
Interrupts handling needs the EXTI.
The callback function of the GPIO API will not work If this option is disabled.

This PR is intended mainly to clarify dependencies.
I would like to make as few changes as possible from the current behavior.

Copy link
Member

@cfriedt cfriedt Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's required, should be depends on. imply means that it is optional but should be the default. Alternatively, selects could be used..

Copy link
Member Author

@soburi soburi Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more change gpio_pin_interrupt_configure API returns -ENOTSUP if GD32_EXTI disabled.

It make allow to disable GD32_EXTI without API contradiction.

https://github.com/zephyrproject-rtos/zephyr/pull/50879/files#diff-606da3fe7a304f5544526be564097f77dc7db8e627c004fc62b8eed50e1b45dbR329-R331

@soburi soburi force-pushed the gd32_gpio_wo_exti branch from 7d7ad35 to 37a9f70 Compare October 2, 2022 23:06
@soburi soburi requested a review from cfriedt October 2, 2022 23:35
@soburi soburi force-pushed the gd32_gpio_wo_exti branch 2 times, most recently from fa22798 to 581b7cd Compare October 4, 2022 05:56
Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but should it be as below?

-#if (IS_ENABLED(CONFIG_GD32_EXTI))
+if (IS_ENABLED(CONFIG_GD32_EXTI)) {
...
-#endif
+}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a beautiful solution!

The if-else condition must determine at compile time.
I worry that the intention maybe not have been conveyed to the code reader, adding some comments.

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So before reviewing, why do we need this change? Why would a new GD platform need that?

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 if this is needed for #49886

@soburi
Copy link
Member Author

soburi commented Oct 6, 2022

@gmarull ,

-1 if this is needed for #49886

I found this problem in work about #49886, but This PR is not related to #49886 and is also not required by.

It is a problem that no dependency defines in Kconfig even though gd32_gpio.c depends on gd32_exti.c.

The simple way to solve this is to use select GD32_EXTI as @cfriedt says.
But making it able to compile without GD32_EXTI is the preferable way, I think, for the following reasons.

  • It does not violate API spec. (gpio_pin_interrupt_configure can return -ENOTSUP.)
  • It makes providing more options to users. (User can disable EXTI if no use GPIO callbacks.)
  • The default behavior has not changed. (imply make EXTI enable default.)

I agree there is no solid reason to merge this patch.
Because it is useful only in rare cases.
But I think it is good to fix it from the viewpoint of the integrity of dependency.

@soburi soburi force-pushed the gd32_gpio_wo_exti branch 2 times, most recently from 6e4af77 to 64c8ab8 Compare October 6, 2022 21:11
@nandojve
Copy link
Member

Hi @gmarull ,

Do you still with same position or @soburi justification is OK?
We need decide if we will keep it or not. I'm fine with justification since it is not about #49886.

@nandojve nandojve requested a review from gmarull October 24, 2022 16:15
Comment on lines 289 to 295
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, what should be done is the following:

  1. Add a Kconfig option to build the GD32 driver w/o interrupt support, e.g. CONFIG_GPIO_GD32_INT_ENABLE
  2. Such option should be enabled by default, and select GD32_EXTI (intc drivers do not have a class, so we need to select on a driver basis)
  3. Just ifdefout code if CONFIG_GPIO_GD32_INT_ENABLE=n. I've personally never liked IS_ENABLED because it can't be universally used without getting compile errors in some cases.

But still, I feel it is wrong to add such option at a driver level. It should likely be a subsystem setting to build GPIO drivers with/without interrupt support.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is as you say. I look at the implementation of other GPIO drivers, and none of them enable or disable .pin_interrupt_configure in the settings. So I would like to withdraw this idea.
However, I think that it is better to clarify the dependency on EXTI,
I have changed the fix (and PR title).
Could you please confirm this?

@soburi soburi force-pushed the gd32_gpio_wo_exti branch from 64c8ab8 to 0fcd49a Compare November 1, 2022 03:14
@soburi soburi changed the title drivers: gpio: gd32: Make possible to compile without EXTI drivers: gpio: gd32: add dependency on the EXTI Nov 1, 2022
@soburi soburi requested review from gmarull and nandojve November 1, 2022 03:17
The GPIO pin interruption depends on the EXTI.
Add "select" to clarify the dependency.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the gd32_gpio_wo_exti branch from 0fcd49a to f5da65a Compare November 1, 2022 04:59
bool "GD32 GPIO driver"
default y
depends on DT_HAS_GD_GD32_GPIO_ENABLED
select GD32_EXTI
Copy link
Contributor

@cameled cameled Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I confuse the NVIX and EXTI definition. NVIC provide SysTick, PendSV and other fault exception. EXTI provide periphral interrupt.

That's ok for me now.

@cameled
Copy link
Contributor

cameled commented Nov 7, 2022

Hi @nandojve, @gmarull, please help to confirm the new changes.

@cfriedt cfriedt merged commit c5c0a1a into zephyrproject-rtos:main Nov 9, 2022
@soburi soburi deleted the gd32_gpio_wo_exti branch November 17, 2022 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants