# Path: umap2/phy/iphy.py
# class PhyInterface(object):
#     '''
#     This class specifies the API that a physical interface should conform to
#     '''
# 
#     def __init__(self, app, name):
#         '''
#         :type app: :class:`~umap2.app.base.Umap2App`
#         :param app: application instance
#         '''
#         self.app = app
#         self.name = name
#         self.logger = logging.getLogger('umap2')
#         self.stop = False
#         self.connected_device = None
# 
#     def connect(self, usb_device):
#         '''
#         Connect a USB device
# 
#         :type usb_device: :class:`~umap2.core.usb_class.USBClass`
#         :param usb_device: USB device class
#         '''
#         self.connected_device = usb_device
# 
#     def disconnect(self):
#         '''
#         Disconnect a device.
#         Once this function returns, the phy doesn't have a reference to the
#         device.
# 
#         :return: the disconnected device (if was connected)
#         '''
#         if self.connected_device:
#             self.info('Disconnected device %s' % self.connected_device.name)
#         else:
#             self.info('Disconnect called when already disconnected')
#         dev = self.connected_device
#         self.connected_device = None
#         return dev
# 
#     def is_connected(self):
#         return self.connected_device is not None
# 
#     def send_on_endpoint(self, ep_num, data):
#         '''
#         Send data on a specific endpoint
# 
#         :param ep_num: number of endpoint
#         :param data: data to send
#         '''
#         raise NotImplementedError('should be implemented in subclass')
# 
#     def stall_ep0(self):
#         '''
#         Stalls control endpoint (0)
#         '''
#         raise NotImplementedError('should be implemented in subclass')
# 
#     def run(self):
#         '''
#         Handle USB requests
#         '''
#         raise NotImplementedError('should be implemented in subclass')
# 
#     def verbose(self, msg, *args, **kwargs):
#         self.logger.verbose('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def debug(self, msg, *args, **kwargs):
#         self.logger.debug('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def info(self, msg, *args, **kwargs):
#         self.logger.info('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def warning(self, msg, *args, **kwargs):
#         self.logger.warning('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def error(self, msg, *args, **kwargs):
#         self.logger.error('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def critical(self, msg, *args, **kwargs):
#         self.logger.critical('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def always(self, msg, *args, **kwargs):
#         self.logger.always('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
# Path: umap2/phy/raspdancer/raspdancer.py
# class Raspdancer:
# 
#     def __init__(self):
#         GPIO.setmode(GPIO.BOARD)
#         # pin15=GPIO22 is linked to MAX3420 -RST
#         GPIO.setup(15, GPIO.OUT)
#         GPIO.output(15,GPIO.LOW)
#         GPIO.output(15,GPIO.HIGH)
#         spi.openSPI(speed=26000000)
# 
#     def __del__(self):
#         spi.closeSPI()
#         GPIO.output(15,GPIO.LOW)
#         GPIO.output(15,GPIO.HIGH)
#         GPIO.cleanup()
# 
#     def transfer(self, data=[]):
#         if isinstance(data,str):
#             data = [ord(x) for x in data]
#         data = tuple(data)
#         data = spi.transfer(data)
#         dataout = "".join([chr(x) for x in data])
#         return dataout


import struct
from binascii import hexlify
from umap2.phy.iphy import PhyInterface
from umap2.phy.raspdancer.raspdancer import Raspdancer
    pin_control = 0x11
    revision = 0x12
    function_address = 0x13
    io_pins = 0x14


class USBCTL:
    '''
    USBCTL (r15) register bits
    '''
    hoscsten = 0x80
    vbgate = 0x40
    chipres = 0x20
    pwrdown = 0x10
    connect = 0x08
    sigrwu = 0x04


class PINCTL:
    '''
    PINCTL (r17) register bits
    '''
    setup_data_avail = 0x20  # SUDAVIRQ
    in3_buffer_avail = 0x10  # IN3BAVIRQ
    in2_buffer_avail = 0x08  # IN2BAVIRQ
    out1_data_avail = 0x04  # OUT1DAVIRQ
    out0_data_avail = 0x02  # OUT0DAVIRQ
    in0_buffer_avail = 0x01  # IN0BAVIRQ



# Path: umap2/phy/iphy.py
# class PhyInterface(object):
#     '''
#     This class specifies the API that a physical interface should conform to
#     '''
# 
#     def __init__(self, app, name):
#         '''
#         :type app: :class:`~umap2.app.base.Umap2App`
#         :param app: application instance
#         '''
#         self.app = app
#         self.name = name
#         self.logger = logging.getLogger('umap2')
#         self.stop = False
#         self.connected_device = None
# 
#     def connect(self, usb_device):
#         '''
#         Connect a USB device
# 
#         :type usb_device: :class:`~umap2.core.usb_class.USBClass`
#         :param usb_device: USB device class
#         '''
#         self.connected_device = usb_device
# 
#     def disconnect(self):
#         '''
#         Disconnect a device.
#         Once this function returns, the phy doesn't have a reference to the
#         device.
# 
#         :return: the disconnected device (if was connected)
#         '''
#         if self.connected_device:
#             self.info('Disconnected device %s' % self.connected_device.name)
#         else:
#             self.info('Disconnect called when already disconnected')
#         dev = self.connected_device
#         self.connected_device = None
#         return dev
# 
#     def is_connected(self):
#         return self.connected_device is not None
# 
#     def send_on_endpoint(self, ep_num, data):
#         '''
#         Send data on a specific endpoint
# 
#         :param ep_num: number of endpoint
#         :param data: data to send
#         '''
#         raise NotImplementedError('should be implemented in subclass')
# 
#     def stall_ep0(self):
#         '''
#         Stalls control endpoint (0)
#         '''
#         raise NotImplementedError('should be implemented in subclass')
# 
#     def run(self):
#         '''
#         Handle USB requests
#         '''
#         raise NotImplementedError('should be implemented in subclass')
# 
#     def verbose(self, msg, *args, **kwargs):
#         self.logger.verbose('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def debug(self, msg, *args, **kwargs):
#         self.logger.debug('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def info(self, msg, *args, **kwargs):
#         self.logger.info('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def warning(self, msg, *args, **kwargs):
#         self.logger.warning('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def error(self, msg, *args, **kwargs):
#         self.logger.error('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def critical(self, msg, *args, **kwargs):
#         self.logger.critical('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def always(self, msg, *args, **kwargs):
#         self.logger.always('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
# Path: umap2/phy/raspdancer/raspdancer.py
# class Raspdancer:
# 
#     def __init__(self):
#         GPIO.setmode(GPIO.BOARD)
#         # pin15=GPIO22 is linked to MAX3420 -RST
#         GPIO.setup(15, GPIO.OUT)
#         GPIO.output(15,GPIO.LOW)
#         GPIO.output(15,GPIO.HIGH)
#         spi.openSPI(speed=26000000)
# 
#     def __del__(self):
#         spi.closeSPI()
#         GPIO.output(15,GPIO.LOW)
#         GPIO.output(15,GPIO.HIGH)
#         GPIO.cleanup()
# 
#     def transfer(self, data=[]):
#         if isinstance(data,str):
#             data = [ord(x) for x in data]
#         data = tuple(data)
#         data = spi.transfer(data)
#         dataout = "".join([chr(x) for x in data])
#         return dataout


# Path: umap2/phy/raspdancer/raspdancer_phy.py
import struct
from binascii import hexlify
from umap2.phy.iphy import PhyInterface
from umap2.phy.raspdancer.raspdancer import Raspdancer

    pin_control = 0x11
    revision = 0x12
    function_address = 0x13
    io_pins = 0x14


class USBCTL:
    '''
    USBCTL (r15) register bits
    '''
    hoscsten = 0x80
    vbgate = 0x40
    chipres = 0x20
    pwrdown = 0x10
    connect = 0x08
    sigrwu = 0x04


class PINCTL:
    '''
    PINCTL (r17) register bits
    '''
    setup_data_avail = 0x20  # SUDAVIRQ
    in3_buffer_avail = 0x10  # IN3BAVIRQ
    in2_buffer_avail = 0x08  # IN2BAVIRQ
    out1_data_avail = 0x04  # OUT1DAVIRQ
    out0_data_avail = 0x02  # OUT0DAVIRQ
    in0_buffer_avail = 0x01  # IN0BAVIRQ



class RaspdancerPhy(PhyInterface):