Arduino-GPIO: Yet Another Fast Digital Pin Library

The Arduino-GPIO library has been developed to allow high performance digital pin access. Most access functions are compiled to a single instruction and execute in 1-2 clock cycles. The library functions are more than 10 times faster than the Arduino digital pin functions. In some cases as much as 100 times faster. Additional support classes are available for Shift Register Input/Output, and Software Serial Output. These also demonstrate how the GPIO template class may be used to construct additional libraries (OWI, Software SPI and TWI).

This library supports boards based on SAM3X8E (Arduino Due), ATmega168, ATmega328P (Arduno Uno, Nano, Mini, Lilypad, etc), ATmega32U4 (Arduino Leonardo, Micro, Lilypad USB, etc), ATmega1280, ATmega2560 (Arduino Mega), ATtinyX4 and ATtinyX5 (Arduino Tiny).

The classical Blink example sketch looks like this when using the library.

#include "GPIO.h"

GPIO<BOARD::D13> led;

void setup()
{
  led.output();
}

void loop()
{
  led = HIGH;
  delay(1000);
  led = LOW;
  delay(1000);
}

Please see github for more details and the doxygen generated on-line documentation.

Cheers!

Interesting.

Do you have a documentation page that lists and explains the function calls for newbies who would not be able to make sense of the source code?

At the moment you have support for a limited range of Arduino boards. An explanation of that the numbers in Board.h mean would be useful for someone who wishes to add support for another board. I am assuming that, for (say) an Attiny1634 all that would be required would be extra stuff in the Board.h file?

By the way "boards.txt" is the name of an important file for defining the different Arduino boards for the IDE. IMHO your name "Board.h" is too similar and humans may get confused even if the compiler won't. What about changing it to ardGpioPins.h

Thanks for sharing.

...R

The documentation may be found on github and in the source code as Doxygen documentation tags. And by chance all the Arduino ATmega328p and ATmega32u4 based boards are now supported.

The documentation in the Board.h file explains how to construct the pin pointer value. This may be used to add any additional AVR based MCU. Please note that Arduino Mega boards (e.g. ATmega2560 based) are not currently supported as higher port i/o addresses cannot be accessed with a single instruction (i.e. not atomic). This is critical when writing a pin in the ports with higher i/o addresses. Support for this will be added.

Cheers!

kowalski:
The documentation in the Board.h file explains how to construct the pin pointer value.

Sorry, I missed that.

The documentation may be found on github and in the source code as Doxygen documentation tags. And by chance all the Arduino ATmega328p and ATmega32u4 based boards are now supported.

I had looked at your Github page and I had not (and still cannot) see it. Can you post a link?

...R

The documentation is generated from the source code with doxygen. I have added a doxygen configuration file to make that easier.

Cheers!

OK. I think I understand. I was trying to make the point that it would be a good idea (IMHO) to write a documentation file that does not need doxygen so that a newbie who does not know about doxygen can easily use the library.

People who know how to use doxygen probably also know how to do port manipulation without needing a library.

...R

So what is the best practice on documentation? Any good reference, link?

Clean source code that follows style guides and includes documentation tags is easiest to maintain in larger projects. Generating documentation also allows support with automatic generation of UML class diagrams, cross-references, etc. I will include a zip file of the generated HTML documentation on the next tagged release on github.

Cheers!

kowalski:
So what is the best practice on documentation? Any good reference, link?

I have been impressed by the documentation for the AccelStepper library and for the TMRh20 version of the RF24 library

Clean source code that follows style guides and includes documentation tags is easiest to maintain in larger projects. ...

To my mind that means that the developer considers himself more important than his customers - a not uncommon failing in the OpenSource community :slight_smile:

...R

Great examples of documentation generated from source code by doxygen. And that is what is available for the GPIO library.

To my mind open-source is about sharing and collaborating with peers. I do not see you as a customer but as a good peer that is willing to take the time to comment and discuss improvements.

Thanks!

Please find the initial documentation on-line

Yes. That is going in the right direction.

But I think a newbie would not be clear how this should be used

GPIO< PIN >::operator bool  ( )

does it mean that I should write GPIO5::operator_bool() to get the state of pin 5?

I don't think the same ambiguity exists in the AccelStepper documentation.

By the way, I know I am being a PITA. But to my mind good documentation represent 60% of the value of any library.

...R

Yet another good question. Actually you can find this type of operator definition for the Arduino core Serial class.

void setup()
{
  Serial.begin(9600);
  while (!Serial);
  ...
}

The syntax is a way of expressing that, in this case, the GPIO pin can be used as a boolean value in an expression.

GPIO<BOARD::D4> pin;

// set the pin to output mode
pin.input(); 

// some examples of waiting for the pin signal to go high
while (pin == LOW);  
while (pin != HIGH); 
while (!pin);

// checking pin state
if (pin == HIGH) ...
if (pin) ...

The GPIO class defines two operators; assignment (operator=) and boolean value (operator bool()). These correspond to the Arduino core digitalWrite() and digitalRead().

Cheers!

kowalski:
The syntax is a way of expressing that, in this case, the GPIO pin can be used as a boolean value in an expression.

I feel you are missing the point I have been trying to make.

You know stuff. Other experts know the same stuff. I don't know the stuff straight off but I reckon I know enough to figure it out.

But it will be double-Dutch to a newbie.

Documentation should be understandable without needing to look up a secondary explanation for the explanation.

...R

loved this example

truly elegant replacement for Serial.println

sadr0b0t:
loved this example
Arduino-GPIO/examples/SoftwareSerial/SoftwareSerial.ino at master · mikaelpatel/Arduino-GPIO · GitHub

truly elegant replacement for Serial.println

How is that relevant to this Thread?

...R

Robin2:
How is that relevant to this Thread?

...R

  1. This example comes from Arduino-GPIO project repository
  2. This thread is about Arduino-GPIO project

sadr0b0t:

  1. This example comes from Arduino-GPIO project repository

Apologies. I did not make the connection.

...R

Two new Arduino-GPIO based libraries are available; Arduino-OWI with support of 1-Wire device drivers and Arduino-TWI for I2C device drivers.

The libraries include example device drivers DS18B20 1-Wire Digital Thermometer and DS1307 I2C Real-Time Clock.

Please see on-line documentation and example sketches for the new libraries.

Cheers!

The latest update of the Arduino-GPIO library adds support for the ATtiny core. Example sketches will run on ATtinyX4 and ATtinyX5.

Cheers!

The latest release of the Arduino-GPIO library adds support for Arduino Mega. The library now supports all boards based on ATmega168, ATmega328P, ATmega32U4, ATmega1280, ATmega2560, ATtinyX4 and ATtinyX5.

Cheers!

The latest release of the Arduino-GPIO library adds support for Arduino Due (SAM3X8E).

Cheers!