I'm using the touch pad in ESP32, the software example is nice, an IRQ handler get called when a pad is touched but I'm unable to have the information that the pad has been released.
Thus I've tried to use the touch_pad_read function but this function is blocking/stalling a little amount of time at the following line:
while (GET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_DONE) == 0) {};
Thus it does not fit my needs, I need a non blocking way to read the pad (either touched/untouched).
In sens_reg.h, I understand that the pad measure is handled by a timer.
Thus my question is what is this timer ? How can I get called (IRQ handler for instance) when the touch pad measure is done (SENS_SAR_TOUCH_CTRL2_REG->SENS_TOUCH_MEAS_DONE==1) ?
Best Regards,
Jerome
Getting Timer IRQ when touch pad measure is done
Re: Getting Timer IRQ when touch pad measure is done
I ended up with the following code:
Which basically return the previous value when the value is not ready and when the value is ready read it in a critical section.
It is not as good as gettting called when the value is ready but seems to work correctly in my context.
Code: Select all
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
extern portMUX_TYPE rtc_spinlock;
volatile uint16_t bits=0;
uint16_t get_bits()
{
uint8_t i, j = 0;
uint16_t touch_value;
if (GET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_DONE) == 0)
return bits;
portENTER_CRITICAL(&rtc_spinlock);
bits=0;
for (i = 0; i < 8; i++)
{
// Replaced by non blocking code
//touch_pad_read(bit_port[i], &touch_value);
j=bit_port[i];
uint8_t shift = (j & 1) ? SENS_TOUCH_MEAS_OUT1_S : SENS_TOUCH_MEAS_OUT0_S;
touch_value = READ_PERI_REG(SENS_SAR_TOUCH_OUT1_REG + (j / 2) * 4) >> shift;
if (touch_value<200)
bits|=(1<<i);
}
portEXIT_CRITICAL(&rtc_spinlock);
return bits;
}
It is not as good as gettting called when the value is ready but seems to work correctly in my context.
Re: Getting Timer IRQ when touch pad measure is done
Yes that is a good question how to get an interrupt when pad goes from touched to not-touched. Seems like SENS_TOUCH_OUT_SEL can be flipped but affects all pads not just one.
Re: Getting Timer IRQ when touch pad measure is done
My previously posted code is not totally working as expected, in some case I get false reading.
Probably because the critical section has no effect.
I tried to play with all IRQs source in RTC_CNTL_INT_ENA_REG but I will never get called when a touch measure is ready in the fsm ...
Probably because the critical section has no effect.
I tried to play with all IRQs source in RTC_CNTL_INT_ENA_REG but I will never get called when a touch measure is ready in the fsm ...
Who is online
Users browsing this forum: No registered users and 77 guests