本文整理汇总了Python中Adafruit_GPIO.SPI.BitBang方法的典型用法代码示例。如果您正苦于以下问题:Python SPI.BitBang方法的具体用法?Python SPI.BitBang怎么用?Python SPI.BitBang使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_GPIO.SPI
的用法示例。
在下文中一共展示了SPI.BitBang方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mode_0_read
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_mode_0_read(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
gpio.pin_read[3] = [0, 0, 0, 1, 1, 1, 1, 1]
result = device.read(1)
# Verify clock
self.assertListEqual(gpio.pin_written[1], [0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0])
# Verify MOSI
self.assertNotIn(2, gpio.pin_written)
# Verify MISO
self.assertNotIn(3, gpio.pin_written)
# Verify SS
self.assertListEqual(gpio.pin_written[4], [1, 0, 1])
# Verify result
self.assertEqual(result, bytearray([0x1F]))
示例2: test_read_multiple_bytes
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_read_multiple_bytes(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
gpio.pin_read[3] = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1]
result = device.read(3)
# Verify clock
self.assertListEqual(gpio.pin_written[1], [0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0])
# Verify MOSI
self.assertNotIn(2, gpio.pin_written)
# Verify MISO
self.assertNotIn(3, gpio.pin_written)
# Verify SS
self.assertListEqual(gpio.pin_written[4], [1, 0, 1])
# Verify result
self.assertEqual(result, bytearray([0x1F, 0xF8, 0x1F]))
示例3: test_write_multiple_bytes
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_write_multiple_bytes(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
device.write([0x1F, 0xF8, 0x1F])
# Verify clock
self.assertListEqual(gpio.pin_written[1], [0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0])
# Verify MOSI
self.assertListEqual(gpio.pin_written[2], [0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1])
# Verify MISO
self.assertNotIn(3, gpio.pin_written)
# Verify SS
self.assertListEqual(gpio.pin_written[4], [1, 0, 1])
示例4: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def __init__(self, dc, rst, sclk=None, din=None, cs=None, gpio=None, spi=None):
self._sclk = sclk
self._din = din
self._dc = dc
self._cs = cs
self._rst = rst
self._gpio = gpio
self._spi = spi
# Default to detecting platform GPIO.
if self._gpio is None:
self._gpio = GPIO.get_platform_gpio()
if self._rst is not None:
self._gpio.setup(self._rst, GPIO.OUT)
# Default to bit bang SPI.
if self._spi is None:
self._spi = SPI.BitBang(self._gpio, self._sclk, self._din, None, self._cs)
# Set pin outputs.
self._gpio.setup(self._dc, GPIO.OUT)
# Initialize buffer to Adafruit logo.
self._buffer = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0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 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
示例5: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def __init__(self, clk=None, cs=None, do=None, spi=None, gpio=None):
"""Initialize MAX31855 device with software SPI on the specified CLK,
CS, and DO pins. Alternatively can specify hardware SPI by sending an
Adafruit_GPIO.SPI.SpiDev device in the spi parameter.
"""
self._logger = logging.getLogger('Adafruit_MAX31855.MAX31855')
self._spi = None
# Handle hardware SPI
if spi is not None:
self._logger.debug('Using hardware SPI')
self._spi = spi
elif clk is not None and cs is not None and do is not None:
self._logger.debug('Using software SPI')
# Default to platform GPIO if not provided.
if gpio is None:
gpio = GPIO.get_platform_gpio()
self._spi = SPI.BitBang(gpio, clk, None, do, cs)
else:
raise ValueError('Must specify either spi for for hardware SPI or clk, cs, and do for softwrare SPI!')
self._spi.set_clock_hz(5000000)
self._spi.set_mode(0)
self._spi.set_bit_order(SPI.MSBFIRST)
示例6: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def __init__(self, count, clk=None, do=None, spi=None, gpio=None):
"""Initialize set of WS2801/SPI-like addressable RGB LEDs. Must
specify the count of pixels, and either an explicit clk (clokc) and do
(data output) line for software SPI or a spi instance for hardware SPI.
"""
self._spi = None
if spi:
# Handle hardware SPI.
self._spi = spi
elif clk and do:
# Handle software SPI.
# Default to platform GPIO if not provided.
if not gpio:
import Adafruit_GPIO as GPIO
gpio = GPIO.get_platform_gpio()
self._spi = SPI.BitBang(gpio, clk, do, None, None)
else:
raise ValueError('Must specify either spi for for hardware SPI or clk, and do for software SPI!')
# Setup SPI interface with up to 20mhz speed.
self._spi.set_clock_hz(1000000)
self._spi.set_mode(0)
self._spi.set_bit_order(SPI.MSBFIRST)
# Setup buffer for pixel RGB data.
self._count = count
self._pixels = [0]*(count*3)
示例7: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def __init__(self, clk=None, cs=None, miso=None, mosi=None, spi=None, gpio=None):
"""Initialize MAX31855 device with software SPI on the specified CLK,
CS, and DO pins. Alternatively can specify hardware SPI by sending an
Adafruit_GPIO.SPI.SpiDev device in the spi parameter.
"""
self._spi = None
# Handle hardware SPI
if spi is not None:
self._spi = spi
elif clk is not None and cs is not None and miso is not None and mosi is not None:
# Default to platform GPIO if not provided.
if gpio is None:
gpio = GPIO.get_platform_gpio()
self._spi = SPI.BitBang(gpio, clk, mosi, miso, cs)
else:
raise ValueError('Must specify either spi for for hardware SPI or clk, cs, miso, and mosi for software SPI!')
self._spi.set_clock_hz(1000000)
self._spi.set_mode(0)
self._spi.set_bit_order(SPI.MSBFIRST)
示例8: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def __init__(self, clk=None, cs=None, miso=None, mosi=None, spi=None, gpio=None):
"""Initialize MAX31855 device with software SPI on the specified CLK,
CS, and DO pins. Alternatively can specify hardware SPI by sending an
Adafruit_GPIO.SPI.SpiDev device in the spi parameter.
"""
self._spi = None
# Handle hardware SPI
if spi is not None:
self._spi = spi
elif clk is not None and cs is not None and miso is not None and mosi is not None:
# Default to platform GPIO if not provided.
if gpio is None:
gpio = GPIO.get_platform_gpio()
self._spi = SPI.BitBang(gpio, clk, mosi, miso, cs)
else:
raise ValueError('Must specify either spi for for hardware SPI or clk, cs, miso, and mosi for softwrare SPI!')
#self._spi.set_clock_hz(800000)
#self._spi.set_clock_hz(1000000)
self._spi.set_clock_hz(1000000)
self._spi.set_mode(0)
self._spi.set_bit_order(SPI.MSBFIRST)
示例9: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def __init__(self, count, clk=None, do=None, spi=None, gpio=None):
"""Initialize set of WS2801/SPI-like addressable RGB LEDs. Must
specify the count of pixels, and either an explicit clk (clokc) and do
(data output) line for software SPI or a spi instance for hardware SPI.
"""
self._spi = None
if spi is not None:
# Handle hardware SPI.
self._spi = spi
elif clk is not None and do is not None:
# Handle software SPI.
# Default to platform GPIO if not provided.
if gpio is None:
import Adafruit_GPIO as GPIO
gpio = GPIO.get_platform_gpio()
self._spi = SPI.BitBang(gpio, clk, do, None, None)
else:
raise ValueError('Must specify either spi for for hardware SPI or clk, and do for softwrare SPI!')
# Setup SPI interface with up to 20mhz speed.
self._spi.set_clock_hz(1000000)
self._spi.set_mode(0)
self._spi.set_bit_order(SPI.MSBFIRST)
# Setup buffer for pixel RGB data.
self._count = count
self._pixels = [0]*(count*3)
示例10: test_pin_modes_set_correctly
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_pin_modes_set_correctly(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
self.assertDictEqual(gpio.pin_mode, { 1: GPIO.OUT,
2: GPIO.OUT,
3: GPIO.IN,
4: GPIO.OUT })
示例11: test_ss_set_high_after_initialization
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_ss_set_high_after_initialization(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
self.assertListEqual(gpio.pin_written[4], [1])
示例12: test_mode_0_write
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_mode_0_write(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
device.write([0x1F])
# Verify clock
self.assertListEqual(gpio.pin_written[1], [0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0])
# Verify MOSI
self.assertListEqual(gpio.pin_written[2], [0, 0, 0, 1, 1, 1, 1, 1])
# Verify MISO
self.assertNotIn(3, gpio.pin_written)
# Verify SS
self.assertListEqual(gpio.pin_written[4], [1, 0, 1])
示例13: test_write_assert_deassert_ss_false
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_write_assert_deassert_ss_false(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
device.write([0x1F], assert_ss=False, deassert_ss=False)
self.assertListEqual(gpio.pin_written[4], [1])
示例14: test_write_lsbfirst
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_write_lsbfirst(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
device.set_bit_order(SPI.LSBFIRST)
device.write([0x1F])
self.assertListEqual(gpio.pin_written[2], [1, 1, 1, 1, 1, 0, 0, 0])
示例15: test_invalid_bit_order_fails
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_invalid_bit_order_fails(self):
gpio = MockGPIO()
device = SPI.BitBang(gpio, 1, 2, 3, 4)
self.assertRaises(ValueError, device.set_bit_order, -1)
self.assertRaises(ValueError, device.set_bit_order, 2)