Skip to content

Commit

Permalink
Preserve radio mode when updating iq_tx_phase_cal (#2008)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotherNgineer committed Mar 18, 2024
1 parent 6e34343 commit 8383363
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion firmware/application/hw/max2837.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ void MAX2837::init() {
}

void MAX2837::set_tx_LO_iq_phase_calibration(const size_t v) {
Mode saved_mode = get_mode();

/* TX IQ phase deg CAL adj (+4 ...-4) in 32 steps (5 bits), 00000 = +4deg (Q lags I by 94degs, default), 01111 = +0deg, 11111 = -4deg (Q lags I by 86degs) */

// TX calibration , Logic pins , ENABLE, RXENABLE, TXENABLE = 1,0,1 (5dec), and Reg address 16, D1 (CAL mode 1):DO (CHIP ENABLE 1)
Expand All @@ -172,7 +174,7 @@ void MAX2837::set_tx_LO_iq_phase_calibration(const size_t v) {
_map.r.spi_en.EN_SPI = 1; // Register Settings reg address 16, DO (1 = Chip select enable )
flush_one(Register::SPI_EN);

set_mode(Mode::Standby); // Back 3 logic pins CALIBRATION mode -> Standby.
set_mode(saved_mode); // restore original mode
}

enum class Mask { // There are class Mask ,and class mode with same names, but they are not same.
Expand Down Expand Up @@ -205,12 +207,18 @@ Mask mode_mask(const Mode mode) { // based on enum Mode cases, we set up the co
}

void MAX2837::set_mode(const Mode mode) { // We set up the 3 Logic Pins ENABLE, RXENABLE, TXENABLE accordingly to the max2837 mode case, that we want to set up .
_mode = mode;

Mask mask = mode_mask(mode);
gpio_max283x_enable.write(toUType(mask) & toUType(Mask::Enable));
gpio_max2837_rxenable.write(toUType(mask) & toUType(Mask::RxEnable));
gpio_max2837_txenable.write(toUType(mask) & toUType(Mask::TxEnable));
}

Mode MAX2837::get_mode() {
return _mode;
}

void MAX2837::flush() {
if (_dirty) {
for (size_t n = 0; n < reg_count; n++) {
Expand Down
2 changes: 2 additions & 0 deletions firmware/application/hw/max2837.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ class MAX2837 : public MAX283x {

private:
spi::arbiter::Target& _target;
Mode _mode{Mode::Standby};

RegisterMap _map{initial_register_values};
DirtyRegisters<Register, reg_count> _dirty{};
Expand All @@ -851,6 +852,7 @@ class MAX2837 : public MAX283x {
reg_t read(const Register reg);

void flush();
Mode get_mode();
};

} // namespace max2837
Expand Down
10 changes: 9 additions & 1 deletion firmware/application/hw/max2839.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void MAX2839::init() {
}

void MAX2839::set_tx_LO_iq_phase_calibration(const size_t v) {
Mode saved_mode = get_mode();

/* IQ phase deg CAL adj (+4 ...-4) This IC in 64 steps (6 bits), 000000 = +4deg (Q lags I by 94degs, default), 011111 = +0deg, 111111 = -4deg (Q lags I by 86degs) */

// TX calibration , 2 x Logic pins , ENABLE, RXENABLE = 1,0, (2dec), and Reg address 16, D1 (CAL mode 1):DO (CHIP ENABLE 1)
Expand All @@ -164,7 +166,7 @@ void MAX2839::set_tx_LO_iq_phase_calibration(const size_t v) {
_map.r.spi_en.EN_SPI = 1; // Register Settings reg address 16, DO (1 = Chip select enable )
flush_one(Register::SPI_EN);

set_mode(Mode::Standby); // Back 3 logic pins CALIBRATION mode -> Standby.
set_mode(saved_mode); // restore original mode
}

enum class Mask {
Expand Down Expand Up @@ -196,11 +198,17 @@ Mask mode_mask(const Mode mode) {
}

void MAX2839::set_mode(const Mode mode) {
_mode = mode;

Mask mask = mode_mask(mode);
gpio_max283x_enable.write(toUType(mask) & toUType(Mask::Enable));
gpio_max2839_rxtx.write(toUType(mask) & toUType(Mask::RxTx));
}

Mode MAX2839::get_mode() {
return _mode;
}

void MAX2839::flush() {
if (_dirty) {
for (size_t n = 0; n < reg_count; n++) {
Expand Down
2 changes: 2 additions & 0 deletions firmware/application/hw/max2839.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ class MAX2839 : public MAX283x {

private:
spi::arbiter::Target& _target;
Mode _mode{Mode::Standby};

RegisterMap _map{initial_register_values};
DirtyRegisters<Register, reg_count> _dirty{};
Expand All @@ -712,6 +713,7 @@ class MAX2839 : public MAX283x {
void flush();

void configure_rx_gain();
Mode get_mode();
};

} // namespace max2839
Expand Down

0 comments on commit 8383363

Please sign in to comment.