6.5 Touch Peripheral

Capacitive Voltage Divider (CVD), also known as the Touch peripheral module, to the application by following these steps.
  1. Download and install the Harmony 3 Dependencies, which include the touch library required for configuration and code generation related to the Touch peripheral module. For more details, refer to Install Harmony 3 Dependencies from Related Links section.
  2. In the Project Graph, the user must add the Touch component.
    Note: The use can adjust the available settings for the touch library and any related components as per the requirement.
  3. Upon code generation, the user can access the code generated for the touch library and related components.
  4. The BLE Transparent UART with Touch peripheral application example is available in the wireless_apps_pic32_bz6/apps/ble/peripheral_applications/touch_peripheral_trp_uart. For more details, see BLE + Touch Transparent UART from Related Links.

For more details on different Touch configuration parameters, refer to QTouch Modular Library Peripheral Touch Controller User’s Guide (DS40001986) in Reference Documentation from Related Links.

Application Development

The MCC code generation generates the touch_example.c, which includes the sample application implementation. The touch_mainloop_example() API implements the periodic touch measurement initiation. The task handler in app.c needs to call this API .

The following are the steps to include touch application functionality:
  1. In order to go in sync with wireless task and application task, touch message to be posted in application task queue whenever the periodic RTC timerhanlder is triggered. Add the highlighted code in touch_timer_handler() of touch.c.
    void touch_timer_handler(void)
    {
    APP_Msg_T appMsg;
    time_to_measure_touch_var = 1u;
    qtm_update_qtlib_timer(DEF_TOUCH_MEASUREMENT_PERIOD_MS);
    appMsg.msgId = APP_MSG_TOUCH_MEAS;
    OSAL_QUEUE_SendISR(&appData.appQueue, &appMsg);
    }
  2. Add the APP_MSG_TOUCH_MEAS message ID in APP_MsgId_T of app.h.
    typedef enum APP_MsgId_T
    {
    APP_MSG_BLE_STACK_EVT,
    APP_MSG_TOUCH_MEAS,
    APP_MSG_STACK_END
    } APP_MsgId_T;
  3. The application task needs to call the touch_mainloop_example() API to perform periodic measurement of touch inputs.
    case APP_STATE_SERVICE_TASKS:
    {
    if (OSAL_QUEUE_Receive(&appData.appQueue, &appMsg, OSAL_WAIT_FOREVER))
    {
    if(p_appMsg->msgId==APP_MSG_BLE_STACK_EVT)
    {
    // Pass BLE Stack Event Message to User Application for handling
    APP_BleStackEvtHandler((STACK_Event_T *)p_appMsg->msgData);
    }
    else if(p_appMsg->msgId== APP_MSG_TOUCH_MEAS)
    {
    Touch_MainLoop()
    }
  4. The user can customize the Touch_Mainloop to perform the needed functions by reading the touch input status when the measurement_done_touch is set.