Getting Timer IRQ when touch pad measure is done

jedail
Posts: 3
Joined: Wed Jan 11, 2017 7:50 am

Getting Timer IRQ when touch pad measure is done

Postby jedail » Tue Jan 31, 2017 9:59 am

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

jedail
Posts: 3
Joined: Wed Jan 11, 2017 7:50 am

Re: Getting Timer IRQ when touch pad measure is done

Postby jedail » Wed Feb 01, 2017 9:34 am

I ended up with the following code:

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;
}
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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Getting Timer IRQ when touch pad measure is done

Postby WiFive » Fri Feb 03, 2017 5:12 am

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.

jedail
Posts: 3
Joined: Wed Jan 11, 2017 7:50 am

Re: Getting Timer IRQ when touch pad measure is done

Postby jedail » Fri Feb 03, 2017 9:41 am

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 ...

mezzynine
Posts: 12
Joined: Fri Feb 07, 2020 8:05 am

Re: Getting Timer IRQ when touch pad measure is done

Postby mezzynine » Wed Sep 08, 2021 7:17 pm

hi, did you ever figure this out, interrupt on going from touch to non-touch?
WiFive wrote:
Fri Feb 03, 2017 5:12 am
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.

Who is online

Users browsing this forum: No registered users and 137 guests