本文整理匯總了Python中pyb.SPI屬性的典型用法代碼示例。如果您正苦於以下問題:Python pyb.SPI屬性的具體用法?Python pyb.SPI怎麽用?Python pyb.SPI使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pyb
的用法示例。
在下文中一共展示了pyb.SPI屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def __init__(self, spi_bus=1, led_count=1, intensity=1):
"""
Params:
* spi_bus = SPI bus ID (1 or 2)
* led_count = count of LEDs
* intensity = light intensity (float up to 1)
"""
self.led_count = led_count
self.intensity = intensity
# prepare SPI data buffer (4 bytes for each color)
self.buf_length = self.led_count * 3 * 4
self.buf = bytearray(self.buf_length)
# SPI init
self.spi = pyb.SPI(spi_bus, pyb.SPI.MASTER, baudrate=3200000, polarity=0, phase=1)
# turn LEDs off
self.show([])
示例2: _power_off
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def _power_off(self): # turn of power and all signals
self.Pin_RESET.low()
self.Pin_PANEL_ON.low()
self.Pin_BORDER.low()
self.spi.deinit()
self.Pin_SCK.init(mode = pyb.Pin.OUT_PP)
self.Pin_SCK.low()
self.Pin_MOSI.init(mode = pyb.Pin.OUT_PP)
self.Pin_MOSI.low()
# ensure SPI MOSI and CLOCK are Low before CS Low
self.Pin_EPD_CS.low()
# pulse discharge pin
self.Pin_DISCHARGE.high()
pyb.delay(150)
self.Pin_DISCHARGE.low()
# USER INTERFACE
# clear_screen() calls clear_data() and, if show, EPD_clear()
# showdata() called from show()
示例3: _power_off
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def _power_off(self): # turn of power and all signals
self.Pin_PANEL_ON.low()
# self._SPI_send(b'\x00\x00')
self.spi.deinit()
self.Pin_SCK.init(mode = pyb.Pin.OUT_PP)
self.Pin_SCK.low()
self.Pin_MOSI.init(mode = pyb.Pin.OUT_PP)
self.Pin_MOSI.low()
self.Pin_BORDER.low()
# ensure SPI MOSI and CLOCK are Low before CS Low
self.Pin_RESET.low()
self.Pin_EPD_CS.low()
# pulse discharge pin
self.Pin_DISCHARGE.high()
pyb.delay(150)
self.Pin_DISCHARGE.low()
# One frame of data is the number of lines * rows. For example:
# The 2.7” frame of data is 176 lines * 264 dots.
示例4: _setbuf_fixed
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def _setbuf_fixed(self, line: int, fixed_value: int):
index = 0 # odd pixels
buf = ptr8(self.linebuf)
for b in range(BYTES_PER_LINE, 0, -1): # Optimisation: replacing for .. in range made trivial gains.
buf[index] = fixed_value # Optimisation: buffer SPI data
index += 1
# scan line
scan_pos = (LINES_PER_DISPLAY - line - 1) >> 2
scan_shift = (line & 3) << 1
for b in range(BYTES_PER_SCAN):
if scan_pos == b:
buf[index] = 3 << scan_shift
else:
buf[index] = 0
index += 1
for b in range(BYTES_PER_LINE): # Even pixels
buf[index] = fixed_value
index += 1
示例5: cp
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def cp(source, dest):
if dest.endswith('/'): # minimal way to allow
dest = ''.join((dest, source.split('/')[-1])) # cp /sd/file /fc/
with open(source, 'rb') as infile: # Caller should handle any OSError
with open(dest,'wb') as outfile: # e.g file not found
while True:
buf = infile.read(100)
outfile.write(buf)
if len(buf) < 100:
break
# FlashClass
# The flash and epaper deviices use different SPI modes. You must issue objFlash.begin() before attempting to access
# the device, and objFlash.end() afterwards
# All address method arguments are byte addresses. Hence to erase block 100, issue objFlash.sector_erase(100*4096)
# Sectors must be erased (to 0xff) before they can be written. Writing is done in 256 byte pages. The _write() method
# handles paging transparently but does assume target pages are erased.
示例6: __init__
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def __init__(self, pinout, height=32, external_vcc=True, i2c_devid=DEVID):
self.external_vcc = external_vcc
self.height = 32 if height == 32 else 64
self.pages = int(self.height / 8)
self.columns = 128
# Infer interface type from entries in pinout{}
if 'dc' in pinout:
# SPI
rate = 16 * 1024 * 1024
self.spi = pyb.SPI(2, pyb.SPI.MASTER, baudrate=rate, polarity=1, phase=0) # SCK: Y6: MOSI: Y8
self.dc = pyb.Pin(pinout['dc'], pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
self.res = pyb.Pin(pinout['res'], pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
self.offset = 0
else:
# Infer bus number from pin
if pinout['sda'] == 'X9':
self.i2c = pyb.I2C(1)
else:
self.i2c = pyb.I2C(2)
self.i2c.init(pyb.I2C.MASTER, baudrate=400000) # 400kHz
self.devid = i2c_devid
# used to reserve an extra byte in the image buffer AND as a way to
# infer the interface type
self.offset = 1
# I2C command buffer
self.cbuffer = bytearray(2)
self.cbuffer[0] = CTL_CMD
示例7: send_buf
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def send_buf(self):
"""
Send buffer over SPI.
"""
self.spi.send(self.buf)
gc.collect()
示例8: begin
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def begin(self): # Baud rates of 50MHz supported by chip
self.pinCS.high()
self.spi = pyb.SPI(self.spi_no, pyb.SPI.MASTER, baudrate = 21000000, polarity = 1, phase = 1, bits = 8)
if not self._available(): # Includes 1mS wakeup delay
raise FlashException("Unsupported flash device")
示例9: __init__
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def __init__(self, spi, rst, ce, dc, light, pwr=None):
self.width = 84
self.height = 48
self.power = self.POWER_DOWN
self.addressing = self.ADDRESSING_HORIZ
self.instr = self.INSTR_BASIC
self.display_mode = self.DISPLAY_BLANK
self.temp_coeff = self.TEMP_COEFF_0
self.bias = self.BIAS_1_11
self.voltage = 3060
# init the SPI bus and pins
spi.init(spi.MASTER, baudrate=328125, bits=8, polarity=0, phase=1, firstbit=spi.MSB)
if "OUT_PP" in dir(rst):
# pyBoard style
rst.init(rst.OUT_PP, rst.PULL_NONE) # Reset line
ce.init(ce.OUT_PP, ce.PULL_NONE) # Chip Enable
dc.init(dc.OUT_PP, dc.PULL_NONE) # Data(1) / Command(0) mode
light.init(light.OUT_PP, light.PULL_NONE)
if pwr:
pwr.init(pwr.OUT_PP, pwr.PULL_NONE)
else:
# WiPy style
rst.init(rst.OUT, None)
ce.init(ce.OUT, None)
dc.init(dc.OUT, None)
light.init(light.OUT, None)
if pwr:
pwr.init(pwr.OUT, None)
self.spi = spi
self.rst = rst
self.ce = ce
self.dc = dc
self.light = light
self.pwr = pwr
self.light_off()
self.power_on()
self.ce.value(1) # set chip to disable (don't listen to input)
self.reset()
self.set_contrast(0xbf)
self.clear()
self.lcd_font = font.FONT6_8()
self.chinese = chinese.CN_UTF8()
示例10: init_card
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import SPI [as 別名]
def init_card(self):
# init CS pin
self.cs.init(self.cs.OUT, value=1)
# init SPI bus; use low data rate for initialisation
self.init_spi(10000000)
# clock card at least 100 cycles with cs high
for i in range(16):
self.spi.write(b'\xff')
# CMD0: init card; should return _R1_IDLE_STATE (allow 5 attempts)
for _ in range(5):
if self.cmd(0, 0, 0x95) == _R1_IDLE_STATE:
break
else:
raise OSError("no SD card")
# CMD8: determine card version
r = self.cmd(8, 0x01aa, 0x87, 4)
if r == _R1_IDLE_STATE:
self.init_card_v2()
elif r == (_R1_IDLE_STATE | _R1_ILLEGAL_COMMAND):
self.init_card_v1()
else:
raise OSError("couldn't determine SD card version")
# get the number of sectors
# CMD9: response R2 (R1 byte + 16-byte block read)
if self.cmd(9, 0, 0, 0, False) != 0:
raise OSError("no response from SD card")
csd = bytearray(16)
self.readinto(csd)
if csd[0] & 0xc0 == 0x40: # CSD version 2.0
self.sectors = ((csd[8] << 8 | csd[9]) + 1) * 1024
elif csd[0] & 0xc0 == 0x00: # CSD version 1.0 (old, <=2GB)
c_size = csd[6] & 0b11 | csd[7] << 2 | (csd[8] & 0b11000000) << 4
c_size_mult = ((csd[9] & 0b11) << 1) | csd[10] >> 7
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2))
else:
raise OSError("SD card CSD format not supported")
#print('sectors', self.sectors)
# CMD16: set block length to 512 bytes
if self.cmd(16, 512, 0) != 0:
raise OSError("can't set 512 block size")
# set to high data rate now that it's initialised
self.init_spi(1320000)