6

I've been reading about the linux GPIO functions and tried to make a small example using the function gpio_is_valid, but the compile fails because it can't find linux/gpio.h.

#include <iostream>

#include <linux/gpio.h>

int main()
{
    const bool is17Valid = !!gpio_is_valid(17);
    if (is17Valid)
    {
        std::cout << "17 is valid!" << std::endl;
    }
    else
    {
        std::cout << "17 is *not* valid!" << std::endl;
    }

    return 0;
}

Is linux/gpio.h available on the Raspberry Pi? If not, are none of the functions described in the linux documentation available?

I'm using the original Debian "Squeeze" image.

Jacobm001
  • 11,797
  • 7
  • 45
  • 56
Mark Ingram
  • 859
  • 2
  • 11
  • 18

2 Answers2

1

Assuming you're compiling on the Pi itself, you'll probably need to install some development packages, as precompiled binaries don't need header files present to run (so they're not installed by default.)

I think in this case the name of the package you want is probably linux-headers, which will put gpio.h into /usr/include/linux/gpio.h. Because the file sits in /usr/include it means you don't need to specify this part of the path either in your code or to the compiler, so #include <linux/gpio.h> as you have there is enough, once you've installed the correct package.

Malvineous
  • 1,694
  • 11
  • 20
1

I don't think you need linux/gpio.h - as you stated in a comment, the RPi repo has a pretty redundant version of it.

The GPIO's are memory-mapped, which you can read about it in How does memory-mapped I/O addressing work?.

Alex Chamberlain
  • 15,120
  • 13
  • 63
  • 112