DancingQuanta / pyusbiss

Python API for USB-ISS Multifunction USB Communications Module
MIT License
2 stars 3 forks source link

SPI driver creating an usbiss instance. #14

Open gwdehaan opened 5 years ago

gwdehaan commented 5 years ago

Description

SPI is the only usbiss mode that does not allow any coexistence with another protocol, as it uses all 4 available pins. Therefore in the current implementation of SPI it made sense to open the COM port within the SPI driver.

What I Did

As I2C, Serial and GPIO can be used in combination with each other and therefor it is not possible to open usbiss within The driver, you can only open the COM port once. These 3 drivers expect the user to instantiate a usbiss class and then pass on the instance to the driver.

Example

from usbiss import usbiss
from usbiss import gpio
from usbiss import i2c

port = 'COM3'
# open the COM port for the USBISS
usbissdev = usbiss.USBISS(port)
# use the GPIO in I2C mode (2 pins available for GPIO)
io2 = gpio.GPIO(usbissdev, gpio.I2C)
io2.setup(1, gpio.OUT)
io2.output(1, gpio.HIGH)
io2.setup(2, gpio.IN)
# Open an i2c channel
i2c_chan = I2C.I2C(usbissdev, 'H', 100)

Proposal

To prevent having 2 different driver architectures I would like to suggest to adapt the SPI driver to the same setup.

Current \:

def __init__(self, port, mode=0, max_speed_hz=3000000):
    self._usbiss = USBISS(port)

Proposal \:

def __init__(self, usbissdev, mode=0, max_speed_hz=3000000):
    self._usbiss = usbissdev