1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
4 """Generic RP2040 pin names"""
5 from .rp2040_u2if import rp2040_u2if
9 """A basic Pin class for use with RP2040 with u2if firmware."""
22 def __init__(self, pin_id=None):
27 # pylint:disable = no-self-use
28 def _u2if_open_hid(self, vid, pid):
29 rp2040_u2if.open(vid, pid)
31 def init(self, mode=IN, pull=PULL_NONE):
32 """Initialize the Pin"""
33 pull = Pin.PULL_NONE if pull is None else pull
35 raise RuntimeError("Can not init a None type pin.")
36 if mode not in (Pin.IN, Pin.OUT):
37 raise ValueError("Incorrect mode value.")
38 if pull not in (Pin.PULL_NONE, Pin.PULL_UP, Pin.PULL_DOWN):
39 raise ValueError("Incorrect pull value.")
41 rp2040_u2if.gpio_init_pin(self.id, mode, pull)
46 def value(self, val=None):
47 """Set or return the Pin Value"""
49 if self._mode in (Pin.IN, Pin.OUT):
52 return rp2040_u2if.gpio_get_pin(self.id)
54 if val in (Pin.LOW, Pin.HIGH):
55 rp2040_u2if.gpio_set_pin(self.id, val)
58 raise ValueError("Invalid value for pin.")
61 "No action for mode {} with value {}".format(self._mode, val)
65 # create pin instances for each pin