New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GPIO interrupt fixes for atmega328p #7590
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me - some questions, though.
cpu/atmega_common/periph/gpio.c
Outdated
@@ -148,6 +148,10 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, | |||
/* clear global interrupt flag */ | |||
cli(); | |||
|
|||
#ifdef CPU_ATMEGA328P | |||
pin_num -= 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't question this, but could you please give a short reference/reasoning for this? Thx 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interrupt pins in atmega25.../12... are starting at 0 (e.g. PD0) but in atmega328 start at 2 (e.g. PC2). I'll add a comment :-) 👍
GPIO_LOW = 0, /**< emit interrupt when pin low */ | ||
GPIO_BOTH = 1, /**< emit interrupt on both flanks */ | ||
GPIO_FALLING = 2, /**< emit interrupt on falling flank */ | ||
GPIO_RISING = 3, /**< emit interrupt on rising flank */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit (and personal preference by me): either omit explicit definition of values or align them - looks nicer 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will change 👍
5a65ca3
to
f6b6434
Compare
@smlng comments addressed |
/* INT pins start at PD2 instead of at PD0 */ | ||
pin_num -= 2; | ||
#endif | ||
|
||
EIMSK |= (1 << pin_num); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I read the data sheet correctly there is only 0
and 1
allowed as pin_num for atmega328, maybe add an assert here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous assert already filters anything higher than 3 (line 138) maybe it's a good idea to add a check the lower bound as well. Will do 👍
cpu/atmega_common/periph/gpio.c
Outdated
if (pin_num < 4) { | ||
EICRA |= (1 << pin_num * 2); | ||
} | ||
if (flank > 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3
looks like a magic number here, should be GPIO_FLANK_RISING
or alternatively define GPIO_FLANK_MAX
and check (flank < GPIO_FLANK_MAX)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guilty :-P. Will fix 👍
f6b6434
to
1dd4b2e
Compare
1dd4b2e
to
6365466
Compare
@smlng all comments addressed. Also added extra commit fixing filter for other Atmegas. |
maybe squash? |
And go. The three commits tackle three different issues :-) |
One commit fixes the interrupt set-up and the other supports one more flank and compacts the code.