Skip to content

Commit 58003e2

Browse files
committed
fixup high power enable/disable
1 parent 864012e commit 58003e2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

adafruit_rfm69.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
_REG_FRF_LSB = const(0x09)
8787
_REG_VERSION = const(0x10)
8888
_REG_PA_LEVEL = const(0x11)
89+
_REG_OCP = const(0x13)
8990
_REG_RX_BW = const(0x19)
9091
_REG_AFC_BW = const(0x1A)
9192
_REG_RSSI_VALUE = const(0x24)
@@ -110,6 +111,8 @@
110111
_TEST_PA1_BOOST = const(0x5D)
111112
_TEST_PA2_NORMAL = const(0x70)
112113
_TEST_PA2_BOOST = const(0x7C)
114+
_OCP_NORMAL = const(0x1A)
115+
_OCP_HIGH_POWER = const(0x0F)
113116

114117
# The crystal oscillator frequency and frequency synthesizer step size.
115118
# See the datasheet for details of this calculation.
@@ -285,6 +288,7 @@ def __set__(self, obj: Optional["RFM69"], val: int) -> None:
285288
dio_0_mapping = _RegisterBits(_REG_DIO_MAPPING1, offset=6, bits=2)
286289

287290
# pylint: disable=too-many-statements
291+
# pylint: disable=too-many-arguments
288292
def __init__( # pylint: disable=invalid-name
289293
self,
290294
spi: SPI,
@@ -448,16 +452,17 @@ def reset(self) -> None:
448452
self._reset.value = False
449453
time.sleep(0.005) # 5 ms
450454

451-
def set_boost(self, setting: int) -> None:
452-
"""Set preamp boost if needed."""
453-
if self._tx_power >= 18:
454-
self._write_u8(_REG_TEST_PA1, setting)
455-
self._write_u8(_REG_TEST_PA2, setting)
455+
def disable_boost(self) -> None:
456+
"""Disable preamp boost."""
457+
if self.high_power:
458+
self._write_u8(_REG_TEST_PA1, _TEST_PA1_NORMAL)
459+
self._write_u8(_REG_TEST_PA2, _TEST_PA2_NORMAL)
460+
self._write_u8(_REG_OCP, _OCP_NORMAL)
456461

457462
def idle(self) -> None:
458463
"""Enter idle standby mode (switching off high power amplifiers if necessary)."""
459464
# Like RadioHead library, turn off high power boost if enabled.
460-
self.set_boost(_TEST_PA1_NORMAL)
465+
self.disable_boost()
461466
self.operation_mode = STANDBY_MODE
462467

463468
def sleep(self) -> None:
@@ -469,7 +474,7 @@ def listen(self) -> None:
469474
and retrieve packets as they're available.
470475
"""
471476
# Like RadioHead library, turn off high power boost if enabled.
472-
self.set_boost(_TEST_PA1_NORMAL)
477+
self.disable_boost()
473478
# Enable payload ready interrupt for D0 line.
474479
self.dio_0_mapping = 0b01
475480
# Enter RX mode (will clear FIFO!).
@@ -480,8 +485,11 @@ def transmit(self) -> None:
480485
entering transmit mode and more. For generating and transmitting a packet of data use
481486
:py:func:`send` instead.
482487
"""
483-
# Like RadioHead library, turn on high power boost if enabled.
484-
self.set_boost(_TEST_PA1_BOOST)
488+
# Like RadioHead library, turn on high power boost if needed.
489+
if self.high_power and (self._tx_power >= 18):
490+
self._write_u8(_REG_TEST_PA1, _TEST_PA1_BOOST)
491+
self._write_u8(_REG_TEST_PA2, _TEST_PA2_BOOST)
492+
self._write_u8(_REG_OCP, _OCP_HIGH_POWER)
485493
# Enable packet sent interrupt for D0 line.
486494
self.dio_0_mapping = 0b00
487495
# Enter TX mode (will clear FIFO!).

0 commit comments

Comments
 (0)