|
| 1 | +/* |
| 2 | +* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates |
| 3 | +* |
| 4 | +* SPDX-License-Identifier: BSD-3-Clause |
| 5 | +*/ |
| 6 | + |
| 7 | +/*******************************************************************************************************************//** |
| 8 | + * @ingroup RENESAS_CAPTOUCH_INTERFACES |
| 9 | + * @defgroup TOUCH_API Touch Middleware Interface |
| 10 | + * @brief Interface for Touch Middleware functions. |
| 11 | + * |
| 12 | + * @section TOUCH_API_Summary Summary |
| 13 | + * The TOUCH interface provides TOUCH functionality. |
| 14 | + * |
| 15 | + * |
| 16 | + * @{ |
| 17 | + **********************************************************************************************************************/ |
| 18 | + |
| 19 | +#ifndef RM_TOUCH_API_H |
| 20 | +#define RM_TOUCH_API_H |
| 21 | + |
| 22 | +/*********************************************************************************************************************** |
| 23 | + * Includes |
| 24 | + **********************************************************************************************************************/ |
| 25 | + |
| 26 | +/* Register definitions, common services and error codes. */ |
| 27 | +#include "bsp_api.h" |
| 28 | +#include "r_ctsu_api.h" |
| 29 | +#include "r_uart_api.h" |
| 30 | + |
| 31 | +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ |
| 32 | +FSP_HEADER |
| 33 | + |
| 34 | +/********************************************************************************************************************** |
| 35 | + * Macro definitions |
| 36 | + **********************************************************************************************************************/ |
| 37 | + |
| 38 | +#define TOUCH_COUNT_MAX CTSU_COUNT_MAX ///< Value of Maximum count |
| 39 | +#define TOUCH_OFF_VALUE (0xFFFF) ///< Value of Non-touch |
| 40 | + |
| 41 | +/********************************************************************************************************************** |
| 42 | + * Typedef definitions |
| 43 | + **********************************************************************************************************************/ |
| 44 | + |
| 45 | +/** Control block. Allocate an instance specific control block to pass into the API calls. |
| 46 | + */ |
| 47 | +typedef void touch_ctrl_t; |
| 48 | + |
| 49 | +/** Configuration of each button */ |
| 50 | +typedef struct st_touch_button_cfg |
| 51 | +{ |
| 52 | + uint8_t elem_index; ///< Element number used by this button. |
| 53 | + uint16_t threshold; ///< Touch/non-touch judgment threshold |
| 54 | + uint16_t hysteresis; ///< Threshold hysteresis for chattering prevention. |
| 55 | +} touch_button_cfg_t; |
| 56 | + |
| 57 | +/** Configuration of each slider */ |
| 58 | +typedef struct st_touch_slider_cfg |
| 59 | +{ |
| 60 | + uint8_t const * p_elem_index; ///< Element number array used by this slider. |
| 61 | + uint8_t num_elements; ///< Number of elements used by this slider. |
| 62 | + uint16_t threshold; ///< Position calculation start threshold value. |
| 63 | +} touch_slider_cfg_t; |
| 64 | + |
| 65 | +/** Configuration of each wheel */ |
| 66 | +typedef struct st_touch_wheel_cfg_t |
| 67 | +{ |
| 68 | + uint8_t const * p_elem_index; ///< Element number array used by this wheel. |
| 69 | + uint8_t num_elements; ///< Number of elements used by this wheel. |
| 70 | + uint16_t threshold; ///< Position calculation start threshold value. |
| 71 | +} touch_wheel_cfg_t; |
| 72 | + |
| 73 | +/** Configuration of each pads */ |
| 74 | +typedef struct st_touch_pad_cfg_t |
| 75 | +{ |
| 76 | + uint8_t const * p_elem_index_rx; ///< RX of element number arrays used by this pad. |
| 77 | + uint8_t const * p_elem_index_tx; ///< TX of element number arrays used by this pad. |
| 78 | + uint8_t num_elements; ///< Number of elements used by this pad. |
| 79 | + uint16_t threshold; ///< Coordinate calculation threshold value. |
| 80 | + uint16_t rx_pixel; ///< rx coordinate resolution |
| 81 | + uint16_t tx_pixel; ///< tx coordinate resolution |
| 82 | + uint8_t max_touch; ///< Maximum number of touch judgments used by the pad. |
| 83 | + uint8_t num_drift; ///< Number of pad drift. |
| 84 | +} touch_pad_cfg_t; |
| 85 | + |
| 86 | +/** Callback function parameter data */ |
| 87 | +typedef struct st_ctsu_callback_args touch_callback_args_t; |
| 88 | + |
| 89 | +/** User configuration structure, used in open function */ |
| 90 | +typedef struct st_touch_cfg |
| 91 | +{ |
| 92 | + touch_button_cfg_t const * p_buttons; ///< Pointer to array of button configuration. |
| 93 | + touch_slider_cfg_t const * p_sliders; ///< Pointer to array of slider configuration. |
| 94 | + touch_wheel_cfg_t const * p_wheels; ///< Pointer to array of wheel configuration. |
| 95 | + touch_pad_cfg_t const * p_pad; ///< Pointer of pad configuration. |
| 96 | + uint8_t num_buttons; ///< Number of buttons. |
| 97 | + uint8_t num_sliders; ///< Number of sliders. |
| 98 | + uint8_t num_wheels; ///< Number of wheels. |
| 99 | + uint8_t on_freq; ///< The cumulative number of determinations of ON. |
| 100 | + uint8_t off_freq; ///< The cumulative number of determinations of OFF. |
| 101 | + uint16_t drift_freq; ///< Base value drift frequency. [0 : no use] |
| 102 | + uint16_t cancel_freq; ///< Maximum continuous ON. [0 : no use] |
| 103 | + uint8_t number; ///< Configuration number for QE monitor. |
| 104 | + ctsu_instance_t const * p_ctsu_instance; ///< Pointer to CTSU instance. |
| 105 | + uart_instance_t const * p_uart_instance; ///< Pointer to UART instance. |
| 106 | + void const * p_context; ///< User defined context passed into callback function. |
| 107 | + void const * p_extend; ///< Pointer to extended configuration by instance of interface. |
| 108 | +} touch_cfg_t; |
| 109 | + |
| 110 | +/** Configuration of each touch sensitivity information */ |
| 111 | +typedef struct st_touch_sensitivity_info |
| 112 | +{ |
| 113 | + uint16_t * p_touch_sensitivity_ratio; ///< Pointer to sensitivity ratio array. |
| 114 | + uint16_t old_threshold_ratio; ///< Old threshold ratio. |
| 115 | + uint16_t new_threshold_ratio; ///< New threshold ratio. |
| 116 | + uint8_t new_hysteresis_ratio; ///< New hysteresis ratio. |
| 117 | +} touch_sensitivity_info_t; |
| 118 | + |
| 119 | +/** Functions implemented at the HAL layer will follow this API. */ |
| 120 | +typedef struct st_touch_api |
| 121 | +{ |
| 122 | + /** Open driver. |
| 123 | + * |
| 124 | + * @param[in] p_ctrl Pointer to control structure. |
| 125 | + * @param[in] p_cfg Pointer to pin configuration structure. |
| 126 | + */ |
| 127 | + fsp_err_t (* open)(touch_ctrl_t * const p_ctrl, touch_cfg_t const * const p_cfg); |
| 128 | + |
| 129 | + /** Scan start. |
| 130 | + * |
| 131 | + * @param[in] p_ctrl Pointer to control structure. |
| 132 | + */ |
| 133 | + fsp_err_t (* scanStart)(touch_ctrl_t * const p_ctrl); |
| 134 | + |
| 135 | + /** Data get. |
| 136 | + * |
| 137 | + * @param[in] p_ctrl Pointer to control structure. |
| 138 | + * @param[out] p_button_status Pointer to get data bitmap. |
| 139 | + * @param[out] p_slider_position Pointer to get data array. |
| 140 | + * @param[out] p_wheel_position Pointer to get data array. |
| 141 | + */ |
| 142 | + fsp_err_t (* dataGet)(touch_ctrl_t * const p_ctrl, uint64_t * p_button_status, uint16_t * p_slider_position, |
| 143 | + uint16_t * p_wheel_position); |
| 144 | + |
| 145 | + /** ScanStop. |
| 146 | + * |
| 147 | + * @param[in] p_ctrl Pointer to control structure. |
| 148 | + */ |
| 149 | + fsp_err_t (* scanStop)(ctsu_ctrl_t * const p_ctrl); |
| 150 | + |
| 151 | + /** pad data get. |
| 152 | + * |
| 153 | + * @param[in] p_ctrl Pointer to control structure. |
| 154 | + * @param[out] p_pad_rx_coordinate Pointer to get coordinate of receiver side. |
| 155 | + * @param[out] p_pad_tx_coordinate Pointer to get coordinate of transmitter side. |
| 156 | + * @param[out] p_pad_num_touch Pointer to get touch count. |
| 157 | + */ |
| 158 | + fsp_err_t (* padDataGet)(touch_ctrl_t * const p_ctrl, uint16_t * p_pad_rx_coordinate, |
| 159 | + uint16_t * p_pad_tx_coordinate, uint8_t * p_pad_num_touch); |
| 160 | + |
| 161 | + /** Specify callback function and optional context pointer and working memory pointer. |
| 162 | + * |
| 163 | + * @param[in] p_ctrl Pointer to the CTSU control block. |
| 164 | + * @param[in] p_callback Callback function |
| 165 | + * @param[in] p_context Pointer to send to callback function |
| 166 | + * @param[in] p_working_memory Pointer to volatile memory where callback structure can be allocated. |
| 167 | + * Callback arguments allocated here are only valid during the callback. |
| 168 | + */ |
| 169 | + fsp_err_t (* callbackSet)(touch_ctrl_t * const p_ctrl, void (* p_callback)(touch_callback_args_t *), |
| 170 | + void const * const p_context, touch_callback_args_t * const p_callback_memory); |
| 171 | + |
| 172 | + /** Close driver. |
| 173 | + * |
| 174 | + * @param[in] p_ctrl Pointer to control structure. |
| 175 | + */ |
| 176 | + fsp_err_t (* close)(touch_ctrl_t * const p_ctrl); |
| 177 | + |
| 178 | + /** Sensitivity ratio get. |
| 179 | + * |
| 180 | + * @param[in] p_ctrl Pointer to control structure. |
| 181 | + * @param[in,out] p_touch_sensitivity_info Pointer to touch sensitivity structure. |
| 182 | + */ |
| 183 | + fsp_err_t (* sensitivityRatioGet)(touch_ctrl_t * const p_ctrl, touch_sensitivity_info_t * p_touch_sensitivity_info); |
| 184 | + |
| 185 | + /** Threshold adjust. |
| 186 | + * |
| 187 | + * @param[in] p_ctrl Pointer to control structure. |
| 188 | + * @param[in] p_touch_sensitivity_info Pointer to touch sensitivity structure. |
| 189 | + */ |
| 190 | + fsp_err_t (* thresholdAdjust)(touch_ctrl_t * const p_ctrl, touch_sensitivity_info_t * p_touch_sensitivity_info); |
| 191 | + |
| 192 | + /** Drift control. |
| 193 | + * |
| 194 | + * @param[in] p_ctrl Pointer to control structure. |
| 195 | + * @param[in] input_drift_freq Drift frequency value. |
| 196 | + */ |
| 197 | + fsp_err_t (* driftControl)(touch_ctrl_t * const p_ctrl, uint16_t input_drift_freq); |
| 198 | +} touch_api_t; |
| 199 | + |
| 200 | +/** This structure encompasses everything that is needed to use an instance of this interface. */ |
| 201 | +typedef struct st_touch_instance |
| 202 | +{ |
| 203 | + touch_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance |
| 204 | + touch_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance |
| 205 | + touch_api_t const * p_api; ///< Pointer to the API structure for this instance |
| 206 | +} touch_instance_t; |
| 207 | + |
| 208 | +/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ |
| 209 | +FSP_FOOTER |
| 210 | + |
| 211 | +#endif /* RM_TOUCH_API_H */ |
| 212 | + |
| 213 | +/*******************************************************************************************************************//** |
| 214 | + * @} (end addtogroup TOUCH_API) |
| 215 | + **********************************************************************************************************************/ |
0 commit comments