Sponsored Content
Full Discussion: GPIO and sysfs
Top Forums UNIX for Advanced & Expert Users GPIO and sysfs Post 303030530 by Circuits on Tuesday 12th of February 2019 11:37:23 AM
Old 02-12-2019
GPIO and sysfs

I was recently working on a project where some gpio pins were being toggled from within the user space:


Code:
const char *const amplifierGPIO = "/sys/class/gpio/gpio107/value";

    void amplifierUnmute()
    {
      std::ofstream amp(amplifierGPIO);
      if (amp.is_open())
      {
        amp << "1";
        amp.close();
      }
    }

Now I am wondering how this works. For instance, is there some file where every pin which has been instantiated as a gpio pin is listed s/t the a user can access it like in the example above. Or does one have to go beyond instantiating the pin as gpio? For instance, lets say I build a pin as a gpio:


Code:
MX51_PIN_EIM_A24 = _MXC_BUILD_GPIO_PIN_MX51(1, 18, 1, 0xBC, 0x450),


Now how to access that pin inside the user space... it doesn't seem obvious to me how to go from instantiating a pin as a gpio pin to accessing it from the user space. It also seems foolish to believe that it is hard. I am going to start with this kernels Documentation/gpio.txt

Last edited by RudiC; 02-12-2019 at 01:07 PM..
 

2 More Discussions You Might Find Interesting

1. Programming

Unable to reference sysfs on Linux.

I am porting C code to a linux system but I am unable to link a call to the sysfs function. An excerpt from my code is: if (fstat(fileno(TrCtl.Fp), &fsstat) != -1) { (void) sysfs(1, fsname); if (strcmp(fsname, "nfs")) { (void) lockf(fileno(TrCtl.Fp), F_LOCK, 0L); ... (5 Replies)
Discussion started by: mbb
5 Replies

2. Linux

Query about creating sysfs directory under device driver

Hi all, Currently i am involved in developing a device driver for a custom hardware. My linux stack already has the sysfs directory structure /sys/class/hwmon/ My need is that, while loading my device driver i need to create a "xyz" sysfs directory inside hwmon sysfs directory as... (0 Replies)
Discussion started by: cbalu
0 Replies
GPIOLOCK(4)						   BSD Kernel Interfaces Manual 					       GPIOLOCK(4)

NAME
gpiolock -- support for multi-position keylocks attached to GPIO pins SYNOPSIS
gpiolock* at gpio? offset ? mask ? gpiolock* at gpio? DESCRIPTION
The gpiolock driver allows connecting of multi-position keylocks over GPIO pins. The keylock driver registers with an in-kernel keylock sup- porting system and provides kauth(9) support through an experimental security model. The keylock state can be queried using the hw.keylock sysctl variables. Only locks with 2-4 positions are currently supported. The pin number is specified in the kernel configuration with the offset locator. The mask locator denotes the pins used for the lock (minimum 2, maximum 4 pins are used). The offset and mask can also be specified when gpiolock is attached at runtime using the GPIOATTACH ioctl(2) on the gpio(4) device. SEE ALSO
gpio(4), intro(4) HISTORY
The gpiolock driver first appeared in NetBSD 6.0. AUTHORS
The gpiolock driver was written by Marc Balmer <marc@msys.ch>. BSD
August 21, 2009 BSD
All times are GMT -4. The time now is 04:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy