@@ -1192,6 +1192,94 @@ bool WiFiGenericClass::initiateFTM(uint8_t frm_count, uint16_t burst_period, uin
11921192 return true ;
11931193}
11941194
1195+ /* *
1196+ * Configure Dual antenna.
1197+ * @param gpio_ant1 Configure the GPIO number for the antenna 1 connected to the RF switch (default GPIO2 on ESP32-WROOM-DA)
1198+ * @param gpio_ant2 Configure the GPIO number for the antenna 2 connected to the RF switch (default GPIO25 on ESP32-WROOM-DA)
1199+ * @param rx_mode Set the RX antenna mode. See wifi_rx_ant_t for the options.
1200+ * @param tx_mode Set the TX antenna mode. See wifi_tx_ant_t for the options.
1201+ * @return true on success
1202+ */
1203+ bool WiFiGenericClass::setDualAntennaConfig (uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode) {
1204+
1205+ wifi_ant_gpio_config_t wifi_ant_io;
1206+
1207+ if (ESP_OK != esp_wifi_get_ant_gpio (&wifi_ant_io)) {
1208+ log_e (" Failed to get antenna configuration" );
1209+ return false ;
1210+ }
1211+
1212+ wifi_ant_io.gpio_cfg [0 ].gpio_num = gpio_ant1;
1213+ wifi_ant_io.gpio_cfg [0 ].gpio_select = 1 ;
1214+ wifi_ant_io.gpio_cfg [1 ].gpio_num = gpio_ant2;
1215+ wifi_ant_io.gpio_cfg [1 ].gpio_select = 1 ;
1216+
1217+ if (ESP_OK != esp_wifi_set_ant_gpio (&wifi_ant_io)) {
1218+ log_e (" Failed to set antenna GPIO configuration" );
1219+ return false ;
1220+ }
1221+
1222+ // Set antenna default configuration
1223+ wifi_ant_config_t ant_config = {
1224+ .rx_ant_mode = WIFI_ANT_MODE_AUTO,
1225+ .tx_ant_mode = WIFI_ANT_MODE_AUTO,
1226+ .enabled_ant0 = 0 ,
1227+ .enabled_ant1 = 1 ,
1228+ };
1229+
1230+ switch (rx_mode)
1231+ {
1232+ case WIFI_RX_ANT0:
1233+ ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT0;
1234+ break ;
1235+ case WIFI_RX_ANT1:
1236+ ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT1;
1237+ break ;
1238+ case WIFI_RX_ANT_AUTO:
1239+ log_i (" TX Antenna will be automatically selected" );
1240+ ant_config.rx_ant_default = WIFI_ANT_ANT0;
1241+ ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO;
1242+ // Force TX for AUTO if RX is AUTO
1243+ ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO;
1244+ goto set_ant;
1245+ break ;
1246+ default :
1247+ log_e (" Invalid default antenna! Falling back to AUTO" );
1248+ ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO;
1249+ break ;
1250+ }
1251+
1252+ switch (tx_mode)
1253+ {
1254+ case WIFI_TX_ANT0:
1255+ ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT0;
1256+ break ;
1257+ case WIFI_TX_ANT1:
1258+ ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT1;
1259+ break ;
1260+ case WIFI_TX_ANT_AUTO:
1261+ log_i (" RX Antenna will be automatically selected" );
1262+ ant_config.rx_ant_default = WIFI_ANT_ANT0;
1263+ ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO;
1264+ // Force RX for AUTO if RX is AUTO
1265+ ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO;
1266+ break ;
1267+ default :
1268+ log_e (" Invalid default antenna! Falling back to AUTO" );
1269+ ant_config.rx_ant_default = WIFI_ANT_ANT0;
1270+ ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO;
1271+ break ;
1272+ }
1273+
1274+ set_ant:
1275+ if (ESP_OK != esp_wifi_set_ant (&ant_config)) {
1276+ log_e (" Failed to set antenna configuration" );
1277+ return false ;
1278+ }
1279+
1280+ return true ;
1281+ }
1282+
11951283// -----------------------------------------------------------------------------------------------------------------------
11961284// ------------------------------------------------ Generic Network function ---------------------------------------------
11971285// -----------------------------------------------------------------------------------------------------------------------
0 commit comments