]> Repositories - hackapet/Adafruit_Blinka.git/blobdiff - src/busio.py
Merge pull request #366 from SecT0uch/master
[hackapet/Adafruit_Blinka.git] / src / busio.py
index 5456f65becb42e3964e43ae15a4c504662827065..21e0446a73e2aee7994baacb9a7a53b4b9c13f7a 100755 (executable)
@@ -7,7 +7,10 @@ See `CircuitPython:busio` in CircuitPython for more details.
 * Author(s): cefn
 """
 
-import threading
+try:
+    import threading
+except ImportError:
+    threading = None
 
 import adafruit_platformdetect.constants.boards as ap_board
 import adafruit_platformdetect.constants.chips as ap_chip
@@ -69,8 +72,8 @@ class I2C(Lockable):
                     (scl, sda), i2cPorts
                 )
             )
-
-        self._lock = threading.RLock()
+        if threading is not None:
+            self._lock = threading.RLock()
 
     def deinit(self):
         """Deinitialization"""
@@ -80,11 +83,13 @@ class I2C(Lockable):
             pass
 
     def __enter__(self):
-        self._lock.acquire()
+        if threading is not None:
+            self._lock.acquire()
         return self
 
     def __exit__(self, exc_type, exc_value, traceback):
-        self._lock.release()
+        if threading is not None:
+            self._lock.release()
         self.deinit()
 
     def scan(self):
@@ -122,7 +127,7 @@ class I2C(Lockable):
         in_end=None,
         stop=False
     ):
-        """"Write to a device at specified address from a buffer then read
+        """ "Write to a device at specified address from a buffer then read
         from a device at specified address into a buffer
         """
         return self._i2c.writeto_then_readfrom(
@@ -247,7 +252,12 @@ class SPI(Lockable):
         elif detector.board.greatfet_one:
             from adafruit_blinka.microcontroller.nxp_lpc4330.spi import SPI as _SPI
             from adafruit_blinka.microcontroller.nxp_lpc4330.pin import Pin
-        elif board_id in (ap_board.PINE64, ap_board.PINEBOOK, ap_board.PINEPHONE):
+        elif board_id in (
+            ap_board.PINE64,
+            ap_board.PINEBOOK,
+            ap_board.PINEPHONE,
+            ap_board.SOPINE,
+        ):
             from adafruit_blinka.microcontroller.allwinner.a64.pin import Pin
             from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
         elif board_id == ap_board.CLOCKWORK_CPI3:
@@ -288,7 +298,7 @@ class SPI(Lockable):
         except AttributeError:
             raise NotImplementedError(
                 "Frequency attribute not implemented for this platform"
-            )
+            ) from AttributeError
 
     def write(self, buf, start=0, end=None):
         """Write to the SPI device"""
@@ -407,3 +417,36 @@ class UART(Lockable):
     def write(self, buf):
         """Write to the UART from a buffer"""
         return self._uart.write(buf)
+
+
+class OneWire:
+    """
+    Stub class for OneWire, which is currently not implemented
+    """
+
+    def __init__(self, pin):
+        raise NotImplementedError("OneWire has not been implemented")
+
+    def deinit(self):
+        """
+        Deinitialize the OneWire bus and release any hardware resources for reuse.
+        """
+        raise NotImplementedError("OneWire has not been implemented")
+
+    def reset(self):
+        """
+        Reset the OneWire bus and read presence
+        """
+        raise NotImplementedError("OneWire has not been implemented")
+
+    def read_bit(self):
+        """
+        Read in a bit
+        """
+        raise NotImplementedError("OneWire has not been implemented")
+
+    def write_bit(self, value):
+        """
+        Write out a bit based on value.
+        """
+        raise NotImplementedError("OneWire has not been implemented")