6 RFAMP_hal
*RFAMP_hal::instance
= NULL
;
13 void RFAMP_hal::init()
15 DBGLN("RFAMP_hal Init");
17 #if defined(PLATFORM_ESP32)
18 #define SET_BIT(n) ((n != UNDEF_PIN) ? 1ULL << n : 0)
20 txrx_disable_clr_bits
= 0;
21 txrx_disable_clr_bits
|= SET_BIT(GPIO_PIN_PA_ENABLE
);
22 txrx_disable_clr_bits
|= SET_BIT(GPIO_PIN_RX_ENABLE
);
23 txrx_disable_clr_bits
|= SET_BIT(GPIO_PIN_TX_ENABLE
);
24 txrx_disable_clr_bits
|= SET_BIT(GPIO_PIN_RX_ENABLE_2
);
25 txrx_disable_clr_bits
|= SET_BIT(GPIO_PIN_TX_ENABLE_2
);
27 tx1_enable_set_bits
= 0;
28 tx1_enable_clr_bits
= 0;
29 tx1_enable_set_bits
|= SET_BIT(GPIO_PIN_PA_ENABLE
);
30 tx1_enable_set_bits
|= SET_BIT(GPIO_PIN_TX_ENABLE
);
31 tx1_enable_clr_bits
|= SET_BIT(GPIO_PIN_RX_ENABLE
);
32 tx1_enable_clr_bits
|= SET_BIT(GPIO_PIN_RX_ENABLE_2
);
34 tx2_enable_set_bits
= 0;
35 tx2_enable_clr_bits
= 0;
36 tx2_enable_set_bits
|= SET_BIT(GPIO_PIN_PA_ENABLE
);
37 tx2_enable_set_bits
|= SET_BIT(GPIO_PIN_TX_ENABLE_2
);
38 tx2_enable_clr_bits
|= SET_BIT(GPIO_PIN_RX_ENABLE_2
);
39 tx2_enable_clr_bits
|= SET_BIT(GPIO_PIN_RX_ENABLE
);
41 tx_all_enable_set_bits
= 0;
42 tx_all_enable_clr_bits
= 0;
43 tx_all_enable_set_bits
= tx1_enable_set_bits
| tx2_enable_set_bits
;
44 tx_all_enable_clr_bits
= tx1_enable_clr_bits
| tx2_enable_clr_bits
;
46 rx_enable_set_bits
= 0;
47 rx_enable_clr_bits
= 0;
48 rx_enable_set_bits
|= SET_BIT(GPIO_PIN_PA_ENABLE
);
49 rx_enable_set_bits
|= SET_BIT(GPIO_PIN_RX_ENABLE
);
50 rx_enable_set_bits
|= SET_BIT(GPIO_PIN_RX_ENABLE_2
);
51 rx_enable_clr_bits
|= SET_BIT(GPIO_PIN_TX_ENABLE
);
52 rx_enable_clr_bits
|= SET_BIT(GPIO_PIN_TX_ENABLE_2
);
59 if (GPIO_PIN_PA_ENABLE
!= UNDEF_PIN
)
61 DBGLN("Use PA enable pin: %d", GPIO_PIN_PA_ENABLE
);
62 pinMode(GPIO_PIN_PA_ENABLE
, OUTPUT
);
63 digitalWrite(GPIO_PIN_PA_ENABLE
, LOW
);
66 if (GPIO_PIN_TX_ENABLE
!= UNDEF_PIN
)
68 DBGLN("Use TX pin: %d", GPIO_PIN_TX_ENABLE
);
69 pinMode(GPIO_PIN_TX_ENABLE
, OUTPUT
);
70 digitalWrite(GPIO_PIN_TX_ENABLE
, LOW
);
73 if (GPIO_PIN_RX_ENABLE
!= UNDEF_PIN
)
75 DBGLN("Use RX pin: %d", GPIO_PIN_RX_ENABLE
);
76 pinMode(GPIO_PIN_RX_ENABLE
, OUTPUT
);
77 digitalWrite(GPIO_PIN_RX_ENABLE
, LOW
);
80 if (GPIO_PIN_TX_ENABLE_2
!= UNDEF_PIN
)
82 DBGLN("Use TX_2 pin: %d", GPIO_PIN_TX_ENABLE_2
);
83 pinMode(GPIO_PIN_TX_ENABLE_2
, OUTPUT
);
84 digitalWrite(GPIO_PIN_TX_ENABLE_2
, LOW
);
87 if (GPIO_PIN_RX_ENABLE_2
!= UNDEF_PIN
)
89 DBGLN("Use RX_2 pin: %d", GPIO_PIN_RX_ENABLE_2
);
90 pinMode(GPIO_PIN_RX_ENABLE_2
, OUTPUT
);
91 digitalWrite(GPIO_PIN_RX_ENABLE_2
, LOW
);
95 void ICACHE_RAM_ATTR
RFAMP_hal::TXenable(SX12XX_Radio_Number_t radioNumber
)
97 #if defined(PLATFORM_ESP32_C3)
98 if (radioNumber
== SX12XX_Radio_All
)
100 GPIO
.out_w1ts
.out_w1ts
= tx_all_enable_set_bits
;
101 GPIO
.out_w1tc
.out_w1tc
= tx_all_enable_clr_bits
;
103 else if (radioNumber
== SX12XX_Radio_2
)
105 GPIO
.out_w1ts
.out_w1ts
= tx2_enable_set_bits
;
106 GPIO
.out_w1tc
.out_w1tc
= tx2_enable_clr_bits
;
110 GPIO
.out_w1ts
.out_w1ts
= tx1_enable_set_bits
;
111 GPIO
.out_w1tc
.out_w1tc
= tx1_enable_clr_bits
;
113 #elif defined(PLATFORM_ESP32)
114 if (radioNumber
== SX12XX_Radio_All
)
116 GPIO
.out_w1ts
= (uint32_t)tx_all_enable_set_bits
;
117 GPIO
.out_w1tc
= tx_all_enable_clr_bits
;
119 GPIO
.out1_w1ts
.data
= tx_all_enable_set_bits
>> 32;
120 GPIO
.out1_w1tc
.data
= tx_all_enable_clr_bits
>> 32;
122 else if (radioNumber
== SX12XX_Radio_2
)
124 GPIO
.out_w1ts
= tx2_enable_set_bits
;
125 GPIO
.out_w1tc
= tx2_enable_clr_bits
;
127 GPIO
.out1_w1ts
.data
= tx2_enable_set_bits
>> 32;
128 GPIO
.out1_w1tc
.data
= tx2_enable_clr_bits
>> 32;
132 GPIO
.out_w1ts
= tx1_enable_set_bits
;
133 GPIO
.out_w1tc
= tx1_enable_clr_bits
;
135 GPIO
.out1_w1ts
.data
= tx1_enable_set_bits
>> 32;
136 GPIO
.out1_w1tc
.data
= tx1_enable_clr_bits
>> 32;
139 if (!tx1_enabled
&& !tx2_enabled
&& !rx_enabled
)
141 if (GPIO_PIN_PA_ENABLE
!= UNDEF_PIN
)
143 digitalWrite(GPIO_PIN_PA_ENABLE
, HIGH
);
148 if (GPIO_PIN_RX_ENABLE
!= UNDEF_PIN
)
150 digitalWrite(GPIO_PIN_RX_ENABLE
, LOW
);
152 if (GPIO_PIN_RX_ENABLE_2
!= UNDEF_PIN
)
154 digitalWrite(GPIO_PIN_RX_ENABLE_2
, LOW
);
158 if (radioNumber
== SX12XX_Radio_1
&& !tx1_enabled
)
160 if (GPIO_PIN_TX_ENABLE
!= UNDEF_PIN
)
162 digitalWrite(GPIO_PIN_TX_ENABLE
, HIGH
);
164 if (GPIO_PIN_TX_ENABLE_2
!= UNDEF_PIN
)
166 digitalWrite(GPIO_PIN_TX_ENABLE_2
, LOW
);
171 if (radioNumber
== SX12XX_Radio_2
&& !tx2_enabled
)
173 if (GPIO_PIN_TX_ENABLE
!= UNDEF_PIN
)
175 digitalWrite(GPIO_PIN_TX_ENABLE
, LOW
);
177 if (GPIO_PIN_TX_ENABLE_2
!= UNDEF_PIN
)
179 digitalWrite(GPIO_PIN_TX_ENABLE_2
, HIGH
);
187 void ICACHE_RAM_ATTR
RFAMP_hal::RXenable()
189 #if defined(PLATFORM_ESP32_C3)
190 GPIO
.out_w1ts
.out_w1ts
= rx_enable_set_bits
;
191 GPIO
.out_w1tc
.out_w1tc
= rx_enable_clr_bits
;
192 #elif defined(PLATFORM_ESP32)
193 GPIO
.out_w1ts
= rx_enable_set_bits
;
194 GPIO
.out_w1tc
= rx_enable_clr_bits
;
196 GPIO
.out1_w1ts
.data
= rx_enable_set_bits
>> 32;
197 GPIO
.out1_w1tc
.data
= rx_enable_clr_bits
>> 32;
201 if (!tx1_enabled
&& !tx2_enabled
&& GPIO_PIN_PA_ENABLE
!= UNDEF_PIN
)
202 digitalWrite(GPIO_PIN_PA_ENABLE
, HIGH
);
204 if (tx1_enabled
&& GPIO_PIN_TX_ENABLE
!= UNDEF_PIN
)
206 digitalWrite(GPIO_PIN_TX_ENABLE
, LOW
);
210 if (tx2_enabled
&& GPIO_PIN_TX_ENABLE_2
!= UNDEF_PIN
)
212 digitalWrite(GPIO_PIN_TX_ENABLE_2
, LOW
);
216 if (GPIO_PIN_RX_ENABLE
!= UNDEF_PIN
)
218 digitalWrite(GPIO_PIN_RX_ENABLE
, HIGH
);
220 if (GPIO_PIN_RX_ENABLE_2
!= UNDEF_PIN
)
222 digitalWrite(GPIO_PIN_RX_ENABLE_2
, HIGH
);
230 void ICACHE_RAM_ATTR
RFAMP_hal::TXRXdisable()
232 #if defined(PLATFORM_ESP32_C3)
233 GPIO
.out_w1tc
.out_w1tc
= txrx_disable_clr_bits
;
234 #elif defined(PLATFORM_ESP32)
235 GPIO
.out_w1tc
= txrx_disable_clr_bits
;
236 GPIO
.out1_w1tc
.data
= txrx_disable_clr_bits
>> 32;
240 if (GPIO_PIN_RX_ENABLE
!= UNDEF_PIN
)
242 digitalWrite(GPIO_PIN_RX_ENABLE
, LOW
);
244 if (GPIO_PIN_RX_ENABLE_2
!= UNDEF_PIN
)
246 digitalWrite(GPIO_PIN_RX_ENABLE_2
, LOW
);
252 if (GPIO_PIN_PA_ENABLE
!= UNDEF_PIN
)
254 digitalWrite(GPIO_PIN_PA_ENABLE
, LOW
);
256 if (GPIO_PIN_TX_ENABLE
!= UNDEF_PIN
)
258 digitalWrite(GPIO_PIN_TX_ENABLE
, LOW
);
264 if (GPIO_PIN_PA_ENABLE
!= UNDEF_PIN
)
266 digitalWrite(GPIO_PIN_PA_ENABLE
, LOW
);
268 if (GPIO_PIN_TX_ENABLE_2
!= UNDEF_PIN
)
270 digitalWrite(GPIO_PIN_TX_ENABLE_2
, LOW
);