/*
 * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Unlicense OR CC0-1.0
 */
/* ULP-RISC-V example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.

   This code runs on ULP-RISC-V  coprocessor
*/

#include <stdint.h>
#include "ulp_riscv_utils.h"
#include "ulp_riscv_adc_ulp_core.h"
#include "ulp_riscv_gpio.h"
#include <stdio.h>
#include "example_config.h"

#if 0
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"

extern QueueHandle_t sleep_queue;
extern QueueHandle_t wakeup_queue;
#else

#include "user_sleep.h"

#endif


uint32_t adc_threshold = EXAMPLE_ADC_TRESHOLD;
int32_t wakeup_result = 0x00000000;


uint32_t  last_power_chargeing_status = 1; 
uint32_t  new_power_chargeing_status  = 1; 


int main (void)
{
    uint8_t button_info = 0;
    uint8_t name = 0;

    //adc_ll_set_power_manage(ADC_POWER_BY_FSM);
    int32_t last_result = ulp_riscv_adc_read_channel(EXAMPLE_ADC_UNIT, EXAMPLE_ADC_CHANNEL); //key
    //adc_ll_set_power_manage(ADC_POWER_SW_OFF);
    //adc_ll_set_power_manage(ADC_POWER_BY_FSM);
    int32_t power_result = 0; //= ulp_riscv_adc_read_channel(EXAMPLE_ADC_UNIT, ADC_CHANNEL_3);       //power_key  
    //adc_ll_set_power_manage(ADC_POWER_SW_OFF);

    //sar_ctrl_ll_set_power_mode(SAR_CTRL_LL_POWER_OFF);  
    if (last_result < adc_threshold) {
        wakeup_result = last_result;

        #if 1
        //printf("start wake up\r\n");
        ulp_riscv_wakeup_main_processor();
        #else
        
        #endif
        
    }

    #if  0

    if(power_result <adc_threshold)
    {
        ulp_riscv_wakeup_main_processor();
    }
    #endif

    return 0;
}
