- raise NotImplementedError(
- "Internal pullups not supported in libgpiod, "
- "use physical resistor instead!"
- )
- if pull == self.PULL_DOWN:
- raise NotImplementedError(
- "Internal pulldowns not supported in libgpiod, "
- "use physical resistor instead!"
- )
- raise RuntimeError("Invalid pull for pin: %s" % self.id)
+ if hasattr(gpiod, "LINE_REQ_FLAG_BIAS_PULL_UP"):
+ flags |= gpiod.LINE_REQ_FLAG_BIAS_PULL_UP
+ else:
+ raise NotImplementedError(
+ "Internal pullups not supported in this version of libgpiod, "
+ "use physical resistor instead!"
+ )
+ elif pull == self.PULL_DOWN:
+ if hasattr(gpiod, "line") and hasattr(
+ gpiod, "LINE_REQ_FLAG_BIAS_PULL_DOWN"
+ ):
+ flags |= gpiod.LINE_REQ_FLAG_BIAS_PULL_DOWN
+ else:
+ raise NotImplementedError(
+ "Internal pulldowns not supported in this version of libgpiod, "
+ "use physical resistor instead!"
+ )
+ elif pull == self.PULL_NONE:
+ if hasattr(gpiod, "line") and hasattr(
+ gpiod, "LINE_REQ_FLAG_BIAS_DISABLE"
+ ):
+ flags |= gpiod.LINE_REQ_FLAG_BIAS_DISABLE
+ else:
+ raise NotImplementedError(
+ "Internal pulldowns not supported in this version of libgpiod, "
+ "use physical resistor instead!"
+ )
+ else:
+ raise RuntimeError(f"Invalid pull for pin: {self.id}")