def __init__(self, port, simPort=None): """Constructor :param port: the physical SPI port :type port: :class:`.SPI.Port` :param simPort: This must be an object that implements all of the spi* functions from hal_impl that you use. See ``test_spi.py`` for an example. """ if port not in [self.Port.kOnboardCS0, self.Port.kOnboardCS1, self.Port.kOnboardCS2, self.Port.kOnboardCS3, self.Port.kMXP]: raise ValueError("Invalid value '%s' for SPI port" % port) if hal.HALIsSimulation(): if simPort is None: # If you want more functionality, implement your own mock from hal_impl.spi_helpers import SPISimBase simPort = SPISimBase() msg = "Using stub simulator for SPI port %s" % port warnings.warn(msg) # Just check for basic functionality assert hasattr(simPort, 'initializeSPI') assert hasattr(simPort, 'closeSPI') self._port = (simPort, port) else: self._port = port self.bitOrder = False self.clockPolarity = False self.dataOnTrailing = False hal.initializeSPI(self._port) self.__finalizer = weakref.finalize(self, _freeSPI, self._port) SPI.devices += 1 hal.report(hal.UsageReporting.kResourceType_SPI, SPI.devices)
def __init__(self, port, simPort=None): """Constructor :param port: the physical SPI port :type port: :class:`.SPI.Port` :param simPort: This must be an object that implements all of the spi* functions from hal_impl that you use. See ``test_spi.py`` for an example. """ port = self.Port(port) # python-specific if hal.HALIsSimulation(): if simPort is None: # If you want more functionality, implement your own mock from hal_impl.spi_helpers import SPISimBase simPort = SPISimBase() msg = "Using stub simulator for SPI port %s" % port warnings.warn(msg) # Just check for basic functionality assert hasattr(simPort, "initializeSPI") assert hasattr(simPort, "closeSPI") self._port = (simPort, port) else: self._port = port # python-specific: these are bools instead of integers self.msbFirst = False self.clockIdleHigh = False self.sampleOnTrailing = False self.accum = None hal.initializeSPI(self._port) self.__finalizer = weakref.finalize(self, _freeSPI, self._port) SPI.devices += 1 hal.report(hal.UsageReporting.kResourceType_SPI, SPI.devices)
def __init__(self, port: Port, simPort=None) -> None: """Constructor :param port: the physical SPI port :param simPort: This must be an object that implements all of the spi* functions from hal_impl that you use. See ``test_spi.py`` for an example. """ port = self.Port(port) # python-specific if hal.HALIsSimulation(): if simPort is None: # If you want more functionality, implement your own mock from hal_impl.spi_helpers import SPISimBase simPort = SPISimBase() msg = "Using stub simulator for SPI port %s" % port warnings.warn(msg) # Just check for basic functionality assert hasattr(simPort, "initializeSPI") assert hasattr(simPort, "closeSPI") self.port = (simPort, port) else: self.port = port # python-specific: these are bools instead of integers self.msbFirst = False self.clockIdleHigh = False self.sampleOnTrailing = False self.accum = None hal.initializeSPI(self.port) self.__finalizer = weakref.finalize(self, _freeSPI, self.port) SPI.devices += 1 hal.report(hal.UsageReporting.kResourceType_SPI, SPI.devices)