I have a Model B Revision 1.0 + ECN0001 that I am making a program in C to read and control a HCTL-2022 Quadrature Decoder using the GPIOs by way of sysfs. It's working great, but now I would like to provide the a clock using one of the GPIOs alt functions, specifically GPIO4 (GPCLK0).

Is it possible to configure the pin in this way using sysfs?

I see that I can use the mmap() SET_GPIO_ALT(g,a) Macro, but I recently moved away from this in favor of sysfs in hopes of making the code a little more portable, but perhaps that was a mistake.

  • Welcome to the Raspberry Pi flavour corner of Stack Exchange. "...making the code a little more portable..." well, this is just my opinion, BTW, but I'm not sure have making the code more portable needs to have too high a priority - after all, to what or where would it be ported? 8-) – SlySven Feb 2 '16 at 18:08
  • Thanks @SlySven, the reason I would like to make it a bit more portable is so that I could run on a PI or perhaps a BeagleBone or Arduino without too much added code. But it seems like my only option at this point is to special case based on hardware configuration. easy enough to do though. – hoss Feb 2 '16 at 18:54
  • Just keep the CLK control a modular black box that takes universally applicable parameters (hz, pulse width, etc.) and it will not be a big deal to write different versions of it for different platforms -- if you use one of the pi libs (pigpio, wiringpi, or libbcm2835) internally pretty much anything you could possibly do is doable in a dozen lines of code and I imagine the same goes anywhere else. – goldilocks Feb 2 '16 at 20:07

Is it possible to configure the pin in this way using sysfs?

No. There isn't much of a kernel driver for the pi's GPIO pins. I'm surprised someone hasn't gotten around to writing one, but there you go.

making the code a little more portable

Even if there were a kernel driver to implement the functionality, this isn't, as far as I know, something that is standardized or standardizable -- the point at which you begin setting various specialized functions for the pins is the point at which the pi-as-device becomes something somewhat unique.

  • 1
    Awesome thanks. the kernel docs say there is a TI Driver for a 'gpio-gate-clock', but I'm not sure how, if if these drivers work on the Pi. – hoss Feb 2 '16 at 18:57
  • 1
    TI as in Texas Instruments, an IC manufacturer... so that is probably a hardware device driver for something they make that can be included in a Linux device - there is no guarentee that it would be ported to the ARM hardware a Pi uses IMHO or even that the model used matches what the latter has. OTOH if someone was creating something for the hardware we are concerned about they may well use similar code structures from similar devices - as the GPL/Linux kernel lends itself to code reuse! 8-) – SlySven Feb 2 '16 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.