2021-05-23 20:02:15 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-02-25 09:19:48 -05:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2020-07-21 01:07:34 -04:00
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "esp_types.h"
|
2020-02-25 09:19:48 -05:00
|
|
|
#include "esp_log.h"
|
|
|
|
#include "sys/lock.h"
|
|
|
|
#include "soc/rtc.h"
|
|
|
|
#include "soc/periph_defs.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/xtensa_api.h"
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
#include "freertos/timers.h"
|
|
|
|
#include "esp_intr_alloc.h"
|
|
|
|
#include "driver/rtc_io.h"
|
|
|
|
#include "driver/rtc_cntl.h"
|
|
|
|
#include "driver/gpio.h"
|
|
|
|
#include "driver/adc.h"
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Enable built-in checks in queue.h in debug builds
|
|
|
|
#define INVARIANTS
|
|
|
|
#endif
|
|
|
|
#include "sys/queue.h"
|
|
|
|
#include "hal/adc_types.h"
|
|
|
|
#include "hal/adc_hal.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define ADC_GET_IO_NUM(periph, channel) (adc_channel_io_map[periph][channel])
|
|
|
|
|
|
|
|
|
|
|
|
extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished.
|
|
|
|
#define ADC_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock)
|
|
|
|
#define ADC_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock)
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------
|
|
|
|
HALL SENSOR
|
|
|
|
---------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int hall_sensor_get_value(void) //hall sensor without LNA
|
|
|
|
{
|
|
|
|
int hall_value;
|
|
|
|
|
2020-12-03 00:58:24 -05:00
|
|
|
adc_power_acquire();
|
2020-02-25 09:19:48 -05:00
|
|
|
|
|
|
|
ADC_ENTER_CRITICAL();
|
|
|
|
/* disable other peripherals. */
|
2021-12-21 22:17:42 -05:00
|
|
|
adc_ll_amp_disable();
|
|
|
|
adc_ll_hall_enable();
|
2020-02-25 09:19:48 -05:00
|
|
|
// set controller
|
2021-12-21 22:17:42 -05:00
|
|
|
adc_ll_set_controller( ADC_NUM_1, ADC_LL_CTRL_RTC );
|
2020-02-25 09:19:48 -05:00
|
|
|
hall_value = adc_hal_hall_convert();
|
2021-12-21 22:17:42 -05:00
|
|
|
adc_ll_hall_disable();
|
2020-02-25 09:19:48 -05:00
|
|
|
ADC_EXIT_CRITICAL();
|
|
|
|
|
2020-12-03 00:58:24 -05:00
|
|
|
adc_power_release();
|
2020-02-25 09:19:48 -05:00
|
|
|
return hall_value;
|
|
|
|
}
|
|
|
|
|
2021-12-21 22:17:42 -05:00
|
|
|
/**
|
|
|
|
* To Be Deprecated
|
|
|
|
*/
|
|
|
|
extern esp_err_t adc_common_gpio_init(adc_unit_t adc_unit, adc_channel_t channel);
|
2020-02-25 09:19:48 -05:00
|
|
|
int hall_sensor_read(void)
|
|
|
|
{
|
2021-12-21 22:17:42 -05:00
|
|
|
adc_common_gpio_init(ADC_UNIT_1, ADC1_CHANNEL_0);
|
|
|
|
adc_common_gpio_init(ADC_UNIT_1, ADC1_CHANNEL_3);
|
2020-02-25 09:19:48 -05:00
|
|
|
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_0);
|
|
|
|
adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_0);
|
|
|
|
return hall_sensor_get_value();
|
2020-07-29 08:46:37 -04:00
|
|
|
}
|