jdolinay / Arduino_DIO2

Fast digital I/O functions for Arduino
GNU Lesser General Public License v3.0
4 stars 1 forks source link

New version #1

Open Trusty77 opened 8 years ago

Trusty77 commented 8 years ago

Hello Jan,

I have built a new version of your library with my own improvements : more Arduino cards handeld, no needs for a file copy during installation, and one more function : GPIO_to_Arduino_pin to convert GPIO_pin_t to an integer for some extra usages...

DIO2.zip

What do you think about it ?

Thierry.

PS : This is the actual state of the work we had discussed about in CodeProject comments...

jdolinay commented 8 years ago

Hello Thierry, Thanks for sharing your work. I think there are 3 improvements which you suggest: 1) GPIO_to_Arduino_pin function - this is good.

2) Support for more boards: Nano, Leonardo, Due. Nano and Leonardo would be nice. I currently have only uno, mega, micro and mini (micro and mini not tested on a real board). If you could provide the nano and leonardo it would be nice (but it seems the "board" folder is not included in your DIO2.zip). As for Due, I am not sure if it is worth making the code more complicated with the #ifdef for _LIB_SAM if the DIO2 functions only "map" to the original functions. Is it some benefit for the library to support also the DUE even if it actually does nothing extra?

3) Automatic selection of the pin configuration for a board - the pins2_arduino.h This does not work according to my tests. Your code will select pins for Nano also for Uno (standard). The problem is your selection is based on the processor (microcontroller), but there can be more boards with the same processor, for eample the Nano and Uno both use Atmega328. If the arduino pins of such boards would be mapped in the same way (Nano pin 1 is also pin 1 on Uno, etc.) this would be ok. But I think this is not always true. Also you would have to use one file for both boards because there is no way to tell which board is selected just based on the processor.

To try your board selection I created this sketch: // Test board selection

if defined(AVR_ATmega2560)

//#include "../board/mega/pins2_arduino.h"

error "Mega selected."

else

if defined(AVR_ATmega328P)

//#include "../board/nano/pins2_arduino.h"

error "Nano selected."

else

if defined(AVR_ATmega32U4)

//#include "../board/leonardo/pins2_arduino.h"

error "Leonardo selected."

else

//#include "../board/standard/pins2_arduino.h"

error "Standard (uno) selected."

endif

endif

endif

void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: }

It will stop the compilation and print the selected board as an error. In Arduino IDE 1.6.8 I get Nano both for Nano and Uno.

Best regards, Jan

Trusty77 commented 8 years ago

Thanks for that fast answer !

1) ok. 2) You are right, I forgot the board folder... The new zip file is better ! The support for DUE is only for compatibility purpose. I deliver other libraries (for instance : http://git.framasoft.org/locoduino.org/Commanders) using DIO2, and if I want to make my own libraries compatibles with the Due, the best way is to make DIO2 also Due compilable ! There is no advantage to use it on this platform, but the sources are compatible. 3) The pins2_arduino.h files are the same for Nano and Uno. This is exactly the same thing for pins_arduino.h inside the IDE itself. The only difference is the number of analog pins, which is not relevant here... My mistake is perhaps to have created a 'Nano' folder which is not really necessary. But I wanted to let the user to understand that the library is compatible with the Nano R3... Probably a simple compatibility list in the readme could have been sufficient.

DIO2.zip

jdolinay commented 8 years ago

Thanks for explanation and the new file. As for 3) I wish the Arduino team provided some way to find out which board is used in the code. Since the pinouts are the same this really works, but I cannot say I like it. Probably for most Arduino users it is better to have this way of automatic file selection than copying the pins2 file. But for more experienced users it would be rather confusing to have different folders for uno and nano with the IDE actually using only one of them for both boards. If they wanted to add something specific to, say, Uno and added it in the "standard" folder, it would not be really used, because the IDE would use the file from "nano" folder (or vice versa depending on the code in the library which selects the file). The only "correct" solution would be to have one file for both boards but in which folder - standard or nano... this breaks the folder structure based on boards. Or perhaps the nano is considered something like "sub-variant" because it seems not to have its own pins file in the IDE itself - I did not find any "nano" folder in the variants.