Skip to content

Commit 45f3471

Browse files
committed
Switch registers to enum class
1 parent 0e6f661 commit 45f3471

2 files changed

Lines changed: 58 additions & 59 deletions

File tree

lib/cc1101/cc1101.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,51 +53,51 @@ auto Driver::configure(const Frequency carrier) noexcept -> void {
5353
break;
5454
}
5555

56-
writeRegister(FREQ2, (freq >> 16) & 0xFF);
57-
writeRegister(FREQ1, (freq >> 8) & 0xFF);
58-
writeRegister(FREQ0, (freq & 0xFF));
56+
writeRegister(Register::FREQ2, (freq >> 16) & 0xFF);
57+
writeRegister(Register::FREQ1, (freq >> 8) & 0xFF);
58+
writeRegister(Register::FREQ0, (freq & 0xFF));
5959

60-
writeRegister(MDMCFG2, 0x30); // modulation mode ASK/OOK, no sync
60+
writeRegister(Register::MDMCFG2, 0x30); // modulation mode ASK/OOK, no sync
6161

6262
// Set data rate (doesn't matter for CW, but set anyway)
63-
writeRegister(MDMCFG4, 0xC8); // Bandwidth ~100 kHz
64-
writeRegister(MDMCFG3, 0x93); // Data rate ~9.6 kBaud
63+
writeRegister(Register::MDMCFG4, 0xC8); // Bandwidth ~100 kHz
64+
writeRegister(Register::MDMCFG3, 0x93); // Data rate ~9.6 kBaud
6565

6666
// Disable deviation (CW has no modulation)
67-
writeRegister(DEVIATN, 0x00);
67+
writeRegister(Register::DEVIATN, 0x00);
6868

6969
// Calibration settings
70-
writeRegister(MCSM0, 0x18);
71-
writeRegister(FOCCFG, 0x16);
72-
writeRegister(AGCCTRL2, 0x43);
70+
writeRegister(Register::MCSM0, 0x18);
71+
writeRegister(Register::FOCCFG, 0x16);
72+
writeRegister(Register::AGCCTRL2, 0x43);
7373

7474
// Frequency synthesizer calibration
75-
writeRegister(FSCAL3, 0xE9);
76-
writeRegister(FSCAL2, 0x2A);
77-
writeRegister(FSCAL1, 0x00);
78-
writeRegister(FSCAL0, 0x1F);
75+
writeRegister(Register::FSCAL3, 0xE9);
76+
writeRegister(Register::FSCAL2, 0x2A);
77+
writeRegister(Register::FSCAL1, 0x00);
78+
writeRegister(Register::FSCAL0, 0x1F);
7979

8080
// Test settings for CW
81-
writeRegister(TEST2, 0x81);
82-
writeRegister(TEST1, 0x35);
83-
writeRegister(TEST0, 0x09);
81+
writeRegister(Register::TEST2, 0x81);
82+
writeRegister(Register::TEST1, 0x35);
83+
writeRegister(Register::TEST0, 0x09);
8484

8585
// Set output power to maximum (approximately +10 dBm)
8686
// PA_TABLE values: 0xC0 = +10dBm, 0x84 = +5dBm, 0x60 = 0dBm
87-
writeRegister(PATABLE, 0xC0);
87+
writeRegister(Register::PATABLE, 0xC0);
8888

8989
// Frontend configuration
90-
writeRegister(FREND0, 0x11);
90+
writeRegister(Register::FREND0, 0x11);
9191
};
9292

9393
auto Driver::begin(const Direction dir) noexcept -> void {
9494
writeStrobe(SCAL);
9595
delay(10);
9696

9797
if (dir == Direction::TX) {
98-
writeStrobe(STX);
98+
writeStrobe(Register::STX);
9999
} else if (dir == Direction::RX) {
100-
writeStrobe(SRX);
100+
writeStrobe(Register::SRX);
101101
}
102102
delay(10);
103103
};

