Browse Source

fix default config & _set_power_amplifier_setting_index: no longer set FREND0.LODIV_BUF_CURRENT_TX to 0 (cc1101's default: 1)

Fabian Peter Hammerle 3 years ago
parent
commit
feca9fb7fb
4 changed files with 51 additions and 3 deletions
  1. 1 1
      .github/workflows/python.yml
  2. 3 0
      CHANGELOG.md
  3. 3 2
      cc1101/__init__.py
  4. 44 0
      tests/config/test_0x22_frend0.py

+ 1 - 1
.github/workflows/python.yml

@@ -50,7 +50,7 @@ jobs:
       env:
         PYTHON_VERSION: ${{ matrix.python-version }}
     - run: pipenv graph
-    - run: pipenv run pytest --cov=cc1101 --cov-report=term-missing --cov-fail-under=89
+    - run: pipenv run pytest --cov=cc1101 --cov-report=term-missing --cov-fail-under=90
     - run: pipenv run pylint --load-plugins=pylint_import_requirements cc1101
     # https://github.com/PyCQA/pylint/issues/352
     - run: pipenv run pylint tests/*

+ 3 - 0
CHANGELOG.md

@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Fixed
+- default config via private/unstable method `_set_power_amplifier_setting_index`:
+  no longer set `FREND0.LODIV_BUF_CURRENT_TX` to `0` (default: `1`)
 
 ## [2.6.1] - 2021-01-16
 ### Fixed

+ 3 - 2
cc1101/__init__.py

@@ -472,9 +472,9 @@ class CC1101:
         > shall be programmed to index 0 and 1 respectively.
         """
         frend0 = self._read_single_byte(ConfigurationRegisterAddress.FREND0)
-        frend0 &= 0b000
+        frend0 &= 0b11111000
         frend0 |= setting_index
-        self._write_burst(ConfigurationRegisterAddress.FREND0, [setting_index])
+        self._write_burst(ConfigurationRegisterAddress.FREND0, [frend0])
 
     def _verify_chip(self) -> None:
         partnum = self._read_status_register(StatusRegisterAddress.PARTNUM)
@@ -494,6 +494,7 @@ class CC1101:
             )
 
     def _configure_defaults(self) -> None:
+        # next major/breaking release will probably stick closer to CC1101's defaults
         # 6:4 MOD_FORMAT: OOK (default: 2-FSK)
         self._set_modulation_format(ModulationFormat.ASK_OOK)
         self._set_power_amplifier_setting_index(1)

+ 44 - 0
tests/config/test_0x22_frend0.py

@@ -0,0 +1,44 @@
+# python-cc1101 - Python Library to Transmit RF Signals via C1101 Transceivers
+#
+# Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+import unittest.mock
+
+import pytest
+
+# pylint: disable=protected-access
+
+
+@pytest.mark.parametrize(
+    ("frend0_before", "frend0_after", "setting_index"),
+    [
+        (0b01000, 0b01000, 0),
+        (0b01000, 0b01001, 1),
+        (0b01000, 0b01111, 7),
+        (0b10000, 0b10000, 0),
+        (0b10000, 0b10001, 1),
+        (0b10000, 0b10111, 7),
+    ],
+)
+def test__set_power_amplifier_setting_index(
+    transceiver, frend0_before, frend0_after, setting_index
+):
+    transceiver._spi.xfer.return_value = [15, 15]
+    with unittest.mock.patch.object(
+        transceiver, "_read_single_byte", return_value=frend0_before
+    ):
+        transceiver._set_power_amplifier_setting_index(setting_index)
+    transceiver._spi.xfer.assert_called_once_with([0x22 | 0x40, frend0_after])