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 def _u2if_open_hid(self, vid, pid):
25 rp2040_u2if.open(vid, pid)
27 def init(self, mode=IN, pull=PULL_NONE):
28 """Initialize the Pin"""
29 pull = Pin.PULL_NONE if pull is None else pull
31 raise RuntimeError("Can not init a None type pin.")
32 if mode not in (Pin.IN, Pin.OUT):
33 raise ValueError("Incorrect mode value.")
34 if pull not in (Pin.PULL_NONE, Pin.PULL_UP, Pin.PULL_DOWN):
35 raise ValueError("Incorrect pull value.")
37 rp2040_u2if.gpio_init_pin(self.id, mode,pull)
42 def value(self, val=None):
43 """Set or return the Pin Value"""
45 if self._mode in (Pin.IN, Pin.OUT):
48 return rp2040_u2if.gpio_get_pin(self.id)
50 if val in (Pin.LOW, Pin.HIGH):
51 rp2040_u2if.gpio_set_pin(self.id, val)
54 raise ValueError("Invalid value for pin.")
57 "No action for mode {} with value {}".format(self._mode, val)
61 # create pin instances for each pin