Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60d1370

Browse files
mahollidpgeorge
authored andcommitted
lora-sx126x: Change to class-level memoryview for _cmd buf.
Currently, the LoRa SX126x driver dynamically creates at least one,sometimes two, memoryview objects with each call to `_cmd`. This commitsimply provides the class with a long-lived memoryview object for `_cmd` toeasily slice as necessary.Unlike the SX127x chips, Semtech unfortunately designed the SX126x modemsto be more command-centric (as opposed to directly setting registers).Given the amount `_cmd` is called during normal device operation, even aminor improvement here should have a decent impact.Basic TX and RX tests pass on hardware.Signed-off-by: Max Holliday <maholli@stanford.edu>
1 parentfbf7e12 commit60d1370

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

‎micropython/lora/lora-sx126x/lora/sx126x.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __init__(
152152
dio3_tcxo_start_time_usifdio3_tcxo_millivoltselse0
153153
)
154154

155-
self._buf=bytearray(9)# shared buffer for commands
155+
self._buf_view=memoryview(bytearray(9))# shared buffer for commands
156156

157157
# These settings are kept in the object (as can't read them back from the modem)
158158
self._output_power=14
@@ -704,11 +704,11 @@ def _cmd(self, fmt, *write_args, n_read=0, write_buf=None, read_buf=None):
704704
# have happened well before _cmd() is called again.
705705
self._wait_not_busy(self._busy_timeout)
706706

707-
# Pack write_args into_buf and wrap amemoryview ofthecorrect length around it
707+
# Pack write_args intoslice of _buf_viewmemoryview of correct length
708708
wrlen=struct.calcsize(fmt)
709-
assertn_read+wrlen<=len(self._buf)# if this fails, make _buf bigger!
710-
struct.pack_into(fmt,self._buf,0,*write_args)
711-
buf=memoryview(self._buf)[: (wrlen+n_read)]
709+
assertn_read+wrlen<=len(self._buf_view)# if this fails, make _buf bigger!
710+
struct.pack_into(fmt,self._buf_view,0,*write_args)
711+
buf=self._buf_view[: (wrlen+n_read)]
712712

713713
if_DEBUG:
714714
print(">>> {}".format(buf[:wrlen].hex()))
@@ -723,7 +723,7 @@ def _cmd(self, fmt, *write_args, n_read=0, write_buf=None, read_buf=None):
723723
self._cs(1)
724724

725725
ifn_read>0:
726-
res=memoryview(buf)[wrlen : (wrlen+n_read)]# noqa: E203
726+
res=self._buf_view[wrlen : (wrlen+n_read)]# noqa: E203
727727
if_DEBUG:
728728
print("<<< {}".format(res.hex()))
729729
returnres
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.1.2")
1+
metadata(version="0.1.3")
22
require("lora")
33
package("lora")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp