Switch GPIO numbering mode to board

Change the code so that the RPI.GPIO module addressing is based on the physical board pin number rather than the internal SoC channel.

Boosts compatibility with holder hardware and makes it easier to see which pins do what.
This commit is contained in:
3rd Iteration
2022-08-12 22:16:21 -04:00
parent 3960ed4fbb
commit 8d4552526c
2 changed files with 39 additions and 40 deletions
+4 -4
View File
@@ -13,11 +13,11 @@ class ST7789(object):
self.height = 240 self.height = 240
#Initialize DC RST pin #Initialize DC RST pin
self._dc = 25 self._dc = 22
self._rst = 27 self._rst = 13
self._bl = 24 self._bl = 18
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False) GPIO.setwarnings(False)
GPIO.setup(self._dc,GPIO.OUT) GPIO.setup(self._dc,GPIO.OUT)
GPIO.setup(self._rst,GPIO.OUT) GPIO.setup(self._rst,GPIO.OUT)
+35 -36
View File
@@ -6,27 +6,27 @@ from seedsigner.models.singleton import Singleton
class HardwareButtons(Singleton): class HardwareButtons(Singleton):
if GPIO.RPI_INFO['P1_REVISION'] == 3: #This indicates that we have revision 3 GPIO if GPIO.RPI_INFO['P1_REVISION'] == 3: #This indicates that we have revision 3 GPIO
print("Detected 40pin GPIO (Rasbperry Pi 2 and above)") print("Detected 40pin GPIO (Rasbperry Pi 2 and above)")
KEY_UP_PIN = 6 KEY_UP_PIN = 31
KEY_DOWN_PIN = 19 KEY_DOWN_PIN = 35
KEY_LEFT_PIN = 5 KEY_LEFT_PIN = 29
KEY_RIGHT_PIN = 26 KEY_RIGHT_PIN = 37
KEY_PRESS_PIN = 13 KEY_PRESS_PIN = 33
KEY1_PIN = 21 KEY1_PIN = 40
KEY2_PIN = 20 KEY2_PIN = 38
KEY3_PIN = 16 KEY3_PIN = 36
else: else:
print("Assuming 26 Pin GPIO (Raspberry P1 1)") print("Assuming 26 Pin GPIO (Raspberry P1 1)")
KEY_UP_PIN = 3 KEY_UP_PIN = 5
KEY_DOWN_PIN = 17 KEY_DOWN_PIN = 11
KEY_LEFT_PIN = 2 KEY_LEFT_PIN = 3
KEY_RIGHT_PIN = 22 KEY_RIGHT_PIN = 15
KEY_PRESS_PIN = 4 KEY_PRESS_PIN = 7
KEY1_PIN = 23 KEY1_PIN = 16
KEY2_PIN = 18 KEY2_PIN = 12
KEY3_PIN = 14 KEY3_PIN = 8
@classmethod @classmethod
def get_instance(cls): def get_instance(cls):
@@ -35,7 +35,7 @@ class HardwareButtons(Singleton):
cls._instance = cls.__new__(cls) cls._instance = cls.__new__(cls)
#init GPIO #init GPIO
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BOARD)
GPIO.setup(HardwareButtons.KEY_UP_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(HardwareButtons.KEY_UP_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up
GPIO.setup(HardwareButtons.KEY_DOWN_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(HardwareButtons.KEY_DOWN_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up
GPIO.setup(HardwareButtons.KEY_LEFT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(HardwareButtons.KEY_LEFT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up
@@ -170,31 +170,30 @@ class HardwareButtons(Singleton):
return True return True
return False return False
# class used as short hand for static button/channel lookup values # class used as short hand for static button/channel lookup values
# TODO: Implement `release_lock` functionality as a global somewhere. Mixes up design # TODO: Implement `release_lock` functionality as a global somewhere. Mixes up design
# patterns to have a static constants class plus a settable global value. # patterns to have a static constants class plus a settable global value.
class HardwareButtonsConstants: class HardwareButtonsConstants:
if GPIO.RPI_INFO['P1_REVISION'] == 3: #This indicates that we have revision 3 GPIO if GPIO.RPI_INFO['P1_REVISION'] == 3: #This indicates that we have revision 3 GPIO
KEY_UP = 6 KEY_UP = 31
KEY_DOWN = 19 KEY_DOWN = 35
KEY_LEFT = 5 KEY_LEFT = 29
KEY_RIGHT = 26 KEY_RIGHT = 37
KEY_PRESS = 13 KEY_PRESS = 33
KEY1 = 21
KEY2 = 20 KEY1 = 40
KEY3 = 16 KEY2 = 38
KEY3 = 36
else: else:
KEY_UP = 3 KEY_UP = 5
KEY_DOWN = 17 KEY_DOWN = 11
KEY_LEFT = 2 KEY_LEFT = 3
KEY_RIGHT = 22 KEY_RIGHT = 15
KEY_PRESS = 4 KEY_PRESS = 7
KEY1 = 23
KEY2 = 18 KEY1 = 16
KEY3 = 14 KEY2 = 12
KEY3 = 8
OVERRIDE = 1000 OVERRIDE = 1000