-
Notifications
You must be signed in to change notification settings - Fork 910
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
avr: adding pin change interrupt handling to atmega328p #3139
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.
Thanks, we need this! However, this PR is not ready for review: it contains tons of debug code. Can you please clean up the PR?
I created a ticket for this work too: #3145 |
9fb49cf
to
8b7c145
Compare
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.
This looks good, with some nits here and there that could improve the code a bit and make it more efficient. Thank you for your continued work on this PR!
src/machine/machine_atmega328p.go
Outdated
PCMSK_REG = avr.PCMSK0 | ||
PCIE = avr.PCICR_PCIE0 | ||
PIN0 = PD0 | ||
PCINT = 1 << (pin - PIN0) | ||
IRQ = avr.IRQ_PCINT0 |
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.
You could consider the following:
PCMSK_REG = avr.PCMSK0 | |
PCIE = avr.PCICR_PCIE0 | |
PIN0 = PD0 | |
PCINT = 1 << (pin - PIN0) | |
IRQ = avr.IRQ_PCINT0 | |
pinIndex := pin - PD0 | |
pinCallbacks[0][pinIndex] = callback | |
avr.PCMSK0.SetBits(1 << pinIndex) | |
avr.PCICR.SetBits(avr.PCICR_PCIE0) |
It's less abstract, but it's actually a bit shorter and perhaps more readable as well. Also, I think the compiler will be better able to optimize this code.
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.
Yeah, I was intentionally being abstract because... well... reasons.
However, it ended up not working out very well that way due to... other reasons.
This new way simplifies quite a bit so I'll have the MR updated soon.
...I also need to figure out why "make release" is now crashing my machine....
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.
So, I've make release
, at least to the point that it runs to completion by ripping out all of tinygo and golang and reinstalling them.
However, I now get
$ tinygo build -target=arduino
warning: no avr-gcc installation can be found on the system, cannot link standard libraries
warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
warning: no avr-gcc installation can be found on the system, cannot link standard libraries
warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
However, I have avr-gcc
$ avr-gcc
avr-gcc: fatal error: no input files
compilation terminated.
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.
Please see https://tinygo.org/getting-started/install/linux/#avr-eg-arduino-uno for the install requirements for AVR on Linux.
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.
Just one last thing
So @mrbell321 has this been tested on real hardware? |
I’m on macOS not Linux and I’ve been through the process a couple times.
Not the only one having the issue either. There’s a slack thread.
…On Thu, Sep 29, 2022 at 3:46 AM Ron Evans ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/machine/machine_atmega328p.go
<#3139 (comment)>:
> + PCMSK_REG = avr.PCMSK0
+ PCIE = avr.PCICR_PCIE0
+ PIN0 = PD0
+ PCINT = 1 << (pin - PIN0)
+ IRQ = avr.IRQ_PCINT0
Please see
https://tinygo.org/getting-started/install/linux/#avr-eg-arduino-uno for
the install requirements for AVR on Linux.
—
Reply to this email directly, view it on GitHub
<#3139 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAH52U5JQDUWPUVU5NHFUELWAVJOPANCNFSM6AAAAAAQHFEHMI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
The early version, yes, but there have been changes I cannot test yet due
to the above toolchain issues.
…On Thu, Sep 29, 2022 at 4:42 AM Ron Evans ***@***.***> wrote:
So @mrbell321 <https://github.com/mrbell321> has this been tested on real
hardware?
—
Reply to this email directly, view it on GitHub
<#3139 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAH52UYQXYYNG5NF5676IHTWAVQALANCNFSM6AAAAAAQHFEHMI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
switch { | ||
case pin >= PB0 && pin <= PB7: | ||
// PCMSK0 - PCINT0-7 | ||
pinIndex := pin - PD0 |
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.
pinIndex := pin - PD0 | |
pinIndex := pin - PB0 |
I've tried this change on a custom board with atmega328p chip. Interrupt fires. Can't use |
This can be closed now, @deadprogram ? |
@ysoldak yes. @mrbell321 thank you for pointing the way on the implementation. Now closing this PR. |
This is what I've come up with for AVR pin change interrupts.