GUI Input Device Additional Notes

SDK supports multiple input devices, among which the following input devices have corresponding input subsystem support in the HoneyGUI framework: TouchPad, keyboard, and wheel. The HoneyGUI documentation has provided some introduction to the input subsystem and porting instructions, which can be referenced at GUI Input Subsystem .

This article provides additional explanations on the porting of input devices, related algorithms, and the event response of input devices.

TouchPad

Module Touch

  • In module_touch_common.c, some common behaviors of the TouchPad are defined, such as device initialization, interrupt service function implementation, and data retrieval interface implementation.

  • In touch_xxxx.c, the read and write implementation of different touch drivers is defined.

  • After calling touch_driver_init() to initialize the touch device, the touch information will first be responded to by an interrupt at TOUCH_INT_HANDLER.

  • The interrupt service function needs to call rtk_touch_hal_read_all() to collect the raw touch data and fill it into the TOUCH_DATA structure.

    • The raw data includes initial touch and current touch coordinate information as well as timestamps, etc.

    • TOUCH_DATA information is obtained through the get_raw_touch_data() interface.

  • At the same time, an OS timer will start to monitor whether the touch behavior has ended. The timeout parameter is set through touch_set_timeout_ms().

GUI Migration

  1. port_touchpad_get_data(): This function will call get_raw_touch_data(), obtain TOUCH_DATA, and pass it to gui_touch_port_data_t().

  2. Initialization of the gui_indev structure: Mainly involves the registration of the port interface and the time settings for behaviors such as long press, short press, swipe, and release.

  3. In gui_port_indev_init(), the release time (touch_timeout_ms) also needs to be set, which must be consistent with the OS timer timeout of the module touch.

GUI TouchPad Algorithm

The SDK uses tp_algo_v2.c as the GUI Touch algorithm. This version primarily decouples the dependence of TouchPad data updates on the GUI server task operation. The touchpad algorithm function tp_algo_process() is called at an early stage of the GUI server task operation, and after computation, fills coordinate information, event types, and other data into the touch_info_t structure.

GUI TouchPad Event Response

  • The structure touch_info_t is usually called during the draw prepare process of controls to obtain tp_get_info(), and then different events are reported to controls based on the obtained touch information.

  • Subsequently, gui_obj_event_set() is called to set the event that the current control needs to respond to in the current frame.

  • The upper-layer application of the GUI needs to bind events and callback functions through the gui_obj_add_event_cb() interface. During the draw end process of controls, these events will be collected and responded to sequentially after the draw end process of all controls is completed.

Note

  • The gui_obj_add_event_cb() interface is usually encapsulated by GUI controls into an API with specific behavioral significance. It is recommended to use the API of GUI controls to complete the binding of events and callback functions.

  • Some controls, such as curtains and tabs, respond in real-time to touch actions. These actions are usually handled during the draw prepare process of the control.

Code Example

In this example, a win control is created. Through gui_win_long(), the function win_benchmark_start_cb() is bound to a long-press action, achieving the execution of app_benchmark_start() upon a long press in the win interface.

static void prepare(gui_obj_t *obj)
{
   touch_info_t *tp = tp_get_info();
   gui_win_t *this = (void *)obj;
...
      case TOUCH_LONG:
            {
               if (this->long_flag == false)
               {
                  this->long_flag = true;
                  gui_obj_event_set(obj, GUI_EVENT_TOUCH_LONG);
               }
            }
            break;
...
}

static void win_benchmark_start_cb(void *obj, uint16_t event, void *param)
{
   switch (event)
   {
   case GUI_EVENT_TOUCH_LONG:
      {
            app_benchmark_start();
      }
      break;
...
   }
}
void design_tab_benchmark_main(void *parent)
{
...
   gui_win_t *win = gui_win_create(parent, "win_benchmark_main", 0, 0, 0, 0);
   gui_win_long(win, win_benchmark_start_cb, NULL);
...
}

Keyboard

Module Button

  • In module_button.c, some behaviors of the GPIO Button are defined, including initialization, interrupt service functions, debounce handling, etc.

  • The GPIO_BUTTON_HANDLER interrupt service function needs to call GPIOx_ReadInputDataBit to read the input polarity of the specified GPIO, and start a 20ms OS timer for debounce handling.

  • After debouncing, the current GPIO input polarity, read id, timestamp, and other information will be stored in the T_GPIO_KEY structure.

    • gpio_button_read_key() interface is used to obtain the T_GPIO_KEY structure.

GUI Porting

  1. port_kb_get_data(): This function processes the T_GPIO_KEY structure simply and then passes it to the kb_port_data structure.

  2. Initialization of the gui_indev structure: Mainly involves registration of the port interface and setting the time for long press and short press behaviors.

GUI Keyboard Algorithm

The SDK uses kb_algo.c keyboard algorithm, which is similar to tp_algo_v2.c. The algorithm function kb_algo_process() is called early during the execution of the GUI server task, and after computation, it stores the button's state information, event type, and other data into the kb_info_t structure.

GUI Keyboard Event Response

  • The kb_info_t structure is typically called during the draw prepare process of a widget, using kb_get_info() to obtain it, and then different events are reported to the widget based on the obtained button information.

  • Subsequently, gui_obj_event_set() is called to set the event that the current widget needs to respond to in the current frame.

  • The upper layer of the GUI application needs to bind events and callback functions using the gui_obj_add_event_cb() interface. During the draw end process of a widget, these events are collected and responded to sequentially after the draw end process of all widgets is completed.

  • The KEY1 button on the EVB is used for the LCD wake-up function. To ensure real-time wake-up, it is processed by directly sending a message to the GUI task in the debounce function, waking up gui_wake_up_by_button().

Wheel

Module QDEC

  • The file module_qdec.c defines some behaviors of the QDEC, including initialization, interrupt service functions, etc.

  • The interrupt service function QDEC_Handler obtains data from the qdec peripheral by calling QDEC_GetAxisDirection and stores it in the T_QDEC_DATA structure. The qdec_read_data() interface is used to retrieve data from the T_QDEC_DATA structure.

GUI Porting

  1. port_wheel_get_data(): This function processes the T_GPIO_KEY structure and passes it to the wheel_port_data structure.

  2. Initialization of the gui_indev structure: Mainly involves registration of the port interface.

  3. port_wheel_reset_prev_count(): Used to reset some counts after the screen turns off.

GUI Wheel Algorithm

The SDK uses the file wheel_algo.c for the wheel algorithm, which is similar to tp_algo_v2.c. The algorithm function wheel_algo_process() is called early in the GUI server task execution, and after calculation, it stores the wheel movement steps, status information, event types, and other data in the touch_info_t structure.

GUI Wheel Event Response

  • The structure touch_info_t is usually called during the draw prepare process of a widget using wheel_get_info() to obtain information, then reports different events to the widget based on the obtained button information.

  • Subsequently, gui_obj_event_set() is called to set the event that the current widget needs to respond to in the current frame.

  • The GUI upper-layer application needs to bind events and callback functions through the interface gui_obj_add_event_cb(). During the draw end process of the widget, these events will be collected and responded to sequentially after the draw end process of all widgets is completed.

  • Currently, perspective controls and page controls support some simple operations of the wheel.