From 3dc3db76f583b2bacd21f41622b14d6f3ce580b5 Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Wed, 9 Jun 2021 08:53:08 -0600 Subject: [PATCH 1/3] Convert hall read to use hal/idf --- cores/esp32/esp32-hal-adc.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index 37503ba0386..c5241a63e52 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -245,28 +245,11 @@ void __analogSetVRefPin(uint8_t pin){ __analogVRefPin = pin; } -int __hallRead() //hall sensor without LNA +int __hallRead() //hall sensor using idf read { - int Sens_Vp0; - int Sens_Vn0; - int Sens_Vp1; - int Sens_Vn1; - pinMode(36, ANALOG); pinMode(39, ANALOG); - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_XPD_HALL_FORCE_M); // hall sens force enable - SET_PERI_REG_MASK(RTC_IO_HALL_SENS_REG, RTC_IO_XPD_HALL); // xpd hall - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_HALL_PHASE_FORCE_M); // phase force - CLEAR_PERI_REG_MASK(RTC_IO_HALL_SENS_REG, RTC_IO_HALL_PHASE); // hall phase - Sens_Vp0 = __analogRead(36); - Sens_Vn0 = __analogRead(39); - SET_PERI_REG_MASK(RTC_IO_HALL_SENS_REG, RTC_IO_HALL_PHASE); - Sens_Vp1 = __analogRead(36); - Sens_Vn1 = __analogRead(39); - SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S); - CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_XPD_HALL_FORCE); - CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_HALL_PHASE_FORCE); - return (Sens_Vp1 - Sens_Vp0) - (Sens_Vn1 - Sens_Vn0); + return hall_sensor_read(); } #endif From 88e8f16de2349065ea2c82fbca951d3c908a1799 Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Wed, 9 Jun 2021 16:58:58 -0600 Subject: [PATCH 2/3] docs say to set width first. --- cores/esp32/esp32-hal-adc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index c5241a63e52..ff8de1bafc5 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -249,6 +249,7 @@ int __hallRead() //hall sensor using idf read { pinMode(36, ANALOG); pinMode(39, ANALOG); + adcSetWidth(12); return hall_sensor_read(); } #endif From 064cae1d503c025fb9d5b271bae550eddb21dfa9 Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Wed, 9 Jun 2021 17:06:17 -0600 Subject: [PATCH 3/3] Urgh. Right function this time --- cores/esp32/esp32-hal-adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index ff8de1bafc5..44230e9b545 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -249,7 +249,7 @@ int __hallRead() //hall sensor using idf read { pinMode(36, ANALOG); pinMode(39, ANALOG); - adcSetWidth(12); + __analogSetWidth(12); return hall_sensor_read(); } #endif