2016-10-06 14:21:30 +03:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "sdkconfig.h"
|
2022-05-23 23:54:26 +02:00
|
|
|
#include "esp32-hal-misc.h"
|
|
|
|
#include "esp32-hal.h"
|
2016-10-06 14:21:30 +03:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "esp_attr.h"
|
2017-02-13 00:56:47 +01:00
|
|
|
#include "nvs_flash.h"
|
2017-04-04 01:27:26 +03:00
|
|
|
#include "nvs.h"
|
|
|
|
#include "esp_partition.h"
|
2017-04-13 09:13:45 +03:00
|
|
|
#include "esp_log.h"
|
2018-05-22 16:12:30 +02:00
|
|
|
#include "esp_timer.h"
|
2018-12-10 02:11:37 -07:00
|
|
|
#ifdef CONFIG_BT_ENABLED
|
2018-06-27 09:01:06 +02:00
|
|
|
#include "esp_bt.h"
|
2018-12-10 02:11:37 -07:00
|
|
|
#endif //CONFIG_BT_ENABLED
|
2017-03-20 11:21:56 +02:00
|
|
|
#include <sys/time.h>
|
2018-12-18 20:04:16 +01:00
|
|
|
#include "soc/rtc.h"
|
2018-12-20 01:57:32 +01:00
|
|
|
#include "soc/rtc_cntl_reg.h"
|
2019-01-09 10:07:54 +01:00
|
|
|
#include "soc/apb_ctrl_reg.h"
|
2018-12-28 20:37:33 +02:00
|
|
|
#include "esp_task_wdt.h"
|
2016-10-06 14:21:30 +03:00
|
|
|
|
2020-01-25 05:44:14 +02:00
|
|
|
#include "esp_system.h"
|
|
|
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
|
|
|
#include "esp32/rom/rtc.h"
|
2020-05-09 19:11:30 +03:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
|
|
|
#include "esp32s2/rom/rtc.h"
|
2020-01-25 05:44:14 +02:00
|
|
|
#else
|
|
|
|
#error Target CONFIG_IDF_TARGET is not supported
|
|
|
|
#endif
|
|
|
|
#else // ESP32 Before IDF 4.0
|
|
|
|
#include "rom/rtc.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 17:47:06 +08:00
|
|
|
//Undocumented!!! Get chip temperature in Farenheit
|
|
|
|
//Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_temp_sensor.ino
|
|
|
|
uint8_t temprature_sens_read();
|
|
|
|
|
|
|
|
float temperatureRead()
|
|
|
|
{
|
|
|
|
return (temprature_sens_read() - 32) / 1.8;
|
|
|
|
}
|
|
|
|
|
2019-10-04 11:49:39 +02:00
|
|
|
void __yield()
|
2017-02-11 00:25:15 +02:00
|
|
|
{
|
|
|
|
vPortYield();
|
|
|
|
}
|
|
|
|
|
2019-10-04 11:49:39 +02:00
|
|
|
void yield() __attribute__ ((weak, alias("__yield")));
|
|
|
|
|
2020-05-19 00:08:10 +03:00
|
|
|
unsigned long ARDUINO_ISR_ATTR micros()
|
2016-10-06 14:21:30 +03:00
|
|
|
{
|
2019-01-09 10:07:54 +01:00
|
|
|
return (unsigned long) (esp_timer_get_time());
|
2016-10-06 14:21:30 +03:00
|
|
|
}
|
|
|
|
|
2020-05-19 00:08:10 +03:00
|
|
|
void ARDUINO_ISR_ATTR delayMicroseconds(uint32_t us)
|
2016-10-06 14:21:30 +03:00
|
|
|
{
|
2016-12-02 13:03:48 +02:00
|
|
|
uint32_t m = micros();
|
|
|
|
if(us){
|
2017-03-20 11:21:56 +02:00
|
|
|
uint32_t e = (m + us);
|
2016-12-02 13:03:48 +02:00
|
|
|
if(m > e){ //overflow
|
|
|
|
while(micros() > e){
|
|
|
|
NOP();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(micros() < e){
|
2016-10-06 14:21:30 +03:00
|
|
|
NOP();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|