mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
scripts/libraries: Update rpc_spi_master to use the machine module.
This commit is contained in:
parent
ad45a9f8cb
commit
1ec77498ad
@ -547,24 +547,22 @@ class rpc_spi_master(rpc_master):
|
||||
def __init__(
|
||||
self, cs_pin="P3", freq=1000000, clk_polarity=1, clk_phase=0, spi_bus=2
|
||||
): # private
|
||||
import pyb
|
||||
self.__pin = pyb.Pin(cs_pin, pyb.Pin.OUT_PP)
|
||||
self.__pin = machine.Pin(cs_pin, machine.Pin.OUT)
|
||||
self.__freq = freq
|
||||
self.__polarity = clk_polarity
|
||||
self.__clk_phase = clk_phase
|
||||
self.__spi = pyb.SPI(spi_bus)
|
||||
self.__spi = machine.SPI(spi_bus)
|
||||
rpc_master.__init__(self)
|
||||
self._stream_writer_queue_depth_max = 1
|
||||
|
||||
def get_bytes(self, buff, timeout_ms): # protected
|
||||
import pyb
|
||||
self.__pin.value(False)
|
||||
time.sleep_us(100) # Give slave time to get ready.
|
||||
self.__spi.init(
|
||||
pyb.SPI.MASTER, self.__freq, polarity=self.__polarity, phase=self.__clk_phase
|
||||
baudrate=self.__freq, polarity=self.__polarity, phase=self.__clk_phase
|
||||
)
|
||||
try:
|
||||
self.__spi.send_recv(buff, buff, timeout=timeout_ms) # SPI.recv() is broken.
|
||||
self.__spi.write_readinto(buff, buff) # SPI.readinto() is broken.
|
||||
except OSError:
|
||||
buff = None
|
||||
self.__spi.deinit()
|
||||
@ -574,14 +572,13 @@ class rpc_spi_master(rpc_master):
|
||||
return buff
|
||||
|
||||
def put_bytes(self, data, timeout_ms): # protected
|
||||
import pyb
|
||||
self.__pin.value(False)
|
||||
time.sleep_us(100) # Give slave time to get ready.
|
||||
self.__spi.init(
|
||||
pyb.SPI.MASTER, self.__freq, polarity=self.__polarity, phase=self.__clk_phase
|
||||
baudrate=self.__freq, polarity=self.__polarity, phase=self.__clk_phase
|
||||
)
|
||||
try:
|
||||
self.__spi.send(data, timeout=timeout_ms)
|
||||
self.__spi.write(data)
|
||||
except OSError:
|
||||
pass
|
||||
self.__spi.deinit()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user