From 8d4552526c3cd62347282731335b89cdb0effd2b Mon Sep 17 00:00:00 2001 From: 3rd Iteration Date: Fri, 12 Aug 2022 22:16:21 -0400 Subject: [PATCH] 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. --- src/seedsigner/hardware/ST7789.py | 8 ++-- src/seedsigner/hardware/buttons.py | 71 +++++++++++++++--------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/seedsigner/hardware/ST7789.py b/src/seedsigner/hardware/ST7789.py index 09cebd20..e1e1fade 100644 --- a/src/seedsigner/hardware/ST7789.py +++ b/src/seedsigner/hardware/ST7789.py @@ -13,11 +13,11 @@ class ST7789(object): self.height = 240 #Initialize DC RST pin - self._dc = 25 - self._rst = 27 - self._bl = 24 + self._dc = 22 + self._rst = 13 + self._bl = 18 - GPIO.setmode(GPIO.BCM) + GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(self._dc,GPIO.OUT) GPIO.setup(self._rst,GPIO.OUT) diff --git a/src/seedsigner/hardware/buttons.py b/src/seedsigner/hardware/buttons.py index 44a33d60..d187f8c8 100644 --- a/src/seedsigner/hardware/buttons.py +++ b/src/seedsigner/hardware/buttons.py @@ -6,27 +6,27 @@ from seedsigner.models.singleton import Singleton class HardwareButtons(Singleton): if GPIO.RPI_INFO['P1_REVISION'] == 3: #This indicates that we have revision 3 GPIO print("Detected 40pin GPIO (Rasbperry Pi 2 and above)") - KEY_UP_PIN = 6 - KEY_DOWN_PIN = 19 - KEY_LEFT_PIN = 5 - KEY_RIGHT_PIN = 26 - KEY_PRESS_PIN = 13 + KEY_UP_PIN = 31 + KEY_DOWN_PIN = 35 + KEY_LEFT_PIN = 29 + KEY_RIGHT_PIN = 37 + KEY_PRESS_PIN = 33 - KEY1_PIN = 21 - KEY2_PIN = 20 - KEY3_PIN = 16 + KEY1_PIN = 40 + KEY2_PIN = 38 + KEY3_PIN = 36 else: print("Assuming 26 Pin GPIO (Raspberry P1 1)") - KEY_UP_PIN = 3 - KEY_DOWN_PIN = 17 - KEY_LEFT_PIN = 2 - KEY_RIGHT_PIN = 22 - KEY_PRESS_PIN = 4 + KEY_UP_PIN = 5 + KEY_DOWN_PIN = 11 + KEY_LEFT_PIN = 3 + KEY_RIGHT_PIN = 15 + KEY_PRESS_PIN = 7 - KEY1_PIN = 23 - KEY2_PIN = 18 - KEY3_PIN = 14 + KEY1_PIN = 16 + KEY2_PIN = 12 + KEY3_PIN = 8 @classmethod def get_instance(cls): @@ -35,7 +35,7 @@ class HardwareButtons(Singleton): cls._instance = cls.__new__(cls) #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_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 @@ -170,31 +170,30 @@ class HardwareButtons(Singleton): return True return False - - - # class used as short hand for static button/channel lookup values # TODO: Implement `release_lock` functionality as a global somewhere. Mixes up design # patterns to have a static constants class plus a settable global value. class HardwareButtonsConstants: if GPIO.RPI_INFO['P1_REVISION'] == 3: #This indicates that we have revision 3 GPIO - KEY_UP = 6 - KEY_DOWN = 19 - KEY_LEFT = 5 - KEY_RIGHT = 26 - KEY_PRESS = 13 - KEY1 = 21 - KEY2 = 20 - KEY3 = 16 + KEY_UP = 31 + KEY_DOWN = 35 + KEY_LEFT = 29 + KEY_RIGHT = 37 + KEY_PRESS = 33 + + KEY1 = 40 + KEY2 = 38 + KEY3 = 36 else: - KEY_UP = 3 - KEY_DOWN = 17 - KEY_LEFT = 2 - KEY_RIGHT = 22 - KEY_PRESS = 4 - KEY1 = 23 - KEY2 = 18 - KEY3 = 14 + KEY_UP = 5 + KEY_DOWN = 11 + KEY_LEFT = 3 + KEY_RIGHT = 15 + KEY_PRESS = 7 + + KEY1 = 16 + KEY2 = 12 + KEY3 = 8 OVERRIDE = 1000