1 """Generic RP2040 pin names"""
2 from .rp2040_u2if import rp2040_u2if
6 """A basic Pin class for use with RP2040 with u2if firmware."""
19 def __init__(self, pin_id=None):
24 # pylint:disable = no-self-use
25 def _u2if_open_hid(self, vid, pid):
26 rp2040_u2if.open(vid, pid)
28 def init(self, mode=IN, pull=PULL_NONE):
29 """Initialize the Pin"""
30 pull = Pin.PULL_NONE if pull is None else pull
32 raise RuntimeError("Can not init a None type pin.")
33 if mode not in (Pin.IN, Pin.OUT):
34 raise ValueError("Incorrect mode value.")
35 if pull not in (Pin.PULL_NONE, Pin.PULL_UP, Pin.PULL_DOWN):
36 raise ValueError("Incorrect pull value.")
38 rp2040_u2if.gpio_init_pin(self.id, mode, pull)
43 def value(self, val=None):
44 """Set or return the Pin Value"""
46 if self._mode in (Pin.IN, Pin.OUT):
49 return rp2040_u2if.gpio_get_pin(self.id)
51 if val in (Pin.LOW, Pin.HIGH):
52 rp2040_u2if.gpio_set_pin(self.id, val)
55 raise ValueError("Invalid value for pin.")
58 "No action for mode {} with value {}".format(self._mode, val)
62 # create pin instances for each pin