-
Notifications
You must be signed in to change notification settings - Fork 973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: TSC #1098
Comments
Any contribution are welcome. |
According to one of the datasheets, it's as simple as copy-pasting the following init code: /* Configure TCS */
/* With a charge transfer around 2.5μs */
/* (1) Select fPGCLK = fHCLK/32,
Set pulse high = 2xtPGCLK,Master
Set pulse low = 2xtPGCLK
Set Max count value = 16383 pulses
Enable TSC */
/* (2) Disable hysteresis */
/* (3) Enable end of acquisition IT */
/* (4) Sampling enabled, G2IO4 */
/* (5) Channel enabled, G2IO3 */
/* (6) Enable group, G2 */
TSC->CR = TSC_CR_PGPSC_2 | TSC_CR_PGPSC_0 | TSC_CR_CTPH_0 | TSC_CR_CTPL_0
| TSC_CR_MCV_2 | TSC_CR_MCV_1 | TSC_CR_TSCE; /* (1) */
TSC->IOHCR &= (uint32_t)(~(TSC_IOHCR_G2_IO4 | TSC_IOHCR_G2_IO3)); /* (2) */
TSC->IER = TSC_IER_EOAIE; /* (3) */
TSC->IOSCR = TSC_IOSCR_G2_IO4; /* (4) */
TSC->IOCCR = TSC_IOCCR_G2_IO3; /* (5) */
TSC->IOGCSR |= TSC_IOGCSR_G2E; /* (5) */ And then creating (???) an interrupt: /* End of acquisition flag */
if((TSC->ISR & TSC_ISR_EOAF) == TSC_ISR_EOAF) {
TSC->ICR = TSC_ICR_EOAIC; /* Clear flag */
AcquisitionValue = TSC->IOGXCR[1]; /* Get G2 counter value */
} In its most simple form, what would be required to get from that to something like this: bool led_state = false;
void toggle_led()
{
led_state = !led_state;
}
void main()
{
/* i didn't check if PB14 and PB15 match with the above example! */
pinMode(PB14, INPUT);
pinMode(PB15, INPUT);
attachTSC(digitalPinToInterrupt(PB14), digitalPinToInterrupt(PB15)), toggle_led, CHANGE);
}
void loop()
{
digitalWrite(LED_BUILTIN, led_state);
} With my extremely limited understanding of the code from the datasheet, it seems to me that just implementing that imaginary |
Sorry to revive an old issue. I don't think it's necessary to play around with the registers, or sift through the 1000 page reference manuals; The repository already hosts the
The TSC configuration and initialization is done automatically by configuring the .ioc file in ST's IDE (even the NB: In my project there is also a Hope any of this helps. I agree it would be great to have touch sensing implemented in a project like this. |
I have a similar issue with a NUCLEO-F072RB did you make it work? |
Sorry, I moved on to esp32. |
I was able to get this to work with a STM32WB5MM-DK. I did the following (it took me awhile and I went through quite a bit of trial and error before I was able to get things working):
Logic works for me with the tsc_value returned when not touching as a mostly consistent value and once I touch it I noticed it drops about 80 or so which I then used as the trigger. There was additional touch sensing logic from the STM32 examples but I struggled to even get this part and touching itself working so I am just happy it works consistently with this approach and stm32duino. Passing along in case it's helpful to anyone else. Works with touch detection of button presses at least as a start here. Quite a bit of code to figure out if one button is pressed but I felt absolutely terrible about leaving the giant touch button unused on my development kit so pressed on to this point of at least working. |
Knowing about #247, which seems to be about touch screens only, I'd like to request the feature of touch sensing control to be added to Arduino_Core_STM32. The TSC is part of many STM32s, even down to the STM32F042x4 series, and using touch buttons is quite popular, so I think it would be a good thing to have available without having to resort to direct HAL programming.
The text was updated successfully, but these errors were encountered: