zoukankan      html  css  js  c++  java
  • MiniGUI ial 移植指南

    MiniGUI ial 移植指南
    2.1 ial的定义
    ial是一个通用的抽象输入接口,可以输入统一的数据的结构,也就是说在MiniGUI的核心代码里输入的数据的格式是固定的,不管输入设备是鼠标 还是触摸屏。简单地讲, 就是不管MiniGUI移植到什么操作系统之上,ial在MiniGUI中的代码是相同的,只需重新写入ial接口到操作系统设备之间的代码,这也就是所 谓的移植,这个类似与操作系统以下的驱动。驱动是为了连接系统内核和各种硬件,而ial是为了连接MiniGU和不同的操作系统,如果MiniGUI不需 要移植,也就没有必要定义ial接口。
    2.2 ial中的INPUT数据结构
    ial中的INPUT数据结构是移植的关键所在,这个结构体里面有好多指向函数的指针,ial初始化的时候从MiniGUI内核会送出一个 INPUT结构的数据指针, 用户把自己编写的各种函数指针赋给它,这样MiniGUI就可以间接调用用户的函数,这个方法特别类似Linux下驱动的编写方法。这个数据在 src/include/ial.h 定义:
     typedef struct tagINPUT
     {
        char*   id;
        // Initialization and termination
        BOOL (*init_input) (struct tagINPUT *input, const char* mdev, const char* mtype);
        void (*term_input) (void);
        // Mouse operations
        int  (*update_mouse) (void);
        void (*get_mouse_xy) (int* x, int* y);
        void (*set_mouse_xy) (int x, int y);
        int  (*get_mouse_button) (void);
        void (*set_mouse_range) (int minx, int miny, int maxx, int maxy);
        void (*suspend_mouse) (void);
        int (*resume_mouse) (void);
        // Keyboard operations
        int  (*update_keyboard) (void);
        const char* (*get_keyboard_state) (void);
        void (*suspend_keyboard) (void);
        int (*resume_keyboard) (void);
        void (*set_leds) (unsigned int leds);
        // Event
     #ifdef _LITE_VERSION
        int (*wait_event) (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except,
                struct timeval *timeout);
     #else
        int (*wait_event) (int which, fd_set *in, fd_set *out, fd_set *except,
      char mdev [MAX_PATH + 1];
      }INPUT;
    可以看到这个结构体里面的内容主要可以分为两大类:键盘和鼠标,还有一个等待函数,这个函数的作用就是从设备中读取数据,包括鼠标和键盘的数据。
    2.3 工作流程
    MiniGUI初始化的时候会调用ial的初始化函数。以2410的为例:
     BOOL Init2410Input (INPUT* input, const char* mdev, const char* mtype)
     input就是从内核传递出来的INPUT 结构数据, 
     mdev是设备的路径, 
     mtype是设备类型。
    下面是源码:
       BOOL Init2410Input (INPUT* input, const char* mdev, const char* mtype)
       {
          ts = open (mdev, O_RDONLY); //打开 操作系统的设备文件,
        if (ts update_mouse = mouse_update;  //注册自己的update_mouse 函数
        input->get_mouse_xy = mouse_getxy;   // 注册自己的get_mouse_xy 函数
        input->set_mouse_xy = NULL;                     // 触摸屏不需要这个函数,所以指为 NULL
        input->get_mouse_button = mouse_getbutton; //得到鼠标的按钮状态
        input->set_mouse_range = NULL;  //这个一般也没用
        input->wait_event = wait_event;  //这个是必备的,内核就是利用这个函数接收数据。
        mousex = 0;    
        mousey = 0;
        ts_event.x = ts_event.y = ts_event.pressure = 0;
        return TRUE;
        }
    和这个函数相对应的是void Term2410Input(void),这个类似C++里面的析构函数,在退出的时候作一些释放资源的动作,源码为:
      void Term2410Input(void)
      {
        if (ts >= 0)
            close(ts);  //关闭设备文件
      }
    大家可能会问,系统是靠这两个函数把自己的函数传递给系统,那么系统又是怎样调用这两个函数的呢。从这两个函数的名字可以看出,它们不是标准的, 在文件src/ial/ial.c也可以看到
      #ifdef _SMDK2410_IAL  
        {"SMDK2410", Init2410Input, Term2410Input},
      #endif
    表示:如果打开宏_SMDK2410_IAL并且ial_engine为“SMDK2410”就调用这两个函数,而且ial_engine是在 MiniGUI.cfg里,或者在src/sysres/mgetc-xxx.c文件里被指定的,前者是非内嵌的,后者是内嵌的。
    2.4 注册的子函数的功能
    static int wait_event (int which, fd_set *in, fd_set *out, fd_set *except, struct timeval *timeout)
    由于这个函数同时处理键盘和者鼠标的信息,所以在这个函数里用到了select函数,主要是为了解决i/o复用的问题。wait_event() 主要是读取数据,处理数据,如何处理根据自己的清况去写。
    static int mouse_getbutton(void)
    源码:
     static int mouse_getbutton(void)
     {
        return ts_event.pressure;
     }
    这个函数一般返回鼠标的键值,4代表左键。ts_event.pressure已经在wait_event函数里被处理过了。
    static int mouse_update
    源码:
     static int mouse_update(void)
     {
         return 1;
      }
    对于触摸屏,这个函数一般是直接返回。
    static void mouse_getxy
     static void mouse_getxy(int *x, int* y)
     {
        if (mousex  239) mousex = 239;
        if (mousey > 319) mousey = 319;
        *x = mousex;
        *y = mousey;
     }
    这个函数返回鼠标的坐标值在wait_event中被处理。
    如果需要参考一个完整功能的例子,可以参考 src/ial/native/native.c 文件,它是一个全功能的例子,输入包括键盘和鼠标,而且用户还可以根据自己的要求来设计。
    

      

  • 相关阅读:
    一些你可能用到的代码
    iOS 键盘下去的方法
    iOS设计模式汇总
    随笔
    Spring cloud config 分布式配置中心 (三) 总结
    Spring cloud config 分布式配置中心(二) 客户端
    Spring cloud config 分布式配置中心(一) 服务端
    jdbcUrl is required with driverClassName spring boot 2.0版本
    JpaRepository接口找不到 spring boot 项目
    解决IntelliJ “Initialization failed for 'https://start.spring.io'
  • 原文地址:https://www.cnblogs.com/timssd/p/4086276.html
Copyright © 2011-2022 走看看