From a9213f1194b5fe054041a56b6932298b6d982391 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sun, 19 Jan 2025 12:38:15 +0800 Subject: Define set_tx_power(). --- rf_test/radio.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'rf_test/radio.c') diff --git a/rf_test/radio.c b/rf_test/radio.c index 802144a..39df9d7 100644 --- a/rf_test/radio.c +++ b/rf_test/radio.c @@ -22,7 +22,7 @@ #define RF69_REG_TESTPA1 0x5A #define RF69_REG_TESTPA2 0x5C -static power = 0; +static int8_t power = 0; static inline uint8_t read_reg(uint8_t reg) { @@ -79,6 +79,25 @@ static inline void set_mode(uint8_t mode) } } +void radio_set_tx_power(int8_t val) +{ + uint8_t pa; + + power = val; + + if (power < -2) + power = -2; + + if (power <= 13) + pa = (0x40 | ((power + 18) & 0x1F)); + else if (power >= 18) + pa = (0x40 | 0x20 | ((power + 11) & 0x1F)); + else + pa = (0x40 | 0x20 | ((power + 14) & 0x1F)); + + write_reg(0x11, pa); +} + void radio_send(const char *data, uint8_t n) { uint8_t i; -- cgit v1.2.3