X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka.git/blobdiff_plain/173411fa58ff885d28703c69125a0e90db6cf0bf..d64205c7f1dde94030b92a3e143d63e64182aa6c:/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py diff --git a/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py b/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py index de6e181..a648502 100644 --- a/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py +++ b/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py @@ -16,6 +16,10 @@ class Pin: # pin values LOW = 0 HIGH = 1 + # pin pulls + PULL_NONE = 0 + PULL_UP = 1 + PULL_DOWN = 2 def return_toggle(self): """Returns the pin's expected value, toggling between True and False""" @@ -41,7 +45,8 @@ class Pin: def __init__(self, pin_id=None): self.id = pin_id self._mode = None - self.previous_value = None + self._pull = None + self.previous_value = False self.current_value = None # mapping of pin definition names to expected behavior @@ -50,13 +55,13 @@ class Pin: 1: self.return_false, # Dx_INPUT_FALSE 2: self.return_true, # Dx_INPUT_TRUE_PULL_UP 3: self.return_true, # Dx_INPUT_TRUE_PULL_DOWN - 4: self.return_true, # Dx_OUTPUT_TRUE - 5: self.return_false, # Dx_OUTPUT_FALSE + 4: self.return_true, # Dx_OUTPUT 6: self.return_true, # NEOPIXEL 7: self.return_random_int, # Ax_INPUT_RAND_INT 8: self.return_fixed_int_pi, # Ax_INPUT_FIXED_INT_PI 9: self.return_true, # Ax_OUTPUT_WAVE_SINE 10: self.return_true, # Ax_OUTPUT_WAVE_SAWTOOTH + 11: self.return_toggle, # Dx_INPUT_TOGGLE # Add other mappings as needed } @@ -64,8 +69,8 @@ class Pin: """Initialize the Pin""" if self.id is None: raise RuntimeError("Can not init a None type pin.") - if pull is not None: - raise NotImplementedError("Internal pullups and pulldowns not supported") + pull = Pin.PULL_NONE if pull is None else pull + self._pull = pull self._mode = mode def write(self, new_value): @@ -78,6 +83,13 @@ class Pin: self.previous_value = self.current_value # perform a lookup on the pin_behavior dict to get the value self.current_value = self.pin_behavior.get(self.id)() + + # is pin a pull up and pin is LOW? + if self._pull == Pin.PULL_UP and self.current_value == False: + self.current_value = False + # is pin a pull down and pin is HIGH? + if self._pull == Pin.PULL_DOWN and self.current_value == True: + self.current_value = False return self.current_value def value(self, val=None): @@ -116,7 +128,6 @@ D1 = Pin(1) D2 = Pin(2) D3 = Pin(3) D4 = Pin(4) -D5 = Pin(5) # Special "digital" pins D6 = Pin(6) # Analog pins @@ -125,6 +136,8 @@ A1 = Pin(8) A2 = Pin(9) A3 = Pin(10) +D7 = Pin(11) + # I2C pins SDA = Pin() SCL = Pin()