86
86
_REG_FRF_LSB = const (0x09 )
87
87
_REG_VERSION = const (0x10 )
88
88
_REG_PA_LEVEL = const (0x11 )
89
+ _REG_OCP = const (0x13 )
89
90
_REG_RX_BW = const (0x19 )
90
91
_REG_AFC_BW = const (0x1A )
91
92
_REG_RSSI_VALUE = const (0x24 )
110
111
_TEST_PA1_BOOST = const (0x5D )
111
112
_TEST_PA2_NORMAL = const (0x70 )
112
113
_TEST_PA2_BOOST = const (0x7C )
114
+ _OCP_NORMAL = const (0x1A )
115
+ _OCP_HIGH_POWER = const (0x0F )
113
116
114
117
# The crystal oscillator frequency and frequency synthesizer step size.
115
118
# See the datasheet for details of this calculation.
@@ -285,6 +288,7 @@ def __set__(self, obj: Optional["RFM69"], val: int) -> None:
285
288
dio_0_mapping = _RegisterBits (_REG_DIO_MAPPING1 , offset = 6 , bits = 2 )
286
289
287
290
# pylint: disable=too-many-statements
291
+ # pylint: disable=too-many-arguments
288
292
def __init__ ( # pylint: disable=invalid-name
289
293
self ,
290
294
spi : SPI ,
@@ -316,9 +320,6 @@ def __init__( # pylint: disable=invalid-name
316
320
self ._write_u8 (_REG_FIFO_THRESH , 0b10001111 )
317
321
# Configure low beta off.
318
322
self ._write_u8 (_REG_TEST_DAGC , 0x30 )
319
- # Disable boost.
320
- self ._write_u8 (_REG_TEST_PA1 , _TEST_PA1_NORMAL )
321
- self ._write_u8 (_REG_TEST_PA2 , _TEST_PA2_NORMAL )
322
323
# Set the syncronization word.
323
324
self .sync_word = sync_word
324
325
self .preamble_length = preamble_length # Set the preamble length.
@@ -448,16 +449,17 @@ def reset(self) -> None:
448
449
self ._reset .value = False
449
450
time .sleep (0.005 ) # 5 ms
450
451
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 )
452
+ def disable_boost (self ) -> None :
453
+ """Disable preamp boost."""
454
+ if self .high_power :
455
+ self ._write_u8 (_REG_TEST_PA1 , _TEST_PA1_NORMAL )
456
+ self ._write_u8 (_REG_TEST_PA2 , _TEST_PA2_NORMAL )
457
+ self ._write_u8 (_REG_OCP , _OCP_NORMAL )
456
458
457
459
def idle (self ) -> None :
458
460
"""Enter idle standby mode (switching off high power amplifiers if necessary)."""
459
461
# Like RadioHead library, turn off high power boost if enabled.
460
- self .set_boost ( _TEST_PA1_NORMAL )
462
+ self .disable_boost ( )
461
463
self .operation_mode = STANDBY_MODE
462
464
463
465
def sleep (self ) -> None :
@@ -469,7 +471,7 @@ def listen(self) -> None:
469
471
and retrieve packets as they're available.
470
472
"""
471
473
# Like RadioHead library, turn off high power boost if enabled.
472
- self .set_boost ( _TEST_PA1_NORMAL )
474
+ self .disable_boost ( )
473
475
# Enable payload ready interrupt for D0 line.
474
476
self .dio_0_mapping = 0b01
475
477
# Enter RX mode (will clear FIFO!).
@@ -480,8 +482,11 @@ def transmit(self) -> None:
480
482
entering transmit mode and more. For generating and transmitting a packet of data use
481
483
:py:func:`send` instead.
482
484
"""
483
- # Like RadioHead library, turn on high power boost if enabled.
484
- self .set_boost (_TEST_PA1_BOOST )
485
+ # Like RadioHead library, turn on high power boost if needed.
486
+ if self .high_power and (self ._tx_power >= 18 ):
487
+ self ._write_u8 (_REG_TEST_PA1 , _TEST_PA1_BOOST )
488
+ self ._write_u8 (_REG_TEST_PA2 , _TEST_PA2_BOOST )
489
+ self ._write_u8 (_REG_OCP , _OCP_HIGH_POWER )
485
490
# Enable packet sent interrupt for D0 line.
486
491
self .dio_0_mapping = 0b00
487
492
# Enter TX mode (will clear FIFO!).
@@ -653,10 +658,10 @@ def tx_power(self) -> int:
653
658
if not pa0 and pa1 and not pa2 :
654
659
# -2 to 13 dBm range
655
660
return - 18 + current_output_power
656
- if not pa0 and pa1 and pa2 and not self .high_power :
661
+ if not pa0 and pa1 and pa2 and self .high_power and self . _tx_power < 18 :
657
662
# 2 to 17 dBm range
658
663
return - 14 + current_output_power
659
- if not pa0 and pa1 and pa2 and self .high_power :
664
+ if not pa0 and pa1 and pa2 and self .high_power and self . _tx_power >= 18 :
660
665
# 5 to 20 dBm range
661
666
return - 11 + current_output_power
662
667
raise RuntimeError ("Power amps state unknown!" )
0 commit comments