Enable usage of ft4232 suspend pin
authorDan White <dan@whiteaudio.com>
Sun, 28 Oct 2012 01:37:26 +0000 (20:37 -0500)
committerDan White <dan@whiteaudio.com>
Sun, 28 Oct 2012 01:37:26 +0000 (20:37 -0500)
Need to add an external circuit which switches off power to devboard when
SUSPEND pin is low.

python-lib/calibrate.py
python-lib/devboard.py
python-lib/enable_usb_suspend.sh [new file with mode: 0755]
python-lib/test-nco.py [new file with mode: 0644]

index 98e43ac9c232883534f52e9b35576a68da711047..c10f9559f2291d8fce16a4ba66a56ccd817de6a4 100644 (file)
@@ -457,6 +457,8 @@ def calibrate(name, elements=None, verbose=True):
     an element or list of the specific elements to be calibrated, leaving
     others alone.
 
+    returns: (offsets, stats)
+
     NB: The calibration routines only modify the relevant ota.offset values,
     and sets the .cal bit for the chains.  All other settings (.fast, cint,
     etc) are left un-touched.
@@ -479,7 +481,6 @@ def calibrate(name, elements=None, verbose=True):
                 x0[j,i] = chain.h[i].ota[j].offset
         offsets, stats = secant_opt(func, x0, limits,
                 elements=elements, verbose=verbose)
-
     elif name == 'mux':
         #save mux state
         old_mode = [mux.ota[i].mode for i in range(2)]
index 709793b4c3f2c5fb4d5c781a38a7b9136e2224db..0d99217f0fe95ae4821f4c38b27874aef9c5ac45 100644 (file)
@@ -186,6 +186,20 @@ mux = None
 arb = None
 amux = None
 
+
+def close_usb():
+    """
+    Close the three MPSSE ports from the usb side.  If the serial port is also
+    closed, the kernel will suspend the device.  This makes the SUSPEND pin go
+    low on the usbio board and allows a circuit to cut power to the devboard.
+    """
+    print 'closing usb ports'
+    for c in (spi0.context, spi1.context, i2c.context):
+        usbio.ftdi.usb_close(c)
+    print 'sleeping...'
+    sleep(5)
+
+
 def init_devboard(name='devboard-defaults.yaml'):
     """Initialize devboard <-> usbio with a known configuration.  `name` may be
     a string filename, defaulting to 'devboard-defaults.yaml' or an integer
@@ -202,6 +216,7 @@ def init_devboard(name='devboard-defaults.yaml'):
 
     #blank the slate
     if is_initialized:
+        close_usb()
         _config = {}
         spi0 = None
         spi1 = None
diff --git a/python-lib/enable_usb_suspend.sh b/python-lib/enable_usb_suspend.sh
new file mode 100755 (executable)
index 0000000..b3120e2
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+#
+# turn on autosuspend for usbio
+#
+
+for f in /sys/bus/usb/devices/* ; do
+    if [ -e $f/manufacturer ]; then
+        if [ "$(cat $f/manufacturer)" == "White Audio" ]; then
+            echo $f
+            echo "0" | sudo tee $f/power/autosuspend_delay_ms
+            echo "auto" | sudo tee $f/power/control
+        fi
+    fi
+done
+
diff --git a/python-lib/test-nco.py b/python-lib/test-nco.py
new file mode 100644 (file)
index 0000000..d1f3f28
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+from time import sleep
+
+import devboard as dev
+dev.init_devboard(1)
+
+from calibrate import calibrate
+
+
+
+
+
+sleep(5)
+dev.init_devboard(1)
+
+
+
+