aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2018-01-10 16:20:24 -0800
committerMartin Braun <martin.braun@ettus.com>2018-01-10 17:31:21 -0800
commitd682a90255af146b6c85d8369fa92b3b934f4cca (patch)
tree3e3e1c358fe10bac18020139c3a635f2713d5264 /mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py
parentab1148d62d897a0262a803269254586699b82495 (diff)
downloaduhd-d682a90255af146b6c85d8369fa92b3b934f4cca.tar.gz
uhd-d682a90255af146b6c85d8369fa92b3b934f4cca.tar.bz2
uhd-d682a90255af146b6c85d8369fa92b3b934f4cca.zip
mpm: Factor GPIO panel code into common module
GPIOBank is the new class, n310.FrontpanelGPIO and BackpanelGPIO now derive from that. Other minor changes: - Renamed classes to FrontpanelGPIO and BackpanelGPIO in accordance with coding guidelines - Moved MboardRegsControl before n310 class for consistent code layout
Diffstat (limited to 'mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py')
-rw-r--r--mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py b/mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py
index 29056a51f..4911c1f75 100644
--- a/mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py
+++ b/mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py
@@ -186,3 +186,69 @@ class SysFSGPIO(object):
self.log.trace("Reading value {} from `{}'...".format(read_value, value_path))
return read_value
+class GPIOBank(object):
+ """
+ Extension of a SysFSGPIO
+ """
+ def __init__(self, uio_label, offset, usemask, ddr):
+ self._gpiosize = bin(usemask).count("1")
+ self._offset = offset
+ self._ddr = ddr
+ self._usemask = usemask
+ self._gpios = SysFSGPIO(
+ uio_label,
+ self._usemask << self._offset,
+ self._ddr << self._offset
+ )
+
+ def set_all(self, value):
+ """
+ Set all pins to 'value'.
+ This method will convert value into binary and assign all the bits in
+ the use mask.
+ """
+ bin_value = ('{0:0'+self._gpiosize+'b}').format(value)
+ wr_value = bin_value[-(self._gpiosize):]
+ for i in range(self._gpiosize):
+ if (1 << i) & self._ddr:
+ self._gpios.set(self._offset + i, wr_value[i % self._gpiosize])
+
+ def set(self, index, value=None):
+ """
+ Set a pin by index
+ """
+ assert index in range(self._gpiosize)
+ self._gpios.set(self._offset + index, value)
+
+ def reset_all(self):
+ """
+ Clear all pins
+ """
+ for i in range(self._gpiosize):
+ self._gpios.reset(self._offset+i)
+
+ def reset(self, index):
+ """
+ Clear a pin by index
+ """
+ assert index in range(self._gpiosize)
+ self._gpios.reset(self._offset + index)
+
+ def get_all(self):
+ """
+ Read back all pins
+ """
+ result = 0
+ for i in range(self._gpiosize):
+ if not (1<<i)&self._ddr:
+ value = self._gpios.get(self._offset + i)
+ result = (result << 1) | value
+ return result
+
+ def get(self, index):
+ """
+ Read back a pin by index
+ """
+ assert index in range(self._gpiosize)
+ return self._gpios.get(self._offset + index)
+