From d682a90255af146b6c85d8369fa92b3b934f4cca Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 10 Jan 2018 16:20:24 -0800 Subject: 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 --- mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'mpm/python/usrp_mpm/sys_utils/sysfs_gpio.py') 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<