Sponsored Content
Full Discussion: GPIO and sysfs
Top Forums UNIX for Advanced & Expert Users GPIO and sysfs Post 303030779 by Circuits on Friday 15th of February 2019 11:08:29 AM
Old 02-15-2019
@Corona688 Thanks I will be sure to change my code! So I did managed to figure out the gpio lib. Apparently there is a formula that the Linux kernel uses for identifying pins based on their GPIO number:

linux gpio number = (gpio_bank - 1) * 32 + gpio_bit

So if you're pin is: GPIO2_18, then in the Linux kernel that would be: (2-1)32+18 = 50

That is the number you would have to reference in order to toggle the pin from within the user space using gpiolib.
These 2 Users Gave Thanks to Circuits For This Post:
 

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
GPIOCTL(8)						    BSD System Manager's Manual 						GPIOCTL(8)

NAME
gpioctl -- control GPIO devices SYNOPSIS
gpioctl [-q] device attach device offset mask [flag] gpioctl [-q] device pin [0 | 1 | 2] gpioctl [-q] device pin [on | off | toggle] gpioctl [-q] device pin set [flags] [name] gpioctl [-q] device pin unset DESCRIPTION
The gpioctl program allows manipulation of GPIO (General Purpose Input/Output) device pins. Such devices can be either part of the chipset or embedded CPU, or a separate chip. The usual way of using GPIO is to connect some simple devices such as LEDs and 1-wire thermal sensors to its pins. Each GPIO device has an associated device file in the /dev directory. device can be specified with or without the /dev prefix. For example, /dev/gpio0 or gpio0. GPIO pins can be either ``read'' or ``written'' with the values of logical 0 or 1. If only a pin number is specified on the command line, the pin state will be read from the GPIO controller and displayed. To write to a pin, a value must be specified after the pin number. Val- ues can be either 0 or 1. A value of 2 ``toggles'' the pin, i.e. changes its state to the opposite. Instead of the numerical values, the word on, off, or toggle can be used. To Only pins that have been configured at securelevel 0, typically during system startup, are accessible once the securelevel has been raised. Pins can be given symbolic names for easier use. Besides using individual pins, device drivers that use GPIO pins can be attached to a gpio(4) device using the gpioctl command. Such drivers can be detached at runtime using the drvctl(8) command. The following configuration flags are supported by the GPIO framework: in input direction out output direction inout bi-directional od open-drain output pp push-pull output tri tri-state (output disabled) pu internal pull-up enabled pd internal pull-down enabled iin invert input iout invert output pulsate pulsate output at a hardware-defined frequency and duty cycle Note that not all the flags may be supported by the particular GPIO controller. When executed with only the gpio(4) device name as argument, gpioctl reads information about the GPIO device and displays it. At securelevel 0 the number of physically available pins is displayed, at higher securelevels the number of configured (set) pins is displayed. The options are as follows: -q Operate quietly i.e. nothing is printed to stdout. FILES
/dev/gpiou GPIO device unit u file. EXAMPLES
Configure pin 20 to have push-pull output: # gpioctl gpio0 20 set out pp Write logical 1 to pin 20: # gpioctl gpio0 20 1 Attach a onewire(4) bus on a gpioow(4) device on pin 4: # gpioctl gpio0 attach gpioow 4 0x01 Detach the gpioow0 device: # drvctl -d gpioow0 Configure pin 5 as output and name it error_led: # gpioctl gpio0 5 set out error_led Toggle the error_led: # gpioctl gpio0 error_led 2 SEE ALSO
gpio(4), drvctl(8) HISTORY
The gpioctl command first appeared in OpenBSD 3.6 and NetBSD 4.0. AUTHORS
The gpioctl program was written by Alexander Yurchenko <grange@openbsd.org>. Device attachment was added by Marc Balmer <marc@msys.ch>. BSD
November 13, 2011 BSD
All times are GMT -4. The time now is 09:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy