Beispiel #1
0
        return self._count is not None

    def __len__(self):
        if self._count is not None:
            return self._count
        else:
            raise TypeError(self.__class__.__name__ + " has no len")


BUTTON = 0
LED = 1
SPI_INTERRUPT = 6
I2C_INTERRUPT = 7


_pi_revision = revision()

if _pi_revision == 0:
    # Not running on the Raspberry Pi, so define no-op pin banks
    pins = PinBank(lambda p: p)
    pi_broadcom_soc = pins
    pi_header_1 = pins

else:
    def by_revision(d):
        return d[_pi_revision]


    # Maps header pin numbers to SoC GPIO numbers
    # See http://elinux.org/RPi_Low-level_peripherals
    #
Beispiel #2
0
import sys
import posix
from fcntl import ioctl
from quick2wire.i2c_ctypes import *
from ctypes import create_string_buffer, sizeof, string_at
from quick2wire.board_revision import revision

assert sys.version_info.major >= 3, __name__ + " is only supported on Python 3"


default_bus = 1 if revision() > 1 else 0

class I2CMaster(object):
    """Performs I2C I/O transactions on an I2C bus.
    
    Transactions are performed by passing one or more I2C I/O messages
    to the transaction method of the I2CMaster.  I2C I/O messages are
    created with the reading, reading_into, writing and writing_bytes
    functions defined in the quick2wire.i2c module.
    
    An I2CMaster acts as a context manager, allowing it to be used in a
    with statement.  The I2CMaster's file descriptor is closed at
    the end of the with statement and the instance cannot be used for
    further I/O.
    
    For example:
    
        from quick2wire.i2c import I2CMaster, writing
        
        with I2CMaster() as i2c:
Beispiel #3
0
    def has_len(self):
        return self._count is not None

    def __len__(self):
        if self._count is not None:
            return self._count
        else:
            raise TypeError(self.__class__.__name__ + " has no len")


BUTTON = 0
LED = 1
SPI_INTERRUPT = 6
I2C_INTERRUPT = 7

_pi_revision = revision()

if _pi_revision == 0:
    # Not running on the Raspberry Pi, so define no-op pin banks
    pins = PinBank(lambda p: p)
    pi_broadcom_soc = pins
    pi_header_1 = pins

else:

    def by_revision(d):
        return d[_pi_revision]

    # Maps header pin numbers to SoC GPIO numbers
    # See http://elinux.org/RPi_Low-level_peripherals
    #
Beispiel #4
0
import sys
from contextlib import closing
import posix
from fcntl import ioctl
from quick2wire.i2c_ctypes import *
from ctypes import create_string_buffer, sizeof, c_int, byref, pointer, addressof, string_at
from quick2wire.board_revision import revision

# assert sys.version_info.major >= 3, __name__ + " is only supported on Python 3"

default_bus = 1 if revision() > 1 else 0


class I2CMaster(object):
    u"""Performs I2C I/O transactions on an I2C bus.
    
    Transactions are performed by passing one or more I2C I/O messages
    to the transaction method of the I2CMaster.  I2C I/O messages are
    created with the reading, reading_into, writing and writing_bytes
    functions defined in the quick2wire.i2c module.
    
    An I2CMaster acts as a context manager, allowing it to be used in a
    with statement.  The I2CMaster's file descriptor is closed at
    the end of the with statement and the instance cannot be used for
    further I/O.
    
    For example:
    
        from quick2wire.i2c import I2CMaster, writing
        
        with I2CMaster() as i2c:
Beispiel #5
0
    10: 15, 
    11: 17, 
    12: 18, 
    13: 21, 
    15: 22, 
    16: 23, 
    18: 24, 
    19: 10, 
    21: 9, 
    22: 25, 
    23: 11, 
    24: 8,
    26: 7
}

if revision() > 1:
    RaspberryPi_HeaderToSOC[3] = 2
    RaspberryPi_HeaderToSOC[5] = 3
    RaspberryPi_HeaderToSOC[13] = 27


RaspberryPi_GPIOToHeader = [11, 12, 13, 15, 16, 18, 22, 7]

def gpio_to_soc(gpio_pin_number):
    if 0 <= gpio_pin_number < 8:
        return header_to_soc(RaspberryPi_GPIOToHeader[gpio_pin_number])
    else:
        raise ValueError(str(gpio_pin_number)+" is not a valid GPIO pin")


def header_to_soc(header_pin_number):