Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions lib/cc1101/cc1101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,51 +53,51 @@ 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 {
writeStrobe(SCAL);
delay(10);

if (dir == Direction::TX) {
writeStrobe(STX);
writeStrobe(Register::STX);
} else if (dir == Direction::RX) {
writeStrobe(SRX);
writeStrobe(Register::SRX);
}
delay(10);
};
Expand Down
70 changes: 35 additions & 35 deletions lib/cc1101/cc1101.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@
#include <SPI.h>
#include "digital.hpp"

namespace cc1101 {
namespace amber::cc1101 {

namespace {
enum class Register : uint8_t {

// 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;
// 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
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
// Command Strobes
SRES = 0x30,
SNOP = 0x3D,
SCAL = 0x33,
SRX = 0x34,
STX = 0x35,
SIDLE = 0x36,
};

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;
Expand All @@ -53,12 +53,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