diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-01-19 12:38:15 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-01-19 12:38:15 +0800 |
| commit | a9213f1194b5fe054041a56b6932298b6d982391 (patch) | |
| tree | 7754839363eb9873e9c850a8bb19a9ef93b45e75 /rf_test/radio.c | |
| parent | 36f1d15353eeea06da8f478842fcd50a8b3f04bb (diff) | |
| download | smart-home-a9213f1194b5fe054041a56b6932298b6d982391.tar.gz | |
Define set_tx_power().
Diffstat (limited to 'rf_test/radio.c')
| -rw-r--r-- | rf_test/radio.c | 21 |
1 files changed, 20 insertions, 1 deletions
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; |
