ADS7846 example

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • ADS7846 example

    Do you have any example of using the GUITDRV_ADS7846 touchscreen driver?

    The info in the manual is a bit lacking, an example of the GUITDRV_ADS7846_CONFIG pfSendCmd and pfGetResult callbacks would be very helpful.

    Regards
  • Hi,

    The attachment shows a sample how to use the driver.

    Regards
    Files
    • TouchConf.zip

      (2.08 kB, downloaded 1,170 times, last: )
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Thanks for the reply, still struggling to get your driver working however. See my code below.
    I have tested that I am getting valid data back from the touch controller, stepping through the assembly it appears to never call GUI_TOUCH_StoreStateEx.

    As another test I wrote a new driver and called GUI_TOUCH_StoreStateEx myself, this is actually working ok.

    Cheers

    Source Code

    1. static void platform_touch_send_cmd(U8 Data)
    2. {
    3. /* Sends a 8-bit command to the peripheral */
    4. HAL_StatusTypeDef status = HAL_SPI_Transmit(&handle_spi, &Data, 1, 100);
    5. if (status != HAL_OK) {
    6. DEBUG_BREAK();
    7. }
    8. }
    9. static U16 platform_touch_get_result(void)
    10. {
    11. /* Retrieves the result of the AD conversion. */
    12. uint8_t buffer[2] = {0};
    13. uint8_t dummy[2] = {0};
    14. HAL_StatusTypeDef status = HAL_SPI_TransmitReceive(&handle_spi, dummy, buffer, 2, 100);
    15. if (status != HAL_OK) {
    16. DEBUG_BREAK();
    17. }
    18. uint16_t result = be_to_h_u16(buffer);
    19. result >>= 3;
    20. return result;
    21. }
    22. static char platform_touch_get_busy(void)
    23. {
    24. /* Retrieves the status of the busy line. 0: Not busy; 1: Busy */
    25. //GPIO_PinState gpio_state = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_1);
    26. //return (gpio_state == GPIO_PIN_SET);
    27. return 0;
    28. }
    29. static void platform_touch_set_cs(char OnOff)
    30. {
    31. /* Set chip select line. OnOff == 1 means peripheral selected */
    32. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, (OnOff == 1) ? GPIO_PIN_RESET : GPIO_PIN_SET);
    33. }
    34. static char platform_touch_get_penirq(void)
    35. {
    36. /* Retrieves the status of the PENIRQ line to detect a touch event.
    37. * return 1 if a touch event is recognized and 0 if not. */
    38. GPIO_PinState gpio_state = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_0);
    39. return (gpio_state == GPIO_PIN_RESET);
    40. }
    41. static GUITDRV_ADS7846_CONFIG touch_config = {
    42. .pfSendCmd = platform_touch_send_cmd,
    43. .pfGetResult = platform_touch_get_result,
    44. .pfGetBusy = platform_touch_get_busy,
    45. .pfSetCS = platform_touch_set_cs,
    46. .Orientation = GUI_MIRROR_Y,
    47. .xLog0 = 0,
    48. .xLog1 = (PANEL_WIDTH - 1),
    49. .xPhys0 = 0,
    50. .xPhys1 = 4095,
    51. .yLog0 = 0,
    52. .yLog1 = (PANEL_HEIGHT - 1),
    53. .yPhys1 = 0,
    54. .yPhys0 = 4095,
    55. .pfGetPENIRQ = platform_touch_get_penirq,
    56. };
    Display All