lib/cc1101/cc1101.hpp

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,40 @@
33
#include <SPI.h>
44
#include "digital.hpp"
55

6-
namespace cc1101 {
7-
8-
namespace {
9-
10-
// CC1101 Register Addresses
11-
constexpr uint8_t IOCFG0 = 0x02;
12-
constexpr uint8_t FREQ2 = 0x0D;
13-
constexpr uint8_t FREQ1 = 0x0E;
14-
constexpr uint8_t FREQ0 = 0x0F;
15-
constexpr uint8_t MDMCFG4 = 0x10;
16-
constexpr uint8_t MDMCFG3 = 0x11;
17-
constexpr uint8_t MDMCFG2 = 0x12;
18-
constexpr uint8_t DEVIATN = 0x15;
19-
constexpr uint8_t MCSM0 = 0x18;
20-
constexpr uint8_t FOCCFG = 0x19;
21-
constexpr uint8_t AGCCTRL2 = 0x17;
22-
constexpr uint8_t FREND0 = 0x22;
23-
constexpr uint8_t FSCAL3 = 0x23;
24-
constexpr uint8_t FSCAL2 = 0x24;
25-
constexpr uint8_t FSCAL1 = 0x25;
26-
constexpr uint8_t FSCAL0 = 0x26;
27-
constexpr uint8_t TEST2 = 0x2C;
28-
constexpr uint8_t TEST1 = 0x2D;
29-
constexpr uint8_t TEST0 = 0x2E;
30-
constexpr uint8_t PATABLE = 0x3E;
31-
32-
// Command Strobes
33-
constexpr uint8_t SRES = 0x30;
34-
constexpr uint8_t SNOP = 0x3D;
35-
constexpr uint8_t SCAL = 0x33;
36-
constexpr uint8_t SRX = 0x34;
37-
constexpr uint8_t STX = 0x35;
38-
constexpr uint8_t SIDLE = 0x36;
39-
40-
}; // namespace reg
6+
namespace amber::cc1101 {
7+
8+
enum class Register : uint8_t {
9+
10+
// CC1101 Register Addresses
11+
IOCFG0 = 0x02,
12+
FREQ2 = 0x0D,
13+
FREQ1 = 0x0E,
14+
FREQ0 = 0x0F,
15+
MDMCFG4 = 0x10,
16+
MDMCFG3 = 0x11,
17+
MDMCFG2 = 0x12,
18+
DEVIATN = 0x15,
19+
MCSM0 = 0x18,
20+
FOCCFG = 0x19,
21+
AGCCTRL2 = 0x17,
22+
FREND0 = 0x22,
23+
FSCAL3 = 0x23,
24+
FSCAL2 = 0x24,
25+
FSCAL1 = 0x25,
26+
FSCAL0 = 0x26,
27+
TEST2 = 0x2C,
28+
TEST1 = 0x2D,
29+
TEST0 = 0x2E,
30+
PATABLE = 0x3E,
31+
32+
// Command Strobes
33+
SRES = 0x30,
34+
SNOP = 0x3D,
35+
SCAL = 0x33,
36+
SRX = 0x34,
37+
STX = 0x35,
38+
SIDLE = 0x36,
39+
};
4140

4241
struct Driver {
4342

@@ -53,12 +52,12 @@ struct Driver {
5352

5453
private:
5554

56-
auto writeStrobe(const uint8_t) noexcept -> void;
57-
auto writeRegister(const uint8_t, const uint8_t) noexcept -> void;
55+
auto writeStrobe(const Register) noexcept -> void;
56+
auto writeRegister(const Register, const uint8_t) noexcept -> void;
5857

5958
const SPIClass& _spi;
6059
const pin::DigitalInput& _miso;
6160
pin::DigitalOutput& _cs;
6261
};
6362

64-
} // namespace cc1101
63+
} // namespace amber::cc1101

0 commit comments

Comments
 (0)