Add pins database

Related to @lurch's comments on #148, this PR contains a database of
pins for each Pi revision, along with various other bits of miscellany
(I might've gotten a bit carried away here...).

Any corrections/extensions welcome!
This commit is contained in:
Dave Jones
2016-04-03 19:53:59 +01:00
parent 365e309af6
commit 50946b417c
9 changed files with 775 additions and 26 deletions

View File

@@ -9,6 +9,7 @@ str = type('')
import pigpio
from . import Pin
from .data import pi_info
from ..exc import (
PinInvalidFunction,
PinSetInput,
@@ -93,7 +94,14 @@ class PiGPIOPin(Pin):
GPIO_PULL_UP_NAMES = {v: k for (k, v) in GPIO_PULL_UPS.items()}
GPIO_EDGES_NAMES = {v: k for (k, v) in GPIO_EDGES.items()}
PI_INFO = None
def __new__(cls, number, host='localhost', port=8888):
# XXX What about remote pins? This should probably be instance
# specific rather than class specific for pigpio. Need to check how
# to query remote info though...
if cls.PI_INFO is None:
cls.PI_INFO = pi_info()
try:
return cls._PINS[(host, port, number)]
except KeyError:
@@ -107,7 +115,7 @@ class PiGPIOPin(Pin):
self._host = host
self._port = port
self._number = number
self._pull = 'up' if number in (2, 3) else 'floating'
self._pull = 'up' if cls.PI_INFO.pulled_up('GPIO%d' % number) else 'floating'
self._pwm = False
self._bounce = None
self._when_changed = None
@@ -150,7 +158,7 @@ class PiGPIOPin(Pin):
self.frequency = None
self.when_changed = None
self.function = 'input'
self.pull = 'up' if self.number in (2, 3) else 'floating'
self.pull = 'up' if self.PI_INFO.pulled_up('GPIO%d' % self.number) else 'floating'
def _get_function(self):
return self.GPIO_FUNCTION_NAMES[self._connection.get_mode(self._number)]
@@ -187,7 +195,7 @@ class PiGPIOPin(Pin):
def _set_pull(self, value):
if self.function != 'input':
raise PinFixedPull('cannot set pull on non-input pin %r' % self)
if value != 'up' and self._number in (2, 3):
if value != 'up' and self.PI_INFO.pulled_up('GPIO%d' % self._number):
raise PinFixedPull('%r has a physical pull-up resistor' % self)
try:
self._connection.set_pull_up_down(self._number, self.GPIO_PULL_UPS[value])