X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/03c4bc1d41655d8e73ff89039b2a8ec34b3649ca..3b01699d1e09bc494656bae583d1f70b35d8975e:/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py diff --git a/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py b/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py index 96a06b4..e5198a1 100644 --- a/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py +++ b/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT """Helper class for use with RP2040 running u2if firmware""" # https://github.com/execuc/u2if @@ -68,22 +71,15 @@ class RP2040_u2if: PWM_GET_DUTY_NS = 0x37 def __init__(self): + self._vid = None + self._pid = None + self._hid = None self._opened = False self._i2c_index = None self._spi_index = None self._serial = None self._neopixel_initialized = False - # self._vid = vid - # self._pid = pid - # self._hid = hid.device() - # self._hid.open(self._vid, self._pid) - # if RP2040_U2IF_RESET_DELAY >= 0: - # self._reset() - # self._i2c_index = None - # self._spi_index = None - # self._serial = None - # self._neopixel_initialized = False - # self._uart_rx_buffer = None + self._uart_rx_buffer = None def _hid_xfer(self, report, response=True): """Perform HID Transfer""" @@ -98,6 +94,7 @@ class RP2040_u2if: def _reset(self): self._hid_xfer(bytes([self.SYS_RESET]), False) + self._hid.close() time.sleep(RP2040_U2IF_RESET_DELAY) start = time.monotonic() while time.monotonic() - start < 5: @@ -113,6 +110,8 @@ class RP2040_u2if: # MISC # ---------------------------------------------------------------- def open(self, vid, pid): + """Open HID interface for given USB VID and PID.""" + if self._opened: return self._vid = vid @@ -277,7 +276,7 @@ class RP2040_u2if: out_start=0, out_end=None, in_start=0, - in_end=None + in_end=None, ): """Write data from buffer_out to an address and then read data from an address and into buffer_in @@ -370,7 +369,7 @@ class RP2040_u2if: out_start=0, out_end=None, in_start=0, - in_end=None + in_end=None, ): """SPI write and readinto.""" raise NotImplementedError("SPI write_readinto Not implemented")