Arduino-GPIO icon indicating copy to clipboard operation
Arduino-GPIO copied to clipboard

Enhance GPIO to allow use in non-templated classes and variables

Open lintondf opened this issue 5 years ago • 5 comments

Defines a pure virtual base class IGPIO from which the hardware-specific GPIO classes are derived. This allows references to IGPIO objects to be passed to non-templated class constructors and methods and allows class and other variables to be IGPIO methods without the use of templates.

Since none of the methods of the GPIO classes modify any class attributes I added const declarations throughout.

Neither the size or speed of the native hardware-specific GPIO classes are affected.

I added new benchmark methods to demonstrate the performance of the wrapped objects.

lintondf avatar Jan 24 '20 11:01 lintondf

Please add benchmark when passing as parameter. This will give some insight to the current design pattern.

mikaelpatel avatar Jan 26 '20 00:01 mikaelpatel

Please explain changes ”const party”. What is the improvement? The class does not have state.

mikaelpatel avatar Jan 26 '20 00:01 mikaelpatel

My newly added IGPIO.h adds the pure virtual interface class IGPIO and the VGPIO class which subclasses the interface and your standard GPIO class.

I have committed additional changes. Please look at BenchmarkV.ino which replicates your Benchmark.ino but using the VGPIO class. Benchmark.ino does the same for IGPIO and illustrates using an IGPIO const reference to access a VGPIO object.

On Sat, Jan 25, 2020 at 7:09 PM Mikael Patel [email protected] wrote:

Please add benchmark when passing as parameter. This will give some insight to the current design pattern.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mikaelpatel/Arduino-GPIO/pull/14?email_source=notifications&email_token=ACBVP7MUUZNIAF3NUMA47JTQ7TID5A5CNFSM4KLE2S42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ5IREA#issuecomment-578455696, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBVP7IARPWFOJMHGZIK44LQ7TID5ANCNFSM4KLE2S4Q .

lintondf avatar Jan 26 '20 15:01 lintondf

Since your hardware-specific GPIO classes have no state, every member function was already 'const' in practice, adding the declaration simply recognizes the fact.

I ran your benchmark before and after and observed no impact. However, by adding these declarations we can pass const references to derived objects which the compiler can better optimize.

On Sat, Jan 25, 2020 at 7:24 PM Mikael Patel [email protected] wrote:

Please explain changes ”const party”. What is the improvement? The class does not have state.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mikaelpatel/Arduino-GPIO/pull/14?email_source=notifications&email_token=ACBVP7IBI2DJSRDAIPVKJKTQ7TJ4DA5CNFSM4KLE2S42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ5IXNQ#issuecomment-578456502, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBVP7OPBALE7V7MOQKHYNTQ7TJ4DANCNFSM4KLE2S4Q .

lintondf avatar Jan 26 '20 15:01 lintondf

There is a need for a benchmark that uses the VPIO by-reference. This will force the compiler to generate the virtual table and the virtual function call over-head will be more obvious.

mikaelpatel avatar Feb 07 '20 14:02 mikaelpatel