drivers: Replace deprecated Pin.high()/low() methods with .__call__(1/0).
This commit is contained in:
parent
bcf31a3908
commit
1c9ee49756
|
@ -139,23 +139,23 @@ class SSD1306_SPI(SSD1306):
|
||||||
|
|
||||||
def write_cmd(self, cmd):
|
def write_cmd(self, cmd):
|
||||||
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
|
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.dc.low()
|
self.dc(0)
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.write(bytearray([cmd]))
|
self.spi.write(bytearray([cmd]))
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
|
|
||||||
def write_data(self, buf):
|
def write_data(self, buf):
|
||||||
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
|
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.dc.high()
|
self.dc(1)
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.write(buf)
|
self.spi.write(buf)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
|
|
||||||
def poweron(self):
|
def poweron(self):
|
||||||
self.res.high()
|
self.res(1)
|
||||||
time.sleep_ms(1)
|
time.sleep_ms(1)
|
||||||
self.res.low()
|
self.res(0)
|
||||||
time.sleep_ms(10)
|
time.sleep_ms(10)
|
||||||
self.res.high()
|
self.res(1)
|
||||||
|
|
|
@ -66,8 +66,8 @@ class NRF24L01:
|
||||||
ce.init(ce.OUT, value=0)
|
ce.init(ce.OUT, value=0)
|
||||||
|
|
||||||
# reset everything
|
# reset everything
|
||||||
self.ce.low()
|
self.ce(0)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.payload_size = payload_size
|
self.payload_size = payload_size
|
||||||
self.pipe0_read_addr = None
|
self.pipe0_read_addr = None
|
||||||
utime.sleep_ms(5)
|
utime.sleep_ms(5)
|
||||||
|
@ -109,36 +109,36 @@ class NRF24L01:
|
||||||
self.spi.init(master, baudrate=baudrate, polarity=0, phase=0)
|
self.spi.init(master, baudrate=baudrate, polarity=0, phase=0)
|
||||||
|
|
||||||
def reg_read(self, reg):
|
def reg_read(self, reg):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.readinto(self.buf, reg)
|
self.spi.readinto(self.buf, reg)
|
||||||
self.spi.readinto(self.buf)
|
self.spi.readinto(self.buf)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
return self.buf[0]
|
return self.buf[0]
|
||||||
|
|
||||||
def reg_write_bytes(self, reg, buf):
|
def reg_write_bytes(self, reg, buf):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.readinto(self.buf, 0x20 | reg)
|
self.spi.readinto(self.buf, 0x20 | reg)
|
||||||
self.spi.write(buf)
|
self.spi.write(buf)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
return self.buf[0]
|
return self.buf[0]
|
||||||
|
|
||||||
def reg_write(self, reg, value):
|
def reg_write(self, reg, value):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.readinto(self.buf, 0x20 | reg)
|
self.spi.readinto(self.buf, 0x20 | reg)
|
||||||
ret = self.buf[0]
|
ret = self.buf[0]
|
||||||
self.spi.readinto(self.buf, value)
|
self.spi.readinto(self.buf, value)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def flush_rx(self):
|
def flush_rx(self):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.readinto(self.buf, FLUSH_RX)
|
self.spi.readinto(self.buf, FLUSH_RX)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
|
|
||||||
def flush_tx(self):
|
def flush_tx(self):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.readinto(self.buf, FLUSH_TX)
|
self.spi.readinto(self.buf, FLUSH_TX)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
|
|
||||||
# power is one of POWER_x defines; speed is one of SPEED_x defines
|
# power is one of POWER_x defines; speed is one of SPEED_x defines
|
||||||
def set_power_speed(self, power, speed):
|
def set_power_speed(self, power, speed):
|
||||||
|
@ -190,11 +190,11 @@ class NRF24L01:
|
||||||
|
|
||||||
self.flush_rx()
|
self.flush_rx()
|
||||||
self.flush_tx()
|
self.flush_tx()
|
||||||
self.ce.high()
|
self.ce(1)
|
||||||
utime.sleep_us(130)
|
utime.sleep_us(130)
|
||||||
|
|
||||||
def stop_listening(self):
|
def stop_listening(self):
|
||||||
self.ce.low()
|
self.ce(0)
|
||||||
self.flush_tx()
|
self.flush_tx()
|
||||||
self.flush_rx()
|
self.flush_rx()
|
||||||
|
|
||||||
|
@ -204,10 +204,10 @@ class NRF24L01:
|
||||||
|
|
||||||
def recv(self):
|
def recv(self):
|
||||||
# get the data
|
# get the data
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.readinto(self.buf, R_RX_PAYLOAD)
|
self.spi.readinto(self.buf, R_RX_PAYLOAD)
|
||||||
buf = self.spi.read(self.payload_size)
|
buf = self.spi.read(self.payload_size)
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
# clear RX ready flag
|
# clear RX ready flag
|
||||||
self.reg_write(STATUS, RX_DR)
|
self.reg_write(STATUS, RX_DR)
|
||||||
|
|
||||||
|
@ -229,17 +229,17 @@ class NRF24L01:
|
||||||
self.reg_write(CONFIG, (self.reg_read(CONFIG) | PWR_UP) & ~PRIM_RX)
|
self.reg_write(CONFIG, (self.reg_read(CONFIG) | PWR_UP) & ~PRIM_RX)
|
||||||
utime.sleep_us(150)
|
utime.sleep_us(150)
|
||||||
# send the data
|
# send the data
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.readinto(self.buf, W_TX_PAYLOAD)
|
self.spi.readinto(self.buf, W_TX_PAYLOAD)
|
||||||
self.spi.write(buf)
|
self.spi.write(buf)
|
||||||
if len(buf) < self.payload_size:
|
if len(buf) < self.payload_size:
|
||||||
self.spi.write(b'\x00' * (self.payload_size - len(buf))) # pad out data
|
self.spi.write(b'\x00' * (self.payload_size - len(buf))) # pad out data
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
|
|
||||||
# enable the chip so it can send the data
|
# enable the chip so it can send the data
|
||||||
self.ce.high()
|
self.ce(1)
|
||||||
utime.sleep_us(15) # needs to be >10us
|
utime.sleep_us(15) # needs to be >10us
|
||||||
self.ce.low()
|
self.ce(0)
|
||||||
|
|
||||||
# returns None if send still in progress, 1 for success, 2 for fail
|
# returns None if send still in progress, 1 for success, 2 for fail
|
||||||
def send_done(self):
|
def send_done(self):
|
||||||
|
|
|
@ -7,11 +7,11 @@ temperature sensors. It supports multiple devices on the same 1-wire bus.
|
||||||
The following example assumes the ground of your DS18x20 is connected to
|
The following example assumes the ground of your DS18x20 is connected to
|
||||||
Y11, vcc is connected to Y9 and the data pin is connected to Y10.
|
Y11, vcc is connected to Y9 and the data pin is connected to Y10.
|
||||||
|
|
||||||
>>> from pyb import Pin
|
>>> from machine import Pin
|
||||||
>>> gnd = Pin('Y11', Pin.OUT_PP)
|
>>> gnd = Pin('Y11', Pin.OUT_PP)
|
||||||
>>> gnd.low()
|
>>> gnd.off()
|
||||||
>>> vcc = Pin('Y9', Pin.OUT_PP)
|
>>> vcc = Pin('Y9', Pin.OUT_PP)
|
||||||
>>> vcc.high()
|
>>> vcc.on()
|
||||||
|
|
||||||
>>> from ds18x20 import DS18X20
|
>>> from ds18x20 import DS18X20
|
||||||
>>> d = DS18X20(Pin('Y10'))
|
>>> d = DS18X20(Pin('Y10'))
|
||||||
|
|
|
@ -130,7 +130,7 @@ class SDCard:
|
||||||
raise OSError("timeout waiting for v2 card")
|
raise OSError("timeout waiting for v2 card")
|
||||||
|
|
||||||
def cmd(self, cmd, arg, crc, final=0, release=True):
|
def cmd(self, cmd, arg, crc, final=0, release=True):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
|
|
||||||
# create and send the command
|
# create and send the command
|
||||||
buf = self.cmdbuf
|
buf = self.cmdbuf
|
||||||
|
@ -150,12 +150,12 @@ class SDCard:
|
||||||
for j in range(final):
|
for j in range(final):
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
if release:
|
if release:
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# timeout
|
# timeout
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
@ -164,15 +164,15 @@ class SDCard:
|
||||||
self.spi.read(1, 0xff) # ignore stuff byte
|
self.spi.read(1, 0xff) # ignore stuff byte
|
||||||
for _ in range(_CMD_TIMEOUT):
|
for _ in range(_CMD_TIMEOUT):
|
||||||
if self.spi.read(1, 0xff)[0] == 0xff:
|
if self.spi.read(1, 0xff)[0] == 0xff:
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
return 0 # OK
|
return 0 # OK
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
return 1 # timeout
|
return 1 # timeout
|
||||||
|
|
||||||
def readinto(self, buf):
|
def readinto(self, buf):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
|
|
||||||
# read until start byte (0xff)
|
# read until start byte (0xff)
|
||||||
while self.spi.read(1, 0xff)[0] != 0xfe:
|
while self.spi.read(1, 0xff)[0] != 0xfe:
|
||||||
|
@ -186,11 +186,11 @@ class SDCard:
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
|
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
|
|
||||||
def write(self, token, buf):
|
def write(self, token, buf):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
|
|
||||||
# send: start of block, data, checksum
|
# send: start of block, data, checksum
|
||||||
self.spi.read(1, token)
|
self.spi.read(1, token)
|
||||||
|
@ -200,7 +200,7 @@ class SDCard:
|
||||||
|
|
||||||
# check the response
|
# check the response
|
||||||
if (self.spi.read(1, 0xff)[0] & 0x1f) != 0x05:
|
if (self.spi.read(1, 0xff)[0] & 0x1f) != 0x05:
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -208,18 +208,18 @@ class SDCard:
|
||||||
while self.spi.read(1, 0xff)[0] == 0:
|
while self.spi.read(1, 0xff)[0] == 0:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
|
|
||||||
def write_token(self, token):
|
def write_token(self, token):
|
||||||
self.cs.low()
|
self.cs(0)
|
||||||
self.spi.read(1, token)
|
self.spi.read(1, token)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
# wait for write to finish
|
# wait for write to finish
|
||||||
while self.spi.read(1, 0xff)[0] == 0x00:
|
while self.spi.read(1, 0xff)[0] == 0x00:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.cs.high()
|
self.cs(1)
|
||||||
self.spi.write(b'\xff')
|
self.spi.write(b'\xff')
|
||||||
|
|
||||||
def count(self):
|
def count(self):
|
||||||
|
|
Loading…
Reference in New Issue