コード例 #1
0
def setup_spi():
    logger.debug("SPI setup")
    spi = SpiDev()
    spi.open(bus=0, device=0)
    spi.max_speed_hz = 1000000
    spi.bits_per_word = 8
    spi.loop = False
    spi.mode = 3
    spi.no_cs = True
    return spi
コード例 #2
0
def read_touch_screen(channel):
    """Read the HackPack touchscreen coordinates."""
    spi = SpiDev()
    spi.open(1, 0)
    spi.no_cs = True
    spi.max_speed_hz = 2000000

    # Manual chip select
    GPIO.output(CS_TOUCH, 1)
    GPIO.output(CS_TOUCH, 0)
    responseData = spi.xfer([channel, 0, 0])
    GPIO.output(CS_TOUCH, 1)
    spi.close()
    return (responseData[1] << 5) | (responseData[2] >> 3)