From d04ce110f9b91c74c4c3c2248d938a58d0127598 Mon Sep 17 00:00:00 2001 From: Zhang Jun Hao Date: Tue, 21 May 2019 16:47:56 +0800 Subject: [PATCH] feat(esp8266): add set tx power via vdd33 function --- components/esp8266/include/esp_wifi.h | 26 ++++++++++++++++++++++++++ components/esp8266/source/phy_init.c | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/components/esp8266/include/esp_wifi.h b/components/esp8266/include/esp_wifi.h index 6988a369..4fc2b319 100644 --- a/components/esp8266/include/esp_wifi.h +++ b/components/esp8266/include/esp_wifi.h @@ -827,6 +827,32 @@ esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx); */ esp_err_t esp_wifi_set_max_tx_power(int8_t power); +/** + * @brief Adjust RF Tx Power according to VDD33; unit : 1/1024 V. + * + * @attention When TOUT pin is suspended, VDD33 can be got by esp_wifi_get_vdd33. + * When TOUT pin is wired to external circuitry, esp_wifi_get_vdd33 can not be used. + * @attention This api only worked when it is called, please call this api every day or hour + * according to power consumption. + * + * @param vdd33 unit is 1/1024V, range [1900, 3300]. + */ +void esp_wifi_set_max_tx_power_via_vdd33(uint16_t vdd33); + +/** + * @brief Measure the power voltage of VDD3P3 pin 3 and 4; unit: 1/1024 V + * + * @attention esp_wifi_get_vdd33 can only be called when TOUT pin is suspended. + * @attention The 107th byte in esp_init_data_default.bin (0 ~ 127 bytes) is named as + * vdd33_const. When TOUT pin is suspended, vdd33_const must be set as + * 0xFF, which is 255. + * @attention The return value of esp_wifi_get_vdd33 may be different in different Wi-Fi + * modes, for example, in Modem-sleep mode or in normal Wi-Fi working mode. + * + * @return the power voltage of vdd33 pin 3 and 4 + */ +uint16_t esp_wifi_get_vdd33(void); + /** * @brief Get maximum WiFi transmiting power * diff --git a/components/esp8266/source/phy_init.c b/components/esp8266/source/phy_init.c index 7f7e9437..11422d1e 100644 --- a/components/esp8266/source/phy_init.c +++ b/components/esp8266/source/phy_init.c @@ -335,3 +335,23 @@ void esp_phy_load_cal_and_init(phy_rf_module_t module) free(cal_data); // PHY maintains a copy of calibration data, so we can free this } + +uint16_t esp_wifi_get_vdd33(void) +{ + if (phy_init_data.params[107] != 0xFF ) { + ESP_LOGE(TAG, "Please set VDD33 const to 0xff"); + return 0xFFFF; + } + extern uint16_t phy_get_vdd33(); + uint16_t ret = phy_get_vdd33(); + if (ret != 0xFFFF) { + ret = ret *12 / 11; + } + return ret; +} + +void esp_wifi_set_max_tx_power_via_vdd33(uint16_t vdd33) +{ + extern void phy_vdd33_set_tpw(uint16_t vdd33); + phy_vdd33_set_tpw(vdd33); +} \ No newline at end of file