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

Should SPI attachInterrupt() and detachInterrupt() be removed? #183

Open
carlosperate opened this issue Feb 24, 2023 · 1 comment
Open

Comments

@carlosperate
Copy link

It looks like these methos are only used in the AVR ports, and even then they indicate that they should not be used.

ArduinoCore-avr/libraries/SPI/src/SPI.h#L306-L310
ArduinoCore-megaavr/libraries/SPI/src/SPI.h#L183-L187

  // These undocumented functions should not be used.  SPI.transfer()
  // polls the hardware flag which is automatically cleared as the
  // AVR responds to SPI's interrupt
  inline static void attachInterrupt() { SPCR |= _BV(SPIE); }
  inline static void detachInterrupt() { SPCR &= ~_BV(SPIE); }

Other cores do nothing or even do not implement it:

When are these methods meant to be used by Arduino users or ArduinoCore developers?

@matthijskooijman
Copy link
Collaborator

From a quick glance at the AVR SPI library, the actual ISR is not implement anywhere, which I think means that calling attachInterrupt() will cause the system to lock up the next time an SPI interrupt is triggered (since the default ISR just has an infinite loop IIRC). Sounds like removing these would indeed make sense - the only case these methods could be "useful" is when a sketch also implements the ISR itself, but those are very specific and advanced sketches that can also just modify SPCR directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants