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
STRUCT 
I2C_BUS_RECOV(9) I2C and SMBus Subsystem STRUCT I2C_BUS_RECOV(9) NAME
struct_i2c_bus_recovery_info - I2C bus recovery information SYNOPSIS
struct i2c_bus_recovery_info { int (* recover_bus) (struct i2c_adapter *); int (* get_scl) (struct i2c_adapter *); void (* set_scl) (struct i2c_adapter *, int val); int (* get_sda) (struct i2c_adapter *); void (* prepare_recovery) (struct i2c_bus_recovery_info *bri); void (* unprepare_recovery) (struct i2c_bus_recovery_info *bri); int scl_gpio; int sda_gpio; }; MEMBERS
recover_bus Recover routine. Either pass driver's recover_bus routine, or i2c_generic_scl_recovery or i2c_generic_gpio_recovery. get_scl This gets current value of SCL line. Mandatory for generic SCL recovery. Used internally for generic GPIO recovery. set_scl This sets/clears SCL line. Mandatory for generic SCL recovery. Used internally for generic GPIO recovery. get_sda This gets current value of SDA line. Optional for generic SCL recovery. Used internally, if sda_gpio is a valid GPIO, for generic GPIO recovery. prepare_recovery This will be called before starting recovery. Platform may configure padmux here for SDA/SCL line or something else they want. unprepare_recovery This will be called after completing recovery. Platform may configure padmux here for SDA/SCL line or something else they want. scl_gpio gpio number of the SCL line. Only required for GPIO recovery. sda_gpio gpio number of the SDA line. Only required for GPIO recovery. COPYRIGHT
Kernel Hackers Manual 3.10 June 2014 STRUCT I2C_BUS_RECOV(9)
All times are GMT -4. The time now is 06:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy