From 45f347118254cd3b00bd3e6442e48fdd628c7c7e Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Mon, 17 Nov 2025 17:19:28 -0500 Subject: [PATCH 1/2] Switch registers to enum class --- lib/cc1101/cc1101.cpp | 42 ++++++++++++------------ lib/cc1101/cc1101.hpp | 75 +++++++++++++++++++++---------------------- 2 files changed, 58 insertions(+), 59 deletions(-) diff --git a/lib/cc1101/cc1101.cpp b/lib/cc1101/cc1101.cpp index 2185078..1e373f7 100644 --- a/lib/cc1101/cc1101.cpp +++ b/lib/cc1101/cc1101.cpp @@ -53,41 +53,41 @@ auto Driver::configure(const Frequency carrier) noexcept -> void { break; } - writeRegister(FREQ2, (freq >> 16) & 0xFF); - writeRegister(FREQ1, (freq >> 8) & 0xFF); - writeRegister(FREQ0, (freq & 0xFF)); + writeRegister(Register::FREQ2, (freq >> 16) & 0xFF); + writeRegister(Register::FREQ1, (freq >> 8) & 0xFF); + writeRegister(Register::FREQ0, (freq & 0xFF)); - writeRegister(MDMCFG2, 0x30); // modulation mode ASK/OOK, no sync + writeRegister(Register::MDMCFG2, 0x30); // modulation mode ASK/OOK, no sync // Set data rate (doesn't matter for CW, but set anyway) - writeRegister(MDMCFG4, 0xC8); // Bandwidth ~100 kHz - writeRegister(MDMCFG3, 0x93); // Data rate ~9.6 kBaud + writeRegister(Register::MDMCFG4, 0xC8); // Bandwidth ~100 kHz + writeRegister(Register::MDMCFG3, 0x93); // Data rate ~9.6 kBaud // Disable deviation (CW has no modulation) - writeRegister(DEVIATN, 0x00); + writeRegister(Register::DEVIATN, 0x00); // Calibration settings - writeRegister(MCSM0, 0x18); - writeRegister(FOCCFG, 0x16); - writeRegister(AGCCTRL2, 0x43); + writeRegister(Register::MCSM0, 0x18); + writeRegister(Register::FOCCFG, 0x16); + writeRegister(Register::AGCCTRL2, 0x43); // Frequency synthesizer calibration - writeRegister(FSCAL3, 0xE9); - writeRegister(FSCAL2, 0x2A); - writeRegister(FSCAL1, 0x00); - writeRegister(FSCAL0, 0x1F); + writeRegister(Register::FSCAL3, 0xE9); + writeRegister(Register::FSCAL2, 0x2A); + writeRegister(Register::FSCAL1, 0x00); + writeRegister(Register::FSCAL0, 0x1F); // Test settings for CW - writeRegister(TEST2, 0x81); - writeRegister(TEST1, 0x35); - writeRegister(TEST0, 0x09); + writeRegister(Register::TEST2, 0x81); + writeRegister(Register::TEST1, 0x35); + writeRegister(Register::TEST0, 0x09); // Set output power to maximum (approximately +10 dBm) // PA_TABLE values: 0xC0 = +10dBm, 0x84 = +5dBm, 0x60 = 0dBm - writeRegister(PATABLE, 0xC0); + writeRegister(Register::PATABLE, 0xC0); // Frontend configuration - writeRegister(FREND0, 0x11); + writeRegister(Register::FREND0, 0x11); }; auto Driver::begin(const Direction dir) noexcept -> void { @@ -95,9 +95,9 @@ auto Driver::begin(const Direction dir) noexcept -> void { delay(10); if (dir == Direction::TX) { - writeStrobe(STX); + writeStrobe(Register::STX); } else if (dir == Direction::RX) { - writeStrobe(SRX); + writeStrobe(Register::SRX); } delay(10); }; diff --git a/lib/cc1101/cc1101.hpp b/lib/cc1101/cc1101.hpp index a62d8ec..6595c5e 100644 --- a/lib/cc1101/cc1101.hpp +++ b/lib/cc1101/cc1101.hpp @@ -3,41 +3,40 @@ #include #include "digital.hpp" -namespace cc1101 { - -namespace { - -// CC1101 Register Addresses -constexpr uint8_t IOCFG0 = 0x02; -constexpr uint8_t FREQ2 = 0x0D; -constexpr uint8_t FREQ1 = 0x0E; -constexpr uint8_t FREQ0 = 0x0F; -constexpr uint8_t MDMCFG4 = 0x10; -constexpr uint8_t MDMCFG3 = 0x11; -constexpr uint8_t MDMCFG2 = 0x12; -constexpr uint8_t DEVIATN = 0x15; -constexpr uint8_t MCSM0 = 0x18; -constexpr uint8_t FOCCFG = 0x19; -constexpr uint8_t AGCCTRL2 = 0x17; -constexpr uint8_t FREND0 = 0x22; -constexpr uint8_t FSCAL3 = 0x23; -constexpr uint8_t FSCAL2 = 0x24; -constexpr uint8_t FSCAL1 = 0x25; -constexpr uint8_t FSCAL0 = 0x26; -constexpr uint8_t TEST2 = 0x2C; -constexpr uint8_t TEST1 = 0x2D; -constexpr uint8_t TEST0 = 0x2E; -constexpr uint8_t PATABLE = 0x3E; - -// Command Strobes -constexpr uint8_t SRES = 0x30; -constexpr uint8_t SNOP = 0x3D; -constexpr uint8_t SCAL = 0x33; -constexpr uint8_t SRX = 0x34; -constexpr uint8_t STX = 0x35; -constexpr uint8_t SIDLE = 0x36; - -}; // namespace reg +namespace amber::cc1101 { + +enum class Register : uint8_t { + + // CC1101 Register Addresses + IOCFG0 = 0x02, + FREQ2 = 0x0D, + FREQ1 = 0x0E, + FREQ0 = 0x0F, + MDMCFG4 = 0x10, + MDMCFG3 = 0x11, + MDMCFG2 = 0x12, + DEVIATN = 0x15, + MCSM0 = 0x18, + FOCCFG = 0x19, + AGCCTRL2 = 0x17, + FREND0 = 0x22, + FSCAL3 = 0x23, + FSCAL2 = 0x24, + FSCAL1 = 0x25, + FSCAL0 = 0x26, + TEST2 = 0x2C, + TEST1 = 0x2D, + TEST0 = 0x2E, + PATABLE = 0x3E, + + // Command Strobes + SRES = 0x30, + SNOP = 0x3D, + SCAL = 0x33, + SRX = 0x34, + STX = 0x35, + SIDLE = 0x36, +}; struct Driver { @@ -53,12 +52,12 @@ struct Driver { private: - auto writeStrobe(const uint8_t) noexcept -> void; - auto writeRegister(const uint8_t, const uint8_t) noexcept -> void; + auto writeStrobe(const Register) noexcept -> void; + auto writeRegister(const Register, const uint8_t) noexcept -> void; const SPIClass& _spi; const pin::DigitalInput& _miso; pin::DigitalOutput& _cs; }; -} // namespace cc1101 +} // namespace amber::cc1101 From 57bbe7c601f9cab9645e66c529cb742eeb45f80c Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Mon, 17 Nov 2025 17:21:27 -0500 Subject: [PATCH 2/2] Add test mode configuration --- lib/cc1101/cc1101.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cc1101/cc1101.hpp b/lib/cc1101/cc1101.hpp index 6595c5e..5f25735 100644 --- a/lib/cc1101/cc1101.hpp +++ b/lib/cc1101/cc1101.hpp @@ -42,6 +42,7 @@ struct Driver { enum class Frequency : uint8_t { MHZ_433, MHZ_915 }; enum class Direction : uint8_t { TX, RX }; + enum class TestMode : uint8_t { UNMOD, MOD }; Driver(const SPIClass&, const pin::DigitalInput&, pin::DigitalOutput&); ~Driver() = default;