Skip to content
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

Merged
merged 3 commits into from Sep 15, 2017

Conversation

lebrush
Copy link
Member

@lebrush lebrush commented Sep 9, 2017

One commit fixes the interrupt set-up and the other supports one more flank and compacts the code.

@lebrush lebrush added Platform: AVR Platform: This PR/issue effects AVR-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels Sep 9, 2017
@lebrush lebrush added this to the Release 2017.10 milestone Sep 9, 2017
Copy link
Member

@smlng smlng left a 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.

@@ -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;
Copy link
Member

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 😄

Copy link
Member Author

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 */
Copy link
Member

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 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, will change 👍

@lebrush
Copy link
Member Author

lebrush commented Sep 11, 2017

@smlng comments addressed

/* INT pins start at PD2 instead of at PD0 */
pin_num -= 2;
#endif

EIMSK |= (1 << pin_num);
Copy link
Member

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?

Copy link
Member Author

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 👍

if (pin_num < 4) {
EICRA |= (1 << pin_num * 2);
}
if (flank > 3) {
Copy link
Member

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).

Copy link
Member Author

Choose a reason for hiding this comment

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

Guilty :-P. Will fix 👍

@lebrush
Copy link
Member Author

lebrush commented Sep 14, 2017

@smlng all comments addressed. Also added extra commit fixing filter for other Atmegas.

@smlng
Copy link
Member

smlng commented Sep 15, 2017

maybe squash?

@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 15, 2017
@lebrush
Copy link
Member Author

lebrush commented Sep 15, 2017

And go. The three commits tackle three different issues :-)

@lebrush lebrush merged commit c054e38 into RIOT-OS:master Sep 15, 2017
@lebrush lebrush deleted the fix/atmega-gpio-misc branch September 15, 2017 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: AVR Platform: This PR/issue effects AVR-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants