--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.
Just to throw in a random opinion: I think something like this would be good to include, although I haven't thought about the technical details. If it does get added, though, it should probably be called something like attachPinChangeInterrupt() as opposed to something with "PCINT" or "int".
Why not share the libraries with us?
I looked through the available resources and came to the following conclusion:
The most advanced PCINT library on github might be powerfull but is very complicated. People who understand this code can rather code this stuff manually, from my point of view.
On Feb 23, 2015, at 10:00 AM, Nevada Smith <nico...@web.de> wrote:Well it would conflict the same as the normal Interrupts. If the user adds to long function calls inside the ISR or Serial print etc this will fail and maybe crash the program. But its just the same positive or negatives aspects a normal interrupt has (like on pin 2 or 3).
The speed also isnt a big deal since I measured 4uS to actually execute the correct sketch. I can imagine that the not so optimized Arduino functions for a single pin are ironically slower. If more pins are attached at the same time, and triggered very often this could conflict in missed ISRs. But thats a genral ISR problem the user should be aware and has nothing to do with the library. Only do short things inside the ISR.
It would break SoftSerial though. At least you cannot use both at the same time. I tried to integrat the Softserial with this library but since it has fixed function names this would need function pointers or some workaround. I could get it working in my first attempt and I had not the mood to continue with it (because noone even merges the perfect Softserial fix of blathijs on github, so I shouldnt care about SS compatibility before this happens and anyone shows interrest in merging this perfect PR).
The really only disadvantage is the fixed function naming. Then It is not that easy to create libraries which uses PCINT with a passed in pin. The user has to add the ISR in the .ino file (see my IRL remote on github with an old version of the pcint lib). The rest is just the same as normal pin interrupts. Just that we now can use all Arduino pins for that :)
On Feb 23, 2015, at 10:24 AM, Nevada Smith <nico...@web.de> wrote:Tom,
you cannot detect it I think. Maybe the Arduino built environment could if you have a look at the preprocessors makros for the include guard. The problem simply is that softserial Implements EVERY Pcint ISR routine. So then the sketch wont compile because they are implemented. That of course only happens if you try to use both at the same time. A simple documentation note should be fine. You cannot have everything at the same time. AltSoftSerial would still work I think (uses timers).
As you can see in the example you can use PinChangeEvent(pinNumber)just that the passed in pinNumber has to be text. If you look at the source, this is a makro which uses some makro tricks to create if statements with makros. So the input has to happen via a makro like
#define myPin 3
or just passing the pin directly PinChangeEvent(3)
What not work (also stated in the example) is use a
const int myPin = 3;
Since the makro cannot convert this (due to the fixed functions)
We COULD use function pointers to solve this though. I havent tried to integrate this library to the core, then it could make sense to use function pointers. Function pointers would enable using different function names, correct the problem described above and may be used easier with other libs and chaning the interrupts at runtime. But I am not sure if it is worth it. In the worst case it eats the number of available PCINT pins, 2 bytes per function pointer. In the best case it only compiled for the used port, this is 12, 12 and 16 bytes for the Uno ports.
What I'd like to see, and would make things a lot easier is to use the PCINT as library (like spi and Softserial). The problem with that is the linkage. Someone has do add something like library.properties where you can say compileAsDotA file. Because if you compile it as .a file it only uses the needed ISRs of the library and not all. (thats how I understood it, blathijs explained me that in the Arduino irc chat).
So: Would you like to see this as core file or as external library. As library we need a .a compiling option. (not a genrat fix since this could break other libs).
And would you like to use function pointers or not? Its relatively easy to add, it just takes more flash which I dont really want to spend since PCINT should be a simple and compact addition to the Arduino and not use up more ram. As the stysle of a library I could add a makro for fixed/ram functions maybe. Like deacticating ports manually right now. But that would take more work of course.
--
A couple of thoughts.One is that the current attachInterrupt() function uses (I believe) function pointers (and associated table). Has the overhead of that approach been a problem in practice? If not, it's not clear (at least to me) that we'd need pin change interrupt handling to be more optimized than regular interrupts. Consider also that the trend is towards microcontrollers with more memory and speed.A second suggestion if that if we really want a way to optimize away the function pointers / table, it might be simpler simply to have (optional) functions / events with names based on their pin numbers. That is, to handle a pin change event on pin 10, you'd simply implement pinChangeInterruptEvent10(). That seems much simpler than introducing the two parentheses notation I see in your current example:void PinChangeInterruptEvent(interruptBlink)(void)In general, Arduino tries hard to avoid introducing new syntax and it would be nice to avoid it in this case too.