From 619fa30c9482f9e36d08580cdea32922fffffbbe Mon Sep 17 00:00:00 2001 From: Max Holliday Date: Mon, 8 Jul 2024 20:01:02 -0700 Subject: [PATCH 1/2] lora-sx126x: Change to class-level memoryview for _cmd buf. Signed-off-by: Max Holliday --- micropython/lora/lora-sx126x/lora/sx126x.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/micropython/lora/lora-sx126x/lora/sx126x.py b/micropython/lora/lora-sx126x/lora/sx126x.py index eeb3bffb7..4f7af1978 100644 --- a/micropython/lora/lora-sx126x/lora/sx126x.py +++ b/micropython/lora/lora-sx126x/lora/sx126x.py @@ -152,7 +152,8 @@ def __init__( dio3_tcxo_start_time_us if dio3_tcxo_millivolts else 0 ) - self._buf = bytearray(9) # shared buffer for commands + self._buf = bytearray(9) # shared buffer for commands, access through _buf_view + self._buf_view = memoryview(self._buf) # These settings are kept in the object (as can't read them back from the modem) self._output_power = 14 @@ -704,11 +705,11 @@ def _cmd(self, fmt, *write_args, n_read=0, write_buf=None, read_buf=None): # have happened well before _cmd() is called again. self._wait_not_busy(self._busy_timeout) - # Pack write_args into _buf and wrap a memoryview of the correct length around it + # Pack write_args into slice of _buf_view memoryview of correct length wrlen = struct.calcsize(fmt) - assert n_read + wrlen <= len(self._buf) # if this fails, make _buf bigger! - struct.pack_into(fmt, self._buf, 0, *write_args) - buf = memoryview(self._buf)[: (wrlen + n_read)] + assert n_read + wrlen <= len(self._buf_view) # if this fails, make _buf bigger! + struct.pack_into(fmt, self._buf_view, 0, *write_args) + buf = self._buf_view[: (wrlen + n_read)] if _DEBUG: print(">>> {}".format(buf[:wrlen].hex())) @@ -723,7 +724,7 @@ def _cmd(self, fmt, *write_args, n_read=0, write_buf=None, read_buf=None): self._cs(1) if n_read > 0: - res = memoryview(buf)[wrlen : (wrlen + n_read)] # noqa: E203 + res = self._buf_view[wrlen : (wrlen + n_read)] # noqa: E203 if _DEBUG: print("<<< {}".format(res.hex())) return res From 4c8163a26241d63f8aa4244e15168e63b7ccc35d Mon Sep 17 00:00:00 2001 From: Max Holliday Date: Fri, 12 Jul 2024 14:48:25 -0700 Subject: [PATCH 2/2] lora-sx126x: Remove separate _buf object. Signed-off-by: Max Holliday --- micropython/lora/lora-sx126x/lora/sx126x.py | 3 +-- micropython/lora/lora-sx126x/manifest.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/micropython/lora/lora-sx126x/lora/sx126x.py b/micropython/lora/lora-sx126x/lora/sx126x.py index 4f7af1978..77052c97c 100644 --- a/micropython/lora/lora-sx126x/lora/sx126x.py +++ b/micropython/lora/lora-sx126x/lora/sx126x.py @@ -152,8 +152,7 @@ def __init__( dio3_tcxo_start_time_us if dio3_tcxo_millivolts else 0 ) - self._buf = bytearray(9) # shared buffer for commands, access through _buf_view - self._buf_view = memoryview(self._buf) + self._buf_view = memoryview(bytearray(9)) # shared buffer for commands # These settings are kept in the object (as can't read them back from the modem) self._output_power = 14 diff --git a/micropython/lora/lora-sx126x/manifest.py b/micropython/lora/lora-sx126x/manifest.py index 177877091..785a975aa 100644 --- a/micropython/lora/lora-sx126x/manifest.py +++ b/micropython/lora/lora-sx126x/manifest.py @@ -1,3 +1,3 @@ -metadata(version="0.1.2") +metadata(version="0.1.3") require("lora") package("lora")