diff --git a/main/power_profiler.c b/main/power_profiler.c index 650d222..c970451 100644 --- a/main/power_profiler.c +++ b/main/power_profiler.c @@ -7,18 +7,22 @@ #include "esp_adc/adc_cali.h" #include "esp_adc/adc_continuous.h" #include "esp_adc/adc_oneshot.h" +#include "esp_intr_alloc.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/portmacro.h" #include "hal/adc_types.h" +#include "hal/gpio_types.h" #include "resistor_ranges.h" #include "measure.h" #include "soc/soc_caps.h" #define TAG "main" +#define OVERRANGE_PIN 4 + enum ranges {R1, R10, R100, R_NUM}; resistor_range ranges[] = { @@ -87,7 +91,27 @@ static bool IRAM_ATTR on_conv_done(adc_continuous_handle_t handle, const adc_con return false; } +char overrange_flag = 0; + +static void IRAM_ATTR overrange_handler(void* arg) +{ + overrange_flag = 1; +} + void app_main(void){ + gpio_config_t overrange_input = { + .intr_type = GPIO_INTR_POSEDGE, + .mode = GPIO_MODE_INPUT, + .pin_bit_mask = 1ULL << OVERRANGE_PIN, + .pull_down_en = 0, + .pull_up_en = 0, + }; + gpio_config(&overrange_input); + + gpio_install_isr_service(0); + + gpio_isr_handler_add(OVERRANGE_PIN, overrange_handler, NULL); + set_resistor_gpio(ranges, R100); activate_range(ranges, R100, R100); @@ -127,6 +151,9 @@ void app_main(void){ ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc_conv_h[i], meas_res_buff[i]/meas_nb_buff[i], &mv)); ESP_LOGI(TAG, "IN %d : %d mV (%d / %d)", i, mv, meas_res_buff[i], meas_nb_buff[i]); } + + ESP_LOGI(TAG, "overrange %d", overrange_flag); + overrange_flag = 0; //activate_range(ranges, r_ind, R100); vTaskDelay(5000 / portTICK_PERIOD_MS);