summaryrefslogtreecommitdiffstats
path: root/rf_test
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-01-19 12:38:15 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-01-19 12:38:15 +0800
commita9213f1194b5fe054041a56b6932298b6d982391 (patch)
tree7754839363eb9873e9c850a8bb19a9ef93b45e75 /rf_test
parent36f1d15353eeea06da8f478842fcd50a8b3f04bb (diff)
downloadsmart-home-a9213f1194b5fe054041a56b6932298b6d982391.tar.gz
Define set_tx_power().
Diffstat (limited to 'rf_test')
-rw-r--r--rf_test/radio.c21
-rw-r--r--rf_test/radio.h2
2 files changed, 22 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;
diff --git a/rf_test/radio.h b/rf_test/radio.h
index c56121b..924da2d 100644
--- a/rf_test/radio.h
+++ b/rf_test/radio.h
@@ -11,6 +11,8 @@ struct radio_cfg {
void radio_init(const struct radio_cfg *cfg);
+void radio_set_tx_power(int8_t val);
+
void radio_listen(void);
void radio_send(const char *data, uint8_t n);