1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 #include "esp_phy_init.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #define ESP_CAL_DATA_CHECK_FAIL 1
23 
24 /**
25  * @file phy.h
26  * @brief Declarations for functions provided by libphy.a
27  */
28 
29 /**
30  * @brief Return ROM function pointer table from PHY library.
31  */
32 void phy_get_romfunc_addr(void);
33 
34 /**
35  * @brief Initialize PHY module and do RF calibration
36  * @param[in] init_data Initialization parameters to be used by the PHY
37  * @param[inout] cal_data As input, calibration data previously obtained. As output, will contain new calibration data.
38  * @param[in] cal_mode  RF calibration mode
39  * @return ESP_CAL_DATA_CHECK_FAIL if calibration data checksum fails, other values are reserved for future use
40  */
41 int register_chipv7_phy(const esp_phy_init_data_t* init_data, esp_phy_calibration_data_t *cal_data, esp_phy_calibration_mode_t cal_mode);
42 
43 /**
44  * @brief Get the format version of calibration data used by PHY library.
45  * @return Format version number, OR'ed with BIT(16) if PHY is in WIFI only mode.
46  */
47 uint32_t phy_get_rf_cal_version(void);
48 
49 /**
50  * @brief Set RF/BB for only WIFI mode or coexist(WIFI & BT) mode
51  * @param[in] true is for only WIFI mode, false is for coexist mode. default is 0.
52  * @return NULL
53  */
54 void phy_set_wifi_mode_only(bool wifi_only);
55 
56 /**
57  * @brief Set BT the highest priority in coexist mode.
58  * @return NULL
59  */
60 void coex_bt_high_prio(void);
61 
62 /**
63  * @brief Open PHY and RF.
64  */
65 void phy_wakeup_init(void);
66 
67 /**
68  * @brief Shutdown PHY and RF.
69  */
70 void phy_close_rf(void);
71 
72 #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
73 /**
74  * @brief Disable PHY temperature sensor.
75  */
76 void phy_xpd_tsens(void);
77 #endif
78 
79 /**
80  * @brief Store and load PHY digital registers.
81  *
82  * @param     backup_en  if backup_en is true, store PHY digital registers to memory. Otherwise load PHY digital registers from memory
83  * @param     mem_addr   Memory address to store and load PHY digital registers
84  *
85  * @return    memory size
86  */
87 uint8_t phy_dig_reg_backup(bool backup_en, uint32_t *mem_addr);
88 
89 #if CONFIG_MAC_BB_PD
90 /**
91  * @brief Store and load baseband registers.
92  */
93 void phy_freq_mem_backup(bool backup_en, uint32_t *mem);
94 #endif
95 
96 #ifdef __cplusplus
97 }
98 #endif
99