]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Add support for ftdi URLs in the BLINKA_FT232H variable.
authorTom Rothamel <tom@rothamel.us>
Thu, 25 Mar 2021 04:46:48 +0000 (00:46 -0400)
committerTom Rothamel <tom@rothamel.us>
Thu, 25 Mar 2021 04:46:48 +0000 (00:46 -0400)
This allows the an FTDI URL, like ftdi://ftdi:232h:W00001/1
to be given in the BLINKA_FT232H. If it's used, then that
board is the one that is opened. If the value of the variable
is not an FTDI url, then the default is used.

This makes it possible for multiple processes on the same
computer to talk to different FTDI boards. While talking
to multiple boards from a single process might be possible,
that's outside of the scope of this commit.

src/adafruit_blinka/microcontroller/ft232h/i2c.py
src/adafruit_blinka/microcontroller/ft232h/pin.py
src/adafruit_blinka/microcontroller/ft232h/spi.py
src/adafruit_blinka/microcontroller/ft232h/url.py [new file with mode: 0644]

index 2d21f15408a9512d86ff5207543434fe5790cbeb..a2501a0def2af59283970fa337c15d757223e574 100644 (file)
@@ -1,6 +1,6 @@
 """I2C Class for FT232H"""
 from adafruit_blinka.microcontroller.ft232h.pin import Pin
 """I2C Class for FT232H"""
 from adafruit_blinka.microcontroller.ft232h.pin import Pin
-
+from adafruit_blinka.microcontroller.ft232h.url import get_ftdi_url
 
 class I2C:
     """Custom I2C Class for FT232H"""
 
 class I2C:
     """Custom I2C Class for FT232H"""
@@ -13,7 +13,7 @@ class I2C:
         # pylint: enable=import-outside-toplevel
 
         self._i2c = I2cController()
         # pylint: enable=import-outside-toplevel
 
         self._i2c = I2cController()
-        self._i2c.configure("ftdi://ftdi:ft232h/1", frequency=frequency)
+        self._i2c.configure(get_ftdi_url(), frequency=frequency)
         Pin.ft232h_gpio = self._i2c.get_gpio()
 
     def scan(self):
         Pin.ft232h_gpio = self._i2c.get_gpio()
 
     def scan(self):
index 42ae5abd70e1176e7f6faaf23c3e53a4d5fd98ad..e7a2ad80e7084699b529a39da3424fb05e9ccb50 100644 (file)
@@ -1,5 +1,6 @@
 """FT232H pin names"""
 
 """FT232H pin names"""
 
+from adafruit_blinka.microcontroller.ft232h.url import get_ftdi_url
 
 class Pin:
     """A basic Pin class for use with FT232H."""
 
 class Pin:
     """A basic Pin class for use with FT232H."""
@@ -24,7 +25,7 @@ class Pin:
             # pylint: enable=import-outside-toplevel
 
             i2c = I2cController()
             # pylint: enable=import-outside-toplevel
 
             i2c = I2cController()
-            i2c.configure("ftdi://ftdi:ft232h/1")
+            i2c.configure(get_ftdi_url())
             Pin.ft232h_gpio = i2c.get_gpio()
         # check if pin is valid
         if pin_id:
             Pin.ft232h_gpio = i2c.get_gpio()
         # check if pin is valid
         if pin_id:
index c768eaf8b87d960990feff26a308890a2a4520c5..fd16b39348f71f5c23c063ea3434bcfebe194ef2 100644 (file)
@@ -1,5 +1,6 @@
 """SPI Class for FT232H"""
 from adafruit_blinka.microcontroller.ft232h.pin import Pin
 """SPI Class for FT232H"""
 from adafruit_blinka.microcontroller.ft232h.pin import Pin
+from adafruit_blinka.microcontroller.ft232h.url import get_ftdi_url
 
 # pylint: disable=protected-access
 class SPI:
 
 # pylint: disable=protected-access
 class SPI:
@@ -14,7 +15,7 @@ class SPI:
         # pylint: enable=import-outside-toplevel
 
         self._spi = SpiController(cs_count=1)
         # pylint: enable=import-outside-toplevel
 
         self._spi = SpiController(cs_count=1)
-        self._spi.configure("ftdi://ftdi:ft232h/1")
+        self._spi.configure(get_ftdi_url())
         self._port = self._spi.get_port(0)
         self._port.set_frequency(100000)
         self._port._cpol = 0
         self._port = self._spi.get_port(0)
         self._port.set_frequency(100000)
         self._port._cpol = 0
diff --git a/src/adafruit_blinka/microcontroller/ft232h/url.py b/src/adafruit_blinka/microcontroller/ft232h/url.py
new file mode 100644 (file)
index 0000000..ee2cb62
--- /dev/null
@@ -0,0 +1,16 @@
+"""Support for getting the URL from the BLINKA_FT232H variable."""
+
+import os
+
+def get_ftdi_url():
+    """
+    Return the FTDI url to use. If BLINKA_FT232H starts with ftdi:, returns
+    that. Otherwise, returns a default value.  
+    """
+
+    url = os.environ.get("BLINKA_FT232H", "1")
+
+    if url.startswith("ftdi:"):
+        return url
+    else:
+        return "ftdi://ftdi:ft232h/1"