2022-03-01 16:12:45 +08:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2022-04-13 12:15:38 +08:00
|
|
|
#include "esp_attr.h"
|
2022-03-01 16:12:45 +08:00
|
|
|
#include "driver/adc.h"
|
2023-07-24 12:35:30 +08:00
|
|
|
#include "esp_private/sar_periph_ctrl.h"
|
|
|
|
|
2022-03-01 16:12:45 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is used to override the hooks provided by the PHY lib for some system features.
|
|
|
|
* Call phy_override() so that this file will be linked.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static bool s_wifi_adc_xpd_flag;
|
2023-07-24 14:34:55 +08:00
|
|
|
static bool s_wifi_tsens_xpd_flag;
|
2022-03-01 16:12:45 +08:00
|
|
|
|
|
|
|
void include_esp_phy_override(void)
|
|
|
|
{
|
|
|
|
/* When this empty function is called, all functions below will be linked. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Coordinate ADC power with other modules. */
|
|
|
|
// It seems that it is only required on ESP32, but we still compile it for all chips, in case it is
|
|
|
|
// called by PHY unexpectedly.
|
|
|
|
void set_xpd_sar(bool en)
|
|
|
|
{
|
|
|
|
if (s_wifi_adc_xpd_flag == en) {
|
|
|
|
/* ignore repeated calls to set_xpd_sar when the state is already correct */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_wifi_adc_xpd_flag = en;
|
|
|
|
if (en) {
|
|
|
|
adc_power_acquire();
|
|
|
|
} else {
|
|
|
|
adc_power_release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//add spinlock protection
|
|
|
|
extern void regi2c_enter_critical(void);
|
|
|
|
extern void regi2c_exit_critical(void);
|
|
|
|
|
2022-04-13 12:15:38 +08:00
|
|
|
IRAM_ATTR void phy_i2c_enter_critical(void)
|
2022-03-01 16:12:45 +08:00
|
|
|
{
|
|
|
|
regi2c_enter_critical();
|
|
|
|
}
|
|
|
|
|
2022-04-13 12:15:38 +08:00
|
|
|
IRAM_ATTR void phy_i2c_exit_critical(void)
|
2022-03-01 16:12:45 +08:00
|
|
|
{
|
|
|
|
regi2c_exit_critical();
|
|
|
|
}
|
2023-07-24 12:35:30 +08:00
|
|
|
|
|
|
|
void phy_set_tsens_power(bool en)
|
|
|
|
{
|
2023-07-24 14:34:55 +08:00
|
|
|
if (s_wifi_tsens_xpd_flag == en) {
|
|
|
|
/* ignore repeated calls to phy_set_tsens_power when the state is already correct */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_wifi_tsens_xpd_flag = en;
|
|
|
|
|
2023-07-24 12:35:30 +08:00
|
|
|
if (en) {
|
|
|
|
temperature_sensor_power_acquire();
|
|
|
|
} else {
|
|
|
|
temperature_sensor_power_release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t phy_get_tsens_value(void)
|
|
|
|
{
|
|
|
|
return temp_sensor_get_raw_value(NULL);
|
|
|
|
}
|