2018-03-24 13:38:43 +01:00
|
|
|
/* switches wifi antenna, if board has switch to select internal and external antenna */
|
|
|
|
|
|
|
|
#ifdef HAS_ANTENNA_SWITCH
|
2018-03-18 19:45:17 +01:00
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
// Local logging tag
|
2018-05-27 17:42:18 +02:00
|
|
|
static const char* TAG = "wifi";
|
2018-03-18 19:45:17 +01:00
|
|
|
|
2018-03-24 11:28:33 +01:00
|
|
|
typedef enum {
|
|
|
|
ANTENNA_INT = 0,
|
|
|
|
ANTENNA_EXT
|
|
|
|
} antenna_type_t;
|
2018-03-18 19:45:17 +01:00
|
|
|
|
|
|
|
void antenna_init(void) {
|
2018-03-24 13:38:43 +01:00
|
|
|
gpio_config_t gpioconf = {.pin_bit_mask = 1ull << HAS_ANTENNA_SWITCH,
|
2018-03-18 19:45:17 +01:00
|
|
|
.mode = GPIO_MODE_OUTPUT,
|
|
|
|
.pull_up_en = GPIO_PULLUP_DISABLE,
|
|
|
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
|
|
|
.intr_type = GPIO_INTR_DISABLE};
|
|
|
|
gpio_config(&gpioconf);
|
|
|
|
}
|
|
|
|
|
2018-04-28 14:09:27 +02:00
|
|
|
void antenna_select (const uint8_t _ant) {
|
2018-03-24 13:38:43 +01:00
|
|
|
if (HAS_ANTENNA_SWITCH < 32) {
|
2018-03-24 11:28:33 +01:00
|
|
|
if (_ant == ANTENNA_EXT) {
|
2018-03-24 13:38:43 +01:00
|
|
|
GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, 1 << HAS_ANTENNA_SWITCH);
|
2018-03-18 19:45:17 +01:00
|
|
|
} else {
|
2018-03-24 13:38:43 +01:00
|
|
|
GPIO_REG_WRITE(GPIO_OUT_W1TC_REG, 1 << HAS_ANTENNA_SWITCH);
|
2018-03-18 19:45:17 +01:00
|
|
|
}
|
|
|
|
} else {
|
2018-03-24 11:28:33 +01:00
|
|
|
if (_ant == ANTENNA_EXT) {
|
2018-03-24 13:38:43 +01:00
|
|
|
GPIO_REG_WRITE(GPIO_OUT1_W1TS_REG, 1 << (HAS_ANTENNA_SWITCH & 31));
|
2018-03-18 19:45:17 +01:00
|
|
|
} else {
|
2018-03-24 13:38:43 +01:00
|
|
|
GPIO_REG_WRITE(GPIO_OUT1_W1TC_REG, 1 << (HAS_ANTENNA_SWITCH & 31));
|
2018-03-18 19:45:17 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-24 11:28:33 +01:00
|
|
|
ESP_LOGI(TAG, "Wifi Antenna switched to %s", _ant ? "external" : "internal");
|
2018-03-18 19:45:17 +01:00
|
|
|
}
|
|
|
|
|
2018-03-24 13:38:43 +01:00
|
|
|
#endif
|