|
|
@@ -10,16 +10,18 @@
|
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
#include "esp_sleep.h"
|
|
|
-#include "nvs.h"
|
|
|
-#include "nvs_flash.h"
|
|
|
#include "soc/rtc_cntl_reg.h"
|
|
|
#include "soc/sens_reg.h"
|
|
|
#include "driver/gpio.h"
|
|
|
#include "driver/rtc_io.h"
|
|
|
-#include "driver/dac.h"
|
|
|
-#include "esp32/ulp.h"
|
|
|
+#include "ulp.h"
|
|
|
#include "ulp_main.h"
|
|
|
#include "esp_adc/adc_oneshot.h"
|
|
|
+#include "ulp/example_config.h"
|
|
|
+#include "ulp_adc.h"
|
|
|
+
|
|
|
+#include "freertos/FreeRTOS.h"
|
|
|
+#include "freertos/task.h"
|
|
|
|
|
|
extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start");
|
|
|
extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end");
|
|
|
@@ -51,6 +53,12 @@ void app_main(void)
|
|
|
printf("Entering deep sleep\n\n");
|
|
|
start_ulp_program();
|
|
|
ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup() );
|
|
|
+
|
|
|
+#if !CONFIG_IDF_TARGET_ESP32
|
|
|
+ /* RTC peripheral power domain needs to be kept on to keep SAR ADC related configs during sleep */
|
|
|
+ esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
|
|
+#endif
|
|
|
+
|
|
|
esp_deep_sleep_start();
|
|
|
}
|
|
|
|
|
|
@@ -60,35 +68,31 @@ static void init_ulp_program(void)
|
|
|
(ulp_main_bin_end - ulp_main_bin_start) / sizeof(uint32_t));
|
|
|
ESP_ERROR_CHECK(err);
|
|
|
|
|
|
- //-------------ADC1 Init---------------//
|
|
|
- adc_oneshot_unit_handle_t adc1_handle;
|
|
|
- adc_oneshot_unit_init_cfg_t init_config1 = {
|
|
|
- .unit_id = ADC_UNIT_1,
|
|
|
+ ulp_adc_cfg_t cfg = {
|
|
|
+ .adc_n = EXAMPLE_ADC_UNIT,
|
|
|
+ .channel = EXAMPLE_ADC_CHANNEL,
|
|
|
+ .width = EXAMPLE_ADC_WIDTH,
|
|
|
+ .atten = EXAMPLE_ADC_ATTEN,
|
|
|
.ulp_mode = ADC_ULP_MODE_FSM,
|
|
|
};
|
|
|
- ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle));
|
|
|
|
|
|
- //-------------ADC1 Channel Config---------------//
|
|
|
- // Note: when changing channel here, also change 'adc_channel' constant in adc.S
|
|
|
- adc_oneshot_chan_cfg_t config = {
|
|
|
- .bitwidth = ADC_BITWIDTH_DEFAULT,
|
|
|
- .atten = ADC_ATTEN_DB_11,
|
|
|
- };
|
|
|
- ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, ADC_CHANNEL_6, &config));
|
|
|
+ ESP_ERROR_CHECK(ulp_adc_init(&cfg));
|
|
|
|
|
|
- /* Set low and high thresholds, approx. 1.35V - 1.75V*/
|
|
|
- ulp_low_thr = 1500;
|
|
|
- ulp_high_thr = 2000;
|
|
|
+ ulp_low_thr = EXAMPLE_ADC_LOW_TRESHOLD;
|
|
|
+ ulp_high_thr = EXAMPLE_ADC_HIGH_TRESHOLD;
|
|
|
|
|
|
/* Set ULP wake up period to 20ms */
|
|
|
ulp_set_wakeup_period(0, 20000);
|
|
|
|
|
|
+#if CONFIG_IDF_TARGET_ESP32
|
|
|
/* Disconnect GPIO12 and GPIO15 to remove current drain through
|
|
|
- * pullup/pulldown resistors.
|
|
|
+ * pullup/pulldown resistors on modules which have these (e.g. ESP32-WROVER)
|
|
|
* GPIO12 may be pulled high to select flash voltage.
|
|
|
*/
|
|
|
rtc_gpio_isolate(GPIO_NUM_12);
|
|
|
rtc_gpio_isolate(GPIO_NUM_15);
|
|
|
+#endif // CONFIG_IDF_TARGET_ESP32
|
|
|
+
|
|
|
esp_deep_sleep_disable_rom_logging(); // suppress boot messages
|
|
|
}
|
|
|
|