jobin-sun / raspberry-gpio-python

Automatically exported from code.google.com/p/raspberry-gpio-python
MIT License
0 stars 0 forks source link

Add gpio_function subroutine #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Add gpio_function subroutine:

int gpio_function(int gpio)
{
   int offset = FSEL_OFFSET + (gpio/10);
   int shift = (gpio%10)*3;

   int value = *(gpio_map+offset);
   value >>= shift
   value &= 7;
   return value; //0 = input 1=output 4=alt0
}

Original issue reported on code.google.com by btcros...@googlemail.com on 9 Sep 2012 at 3:02

GoogleCodeExporter commented 9 years ago
Change now in source code library.  Awaiting formal release in 0.4.0a

Original comment by btcros...@googlemail.com on 9 Sep 2012 at 3:04

GoogleCodeExporter commented 9 years ago
Just tested it successfully.
But the check you added in py_setup_channel is may be too much as you must use 
force=1 if you close RPi.GPIO then reopen it. It can happen if you use RPi.GPIO 
with cron for instance.

pi@raspberrypi ~ $ sudo python
Python 2.7.3rc2 (default, May  6 2012, 20:02:25) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as g
>>> g.setmode(g.BCM)
>>> g.gpio_function(7)
1
>>> g.setup(7, 0)
>>> g.gpio_function(7)
0
>>> 
KeyboardInterrupt
>>> 

pi@raspberrypi ~ $ sudo python
Python 2.7.3rc2 (default, May  6 2012, 20:02:25) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as g
>>> g.setmode(g.BCM)
>>> g.gpio_function(7)
0
>>> g.setup(7, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RPi.GPIO.InvalidChannelException: This channel is in use.  Try GPIO.setup( ... 
, force=1) to override
>>> 

Original comment by tro...@trouch.com on 9 Sep 2012 at 4:30

GoogleCodeExporter commented 9 years ago
Exception changed to just a warning message.
Included in release 0.4.0a - closing issue

Original comment by btcros...@googlemail.com on 21 Sep 2012 at 1:51